bar.cpp
103 lines
| 3.2 KiB
| text/x-c
|
CppLexer
Miikka Heikkinen
|
r2854 | /**************************************************************************** | ||
Jani Honkonen
|
r794 | ** | ||
Miikka Heikkinen
|
r2854 | ** Copyright (C) 2016 The Qt Company Ltd. | ||
** Contact: https://www.qt.io/licensing/ | ||||
Jani Honkonen
|
r794 | ** | ||
Miikka Heikkinen
|
r2854 | ** This file is part of the Qt Charts module of the Qt Toolkit. | ||
Jani Honkonen
|
r794 | ** | ||
Miikka Heikkinen
|
r2854 | ** $QT_BEGIN_LICENSE:GPL$ | ||
Titta Heikkala
|
r2845 | ** Commercial License Usage | ||
** Licensees holding valid commercial Qt licenses may use this file in | ||||
** accordance with the commercial license agreement provided with the | ||||
** Software or, alternatively, in accordance with the terms contained in | ||||
** a written agreement between you and The Qt Company. For licensing terms | ||||
Miikka Heikkinen
|
r2854 | ** and conditions see https://www.qt.io/terms-conditions. For further | ||
** information use the contact form at https://www.qt.io/contact-us. | ||||
** | ||||
** GNU General Public License Usage | ||||
** Alternatively, this file may be used under the terms of the GNU | ||||
** General Public License version 3 or (at your option) any later version | ||||
** approved by the KDE Free Qt Foundation. The licenses are as published by | ||||
** the Free Software Foundation and appearing in the file LICENSE.GPL3 | ||||
** included in the packaging of this file. Please review the following | ||||
** information to ensure the GNU General Public License requirements will | ||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html. | ||||
Jani Honkonen
|
r794 | ** | ||
Titta Heikkala
|
r2845 | ** $QT_END_LICENSE$ | ||
** | ||||
Miikka Heikkinen
|
r2854 | ****************************************************************************/ | ||
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 | ||