Skip to content

Commit

Permalink
Merge pull request #458 from ghutchis/set-tool-icons
Browse files Browse the repository at this point in the history
Fixes for new SVG icons and setting dark / light mode on tools
  • Loading branch information
ghutchis authored Jan 18, 2024
2 parents eed3c8a + 1093d70 commit 09fb213
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion avogadro/lastinstall/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if((APPLE OR WIN32) AND NOT ${CMAKE_VERSION} VERSION_LESS 2.8.8)
list(APPEND plugins ${location})
endforeach()
else()
foreach(qt_plugin Qt5::QJpegPlugin Qt5::QWbmpPlugin Qt5::QWebpPlugin Qt5::QGifPlugin)
foreach(qt_plugin Qt5::QSvgPlugin Qt5::QJpegPlugin Qt5::QWbmpPlugin Qt5::QWebpPlugin Qt5::QGifPlugin)
get_property(location TARGET ${qt_plugin} PROPERTY LOCATION_RELEASE)
list(APPEND plugins ${location})
endforeach()
Expand Down
9 changes: 9 additions & 0 deletions avogadro/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include <QtGui/QCloseEvent>
#include <QtGui/QDesktopServices>
#include <QtGui/QKeySequence>
#include <QtGui/QPalette>

#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
Expand Down Expand Up @@ -2178,12 +2179,20 @@ void MainWindow::buildTools()
{
PluginManager* plugin = PluginManager::instance();

// determine if need dark mode or light mode icons
// e.g. https://www.qt.io/blog/dark-mode-on-windows-11-with-qt-6.5
const QPalette defaultPalette;
// is the text lighter than the window color?
bool darkMode = (defaultPalette.color(QPalette::WindowText).lightness() >
defaultPalette.color(QPalette::Window).lightness());

// Now the tool plugins need to be built/added.
QList<ToolPluginFactory*> toolPluginFactories =
plugin->pluginFactories<ToolPluginFactory>();
foreach (ToolPluginFactory* factory, toolPluginFactories) {
ToolPlugin* tool = factory->createInstance(QCoreApplication::instance());
tool->setParent(this);
tool->setIcon(darkMode);
if (tool)
m_tools << tool;
}
Expand Down

0 comments on commit 09fb213

Please sign in to comment.