const QScrollBar* scrollBar = (view->scrollOrientation() == Qt::Vertical)
? verticalScrollBar() : horizontalScrollBar();
- const qreal currentOffset = view->offset();
+ const qreal currentOffset = view->scrollOffset();
if (static_cast<int>(currentOffset) == scrollBar->value()) {
// The current offset is already synchronous to the scrollbar
return;
m_smoothScrollingAnimation->setEndValue(endOffset);
m_smoothScrollingAnimation->setEasingCurve(animRunning ? QEasingCurve::OutQuad : QEasingCurve::InOutQuad);
m_smoothScrollingAnimation->start();
- view->setOffset(startOffset);
+ view->setScrollOffset(startOffset);
} else {
- view->setOffset(endOffset);
+ view->setScrollOffset(endOffset);
}
}
QGraphicsScene* scene = static_cast<QGraphicsView*>(viewport())->scene();
if (previous) {
scene->removeItem(previous);
- disconnect(previous, SIGNAL(offsetChanged(qreal,qreal)), this, SLOT(updateScrollBars()));
- disconnect(previous, SIGNAL(maximumOffsetChanged(qreal,qreal)), this, SLOT(updateScrollBars()));
- disconnect(previous, SIGNAL(scrollTo(qreal)), this, SLOT(scrollTo(qreal)));
+ disconnect(previous, SIGNAL(scrollOffsetChanged(qreal,qreal)), this, SLOT(updateScrollOffsetScrollBar()));
+ disconnect(previous, SIGNAL(maximumScrollOffsetChanged(qreal,qreal)), this, SLOT(updateScrollOffsetScrollBar()));
+ disconnect(previous, SIGNAL(itemOffsetChanged(qreal,qreal)), this, SLOT(updateItemOffsetScrollBar()));
+ disconnect(previous, SIGNAL(maximumItemOffsetChanged(qreal,qreal)), this, SLOT(updateItemOffsetScrollBar()));
+ disconnect(previous, SIGNAL(scrollTo(qreal)), this, SLOT(scrollTo(qreal)));
m_smoothScrollingAnimation->setTargetObject(0);
}
if (current) {
scene->addItem(current);
- connect(current, SIGNAL(offsetChanged(qreal,qreal)), this, SLOT(updateScrollBars()));
- connect(current, SIGNAL(maximumOffsetChanged(qreal,qreal)), this, SLOT(updateScrollBars()));
- connect(current, SIGNAL(scrollTo(qreal)), this, SLOT(scrollTo(qreal)));
+ connect(current, SIGNAL(scrollOffsetChanged(qreal,qreal)), this, SLOT(updateScrollOffsetScrollBar()));
+ connect(current, SIGNAL(maximumScrollOffsetChanged(qreal,qreal)), this, SLOT(updateScrollOffsetScrollBar()));
+ connect(current, SIGNAL(itemOffsetChanged(qreal,qreal)), this, SLOT(updateItemOffsetScrollBar()));
+ connect(current, SIGNAL(maximumItemOffsetChanged(qreal,qreal)), this, SLOT(updateItemOffsetScrollBar()));
+ connect(current, SIGNAL(scrollTo(qreal)), this, SLOT(scrollTo(qreal)));
m_smoothScrollingAnimation->setTargetObject(current);
}
}
scrollBar->setValue(offset);
}
-void KItemListContainer::updateScrollBars()
+void KItemListContainer::updateScrollOffsetScrollBar()
{
const KItemListView* view = m_controller->view();
if (!view) {
return;
}
- QScrollBar* scrollBar = 0;
+ QScrollBar* scrollOffsetScrollBar = 0;
int singleStep = 0;
int pageStep = 0;
- QScrollBar* otherScrollBar = 0;
if (view->scrollOrientation() == Qt::Vertical) {
- scrollBar = verticalScrollBar();
+ scrollOffsetScrollBar = verticalScrollBar();
singleStep = view->itemSize().height();
pageStep = view->size().height();
- otherScrollBar = horizontalScrollBar();
} else {
- scrollBar = horizontalScrollBar();
+ scrollOffsetScrollBar = horizontalScrollBar();
singleStep = view->itemSize().width();
pageStep = view->size().width();
- otherScrollBar = verticalScrollBar();
}
- const int value = view->offset();
- const int maximum = qMax(0, int(view->maximumOffset() - pageStep));
+ const int value = view->scrollOffset();
+ const int maximum = qMax(0, int(view->maximumScrollOffset() - pageStep));
if (m_smoothScrollingAnimation->state() == QAbstractAnimation::Running) {
- if (maximum == scrollBar->maximum()) {
+ if (maximum == scrollOffsetScrollBar->maximum()) {
// The value has been changed by the animation, no update
// of the scrollbars is required as their target state will be
// reached with the end of the animation.
m_smoothScrollingAnimation->stop();
}
- scrollBar->setSingleStep(singleStep);
- scrollBar->setPageStep(pageStep);
- scrollBar->setMinimum(0);
- scrollBar->setMaximum(maximum);
- scrollBar->setValue(value);
+ scrollOffsetScrollBar->setSingleStep(singleStep);
+ scrollOffsetScrollBar->setPageStep(pageStep);
+ scrollOffsetScrollBar->setMinimum(0);
+ scrollOffsetScrollBar->setMaximum(maximum);
+ scrollOffsetScrollBar->setValue(value);
+}
+
+void KItemListContainer::updateItemOffsetScrollBar()
+{
+ const KItemListView* view = m_controller->view();
+ if (!view) {
+ return;
+ }
+
+ QScrollBar* itemOffsetScrollBar = 0;
+ int singleStep = 0;
+ int pageStep = 0;
+ if (view->scrollOrientation() == Qt::Vertical) {
+ itemOffsetScrollBar = horizontalScrollBar();
+ singleStep = view->itemSize().width() / 10;
+ pageStep = view->size().width();
+ } else {
+ itemOffsetScrollBar = verticalScrollBar();
+ singleStep = view->itemSize().height() / 10;
+ pageStep = view->size().height();
+ }
+
+ const int value = view->itemOffset();
+ const int maximum = qMax(0, int(view->maximumItemOffset() - pageStep));
- // Make sure that the other scroll bar is hidden
- otherScrollBar->setMaximum(0);
- otherScrollBar->setValue(0);
+ itemOffsetScrollBar->setSingleStep(singleStep);
+ itemOffsetScrollBar->setPageStep(pageStep);
+ itemOffsetScrollBar->setMinimum(0);
+ itemOffsetScrollBar->setMaximum(maximum);
+ itemOffsetScrollBar->setValue(value);
}
void KItemListContainer::updateGeometries()
{
QRect rect = geometry();
- int widthDec = frameWidth() * 2;
- if (verticalScrollBar()->isVisible()) {
- widthDec += style()->pixelMetric(QStyle::PM_ScrollBarExtent);
- }
+ const int widthDec = verticalScrollBar()->isVisible()
+ ? frameWidth() + style()->pixelMetric(QStyle::PM_ScrollBarExtent)
+ : frameWidth() * 2;
- int heightDec = frameWidth() * 2;
- if (horizontalScrollBar()->isVisible()) {
- heightDec += style()->pixelMetric(QStyle::PM_ScrollBarExtent);
- }
+ const int heightDec = horizontalScrollBar()->isVisible()
+ ? frameWidth() + style()->pixelMetric(QStyle::PM_ScrollBarExtent)
+ : frameWidth() * 2;
rect.adjust(0, 0, -widthDec, -heightDec);
static_cast<KItemListContainerViewport*>(viewport())->scene()->setSceneRect(0, 0, rect.width(), rect.height());
static_cast<KItemListContainerViewport*>(viewport())->viewport()->setGeometry(QRect(0, 0, rect.width(), rect.height()));
- updateScrollBars();
+ updateScrollOffsetScrollBar();
+ updateItemOffsetScrollBar();
}
void KItemListContainer::initialize()
QGraphicsView* graphicsView = new KItemListContainerViewport(new QGraphicsScene(this), this);
setViewport(graphicsView);
- m_smoothScrollingAnimation = new QPropertyAnimation(this, "offset");
+ m_smoothScrollingAnimation = new QPropertyAnimation(this, "scrollOffset");
m_smoothScrollingAnimation->setDuration(300);
connect(m_smoothScrollingAnimation, SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)),
this, SLOT(slotAnimationStateChanged(QAbstractAnimation::State,QAbstractAnimation::State)));