bar.cpp
92 lines
| 2.5 KiB
| text/x-c
|
CppLexer
Jani Honkonen
|
r794 | /**************************************************************************** | ||
** | ||||
Titta Heikkala
|
r2688 | ** Copyright (C) 2014 Digia Plc | ||
Jani Honkonen
|
r794 | ** All rights reserved. | ||
Titta Heikkala
|
r2740 | ** For any questions to Digia, please use contact form at http://qt.io | ||
Jani Honkonen
|
r794 | ** | ||
Titta Heikkala
|
r2740 | ** This file is part of the Qt Charts module. | ||
Jani Honkonen
|
r794 | ** | ||
Titta Heikkala
|
r2740 | ** Licensees holding valid commercial license for Qt may use this file in | ||
** accordance with the Qt License Agreement provided with the Software | ||||
** or, alternatively, in accordance with the terms contained in a written | ||||
** agreement between you and Digia. | ||||
Jani Honkonen
|
r794 | ** | ||
** If you have questions regarding the use of this file, please use | ||||
Titta Heikkala
|
r2740 | ** contact form at http://qt.io | ||
Jani Honkonen
|
r794 | ** | ||
****************************************************************************/ | ||||
Titta Heikkala
|
r2714 | #include <private/bar_p.h> | ||
#include <QtGui/QPainter> | ||||
#include <QtWidgets/QGraphicsSceneEvent> | ||||
Titta Heikkala
|
r2739 | #include <QtWidgets/QStyleOptionGraphicsItem> | ||
#include <QtWidgets/QStyle> | ||||
sauimone
|
r56 | |||
Titta Heikkala
|
r2712 | QT_CHARTS_BEGIN_NAMESPACE | ||
sauimone
|
r56 | |||
sauimone
|
r1321 | Bar::Bar(QBarSet *barset, int index, QGraphicsItem *parent) : QGraphicsRectItem(parent), | ||
m_index(index), | ||||
sauimone
|
r1563 | m_barset(barset), | ||
Titta Heikkala
|
r2739 | m_hovering(false), | ||
m_mousePressed(false) | ||||
sauimone
|
r56 | { | ||
sauimone
|
r1321 | setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton); | ||
sauimone
|
r280 | setAcceptHoverEvents(true); | ||
Titta Heikkala
|
r2739 | setFlag(QGraphicsItem::ItemIsSelectable); | ||
sauimone
|
r56 | } | ||
sauimone
|
r1563 | Bar::~Bar() | ||
{ | ||||
// End hover event, if bar is deleted during it | ||||
Titta Heikkala
|
r2726 | if (m_hovering) | ||
Titta Heikkala
|
r2600 | emit hovered(false, m_index, m_barset); | ||
sauimone
|
r1563 | } | ||
Tero Ahola
|
r737 | void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event) | ||
sauimone
|
r256 | { | ||
Titta Heikkala
|
r2739 | emit pressed(m_index, m_barset); | ||
m_mousePressed = true; | ||||
Michal Klocek
|
r1747 | QGraphicsItem::mousePressEvent(event); | ||
sauimone
|
r256 | } | ||
Tero Ahola
|
r737 | void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event) | ||
sauimone
|
r276 | { | ||
Jani Honkonen
|
r978 | Q_UNUSED(event) | ||
sauimone
|
r1563 | m_hovering = true; | ||
Titta Heikkala
|
r2600 | emit hovered(true, m_index, m_barset); | ||
Michal Klocek
|
r1747 | |||
sauimone
|
r276 | } | ||
Tero Ahola
|
r737 | void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) | ||
sauimone
|
r276 | { | ||
Tero Ahola
|
r737 | Q_UNUSED(event) | ||
sauimone
|
r1563 | m_hovering = false; | ||
Titta Heikkala
|
r2600 | emit hovered(false, m_index, m_barset); | ||
sauimone
|
r276 | } | ||
Titta Heikkala
|
r2739 | void Bar::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) | ||
{ | ||||
emit released(m_index, m_barset); | ||||
Titta Heikkala
|
r2746 | if (m_mousePressed) | ||
Titta Heikkala
|
r2739 | emit clicked(m_index, m_barset); | ||
m_mousePressed = false; | ||||
QGraphicsItem::mouseReleaseEvent(event); | ||||
} | ||||
void Bar::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) | ||||
{ | ||||
emit doubleClicked(m_index, m_barset); | ||||
QGraphicsItem::mouseDoubleClickEvent(event); | ||||
} | ||||
void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | ||||
{ | ||||
// Remove selection border around bar | ||||
QStyleOptionGraphicsItem barOption(*option); | ||||
barOption.state &= ~QStyle::State_Selected; | ||||
QGraphicsRectItem::paint(painter, &barOption, widget); | ||||
} | ||||
sauimone
|
r256 | #include "moc_bar_p.cpp" | ||
sauimone
|
r239 | |||
Titta Heikkala
|
r2712 | QT_CHARTS_END_NAMESPACE | ||