• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • workspace API Reference
  • KDE Home
  • Contact Us
 

liblancelot

  • sources
  • kde-4.14
  • workspace
  • kdeplasma-addons
  • libs
  • lancelot
  • widgets
ScrollBar.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007, 2008, 2009, 2010 Ivan Cukic <ivan.cukic(at)kde.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser/Library General Public License version 2,
6  * or (at your option) any later version, as published by the Free
7  * Software Foundation
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser/Library General Public License for more details
13  *
14  * You should have received a copy of the GNU Lesser/Library General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
20 #include "ScrollBar.h"
21 #include "ExtenderButton.h"
22 
23 #include <QTimer>
24 #include <QGraphicsSceneMouseEvent>
25 #include <QBasicTimer>
26 
27 #define SINGLE_SHOT_INTERVAL 50
28 #define SINGLE_SHOT_MOVE 10
29 
30 namespace Lancelot
31 {
32 
33 class ScrollBar::Private {
34 public:
35  Private()
36  : direction(0), hoverScroll(true)
37  {}
38 
39  QBasicTimer timer;
40  int direction;
41  bool hoverScroll: 1;
42 };
43 
44 ScrollBar::ScrollBar(QGraphicsWidget * parent)
45  : Plasma::ScrollBar(parent), d(new Private())
46 {
47  setPageStep(100);
48  setSingleStep(20);
49 }
50 
51 ScrollBar::~ScrollBar()
52 {
53  delete d;
54 }
55 
56 void ScrollBar::wheelEvent(QGraphicsSceneWheelEvent * event)
57 {
58  if (isVisible()) {
59  Plasma::ScrollBar::wheelEvent(event);
60  }
61 }
62 
63 void ScrollBar::hoverLeaveEvent(QGraphicsSceneHoverEvent * event)
64 {
65  d->timer.stop();
66  Plasma::ScrollBar::hoverLeaveEvent(event);
67 }
68 
69 void ScrollBar::hoverMoveEvent(QGraphicsSceneHoverEvent * event)
70 {
71  Plasma::ScrollBar::hoverMoveEvent(event);
72  if (!d->hoverScroll) {
73  return;
74  }
75 
76  QPointF pos = event->pos();
77 
78  QScrollBar * sbar = qobject_cast
79  < QScrollBar * > (widget());
80 
81  if (!sbar) {
82  return;
83  }
84 
85  if (sbar->orientation() == Qt::Vertical) {
86  if (pos.y() < size().width()) {
87  d->direction = -1;
88  } else if (pos.y() > size().height() - size().width()) {
89  d->direction = +1;
90  } else {
91  d->direction = 0;
92  }
93  } else {
94  if (pos.x() < size().height()) {
95  d->direction = -1;
96  } else if (pos.x() > size().width() - size().height()) {
97  d->direction = +1;
98  } else {
99  d->direction = 0;
100  }
101  }
102 
103  if ((!d->timer.isActive()) && (d->direction != 0)) {
104  d->timer.start(SINGLE_SHOT_INTERVAL, this);
105  }
106 }
107 
108 void ScrollBar::timerEvent(QTimerEvent * event)
109 {
110  if (event->timerId() == d->timer.timerId()) {
111  setValue(value() + d->direction * SINGLE_SHOT_MOVE);
112  }
113  Plasma::ScrollBar::timerEvent(event);
114 }
115 
116 void ScrollBar::setActivationMethod(int method)
117 {
118  d->hoverScroll = (method != Lancelot::ClickActivate);
119 }
120 
121 int ScrollBar::activationMethod() const
122 {
123  if (d->hoverScroll) {
124  return Lancelot::HoverActivate;
125  } else {
126  return Lancelot::ClickActivate;
127  }
128 }
129 
130 
131 } // namespace Lancelot
132 
QBasicTimer
Lancelot::ScrollBar::wheelEvent
L_Override void wheelEvent(QGraphicsSceneWheelEvent *event)
Definition: ScrollBar.cpp:56
QGraphicsSceneWheelEvent
Lancelot::ScrollBar::timerEvent
L_Override void timerEvent(QTimerEvent *event)
Definition: ScrollBar.cpp:108
QScrollBar
Lancelot::ScrollBar
A widget implementing scroll bars.
Definition: ScrollBar.h:36
QPointF
QTimerEvent
QPointF::x
qreal x() const
QPointF::y
qreal y() const
SINGLE_SHOT_MOVE
#define SINGLE_SHOT_MOVE
Definition: ScrollBar.cpp:28
Lancelot::ScrollBar::activationMethod
int activationMethod() const
QAbstractSlider::orientation
orientation
QGraphicsWidget
QGraphicsSceneHoverEvent
Lancelot::ScrollBar::~ScrollBar
~ScrollBar()
Destroys this Lancelot::ScrollBar.
Definition: ScrollBar.cpp:51
Lancelot::ScrollBar::ScrollBar
ScrollBar(QGraphicsWidget *parent=0)
Creates a new Lancelot::ScrollBar.
Definition: ScrollBar.cpp:44
Lancelot::ScrollBar::setActivationMethod
void setActivationMethod(int method)
Sets the activation method of the ExtenderButton.
Definition: ScrollBar.cpp:116
SINGLE_SHOT_INTERVAL
#define SINGLE_SHOT_INTERVAL
Definition: ScrollBar.cpp:27
Lancelot::ScrollBar::hoverMoveEvent
L_Override void hoverMoveEvent(QGraphicsSceneHoverEvent *event)
Definition: ScrollBar.cpp:69
Lancelot::ScrollBar::hoverLeaveEvent
L_Override void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Definition: ScrollBar.cpp:63
ExtenderButton.h
QTimerEvent::timerId
int timerId() const
ScrollBar.h
Lancelot::HoverActivate
Definition: lancelot.h:40
Lancelot::ClickActivate
Definition: lancelot.h:41
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:43:01 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

liblancelot

Skip menu "liblancelot"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

workspace API Reference

Skip menu "workspace API Reference"
  • kdeplasma-addons
  •       GroupingDesktop
  •     liblancelot

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal