1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#include "helpwindow.h"
#include <QPushButton>
#include <QGridLayout>
#include <QAction>
#include <QLabel>
#include <QDebug>
#include <QApplication>
#include <QScreen>
#define ICON_SIZE (50)
#define ICON_SIZE_SMALL (32)
HelpWindow::HelpWindow(const QList<QAction*> &actions, QWidget *parent) :
QDialog(parent)
{
setWindowTitle(tr("Help"));
int iconSize = ICON_SIZE;
for (auto screen : qApp->screens()) {
if (screen->geometry().height() < 900) {
iconSize = ICON_SIZE_SMALL;
break;
}
}
QGridLayout *layout = new QGridLayout(this);
layout->setSpacing(2);
QSizePolicy sizePol(QSizePolicy::Minimum, QSizePolicy::Preferred);
QList<QLabel*> wrapLabels;
// Add help items
int row = 0;
for (QAction *action : actions) {
if (action->icon().isNull() || action->text().isEmpty())
continue;
QLabel *icon = new QLabel(this);
icon->setPixmap(action->icon().pixmap(iconSize, iconSize, QIcon::Normal, QIcon::Off));
icon->setMinimumSize(iconSize + 5, iconSize + 2);
layout->addWidget(icon, row, 0, 3, 1, Qt::AlignTop | Qt::AlignLeft);
QLabel *headline = new QLabel(action->toolTip(), this);
QFont boldFont = headline->font();
boldFont.setBold(true);
headline->setFont(boldFont);
headline->setAlignment(Qt::AlignTop | Qt::AlignLeft);
layout->addWidget(headline, row, 1, Qt::AlignTop);
QLabel *description = new QLabel(action->text(), this);
description->setWordWrap(true);
description->setAlignment(Qt::AlignTop | Qt::AlignLeft);
description->setSizePolicy(sizePol);
wrapLabels.append(description);
layout->addWidget(description, row + 1, 1, Qt::AlignTop);
layout->setRowStretch(row + 2, 1);
QFrame *line = new QFrame();
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
layout->addWidget(line, row + 3, 0, 1, 2);
row += 4;
}
layout->setColumnStretch(1, 1);
// Add close button
layout->setRowStretch(row++, 1000);
QPushButton *close = new QPushButton(tr("Close"), this);
QFont bigFont = close->font();
bigFont.setPointSize(20);
close->setFont(bigFont);
close->setDefault(true);
connect(close, SIGNAL(clicked()), this, SLOT(hide()));
layout->addWidget(close, row++, 0, 1, 2);
this->setFixedWidth(600);
this->setSizePolicy(sizePol);
}
|