1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : Rubber band for Q3ScrollView
9
* Copyright (C) 2008-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
11
* This program is free software; you can redistribute it
12
* and/or modify it under the terms of the GNU General
13
* Public License as published by the Free Software Foundation;
14
* either version 2, or (at your option)
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* ============================================================ */
24
#include "drubberband.h"
28
#include <Qt3Support/Q3ScrollView>
33
class DRubberBand::DRubberBandPrivate
43
Q3ScrollView* scrollView;
50
DRubberBand::DRubberBand(Q3ScrollView* scrollView)
51
: QRubberBand(QRubberBand::Rectangle, scrollView->viewport()),
52
d(new DRubberBandPrivate)
54
d->scrollView = scrollView;
58
DRubberBand::~DRubberBand()
63
QRect DRubberBand::rubberBandAreaOnContents() const
65
QRect rubber = QRect(d->firstPoint, d->secondPoint);
66
rubber = rubber.normalized();
68
if (!d->restriction.isNull())
70
rubber = rubber.intersected(d->restriction);
76
bool DRubberBand::isActive() const
81
void DRubberBand::setActive(bool active)
95
void DRubberBand::setFirstPointOnViewport(const QPoint& p)
101
void DRubberBand::setFirstPointOnContents(const QPoint& p)
103
setFirstPointOnViewport(d->scrollView->contentsToViewport(p));
106
void DRubberBand::setSecondPointOnViewport(const QPoint& p)
110
updateForContentsPosition(d->scrollView->contentsX(), d->scrollView->contentsY());
118
void DRubberBand::setSecondPointOnContents(const QPoint& p)
120
setSecondPointOnViewport(d->scrollView->contentsToViewport(p));
123
void DRubberBand::setRestrictionOnContents(const QRect& rect)
125
d->restriction = rect;
128
void DRubberBand::setRectOnContents(const QRect& rect)
130
setFirstPointOnContents(rect.topLeft());
131
setSecondPointOnContents(rect.bottomRight());
134
void DRubberBand::setRectOnViewport(const QRect& rect)
136
setFirstPointOnViewport(rect.topLeft());
137
setSecondPointOnViewport(rect.bottomRight());
140
void DRubberBand::updateForContentsPosition(int contentsX, int contentsY)
142
QRect rubber = rubberBandAreaOnContents();
143
rubber.translate( - contentsX, - contentsY);
145
move(rubber.x(), rubber.y());
146
resize(rubber.width(), rubber.height());
149
} // namespace Digikam