Commit 1b8eeeb2 authored by Jonathan Marten's avatar Jonathan Marten

Consistently handle orientation setting throughout ViewBase and MixDeviceWidget

The ViewBase retains the master orientation setting, as a separate
Qt::Orientation value;  it is eliminated from ViewFlags.  ViewBase
subclasses use this setting.  MixDeviceWidget subclasses ask their
associated view for the same setting.

ViewBase subclasses (ViewSliders and ViewDockAreaPopup) query the
appropriate application setting via their virtual orientationSetting().
parent 04c3b4a3
......@@ -1002,11 +1002,6 @@ bool KMixWindow::addMixerWidget(const QString& mixer_ID, QString guiprofId, int
ViewBase::ViewFlags vflags = ViewBase::HasMenuBar;
if ((_actionShowMenubar == 0) || _actionShowMenubar->isChecked())
vflags |= ViewBase::MenuBarVisible;
if (GlobalConfig::instance().data.getToplevelOrientation() == Qt::Vertical)
vflags |= ViewBase::Horizontal;
else
vflags |= ViewBase::Vertical;
KMixerWidget *kmw = new KMixerWidget(mixer, this, vflags, guiprofId, actionCollection());
/* A newly added mixer will automatically added at the top
* and thus the window title is also set appropriately */
......
......@@ -41,6 +41,7 @@ GuiVisibility const GuiVisibility::GuiEXTENDED(QString("extended") , GuiVisibili
GuiVisibility const GuiVisibility::GuiFULL (QString("all" ) , GuiVisibility::FULL);
GuiVisibility const GuiVisibility::GuiCUSTOM (QString("custom" ) , GuiVisibility::CUSTOM);
GuiVisibility const GuiVisibility::GuiNEVER (QString("never" ) , GuiVisibility::NEVER);
GuiVisibility const GuiVisibility::GuiDEFAULT (QString("default" ) , GuiVisibility::DEFAULT);
bool SortedStringComparator::operator()(const std::string& s1, const std::string& s2) const {
......
......@@ -66,7 +66,7 @@ public:
*/
class GuiVisibility
{
enum GuiVisibilityId { SIMPLE, EXTENDED, FULL, CUSTOM, NEVER };
enum GuiVisibilityId { SIMPLE, EXTENDED, FULL, CUSTOM, NEVER, DEFAULT };
QString id;
GuiVisibilityId idCode;
......@@ -75,7 +75,8 @@ static GuiVisibility const GuiSIMPLE;
static GuiVisibility const GuiEXTENDED;
static GuiVisibility const GuiFULL;
static GuiVisibility const GuiCUSTOM;
static GuiVisibility const GuiNEVER; // e.g. templates with regexp's
static GuiVisibility const GuiNEVER; // e.g. templates with regexp's
static GuiVisibility const GuiDEFAULT; // default argument to ViewBase::findMdw()
private:
GuiVisibility(QString id, GuiVisibilityId idCode)
......@@ -94,6 +95,7 @@ static GuiVisibility const GuiNEVER; // e.g. templates with regexp's
* Returns whether this GuiVisibility satisfies the other GuiVisibility.
* GuiNEVER can never be satisfied - if this or other is GuiNEVER, the result is false.
* GuiCUSTOM is always satisfied - if this or other is GuiCUSTOM, the result is true.
* GuiDEFAULT for the other is always satisfied.
* The other 3 enum values are completely ordered as GuiSIMPLE, GuiEXTENDED, GuiFULL.
* <p>
* For example
......@@ -109,6 +111,9 @@ static GuiVisibility const GuiNEVER; // e.g. templates with regexp's
if (this->idCode == GuiVisibility::CUSTOM || other.idCode == GuiVisibility::CUSTOM)
return false;
if (other.idCode==GuiVisibility::DEFAULT)
return true;
return this->idCode <= other.idCode;
}
......
......@@ -44,9 +44,8 @@
* The orientation (horizontal, vertical) is ignored
*/
MDWEnum::MDWEnum( shared_ptr<MixDevice> md,
Qt::Orientation orientation,
QWidget* parent, ViewBase* view, ProfControl* par_pctl) :
MixDeviceWidget(md, false, orientation, parent, view, par_pctl),
MixDeviceWidget(md, false, parent, view, par_pctl),
_label(0), _enumCombo(0), _layout(0)
{
// create actions (on _mdwActions, see MixDeviceWidget)
......@@ -66,7 +65,7 @@ MDWEnum::MDWEnum( shared_ptr<MixDevice> md,
void MDWEnum::createWidgets()
{
if ( m_orientation == Qt::Vertical ) {
if (orientation()==Qt::Vertical) {
_layout = new QVBoxLayout( this );
_layout->setAlignment(Qt::AlignLeft);
}
......
......@@ -40,7 +40,6 @@ class MDWEnum : public MixDeviceWidget
public:
MDWEnum( shared_ptr<MixDevice> md,
Qt::Orientation orientation,
QWidget* parent, ViewBase* view, ProfControl* pctl);
virtual ~MDWEnum() = default;
......
......@@ -60,11 +60,11 @@ bool MDWSlider::debugMe = false;
* Due to the many options, this is the most complicated MixDeviceWidget subclass.
*/
MDWSlider::MDWSlider(shared_ptr<MixDevice> md, bool showMuteLED, bool showCaptureLED
, bool includeMixerName, bool small, Qt::Orientation orientation, QWidget* parent
, bool includeMixerName, bool small, QWidget* parent
, ViewBase* view
, ProfControl* par_ctl
) :
MixDeviceWidget(md,small,orientation,parent,view, par_ctl),
MixDeviceWidget(md,small,parent,view, par_ctl),
m_linked(true),
m_controlGrid(nullptr),
m_controlIcon(nullptr),
......@@ -191,7 +191,7 @@ void MDWSlider::createShortcutActions()
QSizePolicy MDWSlider::sizePolicy() const
{
if ( m_orientation == Qt::Vertical )
if (orientation()==Qt::Vertical)
{
return QSizePolicy( QSizePolicy::Preferred, QSizePolicy::MinimumExpanding );
}
......@@ -218,7 +218,7 @@ int MDWSlider::labelExtentHint() const
{
if (m_controlLabel==nullptr) return (0);
if (m_orientation==Qt::Vertical) return (m_controlLabel->heightForWidth(m_controlLabel->minimumWidth()));
if (orientation()==Qt::Vertical) return (m_controlLabel->heightForWidth(m_controlLabel->minimumWidth()));
else return (m_controlLabel->sizeHint().width());
}
......@@ -229,7 +229,7 @@ void MDWSlider::setLabelExtent(int extent)
{
if (m_controlGrid==nullptr) return;
if (m_orientation==Qt::Vertical) m_controlGrid->setRowMinimumHeight(1, extent);
if (orientation()==Qt::Vertical) m_controlGrid->setRowMinimumHeight(1, extent);
else m_controlGrid->setColumnMinimumWidth(1, extent);
}
......@@ -291,7 +291,7 @@ QWidget *MDWSlider::guiAddButtonSpacer()
if (hasMuteButton() || hasCaptureLED()) return (nullptr);
// spacer not needed
QWidget *buttonSpacer = new QWidget(this);
if (m_orientation==Qt::Vertical) // vertical sliders
if (orientation()==Qt::Vertical) // vertical sliders
{
buttonSpacer->setMinimumHeight(controlButtonSize().height());
buttonSpacer->setMaximumWidth(1);
......@@ -352,7 +352,7 @@ void MDWSlider::createWidgets( bool showMuteButton, bool showCaptureLED, bool in
setLayout(m_controlGrid);
QBoxLayout *volLayout;
if (m_orientation==Qt::Vertical) // vertical sliders
if (orientation()==Qt::Vertical) // vertical sliders
{
m_controlGrid->setContentsMargins(2, 0, 2, 0);
const Qt::Alignment sliderAlign = Qt::AlignHCenter|Qt::AlignBottom;
......@@ -530,10 +530,8 @@ void MDWSlider::addMediaControls(QBoxLayout* volLayout)
MediaController* mediaController = mixDevice()->getMediaController();
QBoxLayout *mediaLayout;
if (m_orientation == Qt::Vertical)
mediaLayout = new QVBoxLayout();
else
mediaLayout = new QHBoxLayout();
if (orientation()==Qt::Vertical) mediaLayout = new QVBoxLayout();
else mediaLayout = new QHBoxLayout();
// QFrame* frame1 = new QFrame(this);
// frame1->setFrameShape(QFrame::StyledPanel);
......@@ -644,17 +642,17 @@ void MDWSlider::addSliders( QBoxLayout *volLayout, char type, Volume& vol,
QString subcontrolTranslation;
if ( type == 'c' ) subcontrolTranslation += i18n("Capture") + ' ';
subcontrolTranslation += Volume::channelNameReadable(vc.chid);
subcontrolLabel = createLabel(this, subcontrolTranslation, m_orientation, true);
subcontrolLabel = createLabel(this, subcontrolTranslation, orientation(), true);
volLayout->addWidget(subcontrolLabel);
QAbstractSlider* slider;
if ( m_small )
{
slider = new KSmallSlider( minvol, maxvol, (maxvol-minvol+1) / Volume::VOLUME_PAGESTEP_DIVISOR,
vol.getVolume( vc.chid ), m_orientation, this );
vol.getVolume( vc.chid ), orientation(), this );
} // small
else {
slider = new VolumeSlider( m_orientation, this );
slider = new VolumeSlider(orientation(), this);
slider->setMinimum(minvol);
slider->setMaximum(maxvol);
slider->setPageStep(maxvol / Volume::VOLUME_PAGESTEP_DIVISOR);
......@@ -663,12 +661,8 @@ void MDWSlider::addSliders( QBoxLayout *volLayout, char type, Volume& vol,
extraData(slider).setSubcontrolLabel(subcontrolLabel);
if ( m_orientation == Qt::Vertical ) {
slider->setMinimumHeight( minSliderSize );
}
else {
slider->setMinimumWidth( minSliderSize );
}
if (orientation()==Qt::Vertical) slider->setMinimumHeight(minSliderSize);
else slider->setMinimumWidth(minSliderSize);
if ( ! _pctl->getBackgroundColor().isEmpty() ) {
slider->setStyleSheet("QSlider { background-color: " + _pctl->getBackgroundColor() + " }");
}
......
......@@ -51,7 +51,7 @@ class MDWSlider : public MixDeviceWidget
public:
MDWSlider( shared_ptr<MixDevice> md,
bool includePlayback, bool includeCapture,
bool includeMixerName, bool small, Qt::Orientation,
bool includeMixerName, bool small,
QWidget* parent, ViewBase* view, ProfControl *pctl);
virtual ~MDWSlider();
......
......@@ -48,11 +48,11 @@
* the panel applet or any other smallish settings.
*/
MixDeviceWidget::MixDeviceWidget(shared_ptr<MixDevice> md,
bool small, Qt::Orientation orientation,
bool small,
QWidget* parent, ViewBase* view, ProfControl* par_pctl) :
QWidget( parent ), m_mixdevice( md ), m_view( view ), _pctl(par_pctl),
m_orientation( orientation ), m_small( small )
, m_shortcutsDialog(0)
m_small( small ),
m_shortcutsDialog(nullptr)
{
setContextMenuPolicy(Qt::DefaultContextMenu);
......
......@@ -25,18 +25,15 @@
#ifndef MIXDEVICEWIDGET_H
#define MIXDEVICEWIDGET_H
#include <QWidget>
#include "core/mixdevice.h"
#include "core/volume.h"
#include <qpixmap.h>
#include "gui/viewbase.h"
class KActionCollection;
class KShortcutsDialog;
class MixDevice;
class ProfControl;
class ViewBase;
class MixDeviceWidget : public QWidget
{
......@@ -44,7 +41,7 @@ class MixDeviceWidget : public QWidget
public:
MixDeviceWidget( shared_ptr<MixDevice> md,
bool small, Qt::Orientation orientation,
bool small,
QWidget* parent, ViewBase*, ProfControl * );
virtual ~MixDeviceWidget() = default;
......@@ -80,13 +77,14 @@ protected slots:
protected:
void contextMenuEvent(QContextMenuEvent *ev) Q_DECL_OVERRIDE;
Qt::Orientation orientation() const { return (m_view->orientation()); }
protected:
shared_ptr<MixDevice> m_mixdevice;
KActionCollection* _mdwActions;
KActionCollection* _mdwPopupActions;
ViewBase* m_view;
ProfControl* _pctl;
Qt::Orientation m_orientation;
bool m_small;
KShortcutsDialog* m_shortcutsDialog;
};
......
......@@ -58,6 +58,8 @@ ViewBase::ViewBase(QWidget* parent, QString id, Qt::WindowFlags f, ViewBase::Vie
_guiProfileId(guiProfileId)
{
setObjectName(id);
qCDebug(KMIX_LOG) << "id" << id << "flags" << vflags;
// When loading the View from the XML profile, guiLevel can get overridden
m_viewId = id;
......@@ -148,6 +150,9 @@ void ViewBase::createDeviceWidgets()
const bool wasVisible = isVisible();
if (wasVisible) hide(); // hide if currently visible
_orientation = orientationSetting(); // refresh orientation from settings
qCDebug(KMIX_LOG) << id() << "orientation" << _orientation;
initLayout();
foreach (const shared_ptr<MixDevice> md, _mixSet)
{
......@@ -236,6 +241,9 @@ void ViewBase::showContextMenu()
_popMenu->popup( pos );
}
// ---------- Popup stuff END ---------------------
void ViewBase::refreshVolumeLevels()
{
// is virtual
......@@ -312,8 +320,6 @@ void ViewBase::toggleMenuBarSlot() {
//qCDebug(KMIX_LOG) << "ViewBase::toggleMenuBarSlot() done\n";
}
/**
* Loads the configuration of this view.
* <p>
......@@ -403,8 +409,7 @@ ProfControl *ViewBase::findMdw(const QString& mdwId, GuiVisibility visibility) c
QRegExp idRegExp(pControl->id);
if ( mdwId.contains(idRegExp) )
{
if (visibility==GuiVisibility::GuiSIMPLE ||
pControl->getVisibility().satisfiesVisibility(visibility))
if (pControl->getVisibility().satisfiesVisibility(visibility))
{
// qCDebug(KMIX_LOG) << " MATCH " << (*pControl).id << " for " << mdwId << " with visibility " << pControl->getVisibility().getId() << " to " << visibility.getId();
return pControl;
......@@ -470,7 +475,3 @@ void ViewBase::save(KConfig *config) const
}
}
}
// ---------- Popup stuff END ---------------------
......@@ -18,8 +18,8 @@
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef ViewBase_h
#define ViewBase_h
#ifndef VIEWBASE_H
#define VIEWBASE_H
// Qt
#include <QList>
......@@ -34,12 +34,12 @@ class QContextMenuEvent;
class Mixer;
class MixDevice;
class MixDeviceWidget;
// KMix
#include "core/mixdevice.h"
#include "core/mixset.h"
#include "gui/guiprofile.h"
#include "gui/mixdevicewidget.h"
/**
* The ViewBase is an abstract base class, to be used for subclassing the real Mixer Views.
......@@ -52,9 +52,7 @@ public:
enum ViewFlag
{
HasMenuBar = 0x0001,
MenuBarVisible = 0x0002,
Horizontal = 0x0004,
Vertical = 0x0008
MenuBarVisible = 0x0002
};
Q_DECLARE_FLAGS(ViewFlags, ViewFlag);
......@@ -69,12 +67,6 @@ public:
void load(const KConfig *config);
void save(KConfig *config) const;
/**
* Creates the widgets for all supported devices. The default implementation loops
* over the supported MixDevice's and calls add() for each of it.
*/
virtual void createDeviceWidgets();
QMenu *getPopup();
bool isDynamic() const;
......@@ -90,7 +82,7 @@ public:
GUIProfile* guiProfile() const { return (GUIProfile::find(_guiProfileId)); }
ProfControl *findMdw(const QString &mdwId, GuiVisibility visibility = GuiVisibility::GuiSIMPLE) const;
ProfControl *findMdw(const QString &mdwId, GuiVisibility visibility = GuiVisibility::GuiDEFAULT) const;
KActionCollection *actionCollection() const { return (_actions); };
const QList<Mixer*> &getMixers() const { return (_mixers); };
......@@ -98,6 +90,8 @@ public:
int mixDeviceCount() const { return (_mdws.count()); }
QWidget *mixDeviceAt(int i) const { return (_mdws.at(i)); }
Qt::Orientation orientation() const { return (_orientation); }
private:
/**
* Contains the widgets for the _mixSet. There is a 1:1 relationship, which means:
......@@ -112,6 +106,7 @@ private:
KActionCollection *_localActionColletion;
ViewFlags _vflags;
Qt::Orientation _orientation;
GuiVisibility guiLevel;
const QString _guiProfileId;
......@@ -133,6 +128,13 @@ protected:
void addMixer(Mixer *mixer);
virtual void initLayout() = 0;
virtual Qt::Orientation orientationSetting() const = 0;
/**
* Creates the widgets for all supported devices. The default implementation loops
* over the supported MixDevice's and calls add() for each of it.
*/
void createDeviceWidgets();
/**
* Popup stuff
......
......@@ -38,7 +38,6 @@
#include "apps/kmix.h"
#include "core/mixer.h"
#include "core/ControlManager.h"
#include "core/GlobalConfig.h"
#include "gui/dialogchoosebackends.h"
#include "gui/guiprofile.h"
#include "gui/kmixprefdlg.h"
......@@ -288,7 +287,8 @@ Application: KMix (kmix), signal: Segmentation fault
QWidget* ViewDockAreaPopup::add(shared_ptr<MixDevice> md)
{
bool vertical = (GlobalConfig::instance().data.getTraypopupOrientation() == Qt::Vertical); // I am wondering whether using vflags for this would still make sense
const bool vertical = (orientation()==Qt::Vertical);
/*
QString dummyMatchAll("*");
QString matchAllPlaybackAndTheCswitch("pvolume,cvolume,pswitch,cswitch");
......@@ -335,10 +335,9 @@ _layoutMDW->addWidget( seperatorBetweenMastersAndStreams, row, col );
true, // Show Record LED
true, // Include Mixer Name
false, // Small
vertical ? Qt::Vertical : Qt::Horizontal,
this, // parent
this // NOT ANYMORE!!! -> Is "NULL", so that there is no RMB-popup
, pctl
this, // view
pctl // par_ctl
);
mdw->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
int sliderColumn = vertical ? _layoutMDW->columnCount() : _layoutMDW->rowCount();
......@@ -439,3 +438,8 @@ void ViewDockAreaPopup::showPanelSlot()
static_cast<QWidget*>(parent())->hide();
}
Qt::Orientation ViewDockAreaPopup::orientationSetting() const
{
return (GlobalConfig::instance().data.getTraypopupOrientation());
}
......@@ -54,6 +54,7 @@ protected:
KMixWindow *_kmixMainWindow;
void initLayout() Q_DECL_OVERRIDE;
Qt::Orientation orientationSetting() const Q_DECL_OVERRIDE;
private:
QGridLayout* _layoutMDW;
......
......@@ -36,7 +36,6 @@
// KMix
#include "core/ControlManager.h"
#include "core/GlobalConfig.h"
#include "core/mixdevicecomposite.h"
#include "core/mixer.h"
#include "gui/guiprofile.h"
......@@ -112,12 +111,10 @@ void ViewSliders::controlsChange(ControlManager::ChangeType changeType)
QWidget *ViewSliders::add(const shared_ptr<MixDevice> md)
{
MixDeviceWidget *mdw;
Qt::Orientation orientation = GlobalConfig::instance().data.getToplevelOrientation();
if (md->isEnum()) // control is a switch
{
mdw = new MDWEnum(md, // MixDevice (parameter)
orientation, // Orientation
this, // parent
this, // View widget
md->controlProfile()); // profile
......@@ -130,7 +127,6 @@ QWidget *ViewSliders::add(const shared_ptr<MixDevice> md)
true, // Show Record LED
false, // Include Mixer Name
false, // Small
orientation, // Orientation
this, // parent
this, // View widget
md->controlProfile()); // profile
......@@ -172,8 +168,8 @@ void ViewSliders::initLayout()
m_layoutMDW->setRowStretch(0, 1);
m_layoutMDW->setColumnStretch(0, 1);
if (GlobalConfig::instance().data.getToplevelOrientation()==Qt::Horizontal)
{ // horizontal sliders
if (orientation()==Qt::Horizontal) // horizontal sliders
{
m_layoutMDW->setAlignment(Qt::AlignLeft|Qt::AlignTop);
m_layoutSliders = new QVBoxLayout();
......@@ -205,8 +201,8 @@ void ViewSliders::initLayout()
m_emptyStreamHint->setCloseButtonVisible(false);
m_layoutSliders->addWidget(m_emptyStreamHint);
if (GlobalConfig::instance().data.getToplevelOrientation()==Qt::Horizontal)
{ // horizontal sliders
if (orientation()==Qt::Horizontal) // horizontal sliders
{
// Row 0: Sliders
m_layoutMDW->addLayout(m_layoutSliders, 0, 0, 1, -1, Qt::AlignHCenter|Qt::AlignVCenter);
// Row 1: Switches
......@@ -253,7 +249,7 @@ void ViewSliders::initLayout()
// Now check whether subcontrols required
const bool subcontrolPlaybackWanted = (control->useSubcontrolPlayback() && (md->playbackVolume().hasVolume() || md->hasMuteSwitch()));
const bool subcontrolCaptureWanted = (control->useSubcontrolCapture() && (md->captureVolume() .hasVolume() || md->captureVolume() .hasSwitch()));
const bool subcontrolCaptureWanted = (control->useSubcontrolCapture() && (md->captureVolume().hasVolume() || md->captureVolume().hasSwitch()));
const bool subcontrolEnumWanted = (control->useSubcontrolEnum() && md->isEnum());
const bool subcontrolWanted = subcontrolPlaybackWanted|subcontrolCaptureWanted|subcontrolEnumWanted;
if (!subcontrolWanted) continue;
......@@ -403,3 +399,9 @@ void ViewSliders::refreshVolumeLevels()
}
}
}
Qt::Orientation ViewSliders::orientationSetting() const
{
return (GlobalConfig::instance().data.getToplevelOrientation());
}
......@@ -51,6 +51,7 @@ public slots:
protected:
void initLayout() Q_DECL_OVERRIDE;
Qt::Orientation orientationSetting() const Q_DECL_OVERRIDE;
private:
void refreshVolumeLevels() Q_DECL_OVERRIDE;
......
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