Commit 48d04964 authored by Jonathan Marten's avatar Jonathan Marten

Equalise the size of control labels also for enums (combo boxes)

parent 1b8eeeb2
......@@ -131,7 +131,7 @@ bool KMixApp::restoreSessionIfApplicable(bool hasArgKeepvisibility, bool reset)
void KMixApp::newInstance(const QStringList &arguments, const QString &workingDirectory)
{
qDebug();
qCDebug(KMIX_LOG);
/**
* There are 3 cases when starting KMix:
......
......@@ -45,7 +45,7 @@ KMixDeviceManager* KMixDeviceManager::instance()
void KMixDeviceManager::initHotplug()
{
qDebug();
qCDebug(KMIX_LOG);
connect(Solid::DeviceNotifier::instance(), &Solid::DeviceNotifier::deviceAdded,
this, &KMixDeviceManager::pluggedSlot);
connect(Solid::DeviceNotifier::instance(), &Solid::DeviceNotifier::deviceRemoved,
......@@ -141,6 +141,6 @@ void KMixDeviceManager::unpluggedSlot(const QString &udi)
void KMixDeviceManager::setHotpluggingBackends(const QString& backendName)
{
qDebug() << "using" << backendName;
qCDebug(KMIX_LOG) << "using" << backendName;
_hotpluggingBackend = backendName;
}
......@@ -46,7 +46,7 @@
MDWEnum::MDWEnum( shared_ptr<MixDevice> md,
QWidget* parent, ViewBase* view, ProfControl* par_pctl) :
MixDeviceWidget(md, false, parent, view, par_pctl),
_label(0), _enumCombo(0), _layout(0)
_label(0), _enumCombo(0)
{
// create actions (on _mdwActions, see MixDeviceWidget)
......@@ -65,17 +65,23 @@ MDWEnum::MDWEnum( shared_ptr<MixDevice> md,
void MDWEnum::createWidgets()
{
if (orientation()==Qt::Vertical) {
_layout = new QVBoxLayout( this );
_layout->setAlignment(Qt::AlignLeft);
}
else {
_layout = new QHBoxLayout( this );
_layout->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
}
QBoxLayout *_layout;
if (orientation()==Qt::Vertical)
{
_layout = new QVBoxLayout(this);
_layout->setAlignment(Qt::AlignLeft|Qt::AlignTop);
}
else
{
_layout = new QHBoxLayout(this);
_layout->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
}
_label = new QLabel( m_mixdevice->readableName(), this);
_layout->addWidget(_label);
if (orientation()==Qt::Horizontal) _layout->addSpacing(8);
_enumCombo = new QComboBox(this);
_enumCombo->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
......@@ -159,3 +165,27 @@ void MDWEnum::setDisabled( bool hide )
{
emit guiVisibilityChange(this, !hide);
}
/**
* For users of this class who would like to show multiple MDWEnum's properly aligned.
* It returns the size of the control label (in the control layout direction).
*/
int MDWEnum::labelExtentHint() const
{
if (_label==nullptr) return (0);
if (orientation()==Qt::Vertical) return (_label->sizeHint().height());
else return (_label->sizeHint().width());
}
/**
* If a label from another switch is larger than ours, then the
* extent of our label is adjusted.
*/
void MDWEnum::setLabelExtent(int extent)
{
if (_label==nullptr) return;
if (orientation()==Qt::Vertical) _label->setMinimumHeight(extent);
else _label->setMinimumWidth(extent);
}
......@@ -28,7 +28,6 @@ class MixDevice;
class ViewBase;
// Qt
class QBoxLayout;
class QComboBox;
class QLabel;
......@@ -45,6 +44,8 @@ public:
void addActionToPopup( QAction *action );
QSizePolicy sizePolicy() const;
int labelExtentHint() const Q_DECL_OVERRIDE;
void setLabelExtent(int extent) Q_DECL_OVERRIDE;
public slots:
// GUI hide and show
......@@ -63,7 +64,6 @@ private:
QLabel *_label;
QComboBox *_enumCombo;
QBoxLayout *_layout;
};
#endif
......@@ -78,8 +78,8 @@ public:
// Layout
QSizePolicy sizePolicy() const;
QSize sizeHint() const Q_DECL_OVERRIDE;
int labelExtentHint() const;
void setLabelExtent(int extent);
int labelExtentHint() const Q_DECL_OVERRIDE;
void setLabelExtent(int extent) Q_DECL_OVERRIDE;
bool hasMuteButton() const;
bool hasCaptureLED() const;
......
......@@ -58,6 +58,9 @@ public:
virtual void setLabeled(bool);
virtual void setTicks(bool) {}
virtual int labelExtentHint() const { return (0); }
virtual void setLabelExtent(int extent) { Q_UNUSED(extent); }
public slots:
virtual void defineKeys();
virtual void showContextMenu(const QPoint &pos = QCursor::pos()) = 0;
......
......@@ -306,6 +306,8 @@ void ViewSliders::initLayout()
void ViewSliders::constructionFinished()
{
m_layoutSwitches->addStretch(1); // push switches to top or left
configurationUpdate();
if (!isDynamic())
{
......@@ -321,41 +323,60 @@ void ViewSliders::constructionFinished()
void ViewSliders::configurationUpdate()
{
// Adjust height of top part by setting it to the maximum of all mdw's
int labelExtent = 0;
// Adjust the view layout by setting the extent of all the control labels
// to allow space for the largest. The extent of a control's label is
// found from its labelExtentHint() virtual function (which takes account
// of the control layout direction), and is then set by its setLabelExtent()
// virtual function.
// Find out whether any MDWSlider has Switches. If one has, then we need "extents"
// The maximum extent is calculated and set separately for sliders and
// for switches (enums).
int labelExtentSliders = 0;
int labelExtentSwitches = 0;
const int num = mixDeviceCount();
// Pass 1: Set the visibility of all controls
for (int i = 0; i<num; ++i)
{
const MDWSlider *mdw = qobject_cast<MDWSlider *>(mixDeviceAt(i));
if (mdw!=nullptr && mdw->isVisibleTo(this))
{
labelExtent = qMax(labelExtent, mdw->labelExtentHint());
//qCDebug(KMIX_LOG) << "########## EXTENT for " << id() << " is " << labelExtent;
}
MixDeviceWidget *mdw = qobject_cast<MixDeviceWidget *>(mixDeviceAt(i));
if (mdw==nullptr) continue;
// The GUI level has been set earlier, by inspecting the controls
ProfControl *matchingControl = findMdw(mdw->mixDevice()->id());
mdw->setVisible(matchingControl!=nullptr);
}
//qCDebug(KMIX_LOG) << "topPartExtent is " << topPartExtent;
// Pass 2: Find the maximum extent of all applicable controls
for (int i = 0; i<num; ++i)
{
MixDeviceWidget *mdw = qobject_cast<MixDeviceWidget *>(mixDeviceAt(i));
if (mdw!=nullptr)
{
// guiLevel has been set earlier, by inspecting the controls
ProfControl *matchingControl = findMdw(mdw->mixDevice()->id());
mdw->setVisible(matchingControl!=nullptr);
const QWidget *w = mixDeviceAt(i);
Q_ASSERT(w!=nullptr);
if (!w->isVisibleTo(this)) continue; // not currently visible
MDWSlider *mdwSlider = qobject_cast<MDWSlider *>(mdw);
if (mdwSlider!=nullptr && labelExtent>0)
{
// additional options for sliders
mdwSlider->setLabelExtent(labelExtent);
}
} // if have a MixDeviceWidget
} // for all MDW's
const MDWSlider *mdws = qobject_cast<const MDWSlider *>(w);
if (mdws!=nullptr) labelExtentSliders = qMax(labelExtentSliders, mdws->labelExtentHint());
const MDWEnum *mdwe = qobject_cast<const MDWEnum *>(w);
if (mdwe!=nullptr) labelExtentSwitches = qMax(labelExtentSwitches, mdwe->labelExtentHint());
}
// Pass 3: Set the maximum extent of all applicable controls
for (int i = 0; i<num; ++i)
{
QWidget *w = mixDeviceAt(i);
Q_ASSERT(w!=nullptr);
if (!w->isVisibleTo(this)) continue; // not currently visible
MDWSlider *mdws = qobject_cast<MDWSlider *>(w);
if (mdws!=nullptr && labelExtentSliders>0) mdws->setLabelExtent(labelExtentSliders);
MDWEnum *mdwe = qobject_cast<MDWEnum *>(w);
if (mdwe!=nullptr && labelExtentSwitches>0) mdwe->setLabelExtent(labelExtentSwitches);
}
// An old comment here said that this was necessary for KDE3.
// Not sure if it is still required two generations later.
m_layoutMDW->activate();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment