From 30b5abd672dd05a0ae71818a72e49c35574a5d73 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Wed, 5 Aug 2015 21:02:52 +0200 Subject: [PATCH] ui: added icon colors to ColorScheme This change introduces the qt utility function colorizePixmap() for colloring icons in different colors for different color schemes. --- bin/app/data/color_schemes/bright.xml | 3 ++ bin/app/data/color_schemes/dark.xml | 3 ++ src/app/CMakeLists.txt | 1 + src/app/qt/element/QtRefreshBar.cpp | 16 +++++- src/app/qt/element/QtSearchBar.cpp | 8 ++- src/app/qt/element/QtUndoRedo.cpp | 14 ++++- src/app/qt/utility/QtDeviceScaledPixmap.cpp | 50 ++++++++++++++++++ src/app/qt/utility/QtDeviceScaledPixmap.h | 51 ++++--------------- src/app/qt/utility/utilityQt.cpp | 16 +++++- src/app/qt/utility/utilityQt.h | 2 + src/app/qt/view/graphElements/QtGraphNode.cpp | 10 ++-- .../view/graphElements/QtGraphNodeAccess.cpp | 3 ++ .../graphElements/QtGraphNodeExpandToggle.cpp | 3 ++ src/lib/component/view/GraphViewStyle.cpp | 7 +-- src/lib/component/view/GraphViewStyle.h | 4 +- 15 files changed, 134 insertions(+), 57 deletions(-) create mode 100644 src/app/qt/utility/QtDeviceScaledPixmap.cpp diff --git a/bin/app/data/color_schemes/bright.xml b/bin/app/data/color_schemes/bright.xml index 914e9628..50e4d83d 100644 --- a/bin/app/data/color_schemes/bright.xml +++ b/bin/app/data/color_schemes/bright.xml @@ -9,6 +9,7 @@ #B2B2B2 #626262 #F4F4F4 + white @@ -100,6 +101,8 @@ black white #3C3C3C + black + white diff --git a/bin/app/data/color_schemes/dark.xml b/bin/app/data/color_schemes/dark.xml index 79ac5a37..0ed9b8be 100644 --- a/bin/app/data/color_schemes/dark.xml +++ b/bin/app/data/color_schemes/dark.xml @@ -9,6 +9,7 @@ #555555 #444444 #333333 + white @@ -100,6 +101,8 @@ #F7F7F7 #C3C3C3 #272728 + #F7F7F7 + #272728 diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 0c42b3b7..028d0574 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -45,6 +45,7 @@ add_files( qt/graphics/QtStraightLineItem.cpp qt/graphics/QtStraightLineItem.h + qt/utility/QtDeviceScaledPixmap.cpp qt/utility/QtDeviceScaledPixmap.h qt/utility/QtHighlighter.cpp qt/utility/QtHighlighter.h diff --git a/src/app/qt/element/QtRefreshBar.cpp b/src/app/qt/element/QtRefreshBar.cpp index 3520ba48..c31524a5 100644 --- a/src/app/qt/element/QtRefreshBar.cpp +++ b/src/app/qt/element/QtRefreshBar.cpp @@ -6,7 +6,9 @@ #include "utility/messaging/type/MessageAutoRefreshChanged.h" #include "utility/messaging/type/MessageRefresh.h" +#include "qt/utility/utilityQt.h" #include "settings/ApplicationSettings.h" +#include "settings/ColorScheme.h" QtRefreshBar::QtRefreshBar() { @@ -22,7 +24,6 @@ QtRefreshBar::QtRefreshBar() m_refreshButton->setObjectName("refresh_button"); m_refreshButton->setToolTip("refresh"); m_refreshButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac - m_refreshButton->setIcon(QIcon("data/gui/refresh_view/images/refresh.png")); layout->addWidget(m_refreshButton); m_autoRefreshButton = new QPushButton(this); @@ -30,11 +31,12 @@ QtRefreshBar::QtRefreshBar() m_autoRefreshButton->setCheckable(true); m_autoRefreshButton->setToolTip("automatic refresh on window focus"); m_autoRefreshButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac - m_autoRefreshButton->setIcon(QIcon("data/gui/refresh_view/images/auto_refresh.png")); layout->addWidget(m_autoRefreshButton); connect(m_refreshButton, SIGNAL(clicked()), this, SLOT(refreshClicked())); connect(m_autoRefreshButton, SIGNAL(clicked()), this, SLOT(autoRefreshClicked())); + + refreshStyle(); } QtRefreshBar::~QtRefreshBar() @@ -57,4 +59,14 @@ void QtRefreshBar::refreshStyle() m_refreshButton->setFixedHeight(height); m_autoRefreshButton->setFixedHeight(height); + + m_refreshButton->setIcon(utility::colorizePixmap( + QPixmap("data/gui/refresh_view/images/refresh.png"), + ColorScheme::getInstance()->getColor("search/button/icon").c_str() + )); + + m_autoRefreshButton->setIcon(utility::colorizePixmap( + QPixmap("data/gui/refresh_view/images/auto_refresh.png"), + ColorScheme::getInstance()->getColor("search/button/icon").c_str() + )); } diff --git a/src/app/qt/element/QtSearchBar.cpp b/src/app/qt/element/QtSearchBar.cpp index 9a95f2fc..e2410c2c 100644 --- a/src/app/qt/element/QtSearchBar.cpp +++ b/src/app/qt/element/QtSearchBar.cpp @@ -5,7 +5,9 @@ #include #include "qt/element/QtSmartSearchBox.h" +#include "qt/utility/utilityQt.h" #include "settings/ApplicationSettings.h" +#include "settings/ColorScheme.h" QtSearchBar::QtSearchBar() { @@ -39,7 +41,6 @@ QtSearchBar::QtSearchBar() m_searchButton->setObjectName("search_button"); m_searchButton->setToolTip("search"); m_searchButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac - m_searchButton->setIcon(QIcon("data/gui/search_view/images/search.png")); layout->addWidget(m_searchButton); connect(m_searchButton, SIGNAL(clicked()), m_searchBox, SLOT(search())); @@ -84,4 +85,9 @@ void QtSearchBar::refreshStyle() { m_searchBox->setFixedHeight(std::max(ApplicationSettings::getInstance()->getFontSize() + 11, 25)); m_searchButton->setFixedHeight(m_searchBox->height() + 5); + + m_searchButton->setIcon(utility::colorizePixmap( + QPixmap("data/gui/search_view/images/search.png"), + ColorScheme::getInstance()->getColor("search/button/icon").c_str() + )); } diff --git a/src/app/qt/element/QtUndoRedo.cpp b/src/app/qt/element/QtUndoRedo.cpp index dfdc26c0..5ca86d85 100644 --- a/src/app/qt/element/QtUndoRedo.cpp +++ b/src/app/qt/element/QtUndoRedo.cpp @@ -6,7 +6,9 @@ #include "utility/messaging/type/MessageUndo.h" #include "utility/messaging/type/MessageRedo.h" +#include "qt/utility/utilityQt.h" #include "settings/ApplicationSettings.h" +#include "settings/ColorScheme.h" QtUndoRedo::QtUndoRedo() { @@ -16,14 +18,12 @@ QtUndoRedo::QtUndoRedo() m_undoButton->setObjectName("undo_button"); m_undoButton->setToolTip("undo"); m_undoButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac - m_undoButton->setIcon(QIcon("data/gui/undoredo_view/images/arrow_left.png")); m_undoButton->setEnabled(false); m_redoButton = new QPushButton(this); m_redoButton->setObjectName("redo_button"); m_redoButton->setToolTip("redo"); m_redoButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac - m_redoButton->setIcon(QIcon("data/gui/undoredo_view/images/arrow_right.png")); m_redoButton->setEnabled(false); QBoxLayout* layout = new QHBoxLayout(); @@ -70,4 +70,14 @@ void QtUndoRedo::refreshStyle() m_undoButton->setFixedHeight(height); m_redoButton->setFixedHeight(height); + + m_undoButton->setIcon(utility::colorizePixmap( + QPixmap("data/gui/undoredo_view/images/arrow_left.png"), + ColorScheme::getInstance()->getColor("search/button/icon").c_str() + )); + + m_redoButton->setIcon(utility::colorizePixmap( + QPixmap("data/gui/undoredo_view/images/arrow_right.png"), + ColorScheme::getInstance()->getColor("search/button/icon").c_str() + )); } diff --git a/src/app/qt/utility/QtDeviceScaledPixmap.cpp b/src/app/qt/utility/QtDeviceScaledPixmap.cpp new file mode 100644 index 00000000..8beaa0e6 --- /dev/null +++ b/src/app/qt/utility/QtDeviceScaledPixmap.cpp @@ -0,0 +1,50 @@ +#include "qt/utility/QtDeviceScaledPixmap.h" + +#include + +qreal QtDeviceScaledPixmap::devicePixelRatio() +{ + QApplication* app = dynamic_cast(QCoreApplication::instance()); + return app->devicePixelRatio(); +} + +QtDeviceScaledPixmap::QtDeviceScaledPixmap(QString filePath) + : m_pixmap(filePath) +{ + m_pixmap.setDevicePixelRatio(devicePixelRatio()); +} + +QtDeviceScaledPixmap::~QtDeviceScaledPixmap() {} + +const QPixmap& QtDeviceScaledPixmap::pixmap() const +{ + return m_pixmap; +} + +qreal QtDeviceScaledPixmap::width() const +{ + return m_pixmap.width() / devicePixelRatio(); +} + +qreal QtDeviceScaledPixmap::height() const +{ + return m_pixmap.height() / devicePixelRatio(); +} + +void QtDeviceScaledPixmap::scaleToWidth(int width) +{ + m_pixmap = m_pixmap.scaledToWidth(width * devicePixelRatio(), Qt::SmoothTransformation); + m_pixmap.setDevicePixelRatio(devicePixelRatio()); +} + +void QtDeviceScaledPixmap::scaleToHeight(int height) +{ + m_pixmap = m_pixmap.scaledToHeight(height * devicePixelRatio(), Qt::SmoothTransformation); + m_pixmap.setDevicePixelRatio(devicePixelRatio()); +} + +void QtDeviceScaledPixmap::mirror(bool horizontal, bool vertical) +{ + m_pixmap = QPixmap::fromImage(m_pixmap.toImage().mirrored(horizontal, vertical)); + m_pixmap.setDevicePixelRatio(devicePixelRatio()); +} diff --git a/src/app/qt/utility/QtDeviceScaledPixmap.h b/src/app/qt/utility/QtDeviceScaledPixmap.h index 935475a1..706ae607 100644 --- a/src/app/qt/utility/QtDeviceScaledPixmap.h +++ b/src/app/qt/utility/QtDeviceScaledPixmap.h @@ -1,58 +1,25 @@ #ifndef QT_DEVICE_SCALED_PIXMAP_H #define QT_DEVICE_SCALED_PIXMAP_H -#include #include class QtDeviceScaledPixmap { public: - static qreal devicePixelRatio() - { - QApplication* app = dynamic_cast(QCoreApplication::instance()); - return app->devicePixelRatio(); - } + static qreal devicePixelRatio(); - explicit QtDeviceScaledPixmap(QString filePath) - : m_pixmap(filePath) - { - m_pixmap.setDevicePixelRatio(devicePixelRatio()); - } + explicit QtDeviceScaledPixmap(QString filePath); + virtual ~QtDeviceScaledPixmap(); - virtual ~QtDeviceScaledPixmap() {} + const QPixmap& pixmap() const; - const QPixmap& pixmap() const - { - return m_pixmap; - } + qreal width() const; + qreal height() const; - qreal width() const - { - return m_pixmap.width() / devicePixelRatio(); - } + void scaleToWidth(int width); + void scaleToHeight(int height); - qreal height() const - { - return m_pixmap.height() / devicePixelRatio(); - } - - void scaleToWidth(int width) - { - m_pixmap = m_pixmap.scaledToWidth(width * devicePixelRatio(), Qt::SmoothTransformation); - m_pixmap.setDevicePixelRatio(devicePixelRatio()); - } - - void scaleToHeight(int height) - { - m_pixmap = m_pixmap.scaledToHeight(height * devicePixelRatio(), Qt::SmoothTransformation); - m_pixmap.setDevicePixelRatio(devicePixelRatio()); - } - - void mirror(bool horizontal = false, bool vertical = true) - { - m_pixmap = QPixmap::fromImage(m_pixmap.toImage().mirrored(horizontal, vertical)); - m_pixmap.setDevicePixelRatio(devicePixelRatio()); - } + void mirror(bool horizontal = false, bool vertical = true); private: QPixmap m_pixmap; diff --git a/src/app/qt/utility/utilityQt.cpp b/src/app/qt/utility/utilityQt.cpp index 548186ec..2ed2305a 100644 --- a/src/app/qt/utility/utilityQt.cpp +++ b/src/app/qt/utility/utilityQt.cpp @@ -1,9 +1,10 @@ -#include "utilityQt.h" +#include "qt/utility/utilityQt.h" #include #include #include +#include #include "utility/file/FileSystem.h" #include "utility/logging/logging.h" @@ -115,4 +116,17 @@ namespace utility return css; } + + QPixmap colorizePixmap(const QPixmap& pixmap, QColor color) + { + QImage image = pixmap.toImage(); + QImage colorImage(image.size(), image.format()); + QPainter colorPainter(&colorImage); + colorPainter.fillRect(image.rect(), color); + + QPainter painter(&image); + painter.setCompositionMode(QPainter::CompositionMode_SourceAtop); + painter.drawImage(0, 0, colorImage); + return QPixmap::fromImage(image); + } } diff --git a/src/app/qt/utility/utilityQt.h b/src/app/qt/utility/utilityQt.h index 61833191..cd8e582d 100644 --- a/src/app/qt/utility/utilityQt.h +++ b/src/app/qt/utility/utilityQt.h @@ -10,6 +10,8 @@ namespace utility void loadFontsFromDirectory(const std::string& path, const std::string& extension = ".otf"); std::string getStyleSheet(const std::string& path); + + QPixmap colorizePixmap(const QPixmap& pixmap, QColor color); } # endif // UTILITY_QT_H diff --git a/src/app/qt/view/graphElements/QtGraphNode.cpp b/src/app/qt/view/graphElements/QtGraphNode.cpp index 5f85bd42..861a4cc9 100644 --- a/src/app/qt/view/graphElements/QtGraphNode.cpp +++ b/src/app/qt/view/graphElements/QtGraphNode.cpp @@ -9,6 +9,7 @@ #include "qt/graphics/QtRoundedRectItem.h" #include "qt/utility/QtDeviceScaledPixmap.h" +#include "qt/utility/utilityQt.h" #include "qt/view/graphElements/nodeComponents/QtGraphNodeComponent.h" #include "qt/view/graphElements/QtGraphEdge.h" @@ -372,10 +373,11 @@ void QtGraphNode::setStyle(const GraphViewStyle::NodeStyle& style) m_rect->setBrush(QBrush(color)); m_rect->setRadius(radius); - if (style.undefinedPattern) + if (style.hatchingColor.size()) { - QtDeviceScaledPixmap pixmap("data/gui/graph_view/images/pattern.png"); - pixmap.scaleToHeight(10); + QtDeviceScaledPixmap pattern("data/gui/graph_view/images/pattern.png"); + pattern.scaleToHeight(10); + QPixmap pixmap = utility::colorizePixmap(pattern.pixmap(), style.hatchingColor.c_str()); if (!m_undefinedRect) { @@ -387,7 +389,7 @@ void QtGraphNode::setStyle(const GraphViewStyle::NodeStyle& style) p.setColor(Qt::transparent); m_undefinedRect->setPen(p); - m_undefinedRect->setBrush(QBrush(pixmap.pixmap())); + m_undefinedRect->setBrush(pixmap); m_undefinedRect->setRadius(radius); } diff --git a/src/app/qt/view/graphElements/QtGraphNodeAccess.cpp b/src/app/qt/view/graphElements/QtGraphNodeAccess.cpp index 559062a8..eaaaad24 100644 --- a/src/app/qt/view/graphElements/QtGraphNodeAccess.cpp +++ b/src/app/qt/view/graphElements/QtGraphNodeAccess.cpp @@ -7,6 +7,7 @@ #include "component/view/GraphViewStyle.h" #include "qt/graphics/QtRoundedRectItem.h" #include "qt/utility/QtDeviceScaledPixmap.h" +#include "qt/utility/utilityQt.h" QtGraphNodeAccess::QtGraphNodeAccess(TokenComponentAccess::AccessType accessType) : QtGraphNode() @@ -54,6 +55,8 @@ void QtGraphNodeAccess::updateStyle() m_text->setPos(style.textOffset.x + m_accessIconSize + 3, style.textOffset.x + m_accessIconSize + 2 - style.fontSize); m_accessIcon->setPos(style.textOffset.x, style.textOffset.y); + + m_accessIcon->setPixmap(utility::colorizePixmap(m_accessIcon->pixmap(), style.iconColor.c_str())); } void QtGraphNodeAccess::hideLabel() diff --git a/src/app/qt/view/graphElements/QtGraphNodeExpandToggle.cpp b/src/app/qt/view/graphElements/QtGraphNodeExpandToggle.cpp index c7888b42..2033cfb0 100644 --- a/src/app/qt/view/graphElements/QtGraphNodeExpandToggle.cpp +++ b/src/app/qt/view/graphElements/QtGraphNodeExpandToggle.cpp @@ -7,6 +7,7 @@ #include "qt/graphics/QtRoundedRectItem.h" #include "qt/utility/QtDeviceScaledPixmap.h" +#include "qt/utility/utilityQt.h" #include "qt/view/graphElements/QtGraphNodeData.h" QtGraphNodeExpandToggle::QtGraphNodeExpandToggle(bool expanded, int invisibleSubNodeCount) @@ -71,4 +72,6 @@ void QtGraphNodeExpandToggle::updateStyle() (m_rect->rect().width() - m_icon->pixmap().width() / QtDeviceScaledPixmap::devicePixelRatio()) / 2, (m_invisibleSubNodeCount == 0 ? m_rect->rect().height() / 2 - 2 : m_rect->rect().height() - 8) ); + + m_icon->setPixmap(utility::colorizePixmap(m_icon->pixmap(), style.iconColor.c_str())); } diff --git a/src/lib/component/view/GraphViewStyle.cpp b/src/lib/component/view/GraphViewStyle.cpp index cb4064d7..61bfaf81 100644 --- a/src/lib/component/view/GraphViewStyle.cpp +++ b/src/lib/component/view/GraphViewStyle.cpp @@ -26,7 +26,6 @@ GraphViewStyle::NodeStyle::NodeStyle() , borderDashed(false) , fontSize(0) , fontBold(false) - , undefinedPattern(false) { } @@ -283,7 +282,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType( break; case Node::NODE_UNDEFINED_TYPE: - style.undefinedPattern = true; + style.hatchingColor = scheme->getColor("graph/hatching"); case Node::NODE_STRUCT: case Node::NODE_CLASS: @@ -333,7 +332,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleForNodeType( case Node::NODE_UNDEFINED_FUNCTION: case Node::NODE_UNDEFINED_VARIABLE: - style.undefinedPattern = true; + style.hatchingColor = scheme->getColor("graph/hatching"); case Node::NODE_FUNCTION: case Node::NODE_METHOD: @@ -367,6 +366,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfAccessNode() style.color = scheme->getColor("graph/background"); style.textColor = scheme->getColor("graph/text"); + style.iconColor = scheme->getColor("graph/icon"); style.borderColor = "#00000000"; style.cornerRadius = 12; @@ -389,6 +389,7 @@ GraphViewStyle::NodeStyle GraphViewStyle::getStyleOfExpandToggleNode() style.color = scheme->getColor("graph/background"); style.textColor = scheme->getColor("graph/text"); + style.iconColor = scheme->getColor("graph/icon"); style.borderColor = "#00000000"; style.cornerRadius = 100; diff --git a/src/lib/component/view/GraphViewStyle.h b/src/lib/component/view/GraphViewStyle.h index 2b62616b..f2586bb8 100644 --- a/src/lib/component/view/GraphViewStyle.h +++ b/src/lib/component/view/GraphViewStyle.h @@ -40,6 +40,8 @@ public: std::string color; std::string textColor; + std::string iconColor; + std::string hatchingColor; std::string shadowColor; int shadowBlurRadius; @@ -55,8 +57,6 @@ public: bool fontBold; Vec2i textOffset; - - bool undefinedPattern; }; struct EdgeStyle