bar.cpp
92 lines
| 2.5 KiB
| text/x-c
|
CppLexer
|
r794 | /**************************************************************************** | ||
** | ||||
|
r2688 | ** Copyright (C) 2014 Digia Plc | ||
|
r794 | ** All rights reserved. | ||
|
r2740 | ** For any questions to Digia, please use contact form at http://qt.io | ||
|
r794 | ** | ||
|
r2740 | ** This file is part of the Qt Charts module. | ||
|
r794 | ** | ||
|
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. | ||||
|
r794 | ** | ||
** If you have questions regarding the use of this file, please use | ||||
|
r2740 | ** contact form at http://qt.io | ||
|
r794 | ** | ||
****************************************************************************/ | ||||
|
r2714 | #include <private/bar_p.h> | ||
#include <QtGui/QPainter> | ||||
#include <QtWidgets/QGraphicsSceneEvent> | ||||
|
r2739 | #include <QtWidgets/QStyleOptionGraphicsItem> | ||
#include <QtWidgets/QStyle> | ||||
|
r56 | |||
|
r2712 | QT_CHARTS_BEGIN_NAMESPACE | ||
|
r56 | |||
|
r1321 | Bar::Bar(QBarSet *barset, int index, QGraphicsItem *parent) : QGraphicsRectItem(parent), | ||
m_index(index), | ||||
|
r1563 | m_barset(barset), | ||
|
r2739 | m_hovering(false), | ||
m_mousePressed(false) | ||||
|
r56 | { | ||
|
r1321 | setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton); | ||
|
r280 | setAcceptHoverEvents(true); | ||
|
r2739 | setFlag(QGraphicsItem::ItemIsSelectable); | ||
|
r56 | } | ||
|
r1563 | Bar::~Bar() | ||
{ | ||||
// End hover event, if bar is deleted during it | ||||
|
r2726 | if (m_hovering) | ||
|
r2600 | emit hovered(false, m_index, m_barset); | ||
|
r1563 | } | ||
|
r737 | void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event) | ||
|
r256 | { | ||
|
r2739 | emit pressed(m_index, m_barset); | ||
m_mousePressed = true; | ||||
|
r1747 | QGraphicsItem::mousePressEvent(event); | ||
|
r256 | } | ||
|
r737 | void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event) | ||
|
r276 | { | ||
|
r978 | Q_UNUSED(event) | ||
|
r1563 | m_hovering = true; | ||
|
r2600 | emit hovered(true, m_index, m_barset); | ||
|
r1747 | |||
|
r276 | } | ||
|
r737 | void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) | ||
|
r276 | { | ||
|
r737 | Q_UNUSED(event) | ||
|
r1563 | m_hovering = false; | ||
|
r2600 | emit hovered(false, m_index, m_barset); | ||
|
r276 | } | ||
|
r2739 | void Bar::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) | ||
{ | ||||
emit released(m_index, m_barset); | ||||
|
r2746 | if (m_mousePressed) | ||
|
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); | ||||
} | ||||
|
r256 | #include "moc_bar_p.cpp" | ||
|
r239 | |||
|
r2712 | QT_CHARTS_END_NAMESPACE | ||