Diffstat (limited to 'microkde/KDGanttMinimizeSplitter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | microkde/KDGanttMinimizeSplitter.cpp | 194 |
1 files changed, 103 insertions, 91 deletions
diff --git a/microkde/KDGanttMinimizeSplitter.cpp b/microkde/KDGanttMinimizeSplitter.cpp index 72c4e60..4172cd0 100644 --- a/microkde/KDGanttMinimizeSplitter.cpp +++ b/microkde/KDGanttMinimizeSplitter.cpp @@ -38,21 +38,30 @@ #include "qdrawutil.h" #include "qbitmap.h" #if QT_VERSION >= 0x030000 -#include "qptrlist.h" -#include "qmemarray.h" +#include "q3ptrlist.h" +#include "q3memarray.h" #else #include <qlist.h> #include <qarray.h> -#define QPtrList QList -#define QMemArray QArray +#define Q3PtrList QList +#define Q3MemArray QArray #endif #include "qlayoutengine_p.h" -#include "qobjectlist.h" +#include "qobject.h" #include "qstyle.h" #include "qapplication.h" //sendPostedEvents -#include <qvaluelist.h> +#include <q3valuelist.h> #include <qcursor.h> -#include <qframe.h> +#include <q3frame.h> +#include <QDesktopWidget> +//Added by qt3to4: +#include <Q3PointArray> +#include <QPixmap> +#include <QResizeEvent> +#include <QMouseEvent> +#include <QChildEvent> +#include <QEvent> +#include <QPaintEvent> #ifndef KDGANTT_MASTER_CVS //#include "KDGanttMinimizeSplitter.moc" #endif @@ -65,10 +74,10 @@ static int mouseOffset; static int opaqueOldPos = -1; //### there's only one mouse, but this is a bit risky -class KDRubberBand: public QFrame +class KDRubberBand: public Q3Frame { public: - KDRubberBand( QWidget *parent, const char * name, WFlags f ) :QFrame ( parent, name, f ) {;} + KDRubberBand( QWidget *parent, const char * name, Qt::WFlags f ) :Q3Frame ( parent, name, f ) {;} protected: virtual void mousePressEvent ( QMouseEvent * ) @@ -80,9 +89,10 @@ protected: KDGanttSplitterHandle::KDGanttSplitterHandle( Qt::Orientation o, KDGanttMinimizeSplitter *parent, const char * name ) - : QWidget( parent, name ), _activeButton( 0 ), _collapsed( false ) + : _activeButton( 0 ), _collapsed( false ) { - + setObjectName(name); + setParent(parent); if ( QApplication::desktop()->width() > 320 && QApplication::desktop()->width() < 650 ) { mSizeHint = QSize(7,7); mUseOffset = true; @@ -106,10 +116,10 @@ void KDGanttSplitterHandle::setOrientation( Qt::Orientation o ) { orient = o; #ifndef QT_NO_CURSOR - if ( o == KDGanttMinimizeSplitter::Horizontal ) - setCursor( splitHCursor ); + if ( o == Qt::Horizontal ) + setCursor( Qt::splitHCursor ); else - setCursor( splitVCursor ); + setCursor( Qt::splitVCursor ); #endif } @@ -117,7 +127,7 @@ void KDGanttSplitterHandle::setOrientation( Qt::Orientation o ) void KDGanttSplitterHandle::mouseMoveEvent( QMouseEvent *e ) { updateCursor( e->pos() ); - if ( !(e->state()&LeftButton) ) + if ( !(e->state()&Qt::LeftButton) ) return; if ( _activeButton != 0) @@ -137,7 +147,7 @@ void KDGanttSplitterHandle::mouseMoveEvent( QMouseEvent *e ) void KDGanttSplitterHandle::mousePressEvent( QMouseEvent *e ) { - if ( e->button() == LeftButton ) { + if ( e->button() == Qt::LeftButton ) { _activeButton = onButton( e->pos() ); mouseOffset = s->pick(e->pos()); mMouseDown = true; @@ -149,13 +159,13 @@ void KDGanttSplitterHandle::mousePressEvent( QMouseEvent *e ) void KDGanttSplitterHandle::updateCursor( const QPoint& p) { if ( onButton( p ) != 0 ) { - setCursor( arrowCursor ); + setCursor( Qt::arrowCursor ); } else { - if ( orient == KDGanttMinimizeSplitter::Horizontal ) - setCursor( splitHCursor ); + if ( orient == Qt::Horizontal ) + setCursor( Qt::splitHCursor ); else - setCursor( splitVCursor ); + setCursor( Qt::splitVCursor ); } } void KDGanttSplitterHandle::toggle() @@ -195,7 +205,7 @@ void KDGanttSplitterHandle::mouseReleaseEvent( QMouseEvent *e ) updateCursor( e->pos() ); } else { - if ( !opaque() && e->button() == LeftButton ) { + if ( !opaque() && e->button() == Qt::LeftButton ) { QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) - mouseOffset; s->setRubberband( -1 ); @@ -211,10 +221,10 @@ void KDGanttSplitterHandle::mouseReleaseEvent( QMouseEvent *e ) int KDGanttSplitterHandle::onButton( const QPoint& p ) { - QValueList<QPointArray> list = buttonRegions(); + Q3ValueList<Q3PointArray> list = buttonRegions(); int index = 1; int add = 12; - for( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { + for( Q3ValueList<Q3PointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { QRect rect = (*it).boundingRect(); rect.setLeft( rect.left()- add ); rect.setRight( rect.right() + add); @@ -229,16 +239,16 @@ int KDGanttSplitterHandle::onButton( const QPoint& p ) } -QValueList<QPointArray> KDGanttSplitterHandle::buttonRegions() +Q3ValueList<Q3PointArray> KDGanttSplitterHandle::buttonRegions() { - QValueList<QPointArray> list; + Q3ValueList<Q3PointArray> list; int sw = 8; int yyy = 1; int xxx = 1; int voffset[] = { (int) -sw*3, (int) sw*3 }; for ( int i = 0; i < 2; i++ ) { - QPointArray arr; + Q3PointArray arr; if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right || _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left) { int mid = height()/2 + voffset[i]; @@ -311,11 +321,11 @@ void KDGanttSplitterHandle::paintEvent( QPaintEvent * ) p.setBrush( col ); p.setPen( col ); - QValueList<QPointArray> list = buttonRegions(); + Q3ValueList<Q3PointArray> list = buttonRegions(); int index = 1; if ( mUseOffset ) p.translate( 0, 1 ); - for ( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { + for ( Q3ValueList<Q3PointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { if ( index == _activeButton ) { /* @@ -377,12 +387,12 @@ class QSplitterData public: QSplitterData() : opaque( FALSE ), firstShow( TRUE ) {} - QPtrList<QSplitterLayoutStruct> list; + Q3PtrList<QSplitterLayoutStruct> list; bool opaque; bool firstShow; }; -void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos, +void kdganttGeomCalc( Q3MemArray<QLayoutStruct> &chain, int start, int count, int pos, int space, int spacer ); #endif // DOXYGEN_SKIP_INTERNAL @@ -461,12 +471,13 @@ static QSize minSizeHint( const QWidget* w ) name arguments being passed on to the QFrame constructor. */ KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( QWidget *parent, const char *name ) - :QFrame(parent,name,WPaintUnclipped) + :Q3Frame(parent,name) { + setAttribute(Qt::WA_PaintUnclipped); mRubberBand = 0; mFirstHandle = 0; #if QT_VERSION >= 232 - orient = Horizontal; + orient = Qt::Horizontal; init(); #endif } @@ -475,10 +486,10 @@ KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( QWidget *parent, const char *n Constructs a splitter with orientation \a o with the \a parent and \a name arguments being passed on to the QFrame constructor. */ -KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( Orientation o, QWidget *parent, const char *name ) - :QFrame(parent,name,WPaintUnclipped) +KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( Qt::Orientation o, QWidget *parent, const char *name ) + :Q3Frame(parent,name) { - + setAttribute(Qt::WA_PaintUnclipped); mRubberBand = 0; mFirstHandle = 0; #if QT_VERSION >= 232 @@ -505,7 +516,7 @@ KDGanttMinimizeSplitter::~KDGanttMinimizeSplitter() void KDGanttMinimizeSplitter::init() { data = new QSplitterData; - if ( orient == Horizontal ) + if ( orient == Qt::Horizontal ) setSizePolicy( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum) ); else setSizePolicy( QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Expanding) ); @@ -534,14 +545,14 @@ void KDGanttMinimizeSplitter::toggle() By default the orientation is horizontal (the widgets are side by side). The possible orientations are Qt:Vertical and Qt::Horizontal (the default). */ -void KDGanttMinimizeSplitter::setOrientation( Orientation o ) +void KDGanttMinimizeSplitter::setOrientation( Qt::Orientation o ) { #if QT_VERSION >= 232 if ( orient == o ) return; orient = o; - if ( orient == Horizontal ) + if ( orient == Qt::Horizontal ) setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); else setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); @@ -586,8 +597,8 @@ QSplitterLayoutStruct *KDGanttMinimizeSplitter::addWidget( QWidget *w, bool firs QString tmp = "qt_splithandle_"; tmp += w->name(); newHandle = new KDGanttSplitterHandle( orientation(), this, tmp.latin1() ); - if ( ! mFirstHandle ) - mFirstHandle = newHandle; + if ( ! mFirstHandle ) + mFirstHandle = newHandle; s->wid = newHandle; newHandle->setId(data->list.count()); s->isSplitter = TRUE; @@ -600,7 +611,7 @@ QSplitterLayoutStruct *KDGanttMinimizeSplitter::addWidget( QWidget *w, bool firs s = new QSplitterLayoutStruct; s->mode = Stretch; s->wid = w; - if ( !testWState( WState_Resized ) && w->sizeHint().isValid() ) + if ( !testAttribute( Qt::WA_Resized ) && w->sizeHint().isValid() ) s->sizer = pick( w->sizeHint() ); else s->sizer = pick( w->size() ); @@ -621,20 +632,26 @@ QSplitterLayoutStruct *KDGanttMinimizeSplitter::addWidget( QWidget *w, bool firs */ void KDGanttMinimizeSplitter::childEvent( QChildEvent *c ) { - if ( c->type() == QEvent::ChildInserted ) { + if ( c->type() == QEvent::ChildAdded ) { if ( !c->child()->isWidgetType() ) return; - if ( ((QWidget*)c->child())->testWFlags( WType_TopLevel ) ) + QWidget *cw = (QWidget*)c->child(); + + if ( (cw->windowFlags())&Qt::Window ) + return; + + // avoid infinite recursion + if(cw->objectName().startsWith("qt_splithandle_")) return; QSplitterLayoutStruct *s = data->list.first(); while ( s ) { - if ( s->wid == c->child() ) + if ( s->wid == cw ) return; s = data->list.next(); } - addWidget( (QWidget*)c->child() ); + addWidget( cw ); recalc( isVisible() ); } else if ( c->type() == QEvent::ChildRemoved ) { @@ -670,17 +687,17 @@ void KDGanttMinimizeSplitter::setRubberband( int p ) { #ifdef DESKTOP_VERSION QPainter paint( this ); - paint.setPen( gray ); - paint.setBrush( gray ); - paint.setRasterOp( XorROP ); + paint.setPen( Qt::gray ); + paint.setBrush( Qt::gray ); + paint.setCompositionMode( QPainter::CompositionMode_Xor ); QRect r = contentsRect(); const int rBord = 3; //Themable???? #if QT_VERSION >= 0x030000 - int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); + int sw = style()->pixelMetric(QStyle::PM_SplitterWidth, 0, this); #else int sw = style().splitterWidth(); #endif - if ( orient == Horizontal ) { + if ( orient == Qt::Horizontal ) { if ( opaqueOldPos >= 0 ) paint.drawRect( opaqueOldPos + sw/2 - rBord , r.y(), 2*rBord, r.height() ); @@ -696,7 +713,7 @@ void KDGanttMinimizeSplitter::setRubberband( int p ) opaqueOldPos = p; #else if ( !mRubberBand ) { - mRubberBand = new KDRubberBand( 0, "rubber", WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop); + mRubberBand = new KDRubberBand( 0, "rubber", Qt::WStyle_NoBorder | Qt::WStyle_Customize | Qt::WStyle_StaysOnTop); mRubberBand->setFrameStyle( Box | Raised ); //mRubberBand->setPalette( QPalette ( Qt::red.light(),Qt::red.dark() ) ); mRubberBand->setPalette( QPalette ( colorGroup().background().light(), colorGroup().background().dark() )); @@ -710,7 +727,7 @@ void KDGanttMinimizeSplitter::setRubberband( int p ) rBord = 4; } int sw = style().splitterWidth(); - if ( orient == Horizontal ) { + if ( orient == Qt::Horizontal ) { if ( p >= 0 ) { QPoint geo = mapToGlobal (QPoint ( p + sw/2 - rBord, r.y())); mRubberBand->setGeometry( geo.x(), geo.y(), 2*rBord, r.height() ); @@ -732,7 +749,7 @@ void KDGanttMinimizeSplitter::setRubberband( int p ) /*! \reimp */ bool KDGanttMinimizeSplitter::event( QEvent *e ) { - if ( e->type() == QEvent::LayoutHint || ( e->type() == QEvent::Show && data->firstShow ) ) { + if ( e->type() == QEvent::LayoutRequest || ( e->type() == QEvent::Show && data->firstShow ) ) { recalc( isVisible() ); if ( e->type() == QEvent::Show ) data->firstShow = FALSE; @@ -755,7 +772,7 @@ void KDGanttMinimizeSplitter::drawSplitter( QPainter *p, // LR style().drawPrimitive(QStyle::PE_Splitter, p, QRect(x, y, w, h), colorGroup(), (orientation() == Qt::Horizontal ? - QStyle::Style_Horizontal : 0)); + QStyle::State_Horizontal : 0)); #endif } @@ -796,9 +813,9 @@ void KDGanttMinimizeSplitter::moveSplitter( QCOORD p, int id ) { p = adjustPos( p, id ); QSplitterLayoutStruct *s = data->list.at(id); - int oldP = orient == Horizontal ? s->wid->x() : s->wid->y(); + int oldP = orient == Qt::Horizontal ? s->wid->x() : s->wid->y(); bool upLeft; - if ( false && orient == Horizontal ) { + if ( false && orient == Qt::Horizontal ) { p += s->wid->width(); upLeft = p > oldP; } else @@ -813,8 +830,8 @@ void KDGanttMinimizeSplitter::moveSplitter( QCOORD p, int id ) void KDGanttMinimizeSplitter::setG( QWidget *w, int p, int s, bool isSplitter ) { - if ( orient == Horizontal ) { - if ( false && orient == Horizontal && !isSplitter ) + if ( orient == Qt::Horizontal ) { + if ( false && orient == Qt::Horizontal && !isSplitter ) p = contentsRect().width() - p - s; w->setGeometry( p, contentsRect().y(), s, contentsRect().height() ); } else @@ -840,7 +857,7 @@ void KDGanttMinimizeSplitter::moveBefore( int pos, int id, bool upLeft ) } else if ( s->isSplitter ) { int pos1, pos2; int dd = s->sizer; - if( false && orient == Horizontal ) { + if( false && orient == Qt::Horizontal ) { pos1 = pos; pos2 = pos + dd; } else { @@ -856,7 +873,7 @@ void KDGanttMinimizeSplitter::moveBefore( int pos, int id, bool upLeft ) } } else { int dd, newLeft, nextPos; - if( false && orient == Horizontal ) { + if( false && orient == Qt::Horizontal ) { dd = w->geometry().right() - pos; dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); newLeft = pos+1; @@ -893,7 +910,7 @@ void KDGanttMinimizeSplitter::moveAfter( int pos, int id, bool upLeft ) } else if ( s->isSplitter ) { int dd = s->sizer; int pos1, pos2; - if( false && orient == Horizontal ) { + if( false && orient == Qt::Horizontal ) { pos2 = pos - dd; pos1 = pos2 + 1; } else { @@ -910,7 +927,7 @@ void KDGanttMinimizeSplitter::moveAfter( int pos, int id, bool upLeft ) } else { int left = pick( w->pos() ); int right, dd,/* newRight,*/ newLeft, nextPos; - if ( false && orient == Horizontal ) { + if ( false && orient == Qt::Horizontal ) { dd = pos - left + 1; dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); newLeft = pos-dd+1; @@ -988,9 +1005,9 @@ void KDGanttMinimizeSplitter::getRange( int id, int *min, int *max ) } } QRect r = contentsRect(); - if ( orient == Horizontal && false ) { + if ( orient == Qt::Horizontal && false ) { #if QT_VERSION >= 0x030000 - int splitterWidth = style().pixelMetric(QStyle::PM_SplitterWidth, this); + int splitterWidth = style()->pixelMetric(QStyle::PM_SplitterWidth, 0,this); #else int splitterWidth = style().splitterWidth(); #endif @@ -1030,7 +1047,7 @@ void KDGanttMinimizeSplitter::doResize() QRect r = contentsRect(); int i; int n = data->list.count(); - QMemArray<QLayoutStruct> a( n ); + Q3MemArray<QLayoutStruct> a( n ); for ( i = 0; i< n; i++ ) { a[i].init(); QSplitterLayoutStruct *s = data->list.at(i); @@ -1132,7 +1149,7 @@ void KDGanttMinimizeSplitter::recalc( bool update ) if ( maxt < mint ) maxt = mint; - if ( orient == Horizontal ) { + if ( orient == Qt::Horizontal ) { setMaximumSize( maxl, maxt ); setMinimumSize( minl, mint ); } else { @@ -1267,13 +1284,10 @@ QSize KDGanttMinimizeSplitter::sizeHint() const constPolish(); int l = 0; int t = 0; - if ( children() ) { - const QObjectList * c = children(); - QObjectListIt it( *c ); - QObject * o; - - while( (o=it.current()) != 0 ) { - ++it; + if ( !children().empty() ) { + const QObjectList c = children(); + for(QObjectList::const_iterator i=c.begin();i!=c.end();++i) { + QObject * o = *i; if ( o->isWidgetType() && !((QWidget*)o)->isHidden() ) { QSize s = ((QWidget*)o)->sizeHint(); @@ -1284,7 +1298,7 @@ QSize KDGanttMinimizeSplitter::sizeHint() const } } } - return orientation() == Horizontal ? QSize( l, t ) : QSize( t, l ); + return orientation() == Qt::Horizontal ? QSize( l, t ) : QSize( t, l ); } @@ -1297,13 +1311,10 @@ QSize KDGanttMinimizeSplitter::minimumSizeHint() const constPolish(); int l = 0; int t = 0; - if ( children() ) { - const QObjectList * c = children(); - QObjectListIt it( *c ); - QObject * o; - - while( (o=it.current()) != 0 ) { - ++it; + if ( !children().empty() ) { + const QObjectList c = children(); + for(QObjectList::const_iterator i=c.begin();i!=c.end();++i) { + QObject * o = *i; if ( o->isWidgetType() && !((QWidget*)o)->isHidden() ) { QSize s = minSizeHint((QWidget*)o); @@ -1314,7 +1325,7 @@ QSize KDGanttMinimizeSplitter::minimumSizeHint() const } } } - return orientation() == Horizontal ? QSize( l, t ) : QSize( t, l ); + return orientation() == Qt::Horizontal ? QSize( l, t ) : QSize( t, l ); } @@ -1402,13 +1413,14 @@ bool KDGanttMinimizeSplitter::isHidden( QWidget *w ) const \sa setSizes() */ -QValueList<int> KDGanttMinimizeSplitter::sizes() const +Q3ValueList<int> KDGanttMinimizeSplitter::sizes() const { + /* TODO: hacker if ( !testWState(WState_Polished) ) { QWidget* that = (QWidget*) this; that->polish(); - } - QValueList<int> list; + } */ + Q3ValueList<int> list; QSplitterLayoutStruct *s = data->list.first(); while ( s ) { if ( !s->isSplitter ) @@ -1433,10 +1445,10 @@ QValueList<int> KDGanttMinimizeSplitter::sizes() const \sa sizes() */ -void KDGanttMinimizeSplitter::setSizes( QValueList<int> list ) +void KDGanttMinimizeSplitter::setSizes( Q3ValueList<int> list ) { processChildEvents(); - QValueList<int>::Iterator it = list.begin(); + Q3ValueList<int>::Iterator it = list.begin(); QSplitterLayoutStruct *s = data->list.first(); while ( s && it != list.end() ) { if ( !s->isSplitter ) { @@ -1456,7 +1468,7 @@ void KDGanttMinimizeSplitter::setSizes( QValueList<int> list ) void KDGanttMinimizeSplitter::processChildEvents() { - QApplication::sendPostedEvents( this, QEvent::ChildInserted ); + QApplication::sendPostedEvents( this, QEvent::ChildAdded ); } @@ -1468,7 +1480,7 @@ void KDGanttMinimizeSplitter::styleChange( QStyle& old ) { #if QT_VERSION >= 0x030000 - int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); + int sw = style()->pixelMetric(QStyle::PM_SplitterWidth, 0, this); #else int sw = style().splitterWidth(); #endif @@ -1479,7 +1491,7 @@ void KDGanttMinimizeSplitter::styleChange( QStyle& old ) s = data->list.next(); } doResize(); - QFrame::styleChange( old ); + Q3Frame::styleChange( old ); } #endif @@ -1512,7 +1524,7 @@ static inline int toFixed( int i ) { return i * 256; } static inline int fRound( int i ) { return ( i % 256 < 128 ) ? i / 256 : 1 + i / 256; } -void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos, +void kdganttGeomCalc( Q3MemArray<QLayoutStruct> &chain, int start, int count, int pos, int space, int spacer ) { typedef int fixed; |