@ -21,26 +21,26 @@
# include "sources/source.h"
//#include "kdebug.h"
//#include < qlabel.h> // debugging
//#include < t qlabel.h> // debugging
class FlowLayoutIterator : public QGLayoutIterator{
class FlowLayoutIterator : public T QGLayoutIterator{
public :
FlowLayoutIterator ( QPtrList< QLayoutItem> * layoutItems ) :
FlowLayoutIterator ( T QPtrList< T QLayoutItem> * tq layoutItems ) :
index ( 0 ) ,
mLayoutItems ( layoutItems) {
mLayoutItems ( tq layoutItems) {
}
uint count ( ) const ;
QLayoutItem* current ( ) ;
QLayoutItem* next ( ) ;
QLayoutItem* takeCurrent ( ) ;
T QLayoutItem* current ( ) ;
T QLayoutItem* next ( ) ;
T QLayoutItem* takeCurrent ( ) ;
private :
int index ;
QPtrList< QLayoutItem> * mLayoutItems ;
T QPtrList< T QLayoutItem> * mLayoutItems ;
} ;
QLayoutItem* FlowLayoutIterator : : current ( ) {
T QLayoutItem* FlowLayoutIterator : : current ( ) {
return index < int ( mLayoutItems - > count ( ) ) ? mLayoutItems - > at ( index ) : 0 ;
/*if(index < int(mLayoutItems->count())){
QLayoutItem* item = mLayoutItems - > at ( index ) ;
T QLayoutItem* 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 ( ) {
T QLayoutItem* FlowLayoutIterator : : next ( ) {
index + + ;
//kdDebug() << "FlowLayoutIterator::next, index: " << index << endl;
return current ( ) ;
}
QLayoutItem* FlowLayoutIterator : : takeCurrent ( ) {
T QLayoutItem* FlowLayoutIterator : : takeCurrent ( ) {
return index < int ( mLayoutItems - > count ( ) ) ? mLayoutItems - > take ( index ) : 0 ;
/*if(index < int(mLayoutItems->count())){
QLayoutItem* item = mLayoutItems - > take ( index ) ;
T QLayoutItem* 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 ( T QWidget* tq parent, Qt : : Orientation orientation , int border , int space , const char * name )
: T QLayout( tq parent, 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 ( T QLayout* tq parent, Qt : : Orientation orientation , int space , const char * name )
: T QLayout( tq parent, space , name ) ,
mOrientation ( orientation ) , mLastItem ( NULL ) {
}
FlowLayout : : FlowLayout ( Qt : : Orientation orientation , int space , const char * name )
: QLayout( space , name ) ,
: T QLayout( 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 ( T QRect( 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 ( T QRect( 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< T QLabel*>(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 ( ) ;
T QLayoutItem * 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 ( T QWidget* widget ) {
//kdDebug() << "FlowLayout::remove: " << (static_cast< T QLabel*>(widget))->text() << endl;
widget - > hide ( ) ;
QPtrListIterator< QLayoutItem> it ( mLayoutItems ) ;
T QPtrListIterator< T QLayoutItem> 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 T QLayoutItem
// ( T QWidgetItem)
T QLayout: : 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 T QLayoutItem* which , const T QLayoutItem* relate , DIRECTION direction ) {
int newPos = mLayoutItems . tq findRef( relate ) ;
int oldPos = mLayoutItems . tq findRef( 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 ( ) ; // re layout
activate ( ) ; // re tq layout
// 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 ) ;
T QPtrListIterator< T QLayoutItem> 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 ;
T QSize FlowLayout : : tq sizeHint( ) const {
//return tq minimumSize();
T QSize size ( 0 , 0 ) ;
T QPtrListIterator< T QLayoutItem> it ( mLayoutItems ) ;
T QLayoutItem * o ;
while ( ( o = it . current ( ) ) ! = 0 ) {
+ + it ;
size = size . expandedTo ( o - > sizeHint( ) ) ;
size = size . expandedTo ( o - > tq sizeHint( ) ) ;
}
return size ;
}
QSize FlowLayout : : minimumSize( ) const {
QSize size ( 0 , 0 ) ;
QPtrListIterator< QLayoutItem> it ( mLayoutItems ) ;
QLayoutItem * o ;
T QSize FlowLayout : : tq minimumSize( ) const {
T QSize size ( 0 , 0 ) ;
T QPtrListIterator< T QLayoutItem> it ( mLayoutItems ) ;
T QLayoutItem * o ;
while ( ( o = it . current ( ) ) ! = 0 ) {
+ + it ;
size = size . expandedTo ( o - > minimumSize( ) ) ;
size = size . expandedTo ( o - > tq minimumSize( ) ) ;
}
return size ;
}
QSizePolicy: : ExpandData FlowLayout : : expanding ( ) const {
return QSize Policy: : NoDirection;
T QSizePolicy: : ExpandData FlowLayout : : expanding ( ) const {
return T Q_ 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 T QRect& rect ) {
T QLayout: : setGeometry ( rect ) ;
doLayout ( rect ) ;
}
int FlowLayout : : doLayout ( const QRect& rect , bool testonly ) {
int FlowLayout : : doLayout ( const T QRect& 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 T QRect& 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 ) {
T QPtrListIterator< T QLayoutItem> it ( mLayoutItems ) ;
T QLayoutItem* tq layoutItem;
T QPtrList< T QLayoutItem> column ; // stores the items of one column
while ( ( tq layoutItem = it . current ( ) ) ! = 0 ) {
+ + it ;
//int nextY = y + layoutItem->sizeHint().height() + spacing(); // next y
int nextY = y + layoutItem- > sizeHint( ) . height ( ) ; // next y
//int nextY = y + tq layoutItem->tq sizeHint().height() + spacing(); // next y
int nextY = y + tq layoutItem- > tq sizeHint( ) . 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 + tq layoutItem->tq sizeHint().height() + spacing(); // next y with changed y
nextY = y + tq layoutItem- > tq sizeHint( ) . 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)
tq layoutItem- > setGeometry ( T QRect( T QPoint( x , y ) , tq layoutItem- > tq sizeHint( ) ) ) ;
column . append ( tq layoutItem) ;
height + = tq layoutItem- > tq sizeHint( ) . height ( ) ; // add the height of the current item to the column height
if ( it . current ( ) = = 0 | | nextY + it . current ( ) - > tq sizeHint( ) . 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 ( T QLayoutItem* item = column . first ( ) ; item ; item = column . next ( ) ) {
rWidth = T QMAX( rWidth , item - > widget ( ) - > tq sizeHint( ) . width ( ) ) ;
}
// re layout the items of the former column
// re tq layout 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 ( T QLayoutItem* item = column . first ( ) ; item ; item = column . next ( ) ) {
T QRect r = item - > tq geometry( ) ;
item - > setGeometry ( T QRect( 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 = T QMAX( width , tq layoutItem- > tq sizeHint( ) . width ( ) ) ;
}
return x + width - rect . x ( ) ; // width
}
int FlowLayout : : doLayoutVertical ( const QRect& rect , bool testOnly ) {
int FlowLayout : : doLayoutVertical ( const T QRect& 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 ) {
T QPtrListIterator< T QLayoutItem> it ( mLayoutItems ) ;
T QLayoutItem* tq layoutItem;
while ( ( tq layoutItem = it . current ( ) ) ! = 0 ) {
+ + it ;
//int nextX = x + layoutItem->sizeHint().width() + spacing();
int nextX = x + layoutItem- > sizeHint( ) . width ( ) ;
//int nextX = x + tq layoutItem->tq sizeHint().width() + spacing();
int nextX = x + tq layoutItem- > tq sizeHint( ) . 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 + tq layoutItem->tq sizeHint().width() + spacing(); // next x
nextX = x + tq layoutItem- > tq sizeHint( ) . width ( ) ; // next x
height = 0 ; // reset height for the next line
}
const int itemHeight = layoutItem- > sizeHint( ) . height ( ) ;
const int itemHeight = tq layoutItem- > tq sizeHint( ) . height ( ) ;
if ( ! testOnly )
layoutItem- > setGeometry ( QRect( x , y , rect . right ( ) , itemHeight ) ) ;
tq layoutItem- > setGeometry ( T QRect( x , y , rect . right ( ) , itemHeight ) ) ;
x = nextX ;
height = QMAX( height , itemHeight ) ;
height = T QMAX( 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