Commit c4028835 authored by Jonathan Marten's avatar Jonathan Marten

Tidy up the MixDeviceWidget context menu generation

Let MixDeviceWidget::contextMenuEvent() handle the initial creation
and eventual showing of the menu.  Rename the pure virtual showContextMenu()
to createContextMenu() and have it only add the control-specific actions
to the menu.

Remove the "Hide" control action and MixDeviceWidget::setDisabled().
The action was only defined for a MDWEnum and was not accessible in the GUI.
The same effect can be achieved using "Configure Channels".
parent ba21e699
......@@ -48,10 +48,6 @@ MDWEnum::MDWEnum(shared_ptr<MixDevice> md, MixDeviceWidget::MDWFlags flags, View
_label(nullptr),
_enumCombo(nullptr)
{
KToggleAction *action = channelActions()->add<KToggleAction>("hide");
action->setText( i18n("&Hide") );
connect(action, SIGNAL(triggered(bool)), SLOT(setDisabled(bool)));
createWidgets();
createShortcutsAction();
}
......@@ -103,12 +99,10 @@ void MDWEnum::update()
}
}
void MDWEnum::showContextMenu(const QPoint& pos )
{
if (view()==nullptr) return;
QMenu *menu = view()->getPopup();
menu->popup(pos);
void MDWEnum::createContextMenu(QMenu *menu)
{
// nothing special for this sort of control
}
......@@ -154,11 +148,6 @@ int MDWEnum::enumId()
}
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).
......
......@@ -46,16 +46,15 @@ public:
void setLabelExtent(int extent) override;
public slots:
// GUI hide and show
void setDisabled(bool) override;
// Enum handling: next and selecting
void nextEnumId();
int enumId();
void setEnumId(int value);
void update() override;
void showContextMenu(const QPoint& pos = QCursor::pos()) override;
protected:
void createContextMenu(QMenu *menu) override;
private:
void createWidgets();
......
......@@ -102,13 +102,6 @@ void MDWSlider::createActions()
taction->setText( i18n("Split Channels") );
connect( taction, SIGNAL(triggered(bool)), SLOT(toggleStereoLinked()) );
// QAction *action;
// if ( ! mixDevice()->mixer()->isDynamic() ) {
// action = channelActions()->add<KToggleAction>( "hide" );
// action->setText( i18n("&Hide") );
// connect( action, SIGNAL(triggered(bool)), SLOT(setDisabled(bool)) );
// }
if( mixDevice()->hasMuteSwitch() )
{
taction = channelActions()->add<KToggleAction>( "mute" );
......@@ -960,12 +953,6 @@ void MDWSlider::setMuted(bool value)
}
void MDWSlider::setDisabled( bool hide )
{
emit guiVisibilityChange(this, !hide);
}
/**
* This slot is called on a Keyboard Shortcut event, except for the XF86Audio* shortcuts which are handled by the
* KMixWindow class. So for 99.9% of all users, this method is never called.
......@@ -1129,14 +1116,10 @@ void MDWSlider::updateAccesability()
#endif
void MDWSlider::showContextMenu(const QPoint &pos)
void MDWSlider::createContextMenu(QMenu *menu)
{
if (view()==nullptr) return;
QMenu *menu = view()->getPopup();
menu->addSection( QIcon::fromTheme( "kmix" ), mixDevice()->readableName() );
if (m_moveMenu) {
if (m_moveMenu!=nullptr)
{
MixSet *ms = mixDevice()->moveDestinationMixSet();
Q_ASSERT(ms!=nullptr);
......@@ -1150,7 +1133,8 @@ void MDWSlider::showContextMenu(const QPoint &pos)
menu->addMenu( m_moveMenu );
}
if ( m_slidersPlayback.count()>1 || m_slidersCapture.count()>1) {
if (m_slidersPlayback.count()>1 || m_slidersCapture.count()>1)
{
KToggleAction *stereo = qobject_cast<KToggleAction *>(channelActions()->action("stereo"));
if (stereo!=nullptr) {
QSignalBlocker blocker(stereo);
......@@ -1159,7 +1143,8 @@ void MDWSlider::showContextMenu(const QPoint &pos)
}
}
if ( mixDevice()->captureVolume().hasSwitch() ) {
if (mixDevice()->captureVolume().hasSwitch())
{
KToggleAction *ta = qobject_cast<KToggleAction *>(channelActions()->action("recsrc"));
if (ta!=nullptr) {
QSignalBlocker blocker(ta);
......@@ -1168,7 +1153,8 @@ void MDWSlider::showContextMenu(const QPoint &pos)
}
}
if ( mixDevice()->hasMuteSwitch() ) {
if (mixDevice()->hasMuteSwitch())
{
KToggleAction *ta = qobject_cast<KToggleAction *>(channelActions()->action("mute"));
if (ta!=nullptr) {
QSignalBlocker blocker(ta);
......@@ -1176,15 +1162,6 @@ void MDWSlider::showContextMenu(const QPoint &pos)
menu->addAction( ta );
}
}
QAction *b = channelActions()->action( "keys" );
if (b!=nullptr)
{
menu->addSeparator();
menu->addAction(b);
}
menu->popup(pos);
}
......
......@@ -80,14 +80,15 @@ public slots:
void toggleMuted();
void toggleStereoLinked();
void setDisabled( bool value ) override;
// void setDisabled( bool value ) override;
void update() override;
void showMoveMenu();
void showContextMenu( const QPoint &pos = QCursor::pos() ) override;
void increaseOrDecreaseVolume(bool arg1, Volume::VolumeTypeFlag volumeType);
VolumeSliderExtraData& extraData(QAbstractSlider *slider);
void addMediaControls(QBoxLayout* arg1);
protected:
void createContextMenu(QMenu *menu) override;
private slots:
void setRecsrc(bool value);
void setMuted(bool value);
......@@ -102,6 +103,7 @@ private slots:
void mediaNext(bool);
void mediaPrev(bool);
void showMoveMenu();
void moveStream(bool checked);
private:
......
......@@ -100,16 +100,27 @@ void MixDeviceWidget::configureShortcuts()
void MixDeviceWidget::contextMenuEvent(QContextMenuEvent *ev)
{
showContextMenu(ev->globalPos());
if (view()==nullptr) return;
QMenu *menu = view()->getPopup();
menu->addSection(QIcon::fromTheme("kmix"), mixDevice()->readableName());
createContextMenu(menu);
// the common "Channel Shortcuts" action
QAction *act = m_channelActions->action("keys");
if (act!=nullptr)
{
menu->addSeparator();
menu->addAction(act);
}
menu->popup(ev->globalPos());
}
void MixDeviceWidget::volumeChange( int ) { /* is virtual */ }
//void MixDeviceWidget::setDisabled( bool ) { /* is virtual */ }
//void MixDeviceWidget::setVolume( int /*channel*/, int /*vol*/ ) { /* is virtual */ }
//void MixDeviceWidget::setVolume( Volume /*vol*/ ) { /* is virtual */ }
//void MixDeviceWidget::update() { /* is virtual */ }
//void MixDeviceWidget::showContextMenu( const QPoint &pos ) { /* is virtual */ }
//void MixDeviceWidget::update() { /* is pure virtual */ }
//void MixDeviceWidget::createContextMenu(QMenu *menu) { /* is pure virtual */ }
void MixDeviceWidget::setColors( QColor , QColor , QColor ) { /* is virtual */ }
void MixDeviceWidget::setIcons( bool ) { /* is virtual */ }
void MixDeviceWidget::setLabeled( bool ) { /* is virtual */ }
......
......@@ -76,12 +76,10 @@ signals:
void guiVisibilityChange(MixDeviceWidget* source, bool enable);
protected slots:
virtual void showContextMenu(const QPoint &pos = QCursor::pos()) = 0;
virtual void setDisabled(bool value) = 0;
void volumeChange(int);
protected:
virtual void createContextMenu(QMenu *menu) = 0;
void contextMenuEvent(QContextMenuEvent *ev) override;
void createShortcutsAction();
......
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