34 #include "KDGanttMinimizeSplitter.h"
35 #ifndef TQT_NO_SPLITTER
37 #include "tqpainter.h"
38 #include "tqdrawutil.h"
40 #include "tqptrlist.h"
41 #include "tqmemarray.h"
43 #include "private/tqlayoutengine_p.h"
44 #include "tqobjectlist.h"
46 #include "tqapplication.h"
47 #include <tqvaluelist.h>
50 #include "KDGanttMinimizeSplitter.moc"
52 #ifndef DOXYGEN_SKIP_INTERNAL
54 static int mouseOffset;
55 static int opaqueOldPos = -1;
58 KDGanttSplitterHandle::KDGanttSplitterHandle( TQt::Orientation o,
60 : TQWidget( parent, name ), _activeButton( 0 ), _collapsed( false )
64 setMouseTracking(
true );
67 TQSize KDGanttSplitterHandle::sizeHint()
const
72 void KDGanttSplitterHandle::setOrientation( TQt::Orientation o )
76 if ( o == TQt::Horizontal )
77 setCursor( splitHCursor );
79 setCursor( splitVCursor );
84 void KDGanttSplitterHandle::mouseMoveEvent( TQMouseEvent *e )
86 updateCursor( e->pos() );
87 if ( !(e->state()&TQt::LeftButton) )
90 if ( _activeButton != 0)
93 TQCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos()))
96 s->moveSplitter( pos,
id() );
98 int min = pos;
int max = pos;
99 s->getRange(
id(), &min, &max );
100 s->setRubberband( TQMAX( min, TQMIN(max, pos )));
105 void KDGanttSplitterHandle::mousePressEvent( TQMouseEvent *e )
107 if ( e->button() == TQt::LeftButton ) {
108 _activeButton = onButton( e->pos() );
109 mouseOffset = s->pick(e->pos());
110 if ( _activeButton != 0)
112 updateCursor( e->pos() );
116 void KDGanttSplitterHandle::updateCursor(
const TQPoint& p)
118 if ( onButton( p ) != 0 ) {
119 setCursor( arrowCursor );
122 if ( orient == TQt::Horizontal )
123 setCursor( splitHCursor );
125 setCursor( splitVCursor );
130 void KDGanttSplitterHandle::mouseReleaseEvent( TQMouseEvent *e )
132 if ( _activeButton != 0 ) {
133 if ( onButton( e->pos() ) == _activeButton )
138 s->expandPos(
id(), &min, &max );
139 if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left
140 || s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) {
147 _origPos = s->pick(mapToParent( TQPoint( 0,0 ) ));
148 s->moveSplitter( pos,
id() );
152 s->moveSplitter( _origPos,
id() );
158 updateCursor( e->pos() );
161 if ( !opaque() && e->button() == TQt::LeftButton ) {
162 TQCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos()))
164 s->setRubberband( -1 );
165 s->moveSplitter( pos,
id() );
171 int KDGanttSplitterHandle::onButton(
const TQPoint& p )
173 TQValueList<TQPointArray> list = buttonRegions();
175 for( TQValueList<TQPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) {
176 TQRect rect = (*it).boundingRect();
177 rect.setLeft( rect.left()- 4 );
178 rect.setRight( rect.right() + 4);
179 rect.setTop( rect.top()- 4 );
180 rect.setBottom( rect.bottom() + 4);
181 if ( rect.contains( p ) ) {
190 TQValueList<TQPointArray> KDGanttSplitterHandle::buttonRegions()
192 TQValueList<TQPointArray> list;
195 int voffset[] = { (int) -sw*3, (
int) sw*3 };
196 for (
int i = 0; i < 2; i++ ) {
198 if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right ||
199 _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left) {
200 int mid = height()/2 + voffset[i];
206 else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left ||
207 _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) {
208 int mid = height()/2 + voffset[i];
214 else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up ||
215 _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down) {
216 int mid = width()/2 + voffset[i];
220 mid + sw - 4, sw-4 );
222 else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down ||
223 _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) {
224 int mid = width()/2 + voffset[i];
235 void KDGanttSplitterHandle::paintEvent( TQPaintEvent * )
237 TQPixmap buffer( size() );
238 TQPainter p( &buffer );
241 p.setBrush( colorGroup().background() );
242 p.setPen( colorGroup().foreground() );
243 p.drawRect( rect() );
244 parentWidget()->style().drawPrimitive( TQStyle::PE_Panel, &p, rect(),
245 parentWidget()->colorGroup());
250 TQColor col = colorGroup().background().dark( 200 );
254 TQValueList<TQPointArray> list = buttonRegions();
256 for ( TQValueList<TQPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) {
257 if ( index == _activeButton ) {
259 p.translate( parentWidget()->style().pixelMetric( TQStyle::PM_ButtonShiftHorizontal ),
260 parentWidget()->style().pixelMetric( TQStyle::PM_ButtonShiftVertical ) );
261 p.drawPolygon( *it,
true );
265 p.drawPolygon( *it,
true );
271 if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left ||
272 s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) {
273 int mid = height()/2;
274 p.drawLine ( 2, mid - sw, 2, mid + sw );
275 p.drawLine ( 4, mid - sw, 4, mid + sw );
277 else if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Up ||
278 s->minimizeDirection() == KDGanttMinimizeSplitter::Down ) {
280 p.drawLine( mid -sw, 2, mid +sw, 2 );
281 p.drawLine( mid -sw, 4, mid +sw, 4 );
283 bitBlt(
this, 0, 0, &buffer );
286 class TQSplitterLayoutStruct
298 TQSplitterData() : opaque( FALSE ), firstShow( TRUE ) {}
300 TQPtrList<TQSplitterLayoutStruct> list;
305 void kdganttGeomCalc( TQMemArray<TQLayoutStruct> &chain,
int start,
int count,
int pos,
306 int space,
int spacer );
359 static TQSize minSize(
const TQWidget* )
365 static TQSize minSizeHint(
const TQWidget* w )
367 TQSize min = w->minimumSize();
369 if ( min.height() <= 0 || min.width() <= 0 )
370 s = w->minimumSizeHint();
371 if ( min.height() > 0 )
372 s.setHeight( min.height() );
373 if ( min.width() > 0 )
374 s.setWidth( min.width() );
375 return s.expandedTo(TQSize(0,0));
385 :TQFrame(parent,name,WPaintUnclipped)
387 orient = TQt::Horizontal;
396 :TQFrame(parent,name,WPaintUnclipped)
407 data->list.setAutoDelete( TRUE );
412 void KDGanttMinimizeSplitter::init()
414 data =
new TQSplitterData;
415 if ( orient == TQt::Horizontal )
416 setSizePolicy( TQSizePolicy(TQSizePolicy::Expanding,TQSizePolicy::Minimum) );
418 setSizePolicy( TQSizePolicy(TQSizePolicy::Minimum,TQSizePolicy::Expanding) );
435 if ( orient == TQt::Horizontal )
436 setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Minimum ) );
438 setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Expanding ) );
440 TQSplitterLayoutStruct *s = data->list.first();
443 ((KDGanttSplitterHandle*)s->wid)->setOrientation( o );
444 s = data->list.next();
446 recalc( isVisible() );
468 TQSplitterLayoutStruct *KDGanttMinimizeSplitter::addWidget( TQWidget *w,
bool first )
470 TQSplitterLayoutStruct *s;
471 KDGanttSplitterHandle *newHandle = 0;
472 if ( data->list.count() > 0 ) {
473 s =
new TQSplitterLayoutStruct;
475 TQString tmp =
"qt_splithandle_";
477 newHandle =
new KDGanttSplitterHandle(
orientation(),
this, tmp.latin1() );
479 newHandle->setId(data->list.count());
480 s->isSplitter = TRUE;
481 s->sizer = pick( newHandle->sizeHint() );
483 data->list.insert( 0, s );
485 data->list.append( s );
487 s =
new TQSplitterLayoutStruct;
490 if ( !testWState( WState_Resized ) && w->sizeHint().isValid() )
491 s->sizer = pick( w->sizeHint() );
493 s->sizer = pick( w->size() );
494 s->isSplitter = FALSE;
496 data->list.insert( 0, s );
498 data->list.append( s );
499 if ( newHandle && isVisible() )
511 if ( c->type() == TQEvent::ChildInserted ) {
512 if ( !c->child()->isWidgetType() )
515 if ( ((TQWidget*)c->child())->testWFlags( WType_TopLevel ) )
518 TQSplitterLayoutStruct *s = data->list.first();
520 if ( s->wid == c->child() )
522 s = data->list.next();
524 addWidget( (TQWidget*)c->child() );
525 recalc( isVisible() );
527 }
else if ( c->type() == TQEvent::ChildRemoved ) {
528 TQSplitterLayoutStruct *p = 0;
529 if ( data->list.count() > 1 )
530 p = data->list.at(1);
531 TQSplitterLayoutStruct *s = data->list.first();
533 if ( s->wid == c->child() ) {
534 data->list.removeRef( s );
536 if ( p && p->isSplitter ) {
537 data->list.removeRef( p );
546 s = data->list.next();
558 TQPainter paint(
this );
559 paint.setPen( gray );
560 paint.setBrush( gray );
561 paint.setRasterOp( XorROP );
562 TQRect r = contentsRect();
564 int sw = style().pixelMetric(TQStyle::PM_SplitterWidth,
this);
565 if ( orient == TQt::Horizontal ) {
566 if ( opaqueOldPos >= 0 )
567 paint.drawRect( opaqueOldPos + sw/2 - rBord , r.y(),
568 2*rBord, r.height() );
570 paint.drawRect( p + sw/2 - rBord, r.y(), 2*rBord, r.height() );
572 if ( opaqueOldPos >= 0 )
573 paint.drawRect( r.x(), opaqueOldPos + sw/2 - rBord,
574 r.width(), 2*rBord );
576 paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord );
585 if ( e->type() == TQEvent::LayoutHint || ( e->type() == TQEvent::Show && data->firstShow ) ) {
586 recalc( isVisible() );
587 if ( e->type() == TQEvent::Show )
588 data->firstShow = FALSE;
590 return TQWidget::event( e );
602 TQCOORD x, TQCOORD y, TQCOORD w, TQCOORD h )
604 style().drawPrimitive(TQStyle::PE_Splitter, p, TQRect(x, y, w, h), colorGroup(),
606 TQStyle::Style_Horizontal : 0));
617 TQSplitterLayoutStruct *s = data->list.first();
620 if ( s->isSplitter && seen_w )
621 return data->list.at();
622 if ( !s->isSplitter && s->wid == w )
624 s = data->list.next();
646 TQSplitterLayoutStruct *s = data->list.at(
id);
647 int oldP = orient == TQt::Horizontal ? s->wid->x() : s->wid->y();
649 if ( TQApplication::reverseLayout() && orient == TQt::Horizontal ) {
650 p += s->wid->width();
655 moveAfter( p,
id, upLeft );
656 moveBefore( p-1,
id-1, upLeft );
662 void KDGanttMinimizeSplitter::setG( TQWidget *w,
int p,
int s,
bool isSplitter )
664 if ( orient == TQt::Horizontal ) {
665 if ( TQApplication::reverseLayout() && orient == TQt::Horizontal && !isSplitter )
666 p = contentsRect().width() - p - s;
667 w->setGeometry( p, contentsRect().y(), s, contentsRect().height() );
669 w->setGeometry( contentsRect().x(), p, contentsRect().width(), s );
678 void KDGanttMinimizeSplitter::moveBefore(
int pos,
int id,
bool upLeft )
682 TQSplitterLayoutStruct *s = data->list.at(
id);
685 TQWidget *w = s->wid;
686 if ( w->isHidden() ) {
687 moveBefore( pos,
id-1, upLeft );
688 }
else if ( s->isSplitter ) {
691 if( TQApplication::reverseLayout() && orient == TQt::Horizontal ) {
699 setG( w, pos1, dd, TRUE );
700 moveBefore( pos2,
id-1, upLeft );
702 moveBefore( pos2,
id-1, upLeft );
703 setG( w, pos1, dd, TRUE );
706 int dd, newLeft, nextPos;
707 if( TQApplication::reverseLayout() && orient == TQt::Horizontal ) {
708 dd = w->geometry().right() - pos;
709 dd = TQMAX( pick(minSize(w)), TQMIN(dd, pick(w->maximumSize())));
711 nextPos = newLeft + dd;
713 dd = pos - pick( w->pos() ) + 1;
714 dd = TQMAX( pick(minSize(w)), TQMIN(dd, pick(w->maximumSize())));
716 nextPos = newLeft - 1;
718 setG( w, newLeft, dd, TRUE );
719 moveBefore( nextPos,
id-1, upLeft );
729 void KDGanttMinimizeSplitter::moveAfter(
int pos,
int id,
bool upLeft )
731 TQSplitterLayoutStruct *s =
id < int(data->list.count()) ?
732 data->list.at(
id) : 0;
735 TQWidget *w = s->wid;
736 if ( w->isHidden() ) {
737 moveAfter( pos,
id+1, upLeft );
738 }
else if ( pick( w->pos() ) == pos ) {
741 }
else if ( s->isSplitter ) {
744 if( TQApplication::reverseLayout() && orient == TQt::Horizontal ) {
752 setG( w, pos1, dd, TRUE );
753 moveAfter( pos2,
id+1, upLeft );
755 moveAfter( pos2,
id+1, upLeft );
756 setG( w, pos1, dd, TRUE );
759 int left = pick( w->pos() );
760 int right, dd, newLeft, nextPos;
761 if ( TQApplication::reverseLayout() && orient == TQt::Horizontal ) {
763 dd = TQMAX( pick(minSize(w)), TQMIN(dd, pick(w->maximumSize())));
765 nextPos = newLeft - 1;
767 right = pick( w->geometry().bottomRight() );
768 dd = right - pos + 1;
769 dd = TQMAX( pick(minSize(w)), TQMIN(dd, pick(w->maximumSize())));
772 nextPos = newLeft + dd;
774 setG( w, newLeft, dd, TRUE );
776 moveAfter( nextPos,
id+1, upLeft );
781 void KDGanttMinimizeSplitter::expandPos(
int id,
int* min,
int* max )
783 TQSplitterLayoutStruct *s = data->list.at(
id-1);
784 TQWidget* w = s->wid;
785 *min = pick( w->mapToParent( TQPoint(0,0) ) );
787 if ( (uint)
id == data->list.count() ) {
791 TQSplitterLayoutStruct *s = data->list.at(
id+1);
792 TQWidget* w = s->wid;
793 *max = pick( w->mapToParent( TQPoint( w->width(), w->height() ) ) ) -8;
810 int n = data->list.count();
811 if ( id < 0 || id >= n )
814 for ( i = 0; i < id; i++ ) {
815 TQSplitterLayoutStruct *s = data->list.at(i);
816 if ( s->wid->isHidden() ) {
818 }
else if ( s->isSplitter ) {
822 minB += pick( minSize(s->wid) );
823 maxB += pick( s->wid->maximumSize() );
826 for ( i =
id; i < n; i++ ) {
827 TQSplitterLayoutStruct *s = data->list.at(i);
828 if ( s->wid->isHidden() ) {
830 }
else if ( s->isSplitter ) {
834 minA += pick( minSize(s->wid) );
835 maxA += pick( s->wid->maximumSize() );
838 TQRect r = contentsRect();
839 if ( orient == TQt::Horizontal && TQApplication::reverseLayout() ) {
840 int splitterWidth = style().pixelMetric(TQStyle::PM_SplitterWidth,
this);
842 *min = pick(r.topRight()) - TQMIN( maxB, pick(r.size())-minA ) - splitterWidth;
844 *max = pick(r.topRight()) - TQMAX( minB, pick(r.size())-maxA ) - splitterWidth;
847 *min = pick(r.topLeft()) + TQMAX( minB, pick(r.size())-maxA );
849 *max = pick(r.topLeft()) + TQMIN( maxB, pick(r.size())-minA );
865 p = TQMAX( min, TQMIN( p, max ) );
871 void KDGanttMinimizeSplitter::doResize()
873 TQRect r = contentsRect();
875 int n = data->list.count();
876 TQMemArray<TQLayoutStruct> a( n );
877 for ( i = 0; i< n; i++ ) {
879 TQSplitterLayoutStruct *s = data->list.at(i);
880 if ( s->wid->isHidden() ) {
882 a[i].sizeHint = a[i].minimumSize = 0;
883 a[i].maximumSize = 0;
884 }
else if ( s->isSplitter ) {
886 a[i].sizeHint = a[i].minimumSize = a[i].maximumSize = s->sizer;
888 }
else if ( s->mode == KeepSize ) {
890 a[i].minimumSize = pick( minSize(s->wid) );
891 a[i].sizeHint = s->sizer;
892 a[i].maximumSize = pick( s->wid->maximumSize() );
894 }
else if ( s->mode == FollowSizeHint ) {
896 a[i].minimumSize = a[i].sizeHint = pick( s->wid->sizeHint() );
897 a[i].maximumSize = pick( s->wid->maximumSize() );
900 a[i].stretch = s->sizer;
901 a[i].maximumSize = pick( s->wid->maximumSize() );
902 a[i].sizeHint = a[i].minimumSize = pick( minSize(s->wid) );
907 kdganttGeomCalc( a, 0, n, pick( r.topLeft() ), pick( r.size() ), 0 );
909 for ( i = 0; i< n; i++ ) {
910 TQSplitterLayoutStruct *s = data->list.at(i);
911 setG( s->wid, a[i].pos, a[i].size );
917 void KDGanttMinimizeSplitter::recalc(
bool update )
919 int fi = 2*frameWidth();
922 int maxt = TQWIDGETSIZE_MAX;
924 int n = data->list.count();
931 for (
int i = 0; i< n; i++ ) {
932 TQSplitterLayoutStruct *s = data->list.at(i);
933 if ( !s->isSplitter ) {
934 TQSplitterLayoutStruct *p = (i > 0) ? data->list.at( i-1 ) : 0;
935 if ( p && p->isSplitter )
936 if ( first || s->wid->isHidden() )
940 if ( !s->wid->isHidden() )
946 for (
int j = 0; j< n; j++ ) {
947 TQSplitterLayoutStruct *s = data->list.at(j);
948 if ( !s->wid->isHidden() ) {
950 if ( s->isSplitter ) {
954 TQSize minS = minSize(s->wid);
955 minl += pick( minS );
956 maxl += pick( s->wid->maximumSize() );
957 mint = TQMAX( mint, trans( minS ));
958 int tm = trans( s->wid->maximumSize() );
960 maxt = TQMIN( maxt, tm );
965 if ( parentWidget() != 0 && parentWidget()->inherits(
"KDGanttMinimizeSplitter") ) {
970 maxl = TQWIDGETSIZE_MAX;
973 maxl = TQMIN( maxl, TQWIDGETSIZE_MAX );
978 if ( orient == TQt::Horizontal ) {
979 setMaximumSize( maxl, maxt );
980 setMinimumSize( minl, mint );
982 setMaximumSize( maxt, maxl );
983 setMinimumSize( mint, minl );
997 processChildEvents();
998 TQSplitterLayoutStruct *s = data->list.first();
1000 if ( s->wid == w ) {
1004 s = data->list.next();
1006 s = addWidget( w, TRUE );
1019 return data->opaque;
1043 processChildEvents();
1045 TQSplitterLayoutStruct *s = data->list.first();
1047 if ( s->wid == w ) {
1049 TQSplitterLayoutStruct *p = data->list.prev();
1053 data->list.insert( 0, p );
1054 data->list.insert( 0, s );
1058 s = data->list.next();
1061 addWidget( w, TRUE );
1072 processChildEvents();
1074 TQSplitterLayoutStruct *s = data->list.first();
1076 if ( s->wid == w ) {
1079 TQSplitterLayoutStruct *p = data->list.current();
1082 data->list.append( p );
1084 data->list.append( s );
1087 s = data->list.next();
1095 void KDGanttMinimizeSplitter::recalcId()
1097 int n = data->list.count();
1098 for (
int i = 0; i < n; i++ ) {
1099 TQSplitterLayoutStruct *s = data->list.at(i);
1100 if ( s->isSplitter )
1101 ((KDGanttSplitterHandle*)s->wid)->setId(i);
1113 if ( !childrenListObject().isEmpty() ) {
1114 const TQObjectList c = childrenListObject();
1115 TQObjectListIt it( c );
1118 while( (o=it.current()) != 0 ) {
1120 if ( o->isWidgetType() &&
1121 !((TQWidget*)o)->isHidden() ) {
1122 TQSize s = ((TQWidget*)o)->sizeHint();
1123 if ( s.isValid() ) {
1125 t = TQMAX( t, trans( s ) );
1130 return orientation() == TQt::Horizontal ? TQSize( l, t ) : TQSize( t, l );
1143 if ( !childrenListObject().isEmpty() ) {
1144 const TQObjectList c = childrenListObject();
1145 TQObjectListIt it( c );
1148 while( (o=it.current()) != 0 ) {
1150 if ( o->isWidgetType() &&
1151 !((TQWidget*)o)->isHidden() ) {
1152 TQSize s = minSizeHint((TQWidget*)o);
1153 if ( s.isValid() ) {
1155 t = TQMAX( t, trans( s ) );
1160 return orientation() == TQt::Horizontal ? TQSize( l, t ) : TQSize( t, l );
1168 void KDGanttMinimizeSplitter::storeSizes()
1170 TQSplitterLayoutStruct *s = data->list.first();
1172 if ( !s->isSplitter )
1173 s->sizer = pick( s->wid->size() );
1174 s = data->list.next();
1188 void KDGanttMinimizeSplitter::setHidden( TQWidget *w,
bool hide )
1192 }
else if ( w == w2 ) {
1195 #ifdef TQT_CHECK_RANGE
1196 tqWarning(
"KDGanttMinimizeSplitter::setHidden(), unknown widget" );
1212 bool KDGanttMinimizeSplitter::isHidden( TQWidget *w )
const
1218 #ifdef TQT_CHECK_RANGE
1220 tqWarning(
"KDGanttMinimizeSplitter::isHidden(), unknown widget" );
1250 if ( !testWState(WState_Polished) ) {
1251 TQWidget* that = (TQWidget*)
this;
1254 TQValueList<int> list;
1255 TQSplitterLayoutStruct *s = data->list.first();
1257 if ( !s->isSplitter )
1258 list.append( s->sizer );
1259 s = data->list.next();
1281 processChildEvents();
1282 TQValueList<int>::Iterator it = list.begin();
1283 TQSplitterLayoutStruct *s = data->list.first();
1284 while ( s && it != list.end() ) {
1285 if ( !s->isSplitter ) {
1289 s = data->list.next();
1300 void KDGanttMinimizeSplitter::processChildEvents()
1302 TQApplication::sendPostedEvents(
this, TQEvent::ChildInserted );
1312 int sw = style().pixelMetric(TQStyle::PM_SplitterWidth,
this);
1313 TQSplitterLayoutStruct *s = data->list.first();
1315 if ( s->isSplitter )
1317 s = data->list.next();
1320 TQFrame::styleChange( old );
1332 _direction = direction;
1347 static inline int toFixed(
int i ) {
return i * 256; }
1348 static inline int fRound(
int i ) {
1349 return ( i % 256 < 128 ) ? i / 256 : 1 + i / 256;
1351 void kdganttGeomCalc( TQMemArray<TQLayoutStruct> &chain,
int start,
int count,
int pos,
1352 int space,
int spacer )
1359 int spacerCount = 0;
1361 bool wannaGrow = FALSE;
1365 for ( i = start; i < start + count; i++ ) {
1366 chain[i].done = FALSE;
1367 cHint += chain[i].sizeHint;
1368 cMin += chain[i].minimumSize;
1369 cMax += chain[i].maximumSize;
1370 sumStretch += chain[i].stretch;
1371 if ( !chain[i].empty )
1373 wannaGrow = wannaGrow || chain[i].expansive;
1379 if ( space < cMin + spacerCount * spacer ) {
1381 for ( i = start; i < start+count; i++ ) {
1382 chain[i].size = chain[i].minimumSize;
1383 chain[i].done = TRUE;
1385 }
else if ( space < cHint + spacerCount*spacer ) {
1390 int space_left = space - spacerCount*spacer;
1391 int overdraft = cHint - space_left;
1393 for ( i = start; i < start+count; i++ ) {
1394 if ( !chain[i].done && chain[i].minimumSize >= chain[i].sizeHint) {
1395 chain[i].size = chain[i].sizeHint;
1396 chain[i].done = TRUE;
1397 space_left -= chain[i].sizeHint;
1402 bool finished = n == 0;
1403 while ( !finished ) {
1405 fixed fp_over = toFixed( overdraft );
1408 for ( i = start; i < start+count; i++ ) {
1409 if ( chain[i].done )
1412 fp_w += fp_over / n;
1415 int w = fRound( fp_w );
1416 chain[i].size = chain[i].sizeHint - w;
1417 fp_w -= toFixed( w );
1418 if ( chain[i].size < chain[i].minimumSize ) {
1419 chain[i].done = TRUE;
1420 chain[i].size = chain[i].minimumSize;
1422 overdraft -= chain[i].sizeHint - chain[i].minimumSize;
1431 int space_left = space - spacerCount*spacer;
1433 for ( i = start; i < start + count; i++ ) {
1434 if ( !chain[i].done && (chain[i].maximumSize <= chain[i].sizeHint
1435 || wannaGrow && !chain[i].expansive) ) {
1436 chain[i].size = chain[i].sizeHint;
1437 chain[i].done = TRUE;
1438 space_left -= chain[i].sizeHint;
1439 sumStretch -= chain[i].stretch;
1443 extraspace = space_left;
1454 int surplus, deficit;
1456 surplus = deficit = 0;
1457 fixed fp_space = toFixed( space_left );
1459 for ( i = start; i < start+count; i++ ) {
1460 if ( chain[i].done )
1463 if ( sumStretch <= 0 )
1464 fp_w += fp_space / n;
1466 fp_w += (fp_space * chain[i].stretch) / sumStretch;
1467 int w = fRound( fp_w );
1469 fp_w -= toFixed( w );
1470 if ( w < chain[i].sizeHint ) {
1471 deficit += chain[i].sizeHint - w;
1472 }
else if ( w > chain[i].maximumSize ) {
1473 surplus += w - chain[i].maximumSize;
1476 if ( deficit > 0 && surplus <= deficit ) {
1478 for ( i = start; i < start+count; i++ ) {
1479 if ( !chain[i].done &&
1480 chain[i].size < chain[i].sizeHint ) {
1481 chain[i].size = chain[i].sizeHint;
1482 chain[i].done = TRUE;
1483 space_left -= chain[i].sizeHint;
1484 sumStretch -= chain[i].stretch;
1489 if ( surplus > 0 && surplus >= deficit ) {
1491 for ( i = start; i < start+count; i++ ) {
1492 if ( !chain[i].done &&
1493 chain[i].size > chain[i].maximumSize ) {
1494 chain[i].size = chain[i].maximumSize;
1495 chain[i].done = TRUE;
1496 space_left -= chain[i].maximumSize;
1497 sumStretch -= chain[i].stretch;
1502 }
while ( n > 0 && surplus != deficit );
1504 extraspace = space_left;
1511 int extra = extraspace / ( spacerCount + 2 );
1512 int p = pos + extra;
1513 for ( i = start; i < start+count; i++ ) {
1515 p = p + chain[i].size;
1516 if ( !chain[i].empty )
The KDGanttMinimizeSplitter class implements a splitter widget with minimize buttons.
KDGanttMinimizeSplitter(TQWidget *parent=0, const char *name=0)
void setSizes(TQValueList< int >)
TQValueList< int > sizes() const
void styleChange(TQStyle &)
virtual void setOrientation(TQt::Orientation)
the orientation of the splitter
virtual void setOpaqueResize(bool=TRUE)
virtual TQSize sizeHint() const
virtual void setResizeMode(TQWidget *w, ResizeMode)
void moveSplitter(TQCOORD pos, int id)
void moveToLast(TQWidget *)
bool opaqueResize() const
void moveToFirst(TQWidget *)
int idAfter(TQWidget *) const
void setMinimizeDirection(Direction)
void resizeEvent(TQResizeEvent *)
virtual TQSize minimumSizeHint() const
virtual void setRubberband(int)
~KDGanttMinimizeSplitter()
Direction minimizeDirection() const
void childEvent(TQChildEvent *)
void getRange(int id, int *, int *)
virtual void drawSplitter(TQPainter *, TQCOORD x, TQCOORD y, TQCOORD w, TQCOORD h)
TQt::Orientation orientation() const