summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-09-25 18:24:08 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2019-09-25 18:24:08 -0400
commit01b2a8201dbbb3e5ba8c09246a45cde4f11ed2bc (patch)
tree5d42b51b11e2fd85f7cbc88d57e3ba96c332814b
parent088f27fe48cd8f218052090a97e8187eedf0c06e (diff)
replaced color buttons by a QTableWidget
-rw-r--r--src/settingsdialog.ui237
-rw-r--r--src/settingsdialoggeneral.cpp339
-rw-r--r--src/settingsdialoggeneral.h38
3 files changed, 375 insertions, 239 deletions
diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui
index 78bae6d7..1ecf19f9 100644
--- a/src/settingsdialog.ui
+++ b/src/settingsdialog.ui
@@ -42,46 +42,64 @@
<property name="title">
<string>User Interface</string>
</property>
- <layout class="QGridLayout" name="gridLayout_7">
- <item row="2" column="0">
- <widget class="QLabel" name="label_10">
- <property name="text">
- <string>Style</string>
- </property>
- </widget>
- </item>
- <item row="0" column="0">
- <widget class="QLabel" name="label_5">
- <property name="text">
- <string>Language</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QComboBox" name="languageBox">
- <property name="toolTip">
- <string>The display language</string>
- </property>
- <property name="whatsThis">
- <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
+ <layout class="QVBoxLayout" name="verticalLayout_14">
+ <item>
+ <widget class="QWidget" name="widget_6" native="true">
+ <layout class="QFormLayout" name="formLayout_4">
+ <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 row="0" column="0">
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string>Language</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QComboBox" name="languageBox">
+ <property name="toolTip">
+ <string>The display language</string>
+ </property>
+ <property name="whatsThis">
+ <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:8pt;&quot;&gt;The display language. This will only displaye languages for which you have a translation installed.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
- </property>
- </widget>
- </item>
- <item row="2" column="1">
- <widget class="QComboBox" name="styleBox">
- <property name="toolTip">
- <string>graphical style</string>
- </property>
- <property name="whatsThis">
- <string>graphical style of the MO user interface</string>
- </property>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_10">
+ <property name="text">
+ <string>Style</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QComboBox" name="styleBox">
+ <property name="toolTip">
+ <string>graphical style</string>
+ </property>
+ <property name="whatsThis">
+ <string>graphical style of the MO user interface</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
</widget>
</item>
- <item row="4" column="0" colspan="2">
+ <item>
<widget class="QCheckBox" name="centerDialogs">
<property name="toolTip">
<string>Dialogs will always be centered on the main window, but will remember their size.</string>
@@ -94,7 +112,7 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
- <item row="5" column="0" colspan="2">
+ <item>
<widget class="QPushButton" name="resetDialogsButton">
<property name="maximumSize">
<size>
@@ -113,7 +131,7 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
- <item row="6" column="0" colspan="2">
+ <item>
<widget class="QPushButton" name="categoriesBtn">
<property name="toolTip">
<string>Modify the categories available to arrange your mods.</string>
@@ -126,6 +144,19 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
+ <item>
+ <spacer name="verticalSpacer_11">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
</layout>
</widget>
</item>
@@ -176,70 +207,90 @@ p, li { white-space: pre-wrap; }
<property name="title">
<string>Colors</string>
</property>
- <layout class="QGridLayout" name="gridLayout_5">
- <item row="6" column="0">
- <widget class="QCheckBox" name="colorSeparatorsBox">
- <property name="toolTip">
- <string>When this is enabled, the color defined for a separator will be shown on the mod list scrollbar at the location of the separator. This can be useful for quick navigation between separator sections or to a specific separator section.</string>
- </property>
- <property name="whatsThis">
- <string>When this is enabled, the color defined for a separator will be shown on the mod list scrollbar at the location of the separator. This can be useful for quick navigation between separator sections or to a specific separator section.</string>
- </property>
- <property name="text">
- <string>Show mod list separator colors on the scrollbar</string>
+ <layout class="QVBoxLayout" name="verticalLayout_13">
+ <item>
+ <widget class="QTableWidget" name="colorTable">
+ <property name="editTriggers">
+ <set>QAbstractItemView::NoEditTriggers</set>
</property>
- <property name="checked">
- <bool>true</bool>
+ <property name="selectionMode">
+ <enum>QAbstractItemView::SingleSelection</enum>
</property>
- </widget>
- </item>
- <item row="4" column="0" colspan="2">
- <widget class="QPushButton" name="containedBtn">
- <property name="text">
- <string>Plugin is Contained in selected Mod</string>
+ <property name="selectionBehavior">
+ <enum>QAbstractItemView::SelectRows</enum>
</property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QPushButton" name="overwrittenBtn">
- <property name="text">
- <string>Is overwritten (loose files)</string>
+ <property name="verticalScrollMode">
+ <enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QPushButton" name="overwritingBtn">
- <property name="text">
- <string>Is overwriting (loose files)</string>
- </property>
- </widget>
- </item>
- <item row="5" column="0" colspan="2">
- <widget class="QPushButton" name="resetColorsBtn">
- <property name="text">
- <string>Reset Colors</string>
- </property>
- </widget>
- </item>
- <item row="3" column="0" colspan="2">
- <widget class="QPushButton" name="containsBtn">
- <property name="text">
- <string>Mod Contains selected Plugin</string>
- </property>
- </widget>
- </item>
- <item row="2" column="0">
- <widget class="QPushButton" name="overwrittenArchiveBtn">
- <property name="text">
- <string>Is overwritten (archive files)</string>
+ <property name="cornerButtonEnabled">
+ <bool>false</bool>
</property>
+ <attribute name="horizontalHeaderVisible">
+ <bool>false</bool>
+ </attribute>
+ <attribute name="horizontalHeaderHighlightSections">
+ <bool>false</bool>
+ </attribute>
+ <attribute name="horizontalHeaderStretchLastSection">
+ <bool>true</bool>
+ </attribute>
+ <attribute name="verticalHeaderVisible">
+ <bool>false</bool>
+ </attribute>
</widget>
</item>
- <item row="2" column="1">
- <widget class="QPushButton" name="overwritingArchiveBtn">
- <property name="text">
- <string>Is overwriting (archive files)</string>
- </property>
+ <item>
+ <widget class="QWidget" name="widget_5" native="true">
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <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="QCheckBox" name="colorSeparatorsBox">
+ <property name="toolTip">
+ <string>When this is enabled, the color defined for a separator will be shown on the mod list scrollbar at the location of the separator. This can be useful for quick navigation between separator sections or to a specific separator section.</string>
+ </property>
+ <property name="whatsThis">
+ <string>When this is enabled, the color defined for a separator will be shown on the mod list scrollbar at the location of the separator. This can be useful for quick navigation between separator sections or to a specific separator section.</string>
+ </property>
+ <property name="text">
+ <string>Show mod list separator colors on the scrollbar</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="resetColorsBtn">
+ <property name="text">
+ <string>Reset Colors</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
</widget>
</item>
</layout>
diff --git a/src/settingsdialoggeneral.cpp b/src/settingsdialoggeneral.cpp
index 07aff4a1..be57101e 100644
--- a/src/settingsdialoggeneral.cpp
+++ b/src/settingsdialoggeneral.cpp
@@ -6,64 +6,121 @@
using MOBase::QuestionBoxMemory;
-GeneralSettingsTab::GeneralSettingsTab(Settings& s, SettingsDialog& d)
- : SettingsTab(s, d)
+
+class ColorItem : public QTableWidgetItem
{
- addLanguages();
+public:
+ ColorItem(
+ const QColor& defaultColor,
+ std::function<QColor ()> get,
+ std::function<void (const QColor&)> commit)
+ : m_default(defaultColor), m_get(get), m_commit(commit)
+ {
+ set(get());
+ }
+
+ QColor get() const
+ {
+ return m_temp;
+ }
+
+ bool set(const QColor& c)
{
- QString languageCode = settings().interface().language();
- int currentID = ui->languageBox->findData(languageCode);
- // I made a mess. :( Most languages are stored with only the iso country
- // code (2 characters like "de") but chinese
- // with the exact language variant (zh_TW) so I have to search for both
- // variants
- if (currentID == -1) {
- currentID = ui->languageBox->findData(languageCode.mid(0, 2));
+ if (m_temp != c) {
+ m_temp = c;
+ return true;
}
- if (currentID != -1) {
- ui->languageBox->setCurrentIndex(currentID);
+
+ return false;
+ }
+
+ void commit()
+ {
+ m_commit(m_temp);
+ }
+
+ bool reset()
+ {
+ return set(m_default);
+ }
+
+private:
+ const QColor m_default;
+ std::function<QColor ()> m_get;
+ std::function<void (const QColor&)> m_commit;
+ QColor m_temp;
+};
+
+
+class ColorDelegate : public QStyledItemDelegate
+{
+public:
+ ColorDelegate(QTableWidget* table)
+ : m_table(table)
+ {
+ }
+
+protected:
+ void paint(
+ QPainter* p, const QStyleOptionViewItem& option,
+ const QModelIndex& index) const override
+ {
+ if (!paintColor(p, option, index)) {
+ QStyledItemDelegate::paint(p, option, index);
}
}
- addStyles();
+private:
+ QTableWidget* m_table;
+ bool paintColor(
+ QPainter* p, const QStyleOptionViewItem& option,
+ const QModelIndex& index) const
{
- const int currentID = ui->styleBox->findData(
- settings().interface().styleName().value_or(""));
+ if (index.column() != 1) {
+ return false;
+ }
- if (currentID != -1) {
- ui->styleBox->setCurrentIndex(currentID);
+ const auto* item = dynamic_cast<ColorItem*>(
+ m_table->item(index.row(), index.column()));
+
+ if (!item) {
+ return false;
}
+
+ p->save();
+ p->fillRect(option.rect, item->get());
+ p->restore();
+
+ return true;
}
+};
+
- //version with stylesheet
- setButtonColor(ui->overwritingBtn, settings().colors().modlistOverwritingLoose());
- setButtonColor(ui->overwrittenBtn, settings().colors().modlistOverwrittenLoose());
- setButtonColor(ui->overwritingArchiveBtn, settings().colors().modlistOverwritingArchive());
- setButtonColor(ui->overwrittenArchiveBtn, settings().colors().modlistOverwrittenArchive());
- setButtonColor(ui->containsBtn, settings().colors().modlistContainsPlugin());
- setButtonColor(ui->containedBtn, settings().colors().pluginListContained());
+template <class F>
+void forEachColorItem(QTableWidget* table, F&& f)
+{
+ const auto rowCount = table->rowCount();
- setOverwritingColor(settings().colors().modlistOverwritingLoose());
- setOverwrittenColor(settings().colors().modlistOverwrittenLoose());
- setOverwritingArchiveColor(settings().colors().modlistOverwritingArchive());
- setOverwrittenArchiveColor(settings().colors().modlistOverwrittenArchive());
- setContainsColor(settings().colors().modlistContainsPlugin());
- setContainedColor(settings().colors().pluginListContained());
+ for (int i=0; i<rowCount; ++i) {
+ if (auto* item=dynamic_cast<ColorItem*>(table->item(i, 1))) {
+ f(item);
+ }
+ }
+}
+
+
+GeneralSettingsTab::GeneralSettingsTab(Settings& s, SettingsDialog& d)
+ : SettingsTab(s, d)
+{
+ addLanguages();
+ selectLanguage();
+
+ addStyles();
+ selectStyle();
- ui->centerDialogs->setChecked(settings().geometry().centerDialogs());
- ui->compactBox->setChecked(settings().interface().compactDownloads());
- ui->showMetaBox->setChecked(settings().interface().metaDownloads());
- ui->checkForUpdates->setChecked(settings().checkForUpdates());
- ui->usePrereleaseBox->setChecked(settings().usePrereleases());
- ui->colorSeparatorsBox->setChecked(settings().colors().colorSeparatorScrollbar());
+ setColorTable();
- QObject::connect(ui->overwritingArchiveBtn, &QPushButton::clicked, [&]{ on_overwritingArchiveBtn_clicked(); });
- QObject::connect(ui->overwritingBtn, &QPushButton::clicked, [&]{ on_overwritingBtn_clicked(); });
- QObject::connect(ui->overwrittenArchiveBtn, &QPushButton::clicked, [&]{ on_overwrittenArchiveBtn_clicked(); });
- QObject::connect(ui->overwrittenBtn, &QPushButton::clicked, [&]{ on_overwrittenBtn_clicked(); });
- QObject::connect(ui->containedBtn, &QPushButton::clicked, [&]{ on_containedBtn_clicked(); });
- QObject::connect(ui->containsBtn, &QPushButton::clicked, [&]{ on_containsBtn_clicked(); });
QObject::connect(ui->categoriesBtn, &QPushButton::clicked, [&]{ on_categoriesBtn_clicked(); });
QObject::connect(ui->resetColorsBtn, &QPushButton::clicked, [&]{ on_resetColorsBtn_clicked(); });
QObject::connect(ui->resetDialogsButton, &QPushButton::clicked, [&]{ on_resetDialogsButton_clicked(); });
@@ -86,18 +143,16 @@ void GeneralSettingsTab::update()
emit settings().styleChanged(newStyle);
}
- settings().colors().setModlistOverwritingLoose(getOverwritingColor());
- settings().colors().setModlistOverwrittenLoose(getOverwrittenColor());
- settings().colors().setModlistOverwritingArchive(getOverwritingArchiveColor());
- settings().colors().setModlistOverwrittenArchive(getOverwrittenArchiveColor());
- settings().colors().setModlistContainsPlugin(getContainsColor());
- settings().colors().setPluginListContained(getContainedColor());
-
settings().geometry().setCenterDialogs(ui->centerDialogs->isChecked());
settings().interface().setCompactDownloads(ui->compactBox->isChecked());
settings().interface().setMetaDownloads(ui->showMetaBox->isChecked());
settings().setCheckForUpdates(ui->checkForUpdates->isChecked());
settings().setUsePrereleases(ui->usePrereleaseBox->isChecked());
+
+ forEachColorItem(ui->colorTable, [](auto* item) {
+ item->commit();
+ });
+
settings().colors().setColorSeparatorScrollbar(ui->colorSeparatorsBox->isChecked());
}
@@ -134,6 +189,22 @@ void GeneralSettingsTab::addLanguages()
}
}
+void GeneralSettingsTab::selectLanguage()
+{
+ QString languageCode = settings().interface().language();
+ int currentID = ui->languageBox->findData(languageCode);
+ // I made a mess. :( Most languages are stored with only the iso country
+ // code (2 characters like "de") but chinese
+ // with the exact language variant (zh_TW) so I have to search for both
+ // variants
+ if (currentID == -1) {
+ currentID = ui->languageBox->findData(languageCode.mid(0, 2));
+ }
+ if (currentID != -1) {
+ ui->languageBox->setCurrentIndex(currentID);
+ }
+}
+
void GeneralSettingsTab::addStyles()
{
ui->styleBox->addItem("None", "");
@@ -147,107 +218,136 @@ void GeneralSettingsTab::addStyles()
}
}
-void GeneralSettingsTab::resetDialogs()
+void GeneralSettingsTab::selectStyle()
{
- settings().widgets().resetQuestionButtons();
+ const int currentID = ui->styleBox->findData(
+ settings().interface().styleName().value_or(""));
+
+ if (currentID != -1) {
+ ui->styleBox->setCurrentIndex(currentID);
+ }
}
-void GeneralSettingsTab::setButtonColor(QPushButton *button, const QColor &color)
+void GeneralSettingsTab::setColorTable()
{
- button->setStyleSheet(
- QString("QPushButton {"
- "background-color: rgba(%1, %2, %3, %4);"
- "color: %5;"
- "border: 1px solid;"
- "padding: 3px;"
- "}")
- .arg(color.red())
- .arg(color.green())
- .arg(color.blue())
- .arg(color.alpha())
- .arg(ColorSettings::idealTextColor(color).name())
- );
-};
+ ui->colorTable->setColumnCount(2);
+ ui->colorTable->setHorizontalHeaderLabels({
+ QObject::tr("Item"), QObject::tr("Color")
+ });
-void GeneralSettingsTab::on_containsBtn_clicked()
-{
- QColor result = QColorDialog::getColor(m_ContainsColor, &dialog(), "Color Picker: Mod contains selected plugin", QColorDialog::ShowAlphaChannel);
- if (result.isValid()) {
- m_ContainsColor = result;
- setButtonColor(ui->containsBtn, result);
- }
+ ui->colorTable->setItemDelegate(new ColorDelegate(ui->colorTable));
+
+ addColor(
+ QObject::tr("Is overwritten (loose files)"),
+ QColor(0, 255, 0, 64),
+ [this]{ return settings().colors().modlistOverwrittenLoose(); },
+ [this](auto&& v){ settings().colors().setModlistOverwrittenLoose(v); });
+
+ addColor(
+ QObject::tr("Is overwriting (loose files)"),
+ QColor(255, 0, 0, 64),
+ [this]{ return settings().colors().modlistOverwritingLoose(); },
+ [this](auto&& v){ settings().colors().setModlistOverwritingLoose(v); });
+
+ addColor(
+ QObject::tr("Is overwritten (archives)"),
+ QColor(0, 255, 255, 64),
+ [this]{ return settings().colors().modlistOverwrittenArchive(); },
+ [this](auto&& v){ settings().colors().setModlistOverwrittenArchive(v); });
+
+ addColor(
+ QObject::tr("Is overwriting (archives)"),
+ QColor(255, 0, 255, 64),
+ [this]{ return settings().colors().modlistOverwritingArchive(); },
+ [this](auto&& v){ settings().colors().setModlistOverwritingArchive(v); });
+
+ addColor(
+ QObject::tr("Mod contains selected plugin"),
+ QColor(0, 0, 255, 64),
+ [this]{ return settings().colors().modlistContainsPlugin(); },
+ [this](auto&& v){ settings().colors().setModlistContainsPlugin(v); });
+
+ addColor(
+ QObject::tr("Plugin is contained in selected mod"),
+ QColor(0, 0, 255, 64),
+ [this]{ return settings().colors().pluginListContained(); },
+ [this](auto&& v){ settings().colors().setPluginListContained(v); });
+
+ QObject::connect(
+ ui->colorTable, &QTableWidget::cellActivated,
+ [&]{ onColorActivated(); });
}
-void GeneralSettingsTab::on_containedBtn_clicked()
+void GeneralSettingsTab::addColor(
+ const QString& text, const QColor& defaultColor,
+ std::function<QColor ()> get,
+ std::function<void (const QColor&)> commit)
{
- QColor result = QColorDialog::getColor(m_ContainedColor, &dialog(), "ColorPicker: Plugin is Contained in selected Mod", QColorDialog::ShowAlphaChannel);
- if (result.isValid()) {
- m_ContainedColor = result;
- setButtonColor(ui->containedBtn, result);
- }
+ const auto r = ui->colorTable->rowCount();
+ ui->colorTable->setRowCount(r + 1);
+
+ ui->colorTable->setItem(r, 0, new QTableWidgetItem(text));
+ ui->colorTable->setItem(r, 1, new ColorItem(defaultColor, get, commit));
+
+ ui->colorTable->resizeColumnsToContents();
}
-void GeneralSettingsTab::on_overwrittenBtn_clicked()
+void GeneralSettingsTab::resetDialogs()
{
- QColor result = QColorDialog::getColor(m_OverwrittenColor, &dialog(), "ColorPicker: Is overwritten (loose files)", QColorDialog::ShowAlphaChannel);
- if (result.isValid()) {
- m_OverwrittenColor = result;
- setButtonColor(ui->overwrittenBtn, result);
- }
+ settings().widgets().resetQuestionButtons();
}
-void GeneralSettingsTab::on_overwritingBtn_clicked()
+void GeneralSettingsTab::onColorActivated()
{
- QColor result = QColorDialog::getColor(m_OverwritingColor, &dialog(), "ColorPicker: Is overwriting (loose files)", QColorDialog::ShowAlphaChannel);
- if (result.isValid()) {
- m_OverwritingColor = result;
- setButtonColor(ui->overwritingBtn, result);
+ const auto rows = ui->colorTable->selectionModel()->selectedRows();
+ if (rows.isEmpty()) {
+ return;
}
-}
-void GeneralSettingsTab::on_overwrittenArchiveBtn_clicked()
-{
- QColor result = QColorDialog::getColor(m_OverwrittenArchiveColor, &dialog(), "ColorPicker: Is overwritten (archive files)", QColorDialog::ShowAlphaChannel);
- if (result.isValid()) {
- m_OverwrittenArchiveColor = result;
- setButtonColor(ui->overwrittenArchiveBtn, result);
+ const auto row = rows[0].row();
+
+ const auto text = ui->colorTable->item(row, 0)->text();
+ auto* item = dynamic_cast<ColorItem*>(ui->colorTable->item(row, 1));
+
+ if (!item) {
+ return;
}
-}
-void GeneralSettingsTab::on_overwritingArchiveBtn_clicked()
-{
- QColor result = QColorDialog::getColor(m_OverwritingArchiveColor, &dialog(), "ColorPicker: Is overwriting (archive files)", QColorDialog::ShowAlphaChannel);
+ const QColor result = QColorDialog::getColor(
+ item->get(), &dialog(), text, QColorDialog::ShowAlphaChannel);
+
if (result.isValid()) {
- m_OverwritingArchiveColor = result;
- setButtonColor(ui->overwritingArchiveBtn, result);
+ item->set(result);
+ ui->colorTable->update(ui->colorTable->model()->index(row, 1));
}
}
void GeneralSettingsTab::on_resetColorsBtn_clicked()
{
- m_OverwritingColor = QColor(255, 0, 0, 64);
- m_OverwrittenColor = QColor(0, 255, 0, 64);
- m_OverwritingArchiveColor = QColor(255, 0, 255, 64);
- m_OverwrittenArchiveColor = QColor(0, 255, 255, 64);
- m_ContainsColor = QColor(0, 0, 255, 64);
- m_ContainedColor = QColor(0, 0, 255, 64);
+ bool changed = false;
- setButtonColor(ui->overwritingBtn, m_OverwritingColor);
- setButtonColor(ui->overwrittenBtn, m_OverwrittenColor);
- setButtonColor(ui->overwritingArchiveBtn, m_OverwritingArchiveColor);
- setButtonColor(ui->overwrittenArchiveBtn, m_OverwrittenArchiveColor);
- setButtonColor(ui->containsBtn, m_ContainsColor);
- setButtonColor(ui->containedBtn, m_ContainedColor);
+ forEachColorItem(ui->colorTable, [&](auto* item) {
+ if (item->reset()) {
+ changed = true;
+ }
+ });
+
+ if (changed) {
+ ui->colorTable->update();
+ }
}
void GeneralSettingsTab::on_resetDialogsButton_clicked()
{
- if (QMessageBox::question(
- parentWidget(), QObject::tr("Confirm?"),
+ const auto r = QMessageBox::question(
+ parentWidget(),
+ QObject::tr("Confirm?"),
QObject::tr(
"This will reset all the choices you made to dialogs and make them all "
"visible again. Continue?"),
- QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
+ QMessageBox::Yes | QMessageBox::No);
+
+ if (r == QMessageBox::Yes) {
resetDialogs();
}
}
@@ -255,6 +355,7 @@ void GeneralSettingsTab::on_resetDialogsButton_clicked()
void GeneralSettingsTab::on_categoriesBtn_clicked()
{
CategoriesDialog dialog(&dialog());
+
if (dialog.exec() == QDialog::Accepted) {
dialog.commitChanges();
}
diff --git a/src/settingsdialoggeneral.h b/src/settingsdialoggeneral.h
index 2038ba31..1f7fafff 100644
--- a/src/settingsdialoggeneral.h
+++ b/src/settingsdialoggeneral.h
@@ -12,38 +12,22 @@ public:
void update();
private:
- QColor m_OverwritingColor;
- QColor m_OverwrittenColor;
- QColor m_OverwritingArchiveColor;
- QColor m_OverwrittenArchiveColor;
- QColor m_ContainsColor;
- QColor m_ContainedColor;
-
void addLanguages();
+ void selectLanguage();
+
void addStyles();
- void resetDialogs();
- void setButtonColor(QPushButton *button, const QColor &color);
+ void selectStyle();
- QColor getOverwritingColor() { return m_OverwritingColor; }
- QColor getOverwrittenColor() { return m_OverwrittenColor; }
- QColor getOverwritingArchiveColor() { return m_OverwritingArchiveColor; }
- QColor getOverwrittenArchiveColor() { return m_OverwrittenArchiveColor; }
- QColor getContainsColor() { return m_ContainsColor; }
- QColor getContainedColor() { return m_ContainedColor; }
+ void setColorTable();
+
+ void resetDialogs();
- void setOverwritingColor(QColor col) { m_OverwritingColor = col; }
- void setOverwrittenColor(QColor col) { m_OverwrittenColor = col; }
- void setOverwritingArchiveColor(QColor col) { m_OverwritingArchiveColor = col; }
- void setOverwrittenArchiveColor(QColor col) { m_OverwrittenArchiveColor = col; }
- void setContainsColor(QColor col) { m_ContainsColor = col; }
- void setContainedColor(QColor col) { m_ContainedColor = col; }
+ void addColor(
+ const QString& text, const QColor& defaultColor,
+ std::function<QColor ()> get,
+ std::function<void (const QColor&)> commit);
- void on_overwritingArchiveBtn_clicked();
- void on_overwritingBtn_clicked();
- void on_overwrittenArchiveBtn_clicked();
- void on_overwrittenBtn_clicked();
- void on_containedBtn_clicked();
- void on_containsBtn_clicked();
+ void onColorActivated();
void on_categoriesBtn_clicked();
void on_resetColorsBtn_clicked();