┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2008-12-07 14:08:34 +0000
committerPeter Penz <[email protected]>2008-12-07 14:08:34 +0000
commita44f22a63d6b4af978bba9c2721fb6af9c1f3367 (patch)
treea26b0455fc690f7860db56c5520c4fe1cb4bbd2b
parent3c4c6319cf5bdfdcdb63b66c5304fc09e5125540 (diff)
also implement autoscrolling for horizontally aligned views (e. g. icons view in the column mode)
svn path=/trunk/KDE/kdebase/apps/; revision=893894
-rw-r--r--src/dolphinviewautoscroller.cpp83
-rw-r--r--src/dolphinviewautoscroller.h6
2 files changed, 57 insertions, 32 deletions
diff --git a/src/dolphinviewautoscroller.cpp b/src/dolphinviewautoscroller.cpp
index 45abc1e92..bbcf16ac3 100644
--- a/src/dolphinviewautoscroller.cpp
+++ b/src/dolphinviewautoscroller.cpp
@@ -87,51 +87,48 @@ bool DolphinViewAutoScroller::eventFilter(QObject* watched, QEvent* event)
void DolphinViewAutoScroller::scrollViewport()
{
- // TODO: implement horizontal scrolling
QScrollBar* verticalScrollBar = m_itemView->verticalScrollBar();
if (verticalScrollBar != 0) {
const int value = verticalScrollBar->value();
verticalScrollBar->setValue(value + m_scrollInc);
- if (m_rubberBandSelection) {
- // The scrolling does not lead to an update of the rubberband
- // selection. Fake a mouse move event to let the QAbstractItemView
- // update the rubberband.
- QWidget* viewport = m_itemView->viewport();
- const QPoint pos = viewport->mapFromGlobal(QCursor::pos());
- QMouseEvent event(QEvent::MouseMove, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
- QCoreApplication::sendEvent(viewport, &event);
- }
+ }
+ QScrollBar* horizontalScrollBar = m_itemView->horizontalScrollBar();
+ if (horizontalScrollBar != 0) {
+ const int value = horizontalScrollBar->value();
+ horizontalScrollBar->setValue(value + m_scrollInc);
+
+ }
+
+ if (m_rubberBandSelection) {
+ // The scrolling does not lead to an update of the rubberband
+ // selection. Fake a mouse move event to let the QAbstractItemView
+ // update the rubberband.
+ QWidget* viewport = m_itemView->viewport();
+ const QPoint pos = viewport->mapFromGlobal(QCursor::pos());
+ QMouseEvent event(QEvent::MouseMove, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
+ QCoreApplication::sendEvent(viewport, &event);
}
}
void DolphinViewAutoScroller::triggerAutoScroll()
{
- // TODO: implement horizontal scrolling
-
- const int startSpeed = 2;
- const int speedLimiter = 8;
- const int scrollIncMax = 32;
-
- const int autoScrollBorder = 32;
+ const bool verticalScrolling = (m_itemView->verticalScrollBar() != 0) &&
+ m_itemView->verticalScrollBar()->isVisible();
+ const bool horizontalScrolling = (m_itemView->horizontalScrollBar() != 0) &&
+ m_itemView->horizontalScrollBar()->isVisible();
+ if (!verticalScrolling && !horizontalScrolling) {
+ // no scrollbars are shown at all, so no autoscrolling is necessary
+ return;
+ }
QWidget* viewport = m_itemView->viewport();
const QPoint pos = viewport->mapFromGlobal(QCursor::pos());
- if (pos.y() < autoScrollBorder) {
- // scroll up
- m_scrollInc = -startSpeed + (pos.y() - autoScrollBorder) / speedLimiter;
- if (m_scrollInc < -scrollIncMax) {
- m_scrollInc = -scrollIncMax;
- }
- } else if (pos.y() > viewport->height() - autoScrollBorder) {
- // scroll down
- m_scrollInc = startSpeed + (pos.y() - viewport->height() + autoScrollBorder) / speedLimiter;
- if (m_scrollInc > scrollIncMax) {
- m_scrollInc = scrollIncMax;
- }
- } else {
- // no scrolling
- m_scrollInc = 0;
+ if (verticalScrolling) {
+ calculateScrollIncrement(pos.y(), viewport->height());
+ }
+ if (horizontalScrolling) {
+ calculateScrollIncrement(pos.x(), viewport->width());
}
if (m_timer->isActive()) {
@@ -149,4 +146,26 @@ void DolphinViewAutoScroller::stopAutoScroll()
m_scrollInc = 0;
}
+void DolphinViewAutoScroller::calculateScrollIncrement(int cursorPos, int rangeSize)
+{
+ const int minSpeed = 2;
+ const int maxSpeed = 32;
+ const int speedLimiter = 8;
+ const int autoScrollBorder = 32;
+
+ if (cursorPos < autoScrollBorder) {
+ m_scrollInc = -minSpeed + (cursorPos - autoScrollBorder) / speedLimiter;
+ if (m_scrollInc < -maxSpeed) {
+ m_scrollInc = -maxSpeed;
+ }
+ } else if (cursorPos > rangeSize - autoScrollBorder) {
+ m_scrollInc = minSpeed + (cursorPos - rangeSize + autoScrollBorder) / speedLimiter;
+ if (m_scrollInc > maxSpeed) {
+ m_scrollInc = maxSpeed;
+ }
+ } else {
+ m_scrollInc = 0;
+ }
+}
+
#include "dolphinviewautoscroller.moc"
diff --git a/src/dolphinviewautoscroller.h b/src/dolphinviewautoscroller.h
index c02112b7b..c04e22e28 100644
--- a/src/dolphinviewautoscroller.h
+++ b/src/dolphinviewautoscroller.h
@@ -49,6 +49,12 @@ private:
void triggerAutoScroll();
void stopAutoScroll();
+ /**
+ * Calculates the scroll increment m_scrollInc dependent from
+ * the cursor position \a cursorPos and the range 0 - \a rangeSize - 1.
+ */
+ void calculateScrollIncrement(int cursorPos, int rangeSize);
+
private:
bool m_rubberBandSelection;
int m_scrollInc;