mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-16 10:25:36 +08:00
refs #830, UI for selection mode settings
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
#include <QStyleFactory>
|
#include <QStyleFactory>
|
||||||
|
|
||||||
using namespace BlackMisc;
|
using namespace BlackMisc;
|
||||||
|
using namespace BlackGui::Settings;
|
||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
@@ -38,21 +39,27 @@ namespace BlackGui
|
|||||||
ui->cb_SettingsGuiFont->setCurrentFont(font);
|
ui->cb_SettingsGuiFont->setCurrentFont(font);
|
||||||
ui->cb_SettingsGuiFontSize->setCurrentText(QString::number(font.pointSize()));
|
ui->cb_SettingsGuiFontSize->setCurrentText(QString::number(font.pointSize()));
|
||||||
ui->le_SettingsGuiFontColor->setText(this->m_fontColor.name());
|
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()));
|
bool connected = this->connect(ui->cb_SettingsGuiFont, SIGNAL(currentFontChanged(QFont)), this, SLOT(ps_fontChanged()));
|
||||||
Q_ASSERT(connected);
|
Q_ASSERT(connected);
|
||||||
this->connect(ui->tb_SettingsGuiFontColor, &QToolButton::clicked, this, &CSettingsGuiComponent::ps_fontColorDialog);
|
connected = connect(ui->cb_SettingsGuiFontSize, SIGNAL(currentIndexChanged(QString)), this, SLOT(ps_fontChanged()));
|
||||||
connected = this->connect(ui->cb_SettingsGuiFontSize, SIGNAL(currentIndexChanged(QString)), this, SLOT(ps_fontChanged()));
|
|
||||||
Q_ASSERT(connected);
|
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);
|
Q_ASSERT(connected);
|
||||||
|
|
||||||
// Widget style and rest
|
// Widget style and rest
|
||||||
this->connect(ui->hs_SettingsGuiOpacity, &QSlider::valueChanged, this, &CSettingsGuiComponent::changedWindowsOpacity);
|
connect(ui->hs_SettingsGuiOpacity, &QSlider::valueChanged, this, &CSettingsGuiComponent::changedWindowsOpacity);
|
||||||
this->connect(ui->cb_SettingsGuiWidgetStyle, static_cast<void(QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
|
connect(ui->cb_SettingsGuiWidgetStyle, static_cast<void(QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
|
||||||
this, &CSettingsGuiComponent::widgetStyleChanged);
|
this, &CSettingsGuiComponent::widgetStyleChanged);
|
||||||
this->connect(ui->tb_ResetFont, &QToolButton::pressed, this, &CSettingsGuiComponent::ps_resetFont);
|
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);
|
Q_UNUSED(connected);
|
||||||
this->reloadWidgetStyleFromSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CSettingsGuiComponent::~CSettingsGuiComponent()
|
CSettingsGuiComponent::~CSettingsGuiComponent()
|
||||||
@@ -80,7 +87,7 @@ namespace BlackGui
|
|||||||
fontColor = sGui->getStyleSheetUtility().fontColor();
|
fontColor = sGui->getStyleSheetUtility().fontColor();
|
||||||
}
|
}
|
||||||
ui->le_SettingsGuiFontColor->setText(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)
|
if (ok)
|
||||||
{
|
{
|
||||||
CLogMessage(this).info("Updated font style");
|
CLogMessage(this).info("Updated font style");
|
||||||
@@ -105,20 +112,45 @@ namespace BlackGui
|
|||||||
sGui->resetFont();
|
sGui->resetFont();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSettingsGuiComponent::reloadWidgetStyleFromSettings()
|
void CSettingsGuiComponent::ps_selectionChanged()
|
||||||
{
|
{
|
||||||
int index = ui->cb_SettingsGuiWidgetStyle->findText(m_settingsWidgetStyle.get());
|
QAbstractItemView::SelectionMode sm = QAbstractItemView::NoSelection;
|
||||||
ui->cb_SettingsGuiWidgetStyle->setCurrentIndex(index);
|
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)
|
void CSettingsGuiComponent::widgetStyleChanged(const QString &widgetStyle)
|
||||||
{
|
{
|
||||||
if (widgetStyle == m_settingsWidgetStyle.get()) { return; }
|
const CGeneralGuiSettings settings = m_guiSettings.getThreadLocal();
|
||||||
auto availableStyles = QStyleFactory::keys();
|
if (!settings.isDifferentValidWidgetStyle(widgetStyle)) { return; }
|
||||||
if (availableStyles.contains(widgetStyle))
|
const CStatusMessage m = this->m_guiSettings.setAndSaveProperty(CGeneralGuiSettings::IndexWidgetStyle, widgetStyle);
|
||||||
{
|
CLogMessage::preformatted(m);
|
||||||
m_settingsWidgetStyle.set(widgetStyle);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -56,13 +56,19 @@ namespace BlackGui
|
|||||||
//! Reset font
|
//! Reset font
|
||||||
void ps_resetFont();
|
void ps_resetFont();
|
||||||
|
|
||||||
|
//! Selection radio buttons changed
|
||||||
|
void ps_selectionChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
//! GUI settings changed
|
||||||
|
void guiSettingsChanged();
|
||||||
|
|
||||||
|
//! Widget style has changed
|
||||||
|
void widgetStyleChanged(const QString &widgetStyle);
|
||||||
|
|
||||||
QScopedPointer<Ui::CSettingsGuiComponent> ui;
|
QScopedPointer<Ui::CSettingsGuiComponent> ui;
|
||||||
QColor m_fontColor;
|
QColor m_fontColor;
|
||||||
|
BlackMisc::CSetting<BlackGui::Settings::TGeneralGui> m_guiSettings { this, &CSettingsGuiComponent::guiSettingsChanged };
|
||||||
void reloadWidgetStyleFromSettings();
|
|
||||||
void widgetStyleChanged(const QString &widgetStyle);
|
|
||||||
BlackMisc::CSetting<BlackGui::Settings::TWidgetStyle> m_settingsWidgetStyle { this, &CSettingsGuiComponent::reloadWidgetStyleFromSettings };
|
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -6,12 +6,12 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>223</width>
|
<width>233</width>
|
||||||
<height>245</height>
|
<height>248</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Frame</string>
|
<string>GUI general settings</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="frameShape">
|
<property name="frameShape">
|
||||||
<enum>QFrame::StyledPanel</enum>
|
<enum>QFrame::StyledPanel</enum>
|
||||||
@@ -210,10 +210,25 @@
|
|||||||
<string>General</string>
|
<string>General</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QFormLayout" name="fl_GuiGeneral">
|
<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">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="lbl_SettingsGuiOpacity">
|
<widget class="QLabel" name="lbl_SettingsGuiOpacity">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>0-100%</string>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Opacity (0-100%)</string>
|
<string>Opacity</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@@ -225,6 +240,9 @@
|
|||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>0-100%</string>
|
||||||
|
</property>
|
||||||
<property name="maximum">
|
<property name="maximum">
|
||||||
<number>100</number>
|
<number>100</number>
|
||||||
</property>
|
</property>
|
||||||
@@ -242,13 +260,55 @@
|
|||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="lbl_SettingsGuiWidgetStyle">
|
<widget class="QLabel" name="lbl_SettingsGuiWidgetStyle">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Widget Style</string>
|
<string>Widget style</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QComboBox" name="cb_SettingsGuiWidgetStyle"/>
|
<widget class="QComboBox" name="cb_SettingsGuiWidgetStyle"/>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@@ -499,7 +499,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
QDialog::DialogCode CGuiApplication::showCloseDialog(QMainWindow *mainWindow, QCloseEvent *closeEvent)
|
QDialog::DialogCode CGuiApplication::showCloseDialog(QMainWindow *mainWindow, QCloseEvent *closeEvent)
|
||||||
{
|
{
|
||||||
bool needsDialog = this->hasUnsavedSettings();
|
const bool needsDialog = this->hasUnsavedSettings();
|
||||||
if (!needsDialog) { return QDialog::Accepted; }
|
if (!needsDialog) { return QDialog::Accepted; }
|
||||||
if (!this->m_closeDialog)
|
if (!this->m_closeDialog)
|
||||||
{
|
{
|
||||||
@@ -550,13 +550,18 @@ namespace BlackGui
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGuiApplication::reloadWidgetStyleFromSettings()
|
void CGuiApplication::settingsChanged()
|
||||||
{
|
{
|
||||||
auto widgetStyle = m_settingsWidgetStyle.get();
|
// changing widget style is slow, so I try to prevent setting it when nothing changed
|
||||||
auto availableStyles = QStyleFactory::keys();
|
const QString widgetStyle = m_guiSettings.get().getWidgetStyle();
|
||||||
if (availableStyles.contains(widgetStyle))
|
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
|
} // ns
|
||||||
|
|||||||
@@ -196,14 +196,13 @@ namespace BlackGui
|
|||||||
bool m_uiSetupCompleted = false; //!< ui setup completed
|
bool m_uiSetupCompleted = false; //!< ui setup completed
|
||||||
QScopedPointer<QSplashScreen> m_splashScreen; //!< splash screen
|
QScopedPointer<QSplashScreen> m_splashScreen; //!< splash screen
|
||||||
BlackGui::Components::CApplicationCloseDialog *m_closeDialog = nullptr; //!< close dialog (no QScopedPointer because I need to set parent)
|
BlackGui::Components::CApplicationCloseDialog *m_closeDialog = nullptr; //!< close dialog (no QScopedPointer because I need to set parent)
|
||||||
|
BlackMisc::CSettingReadOnly<BlackGui::Settings::TGeneralGui> m_guiSettings{ this, &CGuiApplication::settingsChanged };
|
||||||
BlackMisc::CSettingReadOnly<BlackGui::Settings::TWidgetStyle> m_settingsWidgetStyle{ this, &CGuiApplication::reloadWidgetStyleFromSettings };
|
|
||||||
|
|
||||||
//! Qt help message to formatted HTML
|
//! Qt help message to formatted HTML
|
||||||
static QString beautifyHelpMessage(const QString &helpText);
|
static QString beautifyHelpMessage(const QString &helpText);
|
||||||
|
|
||||||
//! Reload widget style from settings
|
//! Reload widget style from settings
|
||||||
void reloadWidgetStyleFromSettings();
|
void settingsChanged();
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user