-rw-r--r-- | microkde/KDGanttMinimizeSplitter.cpp | 10 | ||||
-rw-r--r-- | microkde/KDGanttMinimizeSplitter.h | 2 |
2 files changed, 12 insertions, 0 deletions
diff --git a/microkde/KDGanttMinimizeSplitter.cpp b/microkde/KDGanttMinimizeSplitter.cpp index 567ae54..84edc0d 100644 --- a/microkde/KDGanttMinimizeSplitter.cpp +++ b/microkde/KDGanttMinimizeSplitter.cpp @@ -121,96 +121,97 @@ void KDGanttSplitterHandle::mouseMoveEvent( QMouseEvent *e ) _collapsed = false; } void KDGanttSplitterHandle::mousePressEvent( QMouseEvent *e ) { if ( e->button() == LeftButton ) { _activeButton = onButton( e->pos() ); mouseOffset = s->pick(e->pos()); if ( _activeButton != 0) repaint(); updateCursor( e->pos() ); } } void KDGanttSplitterHandle::updateCursor( const QPoint& p) { if ( onButton( p ) != 0 ) { setCursor( arrowCursor ); } else { if ( orient == KDGanttMinimizeSplitter::Horizontal ) setCursor( splitHCursor ); else setCursor( splitVCursor ); } } void KDGanttSplitterHandle::toggle() { int pos; int min, max; if ( !_collapsed ) { s->expandPos( id(), &min, &max ); if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left || s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { pos = min; } else { pos = max; } _origPos = s->pick(mapToParent( QPoint( 0,0 ) )); s->moveSplitter( pos, id() ); _collapsed = true; } else { s->moveSplitter( _origPos, id() ); _collapsed = false; } + repaint(); } void KDGanttSplitterHandle::mouseReleaseEvent( QMouseEvent *e ) { if ( _activeButton != 0 ) { if ( onButton( e->pos() ) == _activeButton ) { toggle(); } _activeButton = 0; updateCursor( e->pos() ); } else { if ( !opaque() && e->button() == LeftButton ) { QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) - mouseOffset; s->setRubberband( -1 ); s->moveSplitter( pos, id() ); } } repaint(); } int KDGanttSplitterHandle::onButton( const QPoint& p ) { QValueList<QPointArray> list = buttonRegions(); int index = 1; int add = 12; for( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { QRect rect = (*it).boundingRect(); rect.setLeft( rect.left()- add ); rect.setRight( rect.right() + add); rect.setTop( rect.top()- add ); rect.setBottom( rect.bottom() + add); if ( rect.contains( p ) ) { return index; } index++; } return 0; } QValueList<QPointArray> KDGanttSplitterHandle::buttonRegions() { QValueList<QPointArray> list; int sw = 8; @@ -435,96 +436,105 @@ static QSize minSizeHint( const QWidget* w ) KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( QWidget *parent, const char *name ) :QFrame(parent,name,WPaintUnclipped) { mFirstHandle = 0; #if QT_VERSION >= 232 orient = Horizontal; init(); #endif } /*! 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) { mFirstHandle = 0; #if QT_VERSION >= 232 orient = o; init(); #endif } /*! Destroys the splitter and any children. */ KDGanttMinimizeSplitter::~KDGanttMinimizeSplitter() { #if QT_VERSION >= 232 data->list.setAutoDelete( TRUE ); delete data; #endif } #if QT_VERSION >= 232 void KDGanttMinimizeSplitter::init() { data = new QSplitterData; if ( orient == Horizontal ) setSizePolicy( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum) ); else setSizePolicy( QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Expanding) ); } #endif +void KDGanttMinimizeSplitter::toggle() +{ + if ( mFirstHandle ) + mFirstHandle->toggle(); + else + qDebug("KDGanttMinimizeSplitter::toggle::sorry, handle not available "); + +} + /*! \brief the orientation of the splitter 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 ) { #if QT_VERSION >= 232 if ( orient == o ) return; orient = o; if ( orient == Horizontal ) setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); else setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); QSplitterLayoutStruct *s = data->list.first(); while ( s ) { if ( s->isSplitter ) ((KDGanttSplitterHandle*)s->wid)->setOrientation( o ); s = data->list.next(); // ### next at end of loop, no iterator } recalc( isVisible() ); #endif } #if QT_VERSION >= 232 /*! \reimp */ void KDGanttMinimizeSplitter::resizeEvent( QResizeEvent * ) { doResize(); } /* Inserts the widget \a w at the end (or at the beginning if \a first is TRUE) of the splitter's list of widgets. It is the responsibility of the caller of this function to make sure that \a w is not already in the splitter and to call recalcId if needed. (If \a first is TRUE, then recalcId is very probably needed.) diff --git a/microkde/KDGanttMinimizeSplitter.h b/microkde/KDGanttMinimizeSplitter.h index 75e0443..8120d14 100644 --- a/microkde/KDGanttMinimizeSplitter.h +++ b/microkde/KDGanttMinimizeSplitter.h @@ -35,96 +35,98 @@ #define KDGANTTMINIMIZESPLITTER_H #ifndef QT_H #include "qframe.h" #include "qvaluelist.h" #endif // QT_H #ifndef QT_NO_SPLITTER___ class QSplitterData; class QSplitterLayoutStruct; class KDGanttSplitterHandle; class KDGanttMinimizeSplitter : public QFrame { Q_OBJECT // Q_ENUMS( Direction ) // Q_PROPERTY( Orientation orientation READ orientation WRITE setOrientation ) // Q_PROPERTY( Direction minimizeDirection READ minimizeDirection WRITE setMinimizeDirection ) public: enum ResizeMode { Stretch, KeepSize, FollowSizeHint }; enum Direction { Left, Right, Up, Down }; KDGanttMinimizeSplitter( QWidget* parent=0, const char* name=0 ); KDGanttMinimizeSplitter( Orientation, QWidget* parent=0, const char* name=0 ); ~KDGanttMinimizeSplitter(); virtual void setOrientation( Orientation ); Orientation orientation() const { return orient; } void setMinimizeDirection( Direction ); Direction minimizeDirection() const; #if QT_VERSION >= 232 virtual void setResizeMode( QWidget *w, ResizeMode ); virtual void setOpaqueResize( bool = TRUE ); bool opaqueResize() const; void moveToFirst( QWidget * ); void moveToLast( QWidget * ); void refresh() { recalc( TRUE ); } QSize sizeHint() const; QSize minimumSizeHint() const; QValueList<int> sizes() const; void setSizes( QValueList<int> ); KDGanttSplitterHandle* firstHandle(){ return mFirstHandle;} void expandPos( int id, int* min, int* max ); +public slots: + void toggle(); protected: void childEvent( QChildEvent * ); bool event( QEvent * ); void resizeEvent( QResizeEvent * ); int idAfter( QWidget* ) const; void moveSplitter( QCOORD pos, int id ); virtual void drawSplitter( QPainter*, QCOORD x, QCOORD y, QCOORD w, QCOORD h ); void styleChange( QStyle& ); int adjustPos( int , int ); virtual void setRubberband( int ); void getRange( int id, int*, int* ); private: void init(); void recalc( bool update = FALSE ); void doResize(); void storeSizes(); void processChildEvents(); QSplitterLayoutStruct *addWidget( QWidget*, bool first = FALSE ); void recalcId(); void moveBefore( int pos, int id, bool upLeft ); void moveAfter( int pos, int id, bool upLeft ); void setG( QWidget *w, int p, int s, bool isSplitter = FALSE ); QCOORD pick( const QPoint &p ) const { return orient == Horizontal ? p.x() : p.y(); } QCOORD pick( const QSize &s ) const { return orient == Horizontal ? s.width() : s.height(); } QCOORD trans( const QPoint &p ) const { return orient == Vertical ? p.x() : p.y(); } QCOORD trans( const QSize &s ) const { return orient == Vertical ? s.width() : s.height(); } KDGanttSplitterHandle* mFirstHandle; QSplitterData *data; #endif private: Orientation orient; Direction _direction; #ifndef DOXYGEN_SKIP_INTERNAL friend class KDGanttSplitterHandle; #endif private: // Disabled copy constructor and operator= |