ddc312651d327555aca244d1f2d1fe0faa2561df
[toast/confclerk.git] / src / gui / tabwidget.cpp
1 #include "tabwidget.h"
2
3 #include <QMouseEvent>
4 #include <QPainter>
5 #include <QTabBar>
6
7 TabWidget::TabWidget(QWidget *aParent)
8     : QTabWidget(aParent)
9     , mPressPoint(0,0)
10 {
11     mInfoImage = QImage(":/icons/info.png");
12 }
13
14 void TabWidget::paintEvent(QPaintEvent *event)
15 {
16     Q_UNUSED(event);
17
18     int height = tabBar()->tabRect(currentIndex()).height();
19     QImage image = mInfoImage.scaled(QSize(height,height),Qt::KeepAspectRatioByExpanding,Qt::SmoothTransformation);
20     QPainter painter(this);
21     painter.drawImage(rect().topRight()-QPoint(image.width(),0),image);
22 }
23
24 void TabWidget::mousePressEvent(QMouseEvent *event)
25 {
26     mPressPoint = event->pos();
27 }
28
29 void TabWidget::mouseReleaseEvent(QMouseEvent *event)
30 {
31     int height = tabBar()->tabRect(currentIndex()).height();
32     QImage image = mInfoImage.scaled(QSize(height,height),Qt::KeepAspectRatioByExpanding,Qt::SmoothTransformation);
33     QPoint topLeft = rect().topRight()-QPoint(image.width(),0);
34     QRect infoRect = QRect(topLeft, topLeft+QPoint(image.width(),image.height()));
35     if( (infoRect.contains(event->pos())) && (infoRect.contains(mPressPoint)) )
36     {
37         emit(infoIconClicked());
38     }
39 }
40