[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: kicker scrolling patch
From: Matthias Elter <me () ns ! lst ! de>
Date: 2000-09-23 12:53:06
[Download RAW message or body]
Hi
The attached patch fixes kicker scrolling.
Bye,
Matthias
["kicker_scroll.patch" (application/x-patch)]
Index: core/containerarea.cpp
===================================================================
RCS file: /home/kde/kdebase/kicker/core/containerarea.cpp,v
retrieving revision 1.14
diff -u -b -B -r1.14 containerarea.cpp
--- core/containerarea.cpp 2000/09/23 09:27:03 1.14
+++ core/containerarea.cpp 2000/09/23 12:49:21
@@ -523,12 +523,14 @@
void ContainerArea::removeContainer(BaseContainer *a)
{
if (a) {
+ removeChild(a);
delete a;
_containers.removeRef(a);
}
updateContainerList();
layoutChildren();
+ updateArrows();
saveContainerConfig(true);
}
@@ -1038,11 +1040,6 @@
return static_cast<int>(PGlobal::panel->orientation());
}
-void ContainerArea::updateLayout()
-{
- layoutChildren();
-}
-
void ContainerArea::slotLayoutChildren()
{
layoutChildren();
@@ -1057,18 +1054,31 @@
void ContainerArea::layoutChildren()
{
if (_block_relayout) return;
+
+ QSize newsize = size();
+ int mus = minimumUsedSpace();
+
+ if (orientation() == Horizontal) {
+ if (newsize.width() < mus)
+ newsize.setWidth(mus);
+ }
+ else {
+ if (newsize.height() < mus)
+ newsize.setHeight(mus);
+ }
+ resizeContents(newsize.width()+1, newsize.height()+1);
+
int pos = 0;
int occupiedspace = 0;
int freespace = totalFreeSpace();
- BaseContainer *a;
- for (a = _containers.first(); a != 0; a = _containers.next())
+ for (BaseContainer *a = _containers.first(); a != 0; a = _containers.next())
{
a->slotSetOrientation((Orientation)orientation());
a->slotSetPopupDirection((Direction)popupDirection());
- // get pointer to the next non toplevel applet
+ // get pointer to the nextapplet
BaseContainer *next = _containers.next();
// reset current
@@ -1079,42 +1089,33 @@
fspace += 1;
pos = static_cast<int>(fspace) + occupiedspace;
- if (orientation() == Horizontal)
- {
- a->move( pos, 0 );
+ if (orientation() == Horizontal) {
+ moveChild(a, pos, 0);
int w = a->widthForHeight(height());
- if (isStretch(a))
- {
+ if (isStretch(a)) {
if (next)
- a->resize(w + (next->freeSpace() - a->freeSpace())*freespace,
- height());
+ a->resize(w + (next->freeSpace() - a->freeSpace())*freespace, height());
else
- a->resize(realWidth() - a->x(), height());
+ a->resize(width() - a->x(), height());
}
else
a->resize(w, height());
occupiedspace += w;
}
- else
- {
- a->move( 0, pos );
+ else {
+ moveChild(a, 0, pos);
int h = a->heightForWidth(width());
- if (isStretch(a))
- {
+ if (isStretch(a)) {
if (next)
- a->resize(width(),
- h + (next->freeSpace() - a->freeSpace())*freespace);
+ a->resize(width(), h + (next->freeSpace() - a->freeSpace())*freespace);
else
- a->resize(width(), realHeight() - a->y());
+ a->resize(width(), height() - a->y());
}
else
a->resize(width(), h);
occupiedspace += h;
}
}
-
- // resizeContents(viewport()->childrenRect().width(),
- //viewport()->childrenRect().height());
}
void ContainerArea::dragEnterEvent(QDragEnterEvent *ev)
@@ -1204,9 +1205,9 @@
if (space >= w)
{
if(stretch)
- a->move(b->pos().x() - w, a->y());
+ moveChild(a, b->pos().x() - w, a->y());
else
- a->move(b->pos().x() - space, a->y());
+ moveChild(a, b->pos().x() - space, a->y());
found = true;
break;
}
@@ -1215,9 +1216,9 @@
if (space >= h)
{
if(stretch)
- a->move(b->pos().x() - h, a->y());
+ moveChild(a, b->pos().x() - h, a->y());
else
- a->move(a->x(), b->pos().y() - space);
+ moveChild(a, a->x(), b->pos().y() - space);
found = true;
break;
}
@@ -1337,10 +1338,18 @@
int availablespace;
int usedspace = 0;
- if(orientation() == Horizontal)
+ if(orientation() == Horizontal) {
+ if(contentsWidth() > width())
+ availablespace = contentsWidth();
+ else
availablespace = width();
+ }
+ else {
+ if (contentsHeight() > height())
+ availablespace = contentsHeight();
else
availablespace = height();
+ }
// calculate used space
QListIterator<BaseContainer> it(_containers);
@@ -1362,6 +1371,27 @@
if (freespace < 0) freespace = 0;
return freespace;
+}
+
+int ContainerArea::minimumUsedSpace()
+{
+ int usedspace = 0;
+
+ QListIterator<BaseContainer> it(_containers);
+ for(; it.current() ; ++it)
+ {
+ BaseContainer* a = static_cast<BaseContainer*>(it.current());
+
+ int space;
+ if(orientation() == Horizontal)
+ space = a->widthForHeight(height());
+ else
+ space = a->heightForWidth(width());
+
+ if (space > 0)
+ usedspace += space;
+ }
+ return usedspace;
}
int ContainerArea::relativeContainerPos(BaseContainer* b)
Index: core/containerarea.h
===================================================================
RCS file: /home/kde/kdebase/kicker/core/containerarea.h,v
retrieving revision 1.6
diff -u -b -B -r1.6 containerarea.h
--- core/containerarea.h 2000/09/23 09:27:03 1.6
+++ core/containerarea.h 2000/09/23 12:49:21
@@ -40,15 +40,14 @@
Q_OBJECT
K_DCOP
- public:
+public:
ContainerArea( Orientation orientation, QWidget* parent, const char* name = 0);
~ContainerArea();
-k_dcop:
+ k_dcop:
int position();
int orientation();
int popupDirection();
- void updateLayout();
public:
@@ -68,11 +67,11 @@
bool inMoveOperation() { return _movingAC; }
- public slots:
+public slots:
void startContainerMove(BaseContainer *a);
void stopContainerMove(BaseContainer *a);
- protected:
+protected:
void layoutChildren();
BaseContainer* coversContainer(BaseContainer *a, bool strict);
@@ -80,6 +79,7 @@
void updateContainerList();
int relativeContainerPos(BaseContainer* a);
int totalFreeSpace();
+ int minimumUsedSpace();
void mouseMoveEvent(QMouseEvent *);
void mouseReleaseEvent(QMouseEvent *);
@@ -104,14 +104,14 @@
void moveContainerPush(BaseContainer* a, int distanceRequest);
int moveContainerPushRec(QListIterator<BaseContainer> it, int distanceRequest);
- protected slots:
+protected slots:
void embeddedWindowDestroyed();
void slotSaveContainerConfig();
void slotRemoveContainer(BaseContainer*);
void slotLayoutChildren();
void slotAddExternal(ExternalAppletContainer*);
- private:
+private:
QList<BaseContainer> _containers;
bool _block_relayout;
Index: core/panner.cpp
===================================================================
RCS file: /home/kde/kdebase/kicker/core/panner.cpp,v
retrieving revision 1.2
diff -u -b -B -r1.2 panner.cpp
--- core/panner.cpp 2000/09/23 09:27:03 1.2
+++ core/panner.cpp 2000/09/23 12:49:22
@@ -34,12 +34,12 @@
const int arrow = 12;
Panner::Panner( Orientation orientation, QWidget* parent, const char* name )
- : QScrollView( parent, name )
+ : QScrollView( parent, name ), orient(orientation)
{
- orient = orientation;
-
+ setResizePolicy(Manual);
setVScrollBarMode( QScrollView::AlwaysOff );
setHScrollBarMode( QScrollView::AlwaysOff );
+
viewport()->installEventFilter( this );
viewport()->setBackgroundMode( PaletteBackground );
@@ -44,19 +44,20 @@
viewport()->setBackgroundMode( PaletteBackground );
leftArrow = new QPushButton( this );
- leftArrow->setAutoRepeat( TRUE );
+ leftArrow->setAutoRepeat(true);
connect( leftArrow, SIGNAL( clicked() ), this, SLOT( scrollLeft() ) );
+
rightArrow = new QPushButton( this );
- rightArrow->setAutoRepeat( TRUE );
+ rightArrow->setAutoRepeat(true);
connect( rightArrow, SIGNAL( clicked() ), this, SLOT( scrollRight() ) );
+
upArrow = new QPushButton( this );
- upArrow->setAutoRepeat( TRUE );
+ upArrow->setAutoRepeat(true);
connect( upArrow, SIGNAL( clicked() ), this, SLOT( scrollUp() ) );
+
downArrow = new QPushButton( this );
- downArrow->setAutoRepeat( TRUE );
+ downArrow->setAutoRepeat(true);
connect( downArrow, SIGNAL( clicked() ), this, SLOT( scrollDown() ) );
-
- connect( &updateTimer, SIGNAL( timeout() ), this, SLOT( updateTimerDone() ) );
}
Panner::~Panner() {}
@@ -66,30 +67,10 @@
QScrollView::resizeContents(w, h);
}
-
-int Panner::realWidth()
-{
- if (leftArrow->isVisible())
- return width() - 2*arrow;
- else
- return width();
-}
-
-int Panner::realHeight()
-{
- if (upArrow->isVisible())
- return height() - 2*arrow;
- else
- return height();
-}
-
void Panner::setOrientation(Orientation orientation)
{
orient = orientation;
- // force resizeEvent
resize(size());
- layoutChildren();
- updateArrows();
}
void Panner::resizeEvent( QResizeEvent* e )
@@ -113,59 +94,46 @@
{
QPixmap pm( b->size() );
QPainter p( &pm );
- p.fillRect( QRect( 0, 0, pm.width(), pm.height() ), colorGroup().brush( QColorGroup::Button ) );
- style().drawArrow( &p, type, FALSE, 0, 0, pm.width(), pm.height(), colorGroup(), b->isEnabled() );
+ p.fillRect( QRect( 0, 0, pm.width(), pm.height() ),
+ colorGroup().brush( QColorGroup::Button ) );
+ style().drawArrow( &p, type, FALSE, 0, 0, pm.width(),
+ pm.height(), colorGroup(), b->isEnabled() );
p.end();
b->setPixmap( pm );
}
void Panner::scrollRight()
{
- scrollBy( 10, 0 );
+ scrollBy( 30, 0 );
}
void Panner::scrollLeft()
{
- scrollBy( -10, 0 );
+ scrollBy( -30, 0 );
}
void Panner::scrollUp()
{
- scrollBy( 0, -10 );
+ scrollBy( 0, -30 );
}
void Panner::scrollDown()
{
- scrollBy( 0, 10 );
+ scrollBy( 0, 30 );
}
bool Panner::eventFilter( QObject *, QEvent * e)
{
if ( e->type() == QEvent::LayoutHint ) {
layoutChildren();
-
- //QRect r( viewport()->childrenRect() );
- //resizeContents( r.width()+2*arrow, r.height()+2*arrow );
- //updateArrows();
- if(orientation() == Horizontal && viewport()->childrenRect().width() >
- (width()-(frameWidth()*2))){
- resizeContents(viewport()->childrenRect().width()+2*arrow,
- viewport()->childrenRect().height());
updateArrows();
}
- else if(orientation() == Vertical && viewport()->childrenRect().height() >
- (height()-(frameWidth()*2))){
- resizeContents(viewport()->childrenRect().width(),
- viewport()->childrenRect().height()+2*arrow);
- updateArrows();
- }
- }
- return FALSE;
+ return false;
}
void Panner::updateArrows()
{
- if ( contentsWidth() > width() && orient == Horizontal ) {
+ if ( contentsWidth()-1 > width() && orient == Horizontal ) {
leftArrow->show();
rightArrow->show();
}
@@ -173,7 +141,7 @@
leftArrow->hide();
rightArrow->hide();
}
- if ( contentsHeight() > height() && orient == Vertical ) {
+ if ( contentsHeight()-1 > height() && orient == Vertical ) {
upArrow->show();
downArrow->show();
}
@@ -181,30 +149,4 @@
upArrow->hide();
downArrow->hide();
}
-}
-
-void Panner::deferredLayoutUpdate()
-{
- if ( !updateTimer.isActive() )
- updateTimer.start(0, TRUE);
-}
-
-void Panner::updateTimerDone()
-{
- layoutChildren();
-}
-
-void Panner::cleanupChildren()
-{
- QObjectListIt it( *viewport()->children() );
- QObject *obj;
- while ( (obj=it.current()) ) {
- ++it;
- if ( obj->isWidgetType() ) {
- QWidget* w = (QWidget*)obj;
- if ( !w->isVisibleTo( viewport() ) )
- delete w;
- }
- }
- layoutChildren();
}
Index: core/panner.h
===================================================================
RCS file: /home/kde/kdebase/kicker/core/panner.h,v
retrieving revision 1.2
diff -u -b -B -r1.2 panner.h
--- core/panner.h 2000/08/11 03:13:53 1.2
+++ core/panner.h 2000/09/23 12:49:22
@@ -33,51 +33,41 @@
{
Q_OBJECT
- public:
+public:
Panner( Orientation orientation, QWidget* parent, const char* name = 0);
~Panner();
bool eventFilter( QObject *, QEvent * );
+ QSize minimumSizeHint() const { return QWidget::minimumSizeHint(); }
+
Qt::Orientation orientation() const {return orient; }
virtual void setOrientation(Orientation orientation);
- QSize minimumSizeHint() const { return QWidget::minimumSizeHint(); }
-
- int realHeight();
- int realWidth();
+ void updateArrows();
- public slots:
+public slots:
virtual void resizeContents( int w, int h );
- protected:
+protected:
void resizeEvent(QResizeEvent *ev);
void contentsWheelEvent(QWheelEvent *){;}
void viewportWheelEvent(QWheelEvent *){;}
- // call this whenever the layout has to be redone. Multiple calls will be compacted.
- void deferredLayoutUpdate();
virtual void layoutChildren() = 0;
- private slots:
+private slots:
void scrollRight();
void scrollLeft();
void scrollUp();
void scrollDown();
- void cleanupChildren();
- void updateTimerDone();
+private:
+ void setButtonPixmap( QPushButton* b, Qt::ArrowType type );
- private:
- QPushButton* leftArrow;
- QPushButton* rightArrow;
- QPushButton* upArrow;
- QPushButton* downArrow;
+private:
+ QPushButton *leftArrow, * rightArrow, *upArrow, *downArrow;
Orientation orient;
- QTimer updateTimer;
-
- void updateArrows();
- void setButtonPixmap( QPushButton* b, Qt::ArrowType type );
};
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic