00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "KDGanttSemiSizingControl.h"
00036 #include <qpushbutton.h>
00037 #include <qpointarray.h>
00038 #include <qpainter.h>
00039 #include <qbitmap.h>
00040 #include <qtooltip.h>
00041 #include <qwhatsthis.h>
00066 KDGanttSemiSizingControl::KDGanttSemiSizingControl( QWidget* parent,
00067 const char* name ) :
00068 KDGanttSizingControl( parent, name ), _orient( Horizontal ),
00069 _arrowPos( Before ), _minimizedWidget(0), _maximizedWidget(0)
00070 {
00071 init();
00072 }
00073
00074
00087 KDGanttSemiSizingControl::KDGanttSemiSizingControl( Orientation orientation,
00088 QWidget* parent,
00089 const char* name ) :
00090 KDGanttSizingControl( parent, name ), _orient( orientation ),
00091 _arrowPos( Before ), _minimizedWidget(0), _maximizedWidget(0)
00092 {
00093 init();
00094 }
00095
00096
00110 KDGanttSemiSizingControl::KDGanttSemiSizingControl( ArrowPosition arrowPosition,
00111 Orientation orientation,
00112 QWidget* parent,
00113 const char* name ) :
00114 KDGanttSizingControl( parent, name ), _orient( orientation ),
00115 _arrowPos( arrowPosition ), _minimizedWidget(0), _maximizedWidget(0)
00116 {
00117 init();
00118 }
00119
00120
00130 void KDGanttSemiSizingControl::setMinimizedWidget( QWidget* widget )
00131 {
00132 _minimizedWidget = widget;
00133 if( _minimizedWidget ) _minimizedWidget->hide();
00134 setup();
00135 }
00136
00137
00146 QWidget* KDGanttSemiSizingControl::minimizedWidget() const
00147 {
00148 return _minimizedWidget;
00149 }
00150
00160 void KDGanttSemiSizingControl::setMaximizedWidget( QWidget* widget )
00161 {
00162 _maximizedWidget = widget;
00163
00164 setup();
00165 }
00166
00175 QWidget* KDGanttSemiSizingControl::maximizedWidget() const
00176 {
00177 return _maximizedWidget;
00178 }
00179
00180
00181
00189 void KDGanttSemiSizingControl::setOrientation( Qt::Orientation orientation )
00190 {
00191 if ( _orient != orientation ) {
00192 _orient = orientation;
00193 setup();
00194 }
00195 }
00196
00197
00204 Qt::Orientation KDGanttSemiSizingControl::orientation() const
00205 {
00206 return _orient;
00207 }
00208
00209
00217 void KDGanttSemiSizingControl::setArrowPosition( ArrowPosition arrowPosition )
00218 {
00219 if ( _arrowPos != arrowPosition ) {
00220 _arrowPos = arrowPosition;
00221 setup();
00222 }
00223 }
00224
00225
00233 KDGanttSemiSizingControl::ArrowPosition KDGanttSemiSizingControl::arrowPosition() const
00234 {
00235 return _arrowPos;
00236 }
00237
00238
00247 void KDGanttSemiSizingControl::init()
00248 {
00249 _but = new QPushButton( this );
00250 _but->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
00251 connect( _but, SIGNAL( clicked() ), this, SLOT(changeState()) );
00252 _layout = 0;
00253 QWhatsThis::add( _but, "Click on this button to show the \nlegend at the bottom of the widget");
00254 QToolTip::add( _but, "Show / hide legend");
00255
00256
00257 }
00258
00259 void KDGanttSemiSizingControl::setup()
00260 {
00261
00262 delete _layout;
00263 QBoxLayout* butLayout;
00264
00265 if ( _orient == Horizontal || isMinimized() )
00266 _layout = new QHBoxLayout( this );
00267 else
00268 _layout = new QVBoxLayout( this );
00269
00270 if ( _orient == Vertical && !isMinimized() )
00271 butLayout = new QHBoxLayout( _layout );
00272 else
00273 butLayout = new QVBoxLayout( _layout );
00274
00275
00276
00277
00278 if ( !isMinimized() ) {
00279 _but->setPixmap( pixmap( Down ) );
00280 }
00281 else {
00282 if ( _arrowPos == Before ) {
00283 _but->setPixmap( pixmap( Right ) );
00284 }
00285 else {
00286 _but->setPixmap( pixmap( Left ) );
00287 }
00288 }
00289
00290
00291 if ( _arrowPos == After && _orient == Vertical && !isMinimized() ) {
00292 butLayout->addStretch( 1 );
00293 butLayout->addWidget( _but, 0, Qt::AlignLeft );
00294 }
00295 else {
00296 butLayout->addWidget( _but, 0, Qt::AlignRight );
00297 butLayout->addStretch( 1 );
00298 }
00299
00300
00301 QWidget* widget;
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318 if ( isMinimized() ) {
00319 widget = _minimizedWidget;
00320 if( widget ) {
00321 if ( _arrowPos == Before || _orient == Vertical && !isMinimized() )
00322 _layout->addWidget( widget, 1 );
00323 else
00324 _layout->insertWidget( 0, widget, 1 );
00325 }
00326 }
00327 else {
00328 if ( _arrowPos == Before || _orient == Vertical && !isMinimized() )
00329 _layout->addStretch( 1 );
00330 else
00331 _layout->insertStretch( 0, 1 );
00332 widget = _maximizedWidget;
00333
00334
00335
00336 }
00337 }
00338
00339
00348 void KDGanttSemiSizingControl::restore( bool restore )
00349 {
00350 if ( ! restore ) {
00351 minimize( true );
00352 }
00353 else {
00354 if( _maximizedWidget ) _maximizedWidget->show();
00355 if( _minimizedWidget ) _minimizedWidget->hide();
00356 KDGanttSizingControl::restore( restore );
00357 setup();
00358 }
00359 }
00360
00370 void KDGanttSemiSizingControl::minimize( bool minimize )
00371 {
00372 if ( ! minimize ) {
00373 restore( true );
00374 }
00375 else {
00376 if( _minimizedWidget ) _minimizedWidget->show();
00377 if( _maximizedWidget ) _maximizedWidget->hide();
00378 KDGanttSizingControl::minimize( minimize );
00379 setup();
00380 }
00381 }
00382
00383 QPixmap KDGanttSemiSizingControl::pixmap( Direction direction ) {
00384 int s = 10;
00385 QPixmap pix( s, s );
00386 pix.fill( blue );
00387
00388 QPointArray arr;
00389 switch ( direction ) {
00390 case Up: arr.setPoints( 3, 0, s-1, s-1, s-1, 0, s/2 ); ;break;
00391 case Down: arr.setPoints( 3, 0, 0, s-1, 0, s/2, s-1 ); break;
00392 case Left: arr.setPoints( 3, s-1, 0, s-1, s-1, 0, s/2 ); break;
00393 case Right: arr.setPoints( 3, 0,0, s-1, s/2, 0, s-1 ); break;
00394 }
00395
00396 QPainter p( &pix );
00397 p.setPen( black );
00398 p.setBrush( colorGroup().button() );
00399 p.drawPolygon( arr );
00400 QBitmap bit( s, s );
00401 bit.fill( color0 );
00402
00403 QPainter p2( &bit );
00404 p2.setPen( color1 );
00405 p2.setBrush( color1 );
00406 p2.drawPolygon( arr );
00407 pix.setMask( bit );
00408 return pix;
00409 }
00410
00411 #ifndef KDGANTT_MASTER_CVS
00412 #include "KDGanttSemiSizingControl.moc"
00413 #endif