Commit 04c3b4a3 authored by Jonathan Marten's avatar Jonathan Marten

ViewBase: Constify, data visibility, use QFlags for ViewFlags

parent c2463d49
......@@ -256,8 +256,6 @@ void DialogViewConfiguration::selectionChangedInactive()
*/
void DialogViewConfiguration::createPage()
{
QList<QWidget *> &mdws = _view._mdws;
QLabel *l1 = new QLabel( i18n("Visible channels:") );
_glayout->addWidget(l1,0,0);
......@@ -296,14 +294,16 @@ void DialogViewConfiguration::createPage()
// --- CONTROLS IN THE GRID ------------------------------------
//QPalette::ColorRole bgRole;
for ( int i=0; i<mdws.count(); ++i )
{
const int num = _view.mixDeviceCount();
for (int i = 0; i<num; ++i)
{
MixDeviceWidget *mdw = qobject_cast<MixDeviceWidget *>(_view.mixDeviceAt(i));
if (mdw==nullptr) continue;
//if ( i%2 == 0) bgRole = QPalette::Base; else bgRole = QPalette::AlternateBase;
QWidget *qw = mdws[i];
if ( qw->inherits("MixDeviceWidget") ) {
MixDeviceWidget *mdw = static_cast<MixDeviceWidget*>(qw);
shared_ptr<MixDevice> md = mdw->mixDevice();
QString mdName = md->readableName();
const QString mdName = md->readableName();
int splitted = -1;
if ( ! md->isEnum() ) {
......@@ -343,7 +343,6 @@ void DialogViewConfiguration::createPage()
*/
//_qLimitCB.append(0);
/*}*/
} // is not enum
} // for all MDW's
......@@ -408,7 +407,9 @@ void DialogViewConfiguration::apply()
void DialogViewConfiguration::prepareControls(QAbstractItemModel* model, bool isActiveView, GUIProfile::ControlSet& oldCtlSet, GUIProfile::ControlSet& newCtlSet)
{
int numRows = model->rowCount();
const int numRows = model->rowCount();
const int num = _view.mixDeviceCount();
for (int row = 0; row < numRows; ++row) {
// -1- Extract the value from the model ***************************
QModelIndex index = model->index(row, 0);
......@@ -416,14 +417,11 @@ void DialogViewConfiguration::prepareControls(QAbstractItemModel* model, bool is
vdci = model->data(index, Qt::ToolTipRole); // TooltipRole stores the ID (well, thats not really clean design, but it works)
QString ctlId = vdci.toString();
// -2- Find the mdw, und update it **************************
foreach ( QWidget *qw, _view._mdws )
for (int i = 0; i<num; ++i)
{
MixDeviceWidget *mdw = dynamic_cast<MixDeviceWidget*>(qw);
if ( !mdw ) {
continue;
}
MixDeviceWidget *mdw = qobject_cast<MixDeviceWidget *>(_view.mixDeviceAt(i));
if (mdw==nullptr) continue;
if ( mdw->mixDevice()->id() == ctlId ) {
mdw->setVisible(isActiveView);
......
......@@ -50,15 +50,16 @@
* initLayout() in your derived class.
*/
ViewBase::ViewBase(QWidget* parent, QString id, Qt::WindowFlags f, ViewBase::ViewFlags vflags, QString guiProfileId, KActionCollection *actionColletion)
: QWidget(parent, f), _popMenu(NULL), _actions(actionColletion), _vflags(vflags), _guiProfileId(guiProfileId)
, guiLevel(GuiVisibility::GuiSIMPLE)
: QWidget(parent, f),
_popMenu(NULL),
_actions(actionColletion),
_vflags(vflags),
guiLevel(GuiVisibility::GuiSIMPLE),
_guiProfileId(guiProfileId)
{
setObjectName(id);
// When loading the View from the XML profile, guiLevel can get overridden
m_viewId = id;
// TODO: does not need to be a member
configureIcon = QIcon::fromTheme( QLatin1String( "configure" ));
if ( _actions == 0 ) {
// We create our own action collection, if the actionColletion was 0.
......@@ -79,11 +80,6 @@ ViewBase::ViewBase(QWidget* parent, QString id, Qt::WindowFlags f, ViewBase::Vie
}
}
ViewBase::~ViewBase()
{
// Hint: The GUI profile will not be removed, as it is pooled and might be applied to a new View.
}
void ViewBase::addMixer(Mixer *mixer)
{
......@@ -93,7 +89,8 @@ void ViewBase::addMixer(Mixer *mixer)
QPushButton* ViewBase::createConfigureViewButton()
{
QPushButton* configureViewButton = new QPushButton(configureIcon, "", this);
QPushButton* configureViewButton = new QPushButton(QIcon::fromTheme(QLatin1String("configure")),
QString(), this);
configureViewButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
configureViewButton->setToolTip(i18n( "Configure this view" ));
connect(configureViewButton, SIGNAL(clicked(bool)), SLOT(configureView()));
......@@ -107,10 +104,6 @@ void ViewBase::updateGuiOptions()
updateMediaPlaybackIcons();
}
QString ViewBase::id() const {
return m_viewId;
}
bool ViewBase::isValid() const
{
return ( !_mixSet.isEmpty() || isDynamic() );
......@@ -196,11 +189,11 @@ void ViewBase::guiVisibilitySlot(MixDeviceWidget* mdw, bool enable)
ControlManager::instance().announce(md->mixer()->id(), ControlManager::ControlList, QString("ViewBase::guiVisibilitySlot"));
}
// ---------- Popup stuff START ---------------------
void ViewBase::mousePressEvent( QMouseEvent *e )
// // ---------- Popup stuff START ---------------------
void ViewBase::contextMenuEvent(QContextMenuEvent *ev)
{
if ( e->button() == Qt::RightButton )
showContextMenu();
showContextMenu();
}
/**
......@@ -289,7 +282,7 @@ void ViewBase::resetMdws()
}
int ViewBase::visibleControls()
int ViewBase::visibleControls() const
{
int visibleCount = 0;
foreach (QWidget* qw, _mdws)
......@@ -329,7 +322,7 @@ void ViewBase::toggleMenuBarSlot() {
*
* @param config The view for this config
*/
void ViewBase::load(KConfig *config)
void ViewBase::load(const KConfig *config)
{
ViewBase *view = this;
QString grp = "View.";
......@@ -403,14 +396,15 @@ void ViewBase::setGuiLevel(GuiVisibility& guiLevel)
* @return The corresponding ProfControl*
*
*/
ProfControl* ViewBase::findMdw(const QString& mdwId, GuiVisibility visibility)
ProfControl *ViewBase::findMdw(const QString& mdwId, GuiVisibility visibility) const
{
foreach ( ProfControl* pControl, guiProfile()->getControls() )
{
QRegExp idRegExp(pControl->id);
if ( mdwId.contains(idRegExp) )
{
if (pControl->getVisibility().satisfiesVisibility(visibility))
if (visibility==GuiVisibility::GuiSIMPLE ||
pControl->getVisibility().satisfiesVisibility(visibility))
{
// qCDebug(KMIX_LOG) << " MATCH " << (*pControl).id << " for " << mdwId << " with visibility " << pControl->getVisibility().getId() << " to " << visibility.getId();
return pControl;
......@@ -420,50 +414,24 @@ ProfControl* ViewBase::findMdw(const QString& mdwId, GuiVisibility visibility)
// qCDebug(KMIX_LOG) << "NOMATCH " << (*pControl).id << " for " << mdwId << " with visibility " << pControl->getVisibility().getId() << " to " << visibility.getId();
}
}
} // iterate over all ProfControl entries
return 0; // not found
} // iterate over all ProfControl entries
return (nullptr); // not found
}
/**
* Returns the ProfControl* to the given id. The first found is returned.
* GuiVisibilityis not taken into account. . All ProfControl objects are inspected.
*
* @param id The control ID
* @return The corresponding ProfControl*, or 0 if no match was found
*/
ProfControl* ViewBase::findMdw(const QString& id)
{
foreach ( ProfControl* pControl, guiProfile()->getControls() )
{
QRegExp idRegExp(pControl->id);
//qCDebug(KMIX_LOG) << "KMixToolBox::loadView() try match " << (*pControl).id << " for " << mdw->mixDevice()->id();
if ( id.contains(idRegExp) )
{
return pControl;
}
} // iterate over all ProfControl entries
return 0;// not found
}
/*
* Saves the View configuration
*/
void ViewBase::save(KConfig *config)
void ViewBase::save(KConfig *config) const
{
ViewBase *view = this;
QString grp = "View.";
grp += view->id();
const QString grp = "View."+id();
// Certain bits are not saved for dynamic mixers (e.g. PulseAudio)
bool dynamic = isDynamic(); // TODO 11 Dynamic view configuration
for (int i = 0; i < view->_mdws.count(); ++i)
for (int i = 0; i<_mdws.count(); ++i)
{
QWidget *qmdw = view->_mdws[i];
MixDeviceWidget *mdw = qobject_cast<MixDeviceWidget *>(qmdw);
MixDeviceWidget *mdw = qobject_cast<MixDeviceWidget *>(_mdws[i]);
if (mdw!=nullptr)
{
shared_ptr<MixDevice> md = mdw->mixDevice();
......
......@@ -22,14 +22,15 @@
#define ViewBase_h
// Qt
#include <QWidget>
#include <QIcon>
#include <QList>
#include <QPushButton>
#include <QFlags>
// KDE
#include <KActionCollection>
class QMenu;
class QContextMenuEvent;
class Mixer;
class MixDevice;
......@@ -41,48 +42,32 @@ class MixDevice;
#include "gui/mixdevicewidget.h"
/**
* The ViewBase is a virtual base class, to be used for subclassing the real Mixer Views.
* The ViewBase is an abstract base class, to be used for subclassing the real Mixer Views.
*/
class ViewBase : public QWidget
{
Q_OBJECT
friend class KMixToolBox; // the toolbox is everybodys friend :-)
public:
enum ViewFlag
{
HasMenuBar = 0x0001,
MenuBarVisible = 0x0002,
Horizontal = 0x0004,
Vertical = 0x0008
};
Q_DECLARE_FLAGS(ViewFlags, ViewFlag);
typedef uint ViewFlags;
enum ViewFlagsEnum {
// Regular flags
HasMenuBar = 0x0001,
MenuBarVisible = 0x0002,
Horizontal = 0x0004,
Vertical = 0x0008
};
ViewBase(QWidget* parent, QString id, Qt::WindowFlags f, ViewFlags vflags, QString guiProfileId, KActionCollection* actionCollection = 0);
virtual ~ViewBase();
void addMixer(Mixer *mixer);
QString id() const;
// This method is called by ViewBase at the end of createDeviceWidgets(). The default
// implementation does nothing. Subclasses can override this method for doing final
// touches. This is very much like polish(), but called at an exactly well-known time.
// Also I do not want Views to interfere with polish()
virtual void constructionFinished() = 0;
/**
* Creates a suitable representation for the given MixDevice.
*/
virtual QWidget* add(const shared_ptr<MixDevice>) = 0;
// The GUI profile will not be removed on destruction,
// as it is pooled and might be applied to a new View.
virtual ~ViewBase() = default;
// This method is called after a configuration update (show/hide controls, split/unsplit).
virtual void configurationUpdate() = 0;
void load(KConfig *config);
void save(KConfig *config);
void load(const KConfig *config);
void save(KConfig *config) const;
/**
* Creates the widgets for all supported devices. The default implementation loops
......@@ -90,34 +75,30 @@ public:
*/
virtual void createDeviceWidgets();
int visibleControls();
QMenu *getPopup();
bool isDynamic() const;
bool pulseaudioPresent() const;
/**
* Popup stuff
*/
virtual QMenu* getPopup();
virtual void popupReset();
virtual void showContextMenu();
virtual bool isValid() const;
int visibleControls() const;
void setIcons(bool on);
void setLabels(bool on);
void setTicks(bool on);
GUIProfile* guiProfile() { return GUIProfile::find(_guiProfileId); };
// GUIComplexity getGuiComplexity() { return guiComplexity; };
ProfControl* findMdw(const QString& id);
ProfControl* findMdw(const QString& mdwId, GuiVisibility visibility);
bool isValid() const;
QString id() const { return (m_viewId); }
KActionCollection* actionCollection() { return _actions; };
GUIProfile* guiProfile() const { return (GUIProfile::find(_guiProfileId)); }
ProfControl *findMdw(const QString &mdwId, GuiVisibility visibility = GuiVisibility::GuiSIMPLE) const;
KActionCollection *actionCollection() const { return (_actions); };
const QList<Mixer*> &getMixers() const { return (_mixers); };
QList<Mixer*>& getMixers() { return _mixers; };
int mixDeviceCount() const { return (_mdws.count()); }
QWidget *mixDeviceAt(int i) const { return (_mdws.at(i)); }
private:
/**
* Contains the widgets for the _mixSet. There is a 1:1 relationship, which means:
* _mdws[i] is the Widget for the MixDevice _mixSet[i] - please see ViewBase::createDeviceWidgets().
......@@ -126,46 +107,60 @@ public:
*/
QList<QWidget *> _mdws;
protected:
MixSet _mixSet;
QList<Mixer*> _mixers;
QMenu *_popMenu;
KActionCollection* _actions; // -<- application wide action collection
KActionCollection *_localActionColletion;
ViewFlags _vflags;
GuiVisibility guiLevel;
const QString _guiProfileId;
KActionCollection *_localActionColletion;
QIcon configureIcon;
QString m_viewId;
virtual void initLayout() = 0;
private:
void setGuiLevel(GuiVisibility& guiLevel);
void updateMediaPlaybackIcons();
void popupReset();
protected:
MixSet _mixSet;
QList<Mixer*> _mixers;
protected:
void resetMdws();
void updateGuiOptions();
QPushButton* createConfigureViewButton();
QPushButton *createConfigureViewButton();
void addMixer(Mixer *mixer);
void setGuiLevel(GuiVisibility& guiLevel);
virtual void initLayout() = 0;
GuiVisibility guiLevel;
/**
* Popup stuff
*/
void contextMenuEvent(QContextMenuEvent *ev) Q_DECL_OVERRIDE;
virtual void showContextMenu();
// Creates a suitable representation for the given MixDevice.
virtual QWidget *add(const shared_ptr<MixDevice>) = 0;
// This method is called by ViewBase at the end of createDeviceWidgets(). The default
// implementation does nothing. Subclasses can override this method for doing final
// touches. This is very much like polish(), but called at an exactly well-known time.
// Also I do not want Views to interfere with polish()
virtual void constructionFinished() = 0;
public slots:
virtual void refreshVolumeLevels(); // TODO remove
virtual void configureView();
void toggleMenuBarSlot();
protected slots:
void mousePressEvent( QMouseEvent *e ) Q_DECL_OVERRIDE;
signals:
void toggleMenuBar();
private:
QString m_viewId;
void updateMediaPlaybackIcons();
private slots:
void guiVisibilitySlot(MixDeviceWidget* source, bool enable);
void toggleMenuBarSlot();
};
#endif
Q_DECLARE_OPERATORS_FOR_FLAGS(ViewBase::ViewFlags);
#endif
......@@ -128,13 +128,6 @@ void ViewDockAreaPopup::controlsChange(ControlManager::ChangeType changeType)
}
void ViewDockAreaPopup::wheelEvent ( QWheelEvent * e )
{
if ( _mdws.isEmpty() )
return;
}
void ViewDockAreaPopup::configurationUpdate()
{
// TODO Do we still need configurationUpdate(). It was never implemented for ViewDockAreaPopup
......@@ -407,16 +400,18 @@ QPushButton* ViewDockAreaPopup::createRestoreVolumeButton ( int storageSlot )
return profileButton;
}
void ViewDockAreaPopup::refreshVolumeLevels()
{
foreach ( QWidget* qw, _mdws )
{
//qCDebug(KMIX_LOG) << "rvl: " << qw;
MixDeviceWidget* mdw = qobject_cast<MixDeviceWidget*>(qw);
if ( mdw != 0 ) mdw->update();
}
const int num = mixDeviceCount();
for (int i = 0; i<num; ++i)
{
MixDeviceWidget *mdw = qobject_cast<MixDeviceWidget *>(mixDeviceAt(i));
if (mdw!=nullptr) mdw->update();
}
}
void ViewDockAreaPopup::configureView()
{
// Q_ASSERT( !pulseaudioPresent() );
......
......@@ -53,7 +53,6 @@ public:
protected:
KMixWindow *_kmixMainWindow;
void wheelEvent ( QWheelEvent * e ) Q_DECL_OVERRIDE;
void initLayout() Q_DECL_OVERRIDE;
private:
......
......@@ -329,9 +329,11 @@ void ViewSliders::configurationUpdate()
int labelExtent = 0;
// Find out whether any MDWSlider has Switches. If one has, then we need "extents"
for (int i = 0; i<_mdws.count(); ++i)
const int num = mixDeviceCount();
for (int i = 0; i<num; ++i)
{
const MDWSlider *mdw = qobject_cast<MDWSlider *>(_mdws[i]);
const MDWSlider *mdw = qobject_cast<MDWSlider *>(mixDeviceAt(i));
if (mdw!=nullptr && mdw->isVisibleTo(this))
{
labelExtent = qMax(labelExtent, mdw->labelExtentHint());
......@@ -340,16 +342,16 @@ void ViewSliders::configurationUpdate()
}
//qCDebug(KMIX_LOG) << "topPartExtent is " << topPartExtent;
for (int i = 0; i<_mdws.count(); ++i)
for (int i = 0; i<num; ++i)
{
MixDeviceWidget *mdw = qobject_cast<MixDeviceWidget *>(_mdws[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(), guiLevel);
ProfControl *matchingControl = findMdw(mdw->mixDevice()->id());
mdw->setVisible(matchingControl!=nullptr);
MDWSlider *mdwSlider = qobject_cast<MDWSlider *>(_mdws[i]);
MDWSlider *mdwSlider = qobject_cast<MDWSlider *>(mdw);
if (mdwSlider!=nullptr && labelExtent>0)
{
// additional options for sliders
......@@ -364,12 +366,11 @@ void ViewSliders::configurationUpdate()
void ViewSliders::refreshVolumeLevels()
{
for (int i = 0; i < _mdws.count(); i++)
const int num = mixDeviceCount();
for (int i = 0; i<num; ++i)
{
QWidget *mdwx = _mdws[i];
MixDeviceWidget* mdw = ::qobject_cast<MixDeviceWidget*>(mdwx);
if (mdw != 0)
MixDeviceWidget *mdw = qobject_cast<MixDeviceWidget*>(mixDeviceAt(i));
if (mdw!=nullptr)
{ // sanity check
#ifdef TEST_MIXDEVICE_COMPOSITE
......
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