refs #830, UI for selection mode settings

This commit is contained in:
Klaus Basan
2016-12-10 16:47:30 +01:00
parent f3037f083a
commit c90ae32c7e
5 changed files with 138 additions and 36 deletions

View File

@@ -17,6 +17,7 @@
#include <QStyleFactory>
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<void(QComboBox::*)(const QString &)>(&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<void(QComboBox::*)(const QString &)>(&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

View File

@@ -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::CSettingsGuiComponent> ui;
QColor m_fontColor;
void reloadWidgetStyleFromSettings();
void widgetStyleChanged(const QString &widgetStyle);
BlackMisc::CSetting<BlackGui::Settings::TWidgetStyle> m_settingsWidgetStyle { this, &CSettingsGuiComponent::reloadWidgetStyleFromSettings };
BlackMisc::CSetting<BlackGui::Settings::TGeneralGui> m_guiSettings { this, &CSettingsGuiComponent::guiSettingsChanged };
};
} // ns
} // ns

View File

@@ -6,12 +6,12 @@
<rect>
<x>0</x>
<y>0</y>
<width>223</width>
<height>245</height>
<width>233</width>
<height>248</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
<string>GUI general settings</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
@@ -210,10 +210,25 @@
<string>General</string>
</property>
<layout class="QFormLayout" name="fl_GuiGeneral">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item row="1" column="0">
<widget class="QLabel" name="lbl_SettingsGuiOpacity">
<property name="toolTip">
<string>0-100%</string>
</property>
<property name="text">
<string>Opacity (0-100%)</string>
<string>Opacity</string>
</property>
</widget>
</item>
@@ -225,6 +240,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>0-100%</string>
</property>
<property name="maximum">
<number>100</number>
</property>
@@ -242,13 +260,55 @@
<item row="2" column="0">
<widget class="QLabel" name="lbl_SettingsGuiWidgetStyle">
<property name="text">
<string>Widget Style</string>
<string>Widget style</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="cb_SettingsGuiWidgetStyle"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lbl_PreferredMultiSelect">
<property name="text">
<string>Selection</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QWidget" name="wi_PreferredSelection" native="true">
<layout class="QHBoxLayout" name="hl_PreferredMultiSelect">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QRadioButton" name="rb_PreferExtendedSelection">
<property name="text">
<string>Extended</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rb_PreferMultiSelection">
<property name="text">
<string>Multi</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>

View File

@@ -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

View File

@@ -196,14 +196,13 @@ namespace BlackGui
bool m_uiSetupCompleted = false; //!< ui setup completed
QScopedPointer<QSplashScreen> m_splashScreen; //!< splash screen
BlackGui::Components::CApplicationCloseDialog *m_closeDialog = nullptr; //!< close dialog (no QScopedPointer because I need to set parent)
BlackMisc::CSettingReadOnly<BlackGui::Settings::TWidgetStyle> m_settingsWidgetStyle{ this, &CGuiApplication::reloadWidgetStyleFromSettings };
BlackMisc::CSettingReadOnly<BlackGui::Settings::TGeneralGui> 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