Commit 91568edc authored by Jonathan Marten's avatar Jonathan Marten
Browse files

Preferences dialogue: Simplify creation and showing

There is no need for the separate createInstance() and getInstance().
However, it does need to be created at initialisation time so that the
signal can be connected.
parent 1ead0478
......@@ -266,9 +266,11 @@ void KMixWindow::initActionsAfterInitMixer()
}
// This needs to done on initialisation, so that the
// signal can be connected.
void KMixWindow::initPrefDlg()
{
KMixPrefDlg *prefDlg = KMixPrefDlg::createInstance(this);
KMixPrefDlg *prefDlg = KMixPrefDlg::instance(this);
connect(prefDlg, &KMixPrefDlg::kmixConfigHasChanged, this, &KMixWindow::applyPrefs);
}
......@@ -1092,11 +1094,11 @@ void KMixWindow::quit()
}
/**
* Shows the configuration dialog, with the "general" tab opened.
* Shows the configuration dialog, with the "General" tab opened.
*/
void KMixWindow::showSettings()
{
KMixPrefDlg::getInstance()->switchToPage(KMixPrefDlg::PrefGeneral);
KMixPrefDlg::instance()->showAtPage(KMixPrefDlg::PageGeneral);
}
......
......@@ -38,26 +38,15 @@
#include "dialogstatesaver.h"
#include "gui/kmixerwidget.h"
#include "gui/dialogchoosebackends.h"
#include "settings.h"
KMixPrefDlg* KMixPrefDlg::instance = 0;
KMixPrefDlg* KMixPrefDlg::getInstance()
/* static */ KMixPrefDlg *KMixPrefDlg::instance(QWidget *parent)
{
return instance;
KMixPrefDlg *sInstance = new KMixPrefDlg(parent);
return (sInstance);
}
KMixPrefDlg* KMixPrefDlg::createInstance(QWidget *parent)
{
if (instance == 0)
{
instance = new KMixPrefDlg(parent);
}
return instance;
}
KMixPrefDlg::KMixPrefDlg(QWidget *parent)
: KConfigDialog(parent, i18n("Configure"), Settings::self())
......@@ -66,45 +55,41 @@ KMixPrefDlg::KMixPrefDlg(QWidget *parent)
dvc = nullptr;
// general buttons
m_generalTab = new QFrame(this);
m_controlsTab = new QFrame(this);
m_startupTab = new QFrame(this);
createStartupTab();
m_generalTab = new QFrame(this);
createGeneralTab();
m_controlsTab = new QFrame(this);
createControlsTab();
updateWidgets(); // I thought KConfigDialog would call this, but I saw during a gdb session that it does not do so.
generalPage = addPage(m_generalTab, i18n("General"), "configure");
startupPage = addPage(m_startupTab, i18n("Startup"), "preferences-system-login");
soundmenuPage = addPage(m_controlsTab, i18n("Volume Control"), "audio-volume-high");
m_generalPage = addPage(m_generalTab, i18n("General"), "configure");
m_startupPage = addPage(m_startupTab, i18n("Startup"), "preferences-system-login");
m_soundmenuPage = addPage(m_controlsTab, i18n("Volume Control"), "audio-volume-high");
new DialogStateSaver(this);
new DialogStateSaver(this); // save dialogue size when closed
}
/**
* Switches to a specific page and shows it.
* @param page
*/
void KMixPrefDlg::switchToPage(KMixPrefPage page)
void KMixPrefDlg::showAtPage(KMixPrefDlg::PrefPage page)
{
switch (page)
{
case PrefGeneral:
setCurrentPage(generalPage);
case PageGeneral:
setCurrentPage(m_generalPage);
break;
case PrefSoundMenu:
setCurrentPage(soundmenuPage);
case PageStartup:
setCurrentPage(m_startupPage);
break;
case PrefStartup:
setCurrentPage(startupPage);
case PageVolumeControl:
setCurrentPage(m_soundmenuPage);
break;
default:
qCWarning(KMIX_LOG) << "Tried to activated unknown preferences page" << page;
qCWarning(KMIX_LOG) << "Unknown preferences page" << page;
break;
}
show();
show(); // show with the selected page
}
......
......@@ -44,9 +44,11 @@ class KMixPrefDlg: public KConfigDialog
Q_OBJECT
public:
enum KMixPrefPage
enum PrefPage
{
PrefGeneral, PrefSoundMenu, PrefStartup
PageGeneral,
PageStartup,
PageVolumeControl
};
enum PrefChanged
......@@ -59,15 +61,14 @@ public:
};
Q_DECLARE_FLAGS(PrefChanges, PrefChanged);
static KMixPrefDlg* createInstance(QWidget *parent);
static KMixPrefDlg* getInstance();
void switchToPage(KMixPrefPage page);
static KMixPrefDlg *instance(QWidget *parent = nullptr);
void showAtPage(KMixPrefDlg::PrefPage page);
signals:
void kmixConfigHasChanged(KMixPrefDlg::PrefChanges changed);
protected:
void showEvent(QShowEvent * event) override;
void showEvent(QShowEvent *event) override;
/**
* Orientation is not supported by default => implement manually
* @Override
......@@ -85,9 +86,7 @@ private slots:
void settingChanged(KMixPrefDlg::PrefChanged changes = KMixPrefDlg::ChangedAny);
private:
static KMixPrefDlg* instance;
KMixPrefDlg(QWidget *parent);
explicit KMixPrefDlg(QWidget *parent = nullptr);
virtual ~KMixPrefDlg() = default;
enum KMixPrefDlgPrefOrientationType
......@@ -133,9 +132,9 @@ private:
QRadioButton *_rbTraypopupVertical;
QRadioButton *_rbTraypopupHorizontal;
KPageWidgetItem* generalPage;
KPageWidgetItem* soundmenuPage;
KPageWidgetItem* startupPage;
KPageWidgetItem *m_generalPage;
KPageWidgetItem *m_soundmenuPage;
KPageWidgetItem *m_startupPage;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(KMixPrefDlg::PrefChanges)
......
......@@ -491,8 +491,7 @@ void ViewDockAreaPopup::refreshVolumeLevels()
void ViewDockAreaPopup::configureView()
{
KMixPrefDlg *prefDlg = KMixPrefDlg::getInstance();
prefDlg->switchToPage(KMixPrefDlg::PrefSoundMenu);
KMixPrefDlg::instance()->showAtPage(KMixPrefDlg::PageVolumeControl);
}
......
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