Integrate preferences dialog into UI settings
These preferences are all about the UI so it makes sense to integrate them into the UI settings. This also reduces the amount of code a little bit as now certain aspects are handled by `QtUtilities::SettingsDialog`.
This commit is contained in:
parent
897b2486e1
commit
300adc5001
|
@ -24,7 +24,8 @@
|
|||
|
||||
*/
|
||||
|
||||
#include <QtWidgets>
|
||||
#include <QDir>
|
||||
#include <QFontInfo>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonValue>
|
||||
|
@ -34,20 +35,21 @@
|
|||
#include "GuiPreferencesDialog.h"
|
||||
#include "GlView.h"
|
||||
|
||||
GuiPreferencesDialog::GuiPreferencesDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
#include "ui_GuiPreferencesDialog.h"
|
||||
|
||||
GuiPreferencesOptionPage::GuiPreferencesOptionPage(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_settings(nullptr)
|
||||
, m_song(nullptr)
|
||||
, m_glView(nullptr)
|
||||
{
|
||||
setupUi(this);
|
||||
m_song = nullptr;
|
||||
m_settings = nullptr;
|
||||
m_glView = nullptr;
|
||||
setWindowTitle(tr("Preferences"));
|
||||
followStopPointCombo->addItem(tr("Automatic (Recommended)"));
|
||||
followStopPointCombo->addItem(tr("On the Beat"));
|
||||
followStopPointCombo->addItem(tr("After the Beat"));
|
||||
}
|
||||
|
||||
void GuiPreferencesDialog::initLanguageCombo(){
|
||||
GuiPreferencesOptionPage::~GuiPreferencesOptionPage()
|
||||
{
|
||||
}
|
||||
|
||||
void GuiPreferencesOptionPage::initLanguageCombo() {
|
||||
#ifndef NO_LANGS
|
||||
|
||||
// read langs.json
|
||||
|
@ -66,11 +68,11 @@ void GuiPreferencesDialog::initLanguageCombo(){
|
|||
|
||||
// load languages
|
||||
const auto rootLangs = document.object();
|
||||
languageCombo->clear();
|
||||
languageCombo->addItem(QString(QChar('<') % tr("System Language") % QChar('>')), QString());
|
||||
languageCombo->addItem(QStringLiteral("English"), QStringLiteral("en"));
|
||||
ui()->languageCombo->clear();
|
||||
ui()->languageCombo->addItem(QString(QChar('<') % tr("System Language") % QChar('>')), QString());
|
||||
ui()->languageCombo->addItem(QStringLiteral("English"), QStringLiteral("en"));
|
||||
if (m_settings->value(QStringLiteral("General/lang"), QString()).toString() == QLatin1String("en")){
|
||||
languageCombo->setCurrentIndex(languageCombo->count() - 1);
|
||||
ui()->languageCombo->setCurrentIndex(ui()->languageCombo->count() - 1);
|
||||
}
|
||||
|
||||
auto dirLang = QDir(localeDirectory);
|
||||
|
@ -107,9 +109,9 @@ void GuiPreferencesDialog::initLanguageCombo(){
|
|||
languageName=langCode;
|
||||
}
|
||||
|
||||
languageCombo->addItem(languageName,langCode);
|
||||
ui()->languageCombo->addItem(languageName, langCode);
|
||||
if (m_settings->value(QStringLiteral("General/lang"), QString()).toString() == langCode){
|
||||
languageCombo->setCurrentIndex(languageCombo->count() - 1);
|
||||
ui()->languageCombo->setCurrentIndex(ui()->languageCombo->count() - 1);
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
@ -120,39 +122,46 @@ void GuiPreferencesDialog::initLanguageCombo(){
|
|||
#endif
|
||||
}
|
||||
|
||||
void GuiPreferencesDialog::init(CSong* song, CSettings* settings, CGLView * glView)
|
||||
void GuiPreferencesOptionPage::init(CSong* song, CSettings* settings, CGLView * glView)
|
||||
{
|
||||
m_song = song;
|
||||
m_settings = settings;
|
||||
m_glView = glView;
|
||||
|
||||
timingMarkersCheck->setChecked(m_song->cfg_timingMarkersFlag);
|
||||
showNoteNamesCheck->setChecked(m_settings->isNoteNamesEnabled());
|
||||
courtesyAccidentalsCheck->setChecked(m_settings->displayCourtesyAccidentals());
|
||||
showTutorPagesCheck->setChecked(m_settings->isTutorPagesEnabled());
|
||||
followThroughErrorsCheck->setChecked(m_settings->isFollowThroughErrorsEnabled());
|
||||
showColoredNotesCheck->setChecked(m_settings->isColoredNotesEnabled());
|
||||
|
||||
followStopPointCombo->setCurrentIndex(m_song->cfg_stopPointMode);
|
||||
|
||||
initLanguageCombo();
|
||||
}
|
||||
|
||||
void GuiPreferencesDialog::accept()
|
||||
bool GuiPreferencesOptionPage::apply()
|
||||
{
|
||||
m_song->cfg_timingMarkersFlag = timingMarkersCheck->isChecked();
|
||||
m_song->cfg_timingMarkersFlag = ui()->timingMarkersCheck->isChecked();
|
||||
m_settings->setValue("Score/TimingMarkers", m_song->cfg_timingMarkersFlag );
|
||||
m_settings->setNoteNamesEnabled( showNoteNamesCheck->isChecked());
|
||||
m_settings->setCourtesyAccidentals( courtesyAccidentalsCheck->isChecked());
|
||||
m_settings->setTutorPagesEnabled( showTutorPagesCheck->isChecked());
|
||||
m_settings->setFollowThroughErrorsEnabled( followThroughErrorsCheck->isChecked());
|
||||
m_settings->setColoredNotes( showColoredNotesCheck->isChecked());
|
||||
m_song->cfg_stopPointMode = static_cast<stopPointMode_t> (followStopPointCombo->currentIndex());
|
||||
m_settings->setNoteNamesEnabled( ui()->showNoteNamesCheck->isChecked());
|
||||
m_settings->setCourtesyAccidentals( ui()->courtesyAccidentalsCheck->isChecked());
|
||||
m_settings->setTutorPagesEnabled( ui()->showTutorPagesCheck->isChecked());
|
||||
m_settings->setFollowThroughErrorsEnabled( ui()->followThroughErrorsCheck->isChecked());
|
||||
m_settings->setColoredNotes( ui()->showColoredNotesCheck->isChecked());
|
||||
m_song->cfg_stopPointMode = static_cast<stopPointMode_t>(ui()->followStopPointCombo->currentIndex());
|
||||
m_settings->setValue("Score/StopPointMode", m_song->cfg_stopPointMode );
|
||||
|
||||
m_settings->setValue("General/lang", languageCombo->currentData().toString());
|
||||
|
||||
m_settings->setValue("General/lang", ui()->languageCombo->currentData().toString());
|
||||
m_song->refreshScroll();
|
||||
|
||||
this->QDialog::accept();
|
||||
return true;
|
||||
}
|
||||
|
||||
void GuiPreferencesOptionPage::reset()
|
||||
{
|
||||
ui()->timingMarkersCheck->setChecked(m_song->cfg_timingMarkersFlag);
|
||||
ui()->showNoteNamesCheck->setChecked(m_settings->isNoteNamesEnabled());
|
||||
ui()->courtesyAccidentalsCheck->setChecked(m_settings->displayCourtesyAccidentals());
|
||||
ui()->showTutorPagesCheck->setChecked(m_settings->isTutorPagesEnabled());
|
||||
ui()->followThroughErrorsCheck->setChecked(m_settings->isFollowThroughErrorsEnabled());
|
||||
ui()->showColoredNotesCheck->setChecked(m_settings->isColoredNotesEnabled());
|
||||
ui()->followStopPointCombo->setCurrentIndex(m_song->cfg_stopPointMode);
|
||||
}
|
||||
|
||||
QWidget *GuiPreferencesOptionPage::setupWidget()
|
||||
{
|
||||
auto *widget = GuiPreferencesOptionPageBase::setupWidget();
|
||||
ui()->followStopPointCombo->addItem(tr("Automatic (Recommended)"));
|
||||
ui()->followStopPointCombo->addItem(tr("On the Beat"));
|
||||
ui()->followStopPointCombo->addItem(tr("After the Beat"));
|
||||
initLanguageCombo();
|
||||
return widget;
|
||||
}
|
||||
|
|
|
@ -29,26 +29,28 @@
|
|||
#ifndef __GUIPREFERENCESDIALOG_H__
|
||||
#define __GUIPREFERENCESDIALOG_H__
|
||||
|
||||
#include <QtWidgets>
|
||||
#include <qtutilities/settingsdialog/optionpage.h>
|
||||
|
||||
#include "Song.h"
|
||||
#include "Settings.h"
|
||||
|
||||
#include "ui_GuiPreferencesDialog.h"
|
||||
|
||||
class CGLView;
|
||||
|
||||
class GuiPreferencesDialog : public QDialog, private Ui::GuiPreferencesDialog
|
||||
{
|
||||
class Ui_GuiPreferencesDialog;
|
||||
|
||||
using GuiPreferencesOptionPageBase = ::QtUtilities::UiFileBasedOptionPage<Ui_GuiPreferencesDialog>;
|
||||
class GuiPreferencesOptionPage : public QObject, public GuiPreferencesOptionPageBase {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GuiPreferencesDialog(QWidget *parent = 0);
|
||||
|
||||
explicit GuiPreferencesOptionPage(QObject *parent = nullptr);
|
||||
~GuiPreferencesOptionPage();
|
||||
void init(CSong* song, CSettings* settings, CGLView* glView);
|
||||
bool apply() override;
|
||||
void reset() override;
|
||||
|
||||
private slots:
|
||||
void accept();
|
||||
protected: \
|
||||
QWidget *setupWidget() override;
|
||||
|
||||
private:
|
||||
void initLanguageCombo();
|
||||
|
|
|
@ -1,15 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>GuiPreferencesDialog</class>
|
||||
<widget class="QDialog" name="GuiPreferencesDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>411</width>
|
||||
<height>419</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QWidget" name="GuiPreferencesDialog">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
|
@ -17,7 +9,10 @@
|
|||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
<string>Preferences</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset theme="preferences-other"/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
|
@ -211,51 +206,8 @@
|
|||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>GuiPreferencesDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>257</x>
|
||||
<y>385</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>GuiPreferencesDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>325</x>
|
||||
<y>385</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
@ -378,11 +378,6 @@ void QtWindow::createActions()
|
|||
}
|
||||
connect(m_viewPianoKeyboard, SIGNAL(triggered()), this, SLOT(onViewPianoKeyboard()));
|
||||
|
||||
m_setupPreferencesAct = new QAction(tr("&Preferences ..."), this);
|
||||
m_setupPreferencesAct->setToolTip(tr("Settings"));
|
||||
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"));
|
||||
|
@ -468,7 +463,6 @@ void QtWindow::createMenus()
|
|||
m_setupMenu->setToolTipsVisible(true);
|
||||
m_setupMenu->addAction(m_setupMidiAct);
|
||||
m_setupMenu->addAction(m_setupKeyboardAct);
|
||||
m_setupMenu->addAction(m_setupPreferencesAct);
|
||||
if (m_qtSettings) {
|
||||
m_setupMenu->addAction(m_setupUISettingsAct);
|
||||
}
|
||||
|
@ -523,19 +517,24 @@ void QtWindow::showMidiSetup(){
|
|||
void QtWindow::showUISettingsDialog()
|
||||
{
|
||||
if (!m_settingsDlg) {
|
||||
m_settingsDlg = new QtUtilities::SettingsDialog(this);
|
||||
if (m_qtSettings) {
|
||||
m_settingsDlg->setWindowTitle(tr("UI settings"));
|
||||
auto *const category = new QtUtilities::OptionCategory;
|
||||
category->setDisplayName(QCoreApplication::translate("QtGui::QtOptionCategory", "UI settings"));
|
||||
category->assignPages({ new QtUtilities::QtAppearanceOptionPage(*m_qtSettings) });
|
||||
m_settingsDlg->setSingleCategory(category);
|
||||
connect(m_settingsDlg, &QtUtilities::SettingsDialog::applied, this, [this] {
|
||||
m_settingsDlg = new QtUtilities::SettingsDialog(this);
|
||||
m_settingsDlg->setWindowTitle(tr("UI settings"));
|
||||
auto *const category = new QtUtilities::OptionCategory;
|
||||
auto *const preferencesPage = new GuiPreferencesOptionPage;
|
||||
preferencesPage->init(m_song, m_settings, m_glWidget);
|
||||
auto pages = QList<QtUtilities::OptionPage *>({preferencesPage});
|
||||
if (m_qtSettings) {
|
||||
pages << new QtUtilities::QtAppearanceOptionPage(*m_qtSettings);
|
||||
}
|
||||
category->assignPages(pages);
|
||||
m_settingsDlg->setSingleCategory(category);
|
||||
connect(m_settingsDlg, &QtUtilities::SettingsDialog::applied, this, [this] {
|
||||
if (m_qtSettings) {
|
||||
m_qtSettings->apply();
|
||||
m_qtSettings->save(*m_settings);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
refreshTranslate();
|
||||
});
|
||||
}
|
||||
if (m_settingsDlg->isHidden()) {
|
||||
m_settingsDlg->showNormal();
|
||||
|
@ -871,6 +870,5 @@ void QtWindow::refreshTranslate() {
|
|||
m_topBar->updateTranslate();
|
||||
m_settings->updateWarningMessages();
|
||||
m_settings->updateTutorPage();
|
||||
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -93,16 +93,6 @@ private slots:
|
|||
|
||||
void showMidiSetup();
|
||||
|
||||
void showPreferencesDialog()
|
||||
{
|
||||
GuiPreferencesDialog preferencesDialog(this);
|
||||
preferencesDialog.init(m_song, m_settings, m_glWidget);
|
||||
preferencesDialog.exec();
|
||||
|
||||
refreshTranslate();
|
||||
m_score->refreshScroll();
|
||||
}
|
||||
|
||||
void showSongDetailsDialog()
|
||||
{
|
||||
GuiSongDetailsDialog songDetailsDialog(this);
|
||||
|
@ -221,7 +211,6 @@ private:
|
|||
QAction *m_sidePanelStateAct;
|
||||
QAction *m_viewPianoKeyboard;
|
||||
QAction *m_fullScreenStateAct;
|
||||
QAction *m_setupPreferencesAct;
|
||||
QAction *m_setupUISettingsAct;
|
||||
QAction *m_songDetailsAct;
|
||||
|
||||
|
|
Loading…
Reference in New Issue