From b5f9e77154b0336bc457dfb3a23fbcf5d0a553b7 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Tue, 20 Mar 2018 16:33:48 +0100 Subject: [PATCH] ui: Added close button to tabbed view --- src/lib_gui/qt/element/QtScreenSearchBox.cpp | 53 ++++++-------------- src/lib_gui/qt/element/QtScreenSearchBox.h | 11 ++-- src/lib_gui/qt/view/QtScreenSearchView.cpp | 2 - src/lib_gui/qt/view/QtTabbedView.cpp | 25 ++++++++- src/lib_gui/qt/view/QtTabbedView.h | 8 ++- 5 files changed, 49 insertions(+), 50 deletions(-) diff --git a/src/lib_gui/qt/element/QtScreenSearchBox.cpp b/src/lib_gui/qt/element/QtScreenSearchBox.cpp index 0d5a67a1..ed7c00a7 100644 --- a/src/lib_gui/qt/element/QtScreenSearchBox.cpp +++ b/src/lib_gui/qt/element/QtScreenSearchBox.cpp @@ -8,6 +8,7 @@ #include #include +#include "qt/element/QtIconButton.h" #include "qt/utility/utilityQt.h" #include "utility/ResourcePaths.h" @@ -42,16 +43,16 @@ QtScreenSearchBox::QtScreenSearchBox(ControllerProxy* co // search field { - m_searchButton = new QPushButton(); - m_searchButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac + m_searchButton = new QtSelfRefreshIconButton( + "", ResourcePaths::getGuiPath().concatenate(L"search_view/images/search.png"), "screen_search/button"); m_searchButton->setObjectName("search_button"); + m_searchButton->setIconSize(QSize(12, 12)); layout->addWidget(m_searchButton); connect(m_searchButton, &QPushButton::clicked, this, &QtScreenSearchBox::setFocus); m_searchBox = new QLineEdit(this); m_searchBox->setObjectName("search_box"); - m_searchBox->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac m_searchBox->setAttribute(Qt::WA_MacShowFocusRect, 0); // remove blue focus box on Mac layout->addWidget(m_searchBox); @@ -75,15 +76,17 @@ QtScreenSearchBox::QtScreenSearchBox(ControllerProxy* co // buttons { - m_prevButton = new QPushButton(); - m_nextButton = new QPushButton(); - - m_prevButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac - m_nextButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac + m_prevButton = new QtSelfRefreshIconButton( + "", ResourcePaths::getGuiPath().concatenate(L"code_view/images/arrow_left.png"), "screen_search/button"); + m_nextButton = new QtSelfRefreshIconButton( + "", ResourcePaths::getGuiPath().concatenate(L"code_view/images/arrow_right.png"), "screen_search/button"); m_prevButton->setObjectName("prev_button"); m_nextButton->setObjectName("next_button"); + m_prevButton->setIconSize(QSize(12, 12)); + m_nextButton->setIconSize(QSize(12, 12)); + layout->addWidget(m_prevButton); layout->addWidget(m_nextButton); @@ -100,9 +103,10 @@ QtScreenSearchBox::QtScreenSearchBox(ControllerProxy* co // buttons { - m_closeButton = new QPushButton(); + m_closeButton = new QtSelfRefreshIconButton( + "", ResourcePaths::getGuiPath().concatenate(L"screen_search_view/images/close.png"), "screen_search/button"); m_closeButton->setObjectName("close_button"); - m_closeButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); // fixes layouting on Mac + m_closeButton->setIconSize(QSize(15, 15)); layout->addWidget(m_closeButton); connect(m_closeButton, &QPushButton::clicked, [this](){ emit closePressed(); }); @@ -112,7 +116,6 @@ QtScreenSearchBox::QtScreenSearchBox(ControllerProxy* co m_timer->setSingleShot(true); connect(m_timer, &QTimer::timeout, this, &QtScreenSearchBox::findMatches); - refreshStyle(); setMatchCount(0); } @@ -120,34 +123,6 @@ QtScreenSearchBox::~QtScreenSearchBox() { } -void QtScreenSearchBox::refreshStyle() -{ - m_searchButton->setIcon(utility::createButtonIcon( - ResourcePaths::getGuiPath().concatenate(L"search_view/images/search.png"), - "screen_search/button" - )); - - m_prevButton->setIcon(utility::createButtonIcon( - ResourcePaths::getGuiPath().concatenate(L"code_view/images/arrow_left.png"), - "screen_search/button" - )); - - m_nextButton->setIcon(utility::createButtonIcon( - ResourcePaths::getGuiPath().concatenate(L"code_view/images/arrow_right.png"), - "screen_search/button" - )); - - m_closeButton->setIcon(utility::createButtonIcon( - ResourcePaths::getGuiPath().concatenate(L"screen_search_view/images/close.png"), - "screen_search/button" - )); - - m_searchButton->setIconSize(QSize(12, 12)); - m_prevButton->setIconSize(QSize(12, 12)); - m_nextButton->setIconSize(QSize(12, 12)); - m_closeButton->setIconSize(QSize(15, 15)); -} - void QtScreenSearchBox::setMatchCount(size_t matchCount) { m_matchCount = matchCount; diff --git a/src/lib_gui/qt/element/QtScreenSearchBox.h b/src/lib_gui/qt/element/QtScreenSearchBox.h index bf6a88b8..3424e400 100644 --- a/src/lib_gui/qt/element/QtScreenSearchBox.h +++ b/src/lib_gui/qt/element/QtScreenSearchBox.h @@ -10,6 +10,7 @@ class QCheckBox; class QHBoxLayout; class QLineEdit; class QPushButton; +class QtSelfRefreshIconButton; class QTimer; @@ -38,8 +39,6 @@ public: QtScreenSearchBox(ControllerProxy* controllerProxy, QWidget* parent = nullptr); virtual ~QtScreenSearchBox(); - void refreshStyle(); - void setMatchCount(size_t matchCount); void setMatchIndex(size_t matchIndex); @@ -69,10 +68,10 @@ private: QLineEdit* m_searchBox; QPushButton* m_matchLabel; - QPushButton* m_searchButton; - QPushButton* m_prevButton; - QPushButton* m_nextButton; - QPushButton* m_closeButton; + QtSelfRefreshIconButton* m_searchButton; + QtSelfRefreshIconButton* m_prevButton; + QtSelfRefreshIconButton* m_nextButton; + QtSelfRefreshIconButton* m_closeButton; QHBoxLayout* m_checkboxLayout; std::vector m_checkBoxes; diff --git a/src/lib_gui/qt/view/QtScreenSearchView.cpp b/src/lib_gui/qt/view/QtScreenSearchView.cpp index 0035daf9..e155d00f 100644 --- a/src/lib_gui/qt/view/QtScreenSearchView.cpp +++ b/src/lib_gui/qt/view/QtScreenSearchView.cpp @@ -51,8 +51,6 @@ void QtScreenSearchView::refreshView() ) ).c_str() ); - - m_widget->refreshStyle(); }); } diff --git a/src/lib_gui/qt/view/QtTabbedView.cpp b/src/lib_gui/qt/view/QtTabbedView.cpp index d8c2fa70..c78fb5ff 100644 --- a/src/lib_gui/qt/view/QtTabbedView.cpp +++ b/src/lib_gui/qt/view/QtTabbedView.cpp @@ -1,10 +1,12 @@ #include "qt/view/QtTabbedView.h" -#include +#include #include #include #include +#include +#include "qt/element/QtIconButton.h" #include "qt/utility/utilityQt.h" #include "qt/view/QtViewWidgetWrapper.h" #include "settings/ColorScheme.h" @@ -28,13 +30,22 @@ void QtTabbedView::initView() { QWidget* widget = QtViewWidgetWrapper::getWidgetOfView(this); - QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom); + QVBoxLayout* layout = new QVBoxLayout(); layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); widget->setLayout(layout); m_widget = new QTabWidget(widget); layout->addWidget(m_widget); + + m_closeButton = new QtSelfRefreshIconButton("", + ResourcePaths::getGuiPath().concatenate(L"screen_search_view/images/close.png"), "screen_search/button", widget); + m_closeButton->setIconSize(QSize(15, 15)); + m_closeButton->setStyleSheet("background: transparent; border: none;"); + + widget->connect(m_closeButton, &QPushButton::clicked, [this](){ hideView(this); }); + m_widget->tabBar()->installEventFilter(this); + widget->installEventFilter(this); } void QtTabbedView::refreshView() @@ -70,3 +81,13 @@ void QtTabbedView::setStyleSheet() utility::getStyleSheet(ResourcePaths::getGuiPath().concatenate(L"tabbed_view/tabbed_view.css")).c_str() ); } + +bool QtTabbedView::eventFilter(QObject* obj, QEvent* event) +{ + if (event->type() == QEvent::Resize) + { + m_closeButton->setGeometry(m_widget->width() - 23, (m_widget->tabBar()->height() - 15) / 2 + 1, 15, 15); + m_closeButton->show(); + } + return QObject::eventFilter(obj, event); +} diff --git a/src/lib_gui/qt/view/QtTabbedView.h b/src/lib_gui/qt/view/QtTabbedView.h index bf1416ad..db6fe84c 100644 --- a/src/lib_gui/qt/view/QtTabbedView.h +++ b/src/lib_gui/qt/view/QtTabbedView.h @@ -1,13 +1,17 @@ #ifndef QT_TABBED_VIEW #define QT_TABBED_VIEW +#include + #include "component/view/TabbedView.h" #include "qt/utility/QtThreadedFunctor.h" class QTabWidget; +class QtSelfRefreshIconButton; class QtTabbedView - : public TabbedView + : public QObject + , public TabbedView { public: QtTabbedView(ViewLayout* viewLayout, const std::string& name); @@ -24,9 +28,11 @@ public: private: void setStyleSheet(); + bool eventFilter(QObject* obj, QEvent* event); QtThreadedLambdaFunctor m_onQtThread; QTabWidget* m_widget; + QtSelfRefreshIconButton* m_closeButton; }; #endif // QT_TABBED_VIEW