author | zautrix <zautrix> | 2005-04-21 12:32:52 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-04-21 12:32:52 (UTC) |
commit | 0a13a3490ec3bf4735e3435f80f58fa7d50b4448 (patch) (side-by-side diff) | |
tree | c7f28c49b52e479f47da0dce9f0bfe9189ecdca4 | |
parent | 4d96d7b681ce99d76746a843c289b75f5e7dba64 (diff) | |
download | kdepimpi-0a13a3490ec3bf4735e3435f80f58fa7d50b4448.zip kdepimpi-0a13a3490ec3bf4735e3435f80f58fa7d50b4448.tar.gz kdepimpi-0a13a3490ec3bf4735e3435f80f58fa7d50b4448.tar.bz2 |
rubberband fix
-rw-r--r-- | korganizer/komonthview.cpp | 2 | ||||
-rw-r--r-- | microkde/KDGanttMinimizeSplitter.cpp | 21 | ||||
-rw-r--r-- | microkde/KDGanttMinimizeSplitter.h | 5 |
3 files changed, 22 insertions, 6 deletions
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp index 7927307..8ee1363 100644 --- a/korganizer/komonthview.cpp +++ b/korganizer/komonthview.cpp @@ -581,385 +581,385 @@ bool MonthViewCell::isPrimary() const } void MonthViewCell::setHoliday( bool holiday ) { mHoliday = holiday; //setMyPalette(); } void MonthViewCell::setHoliday( const QString &holiday ) { mHolidayString = holiday; if ( !holiday.isEmpty() ) { setHoliday( true ); } } void MonthViewCell::startUpdateCell() { mdayCount = 0; setFocusPolicy(NoFocus); if ( !mMonthView->isUpdatePossible() ) return; MonthViewItem *mitem = (MonthViewItem*) firstItem (); while ( mitem ) { mitem->setBlockRepaint( true ); mitem = (MonthViewItem *)mitem->next(); } if ( mAvailItemList.count() > 20 ) { mAvailItemList.setAutoDelete( true ); mAvailItemList.clear(); mAvailItemList.setAutoDelete( false ); } setPrimary( mDate.month()%2 ); setHoliday( KOGlobals::self()->calendarSystem()->dayOfWeek(mDate) == KOGlobals::self()->calendarSystem()->weekDayOfPray() || ( mDate.dayOfWeek() == 6 ) && KOPrefs::instance()-> mExcludeSaturdays); if ( mDate == QDate::currentDate() ) { setLineWidth( 3 ); } else { setLineWidth( 1 ); } MonthViewItem* CurrentAvailItem = (MonthViewItem*) firstItem (); //clear(); while ( CurrentAvailItem ) { MonthViewItem *item = CurrentAvailItem; CurrentAvailItem = (MonthViewItem *)item->next(); mAvailItemList.append( item ); takeItem ( item ); } #ifdef DESKTOP_VERSION QToolTip::remove(this); #endif mToolTip.clear(); //qApp->processEvents(); #if 0 if ( !mHolidayString.isEmpty() ) { MonthViewItem *item = new MonthViewItem( 0, mDate, mHolidayString ); item->setPalette( mHolidayPalette ); insertItem( item ); mToolTip.append ( mHolidayString ); } #endif } int MonthViewCell::insertEvent(Event *event) { bool useToolTips = true; #ifndef DESKTOP_VERSION useToolTips = false; #endif QString mToolTipText; setFocusPolicy(WheelFocus); if ( !(event->doesRecur() == Recurrence::rNone) ) { if ( !KOPrefs::instance()->mMonthDailyRecur && event->doesRecur() == Recurrence::rDaily ) return mdayCount; else if ( !KOPrefs::instance()->mMonthWeeklyRecur && event->doesRecur() == Recurrence::rWeekly ) return mdayCount; } if ( event->isHoliday()) { setHoliday( true ); if ( mDate.dayOfWeek() == 7 ) setLineWidth( 3 ); } QString text; int multiday = 0;// 1 = start, 2 = midddle, 3 = end day if (event->isMultiDay()) { QString prefix = "<->";multiday = 2; QString time; if ( event->doesRecur() ) { if ( event->recursOn( mDate) ) { prefix ="->" ;multiday = 1; } else { int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); if ( event->recursOn( mDate.addDays( -days)) ) { prefix ="<-" ;multiday = 3; } } } else { if (mDate == event->dtStart().date()) { prefix ="->" ;multiday = 1; } else if (mDate == event->dtEnd().date()) { prefix ="<-" ;multiday = 3; } } if ( !event->doesFloat() ) { if ( mDate == event->dtStart().date () ) time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; else if ( mDate == event->dtEnd().date () ) time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; } text = time + event->summary(); if ( useToolTips ) mToolTipText += prefix + text; } else { if (event->doesFloat()) { text = event->summary(); if ( useToolTips ) mToolTipText += text; } else { text = KGlobal::locale()->formatTime(event->dtStart().time()); text += " " + event->summary(); if ( useToolTips ) mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); } } if ( useToolTips && ! event->location().isEmpty() ) { mToolTipText += " (" + event->location() +")"; } MonthViewItem *item ; if ( mAvailItemList.count() ) { item = mAvailItemList.first(); mAvailItemList.remove( item ); item->recycle( event, mDate, text ); } else { item = new MonthViewItem( event, mDate, text ); } QPalette pal; if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { QStringList categories = event->categories(); QString cat = categories.first(); if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { pal = getPalette(); if (cat.isEmpty()) { pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); } else { pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); } } else { if (cat.isEmpty()) { pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); } else { pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); } } } else { pal = mStandardPalette ; } item->setPalette( pal ); item->setRecur( event->recurrence()->doesRecur() ); item->setAlarm( event->isAlarmEnabled() && multiday < 2 ); item->setMoreInfo( event->description().length() > 0 ); #ifdef DESKTOP_VERSION Attendee *me = event->attendeeByMails(KOPrefs::instance()->mAdditionalMails, KOPrefs::instance()->email()); if ( me != 0 ) { if ( me->status() == Attendee::NeedsAction && me->RSVP()) item->setReply(true && multiday < 2); else item->setReply(false); } else item->setReply(false); #endif item->setMultiDay( multiday ); if ( multiday ) { insertItem( item ,mdayCount); ++mdayCount; } else { uint i; int pos = mdayCount; for ( i = mdayCount; i < count();++i ) { QListBoxItem* it = this->item ( i ); - if ( text < it->text() ) { + if ( it && text < it->text() ) { pos = i; break; } ++pos; } insertItem( item ,pos); } if ( useToolTips ) { mToolTip.append( mToolTipText ); } return mdayCount; } void MonthViewCell::insertTodo(Todo *todo) { setFocusPolicy(WheelFocus); QString text; if (todo->hasDueDate()) { if (!todo->doesFloat()) { text += KGlobal::locale()->formatTime(todo->dtDue().time()); text += " "; } } text += todo->summary(); MonthViewItem *item ; if ( mAvailItemList.count() ) { item = mAvailItemList.first(); mAvailItemList.remove( item ); item->recycle( todo, mDate, text ); } else { item = new MonthViewItem( todo, mDate, text ); } //MonthViewItem *item = new MonthViewItem( todo, mDate, text ); //item->setPalette( mStandardPalette ); QPalette pal; if (KOPrefs::instance()->mMonthViewUsesCategoryColor) { QStringList categories = todo->categories(); QString cat = categories.first(); if ( KOPrefs::instance()->mMonthViewUsesForegroundColor ) { pal = getPalette(); if (cat.isEmpty()) { pal.setColor(QColorGroup::Foreground,KOPrefs::instance()->mEventColor); } else { pal.setColor(QColorGroup::Foreground, *(KOPrefs::instance()->categoryColor(cat))); } } else { if (cat.isEmpty()) { pal = QPalette(KOPrefs::instance()->mEventColor, KOPrefs::instance()->mEventColor); } else { pal = QPalette(*(KOPrefs::instance()->categoryColor(cat)), *(KOPrefs::instance()->categoryColor(cat))); } } } else { pal = mStandardPalette ; } item->setPalette( pal ); item->setRecur( todo->recurrence()->doesRecur() ); item->setAlarm( todo->isAlarmEnabled() ); item->setMoreInfo( todo->description().length() > 0 ); insertItem( item , count()); #ifdef DESKTOP_VERSION mToolTip.append( text ); #endif } void MonthViewCell::repaintfinishUpdateCell() { MonthViewItem *mitem = (MonthViewItem*) firstItem (); while ( mitem ) { mitem->setBlockRepaint( false ); updateItem ( mitem ); mitem = (MonthViewItem *)mitem->next(); } } void MonthViewCell::finishUpdateCell() { #ifdef DESKTOP_VERSION if (mToolTip.count() > 0 ) { mToolTip.sort(); QToolTip::add(this,mToolTip.join("\n"),toolTipGroup(),""); } #endif //sort(); //setMyPalette(); setMyPalette(); resizeEvent( 0 ); } void MonthViewCell::updateCell() { if ( !mMonthView->isUpdatePossible() ) return; startUpdateCell(); //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); QPtrList<Event> events = mMonthView->calendar()->events( mDate, true ); Event *event; for( event = events.first(); event; event = events.next() ) { // for event insertEvent(event); } // insert due todos QPtrList<Todo> todos = mMonthView->calendar()->todos( mDate ); Todo *todo; for(todo = todos.first(); todo; todo = todos.next()) { insertTodo( todo ); } finishUpdateCell(); // if ( isVisible()) //qApp->processEvents(); } void MonthViewCell::updateConfig( bool bigFont ) // = false { if ( bigFont ) { QFont fo = KOPrefs::instance()->mMonthViewFont; int ps = fo.pointSize() + 2; if ( ps < 18 ) ps += 2; fo.setPointSize( ps ); setFont( fo ); } else setFont( KOPrefs::instance()->mMonthViewFont ); QFontMetrics fm( font() ); mLabelSize = fm.size( 0, "30" ) + QSize( 4, 2 ); mLabelBigSize = fm.size( 0, "Mag 30" ) + QSize( 2, 2 ); mHolidayPalette = mStandardPalette; mPrimaryPalette = mStandardPalette; mNonPrimaryPalette = mStandardPalette; if ( KOPrefs::instance()->mMonthViewUsesDayColors ) { mHolidayPalette.setColor(QColorGroup::Base, KOPrefs::instance()->mMonthViewHolidayColor ); mHolidayPalette.setColor(QColorGroup::Background, KOPrefs::instance()->mMonthViewHolidayColor ); mHolidayPalette.setColor(QColorGroup::Foreground, KOPrefs::instance()->mMonthViewHolidayColor.dark()); mPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewOddColor.dark()); mPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewOddColor); mPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewOddColor); mNonPrimaryPalette.setColor(QColorGroup::Foreground,KOPrefs::instance()->mMonthViewEvenColor.dark()); mNonPrimaryPalette.setColor(QColorGroup::Base,KOPrefs::instance()->mMonthViewEvenColor); mNonPrimaryPalette.setColor(QColorGroup::Background,KOPrefs::instance()->mMonthViewEvenColor); } //updateCell(); } void MonthViewCell::enableScrollBars( bool enabled ) { return; if ( enabled ) { QListBoxItem *fi = firstItem (); if (fi ) { int ihei = fi->height( this ); int hei = numRows () * ihei; if ( hei < height() - horizontalScrollBar()->height () ) { setVScrollBarMode(QScrollView::AlwaysOff); } else setVScrollBarMode(QScrollView::Auto); if ( ihei *3 > height() ) { setHScrollBarMode(QScrollView::AlwaysOff); } else { setHScrollBarMode(QScrollView::Auto); } } else { setVScrollBarMode(QScrollView::Auto); setHScrollBarMode(QScrollView::Auto); } } else { setVScrollBarMode(QScrollView::AlwaysOff); setHScrollBarMode(QScrollView::AlwaysOff); } } Incidence *MonthViewCell::selectedIncidence() { int index = currentItem(); if ( index < 0 ) return 0; MonthViewItem *mitem = static_cast<MonthViewItem *>( item( index ) ); if ( !mitem ) return 0; return mitem->incidence(); } QDate MonthViewCell::selectedIncidenceDate() { diff --git a/microkde/KDGanttMinimizeSplitter.cpp b/microkde/KDGanttMinimizeSplitter.cpp index fb5d4e3..72c4e60 100644 --- a/microkde/KDGanttMinimizeSplitter.cpp +++ b/microkde/KDGanttMinimizeSplitter.cpp @@ -1,385 +1,400 @@ /* -*- 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> +#include <qframe.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 +class KDRubberBand: public QFrame +{ +public: + KDRubberBand( QWidget *parent, const char * name, WFlags f ) :QFrame ( parent, name, f ) {;} + +protected: + virtual void mousePressEvent ( QMouseEvent * ) + { + close(); + }; + +}; 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 ( 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()); 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() ); } } - if ( s->rubberBand() ) - s->rubberBand()->hide(); + if ( s->rubberBand() ) { + //qDebug("hide rubberband "); + s->rubberBand()->close(); + } 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() ); #ifndef DESKTOP_VERSION if ( mMouseDown && ! _activeButton) buffer.fill( colorGroup().background().dark() ); else #endif 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. @@ -492,385 +507,385 @@ void KDGanttMinimizeSplitter::init() data = new QSplitterData; if ( orient == Horizontal ) setSizePolicy( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum) ); else setSizePolicy( QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Expanding) ); #ifndef DESKTOP_VERSION setOpaqueResize( false ); #else setOpaqueResize( true ); #endif } #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.) */ QSplitterLayoutStruct *KDGanttMinimizeSplitter::addWidget( QWidget *w, bool first ) { QSplitterLayoutStruct *s; KDGanttSplitterHandle *newHandle = 0; if ( data->list.count() > 0 ) { s = new QSplitterLayoutStruct; s->mode = KeepSize; QString tmp = "qt_splithandle_"; tmp += w->name(); newHandle = new KDGanttSplitterHandle( orientation(), this, tmp.latin1() ); if ( ! mFirstHandle ) mFirstHandle = newHandle; s->wid = newHandle; newHandle->setId(data->list.count()); s->isSplitter = TRUE; s->sizer = pick( newHandle->sizeHint() ); if ( first ) data->list.insert( 0, s ); else data->list.append( s ); } s = new QSplitterLayoutStruct; s->mode = Stretch; s->wid = w; if ( !testWState( WState_Resized ) && w->sizeHint().isValid() ) s->sizer = pick( w->sizeHint() ); else s->sizer = pick( w->size() ); s->isSplitter = FALSE; if ( first ) data->list.insert( 0, s ); else data->list.append( s ); if ( newHandle && isVisible() ) newHandle->show(); //will trigger sending of post events return s; } /*! Tells the splitter that a child widget has been inserted or removed. The event is passed in \a c. */ void KDGanttMinimizeSplitter::childEvent( QChildEvent *c ) { if ( c->type() == QEvent::ChildInserted ) { if ( !c->child()->isWidgetType() ) return; if ( ((QWidget*)c->child())->testWFlags( WType_TopLevel ) ) return; QSplitterLayoutStruct *s = data->list.first(); while ( s ) { if ( s->wid == c->child() ) return; s = data->list.next(); } addWidget( (QWidget*)c->child() ); recalc( isVisible() ); } else if ( c->type() == QEvent::ChildRemoved ) { QSplitterLayoutStruct *p = 0; if ( data->list.count() > 1 ) p = data->list.at(1); //remove handle _after_ first widget. QSplitterLayoutStruct *s = data->list.first(); while ( s ) { if ( s->wid == c->child() ) { data->list.removeRef( s ); delete s; if ( p && p->isSplitter ) { data->list.removeRef( p ); delete p->wid; //will call childEvent delete p; } recalcId(); doResize(); return; } p = s; s = data->list.next(); } } } /*! Shows a rubber band at position \a p. If \a p is negative, the rubber band is removed. */ void KDGanttMinimizeSplitter::setRubberband( int p ) { #ifdef DESKTOP_VERSION QPainter paint( this ); paint.setPen( gray ); paint.setBrush( gray ); paint.setRasterOp( XorROP ); QRect r = contentsRect(); const int rBord = 3; //Themable???? #if QT_VERSION >= 0x030000 int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); #else int sw = style().splitterWidth(); #endif if ( orient == Horizontal ) { if ( opaqueOldPos >= 0 ) paint.drawRect( opaqueOldPos + sw/2 - rBord , r.y(), 2*rBord, r.height() ); if ( p >= 0 ) paint.drawRect( p + sw/2 - rBord, r.y(), 2*rBord, r.height() ); } else { if ( opaqueOldPos >= 0 ) paint.drawRect( r.x(), opaqueOldPos + sw/2 - rBord, r.width(), 2*rBord ); if ( p >= 0 ) paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord ); } opaqueOldPos = p; #else if ( !mRubberBand ) { - mRubberBand = new QFrame( 0, "rubber", WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop); + mRubberBand = new KDRubberBand( 0, "rubber", WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop); mRubberBand->setFrameStyle( Box | Raised ); //mRubberBand->setPalette( QPalette ( Qt::red.light(),Qt::red.dark() ) ); mRubberBand->setPalette( QPalette ( colorGroup().background().light(), colorGroup().background().dark() )); } QRect r = contentsRect(); static int rBord = 0; //Themable???? if ( !rBord ) { if (QApplication::desktop()->width() <= 320 ) rBord = 3; else rBord = 4; } int sw = style().splitterWidth(); if ( orient == Horizontal ) { if ( p >= 0 ) { QPoint geo = mapToGlobal (QPoint ( p + sw/2 - rBord, r.y())); mRubberBand->setGeometry( geo.x(), geo.y(), 2*rBord, r.height() ); } } else { if ( p >= 0 ) { QPoint geo = mapToGlobal (QPoint ( r.x(), p + sw/2 - rBord)); mRubberBand->setGeometry( geo.x(), geo.y(), r.width(), 2*rBord); } } opaqueOldPos = p; if ( ! mRubberBand->isVisible() ) { mRubberBand->show(); } #endif } /*! \reimp */ bool KDGanttMinimizeSplitter::event( QEvent *e ) { if ( e->type() == QEvent::LayoutHint || ( e->type() == QEvent::Show && data->firstShow ) ) { recalc( isVisible() ); if ( e->type() == QEvent::Show ) data->firstShow = FALSE; } return QWidget::event( e ); } /*! \obsolete Draws the splitter handle in the rectangle described by \a x, \a y, \a w, \a h using painter \a p. \sa QStyle::drawPrimitive() */ void KDGanttMinimizeSplitter::drawSplitter( QPainter *p, QCOORD x, QCOORD y, QCOORD w, QCOORD h ) { #if 0 // LR style().drawPrimitive(QStyle::PE_Splitter, p, QRect(x, y, w, h), colorGroup(), (orientation() == Qt::Horizontal ? QStyle::Style_Horizontal : 0)); #endif } /*! Returns the id of the splitter to the right of or below the widget \a w, or 0 if there is no such splitter (i.e. it is either not in this KDGanttMinimizeSplitter or it is at the end). */ int KDGanttMinimizeSplitter::idAfter( QWidget* w ) const { QSplitterLayoutStruct *s = data->list.first(); bool seen_w = FALSE; while ( s ) { if ( s->isSplitter && seen_w ) return data->list.at(); if ( !s->isSplitter && s->wid == w ) seen_w = TRUE; s = data->list.next(); } return 0; } /*! Moves the left/top edge of the splitter handle with id \a id as close as possible to position \a p, which is the distance from the left (or top) edge of the widget. For Arabic and Hebrew the layout is reversed, and using this function to set the position of the splitter might lead to unexpected results, since in Arabic and Hebrew the position of splitter one is to the left of the position of splitter zero. \sa idAfter() */ 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(); bool upLeft; if ( false && orient == Horizontal ) { p += s->wid->width(); upLeft = p > oldP; } else upLeft = p < oldP; moveAfter( p, id, upLeft ); moveBefore( p-1, id-1, upLeft ); storeSizes(); } void KDGanttMinimizeSplitter::setG( QWidget *w, int p, int s, bool isSplitter ) { if ( orient == Horizontal ) { if ( false && orient == Horizontal && !isSplitter ) p = contentsRect().width() - p - s; w->setGeometry( p, contentsRect().y(), s, contentsRect().height() ); } else w->setGeometry( contentsRect().x(), p, contentsRect().width(), s ); } /* Places the right/bottom edge of the widget at \a id at position \a pos. \sa idAfter() */ void KDGanttMinimizeSplitter::moveBefore( int pos, int id, bool upLeft ) { if( id < 0 ) return; QSplitterLayoutStruct *s = data->list.at(id); if ( !s ) return; QWidget *w = s->wid; if ( w->isHidden() ) { moveBefore( pos, id-1, upLeft ); } else if ( s->isSplitter ) { int pos1, pos2; int dd = s->sizer; if( false && orient == Horizontal ) { pos1 = pos; pos2 = pos + dd; } else { pos2 = pos - dd; pos1 = pos2 + 1; } if ( upLeft ) { setG( w, pos1, dd, TRUE ); moveBefore( pos2, id-1, upLeft ); } else { moveBefore( pos2, id-1, upLeft ); setG( w, pos1, dd, TRUE ); } } else { int dd, newLeft, nextPos; if( false && orient == Horizontal ) { dd = w->geometry().right() - pos; dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); newLeft = pos+1; nextPos = newLeft + dd; } else { dd = pos - pick( w->pos() ) + 1; dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); newLeft = pos-dd+1; nextPos = newLeft - 1; } setG( w, newLeft, dd, TRUE ); moveBefore( nextPos, id-1, upLeft ); } } /* Places the left/top edge of the widget at \a id at position \a pos. \sa idAfter() */ void KDGanttMinimizeSplitter::moveAfter( int pos, int id, bool upLeft ) { QSplitterLayoutStruct *s = id < int(data->list.count()) ? data->list.at(id) : 0; if ( !s ) return; QWidget *w = s->wid; if ( w->isHidden() ) { moveAfter( pos, id+1, upLeft ); } else if ( pick( w->pos() ) == pos ) { //No need to do anything if it's already there. diff --git a/microkde/KDGanttMinimizeSplitter.h b/microkde/KDGanttMinimizeSplitter.h index 585298d..3042e0a 100644 --- a/microkde/KDGanttMinimizeSplitter.h +++ b/microkde/KDGanttMinimizeSplitter.h @@ -1,191 +1,192 @@ /* -*- Mode: C++ -*- $Id$ */ /**************************************************************************** ** Copyright (C) 2001-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. ** **********************************************************************/ #ifndef KDGANTTMINIMIZESPLITTER_H #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 KDRubberBand; 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 ); - QFrame* rubberBand() { return mRubberBand ;} + KDRubberBand* rubberBand() { return mRubberBand ;} 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: - QFrame* mRubberBand; + KDRubberBand* mRubberBand; 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 |