From 00cba732df03bfbe29865495b19ae75e4f4a738d Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Mon, 30 Jan 2017 16:28:32 +0100 Subject: [PATCH] ui: Added style for graph zoom buttons * moved zoom buttons to QtGraphicsView due to stylesheet and repositioning on resize --- bin/app/data/gui/graph_view/graph_view.css | 19 +++++++ bin/app/data/gui/graph_view/images/zoomin.png | Bin 0 -> 881 bytes .../data/gui/graph_view/images/zoomout.png | Bin 0 -> 753 bytes src/lib_gui/qt/graphics/QtGraphicsView.cpp | 50 ++++++++++++++++++ src/lib_gui/qt/graphics/QtGraphicsView.h | 18 ++++++- src/lib_gui/qt/view/QtGraphView.cpp | 41 +------------- src/lib_gui/qt/view/QtGraphView.h | 13 ----- 7 files changed, 87 insertions(+), 54 deletions(-) create mode 100644 bin/app/data/gui/graph_view/images/zoomin.png create mode 100644 bin/app/data/gui/graph_view/images/zoomout.png diff --git a/bin/app/data/gui/graph_view/graph_view.css b/bin/app/data/gui/graph_view/graph_view.css index bc387e04..d15bdb58 100644 --- a/bin/app/data/gui/graph_view/graph_view.css +++ b/bin/app/data/gui/graph_view/graph_view.css @@ -2,3 +2,22 @@ QGraphicsView, QGraphicsScene { background-color: ; border: none; } + +QPushButton { + background: ; + border: none; + color: white; + border-radius: 5px; +} + +QPushButton:disabled { + background: ; +} + +QPushButton:hover { + background: ; +} + +QPushButton:pressed { + background: ; +} diff --git a/bin/app/data/gui/graph_view/images/zoomin.png b/bin/app/data/gui/graph_view/images/zoomin.png new file mode 100644 index 0000000000000000000000000000000000000000..79f5052aabe1b6ebbe6af534a47141767a2b5eb3 GIT binary patch literal 881 zcmeAS@N?(olHy`uVBq!ia0vp^HXzKw1|+Ti+$;i8jKx9jP7LeL$-D%zPiKZiltlRY zSS9D@>LsS+C#C9DzCHb_`sNdc^+B->Ug z!Z$#{Ilm}X!Bo#g&p^qJOF==wrYI%ND#*nRsvXF)RmvzSDX`MlFE20GD>v55FG|-p zw6wI;H!#vSGSUUA&@HaaD@m--%_~-h7y>iLCAB!YD6^m>Ge1uOWNuz7iBo^o!>KW)`(^Qg~hHxH=E|3gF8`xJ6%WQx_W93|wnpl!w z6q28xW9JA8I|a|&#Prml)WnoZ8+~*Y2$$M`jI{DE%1j0N733p3LmPbzF{pYQeUNvN zyblRmuqZHa?YMw8!6M3zOH=QxEihU`JY5_^GFab6b#opv5D8Jg;A_>TT*9h;jkkok zww+CG;m%);7v_CeFnKxg$=z6vFBi`qOJrTsAi9AmY(ZE;hj_*(L$<@&TYj%zXzw<; zCwYUG%WHLmofhniXJtq-zZSZ!x7)^?(NZk7=;lTq5kujy64T;Mha-89?vusMtU8_; zqWqyT&hFa&+Gn-Pf8Adf{cLXX#rfLm$vQz|F{gzs&6C%iYEZhp&$4>v0o_YhTY{3^ zt2#WhmAU7gklg9drfg%G_*TDmi8j0c)e7Fj^Na1+ykmZP?_WAmxoD|j`I47U_#HWp zE%Mf@FVCE5U|q~LLpH2nV&R6vKC-N5__TMNu(*-9tdA+JT{I>|=8ZwHJLBt@A6hw% z85rf>6j&v=cGbz8rAarh+`8Gz`1kDjrIBrlY#Dso36OB{Y-G1~SQu%uu}lh-IXqqc KT-G@yGywod^)&kc literal 0 HcmV?d00001 diff --git a/bin/app/data/gui/graph_view/images/zoomout.png b/bin/app/data/gui/graph_view/images/zoomout.png new file mode 100644 index 0000000000000000000000000000000000000000..c1057cea05aa63beae54cc10311eda01f9a44d56 GIT binary patch literal 753 zcmeAS@N?(olHy`uVBq!ia0vp^HXzKw1|+Ti+$;i8jKx9jP7LeL$-D%zPiKZiltlRY zSS9D@>LsS+C#C9DzCHb_`sNdc^+B->Ug z!Z$#{Ilm}X!Bo#g&p^qJOF==wrYI%ND#*nRsvXF)RmvzSDX`MlFE20GD>v55FG|-p zw6wI;H!#vSGSUUA&@HaaD@m--%_~-h7y>iLCAB!YD6^m>Ge1uOWNuz7iBo^o!>KW)`(^Qg~hHxH=E|3gF8`xJ6%WQx_W93|wnpl!w z6q28xW9JA8I|a|&#Prml)WnoZ8+~*Y2$$M`jI{DE%1j0N733p3LmPbzF{pYQeUNvN zyblRmuqZHa?YMw8!6M3zOH=QxEimq`c)B=-WU#)yc9FNqK!72jgvmXD#l0xleS)CG zLEbM?Px|?9EpvUGU8I;<_4aNv!{G!01&0O(MkW>xbjDd0KT+#=W%HvE8{Iu$$#`B? z_xiNCSZ`use}$~f%C->i&mTL4`|`?c?XO-cxs&w$>xTTD%Vw4Je||Uh^dZCI+Wx1J zrccf8EN)zu{>042eC@KF&(BQ%UiH?#+dTiD&eeYvB|rJ{Y+jz9G285!uOKd0xO44c YTzP2gOvhC1W1z(8>FVdQ&MBb@0C;`&bN~PV literal 0 HcmV?d00001 diff --git a/src/lib_gui/qt/graphics/QtGraphicsView.cpp b/src/lib_gui/qt/graphics/QtGraphicsView.cpp index 48eb91b2..160122cd 100644 --- a/src/lib_gui/qt/graphics/QtGraphicsView.cpp +++ b/src/lib_gui/qt/graphics/QtGraphicsView.cpp @@ -14,7 +14,9 @@ #include "qt/view/graphElements/QtGraphNodeData.h" #include "qt/view/graphElements/QtGraphNodeBundle.h" #include "qt/utility/QtContextMenu.h" +#include "qt/utility/utilityQt.h" #include "settings/ApplicationSettings.h" +#include "utility/ResourcePaths.h" QtGraphicsView::QtGraphicsView(QWidget* parent) : QGraphicsView(parent) @@ -25,6 +27,8 @@ QtGraphicsView::QtGraphicsView(QWidget* parent) , m_left(false) , m_right(false) , m_shift(false) + , m_zoomInButtonSpeed(20.0f) + , m_zoomOutButtonSpeed(-20.0f) { setTransformationAnchor(QGraphicsView::AnchorUnderMouse); @@ -44,6 +48,20 @@ QtGraphicsView::QtGraphicsView(QWidget* parent) m_copyNodeNameAction->setStatusTip(tr("Copies the name of this node to the clipboard")); m_copyNodeNameAction->setToolTip(tr("Copies the name of this node to the clipboard")); connect(m_copyNodeNameAction, SIGNAL(triggered()), this, SLOT(copyNodeName())); + + m_zoomInButton = new QPushButton(this); + m_zoomInButton->setObjectName("zoom_in_button"); + m_zoomInButton->setAutoRepeat(true); + m_zoomInButton->setToolTip("Zoom in (Shift + Mousewheel forward)"); + connect(m_zoomInButton, SIGNAL(pressed()), this, SLOT(zoomInPressed())); + + m_zoomOutButton = new QPushButton(this); + m_zoomOutButton->setObjectName("zoom_out_button"); + m_zoomOutButton->setAutoRepeat(true); + m_zoomOutButton->setToolTip("Zoom out (Shift + Mousewheel back)"); + connect(m_zoomOutButton, SIGNAL(pressed()), this, SLOT(zoomOutPressed())); + + refreshStyle(); } float QtGraphicsView::getZoomFactor() const @@ -118,6 +136,28 @@ void QtGraphicsView::updateZoom(float delta) updateTransform(); } +void QtGraphicsView::refreshStyle() +{ + m_zoomInButton->setIcon(utility::createButtonIcon( + ResourcePaths::getGuiPath() + "graph_view/images/zoomin.png", + "search/button" + )); + + m_zoomOutButton->setIcon(utility::createButtonIcon( + ResourcePaths::getGuiPath() + "graph_view/images/zoomout.png", + "search/button" + )); +} + +void QtGraphicsView::resizeEvent(QResizeEvent* event) +{ + m_zoomInButton->setGeometry(QRect(8, event->size().height() - 50, 19, 19)); + m_zoomOutButton->setGeometry(QRect(8, event->size().height() - 27, 19, 19)); + + m_zoomInButton->setIconSize(QSize(15, 15)); + m_zoomOutButton->setIconSize(QSize(15, 15)); +} + void QtGraphicsView::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton && !itemAt(event->pos())) @@ -405,6 +445,16 @@ void QtGraphicsView::copyNodeName() QApplication::clipboard()->setText(m_clipboardNodeName.c_str()); } +void QtGraphicsView::zoomInPressed() +{ + updateZoom(m_zoomInButtonSpeed); +} + +void QtGraphicsView::zoomOutPressed() +{ + updateZoom(m_zoomOutButtonSpeed); +} + bool QtGraphicsView::moves() const { return m_up || m_down || m_left || m_right; diff --git a/src/lib_gui/qt/graphics/QtGraphicsView.h b/src/lib_gui/qt/graphics/QtGraphicsView.h index bb62bcaf..aedd6344 100644 --- a/src/lib_gui/qt/graphics/QtGraphicsView.h +++ b/src/lib_gui/qt/graphics/QtGraphicsView.h @@ -4,6 +4,7 @@ #include #include +#include #include "utility/file/FilePath.h" @@ -27,9 +28,13 @@ public: void updateZoom(float delta); + void refreshStyle(); + protected: - void mousePressEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); + void resizeEvent(QResizeEvent* event); + + void mousePressEvent(QMouseEvent* event); + void mouseReleaseEvent(QMouseEvent* event); void keyPressEvent(QKeyEvent* event); void keyReleaseEvent(QKeyEvent* event); @@ -48,6 +53,9 @@ private slots: void exportGraph(); void copyNodeName(); + void zoomInPressed(); + void zoomOutPressed(); + private: bool moves() const; @@ -71,6 +79,12 @@ private: QAction* m_exportGraphAction; QAction* m_copyNodeNameAction; + + QPushButton* m_zoomInButton; + QPushButton* m_zoomOutButton; + + float m_zoomInButtonSpeed; + float m_zoomOutButtonSpeed; }; #endif // QT_GRAPHICS_VIEW_H diff --git a/src/lib_gui/qt/view/QtGraphView.cpp b/src/lib_gui/qt/view/QtGraphView.cpp index 6ab39d8e..d233e158 100644 --- a/src/lib_gui/qt/view/QtGraphView.cpp +++ b/src/lib_gui/qt/view/QtGraphView.cpp @@ -40,10 +40,6 @@ QtGraphView::QtGraphView(ViewLayout* viewLayout) , m_refreshFunctor(std::bind(&QtGraphView::doRefreshView, this)) , m_focusInFunctor(std::bind(&QtGraphView::doFocusIn, this, std::placeholders::_1)) , m_focusOutFunctor(std::bind(&QtGraphView::doFocusOut, this, std::placeholders::_1)) - , m_zoomInButton() - , m_zoomOutButton() - , m_zoomInButtonSpeed(20.0f) - , m_zoomOutButtonSpeed(-20.0f) { } @@ -74,22 +70,6 @@ void QtGraphView::initView() widget->layout()->addWidget(view); - m_zoomInButton = new QPushButton(widget); - m_zoomInButton->setObjectName("zoom_in_button"); - m_zoomInButton->setText("+"); - m_zoomInButton->setGeometry(QRect(5, 5, 25, 25)); - m_zoomInButton->setAutoRepeat(true); - m_zoomInButton->setToolTip("Zoom in (Shift + Mousewheel forward)"); - connect(m_zoomInButton, SIGNAL(pressed()), this, SLOT(zoomInPressed())); - - m_zoomOutButton = new QPushButton(widget); - m_zoomOutButton->setObjectName("zoom_out_button"); - m_zoomOutButton->setText("-"); - m_zoomOutButton->setGeometry(QRect(5, 34, 25, 25)); - m_zoomOutButton->setAutoRepeat(true); - m_zoomOutButton->setToolTip("Zoom out (Shift + Mousewheel back)"); - connect(m_zoomOutButton, SIGNAL(pressed()), this, SLOT(zoomOutPressed())); - connect(view, SIGNAL(emptySpaceClicked()), this, SLOT(clickedInEmptySpace())); m_scrollSpeedChangeListenerHorizontal.setScrollBar(view->horizontalScrollBar()); @@ -101,6 +81,8 @@ void QtGraphView::initView() void QtGraphView::refreshView() { m_refreshFunctor(); + + getView()->refreshStyle(); } void QtGraphView::rebuildGraph( @@ -166,16 +148,6 @@ void QtGraphView::clickedInEmptySpace() } } -void QtGraphView::zoomInPressed() -{ - zoom(m_zoomInButtonSpeed); -} - -void QtGraphView::zoomOutPressed() -{ - zoom(m_zoomOutButtonSpeed); -} - void QtGraphView::switchToNewGraphData() { m_oldGraph = m_graph; @@ -752,12 +724,3 @@ void QtGraphView::doFocusOut(const std::vector& tokenIds) } } } - -void QtGraphView::zoom(const float delta) -{ - QtGraphicsView* view = getView(); - if (view != NULL) - { - view->updateZoom(delta); - } -} diff --git a/src/lib_gui/qt/view/QtGraphView.h b/src/lib_gui/qt/view/QtGraphView.h index ca728965..99fe4362 100644 --- a/src/lib_gui/qt/view/QtGraphView.h +++ b/src/lib_gui/qt/view/QtGraphView.h @@ -6,8 +6,6 @@ #include #include -#include - #include "component/view/GraphView.h" #include "qt/utility/QtScrollSpeedChangeListener.h" #include "qt/utility/QtThreadedFunctor.h" @@ -55,9 +53,6 @@ private slots: void finishedTransition(); void clickedInEmptySpace(); - void zoomInPressed(); - void zoomOutPressed(); - private: void switchToNewGraphData(); @@ -75,8 +70,6 @@ private: void doFocusIn(const std::vector& tokenIds); void doFocusOut(const std::vector& tokenIds); - void zoom(const float delta); - std::shared_ptr findNodeRecursive(const std::list>& nodes, Id tokenId); std::shared_ptr createNodeRecursive( @@ -125,12 +118,6 @@ private: QtScrollSpeedChangeListener m_scrollSpeedChangeListenerHorizontal; QtScrollSpeedChangeListener m_scrollSpeedChangeListenerVertical; - - QPushButton* m_zoomInButton; - QPushButton* m_zoomOutButton; - - float m_zoomInButtonSpeed; - float m_zoomOutButtonSpeed; }; #endif // QT_GRAPH_VIEW_H