qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
toolboxgraphicsitem.cpp
Go to the documentation of this file.
1 /*
2  Copyright © 2015-2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "toolboxgraphicsitem.h"
21 
22 #include <QPainter>
23 
25 {
26  this->opacityAnimation = new QPropertyAnimation(this, QByteArrayLiteral("opacity"), this);
27 
28  this->opacityAnimation->setKeyValueAt(0, this->idleOpacity);
29  this->opacityAnimation->setKeyValueAt(1, this->activeOpacity);
30  this->opacityAnimation->setDuration(this->fadeTimeMs);
31 
32  setOpacity(this->activeOpacity);
33 }
34 
36 {
37 }
38 
39 void ToolBoxGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
40 {
41  startAnimation(QAbstractAnimation::Backward);
42  QGraphicsItemGroup::hoverEnterEvent(event);
43 }
44 
45 void ToolBoxGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
46 {
47  startAnimation(QAbstractAnimation::Forward);
48  QGraphicsItemGroup::hoverLeaveEvent(event);
49 }
50 
51 void ToolBoxGraphicsItem::startAnimation(QAbstractAnimation::Direction direction)
52 {
53  this->opacityAnimation->setDirection(direction);
54  this->opacityAnimation->start();
55 }
56 
57 void ToolBoxGraphicsItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
58  QWidget* widget)
59 {
60  painter->save();
61  painter->setPen(Qt::NoPen);
62  painter->setBrush(QBrush(QColor(0xFF, 0xE2, 0x82)));
63  painter->drawRect(childrenBoundingRect());
64  painter->restore();
65 
66  QGraphicsItemGroup::paint(painter, option, widget);
67 }
ToolBoxGraphicsItem::paint
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) final
Definition: toolboxgraphicsitem.cpp:57
ToolBoxGraphicsItem::startAnimation
void startAnimation(QAbstractAnimation::Direction direction)
Definition: toolboxgraphicsitem.cpp:51
toolboxgraphicsitem.h
ToolBoxGraphicsItem::idleOpacity
qreal idleOpacity
Definition: toolboxgraphicsitem.h:45
ToolBoxGraphicsItem::activeOpacity
qreal activeOpacity
Definition: toolboxgraphicsitem.h:46
ToolBoxGraphicsItem::fadeTimeMs
int fadeTimeMs
Definition: toolboxgraphicsitem.h:47
ToolBoxGraphicsItem::hoverLeaveEvent
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) final
Definition: toolboxgraphicsitem.cpp:45
ToolBoxGraphicsItem::opacityAnimation
QPropertyAnimation * opacityAnimation
Definition: toolboxgraphicsitem.h:44
ToolBoxGraphicsItem::ToolBoxGraphicsItem
ToolBoxGraphicsItem()
Definition: toolboxgraphicsitem.cpp:24
ToolBoxGraphicsItem::~ToolBoxGraphicsItem
~ToolBoxGraphicsItem()
Definition: toolboxgraphicsitem.cpp:35
ToolBoxGraphicsItem::hoverEnterEvent
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) final
Definition: toolboxgraphicsitem.cpp:39