Add UI settings via Qt Utilities
It is likely best to apply these settings before instantiating the main window. So this change moves out the instantiation of settings objects to the main function.
This commit is contained in:
parent
eb0111dd7b
commit
1648807059
|
@ -28,6 +28,7 @@
|
|||
#include <cstdlib>
|
||||
|
||||
#include "QtWindow.h"
|
||||
#include "Settings.h"
|
||||
#include "resources/config.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
@ -35,8 +36,10 @@ int main(int argc, char *argv[]) {
|
|||
SET_QT_APPLICATION_INFO;
|
||||
QGuiApplication::setDesktopFileName(QStringLiteral(PROJECT_NAME));
|
||||
auto app = QApplication(argc, argv);
|
||||
auto settings = CSettings();
|
||||
auto qtSettings = QtUtilities::QtSettings();
|
||||
qtSettings.disableNotices();
|
||||
qtSettings.restore(settings);
|
||||
qtSettings.apply();
|
||||
|
||||
// print version
|
||||
|
@ -49,9 +52,10 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
// show main window and execute app
|
||||
auto window = QtWindow();
|
||||
auto window = QtWindow(&settings, &qtSettings);
|
||||
window.show();
|
||||
const auto ret = app.exec();
|
||||
settings.writeSettings();
|
||||
closeLogs();
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,10 @@
|
|||
#include "QtWindow.h"
|
||||
#include "resources/config.h"
|
||||
|
||||
#include <qtutilities/settingsdialog/optioncategorymodel.h>
|
||||
#include <qtutilities/settingsdialog/qtsettings.h>
|
||||
#include <qtutilities/settingsdialog/settingsdialog.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QSurfaceFormat>
|
||||
#include <QStringBuilder>
|
||||
|
@ -56,9 +60,12 @@ static int set_realtime_priority(int policy, int prio)
|
|||
}
|
||||
#endif
|
||||
|
||||
QtWindow::QtWindow()
|
||||
QtWindow::QtWindow(CSettings *settings, QtUtilities::QtSettings *qtSettings, QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, m_settings(settings)
|
||||
, m_qtSettings(qtSettings)
|
||||
, m_settingsDlg(nullptr)
|
||||
{
|
||||
m_settings = new CSettings(this);
|
||||
setWindowIcon(QIcon(":/images/pianobooster.png"));
|
||||
setWindowTitle(tr("Piano Booster"));
|
||||
|
||||
|
@ -104,7 +111,7 @@ QtWindow::QtWindow()
|
|||
m_tutorWindow = new QTextBrowser(this);
|
||||
m_tutorWindow->hide();
|
||||
|
||||
m_settings->init(m_song, m_sidePanel, m_topBar);
|
||||
m_settings->init(this, m_song, m_sidePanel, m_topBar);
|
||||
|
||||
mainLayout->addWidget(m_sidePanel);
|
||||
columnLayout->addWidget(m_topBar);
|
||||
|
@ -159,7 +166,6 @@ void QtWindow::init()
|
|||
|
||||
QtWindow::~QtWindow()
|
||||
{
|
||||
delete m_settings;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -375,6 +381,11 @@ void QtWindow::createActions()
|
|||
m_setupPreferencesAct->setShortcut(tr("Ctrl+P"));
|
||||
connect(m_setupPreferencesAct, SIGNAL(triggered()), this, SLOT(showPreferencesDialog()));
|
||||
|
||||
m_setupUISettingsAct = new QAction(tr("&UI settings ..."), this);
|
||||
m_setupUISettingsAct->setToolTip(tr("UI-related settings"));
|
||||
m_setupUISettingsAct->setShortcut(tr("Ctrl+U"));
|
||||
connect(m_setupUISettingsAct, &QAction::triggered, this, &QtWindow::showUISettingsDialog);
|
||||
|
||||
m_songDetailsAct = new QAction(tr("Song &Details ..."), this);
|
||||
m_songDetailsAct->setToolTip(tr("Song Settings"));
|
||||
m_songDetailsAct->setShortcut(tr("Ctrl+D"));
|
||||
|
@ -454,6 +465,9 @@ void QtWindow::createMenus()
|
|||
m_setupMenu->addAction(m_setupMidiAct);
|
||||
m_setupMenu->addAction(m_setupKeyboardAct);
|
||||
m_setupMenu->addAction(m_setupPreferencesAct);
|
||||
if (m_qtSettings) {
|
||||
m_setupMenu->addAction(m_setupUISettingsAct);
|
||||
}
|
||||
|
||||
m_helpMenu = menuBar()->addMenu(tr("&Help"));
|
||||
m_helpMenu->setToolTipsVisible(true);
|
||||
|
@ -500,6 +514,26 @@ void QtWindow::showMidiSetup(){
|
|||
m_glWidget->startTimerEvent();
|
||||
}
|
||||
|
||||
void QtWindow::showUISettingsDialog()
|
||||
{
|
||||
if (!m_settingsDlg) {
|
||||
m_settingsDlg = new QtUtilities::SettingsDialog(this);
|
||||
if (m_qtSettings) {
|
||||
m_settingsDlg->setWindowTitle(tr("UI settings"));
|
||||
m_settingsDlg->setSingleCategory(m_qtSettings->category());
|
||||
connect(m_settingsDlg, &QtUtilities::SettingsDialog::applied, this, [this] {
|
||||
m_qtSettings->apply();
|
||||
m_qtSettings->save(*m_settings);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (m_settingsDlg->isHidden()) {
|
||||
m_settingsDlg->showNormal();
|
||||
} else {
|
||||
m_settingsDlg->activateWindow();
|
||||
}
|
||||
}
|
||||
|
||||
// load the recent file list from the config file into the file menu
|
||||
void QtWindow::updateRecentFileActions()
|
||||
{
|
||||
|
@ -695,7 +729,6 @@ void QtWindow::writeSettings()
|
|||
{
|
||||
m_settings->setValue("Window/Pos", pos());
|
||||
m_settings->setValue("Window/Size", size());
|
||||
m_settings->writeSettings();
|
||||
}
|
||||
|
||||
void QtWindow::closeEvent(QCloseEvent *event)
|
||||
|
|
|
@ -50,12 +50,17 @@ class QTextBrowser;
|
|||
|
||||
static constexpr int maxRecentFiles() { return 20; }
|
||||
|
||||
namespace QtUtilities {
|
||||
class SettingsDialog;
|
||||
class QtSettings;
|
||||
} // namespace QtUtilities
|
||||
|
||||
class QtWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtWindow();
|
||||
QtWindow(CSettings* settings, QtUtilities::QtSettings *qtSettings = nullptr, QWidget *parent = nullptr);
|
||||
~QtWindow();
|
||||
|
||||
void init();
|
||||
|
@ -112,6 +117,8 @@ private slots:
|
|||
keyboardSetup.exec();
|
||||
}
|
||||
|
||||
void showUISettingsDialog();
|
||||
|
||||
void toggleSidePanel()
|
||||
{
|
||||
m_sidePanel->setVisible(m_sidePanelStateAct->isChecked());
|
||||
|
@ -193,6 +200,8 @@ private:
|
|||
void writeSettings();
|
||||
|
||||
CSettings* m_settings;
|
||||
QtUtilities::QtSettings *m_qtSettings;
|
||||
QtUtilities::SettingsDialog *m_settingsDlg;
|
||||
|
||||
GuiSidePanel *m_sidePanel;
|
||||
GuiTopBar *m_topBar;
|
||||
|
@ -217,6 +226,7 @@ private:
|
|||
QAction *m_viewPianoKeyboard;
|
||||
QAction *m_fullScreenStateAct;
|
||||
QAction *m_setupPreferencesAct;
|
||||
QAction *m_setupUISettingsAct;
|
||||
QAction *m_songDetailsAct;
|
||||
|
||||
QMenu *m_fileMenu;
|
||||
|
|
|
@ -61,11 +61,10 @@
|
|||
#define debugSettings(args)
|
||||
#endif
|
||||
|
||||
CSettings::CSettings(QtWindow *mainWindow) : QSettings(CSettings::IniFormat, CSettings::UserScope, "PianoBooster", "Piano Booster"),
|
||||
m_mainWindow(mainWindow)
|
||||
CSettings::CSettings()
|
||||
: QSettings(CSettings::IniFormat, CSettings::UserScope, "PianoBooster", "Piano Booster")
|
||||
, m_mainWindow(nullptr)
|
||||
{
|
||||
// It is all done in the initialisation list
|
||||
|
||||
m_advancedMode = false;
|
||||
m_pianistActive = false;
|
||||
m_noteNamesEnabled = value("Score/NoteNames", true ).toBool();
|
||||
|
@ -86,8 +85,9 @@ void CSettings::setDefaultValue(const QString & key, const QVariant & value )
|
|||
setValue(key, value);
|
||||
}
|
||||
|
||||
void CSettings::init(CSong* song, GuiSidePanel* sidePanel, GuiTopBar* topBar)
|
||||
void CSettings::init(QtWindow *mainWindow, CSong* song, GuiSidePanel* sidePanel, GuiTopBar* topBar)
|
||||
{
|
||||
m_mainWindow = mainWindow;
|
||||
m_song = song;
|
||||
m_guiSidePanel = sidePanel;
|
||||
m_guiTopBar = topBar;
|
||||
|
@ -272,6 +272,9 @@ void CSettings::saveXmlFile()
|
|||
|
||||
void CSettings::updateTutorPage()
|
||||
{
|
||||
if (!m_mainWindow) {
|
||||
return;
|
||||
}
|
||||
QFileInfo fileInfo(getCurrentSongLongFileName());
|
||||
const char* EXTN = ".html";
|
||||
|
||||
|
@ -413,7 +416,7 @@ void CSettings::unzipBoosterMusicBooks()
|
|||
// Set default value
|
||||
const QString ZIPFILENAME("BoosterMusicBooks.zip");
|
||||
|
||||
if (value("PianoBooster/MusicRelease", 0).toInt() < MUSIC_RELEASE)
|
||||
if (m_mainWindow && value("PianoBooster/MusicRelease", 0).toInt() < MUSIC_RELEASE)
|
||||
{
|
||||
QString musicSrcDir = QApplication::applicationDirPath() + "/";
|
||||
|
||||
|
@ -501,8 +504,10 @@ void CSettings::setCurrentSongName(const QString & name)
|
|||
|
||||
m_guiSidePanel->refresh();
|
||||
m_guiTopBar->refresh(true);
|
||||
m_mainWindow->setWindowTitle("Piano Booster - " + m_song->getSongTitle());
|
||||
updateTutorPage();
|
||||
if (m_mainWindow) {
|
||||
m_mainWindow->setWindowTitle("Piano Booster - " + m_song->getSongTitle());
|
||||
updateTutorPage();
|
||||
}
|
||||
}
|
||||
|
||||
void CSettings::setCurrentBookName(const QString & name, bool clearSongName)
|
||||
|
|
|
@ -43,9 +43,9 @@ class CSettings : public QSettings
|
|||
{
|
||||
|
||||
public:
|
||||
CSettings(QtWindow *mainWindow);
|
||||
explicit CSettings();
|
||||
|
||||
void init(CSong* song, GuiSidePanel* sidePanel, GuiTopBar* topBar);
|
||||
void init(QtWindow *mainWindow, CSong* song, GuiSidePanel* sidePanel, GuiTopBar* topBar);
|
||||
|
||||
/// returns true if the user wants to see the note names
|
||||
bool isNoteNamesEnabled() { return m_noteNamesEnabled; }
|
||||
|
@ -193,7 +193,6 @@ private:
|
|||
QDomElement m_domHand; // The saved settings for each hand
|
||||
|
||||
QtWindow *m_mainWindow;
|
||||
|
||||
CSong* m_song;
|
||||
GuiSidePanel* m_guiSidePanel;
|
||||
GuiTopBar* m_guiTopBar;
|
||||
|
|
Loading…
Reference in New Issue