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 #include "KDGanttSemiSizingControl.h"
00034 #include <QPushButton>
00035 #include <QPainter>
00036 #include <QBitmap>
00037
00038 #include <QWhatsThis>
00063 KDGanttSemiSizingControl::KDGanttSemiSizingControl( QWidget* parent ) :
00064 KDGanttSizingControl( parent ), _orient( Qt::Horizontal ),
00065 _arrowPos( Before ), _minimizedWidget(0), _maximizedWidget(0)
00066 {
00067 init();
00068 }
00069
00070
00083 KDGanttSemiSizingControl::KDGanttSemiSizingControl( Qt::Orientation orientation,
00084 QWidget* parent ):
00085 KDGanttSizingControl( parent ), _orient( orientation ),
00086 _arrowPos( Before ), _minimizedWidget(0), _maximizedWidget(0)
00087 {
00088 init();
00089 }
00090
00091
00105 KDGanttSemiSizingControl::KDGanttSemiSizingControl( ArrowPosition arrowPosition,
00106 Qt::Orientation orientation,
00107 QWidget* parent ):
00108 KDGanttSizingControl( parent ), _orient( orientation ),
00109 _arrowPos( arrowPosition ), _minimizedWidget(0), _maximizedWidget(0)
00110 {
00111 init();
00112 }
00113
00114
00124 void KDGanttSemiSizingControl::setMinimizedWidget( QWidget* widget )
00125 {
00126 _minimizedWidget = widget;
00127 if( _minimizedWidget ) _minimizedWidget->hide();
00128 setup();
00129 }
00130
00131
00140 QWidget* KDGanttSemiSizingControl::minimizedWidget() const
00141 {
00142 return _minimizedWidget;
00143 }
00144
00154 void KDGanttSemiSizingControl::setMaximizedWidget( QWidget* widget )
00155 {
00156 _maximizedWidget = widget;
00157
00158 setup();
00159 }
00160
00169 QWidget* KDGanttSemiSizingControl::maximizedWidget() const
00170 {
00171 return _maximizedWidget;
00172 }
00173
00174
00175
00183 void KDGanttSemiSizingControl::setOrientation( Qt::Orientation orientation )
00184 {
00185 if ( _orient != orientation ) {
00186 _orient = orientation;
00187 setup();
00188 }
00189 }
00190
00191
00198 Qt::Orientation KDGanttSemiSizingControl::orientation() const
00199 {
00200 return _orient;
00201 }
00202
00203
00211 void KDGanttSemiSizingControl::setArrowPosition( ArrowPosition arrowPosition )
00212 {
00213 if ( _arrowPos != arrowPosition ) {
00214 _arrowPos = arrowPosition;
00215 setup();
00216 }
00217 }
00218
00219
00227 KDGanttSemiSizingControl::ArrowPosition KDGanttSemiSizingControl::arrowPosition() const
00228 {
00229 return _arrowPos;
00230 }
00231
00232
00241 void KDGanttSemiSizingControl::init()
00242 {
00243 _but = new QPushButton( this );
00244 _but->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
00245 connect( _but, SIGNAL( clicked() ), this, SLOT(changeState()) );
00246 _layout = 0;
00247 _but->setWhatsThis( "Click on this button to show the \nlegend at the bottom of the widget");
00248 _but->setToolTip( "Show / hide legend");
00249
00250
00251 }
00252
00253 void KDGanttSemiSizingControl::setup()
00254 {
00255
00256 delete _layout;
00257 QBoxLayout* butLayout;
00258
00259 if ( _orient == Qt::Horizontal || isMinimized() )
00260 _layout = new QHBoxLayout( this );
00261 else
00262 _layout = new QVBoxLayout( this );
00263
00264 if ( _orient == Qt::Vertical && !isMinimized() ) {
00265 butLayout = new QHBoxLayout();
00266 _layout->addItem( butLayout );
00267 } else {
00268 butLayout = new QVBoxLayout();
00269 _layout->addItem( butLayout );
00270 }
00271
00272
00273
00274 if ( !isMinimized() ) {
00275 _but->setIcon( QIcon(pixmap( Down )) );
00276 }
00277 else {
00278 if ( _arrowPos == Before ) {
00279 _but->setIcon( QIcon(pixmap( Right )) );
00280 }
00281 else {
00282 _but->setIcon( QIcon(pixmap( Left )) );
00283 }
00284 }
00285
00286
00287 if ( _arrowPos == After && _orient == Qt::Vertical && !isMinimized() ) {
00288 butLayout->addStretch( 1 );
00289 butLayout->addWidget( _but, 0, Qt::AlignLeft );
00290 }
00291 else {
00292 butLayout->addWidget( _but, 0, Qt::AlignRight );
00293 butLayout->addStretch( 1 );
00294 }
00295
00296
00297 QWidget* widget;
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 if ( isMinimized() ) {
00315 widget = _minimizedWidget;
00316 if( widget ) {
00317 if ( _arrowPos == Before || _orient == Qt::Vertical && !isMinimized() )
00318 _layout->addWidget( widget, 1 );
00319 else
00320 _layout->insertWidget( 0, widget, 1 );
00321 }
00322 }
00323 else {
00324 if ( _arrowPos == Before || _orient == Qt::Vertical && !isMinimized() )
00325 _layout->addStretch( 1 );
00326 else
00327 _layout->insertStretch( 0, 1 );
00328 widget = _maximizedWidget;
00329
00330
00331
00332 }
00333 }
00334
00335
00344 void KDGanttSemiSizingControl::restore( bool restore )
00345 {
00346 if ( ! restore ) {
00347 minimize( true );
00348 }
00349 else {
00350 if( _maximizedWidget ) _maximizedWidget->show();
00351 if( _minimizedWidget ) _minimizedWidget->hide();
00352 KDGanttSizingControl::restore( restore );
00353 setup();
00354 }
00355 }
00356
00366 void KDGanttSemiSizingControl::minimize( bool minimize )
00367 {
00368 if ( ! minimize ) {
00369 restore( true );
00370 }
00371 else {
00372 if( _minimizedWidget ) _minimizedWidget->show();
00373 if( _maximizedWidget ) _maximizedWidget->hide();
00374 KDGanttSizingControl::minimize( minimize );
00375 setup();
00376 }
00377 }
00378
00379 QPixmap KDGanttSemiSizingControl::pixmap( Direction direction ) {
00380 int s = 10;
00381 QPixmap pix( s, s );
00382 pix.fill( Qt::blue );
00383
00384 QPointArray arr;
00385 switch ( direction ) {
00386 case Up: arr.setPoints( 3, 0, s-1, s-1, s-1, 0, s/2 ); ;break;
00387 case Down: arr.setPoints( 3, 0, 0, s-1, 0, s/2, s-1 ); break;
00388 case Left: arr.setPoints( 3, s-1, 0, s-1, s-1, 0, s/2 ); break;
00389 case Right: arr.setPoints( 3, 0,0, s-1, s/2, 0, s-1 ); break;
00390 }
00391 #if QT_VERSION < 0x040000
00392 QPainter p( &pix );
00393 p.setPen( Qt::black );
00394 p.setBrush( colorGroup().button() );
00395 p.drawPolygon( arr );
00396 QBitmap bit( s, s );
00397 bit.fill( color0 );
00398
00399 QPainter p2( &bit );
00400 p2.setPen( color1 );
00401 p2.setBrush( color1 );
00402 p2.drawPolygon( arr );
00403 pix.setMask( bit );
00404 #else
00405 QPainter p( &pix );
00406 p.setPen( Qt::black );
00407 p.setBrush( palette().color( QPalette::Button) );
00408 p.drawPolygon( arr );
00409 QBitmap bit( s, s );
00410 bit.fill( Qt::blue );
00411
00412 QPainter p2( &bit );
00413 p2.setPen( Qt::red );
00414 p2.setBrush( Qt::red );
00415 p2.drawPolygon( arr );
00416 pix.setMask( bit );
00417 #endif
00418 return pix;
00419 }
00420
00421 #include "KDGanttSemiSizingControl.moc"