Added include for QTimer in header file.
[easylist] / mycheckbox.cpp
1 #include "mycheckbox.h"\r
2 \r
3 int MyCheckBox::instances = 0;\r
4 \r
5 MyCheckBox::MyCheckBox(QWidget *parent) :\r
6     QCheckBox(parent)\r
7 {\r
8     ++instances;\r
9     qDebug() << "MyCheckBox instances:" << instances;\r
10     uncheckedColor = palette();\r
11     checkedColor.setColor(QPalette::WindowText, Qt::gray);\r
12 \r
13     setContextMenuPolicy(Qt::CustomContextMenu);\r
14     connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotContextMenuActivated(QPoint)));\r
15     connect(this, SIGNAL(toggled(bool)), this, SLOT(slotTriggered(bool)));\r
16 }\r
17 \r
18 MyCheckBox::MyCheckBox(const QString & text, QWidget *parent) :\r
19         QCheckBox(text, parent)\r
20 {\r
21     ++instances;\r
22     qDebug() << "MyCheckBox instances:" << instances;\r
23 \r
24     uncheckedColor = palette();\r
25     checkedColor.setColor(QPalette::WindowText, Qt::gray);\r
26 \r
27     setContextMenuPolicy(Qt::CustomContextMenu);\r
28     connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotContextMenuActivated(QPoint)));\r
29     connect(this, SIGNAL(toggled(bool)), this, SLOT(slotTriggered(bool)));\r
30 }\r
31 \r
32 MyCheckBox::~MyCheckBox()\r
33 {\r
34     --instances;\r
35     qDebug() << "MyCheckBox instances left:" << instances;\r
36 }\r
37 \r
38 void MyCheckBox::slotDeleteClicked()\r
39 {\r
40     qDebug() << "Delete clicked";\r
41     emit signalDeleteClicked(this);\r
42 }\r
43 \r
44 void MyCheckBox::slotContextMenuActivated(QPoint point)\r
45 {\r
46     qDebug() << "Context menu activated";\r
47     QMenu menu(this);\r
48     menu.addAction(tr("Delete"), this, SLOT(slotDeleteClicked()));\r
49     menu.exec(this->mapToGlobal(point));\r
50 }\r
51 \r
52 void MyCheckBox::slotTriggered(bool checked)\r
53 {\r
54     if(checked)\r
55     {\r
56         setPalette(checkedColor);\r
57     }\r
58     else\r
59     {\r
60         setPalette(uncheckedColor);\r
61     }\r
62     QFont f(font());\r
63     f.setStrikeOut(checked);\r
64     setFont(f);\r
65 }\r