author | zautrix <zautrix> | 2005-03-26 11:15:27 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-26 11:15:27 (UTC) |
commit | bc8929ccca1ad8cd04f61366c78254803d9c1565 (patch) (side-by-side diff) | |
tree | 9a99b7e9cefa3c32f90e494afb7e324c59cb8584 /microkde | |
parent | ef825f1805452ba2cfb30cd7a41c392d3961f01e (diff) | |
download | kdepimpi-bc8929ccca1ad8cd04f61366c78254803d9c1565.zip kdepimpi-bc8929ccca1ad8cd04f61366c78254803d9c1565.tar.gz kdepimpi-bc8929ccca1ad8cd04f61366c78254803d9c1565.tar.bz2 |
nf
-rw-r--r-- | microkde/KDGanttMinimizeSplitter.cpp | 8 | ||||
-rw-r--r-- | microkde/KDGanttMinimizeSplitter.h | 1 |
2 files changed, 8 insertions, 1 deletions
diff --git a/microkde/KDGanttMinimizeSplitter.cpp b/microkde/KDGanttMinimizeSplitter.cpp index 84edc0d..c60b566 100644 --- a/microkde/KDGanttMinimizeSplitter.cpp +++ b/microkde/KDGanttMinimizeSplitter.cpp @@ -1,377 +1,383 @@ /* -*- Mode: C++ -*- $Id$ */ /**************************************************************************** ** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved. ** ** This file is part of the KDGantt library. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** Licensees holding valid commercial KDGantt licenses may use this file in ** accordance with the KDGantt Commercial License Agreement provided with ** the Software. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for ** information about KDGantt Commercial License Agreements. ** ** Contact info@klaralvdalens-datakonsult.se if any conditions of this ** licensing are not clear to you. ** ** As a special exception, permission is given to link this program ** with any edition of Qt, and distribute the resulting executable, ** without including the source code for Qt in the source distribution. ** **********************************************************************/ #include "KDGanttMinimizeSplitter.h" #ifndef QT_NO_SPLITTER___ #include "qpainter.h" #include "qdrawutil.h" #include "qbitmap.h" #if QT_VERSION >= 0x030000 #include "qptrlist.h" #include "qmemarray.h" #else #include <qlist.h> #include <qarray.h> #define QPtrList QList #define QMemArray QArray #endif #include "qlayoutengine_p.h" #include "qobjectlist.h" #include "qstyle.h" #include "qapplication.h" //sendPostedEvents #include <qvaluelist.h> #include <qcursor.h> #ifndef KDGANTT_MASTER_CVS //#include "KDGanttMinimizeSplitter.moc" #endif #ifndef DOXYGEN_SKIP_INTERNAL #if QT_VERSION >= 232 static int mouseOffset; static int opaqueOldPos = -1; //### there's only one mouse, but this is a bit risky KDGanttSplitterHandle::KDGanttSplitterHandle( Qt::Orientation o, KDGanttMinimizeSplitter *parent, const char * name ) : QWidget( parent, name ), _activeButton( 0 ), _collapsed( false ) { if ( QApplication::desktop()->width() > 320 && QApplication::desktop()->width() < 650 ) { mSizeHint = QSize(7,7); mUseOffset = true; } else { mSizeHint = QSize(6,6); mUseOffset = false; } s = parent; setOrientation(o); setMouseTracking( true ); + mMouseDown = false; //setMaximumHeight( 5 ); // test only } QSize KDGanttSplitterHandle::sizeHint() const { return mSizeHint; } void KDGanttSplitterHandle::setOrientation( Qt::Orientation o ) { orient = o; #ifndef QT_NO_CURSOR if ( o == KDGanttMinimizeSplitter::Horizontal ) setCursor( splitHCursor ); else setCursor( splitVCursor ); #endif } void KDGanttSplitterHandle::mouseMoveEvent( QMouseEvent *e ) { updateCursor( e->pos() ); if ( !(e->state()&LeftButton) ) return; if ( _activeButton != 0) return; QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) - mouseOffset; if ( true /*opaque()*/ ) { s->moveSplitter( pos, id() ); } else { int min = pos; int max = pos; s->getRange( id(), &min, &max ); s->setRubberband( QMAX( min, QMIN(max, pos ))); } _collapsed = false; } void KDGanttSplitterHandle::mousePressEvent( QMouseEvent *e ) { if ( e->button() == LeftButton ) { _activeButton = onButton( e->pos() ); mouseOffset = s->pick(e->pos()); - if ( _activeButton != 0) + mMouseDown = true; 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 ) { + mMouseDown = false; 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; int yyy = 1; int xxx = 1; int voffset[] = { (int) -sw*3, (int) sw*3 }; for ( int i = 0; i < 2; i++ ) { QPointArray arr; if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right || _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left) { int mid = height()/2 + voffset[i]; arr.setPoints( 3, 1-xxx, mid - sw + 4, sw-3-xxx, mid, 1-xxx, mid + sw -4); } else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left || _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { int mid = height()/2 + voffset[i]; arr.setPoints( 3, sw-4, mid - sw + 4, 0, mid, sw-4, mid + sw - 4); } else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up || _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down) { int mid = width()/2 + voffset[i]; arr.setPoints( 3, mid - sw + 4, sw-4, mid, 0, mid + sw - 4, sw-4 ); } else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down || _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { int mid = width()/2 + voffset[i]; arr.setPoints( 3, mid - sw + 4, 1-yyy, mid, sw-3-yyy, mid + sw -4, 1-yyy); } list.append( arr ); } return list; } void KDGanttSplitterHandle::paintEvent( QPaintEvent * ) { QPixmap buffer( size() ); QPainter p( &buffer ); //LR // Draw the splitter rectangle p.setBrush( colorGroup().background() ); p.setPen( colorGroup().foreground() ); //p.drawRect( rect() ); buffer.fill( colorGroup().background() ); //buffer.fill( backgroundColor() ); // parentWidget()->style().drawPrimitive( QStyle::PE_Panel, &p, rect(), parentWidget()->colorGroup()); int sw = 8; // Hardcoded, given I didn't use styles anymore, I didn't like to use their size // arrow color QColor col; if ( _activeButton ) col = colorGroup().background().dark( 250 ); + else { + if ( mMouseDown ) + col = Qt::white; else col = colorGroup().background().dark( 150 ); + } //QColor col = backgroundColor().dark( 130 ); p.setBrush( col ); p.setPen( col ); QValueList<QPointArray> list = buttonRegions(); int index = 1; if ( mUseOffset ) p.translate( 0, 1 ); for ( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { if ( index == _activeButton ) { /* if ( ! _collapsed ) { p.save(); // p.translate( parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftHorizontal ), // parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftVertical ) ); p.translate( -1, 0 ); p.drawPolygon( *it, true ); p.restore(); } else */ p.drawPolygon( *it, true ); } else { /* if ( ! _collapsed ) { p.save(); p.translate( -1, 0 ); p.drawPolygon( *it, true ); p.restore(); } else */ p.drawPolygon( *it, true ); } index++; } // Draw the lines between the arrows if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left || s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { int mid = height()/2; p.drawLine ( 1, mid - sw, 1, mid + sw ); p.drawLine ( 3, mid - sw, 3, mid + sw ); } else if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Up || s->minimizeDirection() == KDGanttMinimizeSplitter::Down ) { int mid = width()/2; p.drawLine( mid -sw, 1, mid +sw, 1 ); p.drawLine( mid -sw, 3, mid +sw, 3 ); } bitBlt( this, 0, 0, &buffer ); } #endif class QSplitterLayoutStruct { public: KDGanttMinimizeSplitter::ResizeMode mode; QCOORD sizer; bool isSplitter; QWidget *wid; }; class QSplitterData { public: QSplitterData() : opaque( FALSE ), firstShow( TRUE ) {} QPtrList<QSplitterLayoutStruct> list; bool opaque; bool firstShow; }; void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos, int space, int spacer ); #endif // DOXYGEN_SKIP_INTERNAL /*! \class KDGanttMinimizeSplitter KDGanttMinimizeSplitter.h \brief The KDGanttMinimizeSplitter class implements a splitter widget with minimize buttons. This class (and its documentation) is largely a copy of Qt's QSplitter; the copying was necessary because QSplitter is not extensible at all. QSplitter and its documentation are licensed according to the GPL and the Qt Professional License (if you hold such a license) and are (C) Trolltech AS. A splitter lets the user control the size of child widgets by dragging the boundary between the children. Any number of widgets may be controlled. To show a QListBox, a QListView and a QTextEdit side by side: diff --git a/microkde/KDGanttMinimizeSplitter.h b/microkde/KDGanttMinimizeSplitter.h index 8120d14..84d3d8e 100644 --- a/microkde/KDGanttMinimizeSplitter.h +++ b/microkde/KDGanttMinimizeSplitter.h @@ -76,113 +76,114 @@ public: 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= #if defined(Q_DISABLE_COPY) KDGanttMinimizeSplitter( const KDGanttMinimizeSplitter & ); KDGanttMinimizeSplitter& operator=( const KDGanttMinimizeSplitter & ); #endif }; #ifndef DOXYGEN_SKIP_INTERNAL // This class was continued from a verbatim copy of the // QSplitterHandle pertaining to the Qt Enterprise License and the // GPL. It has only been renamed to KDGanttSplitterHandler in order to // avoid a symbol clash on some platforms. class KDGanttSplitterHandle : public QWidget { Q_OBJECT #if QT_VERSION >= 232 public: KDGanttSplitterHandle( Qt::Orientation o, KDGanttMinimizeSplitter *parent, const char* name=0 ); void setOrientation( Qt::Orientation o ); Qt::Orientation orientation() const { return orient; } bool opaque() const { return s->opaqueResize(); } QSize sizeHint() const; void toggle(); int id() const { return myId; } // data->list.at(id())->wid == this void setId( int i ) { myId = i; } protected: QValueList<QPointArray> buttonRegions(); void paintEvent( QPaintEvent * ); void mouseMoveEvent( QMouseEvent * ); void mousePressEvent( QMouseEvent * ); void mouseReleaseEvent( QMouseEvent * ); int onButton( const QPoint& p ); void updateCursor( const QPoint& p ); private: + bool mMouseDown; QSize mSizeHint; bool mUseOffset; Qt::Orientation orient; bool opaq; int myId; KDGanttMinimizeSplitter *s; int _activeButton; bool _collapsed; int _origPos; #endif }; #endif #endif // QT_NO_SPLITTER #endif // KDGANTTMINIMIZESPLITTER_H |