From 591f723b826b119116ff698729bc5a2d3cb02795 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Tue, 14 Feb 2017 13:39:01 +0100 Subject: [PATCH] ui: Fixed icons in setup dialogs blurry on high DPI screens --- bin/app/data/gui/window/listbox.css | 37 ++++--------------- bin/app/data/gui/window/window.css | 29 ++------------- src/lib_gui/CMakeLists.txt | 2 + src/lib_gui/qt/element/QtDirectoryListBox.cpp | 26 +++++++------ src/lib_gui/qt/element/QtIconButton.cpp | 31 ++++++++++++++++ src/lib_gui/qt/element/QtIconButton.h | 21 +++++++++++ src/lib_gui/qt/element/QtLocationPicker.cpp | 9 ++++- .../QtProjectWizzardContent.cpp | 11 +++++- .../project_wizzard/QtProjectWizzardContent.h | 4 +- .../QtProjectWizzardContentBuildFile.cpp | 9 +++-- 10 files changed, 102 insertions(+), 77 deletions(-) create mode 100644 src/lib_gui/qt/element/QtIconButton.cpp create mode 100644 src/lib_gui/qt/element/QtIconButton.h diff --git a/bin/app/data/gui/window/listbox.css b/bin/app/data/gui/window/listbox.css index 9c662fc1..e231c44c 100644 --- a/bin/app/data/gui/window/listbox.css +++ b/bin/app/data/gui/window/listbox.css @@ -35,45 +35,21 @@ QtListItemWidget #field { border-top: 1px solid lightgray; } -#plusButton, #minusButton, #dotsButton, #editButton { +#iconButton, #dotsButton, #plusButton, #minusButton, #editButton { + border: none; color: white; height: 1em; - margin-right: 3px; width: 1em; - border: none; + padding: 1px; } -#dotsButton { - margin-top: 2px; -} - -#plusButton { - border-image: url(window/plus.png); -} - -#plusButton:hover { - border-image: url(window/plus_hover.png); -} - -#minusButton { - border-image: url(window/minus.png); -} - -#minusButton:hover { - border-image: url(window/minus_hover.png); -} - -#dotsButton { - border-image: url(window/dots.png); -} - -#dotsButton:hover { - border-image: url(window/dots_hover.png); +#plusButton, #minusButton, #editButton { + margin-right: 3px; } #editButton { - border-image: url(code_view/images/edit.png); margin-left: 6px; + margin-right: 3px; } #editButton:hover { @@ -82,4 +58,5 @@ QtListItemWidget #field { #dropInfo { color: #999; + margin-top: 2px; } diff --git a/bin/app/data/gui/window/window.css b/bin/app/data/gui/window/window.css index 6079d131..228f42e3 100644 --- a/bin/app/data/gui/window/window.css +++ b/bin/app/data/gui/window/window.css @@ -63,35 +63,16 @@ QLabel, QCheckBox { background: transparent; } -#helpButton, #dotsButton, #refreshButton { +#iconButton, #dotsButton { border: none; color: white; height: 1em; width: 1em; -} - -#helpButton { - border-image: url(window/help.png); -} - -#helpButton:hover { - border-image: url(window/help_hover.png); + padding: 1px; } #dotsButton { - border-image: url(window/dots.png); -} - -#dotsButton:hover { - border-image: url(window/dots_hover.png); -} - -#refreshButton { - border-image: url(window/refresh.png); -} - -#refreshButton:hover { - border-image: url(window/refresh_hover.png); + margin-right: 2px; } #name, #picker { @@ -119,10 +100,6 @@ QLabel, QCheckBox { color: black; } -#dotsButton, #refreshButton { - margin-right: 2px; -} - #windowButton { background: white; border: 1px solid lightgray; diff --git a/src/lib_gui/CMakeLists.txt b/src/lib_gui/CMakeLists.txt index 21302540..9bb665eb 100644 --- a/src/lib_gui/CMakeLists.txt +++ b/src/lib_gui/CMakeLists.txt @@ -34,6 +34,8 @@ add_files( qt/element/QtDirectoryListBox.h qt/element/QtFontPicker.cpp qt/element/QtFontPicker.h + qt/element/QtIconButton.cpp + qt/element/QtIconButton.h qt/element/QtLineEdit.cpp qt/element/QtLineEdit.h qt/element/QtLocationPicker.cpp diff --git a/src/lib_gui/qt/element/QtDirectoryListBox.cpp b/src/lib_gui/qt/element/QtDirectoryListBox.cpp index 8f8a3cdb..ff4a963e 100644 --- a/src/lib_gui/qt/element/QtDirectoryListBox.cpp +++ b/src/lib_gui/qt/element/QtDirectoryListBox.cpp @@ -11,6 +11,7 @@ #include "utility/ResourcePaths.h" #include "utility/utilityString.h" +#include "qt/element/QtIconButton.h" #include "qt/utility/utilityQt.h" #include "qt/window/QtTextEditDialog.h" @@ -29,8 +30,9 @@ QtListItemWidget::QtListItemWidget(QtDirectoryListBox* list, QListWidgetItem* it m_data->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac m_data->setObjectName("field"); - m_button = new QPushButton(""); - m_button->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac + m_button = new QtIconButton( + (ResourcePaths::getGuiPath() + "window/dots.png").c_str(), + (ResourcePaths::getGuiPath() + "window/dots_hover.png").c_str()); m_button->setObjectName("dotsButton"); layout->addWidget(m_data); @@ -138,19 +140,19 @@ QtDirectoryListBox::QtDirectoryListBox(QWidget *parent, const QString& listName, buttonContainer->setObjectName("bar"); QHBoxLayout* innerLayout = new QHBoxLayout(); - innerLayout->setContentsMargins(8, 4, 8, 3); + innerLayout->setContentsMargins(8, 4, 8, 2); innerLayout->setSpacing(0); - m_addButton = new QPushButton("", this); - m_addButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - m_addButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac + m_addButton = new QtIconButton( + (ResourcePaths::getGuiPath() + "window/plus.png").c_str(), + (ResourcePaths::getGuiPath() + "window/plus_hover.png").c_str()); m_addButton->setObjectName("plusButton"); m_addButton->setToolTip("add line"); innerLayout->addWidget(m_addButton); - m_removeButton = new QPushButton("", this); - m_removeButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - m_removeButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac + m_removeButton = new QtIconButton( + (ResourcePaths::getGuiPath() + "window/minus.png").c_str(), + (ResourcePaths::getGuiPath() + "window/minus_hover.png").c_str()); m_removeButton->setObjectName("minusButton"); m_removeButton->setToolTip("remove line"); innerLayout->addWidget(m_removeButton); @@ -163,9 +165,9 @@ QtDirectoryListBox::QtDirectoryListBox(QWidget *parent, const QString& listName, dropInfoText->setAlignment(Qt::AlignRight); innerLayout->addWidget(dropInfoText); - QPushButton* editButton = new QPushButton("", this); - editButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - editButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac + QPushButton* editButton = new QtIconButton( + (ResourcePaths::getGuiPath() + "code_view/images/edit.png").c_str(), + QString()); editButton->setObjectName("editButton"); editButton->setToolTip("edit plain text"); innerLayout->addWidget(editButton); diff --git a/src/lib_gui/qt/element/QtIconButton.cpp b/src/lib_gui/qt/element/QtIconButton.cpp new file mode 100644 index 00000000..a2521a0e --- /dev/null +++ b/src/lib_gui/qt/element/QtIconButton.cpp @@ -0,0 +1,31 @@ +#include "qt/element/QtIconButton.h" + +QtIconButton::QtIconButton(QString iconPath, QString hoveredIconPath, QWidget* parent) + : QPushButton("", parent) + , m_iconPath(iconPath) + , m_hoveredIconPath(hoveredIconPath) +{ + setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac + setMouseTracking(true); + + setObjectName("iconButton"); + + leaveEvent(nullptr); +} + +void QtIconButton::enterEvent(QEvent *event) +{ + if (m_hoveredIconPath.size()) + { + setIcon(QIcon(QPixmap(m_hoveredIconPath))); + } +} + +void QtIconButton::leaveEvent(QEvent *event) +{ + if (m_iconPath.size()) + { + setIcon(QIcon(QPixmap(m_iconPath))); + } +} diff --git a/src/lib_gui/qt/element/QtIconButton.h b/src/lib_gui/qt/element/QtIconButton.h new file mode 100644 index 00000000..b9be39cf --- /dev/null +++ b/src/lib_gui/qt/element/QtIconButton.h @@ -0,0 +1,21 @@ +#ifndef QT_ICON_BUTTON_H +#define QT_ICON_BUTTON_H + +#include + +class QtIconButton + : public QPushButton +{ +public: + QtIconButton(QString iconPath, QString hoveredIconPath, QWidget* parent = nullptr); + +protected: + void enterEvent(QEvent *event); + void leaveEvent(QEvent *event); + +private: + QString m_iconPath; + QString m_hoveredIconPath; +}; + +#endif // QT_ICON_BUTTON_H diff --git a/src/lib_gui/qt/element/QtLocationPicker.cpp b/src/lib_gui/qt/element/QtLocationPicker.cpp index 1ab84506..39d93aef 100644 --- a/src/lib_gui/qt/element/QtLocationPicker.cpp +++ b/src/lib_gui/qt/element/QtLocationPicker.cpp @@ -7,6 +7,10 @@ #include #include +#include "utility/ResourcePaths.h" + +#include "qt/element/QtIconButton.h" + QtLocationPicker::QtLocationPicker(QWidget *parent) : QWidget(parent) , m_pickDirectory(false) @@ -23,10 +27,11 @@ QtLocationPicker::QtLocationPicker(QWidget *parent) m_data->setObjectName("locationField"); layout->addWidget(m_data); - m_button = new QPushButton(""); + m_button = new QtIconButton( + (ResourcePaths::getGuiPath() + "window/dots.png").c_str(), + (ResourcePaths::getGuiPath() + "window/dots_hover.png").c_str()); m_button->setObjectName("dotsButton"); m_button->setToolTip("pick file"); - m_button->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac connect(m_button, SIGNAL(clicked()), this, SLOT(handleButtonPress())); layout->addWidget(m_button); diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.cpp index ec382005..401a6415 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.cpp @@ -3,17 +3,24 @@ #include #include "qt/window/QtTextEditDialog.h" +#include "utility/ResourcePaths.h" #include "utility/utilityString.h" QtHelpButton::QtHelpButton(const QString& helpText, QWidget* parent) - : QPushButton("", parent) + : QtIconButton( + (ResourcePaths::getGuiPath() + "window/help.png").c_str(), + (ResourcePaths::getGuiPath() + "window/help_hover.png").c_str(), + parent) , m_helpText(helpText) { setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac - setObjectName("helpButton"); + setMouseTracking(true); + setToolTip("help"); + leaveEvent(nullptr); + connect(this, SIGNAL(clicked()), this, SLOT(handleHelpPress())); } diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.h b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.h index 7eebdf2e..fb17eced 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.h +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContent.h @@ -3,17 +3,17 @@ #include #include -#include #include #include +#include "qt/element/QtIconButton.h" #include "qt/window/project_wizzard/QtProjectWizzardWindow.h" #include "settings/ProjectSettings.h" class QtTextEditDialog; class QtHelpButton - : public QPushButton + : public QtIconButton { Q_OBJECT diff --git a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp index 6a2bfe46..5cafbed3 100644 --- a/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp +++ b/src/lib_gui/qt/window/project_wizzard/QtProjectWizzardContentBuildFile.cpp @@ -3,6 +3,9 @@ #include #include +#include "utility/ResourcePaths.h" + +#include "qt/element/QtIconButton.h" #include "qt/element/QtLocationPicker.h" #include "settings/CxxProjectSettings.h" @@ -59,9 +62,9 @@ void QtProjectWizzardContentBuildFile::populate(QGridLayout* layout, int& row) m_picker->setFileFilter(filter); m_picker->setRelativeRootDirectory(m_settings->getProjectFileLocation()); - QPushButton* button = new QPushButton("", this); - button->setObjectName("refreshButton"); - button->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac + QPushButton* button = new QtIconButton( + (ResourcePaths::getGuiPath() + "window/refresh.png").c_str(), + (ResourcePaths::getGuiPath() + "window/refresh_hover.png").c_str()); button->setToolTip("refresh paths"); connect(button, SIGNAL(clicked()), this, SLOT(refreshClicked()));