summaryrefslogtreecommitdiffstats
path: root/shared
diff options
context:
space:
mode:
authorAdriano Rezende <adriano.rezende@openbossa.org>2009-11-16 11:35:40 -0300
committerAdriano Rezende <adriano.rezende@openbossa.org>2009-11-16 14:56:00 -0300
commit8e956cf08bf56a1f4dd0c3f4c0949594d77309ff (patch)
treecf654dc44b3ac954ab43d344d5a0f054cf1defac /shared
parentbd197df9d2a5a4f9f858911f3c1d7af13beb2bb0 (diff)
Shared: Added ScrollBar widget
The ScrollBar can be used as a position indicator in conjunction with a ListView or scrollable widgets. Signed-off-by: Adriano Rezende <adriano.rezende@openbossa.org>
Diffstat (limited to 'shared')
-rw-r--r--shared/scrollbar.cpp135
-rw-r--r--shared/scrollbar.h69
2 files changed, 204 insertions, 0 deletions
diff --git a/shared/scrollbar.cpp b/shared/scrollbar.cpp
new file mode 100644
index 0000000..2668686
--- /dev/null
+++ b/shared/scrollbar.cpp
@@ -0,0 +1,135 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: openBossa - INdT (renato.chencarek@openbossa.org)
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** the openBossa stream from INdT (renato.chencarek@openbossa.org).
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QPixmap>
+
+#include "scrollbar.h"
+
+
+class ScrollBarPrivate
+{
+public:
+ ScrollBarPrivate(ScrollBar *qptr);
+ void updateKnob();
+
+ ScrollBar *q;
+ int value;
+ int pageSize;
+ int maximum;
+ PixmapWidget *knob;
+};
+
+ScrollBarPrivate::ScrollBarPrivate(ScrollBar *qptr)
+ : q(qptr), value(0), pageSize(10), maximum(100)
+{
+
+}
+
+void ScrollBarPrivate::updateKnob()
+{
+ qreal th = q->size().height();
+ qreal fh = ((qreal)pageSize / qMax(pageSize + maximum, 1)) * th;
+
+ int tb, bb;
+ knob->getBorders(0, &tb, 0, &bb);
+ knob->resize(knob->preferredWidth(), qBound<qreal>(tb + bb, fh, th));
+
+ qreal max = qMax<qreal>(0, th - knob->size().height());
+ knob->setY((value * max) / qMax(1, maximum));
+}
+
+
+ScrollBar::ScrollBar(const QPixmap &background,
+ const QPixmap &foreground,
+ QGraphicsItem *parent)
+ : PixmapWidget(background, parent),
+ d(new ScrollBarPrivate(this))
+{
+ setCacheMode(QGraphicsItem::ItemCoordinateCache);
+ setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
+
+ d->knob = new PixmapWidget(foreground, this);
+ d->knob->setCacheMode(QGraphicsItem::ItemCoordinateCache);
+ d->knob->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
+
+ d->knob->setPos(0, 0);
+ d->updateKnob();
+}
+
+int ScrollBar::value() const
+{
+ return d->value;
+}
+
+void ScrollBar::setValue(int value)
+{
+ if (d->value != value) {
+ d->value = value;
+ d->updateKnob();
+ }
+}
+
+int ScrollBar::maximum() const
+{
+ return d->maximum;
+}
+
+void ScrollBar::setMaximum(int maximum)
+{
+ if (d->maximum != maximum) {
+ d->maximum = maximum;
+ d->updateKnob();
+ }
+}
+
+int ScrollBar::pageSize() const
+{
+ return d->pageSize;
+}
+
+void ScrollBar::setPageSize(int pageSize)
+{
+ if (d->pageSize != pageSize) {
+ d->pageSize = pageSize;
+ d->updateKnob();
+ }
+}
+
+void ScrollBar::setKnobBorders(int left, int top, int right, int bottom)
+{
+ d->knob->setBorders(left, top, right, bottom);
+}
+
+void ScrollBar::resizeEvent(QGraphicsSceneResizeEvent *event)
+{
+ PixmapWidget::resizeEvent(event);
+ d->updateKnob();
+}
diff --git a/shared/scrollbar.h b/shared/scrollbar.h
new file mode 100644
index 0000000..93466a7
--- /dev/null
+++ b/shared/scrollbar.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: openBossa - INdT (renato.chencarek@openbossa.org)
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** the openBossa stream from INdT (renato.chencarek@openbossa.org).
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef SCROLLBAR_H
+#define SCROLLBAR_H
+
+#include "pixmapwidget.h"
+
+class QPixmap;
+class QGraphicsItem;
+class ScrollBarPrivate;
+
+
+class ScrollBar : public PixmapWidget
+{
+ Q_OBJECT
+
+public:
+ ScrollBar(const QPixmap &background, const QPixmap &foreground,
+ QGraphicsItem *parent = 0);
+
+ int value() const;
+ void setValue(int value);
+
+ int maximum() const;
+ void setMaximum(int maximum);
+
+ int pageSize() const;
+ void setPageSize(int pageSize);
+
+ void setKnobBorders(int left, int top, int right, int bottom);
+
+protected:
+ void resizeEvent(QGraphicsSceneResizeEvent *event);
+
+private:
+ ScrollBarPrivate *d;
+ friend class ScrollBarPrivate;
+};
+
+#endif