author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 14:03:49 +0300 | |
changeset 6 | 1c3b8676e58c |
child 16 | 3c88a81ff781 |
permissions | -rw-r--r-- |
6
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1 |
/* |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
3 |
* All rights reserved. |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
4 |
* |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU Lesser General Public License as published by |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
7 |
* the Free Software Foundation, version 2.1 of the License. |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
8 |
* |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
12 |
* GNU Lesser General Public License for more details. |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
13 |
* |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU Lesser General Public License |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
15 |
* along with this program. If not, |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
16 |
* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
17 |
* |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
18 |
* Description: |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
19 |
* |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
20 |
*/ |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
21 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
22 |
#include "ScrollableViewBase.h" |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
23 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
24 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
25 |
#include "Kinetics/KineticScroller.h" |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
26 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
27 |
#include <QGraphicsScene> |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
28 |
#include <QGraphicsSceneMouseEvent> |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
29 |
#include <QPointF> |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
30 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
31 |
namespace GVA { |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
32 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
33 |
ScrollableViewBase::ScrollableViewBase(QGraphicsItem* parent, Qt::WindowFlags wFlags) |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
34 |
: QGraphicsWidget(parent, wFlags) |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
35 |
, m_scrollWidget(0) |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
36 |
{ |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
37 |
//To get only the mouse events within the ScrollableViewBase. |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
38 |
setFlag(QGraphicsItem::ItemClipsToShape, true); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
39 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
40 |
//To disable childrens painting outside the ViewportItem's rect. |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
41 |
setFlag(QGraphicsItem::ItemClipsChildrenToShape, true); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
42 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
43 |
//To speed up painting. |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
44 |
setFlag(QGraphicsItem::ItemHasNoContents, true); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
45 |
setAttribute(Qt::WA_OpaquePaintEvent, true); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
46 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
47 |
m_kineticScroller = new KineticScroller(this); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
48 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
49 |
//Event filter on all children of the viewport, so that all mouse |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
50 |
//events can be intercepted and used for kinetic scrolling. |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
51 |
setFiltersChildEvents(true); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
52 |
} |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
53 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
54 |
ScrollableViewBase::~ScrollableViewBase() |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
55 |
{} |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
56 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
57 |
void ScrollableViewBase::setWidget(QGraphicsWidget* view) |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
58 |
{ |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
59 |
if (view == m_scrollWidget) |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
60 |
return; |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
61 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
62 |
if (m_scrollWidget) { |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
63 |
m_scrollWidget->setParentItem(0); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
64 |
delete m_scrollWidget; |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
65 |
} |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
66 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
67 |
m_scrollWidget = view; |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
68 |
m_scrollWidget->setAttribute(Qt::WA_OpaquePaintEvent, true); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
69 |
m_scrollWidget->setParentItem(this); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
70 |
} |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
71 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
72 |
QSize ScrollableViewBase::viewportSize() const |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
73 |
{ |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
74 |
return size().toSize(); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
75 |
} |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
76 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
77 |
QPoint ScrollableViewBase::maximumScrollPosition() const |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
78 |
{ |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
79 |
QSizeF contentsSize = m_scrollWidget->size(); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
80 |
QSizeF viewportSize = size(); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
81 |
QSize maxScrollSize = (contentsSize - viewportSize).toSize(); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
82 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
83 |
return QPoint(qMax(0, maxScrollSize.width()), qMax(0, maxScrollSize.height())); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
84 |
} |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
85 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
86 |
QPoint ScrollableViewBase::scrollPosition() const |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
87 |
{ |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
88 |
return (-scrollWidgetPos()).toPoint(); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
89 |
} |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
90 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
91 |
void ScrollableViewBase::setScrollPosition(const QPoint& pos, const QPoint& overShoot) |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
92 |
{ |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
93 |
m_overShoot = overShoot; |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
94 |
setScrollWidgetPos(-pos); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
95 |
} |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
96 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
97 |
void ScrollableViewBase::stateChanged(KineticScrollable::State oldState |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
98 |
, KineticScrollable::State newState) |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
99 |
{ |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
100 |
Q_UNUSED(oldState); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
101 |
Q_UNUSED(newState); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
102 |
} |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
103 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
104 |
void ScrollableViewBase::setScrollWidgetGeometry(const QRectF& geom) |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
105 |
{ |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
106 |
scrollWidget()->setGeometry(adjustScrollWidgetRect(geom)); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
107 |
} |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
108 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
109 |
QRectF ScrollableViewBase::adjustScrollWidgetRect(const QRectF& rect) |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
110 |
{ |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
111 |
//FIX ME : Stop animation of scroll widget before adjusting it here?? |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
112 |
QRectF newRect(rect); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
113 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
114 |
QSizeF widgetSize = rect.size(); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
115 |
QSizeF viewportSize = size(); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
116 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
117 |
qreal w = viewportSize.width() - widgetSize.width(); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
118 |
qreal h = viewportSize.height() - widgetSize.height(); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
119 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
120 |
if ( w > 0 ) { |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
121 |
newRect.moveLeft(0); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
122 |
m_extraPos.setX(w/2); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
123 |
} |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
124 |
else { |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
125 |
m_extraPos.setX(0); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
126 |
if (newRect.x() < w) |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
127 |
newRect.moveLeft(w); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
128 |
if (newRect.x() > 0) |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
129 |
newRect.moveLeft(0); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
130 |
} |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
131 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
132 |
if ( h > 0 ) { |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
133 |
m_extraPos.setY(h/2); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
134 |
newRect.moveTop(0); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
135 |
} |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
136 |
else { |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
137 |
m_extraPos.setY(0); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
138 |
if (newRect.y() < h) |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
139 |
newRect.moveTop(h); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
140 |
if (newRect.y() > 0) |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
141 |
newRect.moveTop(0); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
142 |
} |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
143 |
//newRect.translate(m_extraPos); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
144 |
newRect.translate(m_overShoot); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
145 |
return newRect; |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
146 |
} |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
147 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
148 |
void ScrollableViewBase::setScrollWidgetPos(const QPointF& pos) |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
149 |
{ |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
150 |
setScrollWidgetGeometry(QRectF(pos, scrollWidget()->size())); |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
151 |
} |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
152 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
153 |
QPointF ScrollableViewBase::scrollWidgetPos() const |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
154 |
{ |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
155 |
return scrollWidget()->pos() /*- m_extraPos*/ - m_overShoot; |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
156 |
} |
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
157 |
|
1c3b8676e58c
Revision: 201026
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
158 |
} //namespace GVA |