iistaskheader.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "iistaskheader.h"
00009 #include "iistaskpanelscheme.h"
00010 #include "iisiconlabel.h"
00011
00012 iisTaskHeader::iisTaskHeader(const QIcon &icon, const QString &title, bool expandable, QWidget *parent)
00013 : QFrame(parent),
00014 myExpandable(expandable),
00015 m_over(false),
00016 m_buttonOver(false),
00017 m_fold(true),
00018 m_opacity(0.1),
00019 myButton(0)
00020 {
00021 myTitle = new iisIconLabel(icon, title, this);
00022 myTitle->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
00023
00024 connect(myTitle, SIGNAL(activated()), this, SLOT(fold()));
00025
00026 QHBoxLayout *hbl = new QHBoxLayout();
00027 hbl->setMargin(2);
00028 setLayout(hbl);
00029
00030 hbl->addWidget(myTitle);
00031
00032 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
00033
00034 setScheme(iisTaskPanelScheme::defaultScheme());
00035 myTitle->setSchemePointer(&myLabelScheme);
00036
00037
00038 if (myExpandable) {
00039 myButton = new QLabel(this);
00040 hbl->addWidget(myButton);
00041 myButton->installEventFilter(this);
00042 myButton->setFixedWidth(myScheme->headerButtonSize.width());
00043 changeIcons();
00044 }
00045 }
00046
00047 iisTaskHeader::~iisTaskHeader()
00048 {
00049
00050 }
00051
00052 bool iisTaskHeader::eventFilter(QObject *obj, QEvent *event)
00053 {
00054 switch (event->type()) {
00055 case QEvent::MouseButtonPress:
00056 fold();
00057 return true;
00058
00059 case QEvent::Enter:
00060 m_buttonOver = true;
00061 changeIcons();
00062 return true;
00063
00064 case QEvent::Leave:
00065 m_buttonOver = false;
00066 changeIcons();
00067 return true;
00068
00069 default:;
00070 }
00071
00072 return QFrame::eventFilter(obj, event);
00073 }
00074
00075 void iisTaskHeader::setScheme(iisTaskPanelScheme *scheme)
00076 {
00077 if (scheme) {
00078 myScheme = scheme;
00079 myLabelScheme = &(scheme->headerLabelScheme);
00080
00081 if (myExpandable) {
00082 setCursor(myLabelScheme->cursorOver ? Qt::PointingHandCursor : cursor());
00083 changeIcons();
00084 }
00085
00086 setFixedHeight(scheme->headerSize);
00087
00088 update();
00089 }
00090 }
00091
00092 void iisTaskHeader::paintEvent ( QPaintEvent * event )
00093 {
00094 QPainter p(this);
00095
00096 #if QT_VERSION >= 0x040203
00097 if (myScheme->headerAnimation)
00098 p.setOpacity(m_opacity+0.7);
00099 #endif
00100
00101 p.setPen(myScheme->headerBorder);
00102 p.setBrush(myScheme->headerBackground);
00103 if (myScheme->headerBorder.style() == Qt::NoPen)
00104 p.drawRect(rect());
00105 else
00106 p.drawRect(rect().adjusted(0,0,-1,-1));
00107 }
00108
00109 void iisTaskHeader::animate()
00110 {
00111 if (!myScheme->headerAnimation)
00112 return;
00113
00114 if (!isEnabled()) {
00115 m_opacity = 0.1;
00116 update();
00117 return;
00118 }
00119
00120 if (m_over) {
00121 if (m_opacity >= 0.3) {
00122 m_opacity = 0.3;
00123 return;
00124 }
00125 m_opacity += 0.05;
00126 } else {
00127 if (m_opacity <= 0.1) {
00128 m_opacity = 0.1;
00129 return;
00130 }
00131 m_opacity = qMax(0.1, m_opacity-0.05);
00132 }
00133
00134 QTimer::singleShot(100, this, SLOT(animate()));
00135 update();
00136 }
00137
00138 void iisTaskHeader::enterEvent ( QEvent * )
00139 {
00140 m_over = true;
00141
00142 if (isEnabled())
00143 QTimer::singleShot(100, this, SLOT(animate()));
00144
00145 update();
00146 }
00147
00148 void iisTaskHeader::leaveEvent ( QEvent * )
00149 {
00150 m_over = false;
00151
00152 if (isEnabled())
00153 QTimer::singleShot(100, this, SLOT(animate()));
00154
00155 update();
00156 }
00157
00158 void iisTaskHeader::fold()
00159 {
00160 if (myExpandable) {
00161 emit activated();
00162
00163 m_fold = !m_fold;
00164 changeIcons();
00165 }
00166 }
00167
00168 void iisTaskHeader::changeIcons()
00169 {
00170 if (!myButton)
00171 return;
00172
00173 if (m_buttonOver)
00174 {
00175 if (m_fold)
00176 myButton->setPixmap(myScheme->headerButtonFoldOver.pixmap(myScheme->headerButtonSize));
00177 else
00178 myButton->setPixmap(myScheme->headerButtonUnfoldOver.pixmap(myScheme->headerButtonSize));
00179 } else
00180 {
00181 if (m_fold)
00182 myButton->setPixmap(myScheme->headerButtonFold.pixmap(myScheme->headerButtonSize));
00183 else
00184 myButton->setPixmap(myScheme->headerButtonUnfold.pixmap(myScheme->headerButtonSize));
00185 }
00186 }
00187
00188 void iisTaskHeader::mouseReleaseEvent ( QMouseEvent * event )
00189 {
00190 if (event->button() == Qt::LeftButton) {
00191 emit activated();
00192 }
00193 }
00194