Commit a4ed51e1 authored by Jonathan Marten's avatar Jonathan Marten
Browse files

Ensure that the volume popup sliders and labels line up

The control alignment carried out for the main KMix window in
ViewSliders::configurationUpdate() was not being done for
the system tray popup, which meant that the controls may
not line up with long labels.  Move the alignment to
ViewBase::adjustControlsLayout() and do it for the system tray
popup also.

CCBUG:314280
parent 0ddf16d7
......@@ -213,11 +213,11 @@ QSize MDWSlider::sizeHint() const
int MDWSlider::labelExtentHint() const
{
if (m_controlLabel==nullptr) return (0);
if (orientation()==Qt::Vertical) return (m_controlLabel->heightForWidth(m_controlLabel->minimumWidth()));
if (orientation()==Qt::Vertical) return (m_controlLabel->heightForWidth(m_controlLabel->width()));
else return (m_controlLabel->sizeHint().width());
}
/**
* If a label from another widget has more lines than this widget, then a spacer is added under the label
*/
......
......@@ -38,6 +38,7 @@
#include "gui/kmixtoolbox.h"
#include "gui/mixdevicewidget.h"
#include "gui/mdwslider.h"
#include "gui/mdwenum.h"
#include "core/ControlManager.h"
#include "core/GlobalConfig.h"
#include "core/mixer.h"
......@@ -171,6 +172,57 @@ void ViewBase::createDeviceWidgets()
if (wasVisible) show(); // show again if originally visible
}
void ViewBase::adjustControlsLayout()
{
// 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.
// 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: Find the maximum extent of all applicable controls
for (int i = 0; i<num; ++i)
{
const QWidget *w = mixDeviceAt(i);
Q_ASSERT(w!=nullptr);
if (!w->isVisibleTo(this)) continue; // not currently visible
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 2: 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 in ViewSliders::configurationUpdate() said
// that this was necessary for KDE3. Not sure if it is still
// required two generations later.
layout()->activate();
}
/**
* Called when a specific control is to be shown or hidden. At the moment it is only called via
* the "hide" action in the MDW context menu.
......
......@@ -134,6 +134,8 @@ protected:
virtual void initLayout() = 0;
virtual Qt::Orientation orientationSetting() const = 0;
void adjustControlsLayout();
/**
* Creates the widgets for all supported devices. The default implementation loops
* over the supported MixDevice's and calls add() for each of it.
......
......@@ -432,9 +432,10 @@ _layoutMDW->addWidget( seperatorBetweenMastersAndStreams, row, col );
return mdw;
}
void ViewDockAreaPopup::constructionFinished()
{
// qCDebug(KMIX_LOG) << "ViewDockAreaPopup::constructionFinished()\n";
//qCDebug(KMIX_LOG);
mainWindowButton = new QPushButton(QIcon::fromTheme("show-mixer"), "" , this);
mainWindowButton->setObjectName(QLatin1String("MixerPanel"));
......@@ -460,17 +461,12 @@ void ViewDockAreaPopup::constructionFinished()
int sliderRow = _layoutMDW->rowCount();
_layoutMDW->addLayout(optionsLayout, sliderRow, 0, 1, _layoutMDW->columnCount());
// The controls layout needs to be adjusted after the popup has been shown.
QTimer::singleShot(0, this, [this](){ adjustControlsLayout(); });
updateGuiOptions();
_layoutMDW->update();
_layoutMDW->activate();
//bool fnc = focusNextChild();
//qCWarning(KMIX_LOG) << "fnc=" <<fnc;
// qCDebug(KMIX_LOG) << "F layout()=" << layout() << ", _layoutMDW=" << _layoutMDW;
}
QPushButton* ViewDockAreaPopup::createRestoreVolumeButton ( int storageSlot )
{
QString buttonText = QString("%1").arg(storageSlot);
......
......@@ -299,7 +299,6 @@ void ViewSliders::initLayout()
void ViewSliders::constructionFinished()
{
m_layoutSwitches->addStretch(1); // push switches to top or left
configurationUpdate();
if (!isDynamic())
{
......@@ -315,20 +314,9 @@ void ViewSliders::constructionFinished()
void ViewSliders::configurationUpdate()
{
// 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.
// 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
// Set the visibility of all controls
for (int i = 0; i<num; ++i)
{
MixDeviceWidget *mdw = qobject_cast<MixDeviceWidget *>(mixDeviceAt(i));
......@@ -338,38 +326,8 @@ void ViewSliders::configurationUpdate()
const ProfControl *matchingControl = findMdw(mdw->mixDevice()->id());
mdw->setVisible(matchingControl!=nullptr);
}
// Pass 2: Find the maximum extent of all applicable controls
for (int i = 0; i<num; ++i)
{
const QWidget *w = mixDeviceAt(i);
Q_ASSERT(w!=nullptr);
if (!w->isVisibleTo(this)) continue; // not currently visible
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();
// Then adjust the controls layout
adjustControlsLayout();
}
......
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