Mercurial > trustbridge
annotate ui/textoverlaybutton.cpp @ 734:f6796ff72b65
Only show overlay if it is not "0"
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Thu, 03 Jul 2014 16:28:35 +0200 |
parents | 0bb54205c55a |
children | c92eb6298dd7 |
rev | line source |
---|---|
722
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
2 * Software engineering by Intevation GmbH |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
3 * |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
4 * This file is Free Software under the GNU GPL (v>=2) |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
6 * See LICENSE.txt for details. |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
7 */ |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
8 |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
9 #include <QPaintEvent> |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
10 #include <QPainter> |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
11 #include <QFont> |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
12 #include <QApplication> |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
13 |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
14 #include <QDebug> |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
15 |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
16 #include "textoverlaybutton.h" |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
17 |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
18 void TextOverlayButton::paintEvent(QPaintEvent *e) |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
19 { |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
20 QToolButton::paintEvent(e); |
734
f6796ff72b65
Only show overlay if it is not "0"
Andre Heinecke <andre.heinecke@intevation.de>
parents:
731
diff
changeset
|
21 if (mOverlay == "0") { |
f6796ff72b65
Only show overlay if it is not "0"
Andre Heinecke <andre.heinecke@intevation.de>
parents:
731
diff
changeset
|
22 return; |
f6796ff72b65
Only show overlay if it is not "0"
Andre Heinecke <andre.heinecke@intevation.de>
parents:
731
diff
changeset
|
23 } |
722
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
24 QPainter painter(this); |
731
0bb54205c55a
(Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents:
722
diff
changeset
|
25 QRect myRect = e->rect().translated(26, -29); |
722
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
26 |
731
0bb54205c55a
(Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents:
722
diff
changeset
|
27 // circle |
0bb54205c55a
(Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents:
722
diff
changeset
|
28 QLinearGradient gradient(myRect.topLeft(), |
0bb54205c55a
(Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents:
722
diff
changeset
|
29 myRect.bottomRight()); |
0bb54205c55a
(Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents:
722
diff
changeset
|
30 gradient.setColorAt(0, Qt::white); |
0bb54205c55a
(Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents:
722
diff
changeset
|
31 gradient.setColorAt(0.7, Qt::red); |
0bb54205c55a
(Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents:
722
diff
changeset
|
32 QBrush brush(gradient); |
0bb54205c55a
(Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents:
722
diff
changeset
|
33 painter.setBrush(brush); |
0bb54205c55a
(Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents:
722
diff
changeset
|
34 painter.setPen(Qt::white); |
0bb54205c55a
(Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents:
722
diff
changeset
|
35 painter.drawEllipse(75.5, 6, 20, 20); |
0bb54205c55a
(Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents:
722
diff
changeset
|
36 |
0bb54205c55a
(Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents:
722
diff
changeset
|
37 // font |
0bb54205c55a
(Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents:
722
diff
changeset
|
38 QFont font; |
0bb54205c55a
(Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents:
722
diff
changeset
|
39 font.setPixelSize(11); |
0bb54205c55a
(Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents:
722
diff
changeset
|
40 font.setWeight(QFont::Bold); |
722
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
41 painter.setFont(font); |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
42 painter.drawText(myRect, Qt::AlignCenter | Qt::AlignVCenter, mOverlay); |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
43 |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
44 return; |
b0929968562a
(Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
45 } |