You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
192 lines
3.8 KiB
192 lines
3.8 KiB
// (c) 2000 Peter Putzer
|
|
|
|
#include <tqscrollbar.h>
|
|
#include <tqlayout.h>
|
|
#include <tqstyle.h>
|
|
|
|
#include <kdebug.h>
|
|
#include <kdialog.h>
|
|
#include <kapplication.h>
|
|
|
|
#include "kscroller.h"
|
|
|
|
class KScroller::KScrollerPrivate
|
|
{
|
|
public:
|
|
KScrollerPrivate ()
|
|
: setCornerWidget (0L)
|
|
{
|
|
}
|
|
|
|
~KScrollerPrivate () {}
|
|
|
|
TQWidget* setCornerWidget;
|
|
};
|
|
|
|
KScroller::KScroller (TQWidget* parent, const char* name)
|
|
: TQFrame (parent, name),
|
|
d (new KScrollerPrivate()),
|
|
mVertical (new TQScrollBar (Qt::Vertical, this)),
|
|
mHorizontal (new TQScrollBar (Qt::Horizontal, this)),
|
|
mCornerWidget (new TQWidget (this)),
|
|
mContent (0L),
|
|
mVerticalOld (0),
|
|
mHorizontalOld (0)
|
|
{
|
|
mCornerWidget->hide();
|
|
mVertical->hide();
|
|
mHorizontal->hide();
|
|
|
|
connect (mVertical, TQT_SIGNAL (valueChanged (int)),
|
|
this, TQT_SLOT (scrollVertical (int)));
|
|
connect (mHorizontal, TQT_SIGNAL (valueChanged (int)),
|
|
this, TQT_SLOT (scrollHorizontal (int)));
|
|
}
|
|
|
|
KScroller::~KScroller ()
|
|
{
|
|
delete d;
|
|
}
|
|
|
|
void KScroller::setContent (TQWidget* content)
|
|
{
|
|
delete mContent;
|
|
|
|
mContent = content;
|
|
updateScrollBars();
|
|
}
|
|
|
|
void KScroller::setCornerWidget (TQWidget* corner)
|
|
{
|
|
delete mCornerWidget;
|
|
|
|
mCornerWidget = d->setCornerWidget = corner;
|
|
|
|
updateScrollBars();
|
|
}
|
|
|
|
TQWidget* KScroller::cornerWidget ()
|
|
{
|
|
return d->setCornerWidget;
|
|
}
|
|
|
|
void KScroller::resizeEvent (TQResizeEvent* e)
|
|
{
|
|
TQFrame::resizeEvent (e);
|
|
|
|
updateScrollBars();
|
|
}
|
|
|
|
TQSize KScroller::tqminimumSizeHint() const
|
|
{
|
|
TQSize size = tqsizeHint();
|
|
if (size.width() > 300)
|
|
size.setWidth(300);
|
|
return size;
|
|
}
|
|
|
|
TQSize KScroller::tqsizeHint() const
|
|
{
|
|
TQSize size = mContent->tqminimumSize();
|
|
int extra = kapp->tqstyle().tqpixelMetric( TQStyle::PM_ScrollBarExtent, 0 );
|
|
size += TQSize( extra, extra );
|
|
return size;
|
|
}
|
|
|
|
void KScroller::updateScrollBars ()
|
|
{
|
|
int w = width();
|
|
int h = height();
|
|
TQSize cs = mContent->tqminimumSize();
|
|
|
|
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->tqstyle().tqpixelMetric( TQStyle::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->tqstyle().tqpixelMetric( TQStyle::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->tqstyle().tqpixelMetric( TQStyle::PM_ScrollBarExtent, 0 );
|
|
|
|
mCornerWidget->raise();
|
|
mCornerWidget->setGeometry (w - extra, h - extra, extra, extra);
|
|
|
|
mCornerWidget->show();
|
|
}
|
|
else
|
|
{
|
|
mCornerWidget->hide();
|
|
}
|
|
}
|
|
|
|
#include "kscroller.moc"
|