close button icon

This commit is contained in:
Gary Wang 2019-10-06 14:12:52 +08:00
parent 0ae1def918
commit 665385aa3d
7 changed files with 142 additions and 12 deletions

View File

@ -30,14 +30,16 @@ SOURCES += \
graphicsview.cpp \ graphicsview.cpp \
bottombuttongroup.cpp \ bottombuttongroup.cpp \
graphicsscene.cpp \ graphicsscene.cpp \
navigatorview.cpp navigatorview.cpp \
toolbutton.cpp
HEADERS += \ HEADERS += \
mainwindow.h \ mainwindow.h \
graphicsview.h \ graphicsview.h \
bottombuttongroup.h \ bottombuttongroup.h \
graphicsscene.h \ graphicsscene.h \
navigatorview.h navigatorview.h \
toolbutton.h
FORMS += FORMS +=

71
icons/window-close.svg Normal file
View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="32"
height="32"
viewBox="0 0 8.4666665 8.4666669"
version="1.1"
id="svg8"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="window-close.svg">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#000000"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.69803922"
inkscape:pageshadow="2"
inkscape:zoom="22.627417"
inkscape:cx="19.29838"
inkscape:cy="15.79404"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
units="px"
inkscape:pagecheckerboard="true"
inkscape:window-width="1920"
inkscape:window-height="1001"
inkscape:window-x="-9"
inkscape:window-y="-9"
inkscape:window-maximized="1" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-288.5333)">
<path
style="fill:none;stroke:#ffffff;stroke-width:0.396875;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
d="m 2.100237,290.55098 4.3234589,4.22265"
id="path817"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:none;stroke:#ffffff;stroke-width:0.396875;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
d="m 2.099406,294.78651 4.3414732,-4.24185"
id="path819"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -1,5 +1,6 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "toolbutton.h"
#include "bottombuttongroup.h" #include "bottombuttongroup.h"
#include "graphicsview.h" #include "graphicsview.h"
#include "navigatorview.h" #include "navigatorview.h"
@ -63,15 +64,9 @@ MainWindow::MainWindow(QWidget *parent) :
connect(m_graphicsView, &GraphicsView::viewportRectChanged, connect(m_graphicsView, &GraphicsView::viewportRectChanged,
m_gv, &NavigatorView::updateMainViewportRegion); m_gv, &NavigatorView::updateMainViewportRegion);
m_closeButton = new QPushButton(m_graphicsView); m_closeButton = new ToolButton(m_graphicsView);
m_closeButton->setFlat(true); m_closeButton->setIcon(QIcon(":/icons/window-close"));
m_closeButton->setFixedSize(50, 50); m_closeButton->setIconSize(QSize(50, 50));
m_closeButton->setStyleSheet("QPushButton {"
"background: transparent;"
"}"
"QPushButton:hover {"
"background: red;"
"}");
connect(m_closeButton, &QAbstractButton::clicked, connect(m_closeButton, &QAbstractButton::clicked,
this, &MainWindow::closeWindow); this, &MainWindow::closeWindow);
@ -174,6 +169,8 @@ void MainWindow::enterEvent(QEvent *event)
m_bribViewOpacityAnimation->setEndValue(1); m_bribViewOpacityAnimation->setEndValue(1);
m_bribViewOpacityAnimation->start(); m_bribViewOpacityAnimation->start();
m_closeButton->setIconOpacity(1);
return QMainWindow::enterEvent(event); return QMainWindow::enterEvent(event);
} }
@ -189,6 +186,8 @@ void MainWindow::leaveEvent(QEvent *event)
m_bribViewOpacityAnimation->setEndValue(0); m_bribViewOpacityAnimation->setEndValue(0);
m_bribViewOpacityAnimation->start(); m_bribViewOpacityAnimation->start();
m_closeButton->setIconOpacity(0);
return QMainWindow::leaveEvent(event); return QMainWindow::leaveEvent(event);
} }

View File

@ -11,6 +11,7 @@ class QGraphicsOpacityEffect;
class QGraphicsView; class QGraphicsView;
QT_END_NAMESPACE QT_END_NAMESPACE
class ToolButton;
class GraphicsView; class GraphicsView;
class NavigatorView; class NavigatorView;
class BottomButtonGroup; class BottomButtonGroup;
@ -55,7 +56,7 @@ private:
QPropertyAnimation *m_fadeOutAnimation; QPropertyAnimation *m_fadeOutAnimation;
QPropertyAnimation *m_floatUpAnimation; QPropertyAnimation *m_floatUpAnimation;
QParallelAnimationGroup *m_exitAnimationGroup; QParallelAnimationGroup *m_exitAnimationGroup;
QPushButton *m_closeButton; ToolButton *m_closeButton;
GraphicsView *m_graphicsView; GraphicsView *m_graphicsView;
NavigatorView *m_gv; NavigatorView *m_gv;
BottomButtonGroup *m_bottomButtonGroup; BottomButtonGroup *m_bottomButtonGroup;

View File

@ -7,5 +7,6 @@
<file>icons/object-rotate-right.svg</file> <file>icons/object-rotate-right.svg</file>
<file>icons/view-background-checkerboard.svg</file> <file>icons/view-background-checkerboard.svg</file>
<file>icons/app-icon.svg</file> <file>icons/app-icon.svg</file>
<file>icons/window-close.svg</file>
</qresource> </qresource>
</RCC> </RCC>

31
toolbutton.cpp Normal file
View File

@ -0,0 +1,31 @@
#include "toolbutton.h"
#include <QPainter>
#include <QGraphicsOpacityEffect>
#include <QPropertyAnimation>
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();
}

25
toolbutton.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef TOOLBUTTON_H
#define TOOLBUTTON_H
#include <QPushButton>
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