• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kdgantt1

KDGanttSemiSizingControl.cpp

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002    $Id: KDGanttSemiSizingControl.cpp,v 1.6 2005/10/11 13:59:02 lutz Exp $
00003 */
00004 
00005 /****************************************************************************
00006  ** Copyright (C)  2002-2004 Klarälvdalens Datakonsult AB.  All rights reserved.
00007  **
00008  ** This file is part of the KDGantt library.
00009  **
00010  ** This file may be used under the terms of the GNU General Public
00011  ** License versions 2.0 or 3.0 as published by the Free Software
00012  ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
00013  ** included in the packaging of this file.  Alternatively you may (at
00014  ** your option) use any later version of the GNU General Public
00015  ** License if such license has been publicly approved by
00016  ** Klarälvdalens Datakonsult AB (or its successors, if any).
00017  ** 
00018  ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
00019  ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
00020  ** A PARTICULAR PURPOSE. Klarälvdalens Datakonsult AB reserves all rights
00021  ** not expressly granted herein.
00022  ** 
00023  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00024  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00025  **
00026  ** As a special exception, permission is given to link this program
00027  ** with any edition of Qt, and distribute the resulting executable,
00028  ** without including the source code for Qt in the source distribution.
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     //if( _maximizedWidget ) _maximizedWidget->show();
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     //-------------------------------------------------- Setup layout
00256     delete _layout;
00257     QBoxLayout* butLayout; // _layout will delete me
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     //---------------------------------------- Set the arrow on the button
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     //------------------------------ Setup the button at the correct possition
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     // Set widget in the correct possition
00297     QWidget* widget;
00298     /* ************************** old code ***************
00299        if ( isMinimized() )
00300        widget = _minimizedWidget;
00301        else
00302        widget = _maximizedWidget;
00303        if( widget ) {
00304        if ( _arrowPos == Before  || _orient == Vertical && !isMinimized() )
00305        _layout->addWidget( widget, 1 );
00306        else
00307        _layout->insertWidget( 0, widget, 1 );
00308     }
00309      ************************************************** */
00310     // hack for the usage in KDGantt as pop-up legend widget
00311     // for this purpose,
00312     // the _maximizedWidget must be a child of the parent of this widget
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       // the following is only the special case
00330       // arrowPos == Before  and  _orient == Vertical
00331       //widget->move( 0+x(), _but->height()+y());
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"

kdgantt1

Skip menu "kdgantt1"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal