summaryrefslogtreecommitdiffstats
path: root/ksysv/kscroller.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit37333bf25ad9a4c538250f5af2f9f1d666362883 (patch)
treec45e8df5b9efbffe07eb3d9340df7811c7e16943 /ksysv/kscroller.cpp
downloadtdeadmin-37333bf25ad9a4c538250f5af2f9f1d666362883.tar.gz
tdeadmin-37333bf25ad9a4c538250f5af2f9f1d666362883.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeadmin@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'ksysv/kscroller.cpp')
-rw-r--r--ksysv/kscroller.cpp191
1 files changed, 191 insertions, 0 deletions
diff --git a/ksysv/kscroller.cpp b/ksysv/kscroller.cpp
new file mode 100644
index 0000000..1f69b74
--- /dev/null
+++ b/ksysv/kscroller.cpp
@@ -0,0 +1,191 @@
+// (c) 2000 Peter Putzer
+
+#include <qscrollbar.h>
+#include <qlayout.h>
+#include <qstyle.h>
+
+#include <kdebug.h>
+#include <kdialog.h>
+#include <kapplication.h>
+
+#include "kscroller.h"
+
+class KScroller::KScrollerPrivate
+{
+public:
+ KScrollerPrivate ()
+ : setCornerWidget (0L)
+ {
+ }
+
+ ~KScrollerPrivate () {}
+
+ QWidget* setCornerWidget;
+};
+
+KScroller::KScroller (QWidget* parent, const char* name)
+ : QFrame (parent, name),
+ d (new KScrollerPrivate()),
+ mVertical (new QScrollBar (QScrollBar::Vertical, this)),
+ mHorizontal (new QScrollBar (QScrollBar::Horizontal, this)),
+ mCornerWidget (new QWidget (this)),
+ mContent (0L),
+ mVerticalOld (0),
+ mHorizontalOld (0)
+{
+ mCornerWidget->hide();
+ mVertical->hide();
+ mHorizontal->hide();
+
+ connect (mVertical, SIGNAL (valueChanged (int)),
+ this, SLOT (scrollVertical (int)));
+ connect (mHorizontal, SIGNAL (valueChanged (int)),
+ this, SLOT (scrollHorizontal (int)));
+}
+
+KScroller::~KScroller ()
+{
+ delete d;
+}
+
+void KScroller::setContent (QWidget* content)
+{
+ delete mContent;
+
+ mContent = content;
+ updateScrollBars();
+}
+
+void KScroller::setCornerWidget (QWidget* corner)
+{
+ delete mCornerWidget;
+
+ mCornerWidget = d->setCornerWidget = corner;
+
+ updateScrollBars();
+}
+
+QWidget* KScroller::cornerWidget ()
+{
+ return d->setCornerWidget;
+}
+
+void KScroller::resizeEvent (QResizeEvent* e)
+{
+ QFrame::resizeEvent (e);
+
+ updateScrollBars();
+}
+
+QSize KScroller::minimumSizeHint() const
+{
+ QSize size = sizeHint();
+ if (size.width() > 300)
+ size.setWidth(300);
+ return size;
+}
+
+QSize KScroller::sizeHint() const
+{
+ QSize size = mContent->minimumSize();
+ int extra = kapp->style().pixelMetric( QStyle::PM_ScrollBarExtent, 0 );
+ size += QSize( extra, extra );
+ return size;
+}
+
+void KScroller::updateScrollBars ()
+{
+ int w = width();
+ int h = height();
+ QSize cs = mContent->minimumSize();
+
+ setupVertical ( cs.width(), cs.height(), w, h);
+ setupHorizontal ( cs.width(), cs.height(), w, h);
+ mContent->resize (cs);
+
+ setupCornerWidget (w, h);
+}
+
+void KScroller::setupHorizontal (int cw, int, int w, int h)
+{
+ mHorizontal->setValue (0);
+ mHorizontalOld = 0;
+
+ if (cw > w)
+ {
+ int extra = kapp->style().pixelMetric( QStyle::PM_ScrollBarExtent, 0 );
+
+ if (!mVertical->isHidden())
+ w -= extra;
+
+ mHorizontal->setRange (0, cw - w);
+ mHorizontal->setPageStep (w);
+ mHorizontal->setLineStep (25);
+ mHorizontal->setGeometry (0, h - extra, w, extra);
+
+ mHorizontal->raise();
+ mHorizontal->show();
+ }
+ else
+ {
+ mHorizontal->hide();
+ }
+}
+
+void KScroller::setupVertical (int, int ch, int w, int h)
+{
+ mVertical->setValue (0);
+ mVerticalOld = 0;
+
+ if (ch > h)
+ {
+ int extra = kapp->style().pixelMetric( QStyle::PM_ScrollBarExtent, 0 );
+ mVertical->setRange (0, ch - h);
+ mVertical->setPageStep (h);
+ mVertical->setLineStep (25);
+
+ mVertical->setGeometry (w - extra, 0, extra, h);
+
+ mVertical->raise();
+ mVertical->show();
+ }
+ else
+ {
+ mVertical->hide();
+ }
+}
+
+void KScroller::scrollVertical (int value)
+{
+ int amount = value - mVerticalOld;
+ mVerticalOld = value;
+
+ mContent->move (mContent->x(), mContent->y() - amount);
+}
+
+void KScroller::scrollHorizontal (int value)
+{
+ int amount = value - mHorizontalOld;
+ mHorizontalOld = value;
+
+ mContent->move (mContent->x() - amount, mContent->y());
+}
+
+void KScroller::setupCornerWidget (int w, int h)
+{
+ if (!mVertical->isHidden() && !mHorizontal->isHidden())
+ {
+ int extra = kapp->style().pixelMetric( QStyle::PM_ScrollBarExtent, 0 );
+
+ mCornerWidget->raise();
+ mCornerWidget->setGeometry (w - extra, h - extra, extra, extra);
+
+ mCornerWidget->show();
+ }
+ else
+ {
+ mCornerWidget->hide();
+ }
+}
+
+#include "kscroller.moc"