diff options
Diffstat (limited to 'src/flowlayout.cpp')
-rw-r--r-- | src/flowlayout.cpp | 202 |
1 files changed, 119 insertions, 83 deletions
diff --git a/src/flowlayout.cpp b/src/flowlayout.cpp index a0ead97..9cc73b3 100644 --- a/src/flowlayout.cpp +++ b/src/flowlayout.cpp @@ -21,26 +21,26 @@ #include "sources/source.h" //#include "kdebug.h" -//#include <qlabel.h> // debugging +//#include <tqlabel.h> // debugging -class FlowLayoutIterator :public QGLayoutIterator{ +class FlowLayoutIterator :public TQGLayoutIterator{ public: - FlowLayoutIterator( QPtrList<QLayoutItem>* layoutItems ): + FlowLayoutIterator( TQPtrList<TQLayoutItem>* tqlayoutItems ): index(0), - mLayoutItems(layoutItems){ + mLayoutItems(tqlayoutItems){ } uint count() const; - QLayoutItem* current(); - QLayoutItem* next(); - QLayoutItem* takeCurrent(); + TQLayoutItem* current(); + TQLayoutItem* next(); + TQLayoutItem* takeCurrent(); private: int index; - QPtrList<QLayoutItem>* mLayoutItems; + TQPtrList<TQLayoutItem>* mLayoutItems; }; -QLayoutItem* FlowLayoutIterator::current(){ +TQLayoutItem* FlowLayoutIterator::current(){ return index < int(mLayoutItems->count()) ? mLayoutItems->at(index) : 0; /*if(index < int(mLayoutItems->count())){ - QLayoutItem* item = mLayoutItems->at(index); + TQLayoutItem* item = mLayoutItems->at(index); kdDebug() << "FlowLayoutIterator::current(index " << index << ") returns: " << item << endl; return item; }else{ @@ -48,15 +48,15 @@ QLayoutItem* FlowLayoutIterator::current(){ return 0; }*/ } -QLayoutItem* FlowLayoutIterator::next(){ +TQLayoutItem* FlowLayoutIterator::next(){ index++; //kdDebug() << "FlowLayoutIterator::next, index: " << index << endl; return current(); } -QLayoutItem* FlowLayoutIterator::takeCurrent(){ +TQLayoutItem* FlowLayoutIterator::takeCurrent(){ return index < int(mLayoutItems->count()) ? mLayoutItems->take(index) : 0; /*if(index < int(mLayoutItems->count())){ - QLayoutItem* item = mLayoutItems->take(index); + TQLayoutItem* item = mLayoutItems->take(index); kdDebug() << "FlowLayoutIterator::takeCurrent(index " << index << ") returns: " << item << endl; return item; }else{ @@ -67,16 +67,16 @@ QLayoutItem* FlowLayoutIterator::takeCurrent(){ } -FlowLayout::FlowLayout( QWidget* parent, Qt::Orientation orientation, int border, int space, const char* name ) - : QLayout( parent, border, space, name ), +FlowLayout::FlowLayout( TQWidget* tqparent, Qt::Orientation orientation, int border, int space, const char* name ) + : TQLayout( tqparent, border, space, name ), mOrientation(orientation), mLastItem(NULL){ } -FlowLayout::FlowLayout( QLayout* parent, Qt::Orientation orientation, int space, const char* name ) - : QLayout( parent, space, name ), +FlowLayout::FlowLayout( TQLayout* tqparent, Qt::Orientation orientation, int space, const char* name ) + : TQLayout( tqparent, space, name ), mOrientation(orientation), mLastItem(NULL){ } FlowLayout::FlowLayout( Qt::Orientation orientation, int space, const char* name ) - : QLayout( space, name ), + : TQLayout( space, name ), mOrientation(orientation), mLastItem(NULL){ } @@ -87,22 +87,22 @@ FlowLayout::~FlowLayout(){ int FlowLayout::heightForWidth( int w ) const{ FlowLayout* mthis = (FlowLayout*)this; - int h = mthis->doLayout( QRect(0,0,w,0), TRUE ); + int h = mthis->doLayout( TQRect(0,0,w,0), TRUE ); return h; } int FlowLayout::widthForHeight( int h ) const{ FlowLayout* mthis = (FlowLayout*)this; - int w = mthis->doLayout( QRect(0,0,0,h), TRUE ); + int w = mthis->doLayout( TQRect(0,0,0,h), TRUE ); return w; } void FlowLayout::addItem(QLayoutItem* item){ - //kdDebug() << "FlowLayout::addItem: " << (static_cast<QLabel*>(item->widget()))->text() << ", width: " << item->widget()->width() << ", height: " << item->widget()->height()<< endl; + //kdDebug() << "FlowLayout::addItem: " << (static_cast<TQLabel*>(item->widget()))->text() << ", width: " << item->widget()->width() << ", height: " << item->widget()->height()<< endl; // we are indirectly called from addSource. this // is a hint for addSource, to let it know which item // was added. - mLastItem = item; + mLastItem = TQT_TQLAYOUTITEM(item); } void FlowLayout::addSource(Source* src){ @@ -113,23 +113,23 @@ void FlowLayout::addSource(Source* src){ // step back until we find an item which has a // smaller position stored in its config. then, we found // the right position for the new item. - QLayoutItem * qli = mLayoutItems.last(); + TQLayoutItem * qli = mLayoutItems.last(); while(qli && mSources[qli]->getPosition() > src->getPosition()) qli = mLayoutItems.prev(); mLayoutItems.insert(mLayoutItems.at()+1, mLastItem); } -void FlowLayout::remove(QWidget* widget){ - //kdDebug() << "FlowLayout::remove: " << (static_cast<QLabel*>(widget))->text() << endl; +void FlowLayout::remove(TQWidget* widget){ + //kdDebug() << "FlowLayout::remove: " << (static_cast<TQLabel*>(widget))->text() << endl; widget->hide(); - QPtrListIterator<QLayoutItem> it(mLayoutItems); + TQPtrListIterator<TQLayoutItem> it(mLayoutItems); while(it.current() != NULL) { if(it.current()->widget() == widget) { mSources.erase(it.current()); mLayoutItems.remove(it.current()); - // removes and deletes only the QLayoutItem - // (QWidgetItem) - QLayout::remove(widget); + // removes and deletes only the TQLayoutItem + // (TQWidgetItem) + TQLayout::remove(widget); break; } ++it; @@ -140,9 +140,9 @@ uint FlowLayout::count(){ return mLayoutItems.count(); } -bool FlowLayout::moveItem(const QLayoutItem* which, const QLayoutItem* relate, DIRECTION direction){ - int newPos = mLayoutItems.findRef(relate); - int oldPos = mLayoutItems.findRef(which); +bool FlowLayout::moveItem(const TQLayoutItem* which, const TQLayoutItem* relate, DIRECTION direction){ + int newPos = mLayoutItems.tqfindRef(relate); + int oldPos = mLayoutItems.tqfindRef(which); // check whether the widget is already at a correct position if(oldPos+1 == newPos && direction == ABOVE || oldPos-1 == newPos && direction == BELOW) @@ -156,7 +156,7 @@ bool FlowLayout::moveItem(const QLayoutItem* which, const QLayoutItem* relate, D newPos += direction; // actually reinsert the item mLayoutItems.insert(newPos, which); - activate(); // relayout + activate(); // retqlayout // kdDebug() << "oldPos: " << oldPos << ", newPos: " << newPos << endl; return true; } @@ -164,7 +164,7 @@ bool FlowLayout::moveItem(const QLayoutItem* which, const QLayoutItem* relate, D void FlowLayout::updatePositions(KConfig * inKConfig){ //kdDebug() << "updating all positions..." << endl; int pos = 0; - QPtrListIterator<QLayoutItem> it(mLayoutItems); + TQPtrListIterator<TQLayoutItem> it(mLayoutItems); while(it.current() != NULL) { mSources[it.current()]->setPosition(pos, inKConfig); ++it; @@ -181,35 +181,41 @@ bool FlowLayout::hasWidthForHeight() const{ return mOrientation == Qt::Horizontal; } -QSize FlowLayout::sizeHint() const{ - //return minimumSize(); - QSize size(0,0); - QPtrListIterator<QLayoutItem> it(mLayoutItems); - QLayoutItem *o; +TQSize FlowLayout::tqsizeHint() const{ + //return tqminimumSize(); + TQSize size(0,0); + TQPtrListIterator<TQLayoutItem> it(mLayoutItems); + TQLayoutItem *o; while((o=it.current()) != 0){ ++it; - size = size.expandedTo( o->sizeHint() ); + size = size.expandedTo( o->tqsizeHint() ); } return size; } -QSize FlowLayout::minimumSize() const{ - QSize size(0,0); - QPtrListIterator<QLayoutItem> it(mLayoutItems); - QLayoutItem *o; +TQSize FlowLayout::tqminimumSize() const{ + TQSize size(0,0); + TQPtrListIterator<TQLayoutItem> it(mLayoutItems); + TQLayoutItem *o; while((o=it.current()) != 0){ ++it; - size = size.expandedTo(o->minimumSize()); + size = size.expandedTo(o->tqminimumSize()); } return size; } -QSizePolicy::ExpandData FlowLayout::expanding() const{ - return QSizePolicy::NoDirection; +TQSizePolicy::ExpandData FlowLayout::expanding() const{ + return TQ_SPNoDirection; } -QLayoutIterator FlowLayout::iterator(){ - return QLayoutIterator(new FlowLayoutIterator(&mLayoutItems)); +TQLayoutIterator FlowLayout::iterator(){ + // [FIXME] +#ifdef USE_QT4 + #warning [FIXME] ContainerAreaLayout iterators may not function correctly under Qt4 + return TQLayoutIterator( this ); // [FIXME] +#else // USE_QT4 + return TQLayoutIterator(new FlowLayoutIterator(&mLayoutItems)); +#endif // USE_QT4 } Qt::Orientation FlowLayout::getOrientation() const{ @@ -220,92 +226,122 @@ void FlowLayout::setOrientation(Qt::Orientation orientation){ mOrientation = orientation; } -void FlowLayout::setGeometry( const QRect& rect ){ - QLayout::setGeometry( rect ); +void FlowLayout::setGeometry( const TQRect& rect ){ + TQLayout::setGeometry( rect ); doLayout( rect ); } -int FlowLayout::doLayout( const QRect& rect, bool testonly ){ +int FlowLayout::doLayout( const TQRect& rect, bool testonly ){ if(mOrientation == Qt::Horizontal) return doLayoutHorizontal(rect, testonly); else return doLayoutVertical(rect, testonly); } -int FlowLayout::doLayoutHorizontal( const QRect& rect, bool testOnly ){ +int FlowLayout::doLayoutHorizontal( const TQRect& rect, bool testOnly ){ //kdDebug() << "spacing: " << spacing() << endl; int x = rect.x(); int y = rect.y(); int width = 0; // width of this column so far int height = 0; // height of this column so far - QPtrListIterator<QLayoutItem> it(mLayoutItems); - QLayoutItem* layoutItem; - QPtrList<QLayoutItem> column; // stores the items of one column - while((layoutItem = it.current()) != 0){ + TQPtrListIterator<TQLayoutItem> it(mLayoutItems); + TQLayoutItem* tqlayoutItem; + TQPtrList<TQLayoutItem> column; // stores the items of one column + while((tqlayoutItem = it.current()) != 0){ ++it; - //int nextY = y + layoutItem->sizeHint().height() + spacing(); // next y - int nextY = y + layoutItem->sizeHint().height(); // next y + //int nextY = y + tqlayoutItem->tqsizeHint().height() + spacing(); // next y + int nextY = y + tqlayoutItem->tqsizeHint().height(); // next y //if( nextY - spacing() > rect.bottom() && width > 0 ) { if( nextY > rect.bottom() && width > 0 ) { // next column y = rect.y(); // reset y x = x + width + spacing(); // new x - //nextY = y + layoutItem->sizeHint().height() + spacing(); // next y with changed y - nextY = y + layoutItem->sizeHint().height(); // next y with changed y + //nextY = y + tqlayoutItem->tqsizeHint().height() + spacing(); // next y with changed y + nextY = y + tqlayoutItem->tqsizeHint().height(); // next y with changed y width = 0; // reset width for the next column } if(!testOnly){ - layoutItem->setGeometry( QRect( QPoint( x, y ), layoutItem->sizeHint() ) ); - column.append(layoutItem); - height += layoutItem->sizeHint().height(); // add the height of the current item to the column height - if( it.current() == 0 || nextY + it.current()->sizeHint().height() > rect.bottom() ){ // test it it's the last item (of this column) + tqlayoutItem->setGeometry( TQRect( TQPoint( x, y ), tqlayoutItem->tqsizeHint() ) ); + column.append(tqlayoutItem); + height += tqlayoutItem->tqsizeHint().height(); // add the height of the current item to the column height + if( it.current() == 0 || nextY + it.current()->tqsizeHint().height() > rect.bottom() ){ // test it it's the last item (of this column) // calculate real needed width int rWidth = 0; - for(QLayoutItem* item = column.first(); item; item = column.next()){ - rWidth = QMAX( rWidth, item->widget()->sizeHint().width() ); + for(TQLayoutItem* item = column.first(); item; item = column.next()){ + rWidth = TQMAX( rWidth, item->widget()->tqsizeHint().width() ); } - // relayout the items of the former column + // retqlayout the items of the former column int space = (rect.height() - height) / (column.count() + 1); int i = 0; // counts the items of this column - for(QLayoutItem* item = column.first(); item; item = column.next()){ - QRect r = item->geometry(); - item->setGeometry( QRect(r.left(), r.top() + ((++i) * space), rWidth, r.height()) ); + for(TQLayoutItem* item = column.first(); item; item = column.next()){ + TQRect r = item->tqgeometry(); + item->setGeometry( TQRect(r.left(), r.top() + ((++i) * space), rWidth, r.height()) ); } column.clear(); // remove the items of the former column height = 0; // reset height for the next column } } y = nextY; - width = QMAX( width, layoutItem->sizeHint().width() ); + width = TQMAX( width, tqlayoutItem->tqsizeHint().width() ); } return x + width - rect.x(); // width } -int FlowLayout::doLayoutVertical( const QRect& rect, bool testOnly ){ +int FlowLayout::doLayoutVertical( const TQRect& rect, bool testOnly ){ int x = rect.x(); int y = rect.y(); int height = 0; // height of this line so far - QPtrListIterator<QLayoutItem> it(mLayoutItems); - QLayoutItem* layoutItem; - while((layoutItem = it.current() ) != 0){ + TQPtrListIterator<TQLayoutItem> it(mLayoutItems); + TQLayoutItem* tqlayoutItem; + while((tqlayoutItem = it.current() ) != 0){ ++it; - //int nextX = x + layoutItem->sizeHint().width() + spacing(); - int nextX = x + layoutItem->sizeHint().width(); + //int nextX = x + tqlayoutItem->tqsizeHint().width() + spacing(); + int nextX = x + tqlayoutItem->tqsizeHint().width(); if(nextX - spacing() > rect.right() && height > 0) { // next line x = rect.x(); // reset x //y = y + height + spacing(); // new y y = y + height; // new y - //nextX = x + layoutItem->sizeHint().width() + spacing(); // next x - nextX = x + layoutItem->sizeHint().width(); // next x + //nextX = x + tqlayoutItem->tqsizeHint().width() + spacing(); // next x + nextX = x + tqlayoutItem->tqsizeHint().width(); // next x height = 0; // reset height for the next line } - const int itemHeight = layoutItem->sizeHint().height(); + const int itemHeight = tqlayoutItem->tqsizeHint().height(); if(!testOnly) - layoutItem->setGeometry(QRect(x, y, rect.right(), itemHeight)); + tqlayoutItem->setGeometry(TQRect(x, y, rect.right(), itemHeight)); x = nextX; - height = QMAX(height, itemHeight); + height = TQMAX(height, itemHeight); } return y + height - rect.y(); // height } + +#ifdef USE_QT4 +/*! + \reimp +*/ +int FlowLayout::count() const { + return mLayoutItems.count(); +} + +/*! + \reimp +*/ +TQLayoutItem* FlowLayout::itemAt(int index) const { + return index >= 0 && index < mLayoutItems.count() ? (const_cast<TQPtrList<TQLayoutItem>&>(mLayoutItems).tqat(index)) : 0; +} + +/*! + \reimp +*/ +TQLayoutItem* FlowLayout::takeAt(int index) { + if (index < 0 || index >= mLayoutItems.count()) + return 0; + TQLayoutItem *item = mLayoutItems.tqat(index); + mLayoutItems.remove(mLayoutItems.tqat(index)); + delete item; + + invalidate(); + return item; +} +#endif // USE_QT4
\ No newline at end of file |