diff --git a/src/blackgui/components/settingsguicomponent.cpp b/src/blackgui/components/settingsguicomponent.cpp index 54f087779..4b47dceb7 100644 --- a/src/blackgui/components/settingsguicomponent.cpp +++ b/src/blackgui/components/settingsguicomponent.cpp @@ -17,6 +17,7 @@ #include using namespace BlackMisc; +using namespace BlackGui::Settings; namespace BlackGui { @@ -38,21 +39,27 @@ namespace BlackGui ui->cb_SettingsGuiFont->setCurrentFont(font); ui->cb_SettingsGuiFontSize->setCurrentText(QString::number(font.pointSize())); ui->le_SettingsGuiFontColor->setText(this->m_fontColor.name()); + + connect(ui->tb_SettingsGuiFontColor, &QToolButton::clicked, this, &CSettingsGuiComponent::ps_fontColorDialog); bool connected = this->connect(ui->cb_SettingsGuiFont, SIGNAL(currentFontChanged(QFont)), this, SLOT(ps_fontChanged())); Q_ASSERT(connected); - this->connect(ui->tb_SettingsGuiFontColor, &QToolButton::clicked, this, &CSettingsGuiComponent::ps_fontColorDialog); - connected = this->connect(ui->cb_SettingsGuiFontSize, SIGNAL(currentIndexChanged(QString)), this, SLOT(ps_fontChanged())); + connected = connect(ui->cb_SettingsGuiFontSize, SIGNAL(currentIndexChanged(QString)), this, SLOT(ps_fontChanged())); Q_ASSERT(connected); - connected = this->connect(ui->cb_SettingsGuiFontStyle, SIGNAL(currentIndexChanged(QString)), this, SLOT(ps_fontChanged())); + connected = connect(ui->cb_SettingsGuiFontStyle, SIGNAL(currentIndexChanged(QString)), this, SLOT(ps_fontChanged())); Q_ASSERT(connected); // Widget style and rest - this->connect(ui->hs_SettingsGuiOpacity, &QSlider::valueChanged, this, &CSettingsGuiComponent::changedWindowsOpacity); - this->connect(ui->cb_SettingsGuiWidgetStyle, static_cast(&QComboBox::currentIndexChanged), - this, &CSettingsGuiComponent::widgetStyleChanged); - this->connect(ui->tb_ResetFont, &QToolButton::pressed, this, &CSettingsGuiComponent::ps_resetFont); + connect(ui->hs_SettingsGuiOpacity, &QSlider::valueChanged, this, &CSettingsGuiComponent::changedWindowsOpacity); + connect(ui->cb_SettingsGuiWidgetStyle, static_cast(&QComboBox::currentIndexChanged), + this, &CSettingsGuiComponent::widgetStyleChanged); + connect(ui->tb_ResetFont, &QToolButton::pressed, this, &CSettingsGuiComponent::ps_resetFont); + + // selection + connect(ui->rb_PreferExtendedSelection, &QRadioButton::released, this, &CSettingsGuiComponent::ps_selectionChanged); + connect(ui->rb_PreferMultiSelection, &QRadioButton::released, this, &CSettingsGuiComponent::ps_selectionChanged); + + this->guiSettingsChanged(); Q_UNUSED(connected); - this->reloadWidgetStyleFromSettings(); } CSettingsGuiComponent::~CSettingsGuiComponent() @@ -80,7 +87,7 @@ namespace BlackGui fontColor = sGui->getStyleSheetUtility().fontColor(); } ui->le_SettingsGuiFontColor->setText(fontColor); - bool ok = sGui->updateFont(fontFamily, fontSize, CStyleSheetUtility::fontStyle(fontStyleCombined), CStyleSheetUtility::fontWeight(fontStyleCombined), fontColor); + const bool ok = sGui->updateFont(fontFamily, fontSize, CStyleSheetUtility::fontStyle(fontStyleCombined), CStyleSheetUtility::fontWeight(fontStyleCombined), fontColor); if (ok) { CLogMessage(this).info("Updated font style"); @@ -105,20 +112,45 @@ namespace BlackGui sGui->resetFont(); } - void CSettingsGuiComponent::reloadWidgetStyleFromSettings() + void CSettingsGuiComponent::ps_selectionChanged() { - int index = ui->cb_SettingsGuiWidgetStyle->findText(m_settingsWidgetStyle.get()); - ui->cb_SettingsGuiWidgetStyle->setCurrentIndex(index); + QAbstractItemView::SelectionMode sm = QAbstractItemView::NoSelection; + if (ui->rb_PreferExtendedSelection->isChecked()) + { + sm = QAbstractItemView::ExtendedSelection; + } + else if (ui->rb_PreferMultiSelection->isChecked()) + { + sm = QAbstractItemView::MultiSelection; + } + if (sm == this->m_guiSettings.get().getPreferredSelection()) { return; } + const CStatusMessage m = this->m_guiSettings.setAndSaveProperty(CGeneralGuiSettings::IndexPreferredSelection, CVariant::fromValue(sm)); + CLogMessage::preformatted(m); + } + + void CSettingsGuiComponent::guiSettingsChanged() + { + const CGeneralGuiSettings settings(m_guiSettings.getThreadLocal()); + const int index = ui->cb_SettingsGuiWidgetStyle->findText(settings.getWidgetStyle()); + if (index != ui->cb_SettingsGuiWidgetStyle->currentIndex()) + { + ui->cb_SettingsGuiWidgetStyle->setCurrentIndex(index); + } + + switch (settings.getPreferredSelection()) + { + case QAbstractItemView::ExtendedSelection: ui->rb_PreferExtendedSelection->setChecked(true); break; + case QAbstractItemView::MultiSelection: ui->rb_PreferMultiSelection->setChecked(true); break; + default: break; + } } void CSettingsGuiComponent::widgetStyleChanged(const QString &widgetStyle) { - if (widgetStyle == m_settingsWidgetStyle.get()) { return; } - auto availableStyles = QStyleFactory::keys(); - if (availableStyles.contains(widgetStyle)) - { - m_settingsWidgetStyle.set(widgetStyle); - } + const CGeneralGuiSettings settings = m_guiSettings.getThreadLocal(); + if (!settings.isDifferentValidWidgetStyle(widgetStyle)) { return; } + const CStatusMessage m = this->m_guiSettings.setAndSaveProperty(CGeneralGuiSettings::IndexWidgetStyle, widgetStyle); + CLogMessage::preformatted(m); } } // ns } // ns diff --git a/src/blackgui/components/settingsguicomponent.h b/src/blackgui/components/settingsguicomponent.h index 491ede093..5d25b2fb8 100644 --- a/src/blackgui/components/settingsguicomponent.h +++ b/src/blackgui/components/settingsguicomponent.h @@ -56,13 +56,19 @@ namespace BlackGui //! Reset font void ps_resetFont(); + //! Selection radio buttons changed + void ps_selectionChanged(); + private: + //! GUI settings changed + void guiSettingsChanged(); + + //! Widget style has changed + void widgetStyleChanged(const QString &widgetStyle); + QScopedPointer ui; QColor m_fontColor; - - void reloadWidgetStyleFromSettings(); - void widgetStyleChanged(const QString &widgetStyle); - BlackMisc::CSetting m_settingsWidgetStyle { this, &CSettingsGuiComponent::reloadWidgetStyleFromSettings }; + BlackMisc::CSetting m_guiSettings { this, &CSettingsGuiComponent::guiSettingsChanged }; }; } // ns } // ns diff --git a/src/blackgui/components/settingsguicomponent.ui b/src/blackgui/components/settingsguicomponent.ui index ba29ecb62..df3085235 100644 --- a/src/blackgui/components/settingsguicomponent.ui +++ b/src/blackgui/components/settingsguicomponent.ui @@ -6,12 +6,12 @@ 0 0 - 223 - 245 + 233 + 248 - Frame + GUI general settings QFrame::StyledPanel @@ -210,10 +210,25 @@ General + + 3 + + + 3 + + + 3 + + + 3 + + + 0-100% + - Opacity (0-100%) + Opacity @@ -225,6 +240,9 @@ 0 + + 0-100% + 100 @@ -242,13 +260,55 @@ - Widget Style + Widget style + + + + Selection + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Extended + + + + + + + Multi + + + true + + + + + + diff --git a/src/blackgui/guiapplication.cpp b/src/blackgui/guiapplication.cpp index 5eebd60c9..ad397349e 100644 --- a/src/blackgui/guiapplication.cpp +++ b/src/blackgui/guiapplication.cpp @@ -499,7 +499,7 @@ namespace BlackGui QDialog::DialogCode CGuiApplication::showCloseDialog(QMainWindow *mainWindow, QCloseEvent *closeEvent) { - bool needsDialog = this->hasUnsavedSettings(); + const bool needsDialog = this->hasUnsavedSettings(); if (!needsDialog) { return QDialog::Accepted; } if (!this->m_closeDialog) { @@ -550,13 +550,18 @@ namespace BlackGui return true; } - void CGuiApplication::reloadWidgetStyleFromSettings() + void CGuiApplication::settingsChanged() { - auto widgetStyle = m_settingsWidgetStyle.get(); - auto availableStyles = QStyleFactory::keys(); - if (availableStyles.contains(widgetStyle)) + // changing widget style is slow, so I try to prevent setting it when nothing changed + const QString widgetStyle = m_guiSettings.get().getWidgetStyle(); + const QString currentWidgetStyle(QApplication::style()->metaObject()->className()); + if (!currentWidgetStyle.contains(widgetStyle, Qt::CaseInsensitive)) { - QApplication::setStyle(QStyleFactory::create(widgetStyle)); + const auto availableStyles = QStyleFactory::keys(); + if (availableStyles.contains(widgetStyle)) + { + QApplication::setStyle(QStyleFactory::create(widgetStyle)); + } } } } // ns diff --git a/src/blackgui/guiapplication.h b/src/blackgui/guiapplication.h index c91ccd8a2..ff01c9c85 100644 --- a/src/blackgui/guiapplication.h +++ b/src/blackgui/guiapplication.h @@ -196,14 +196,13 @@ namespace BlackGui bool m_uiSetupCompleted = false; //!< ui setup completed QScopedPointer m_splashScreen; //!< splash screen BlackGui::Components::CApplicationCloseDialog *m_closeDialog = nullptr; //!< close dialog (no QScopedPointer because I need to set parent) - - BlackMisc::CSettingReadOnly m_settingsWidgetStyle{ this, &CGuiApplication::reloadWidgetStyleFromSettings }; + BlackMisc::CSettingReadOnly m_guiSettings{ this, &CGuiApplication::settingsChanged }; //! Qt help message to formatted HTML static QString beautifyHelpMessage(const QString &helpText); //! Reload widget style from settings - void reloadWidgetStyleFromSettings(); + void settingsChanged(); }; } // ns