iistaskbox.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   Copyright: http://www.ii-system.com                                   *
00004  *   License:   LGPL                                                       *
00005  *                                                                         *
00006  ***************************************************************************/
00007 
00008 #include "iistaskbox.h"
00009 #include "iistaskheader.h"
00010 #include "iistaskgroup.h"
00011 #include "iistaskpanelscheme.h"
00012 
00013 
00014 iisTaskBox::iisTaskBox(const QString &title, bool expandable, QWidget *parent)
00015         : QFrame(parent)
00016 {
00017         myHeader = new iisTaskHeader(QPixmap(), title, expandable, this);
00018         init();
00019 }
00020 
00021 iisTaskBox::iisTaskBox(const QPixmap &icon, const QString &title, bool expandable, QWidget *parent)
00022         : QFrame(parent)
00023 {
00024         myHeader = new iisTaskHeader(icon, title, expandable, this);
00025         init();
00026 }
00027 
00028 void iisTaskBox::init()
00029 {
00030         m_foldStep = 0;
00031 
00032         myScheme = iisTaskPanelScheme::defaultScheme();
00033 
00034         QVBoxLayout *vbl = new QVBoxLayout();
00035         vbl->setMargin(0);
00036         vbl->setSpacing(0);
00037         setLayout(vbl);
00038 
00039         vbl->addWidget(myHeader);
00040 
00041         myGroup = new iisTaskGroup(this, true);
00042         vbl->addWidget(myGroup);
00043 
00044         myDummy = new QWidget(this);
00045         vbl->addWidget(myDummy);
00046         myDummy->hide();
00047 
00048         connect(myHeader, SIGNAL(activated()), this, SLOT(showHide()));
00049 }
00050 
00051 iisTaskBox::~iisTaskBox()
00052 {
00053 
00054 }
00055 
00056 void iisTaskBox::setScheme(iisTaskPanelScheme *pointer)
00057 {
00058         myScheme = pointer;
00059         myHeader->setScheme(pointer);
00060         myGroup->setScheme(pointer);
00061         update();
00062 }
00063 
00064 QBoxLayout* iisTaskBox::groupLayout()
00065 {
00066         return myGroup->groupLayout();
00067 }
00068 
00069 void iisTaskBox::addIconLabel(iisIconLabel *label, bool addToLayout)
00070 {
00071         myGroup->addIconLabel(label, addToLayout);
00072 }
00073 
00074 
00075 void iisTaskBox::showHide()
00076 {
00077         if (m_foldStep)
00078                 return;
00079 
00080         m_foldPixmap = QPixmap::grabWidget(myGroup, myGroup->rect());
00081 
00082         if (myGroup->isVisible()) {
00083                 m_tempHeight = m_fullHeight = myGroup->height();
00084                 m_foldDelta = m_fullHeight / myScheme->groupFoldSteps;
00085                 m_foldStep = myScheme->groupFoldSteps;
00086                 m_foldDirection = -1;
00087 
00088                 myGroup->hide();
00089                 myDummy->setFixedSize(myGroup->size());
00090                 myDummy->show();
00091 
00092                 QTimer::singleShot(myScheme->groupFoldDelay, this, SLOT(processHide()));
00093         }
00094         else {
00095                 m_foldStep = myScheme->groupFoldSteps;
00096                 m_foldDirection = 1;
00097                 m_tempHeight = 0;
00098 
00099                 QTimer::singleShot(myScheme->groupFoldDelay, this, SLOT(processShow()));
00100         }
00101 
00102         myDummy->show();
00103 }
00104 
00105 void iisTaskBox::processHide()
00106 {
00107         if (!--m_foldStep) {
00108                 myDummy->setFixedHeight(0);
00109                 myDummy->hide();
00110                 m_foldPixmap = QPixmap();
00111                 setFixedHeight(myHeader->height());
00112                 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
00113                 return;
00114         }
00115 
00116         setUpdatesEnabled(false);
00117 
00118         m_tempHeight -= m_foldDelta; 
00119         myDummy->setFixedHeight(m_tempHeight);
00120         setFixedHeight(myDummy->height()+myHeader->height());
00121 
00122         QTimer::singleShot(myScheme->groupFoldDelay, this, SLOT(processHide()));
00123 
00124         setUpdatesEnabled(true);
00125 }
00126 
00127 void iisTaskBox::processShow()
00128 {
00129         if (!--m_foldStep) {
00130                 myDummy->hide();
00131                 m_foldPixmap = QPixmap();
00132                 myGroup->show();
00133                 setFixedHeight(m_fullHeight+myHeader->height());
00134                 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
00135                 setMaximumHeight(QWIDGETSIZE_MAX);
00136                 setMinimumHeight(0);
00137                 return;
00138         }
00139 
00140         setUpdatesEnabled(false);
00141 
00142         m_tempHeight += m_foldDelta; 
00143         myDummy->setFixedHeight(m_tempHeight);
00144         setFixedHeight(myDummy->height()+myHeader->height());
00145 
00146         QTimer::singleShot(myScheme->groupFoldDelay, this, SLOT(processShow()));
00147 
00148         setUpdatesEnabled(true);
00149 }
00150 
00151 void iisTaskBox::paintEvent ( QPaintEvent * event ) 
00152 {
00153         QPainter p(this);
00154 
00155         if (myDummy->isVisible()) {
00156 #if QT_VERSION >= 0x040202
00157                 if (m_foldDirection < 0)
00158                         p.setOpacity((double)m_foldStep / myScheme->groupFoldSteps);
00159                 else
00160                         p.setOpacity((double)(myScheme->groupFoldSteps-m_foldStep) / myScheme->groupFoldSteps);
00161 #endif
00162 
00163                 p.drawPixmap(myDummy->x(),myDummy->y(),m_foldPixmap);
00164 
00165                 return;
00166         }
00167 
00168 }

Generated on Wed Nov 23 19:00:18 2011 for FreeCAD by  doxygen 1.6.1