From 829124d8b899101370e55eb2a9cb9164ffd68a55 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Mon, 23 Sep 2019 17:52:46 -0400 Subject: ensure windows are on screen --- src/settings.cpp | 90 ++++++++++++++++++++++++++++++++++++++++++++------------ src/settings.h | 51 ++++++++++++++++++++++---------- 2 files changed, 107 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/settings.cpp b/src/settings.cpp index 7cea52fb..19eca5ec 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -22,7 +22,9 @@ along with Mod Organizer. If not, see . #include "serverinfo.h" #include "executableslist.h" #include "appconfig.h" -#include "expanderwidget.h" +#include "env.h" +#include "envmetrics.h" +#include #include #include @@ -604,21 +606,80 @@ void GeometrySettings::resetIfNeeded() removeSection(m_Settings, "Geometry"); } -void GeometrySettings::saveGeometry(const QWidget* w) +void GeometrySettings::saveGeometry(const QMainWindow* w) +{ + saveWindowGeometry(w); +} + +bool GeometrySettings::restoreGeometry(QMainWindow* w) const +{ + return restoreWindowGeometry(w); +} + +void GeometrySettings::saveGeometry(const QDialog* d) +{ + saveWindowGeometry(d); +} + +bool GeometrySettings::restoreGeometry(QDialog* d) const +{ + return restoreWindowGeometry(d); +} + +void GeometrySettings::saveWindowGeometry(const QWidget* w) { set(m_Settings, "Geometry", geoSettingName(w), w->saveGeometry()); } -bool GeometrySettings::restoreGeometry(QWidget* w) const +bool GeometrySettings::restoreWindowGeometry(QWidget* w) const { if (auto v=getOptional(m_Settings, "Geometry", geoSettingName(w))) { w->restoreGeometry(*v); + ensureWindowOnScreen(w); return true; } return false; } +void GeometrySettings::ensureWindowOnScreen(QWidget* w) const +{ + // users report that the main window and/or dialogs are displayed off-screen; + // the usual workaround is keyboard navigation to move it + // + // qt should have code that deals with multiple monitors and off-screen + // geometries, but there seems to be bugs or inconsistencies that can't be + // reproduced + // + // the closest would probably be https://bugreports.qt.io/browse/QTBUG-64498, + // which is about multiple monitors and high dpi, but it seems fixed as of + // 5.12.4, which is shipped with 2.2.1 + // + // without being to reproduce the problem, some simple checks are made in a + // timer, which may mitigate the issues + + QTimer::singleShot(100, w, [w] { + const auto borders = 20; + + // desktop geometry, made smaller to make sure there isn't just a few pixels + const auto originalDg = env::Environment().metrics().desktopGeometry(); + const auto dg = originalDg.adjusted(borders, borders, -borders, -borders); + + const auto g = w->geometry(); + + if (!dg.intersects(g)) { + log::warn( + "window '{}' is offscreen, moving to main monitor; geo={}, desktop={}", + w->objectName(), g, originalDg); + + // widget is off-screen, center it on main monitor + centerOnMonitor(w, -1); + + log::warn("window '{}' now at {}", w->objectName(), w->geometry()); + } + }); +} + void GeometrySettings::saveState(const QMainWindow* w) { set(m_Settings, "Geometry", stateSettingName(w), w->saveState()); @@ -771,12 +832,17 @@ void GeometrySettings::setModInfoTabOrder(const QString& names) void GeometrySettings::centerOnMainWindowMonitor(QWidget* w) { const auto monitor = getOptional( - m_Settings, "Geometry", "MainWindow_monitor"); + m_Settings, "Geometry", "MainWindow_monitor").value_or(-1); + + centerOnMonitor(w, monitor); +} +void GeometrySettings::centerOnMonitor(QWidget* w, int monitor) +{ QPoint center; - if (monitor && QGuiApplication::screens().size() > *monitor) { - center = QGuiApplication::screens().at(*monitor)->geometry().center(); + if (monitor >= 0 && monitor < QGuiApplication::screens().size()) { + center = QGuiApplication::screens().at(monitor)->geometry().center(); } else { center = QGuiApplication::primaryScreen()->geometry().center(); } @@ -1887,15 +1953,3 @@ void DiagnosticsSettings::setCrashDumpsMax(int n) { set(m_Settings, "Settings", "crash_dumps_max", n); } - - -GeometrySaver::GeometrySaver(Settings& s, QDialog* dialog) - : m_settings(s), m_dialog(dialog) -{ - m_settings.geometry().restoreGeometry(m_dialog); -} - -GeometrySaver::~GeometrySaver() -{ - m_settings.geometry().saveGeometry(m_dialog); -} diff --git a/src/settings.h b/src/settings.h index cd478a5b..b5366911 100644 --- a/src/settings.h +++ b/src/settings.h @@ -41,20 +41,6 @@ class ServerList; class Settings; -// helper class that calls restoreGeometry() in the constructor and -// saveGeometry() in the destructor -// -class GeometrySaver -{ -public: - GeometrySaver(Settings& s, QDialog* dialog); - ~GeometrySaver(); - -private: - Settings& m_settings; - QDialog* m_dialog; -}; - // setting for the currently managed game // @@ -141,8 +127,11 @@ public: void resetIfNeeded(); - void saveGeometry(const QWidget* w); - bool restoreGeometry(QWidget* w) const; + void saveGeometry(const QMainWindow* w); + bool restoreGeometry(QMainWindow* w) const; + + void saveGeometry(const QDialog* d); + bool restoreGeometry(QDialog* d) const; void saveState(const QMainWindow* window); bool restoreState(QMainWindow* window) const; @@ -182,6 +171,12 @@ public: private: QSettings& m_Settings; bool m_Reset; + + void saveWindowGeometry(const QWidget* w); + bool restoreWindowGeometry(QWidget* w) const; + + void ensureWindowOnScreen(QWidget* w) const; + static void centerOnMonitor(QWidget* w, int monitor); }; @@ -764,4 +759,28 @@ private: DiagnosticsSettings m_Diagnostics; }; + +// helper class that calls restoreGeometry() in the constructor and +// saveGeometry() in the destructor +// +template +class GeometrySaver +{ +public: + GeometrySaver(Settings& s, W* w) + : m_settings(s), m_widget(w) + { + m_settings.geometry().restoreGeometry(m_widget); + } + + ~GeometrySaver() + { + m_settings.geometry().saveGeometry(m_widget); + } + +private: + Settings& m_settings; + W* m_widget; +}; + #endif // SETTINGS_H -- cgit v1.3.1 From 200b5283eb5a0eff5ed18e772930b99eea5e11ef Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Mon, 23 Sep 2019 18:21:39 -0400 Subject: added center dialogs option moved download list options to their own group box renamed confusing "Download Meta Information" to "Show Meta Information" --- src/settings.cpp | 34 ++++++- src/settings.h | 6 ++ src/settingsdialog.ui | 208 ++++++++++++++++++++++-------------------- src/settingsdialoggeneral.cpp | 2 + 4 files changed, 149 insertions(+), 101 deletions(-) (limited to 'src') diff --git a/src/settings.cpp b/src/settings.cpp index 19eca5ec..c3e8781e 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -623,7 +623,13 @@ void GeometrySettings::saveGeometry(const QDialog* d) bool GeometrySettings::restoreGeometry(QDialog* d) const { - return restoreWindowGeometry(d); + const auto r = restoreWindowGeometry(d); + + if (centerDialogs()) { + centerOnParent(d); + } + + return r; } void GeometrySettings::saveWindowGeometry(const QWidget* w) @@ -829,6 +835,16 @@ void GeometrySettings::setModInfoTabOrder(const QString& names) set(m_Settings, "Widgets", "ModInfoTabOrder", names); } +bool GeometrySettings::centerDialogs() const +{ + return get(m_Settings, "Settings", "center_dialogs", false); +} + +void GeometrySettings::setCenterDialogs(bool b) +{ + set(m_Settings, "Settings", "center_dialogs", b); +} + void GeometrySettings::centerOnMainWindowMonitor(QWidget* w) { const auto monitor = getOptional( @@ -850,6 +866,22 @@ void GeometrySettings::centerOnMonitor(QWidget* w, int monitor) w->move(center - w->rect().center()); } +void GeometrySettings::centerOnParent(QWidget* w, QWidget* parent) +{ + if (!parent) { + parent = w->parentWidget(); + + if (!parent) { + parent = qApp->activeWindow(); + } + } + + if (parent && parent->isVisible()) { + const auto pr = parent->geometry(); + w->move(pr.center() - w->rect().center()); + } +} + void GeometrySettings::saveMainWindowMonitor(const QMainWindow* w) { if (auto* handle=w->windowHandle()) { diff --git a/src/settings.h b/src/settings.h index b5366911..ee6ff3fe 100644 --- a/src/settings.h +++ b/src/settings.h @@ -160,6 +160,11 @@ public: QStringList modInfoTabOrder() const; void setModInfoTabOrder(const QString& names); + // whether dialogs should be centered on their parent + // + bool centerDialogs() const; + void setCenterDialogs(bool b); + // assumes the given widget is a top-level // void centerOnMainWindowMonitor(QWidget* w); @@ -177,6 +182,7 @@ private: void ensureWindowOnScreen(QWidget* w) const; static void centerOnMonitor(QWidget* w, int monitor); + static void centerOnParent(QWidget* w, QWidget* parent=nullptr); }; diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui index 40079441..9d1e4da1 100644 --- a/src/settingsdialog.ui +++ b/src/settingsdialog.ui @@ -86,97 +86,23 @@ p, li { white-space: pre-wrap; } - User interface + User Interface - - - - - Colors - - - - - - 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. - - - 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. - - - Show mod list separator colors on the scrollbar - - - true - - - - - - - Plugin is Contained in selected Mod - - - - - - - Is overwritten (loose files) - - - - - - - Is overwriting (loose files) - - - - - - - Reset Colors - - - - - - - Mod Contains selected Plugin - - - - - - - Is overwritten (archive files) - - - - - - - Is overwriting (archive files) - - - - - - - - - - Modify the categories available to arrange your mods. + + + + + Dialogs will always be centered on the main window, but will remember their size. - Modify the categories available to arrange your mods. + Dialogs will always be centered on the main window, but will remember their size. - Configure Mod Categories + Always center dialogs - + @@ -195,36 +121,119 @@ p, li { white-space: pre-wrap; } - - + + - If checked, the download interface will be more compact. + Modify the categories available to arrange your mods. + + + Modify the categories available to arrange your mods. - Compact Download Interface + Configure Mod Categories - - - - Qt::Vertical + + + + + + + Download List + + + + + + If checked, the download interface will be more compact. - - - 20 - 40 - + + Compact List - + - + If checked, the download list will display meta information instead of file names. - Download Meta Information + Show Meta Information + + + + + + + + + + Colors + + + + + + 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. + + + 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. + + + Show mod list separator colors on the scrollbar + + + true + + + + + + + Plugin is Contained in selected Mod + + + + + + + Is overwritten (loose files) + + + + + + + Is overwriting (loose files) + + + + + + + Reset Colors + + + + + + + Mod Contains selected Plugin + + + + + + + Is overwritten (archive files) + + + + + + + Is overwriting (archive files) @@ -1411,7 +1420,6 @@ programs you are intentionally running. styleBox logLevelBox usePrereleaseBox - compactBox categoriesBtn baseDirEdit browseBaseDirBtn diff --git a/src/settingsdialoggeneral.cpp b/src/settingsdialoggeneral.cpp index 8ecdcbb9..ae924393 100644 --- a/src/settingsdialoggeneral.cpp +++ b/src/settingsdialoggeneral.cpp @@ -51,6 +51,7 @@ GeneralSettingsTab::GeneralSettingsTab(Settings& s, SettingsDialog& d) setContainsColor(settings().colors().modlistContainsPlugin()); setContainedColor(settings().colors().pluginListContained()); + ui->centerDialogs->setChecked(settings().geometry().centerDialogs()); ui->compactBox->setChecked(settings().interface().compactDownloads()); ui->showMetaBox->setChecked(settings().interface().metaDownloads()); ui->usePrereleaseBox->setChecked(settings().usePrereleases()); @@ -91,6 +92,7 @@ void GeneralSettingsTab::update() 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().setUsePrereleases(ui->usePrereleaseBox->isChecked()); -- cgit v1.3.1 From 088f27fe48cd8f218052090a97e8187eedf0c06e Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Mon, 23 Sep 2019 19:10:19 -0400 Subject: changed the layout of the general settings tab added option to disable checking for updates removed online check, just try it and see --- src/mainwindow.cpp | 16 ++++ src/mainwindow.h | 1 + src/organizercore.cpp | 36 ++------ src/organizercore.h | 1 + src/selfupdater.cpp | 12 ++- src/selfupdater.h | 14 ++- src/settings.cpp | 10 +++ src/settings.h | 5 ++ src/settingsdialog.ui | 203 ++++++++++++++++++++++++++---------------- src/settingsdialoggeneral.cpp | 2 + 10 files changed, 187 insertions(+), 113 deletions(-) (limited to 'src') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 42cbe919..cd650d2f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -263,6 +263,7 @@ MainWindow::MainWindow(Settings &settings setupToolbar(); toggleMO2EndorseState(); + toggleUpdateAction(); TaskProgressManager::instance().tryCreateTaskbar(); @@ -5007,6 +5008,7 @@ void MainWindow::on_actionSettings_triggered() bool oldDisplayForeign(settings.interface().displayForeign()); bool proxy = settings.network().useProxy(); DownloadManager *dlManager = m_OrganizerCore.downloadManager(); + const bool oldCheckForUpdates = settings.checkForUpdates(); SettingsDialog dialog(&m_PluginContainer, settings, this); @@ -5084,6 +5086,14 @@ void MainWindow::on_actionSettings_triggered() m_OrganizerCore.cycleDiagnostics(); toggleMO2EndorseState(); + + if (oldCheckForUpdates != settings.checkForUpdates()) { + toggleUpdateAction(); + + if (settings.checkForUpdates()) { + m_OrganizerCore.checkForUpdates(); + } + } } void MainWindow::on_actionNexus_triggered() @@ -5596,6 +5606,12 @@ void MainWindow::toggleMO2EndorseState() ui->actionEndorseMO->setStatusTip(text); } +void MainWindow::toggleUpdateAction() +{ + const auto& s = m_OrganizerCore.settings(); + ui->actionUpdate->setVisible(s.checkForUpdates()); +} + void MainWindow::nxmEndorsementsAvailable(QVariant userData, QVariant resultData, int) { QVariantList data = resultData.toList(); diff --git a/src/mainwindow.h b/src/mainwindow.h index 1f997ab1..524e2b6e 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -313,6 +313,7 @@ private: void sendSelectedPluginsToPriority(int newPriority); void toggleMO2EndorseState(); + void toggleUpdateAction(); private: diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 0da5b604..a4a89c99 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -74,25 +74,6 @@ using namespace MOBase; //static CrashDumpsType OrganizerCore::m_globalCrashDumpsType = CrashDumpsType::None; -static bool isOnline() -{ - const auto runningFlags = - QNetworkInterface::IsUp | QNetworkInterface::IsRunning; - - for (auto&& i : QNetworkInterface::allInterfaces()) { - if (!(i.flags() & QNetworkInterface::IsLoopBack)) { - if (i.flags() & runningFlags) { - auto addresses = i.addressEntries(); - if (!addresses.empty()) { - return true; - } - } - } - } - - return false; -} - static std::wstring getProcessName(HANDLE process) { wchar_t buffer[MAX_PATH]; @@ -307,14 +288,15 @@ void OrganizerCore::setUserInterface(IUserInterface *userInterface, m_InstallationManager.setParentWidget(widget); m_Updater.setUserInterface(widget); - if (userInterface != nullptr) { - // this currently wouldn't work reliably if the ui isn't initialized yet to - // display the result - if (isOnline() && !m_Settings.network().offlineMode()) { - m_Updater.testForUpdate(); - } else { - log::debug("user doesn't seem to be connected to the internet"); - } + checkForUpdates(); +} + +void OrganizerCore::checkForUpdates() +{ + // this currently wouldn't work reliably if the ui isn't initialized yet to + // display the result + if (m_UserInterface != nullptr) { + m_Updater.testForUpdate(m_Settings); } } diff --git a/src/organizercore.h b/src/organizercore.h index a14d79a9..5de550df 100644 --- a/src/organizercore.h +++ b/src/organizercore.h @@ -109,6 +109,7 @@ public: void updateExecutablesList(); + void checkForUpdates(); void startMOUpdate(); Settings &settings(); diff --git a/src/selfupdater.cpp b/src/selfupdater.cpp index 0ca39b19..8887927a 100644 --- a/src/selfupdater.cpp +++ b/src/selfupdater.cpp @@ -122,8 +122,18 @@ void SelfUpdater::setPluginContainer(PluginContainer *pluginContainer) m_Interface->setPluginContainer(pluginContainer); } -void SelfUpdater::testForUpdate() +void SelfUpdater::testForUpdate(const Settings& settings) { + if (settings.network().offlineMode()) { + log::debug("not checking for updates, in offline mode"); + return; + } + + if (!settings.checkForUpdates()) { + log::debug("not checking for updates, disabled"); + return; + } + // TODO: if prereleases are disabled we could just request the latest release // directly try { diff --git a/src/selfupdater.h b/src/selfupdater.h index bce49495..0c81efc5 100644 --- a/src/selfupdater.h +++ b/src/selfupdater.h @@ -37,7 +37,7 @@ namespace MOBase { class IPluginGame; } class QNetworkReply; class QProgressDialog; - +class Settings; /** * @brief manages updates for Mod Organizer itself @@ -80,6 +80,11 @@ public: void setPluginContainer(PluginContainer *pluginContainer); + /** + * @brief request information about the current version + **/ + void testForUpdate(const Settings& settings); + /** * @brief start the update process * @note this should not be called if there is no update available @@ -91,13 +96,6 @@ public: **/ MOBase::VersionInfo getVersion() const { return m_MOVersion; } -public slots: - - /** - * @brief request information about the current version - **/ - void testForUpdate(); - signals: /** diff --git a/src/settings.cpp b/src/settings.cpp index c3e8781e..462cd92a 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -178,6 +178,16 @@ QString Settings::filename() const return m_Settings.fileName(); } +bool Settings::checkForUpdates() const +{ + return get(m_Settings, "Settings", "check_for_updates", true); +} + +void Settings::setCheckForUpdates(bool b) +{ + set(m_Settings, "Settings", "check_for_updates", b); +} + bool Settings::usePrereleases() const { return get(m_Settings, "Settings", "use_prereleases", false); diff --git a/src/settings.h b/src/settings.h index ee6ff3fe..1556ba1e 100644 --- a/src/settings.h +++ b/src/settings.h @@ -692,6 +692,11 @@ public: bool archiveParsing() const; void setArchiveParsing(bool b); + // whether the user wants to check for updates + // + bool checkForUpdates() const; + void setCheckForUpdates(bool b); + // whether the user wants to upgrade to pre-releases // bool usePrereleases() const; diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui index 9d1e4da1..78bae6d7 100644 --- a/src/settingsdialog.ui +++ b/src/settingsdialog.ui @@ -7,7 +7,7 @@ 0 0 586 - 486 + 491 @@ -23,75 +23,67 @@ General - - - - - - - Language - - - - - - - The display language - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">The display language. This will only displaye languages for which you have a translation installed.</span></p></body></html> - - - - - - - - - - - Style - - - - - - - graphical style - - - graphical style of the MO user interface - - - - - - - - - Update to non-stable releases. - - - If this is enabled, the integrated update mechanism will notify of all releases, including pre-releases (alphas, betas). Please use this only if you're sufficiently tech-savvy to investigate issues, look for known problems in the issue tracker and create meaningful reports. + + + + + Qt::Vertical - - Install Pre-releases (Betas) + + + 0 + 0 + - + - + User Interface - - + + + + + Style + + + + + + + Language + + + + + + + The display language + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">The display language. This will only displaye languages for which you have a translation installed.</span></p></body></html> + + + + + + + graphical style + + + graphical style of the MO user interface + + + + - + Dialogs will always be centered on the main window, but will remember their size. @@ -102,7 +94,7 @@ p, li { white-space: pre-wrap; } - + @@ -121,7 +113,7 @@ p, li { white-space: pre-wrap; } - + Modify the categories available to arrange your mods. @@ -137,36 +129,49 @@ p, li { white-space: pre-wrap; } - + Download List - + - + - If checked, the download interface will be more compact. + If checked, the download list will display meta information instead of file names. - Compact List + Show Meta Information - + - If checked, the download list will display meta information instead of file names. + If checked, the download interface will be more compact. - Show Meta Information + Compact List + + + + Qt::Vertical + + + + 0 + 0 + + + + - + Colors @@ -240,6 +245,54 @@ p, li { white-space: pre-wrap; } + + + + Updates + + + + + + Mod Organizer checks for updates on Github on startup. + + + Mod Organizer checks for updates on Github on startup. + + + Check for updates + + + + + + + Update to non-stable releases. + + + If this is enabled, the integrated update mechanism will notify of all releases, including pre-releases (alphas, betas). Please use this only if you're sufficiently tech-savvy to investigate issues, look for known problems in the issue tracker and create meaningful reports. + + + Install Pre-releases (Betas) + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + @@ -1416,11 +1469,7 @@ programs you are intentionally running. - languageBox - styleBox logLevelBox - usePrereleaseBox - categoriesBtn baseDirEdit browseBaseDirBtn downloadDirEdit diff --git a/src/settingsdialoggeneral.cpp b/src/settingsdialoggeneral.cpp index ae924393..07aff4a1 100644 --- a/src/settingsdialoggeneral.cpp +++ b/src/settingsdialoggeneral.cpp @@ -54,6 +54,7 @@ GeneralSettingsTab::GeneralSettingsTab(Settings& s, SettingsDialog& d) 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()); @@ -95,6 +96,7 @@ void GeneralSettingsTab::update() 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()); settings().colors().setColorSeparatorScrollbar(ui->colorSeparatorsBox->isChecked()); } -- cgit v1.3.1 From 01b2a8201dbbb3e5ba8c09246a45cde4f11ed2bc Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Wed, 25 Sep 2019 18:24:08 -0400 Subject: replaced color buttons by a QTableWidget --- src/settingsdialog.ui | 237 ++++++++++++++++++----------- src/settingsdialoggeneral.cpp | 347 +++++++++++++++++++++++++++--------------- src/settingsdialoggeneral.h | 42 ++--- 3 files changed, 381 insertions(+), 245 deletions(-) (limited to 'src') 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 @@ User Interface - - - - - Style - - - - - - - Language - - - - - - - The display language - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Language + + + + + + + The display language + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">The display language. This will only displaye languages for which you have a translation installed.</span></p></body></html> - - - - - - - graphical style - - - graphical style of the MO user interface - + + + + + + + Style + + + + + + + graphical style + + + graphical style of the MO user interface + + + + - + Dialogs will always be centered on the main window, but will remember their size. @@ -94,7 +112,7 @@ p, li { white-space: pre-wrap; } - + @@ -113,7 +131,7 @@ p, li { white-space: pre-wrap; } - + Modify the categories available to arrange your mods. @@ -126,6 +144,19 @@ p, li { white-space: pre-wrap; } + + + + Qt::Vertical + + + + 0 + 0 + + + + @@ -176,70 +207,90 @@ p, li { white-space: pre-wrap; } Colors - - - - - 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. - - - 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. - - - Show mod list separator colors on the scrollbar + + + + + QAbstractItemView::NoEditTriggers - - true + + QAbstractItemView::SingleSelection - - - - - - Plugin is Contained in selected Mod + + QAbstractItemView::SelectRows - - - - - - Is overwritten (loose files) + + QAbstractItemView::ScrollPerPixel - - - - - - Is overwriting (loose files) - - - - - - - Reset Colors - - - - - - - Mod Contains selected Plugin - - - - - - - Is overwritten (archive files) + + false + + false + + + false + + + true + + + false + - - - - Is overwriting (archive files) - + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 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. + + + 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. + + + Show mod list separator colors on the scrollbar + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Reset Colors + + + + 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 get, + std::function 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 m_get; + std::function 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; + } + + const auto* item = dynamic_cast( + m_table->item(index.row(), index.column())); + + if (!item) { + return false; + } + + p->save(); + p->fillRect(option.rect, item->get()); + p->restore(); + + return true; + } +}; - if (currentID != -1) { - ui->styleBox->setCurrentIndex(currentID); + +template +void forEachColorItem(QTableWidget* table, F&& f) +{ + const auto rowCount = table->rowCount(); + + for (int i=0; i(table->item(i, 1))) { + f(item); } } +} + + +GeneralSettingsTab::GeneralSettingsTab(Settings& s, SettingsDialog& d) + : SettingsTab(s, d) +{ + addLanguages(); + selectLanguage(); + + addStyles(); + selectStyle(); + + setColorTable(); - //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()); - - setOverwritingColor(settings().colors().modlistOverwritingLoose()); - setOverwrittenColor(settings().colors().modlistOverwrittenLoose()); - setOverwritingArchiveColor(settings().colors().modlistOverwritingArchive()); - setOverwrittenArchiveColor(settings().colors().modlistOverwrittenArchive()); - setContainsColor(settings().colors().modlistContainsPlugin()); - setContainedColor(settings().colors().pluginListContained()); - - 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()); - - 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 get, + std::function 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(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); - - 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); + bool changed = false; + + 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 selectStyle(); + + void setColorTable(); + void resetDialogs(); - void setButtonColor(QPushButton *button, const QColor &color); - - 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 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 on_overwritingArchiveBtn_clicked(); - void on_overwritingBtn_clicked(); - void on_overwrittenArchiveBtn_clicked(); - void on_overwrittenBtn_clicked(); - void on_containedBtn_clicked(); - void on_containsBtn_clicked(); + + void addColor( + const QString& text, const QColor& defaultColor, + std::function get, + std::function commit); + + void onColorActivated(); void on_categoriesBtn_clicked(); void on_resetColorsBtn_clicked(); -- cgit v1.3.1 From 8237a1c47fa50ac9dd0f4a3fef26c0c40175fb9e Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Wed, 25 Sep 2019 18:39:37 -0400 Subject: use QStyleFactory to get default styles instead of hardcoding them don't display extensions in style combobox --- src/moapplication.cpp | 4 ++-- src/settingsdialoggeneral.cpp | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/moapplication.cpp b/src/moapplication.cpp index 79e931fb..a071d58b 100644 --- a/src/moapplication.cpp +++ b/src/moapplication.cpp @@ -132,8 +132,8 @@ bool MOApplication::notify(QObject *receiver, QEvent *event) void MOApplication::updateStyle(const QString &fileName) { - if (fileName == "Fusion") { - setStyle(QStyleFactory::create("fusion")); + if (QStyleFactory::keys().contains(fileName)) { + setStyle(QStyleFactory::create(fileName)); setStyleSheet(""); } else { setStyle(new ProxyStyle(QStyleFactory::create(m_DefaultStyle))); diff --git a/src/settingsdialoggeneral.cpp b/src/settingsdialoggeneral.cpp index be57101e..754d10cb 100644 --- a/src/settingsdialoggeneral.cpp +++ b/src/settingsdialoggeneral.cpp @@ -208,13 +208,24 @@ void GeneralSettingsTab::selectLanguage() void GeneralSettingsTab::addStyles() { ui->styleBox->addItem("None", ""); - ui->styleBox->addItem("Fusion", "Fusion"); + for (auto&& key : QStyleFactory::keys()) { + ui->styleBox->addItem(key, key); + } - QDirIterator langIter(QCoreApplication::applicationDirPath() + "/" + QString::fromStdWString(AppConfig::stylesheetsPath()), QStringList("*.qss"), QDir::Files); - while (langIter.hasNext()) { - langIter.next(); - QString style = langIter.fileName(); - ui->styleBox->addItem(style, style); + ui->styleBox->insertSeparator(ui->styleBox->count()); + + QDirIterator iter( + QCoreApplication::applicationDirPath() + "/" + + QString::fromStdWString(AppConfig::stylesheetsPath()), + QStringList("*.qss"), + QDir::Files); + + while (iter.hasNext()) { + iter.next(); + + ui->styleBox->addItem( + iter.fileInfo().completeBaseName(), + iter.fileName()); } } -- cgit v1.3.1 From 5d74bd3789515a3e04e54267f1cdfe8f5397f6df Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Wed, 25 Sep 2019 19:32:53 -0400 Subject: refactored addLanguages() a bit changed some of the tooltips --- src/settingsdialog.ui | 42 ++++++++++++++++++------------- src/settingsdialoggeneral.cpp | 57 ++++++++++++++++++++++++++++--------------- 2 files changed, 63 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui index 1ecf19f9..704e4134 100644 --- a/src/settingsdialog.ui +++ b/src/settingsdialog.ui @@ -68,14 +68,10 @@ - The display language + The language of the user interface. - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">The display language. This will only displaye languages for which you have a translation installed.</span></p></body></html> + The language of the user interface. @@ -89,10 +85,10 @@ p, li { white-space: pre-wrap; } - graphical style + Visual theme of the user interface. - graphical style of the MO user interface + Visual theme of the user interface. @@ -121,10 +117,10 @@ p, li { white-space: pre-wrap; } - Reset stored information from dialogs. + Reset all choices made in dialogs. - This will make all dialogs show up again where you checked the "Remember selection"-box. + Reset all choices made in dialogs. Reset Dialog Choices @@ -169,7 +165,10 @@ p, li { white-space: pre-wrap; } - If checked, the download list will display meta information instead of file names. + Show meta information instead of file names in the download list. + + + Show meta information instead of file names in the download list. Show Meta Information @@ -179,7 +178,10 @@ p, li { white-space: pre-wrap; } - If checked, the download interface will be more compact. + Make the download list more compact. + + + Make the download list more compact. Compact List @@ -257,10 +259,10 @@ p, li { white-space: pre-wrap; } - 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. + Colors set on separators will also be shown in the mod list scrollbar at the location of the separator. This can be useful for quickly navigating to a specific separator. - 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. + Colors set on separators will also be shown in the mod list scrollbar at the location of the separator. This can be useful for quickly navigating to a specific separator. Show mod list separator colors on the scrollbar @@ -285,6 +287,12 @@ p, li { white-space: pre-wrap; } + + Reset all colors to their default value. + + + Reset all colors to their default value. + Reset Colors @@ -305,10 +313,10 @@ p, li { white-space: pre-wrap; } - Mod Organizer checks for updates on Github on startup. + Check for Mod Organizer updates on Github on startup. - Mod Organizer checks for updates on Github on startup. + Check for Mod Organizer updates on Github on startup. Check for updates @@ -321,7 +329,7 @@ p, li { white-space: pre-wrap; } Update to non-stable releases. - If this is enabled, the integrated update mechanism will notify of all releases, including pre-releases (alphas, betas). Please use this only if you're sufficiently tech-savvy to investigate issues, look for known problems in the issue tracker and create meaningful reports. + Update to non-stable releases. Install Pre-releases (Betas) diff --git a/src/settingsdialoggeneral.cpp b/src/settingsdialoggeneral.cpp index 754d10cb..0dfd3a08 100644 --- a/src/settingsdialoggeneral.cpp +++ b/src/settingsdialoggeneral.cpp @@ -158,33 +158,52 @@ void GeneralSettingsTab::update() void GeneralSettingsTab::addLanguages() { + // matches the end of filenames for something like "_en.qm" or "_zh_CN.qm" + const QString pattern = + QString::fromStdWString(AppConfig::translationPrefix()) + + "_([a-z]{2,3}(_[A-Z]{2,2})?).qm"; + + const QRegExp exp(pattern); + + QDirIterator iter( + QCoreApplication::applicationDirPath() + "/translations", + QDir::Files); + std::vector> languages; - QDirIterator langIter(QCoreApplication::applicationDirPath() + "/translations", QDir::Files); - QString pattern = QString::fromStdWString(AppConfig::translationPrefix()) + "_([a-z]{2,3}(_[A-Z]{2,2})?).qm"; - QRegExp exp(pattern); - while (langIter.hasNext()) { - langIter.next(); - QString file = langIter.fileName(); - if (exp.exactMatch(file)) { - QString languageCode = exp.cap(1); - QLocale locale(languageCode); - QString languageString = QString("%1 (%2)").arg(locale.nativeLanguageName()).arg(locale.nativeCountryName()); //QLocale::languageToString(locale.language()); - if (locale.language() == QLocale::Chinese) { - if (languageCode == "zh_TW") { - languageString = "Chinese (traditional)"; - } else { - languageString = "Chinese (simplified)"; - } + while (iter.hasNext()) { + iter.next(); + + const QString file = iter.fileName(); + if (!exp.exactMatch(file)) { + continue; + } + + const QString languageCode = exp.cap(1); + const QLocale locale(languageCode); + + QString languageString = QString("%1 (%2)") + .arg(locale.nativeLanguageName()) + .arg(locale.nativeCountryName()); + + if (locale.language() == QLocale::Chinese) { + if (languageCode == "zh_TW") { + languageString = "Chinese (Traditional)"; + } else { + languageString = "Chinese (Simplified)"; } - languages.push_back(std::make_pair(QString("%1").arg(languageString), exp.cap(1))); } + + languages.push_back({languageString, exp.cap(1)}); } + if (!ui->languageBox->findText("English")) { - languages.push_back(std::make_pair(QString("English"), QString("en_US"))); + languages.push_back({QString("English"), QString("en_US")}); } + std::sort(languages.begin(), languages.end()); - for (const auto &lang : languages) { + + for (const auto& lang : languages) { ui->languageBox->addItem(lang.first, lang.second); } } -- cgit v1.3.1 From 51d664d76ce6b611e7a7585b209bad9d68fe65d7 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Fri, 27 Sep 2019 15:20:02 -0400 Subject: moved color stuff to ColorTable, now shows sample text and icons --- src/CMakeLists.txt | 3 + src/colortable.cpp | 278 ++++++++++++++++++++++++++++++++++++++++++ src/colortable.h | 28 +++++ src/icondelegate.cpp | 15 ++- src/icondelegate.h | 18 +-- src/modflagicondelegate.cpp | 114 +++++++++-------- src/modflagicondelegate.h | 11 +- src/settingsdialog.ui | 9 +- src/settingsdialoggeneral.cpp | 235 +++-------------------------------- src/settingsdialoggeneral.h | 9 -- 10 files changed, 421 insertions(+), 299 deletions(-) create mode 100644 src/colortable.cpp create mode 100644 src/colortable.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7c29ff48..b21d1a8b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -141,6 +141,7 @@ SET(organizer_SRCS envsecurity.cpp envshortcut.cpp envwindows.cpp + colortable.cpp shared/windows_error.cpp shared/error_report.cpp @@ -263,6 +264,7 @@ SET(organizer_HDRS envsecurity.h envshortcut.h envwindows.h + colortable.h shared/windows_error.h shared/error_report.h @@ -473,6 +475,7 @@ set(utilities ) set(widgets + colortable genericicondelegate filerenamer filterwidget diff --git a/src/colortable.cpp b/src/colortable.cpp new file mode 100644 index 00000000..7546abe5 --- /dev/null +++ b/src/colortable.cpp @@ -0,0 +1,278 @@ +#include "colortable.h" +#include "modflagicondelegate.h" +#include "settings.h" + +class ColorItem; +ColorItem* colorItemForRow(QTableWidget* table, int row); + +void paintBackground( + QTableWidget* table, QPainter* p, const QStyleOptionViewItem& option, + const QModelIndex& index); + + +class ColoredBackgroundDelegate : public QStyledItemDelegate +{ +public: + ColoredBackgroundDelegate(QTableWidget* table) + : m_table(table) + { + } + + void paint( + QPainter* p, const QStyleOptionViewItem& option, + const QModelIndex& index) const override + { + paintBackground(m_table, p, option, index); + + QStyleOptionViewItem itemOption(option); + initStyleOption(&itemOption, index); + itemOption.state = QStyle::State_Enabled; + + QStyledItemDelegate::paint(p, itemOption, index); + } + +private: + QTableWidget* m_table; +}; + + +class FakeModFlagIconDelegate : public ModFlagIconDelegate +{ +public: + explicit FakeModFlagIconDelegate(QTableWidget* table) + : m_table(table) + { + } + + void paint( + QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const override + { + paintBackground(m_table, painter, option, index); + ModFlagIconDelegate::paintIcons(painter, option, index, getIcons(index)); + } + +protected: + QList getIcons(const QModelIndex &index) const override + { + const auto flags = { + ModInfo::FLAG_CONFLICT_MIXED, + ModInfo::FLAG_ARCHIVE_LOOSE_CONFLICT_OVERWRITE, + ModInfo::FLAG_ARCHIVE_LOOSE_CONFLICT_OVERWRITTEN, + ModInfo::FLAG_ARCHIVE_CONFLICT_MIXED, + ModInfo::FLAG_BACKUP, + ModInfo::FLAG_NOTENDORSED, + ModInfo::FLAG_NOTES, + ModInfo::FLAG_ALTERNATE_GAME + }; + + return getIconsForFlags(flags, false); + } + + size_t getNumIcons(const QModelIndex &index) const override + { + return getIcons(index).size(); + } + +private: + QTableWidget* m_table; +}; + + +class ColorItem : public QTableWidgetItem +{ +public: + ColorItem( + QString caption, QColor defaultColor, + std::function get, + std::function commit) : + m_caption(std::move(caption)), m_default(defaultColor), + m_get(get), m_commit(commit) + { + setText(m_caption); + set(get()); + } + + const QString& caption() const + { + return m_caption; + } + + QColor get() const + { + return m_temp; + } + + bool set(const QColor& c) + { + if (m_temp != c) { + m_temp = c; + return true; + } + + return false; + } + + void commit() + { + m_commit(m_temp); + } + + bool reset() + { + return set(m_default); + } + +private: + const QString m_caption; + const QColor m_default; + std::function m_get; + std::function m_commit; + QColor m_temp; +}; + + +ColorItem* colorItemForRow(QTableWidget* table, int row) +{ + return dynamic_cast(table->item(row, 0)); +} + +template +void forEachColorItem(QTableWidget* table, F&& f) +{ + const auto rowCount = table->rowCount(); + + for (int i=0; isave(); + p->fillRect(option.rect, ci->get()); + p->restore(); + } +} + + +ColorTable::ColorTable(QWidget* parent) + : QTableWidget(parent), m_settings(nullptr) +{ + setColumnCount(3); + setHorizontalHeaderLabels({"", "", ""}); + + setItemDelegateForColumn(1, new ColoredBackgroundDelegate(this)); + setItemDelegateForColumn(2, new FakeModFlagIconDelegate(this)); + + connect( + this, &QTableWidget::cellActivated, + [&]{ onColorActivated(); }); +} + +void ColorTable::load(Settings& s) +{ + m_settings = &s; + + addColor( + QObject::tr("Is overwritten (loose files)"), + QColor(0, 255, 0, 64), + [this]{ return m_settings->colors().modlistOverwrittenLoose(); }, + [this](auto&& v){ m_settings->colors().setModlistOverwrittenLoose(v); }); + + addColor( + QObject::tr("Is overwriting (loose files)"), + QColor(255, 0, 0, 64), + [this]{ return m_settings->colors().modlistOverwritingLoose(); }, + [this](auto&& v){ m_settings->colors().setModlistOverwritingLoose(v); }); + + addColor( + QObject::tr("Is overwritten (archives)"), + QColor(0, 255, 255, 64), + [this]{ return m_settings->colors().modlistOverwrittenArchive(); }, + [this](auto&& v){ m_settings->colors().setModlistOverwrittenArchive(v); }); + + addColor( + QObject::tr("Is overwriting (archives)"), + QColor(255, 0, 255, 64), + [this]{ return m_settings->colors().modlistOverwritingArchive(); }, + [this](auto&& v){ m_settings->colors().setModlistOverwritingArchive(v); }); + + addColor( + QObject::tr("Mod contains selected plugin"), + QColor(0, 0, 255, 64), + [this]{ return m_settings->colors().modlistContainsPlugin(); }, + [this](auto&& v){ m_settings->colors().setModlistContainsPlugin(v); }); + + addColor( + QObject::tr("Plugin is contained in selected mod"), + QColor(0, 0, 255, 64), + [this]{ return m_settings->colors().pluginListContained(); }, + [this](auto&& v){ m_settings->colors().setPluginListContained(v); }); +} + +void ColorTable::resetColors() +{ + bool changed = false; + + forEachColorItem(this, [&](auto* item) { + if (item->reset()) { + changed = true; + } + }); + + if (changed) { + update(); + } +} + +void ColorTable::commitColors() +{ + forEachColorItem(this, [](auto* item) { + item->commit(); + }); +} + +void ColorTable::addColor( + const QString& text, const QColor& defaultColor, + std::function get, + std::function commit) +{ + const auto r = rowCount(); + setRowCount(r + 1); + + auto* item = new ColorItem(text, defaultColor, get, commit); + + setItem(r, 0, item); + setItem(r, 1, new QTableWidgetItem("Text")); + setItem(r, 2, new QTableWidgetItem); + + resizeColumnsToContents(); +} + +void ColorTable::onColorActivated() +{ + const auto rows = selectionModel()->selectedRows(); + if (rows.isEmpty()) { + return; + } + + const auto row = rows[0].row(); + auto* ci = colorItemForRow(this, row); + if (!ci) { + return; + } + + const QColor result = QColorDialog::getColor( + ci->get(), topLevelWidget(), ci->caption(), QColorDialog::ShowAlphaChannel); + + if (result.isValid()) { + ci->set(result); + update(model()->index(row, 1)); + } +} diff --git a/src/colortable.h b/src/colortable.h new file mode 100644 index 00000000..c2b64a4d --- /dev/null +++ b/src/colortable.h @@ -0,0 +1,28 @@ +#ifndef COLORTABLE_H +#define COLORTABLE_H + +#include + +class Settings; + +class ColorTable : public QTableWidget +{ +public: + ColorTable(QWidget* parent=nullptr); + + void load(Settings& s); + void resetColors(); + void commitColors(); + +private: + Settings* m_settings; + + void addColor( + const QString& text, const QColor& defaultColor, + std::function get, + std::function commit); + + void onColorActivated(); +}; + +#endif // COLORTABLE_H diff --git a/src/icondelegate.cpp b/src/icondelegate.cpp index 39038f3c..03964263 100644 --- a/src/icondelegate.cpp +++ b/src/icondelegate.cpp @@ -32,13 +32,10 @@ IconDelegate::IconDelegate(QObject *parent) { } - -void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +void IconDelegate::paintIcons( + QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index, const QList& icons) { - QStyledItemDelegate::paint(painter, option, index); - - QList icons = getIcons(index); - int x = 4; painter->save(); @@ -67,3 +64,9 @@ void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, painter->restore(); } +void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + QStyledItemDelegate::paint(painter, option, index); + paintIcons(painter, option, index, getIcons(index)); +} + diff --git a/src/icondelegate.h b/src/icondelegate.h index 39694481..bac71a62 100644 --- a/src/icondelegate.h +++ b/src/icondelegate.h @@ -27,25 +27,19 @@ along with Mod Organizer. If not, see . class IconDelegate : public QStyledItemDelegate { - Q_OBJECT -public: + Q_OBJECT; +public: explicit IconDelegate(QObject *parent = 0); - virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; -signals: - -public slots: - -private: + static void paintIcons( + QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index, const QList& icons); +protected: virtual QList getIcons(const QModelIndex &index) const = 0; virtual size_t getNumIcons(const QModelIndex &index) const = 0; - - -private: - }; #endif // ICONDELEGATE_H diff --git a/src/modflagicondelegate.cpp b/src/modflagicondelegate.cpp index 7110a590..a5e9aa22 100644 --- a/src/modflagicondelegate.cpp +++ b/src/modflagicondelegate.cpp @@ -31,72 +31,82 @@ void ModFlagIconDelegate::columnResized(int logicalIndex, int, int newSize) } } -QList ModFlagIconDelegate::getIcons(const QModelIndex &index) const { +QList ModFlagIconDelegate::getIconsForFlags( + std::vector flags, bool compact) +{ QList result; - QVariant modid = index.data(Qt::UserRole + 1); - if (modid.isValid()) { - ModInfo::Ptr info = ModInfo::getByIndex(modid.toInt()); - std::vector flags = info->getFlags(); - // Don't do flags for overwrite - if (std::find(flags.begin(), flags.end(),ModInfo::FLAG_OVERWRITE) != flags.end()) - return result; - - // insert conflict icons to provide nicer alignment - { // insert loose file conflicts first - auto iter = std::find_first_of(flags.begin(), flags.end(), - m_ConflictFlags, m_ConflictFlags + 4); - if (iter != flags.end()) { - result.append(getFlagIcon(*iter)); - flags.erase(iter); - } else if (!m_Compact) { - result.append(QString()); - } + // Don't do flags for overwrite + if (std::find(flags.begin(), flags.end(),ModInfo::FLAG_OVERWRITE) != flags.end()) + return result; + + // insert conflict icons to provide nicer alignment + { // insert loose file conflicts first + auto iter = std::find_first_of(flags.begin(), flags.end(), + m_ConflictFlags, m_ConflictFlags + 4); + if (iter != flags.end()) { + result.append(getFlagIcon(*iter)); + flags.erase(iter); + } else if (!compact) { + result.append(QString()); } + } - { // insert loose vs archive overwrite second - auto iter = std::find(flags.begin(), flags.end(), - ModInfo::FLAG_ARCHIVE_LOOSE_CONFLICT_OVERWRITE); - if (iter != flags.end()) { - result.append(getFlagIcon(*iter)); - flags.erase(iter); - } else if (!m_Compact) { - result.append(QString()); - } + { // insert loose vs archive overwrite second + auto iter = std::find(flags.begin(), flags.end(), + ModInfo::FLAG_ARCHIVE_LOOSE_CONFLICT_OVERWRITE); + if (iter != flags.end()) { + result.append(getFlagIcon(*iter)); + flags.erase(iter); + } else if (!compact) { + result.append(QString()); } + } - { // insert loose vs archive overwritten third - auto iter = std::find_first_of(flags.begin(), flags.end(), - m_ArchiveLooseConflictFlags + 1, m_ArchiveLooseConflictFlags + 2); - if (iter != flags.end()) { - result.append(getFlagIcon(*iter)); - flags.erase(iter); - } else if (!m_Compact) { - result.append(QString()); - } + { // insert loose vs archive overwritten third + auto iter = std::find_first_of(flags.begin(), flags.end(), + m_ArchiveLooseConflictFlags + 1, m_ArchiveLooseConflictFlags + 2); + if (iter != flags.end()) { + result.append(getFlagIcon(*iter)); + flags.erase(iter); + } else if (!compact) { + result.append(QString()); } + } - { // insert archive conflicts last - auto iter = std::find_first_of(flags.begin(), flags.end(), - m_ArchiveConflictFlags, m_ArchiveConflictFlags + 3); - if (iter != flags.end()) { - result.append(getFlagIcon(*iter)); - flags.erase(iter); - } else if (!m_Compact) { - result.append(QString()); - } + { // insert archive conflicts last + auto iter = std::find_first_of(flags.begin(), flags.end(), + m_ArchiveConflictFlags, m_ArchiveConflictFlags + 3); + if (iter != flags.end()) { + result.append(getFlagIcon(*iter)); + flags.erase(iter); + } else if (!compact) { + result.append(QString()); } + } - for (auto iter = flags.begin(); iter != flags.end(); ++iter) { - auto iconPath = getFlagIcon(*iter); - if (!iconPath.isEmpty()) - result.append(iconPath); - } + for (auto iter = flags.begin(); iter != flags.end(); ++iter) { + auto iconPath = getFlagIcon(*iter); + if (!iconPath.isEmpty()) + result.append(iconPath); } + return result; } -QString ModFlagIconDelegate::getFlagIcon(ModInfo::EFlag flag) const +QList ModFlagIconDelegate::getIcons(const QModelIndex &index) const +{ + QVariant modid = index.data(Qt::UserRole + 1); + + if (modid.isValid()) { + ModInfo::Ptr info = ModInfo::getByIndex(modid.toInt()); + return getIconsForFlags(info->getFlags(), m_Compact); + } + + return {}; +} + +QString ModFlagIconDelegate::getFlagIcon(ModInfo::EFlag flag) { switch (flag) { case ModInfo::FLAG_BACKUP: return QStringLiteral(":/MO/gui/emblem_backup"); diff --git a/src/modflagicondelegate.h b/src/modflagicondelegate.h index eb6a76ab..4f22dd90 100644 --- a/src/modflagicondelegate.h +++ b/src/modflagicondelegate.h @@ -5,21 +5,24 @@ class ModFlagIconDelegate : public IconDelegate { -Q_OBJECT + Q_OBJECT; public: explicit ModFlagIconDelegate(QObject *parent = 0, int logicalIndex = -1, int compactSize = 120); virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; + static QList getIconsForFlags( + std::vector flags, bool compact); + + static QString getFlagIcon(ModInfo::EFlag flag); + public slots: void columnResized(int logicalIndex, int oldSize, int newSize); -private: +protected: virtual QList getIcons(const QModelIndex &index) const; virtual size_t getNumIcons(const QModelIndex &index) const; - QString getFlagIcon(ModInfo::EFlag flag) const; - private: static ModInfo::EFlag m_ConflictFlags[4]; static ModInfo::EFlag m_ArchiveLooseConflictFlags[2]; diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui index 704e4134..fba65545 100644 --- a/src/settingsdialog.ui +++ b/src/settingsdialog.ui @@ -211,7 +211,7 @@ - + QAbstractItemView::NoEditTriggers @@ -1527,6 +1527,13 @@ programs you are intentionally running. + + + ColorTable + QTableWidget +
colortable.h
+
+
logLevelBox baseDirEdit diff --git a/src/settingsdialoggeneral.cpp b/src/settingsdialoggeneral.cpp index 0dfd3a08..a9ec5cae 100644 --- a/src/settingsdialoggeneral.cpp +++ b/src/settingsdialoggeneral.cpp @@ -2,114 +2,9 @@ #include "ui_settingsdialog.h" #include "appconfig.h" #include "categoriesdialog.h" +#include "colortable.h" #include -using MOBase::QuestionBoxMemory; - - -class ColorItem : public QTableWidgetItem -{ -public: - ColorItem( - const QColor& defaultColor, - std::function get, - std::function commit) - : m_default(defaultColor), m_get(get), m_commit(commit) - { - set(get()); - } - - QColor get() const - { - return m_temp; - } - - bool set(const QColor& c) - { - if (m_temp != c) { - m_temp = c; - return true; - } - - return false; - } - - void commit() - { - m_commit(m_temp); - } - - bool reset() - { - return set(m_default); - } - -private: - const QColor m_default; - std::function m_get; - std::function 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); - } - } - -private: - QTableWidget* m_table; - - bool paintColor( - QPainter* p, const QStyleOptionViewItem& option, - const QModelIndex& index) const - { - if (index.column() != 1) { - return false; - } - - const auto* item = dynamic_cast( - m_table->item(index.row(), index.column())); - - if (!item) { - return false; - } - - p->save(); - p->fillRect(option.rect, item->get()); - p->restore(); - - return true; - } -}; - - -template -void forEachColorItem(QTableWidget* table, F&& f) -{ - const auto rowCount = table->rowCount(); - - for (int i=0; i(table->item(i, 1))) { - f(item); - } - } -} - - GeneralSettingsTab::GeneralSettingsTab(Settings& s, SettingsDialog& d) : SettingsTab(s, d) { @@ -119,17 +14,26 @@ GeneralSettingsTab::GeneralSettingsTab(Settings& s, SettingsDialog& d) addStyles(); selectStyle(); - setColorTable(); + ui->colorTable->load(s); - 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(); }); + 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(); }); } void GeneralSettingsTab::update() { const QString oldLanguage = settings().interface().language(); - const QString newLanguage = ui->languageBox->itemData(ui->languageBox->currentIndex()).toString(); + const QString newLanguage = ui->languageBox->itemData( + ui->languageBox->currentIndex()).toString(); if (newLanguage != oldLanguage) { settings().interface().setLanguage(newLanguage); @@ -137,7 +41,9 @@ void GeneralSettingsTab::update() } const QString oldStyle = settings().interface().styleName().value_or(""); - const QString newStyle = ui->styleBox->itemData(ui->styleBox->currentIndex()).toString(); + const QString newStyle = ui->styleBox->itemData( + ui->styleBox->currentIndex()).toString(); + if (oldStyle != newStyle) { settings().interface().setStyleName(newStyle); emit settings().styleChanged(newStyle); @@ -149,9 +55,7 @@ void GeneralSettingsTab::update() settings().setCheckForUpdates(ui->checkForUpdates->isChecked()); settings().setUsePrereleases(ui->usePrereleaseBox->isChecked()); - forEachColorItem(ui->colorTable, [](auto* item) { - item->commit(); - }); + ui->colorTable->commitColors(); settings().colors().setColorSeparatorScrollbar(ui->colorSeparatorsBox->isChecked()); } @@ -258,113 +162,14 @@ void GeneralSettingsTab::selectStyle() } } -void GeneralSettingsTab::setColorTable() -{ - ui->colorTable->setColumnCount(2); - ui->colorTable->setHorizontalHeaderLabels({ - QObject::tr("Item"), QObject::tr("Color") - }); - - 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::addColor( - const QString& text, const QColor& defaultColor, - std::function get, - std::function commit) -{ - 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::resetDialogs() { settings().widgets().resetQuestionButtons(); } -void GeneralSettingsTab::onColorActivated() -{ - const auto rows = ui->colorTable->selectionModel()->selectedRows(); - if (rows.isEmpty()) { - return; - } - - const auto row = rows[0].row(); - - const auto text = ui->colorTable->item(row, 0)->text(); - auto* item = dynamic_cast(ui->colorTable->item(row, 1)); - - if (!item) { - return; - } - - const QColor result = QColorDialog::getColor( - item->get(), &dialog(), text, QColorDialog::ShowAlphaChannel); - - if (result.isValid()) { - item->set(result); - ui->colorTable->update(ui->colorTable->model()->index(row, 1)); - } -} - void GeneralSettingsTab::on_resetColorsBtn_clicked() { - bool changed = false; - - forEachColorItem(ui->colorTable, [&](auto* item) { - if (item->reset()) { - changed = true; - } - }); - - if (changed) { - ui->colorTable->update(); - } + ui->colorTable->resetColors(); } void GeneralSettingsTab::on_resetDialogsButton_clicked() diff --git a/src/settingsdialoggeneral.h b/src/settingsdialoggeneral.h index 1f7fafff..706ba9ef 100644 --- a/src/settingsdialoggeneral.h +++ b/src/settingsdialoggeneral.h @@ -18,17 +18,8 @@ private: void addStyles(); void selectStyle(); - void setColorTable(); - void resetDialogs(); - void addColor( - const QString& text, const QColor& defaultColor, - std::function get, - std::function commit); - - void onColorActivated(); - void on_categoriesBtn_clicked(); void on_resetColorsBtn_clicked(); void on_resetDialogsButton_clicked(); -- cgit v1.3.1 From ec48a6d79665915b07f11f93a834fbec7fc09c45 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Fri, 27 Sep 2019 15:26:00 -0400 Subject: a few comments for ColorTable --- src/colortable.cpp | 31 ++++++++++++++++++++++++------- src/colortable.h | 11 +++++++++++ 2 files changed, 35 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/colortable.cpp b/src/colortable.cpp index 7546abe5..61c5ee5f 100644 --- a/src/colortable.cpp +++ b/src/colortable.cpp @@ -10,6 +10,8 @@ void paintBackground( const QModelIndex& index); +// delegate for the sample text column; paints the background color +// class ColoredBackgroundDelegate : public QStyledItemDelegate { public: @@ -26,6 +28,9 @@ public: QStyleOptionViewItem itemOption(option); initStyleOption(&itemOption, index); + + // paint the default stuff like text, but override the state to avoid + // destroying the background for selected items, etc. itemOption.state = QStyle::State_Enabled; QStyledItemDelegate::paint(p, itemOption, index); @@ -36,6 +41,8 @@ private: }; +// delegate for the icons column; paints the background and icons +// class FakeModFlagIconDelegate : public ModFlagIconDelegate { public: @@ -79,6 +86,8 @@ private: }; +// item used in the first column of the table +// class ColorItem : public QTableWidgetItem { public: @@ -93,16 +102,22 @@ public: set(get()); } + // color caption + // const QString& caption() const { return m_caption; } + // the current color + // QColor get() const { return m_temp; } + // sets the current color, commit() must be called to save it + // bool set(const QColor& c) { if (m_temp != c) { @@ -113,14 +128,18 @@ public: return false; } - void commit() + // resets the current color, commit() must be called to save it + // + bool reset() { - m_commit(m_temp); + return set(m_default); } - bool reset() + // saves the current color + // + void commit() { - return set(m_default); + m_commit(m_temp); } private: @@ -246,9 +265,7 @@ void ColorTable::addColor( const auto r = rowCount(); setRowCount(r + 1); - auto* item = new ColorItem(text, defaultColor, get, commit); - - setItem(r, 0, item); + setItem(r, 0, new ColorItem(text, defaultColor, get, commit)); setItem(r, 1, new QTableWidgetItem("Text")); setItem(r, 2, new QTableWidgetItem); diff --git a/src/colortable.h b/src/colortable.h index c2b64a4d..039b6024 100644 --- a/src/colortable.h +++ b/src/colortable.h @@ -5,13 +5,24 @@ class Settings; +// a QTableWidget to view and modify color settings +// class ColorTable : public QTableWidget { public: ColorTable(QWidget* parent=nullptr); + // adds colors to the table from the settings + // void load(Settings& s); + + // resets the colors to their default values; commitColors() must be called + // to save them + // void resetColors(); + + // commits any changes + // void commitColors(); private: -- cgit v1.3.1 From 75941afd34bc61e8d52863a9c765ccf8480ac389 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Wed, 2 Oct 2019 18:28:31 -0400 Subject: fixed checkboxes not being set when opening the settings dialog --- src/settingsdialoggeneral.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/settingsdialoggeneral.cpp b/src/settingsdialoggeneral.cpp index a9ec5cae..e21fc5d0 100644 --- a/src/settingsdialoggeneral.cpp +++ b/src/settingsdialoggeneral.cpp @@ -16,6 +16,13 @@ GeneralSettingsTab::GeneralSettingsTab(Settings& s, SettingsDialog& d) ui->colorTable->load(s); + 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()); + QObject::connect( ui->categoriesBtn, &QPushButton::clicked, [&]{ on_categoriesBtn_clicked(); }); @@ -49,14 +56,13 @@ void GeneralSettingsTab::update() emit settings().styleChanged(newStyle); } + ui->colorTable->commitColors(); + 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()); - - ui->colorTable->commitColors(); - settings().colors().setColorSeparatorScrollbar(ui->colorSeparatorsBox->isChecked()); } -- cgit v1.3.1 From 239cfbe6854f727b5dd3e6922cacc17587361cf5 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Fri, 4 Oct 2019 06:29:23 -0400 Subject: explicit tab order, seems to fix hang when switching tabs --- src/settingsdialog.ui | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui index fba65545..0ecbd101 100644 --- a/src/settingsdialog.ui +++ b/src/settingsdialog.ui @@ -1535,7 +1535,19 @@ programs you are intentionally running. - logLevelBox + tabWidget + languageBox + styleBox + centerDialogs + resetDialogsButton + categoriesBtn + showMetaBox + compactBox + checkForUpdates + usePrereleaseBox + colorTable + colorSeparatorsBox + resetColorsBtn baseDirEdit browseBaseDirBtn downloadDirEdit @@ -1548,7 +1560,18 @@ programs you are intentionally running. browseProfilesDirBtn overwriteDirEdit browseOverwriteDirBtn + managedGameDirEdit + browseGameDirBtn + nexusConnect + nexusManualKey + nexusDisconnect + nexusLog + offlineBox + endorsementBox + proxyBox + hideAPICounterBox associateButton + clearCacheButton knownServersList preferredServersList steamUserEdit @@ -1558,8 +1581,17 @@ programs you are intentionally running. pluginBlacklist appIDEdit mechanismBox + hideUncheckedBox + forceEnableBox + lockGUIBox + displayForeignBox + enableArchiveParsingBox bsaDateBtn - tabWidget + execBlacklistBtn + resetGeometryBtn + logLevelBox + dumpsTypeBox + dumpsMaxEdit -- cgit v1.3.1