Skip to content

Commit

Permalink
Merge branch '1754-mac-auto-theme' into '1.5.x-release'
Browse files Browse the repository at this point in the history
fix mac auto theme

See merge request devel/studio!734
  • Loading branch information
rgoltermann committed Feb 19, 2021
2 parents 66ec0ff + 31ca922 commit 03da6f0
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Version 1.5.4 *
- fixed FIL marker in LOG doesn't handle relative filepaths
- parse port for GAMS Engine URL
- fixed syntax highlighting for standard eolCom in table definition
- instantly follow macOS theme changes (delayed on visible settings dialog)

Version 1.5.3
==================
Expand Down
15 changes: 11 additions & 4 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ MainWindow::MainWindow(QWidget *parent)
ViewHelper::changeAppearance();
connect(Theme::instance(), &Theme::changed, this, &MainWindow::invalidateTheme);
invalidateTheme();
ViewHelper::updateBaseTheme();
initGamsStandardPaths();
updateRunState();

Expand Down Expand Up @@ -448,10 +449,11 @@ bool MainWindow::event(QEvent *event)
} else if (event->type() == QEvent::WindowActivate) {
processFileEvents();
} else if (event->type() == QEvent::ApplicationPaletteChange) {
#ifdef __APPLE__
// reload theme when switching OS theme
Theme::instance()->setActiveTheme(MacOSCocoaBridge::isDarkMode() ? 1 : 0);
#endif
if (!mSettingsDialog || !mSettingsDialog->preventThemeChaning())
ViewHelper::updateBaseTheme();
else {
mSettingsDialog->delayBaseThemeChange(true);
}
}
return QMainWindow::event(event);
}
Expand Down Expand Up @@ -3742,6 +3744,11 @@ void MainWindow::on_actionSettings_triggered()
connect(mSettingsDialog, &SettingsDialog::editorLineWrappingChanged, this, &MainWindow::updateEditorLineWrapping);
connect(mSettingsDialog, &SettingsDialog::finished, this, [this]() {
updateAndSaveSettings();
if (mSettingsDialog->hasDelayedBaseThemeChange()) {
mSettingsDialog->delayBaseThemeChange(false);
ViewHelper::updateBaseTheme();
}

if (mSettingsDialog->miroSettingsEnabled())
updateMiroEnabled();
});
Expand Down
19 changes: 16 additions & 3 deletions src/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
#include "themewidget.h"
#include "viewhelper.h"

#ifdef __APPLE__
#include "../platform/macos/macoscocoabridge.h"
#endif

namespace gams {
namespace studio {
Expand Down Expand Up @@ -194,6 +191,17 @@ void SettingsDialog::setMiroSettingsEnabled(bool enabled)
ui->miroBrowseButton->setEnabled(enabled);
}

bool SettingsDialog::preventThemeChaning()
{
if (isVisible()) return true;
return false;
}

bool SettingsDialog::hasDelayedBaseThemeChange()
{
return mDelayedBaseThemeChange;
}

// save settings from ui to qsettings
void SettingsDialog::saveSettings()
{
Expand Down Expand Up @@ -377,6 +385,11 @@ bool SettingsDialog::eventFilter(QObject *watched, QEvent *event)
return false;
}

void SettingsDialog::delayBaseThemeChange(bool valid)
{
mDelayedBaseThemeChange = valid;
}

SettingsDialog::~SettingsDialog()
{
mSettings->unblock();
Expand Down
6 changes: 6 additions & 0 deletions src/settingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class SettingsDialog : public QDialog

bool miroSettingsEnabled() const;
void setMiroSettingsEnabled(bool enabled);
bool preventThemeChaning();
bool hasDelayedBaseThemeChange();

protected:
void closeEvent(QCloseEvent *event) override;
Expand All @@ -55,6 +57,9 @@ class SettingsDialog : public QDialog
void editorLineWrappingChanged();
void themeChanged();

public slots:
void delayBaseThemeChange(bool valid);

private slots:
void on_buttonBox_clicked(QAbstractButton *button);
void on_tabWidget_currentChanged(int index);
Expand Down Expand Up @@ -88,6 +93,7 @@ private slots:
bool mInitializing = true;
QList<ThemeWidget*> mColorWidgets;
int mFixedThemeCount = 0;
bool mDelayedBaseThemeChange = false;
bool mMiroSettingsEnabled = true;

void saveSettings();
Expand Down
17 changes: 17 additions & 0 deletions src/viewhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include "colors/palettemanager.h"
#include "settings.h"

#ifdef __APPLE__
#include "../platform/macos/macoscocoabridge.h"
#endif

#include <QVariant>

namespace gams {
Expand Down Expand Up @@ -89,6 +93,19 @@ void ViewHelper::setLocation(QWidget *widget, QString location)
}
}

bool ViewHelper::updateBaseTheme()
{
int currentTheme = Theme::instance()->activeTheme();
#ifdef __APPLE__
Theme::instance()->setActiveTheme(MacOSCocoaBridge::isDarkMode() ? 1 : 0);
if (currentTheme != Theme::instance()->activeTheme()) {
Settings::settings()->setInt(skEdAppearance, Theme::instance()->activeTheme());
Settings::settings()->save();
}
#endif
return currentTheme != Theme::instance()->activeTheme();
}

///
/// \brief ViewHelper::setAppearance sets and saves the appearance
/// \param appearance
Expand Down
1 change: 1 addition & 0 deletions src/viewhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class ViewHelper
<< "Text files (*.txt)"
<< "All files (*.*)";
}
static bool updateBaseTheme();
static void setAppearance(int appearance = -1);
static void changeAppearance(int appearance = -1);

Expand Down

0 comments on commit 03da6f0

Please sign in to comment.