annotate ui/textoverlaybutton.cpp @ 964:706405a2f3e8

(issue89) Add help icon to help button
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 28 Aug 2014 12:55:19 +0200
parents 57371f2e8dae
children 947a880ec5d3
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);
743
a467204a35f5 Rework User Interface.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 735
diff changeset
21 if (mOverlay == "0" || mOverlay.isEmpty()) {
734
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);
735
c92eb6298dd7 Activate antialiasing for the painter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 734
diff changeset
25 /* Only usable if opengl is used */
c92eb6298dd7 Activate antialiasing for the painter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 734
diff changeset
26 painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
c92eb6298dd7 Activate antialiasing for the painter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 734
diff changeset
27 /* Else */
c92eb6298dd7 Activate antialiasing for the painter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 734
diff changeset
28 painter.setRenderHint(QPainter::Antialiasing, true);
c92eb6298dd7 Activate antialiasing for the painter
Andre Heinecke <andre.heinecke@intevation.de>
parents: 734
diff changeset
29
731
0bb54205c55a (Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents: 722
diff changeset
30 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
31
731
0bb54205c55a (Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents: 722
diff changeset
32 // circle
932
57371f2e8dae (issue72) Set background image as pixmap in textoverlayicon
Andre Heinecke <andre.heinecke@intevation.de>
parents: 743
diff changeset
33 /* old manually painted background
731
0bb54205c55a (Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents: 722
diff changeset
34 QLinearGradient gradient(myRect.topLeft(),
0bb54205c55a (Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents: 722
diff changeset
35 myRect.bottomRight());
0bb54205c55a (Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents: 722
diff changeset
36 gradient.setColorAt(0, Qt::white);
0bb54205c55a (Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents: 722
diff changeset
37 gradient.setColorAt(0.7, Qt::red);
0bb54205c55a (Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents: 722
diff changeset
38 QBrush brush(gradient);
0bb54205c55a (Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents: 722
diff changeset
39 painter.setBrush(brush);
0bb54205c55a (Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents: 722
diff changeset
40 painter.setPen(Qt::white);
0bb54205c55a (Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents: 722
diff changeset
41 painter.drawEllipse(75.5, 6, 20, 20);
932
57371f2e8dae (issue72) Set background image as pixmap in textoverlayicon
Andre Heinecke <andre.heinecke@intevation.de>
parents: 743
diff changeset
42 */
57371f2e8dae (issue72) Set background image as pixmap in textoverlayicon
Andre Heinecke <andre.heinecke@intevation.de>
parents: 743
diff changeset
43 painter.drawPixmap(75.5, 5, mBackground);
731
0bb54205c55a (Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents: 722
diff changeset
44
0bb54205c55a (Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents: 722
diff changeset
45 // font
0bb54205c55a (Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents: 722
diff changeset
46 QFont font;
0bb54205c55a (Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents: 722
diff changeset
47 font.setPixelSize(11);
0bb54205c55a (Issue31) Improved number formatting and refresh icon.
Emanuel Schuetze <emanuel@intevation.de>
parents: 722
diff changeset
48 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
49 painter.setFont(font);
b0929968562a (Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
50 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
51
b0929968562a (Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
52 return;
b0929968562a (Issue31) Add textoverlaybutton to show a text in the button.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
53 }
932
57371f2e8dae (issue72) Set background image as pixmap in textoverlayicon
Andre Heinecke <andre.heinecke@intevation.de>
parents: 743
diff changeset
54
57371f2e8dae (issue72) Set background image as pixmap in textoverlayicon
Andre Heinecke <andre.heinecke@intevation.de>
parents: 743
diff changeset
55 void TextOverlayButton::setBackgroundIcon (const QString& iconPath) {
57371f2e8dae (issue72) Set background image as pixmap in textoverlayicon
Andre Heinecke <andre.heinecke@intevation.de>
parents: 743
diff changeset
56 mBackground = QIcon(iconPath).pixmap(QSize(22,22));
57371f2e8dae (issue72) Set background image as pixmap in textoverlayicon
Andre Heinecke <andre.heinecke@intevation.de>
parents: 743
diff changeset
57 }

http://wald.intevation.org/projects/trustbridge/