-
Notifications
You must be signed in to change notification settings - Fork 0
/
creatorwindow.cpp
executable file
·53 lines (40 loc) · 1.56 KB
/
creatorwindow.cpp
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
#include "creatorwindow.h"
#include "windowfactory.h"
#include <QFocusFrame>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QSpacerItem>
CreatorWindow::CreatorWindow(QWidget *parent)
: QFrame(parent) {
setFocusPolicy(Qt::ClickFocus);
auto *hLayout = new QHBoxLayout(this);
hLayout->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
auto *vLayout = new QVBoxLayout();
vLayout->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding));
auto types = WindowFactory::Instance()->availableWindowTypes();
for (auto &type : types) {
auto *btn = new QPushButton(type, this);
vLayout->addWidget(btn);
connect(btn, &QPushButton::clicked, this, [ btn, this ]() {
auto clickedTypeName = btn->text();
emit clickedWindowType(clickedTypeName);
});
}
vLayout->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding));
hLayout->addLayout(vLayout);
hLayout->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
setLayout(hLayout);
m_cachedStyle = styleSheet();
setObjectName("CreatorWindow");
}
CreatorWindow::~CreatorWindow() = default;
void CreatorWindow::focusInEvent(QFocusEvent *event) {
// highlight current window
setStyleSheet("#CreatorWindow{border:1px solid blue}");
QWidget::focusInEvent(event);
}
void CreatorWindow::focusOutEvent(QFocusEvent *event) {
setStyleSheet(m_cachedStyle);
QWidget::focusOutEvent(event);
}