aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Fadel <samuelfadel@gmail.com>2016-01-28 11:39:05 +0100
committerSamuel Fadel <samuelfadel@gmail.com>2016-01-28 11:39:05 +0100
commit025b2fac13177bc9182df16ae7324e515720885e (patch)
tree5f16e4c5d8bd1bce73272c80d29c5ee45873ce89
parentb7d624feb33826e63df44ec8706ecaca885f7da5 (diff)
BarChart: handle right clicks (clear selection).
-rw-r--r--barchart.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/barchart.cpp b/barchart.cpp
index 1aacfdb..70c6004 100644
--- a/barchart.cpp
+++ b/barchart.cpp
@@ -354,12 +354,19 @@ void BarChart::hoverLeaveEvent(QHoverEvent *event)
void BarChart::mousePressEvent(QMouseEvent *event)
{
- QCursor dragCursor(Qt::SizeHorCursor);
- setCursor(dragCursor);
+ if (event->button() == Qt::RightButton) {
+ m_dragStartPos = -1.0f;
+ m_dragLastPos = -1.0f;
+ m_selection.assign(m_selection.size(), false);
+ emit selectionInteractivelyChanged(m_selection);
+ } else {
+ QCursor dragCursor(Qt::SizeHorCursor);
+ setCursor(dragCursor);
- float pos = float(event->pos().x()) / width();
- m_dragStartPos = pos;
- m_dragLastPos = pos;
+ float pos = float(event->pos().x()) / width();
+ m_dragStartPos = pos;
+ m_dragLastPos = pos;
+ }
m_shouldUpdateSelectionRect = true;
update();
@@ -367,6 +374,10 @@ void BarChart::mousePressEvent(QMouseEvent *event)
void BarChart::mouseMoveEvent(QMouseEvent *event)
{
+ if (m_dragStartPos < 0.0f) {
+ return;
+ }
+
float pos = float(event->pos().x()) / width();
m_dragLastPos = clamp(pos, 0.0f, 1.0f);
@@ -376,6 +387,10 @@ void BarChart::mouseMoveEvent(QMouseEvent *event)
void BarChart::mouseReleaseEvent(QMouseEvent *event)
{
+ if (m_dragStartPos < 0.0f) {
+ return;
+ }
+
unsetCursor();
float pos = float(event->pos().x()) / width();