annotate ui/certificateitemdelegate.cpp @ 437:4b486a14252f

Acutally use the values that can be taken from the config
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 22 Apr 2014 11:07:14 +0000
parents 2e5499fae159
children d4bf4ceee99d
rev   line source
404
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 375
diff changeset
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 375
diff changeset
2 * Software engineering by Intevation GmbH
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 375
diff changeset
3 *
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 375
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 375
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 375
diff changeset
6 * See LICENSE.txt for details.
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 375
diff changeset
7 */
266
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
8 #include <QtWidgets>
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
9
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
10 #include "certificate.h"
372
6cc124e79066 Add save/load unselected and add role enumerator
Andre Heinecke <andre.heinecke@intevation.de>
parents: 266
diff changeset
11 #include "mainwindow.h"
266
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12 #include "certificateitemdelegate.h"
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14 void CertificateItemDelegate::paint(QPainter *painter,
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
15 const QStyleOptionViewItem &option, const QModelIndex &index) const
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
16 {
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
17 // Save the current painter.
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
18 painter->save();
375
9e38a4bcd44e Move certificateitem role into the certificateitemdelagate where it belongs.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 372
diff changeset
19 int status = index.data(StatusRole).toInt();
266
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20 if (status == 0) {
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
21 // This status is not known, so draw the default item.
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22 QStyledItemDelegate::paint(painter, option, index);
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23 painter->restore();
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
24 return;
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
25 }
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27 if (status == Certificate::InstallNew) {
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28 //Set the icon and use bold and bigger font to highlight this item.
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29 QIcon *icon = new QIcon(":/img/list-add.png");
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
30 QFont *font = new QFont();
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
31 font->setBold(true);
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32 font->setPointSize(font->pointSize() + 1);
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33 drawItem(painter, option, index, icon, font);
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34 }
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
35 else if (status == Certificate::InstallOld) {
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
36 // Set the icon and use the default font for this item.
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37 QIcon *icon = new QIcon(":/img/list-add.png");
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
38 QFont *font = new QFont();
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
39 drawItem(painter, option, index, icon, font);
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
40 }
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
41 else if (status == Certificate::RemoveNew) {
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42 //Set the icon and use bold and bigger font to highlight this item.
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
43 QIcon *icon = new QIcon(":/img/list-remove.png");
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44 QFont *font = new QFont();
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
45 font->setBold(true);
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
46 font->setPointSize(font->pointSize() + 1);
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
47 drawItem(painter, option, index, icon, font);
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
48 }
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
49 else if (status == Certificate::RemoveOld) {
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
50 // Set the icon and use the default font for this item.
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
51 QIcon *icon = new QIcon(":/img/list-remove.png");
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
52 QFont *font = new QFont();
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
53 drawItem(painter, option, index, icon, font);
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
54 }
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
55 else {
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
56 // Draw the default item.
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
57 QStyledItemDelegate::paint(painter, option, index);
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
58 }
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
59 // Restore the painter to have an unmodified painter for the next draw
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
60 // action.
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
61 painter->restore();
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
62 return;
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 }
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
65 void CertificateItemDelegate::drawItem(QPainter *painter,
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 const QStyleOptionViewItem &option, const QModelIndex &index,
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67 QIcon *icon, QFont *font) const
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68 {
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69 // Get temporary style option to draw a checkbox only.
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
70 QStyleOptionViewItem opt = option;
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71 // Initialize the style options with the temporary option object.
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
72 initStyleOption(&opt, index);
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
73 // Clear all text to draw the checkbox only.
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74 opt.text.clear();
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
76 // Draw highlighted background.
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
77 if (option.state & QStyle::State_Selected) {
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
78 painter->fillRect(option.rect, option.palette.highlight());
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
79 }
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
80
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
81 // Draw the checkbox control with the temporary options.
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
82 QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter);
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
83
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
84 // Draw the icon.
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
85 int iconSpace = 25;
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
86 if (!icon->isNull()) {
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
87 QRect rect = option.rect.adjusted(25, 0, 0, 0);
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
88 icon->paint(painter, rect, Qt::AlignVCenter|Qt::AlignLeft);
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
89 iconSpace = 50;
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
90 }
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
91
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
92 // Draw the text using the given font.
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
93 QString text = index.data().toString();
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
94 QRect rect = option.rect.adjusted(iconSpace, 0, 0, 0);
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
95 painter->setFont(*font);
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
96 painter->drawText(rect.left(), rect.top(), rect.width(), rect.height(),
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
97 Qt::AlignVCenter|Qt::AlignLeft, text, &rect);
dd6a09d2699f Added delegate for certificate list items to render a custom ui.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
98 }
433
2e5499fae159 Set sizeHint for certificate item delegates.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
99
2e5499fae159 Set sizeHint for certificate item delegates.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
100 QSize CertificateItemDelegate::sizeHint(const QStyleOptionViewItem &option,
2e5499fae159 Set sizeHint for certificate item delegates.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
101 const QModelIndex &index) const
2e5499fae159 Set sizeHint for certificate item delegates.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
102 {
2e5499fae159 Set sizeHint for certificate item delegates.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
103 int width = option.rect.width() - 50;
2e5499fae159 Set sizeHint for certificate item delegates.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
104 int height = 25;
2e5499fae159 Set sizeHint for certificate item delegates.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
105 return QSize(width, height);
2e5499fae159 Set sizeHint for certificate item delegates.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
106 }

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