diff --git a/PineapplePictures.pro b/PineapplePictures.pro
index 63e4040..a22e560 100644
--- a/PineapplePictures.pro
+++ b/PineapplePictures.pro
@@ -30,14 +30,16 @@ SOURCES += \
graphicsview.cpp \
bottombuttongroup.cpp \
graphicsscene.cpp \
- navigatorview.cpp
+ navigatorview.cpp \
+ toolbutton.cpp
HEADERS += \
mainwindow.h \
graphicsview.h \
bottombuttongroup.h \
graphicsscene.h \
- navigatorview.h
+ navigatorview.h \
+ toolbutton.h
FORMS +=
diff --git a/icons/window-close.svg b/icons/window-close.svg
new file mode 100644
index 0000000..daca19c
--- /dev/null
+++ b/icons/window-close.svg
@@ -0,0 +1,71 @@
+
+
+
+
diff --git a/mainwindow.cpp b/mainwindow.cpp
index 2a18406..8348f5a 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -1,5 +1,6 @@
#include "mainwindow.h"
+#include "toolbutton.h"
#include "bottombuttongroup.h"
#include "graphicsview.h"
#include "navigatorview.h"
@@ -63,15 +64,9 @@ MainWindow::MainWindow(QWidget *parent) :
connect(m_graphicsView, &GraphicsView::viewportRectChanged,
m_gv, &NavigatorView::updateMainViewportRegion);
- m_closeButton = new QPushButton(m_graphicsView);
- m_closeButton->setFlat(true);
- m_closeButton->setFixedSize(50, 50);
- m_closeButton->setStyleSheet("QPushButton {"
- "background: transparent;"
- "}"
- "QPushButton:hover {"
- "background: red;"
- "}");
+ m_closeButton = new ToolButton(m_graphicsView);
+ m_closeButton->setIcon(QIcon(":/icons/window-close"));
+ m_closeButton->setIconSize(QSize(50, 50));
connect(m_closeButton, &QAbstractButton::clicked,
this, &MainWindow::closeWindow);
@@ -174,6 +169,8 @@ void MainWindow::enterEvent(QEvent *event)
m_bribViewOpacityAnimation->setEndValue(1);
m_bribViewOpacityAnimation->start();
+ m_closeButton->setIconOpacity(1);
+
return QMainWindow::enterEvent(event);
}
@@ -189,6 +186,8 @@ void MainWindow::leaveEvent(QEvent *event)
m_bribViewOpacityAnimation->setEndValue(0);
m_bribViewOpacityAnimation->start();
+ m_closeButton->setIconOpacity(0);
+
return QMainWindow::leaveEvent(event);
}
diff --git a/mainwindow.h b/mainwindow.h
index 7687b1a..230650c 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -11,6 +11,7 @@ class QGraphicsOpacityEffect;
class QGraphicsView;
QT_END_NAMESPACE
+class ToolButton;
class GraphicsView;
class NavigatorView;
class BottomButtonGroup;
@@ -55,7 +56,7 @@ private:
QPropertyAnimation *m_fadeOutAnimation;
QPropertyAnimation *m_floatUpAnimation;
QParallelAnimationGroup *m_exitAnimationGroup;
- QPushButton *m_closeButton;
+ ToolButton *m_closeButton;
GraphicsView *m_graphicsView;
NavigatorView *m_gv;
BottomButtonGroup *m_bottomButtonGroup;
diff --git a/resources.qrc b/resources.qrc
index d4311dc..71ea699 100644
--- a/resources.qrc
+++ b/resources.qrc
@@ -7,5 +7,6 @@
icons/object-rotate-right.svg
icons/view-background-checkerboard.svg
icons/app-icon.svg
+ icons/window-close.svg
diff --git a/toolbutton.cpp b/toolbutton.cpp
new file mode 100644
index 0000000..6e66fa8
--- /dev/null
+++ b/toolbutton.cpp
@@ -0,0 +1,31 @@
+#include "toolbutton.h"
+
+#include
+#include
+#include
+
+ToolButton::ToolButton(QWidget *parent)
+ : QPushButton(parent)
+ , m_opacityFx(new QGraphicsOpacityEffect(this))
+ , m_opacityAnimation(new QPropertyAnimation(m_opacityFx, "opacity"))
+{
+ setFlat(true);
+ setFixedSize(50, 50);
+ setGraphicsEffect(m_opacityFx);
+ setStyleSheet("QPushButton {"
+ "background: transparent;"
+ "}"
+ "QPushButton:hover {"
+ "background: red;"
+ "}");
+
+ m_opacityAnimation->setDuration(300);
+}
+
+void ToolButton::setIconOpacity(qreal opacity)
+{
+ m_opacityAnimation->stop();
+ m_opacityAnimation->setStartValue(m_opacityFx->opacity());
+ m_opacityAnimation->setEndValue(opacity);
+ m_opacityAnimation->start();
+}
diff --git a/toolbutton.h b/toolbutton.h
new file mode 100644
index 0000000..0002273
--- /dev/null
+++ b/toolbutton.h
@@ -0,0 +1,25 @@
+#ifndef TOOLBUTTON_H
+#define TOOLBUTTON_H
+
+#include
+
+QT_BEGIN_NAMESPACE
+class QGraphicsOpacityEffect;
+class QPropertyAnimation;
+QT_END_NAMESPACE
+
+class ToolButton : public QPushButton
+{
+ Q_OBJECT
+public:
+ ToolButton(QWidget * parent = nullptr);
+
+public slots:
+ void setIconOpacity(qreal opacity);
+
+private:
+ QGraphicsOpacityEffect * m_opacityFx;
+ QPropertyAnimation * m_opacityAnimation;
+};
+
+#endif // TOOLBUTTON_H