Developer documentation | Axl-2.5.1

axlInspectorSwitch.cpp
Go to the documentation of this file.
1 /* axlInspectorSwitch.cpp ---
2  *
3  * Author: Julien Wintz
4  * Copyright (C) 2008 - Julien Wintz, Inria.
5  * Created: Fri Feb 4 17:35:45 2011 (+0100)
6  * Version: $Id$
7  * Last-Updated: Mon Mar 14 14:54:28 2011 (+0100)
8  * By: Julien Wintz
9  * Update #: 9
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
20 #include "axlInspectorSwitch.h"
21 
22 #include <QtGui/QPainter>
23 #include <QtGui/QPaintEvent>
24 
25 class axlInspectorSwitchPrivate
26 {
27 public:
28  QPixmap pixmap;
29 
30  bool toggled;
31 };
32 
33 axlInspectorSwitch::axlInspectorSwitch(QWidget *parent) : QWidget(parent), d(new axlInspectorSwitchPrivate)
34 {
35  d->pixmap = QPixmap(":dtkGuiSupport/pixmaps/axlInspectorSwitch-off.png");
36 
37  d->toggled = false;
38 
39  this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
40 }
41 
43 {
44  delete d;
45 
46  d = NULL;
47 }
48 
50 {
51  return d->pixmap.size();
52 }
53 
54 void axlInspectorSwitch::mousePressEvent(QMouseEvent *event)
55 {
56  d->toggled = !d->toggled;
57 
58  if(d->toggled)
59  d->pixmap = QPixmap(":dtkGuiSupport/pixmaps/axlInspectorSwitch-on.png");
60  else
61  d->pixmap = QPixmap(":dtkGuiSupport/pixmaps/axlInspectorSwitch-off.png");
62 
63  this->update();
64 
65  emit toggled(d->toggled);
66 }
67 
68 void axlInspectorSwitch::paintEvent(QPaintEvent *event)
69 {
70  QPainter painter(this);
71  painter.drawPixmap(event->rect(), d->pixmap);
72 }
void toggled(bool)
QSize sizeHint(void) const
void mousePressEvent(QMouseEvent *event)
void paintEvent(QPaintEvent *event)
axlInspectorSwitch(QWidget *parent=0)