-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynamicwindow.cpp
executable file
·55 lines (41 loc) · 1.31 KB
/
dynamicwindow.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
54
55
#include "dynamicwindow.h"
#include "renamedialog.h"
DynamicWindow::DynamicWindow(QWidget *parent)
: QFrame(parent) {
m_toolBar = new QToolBar(this);
m_toolBar->setVisible(false);
setFocusPolicy(Qt::ClickFocus);
m_nameAction = m_toolBar->addAction("&" + name(), this, &DynamicWindow::renameWindow);
connect(this, &DynamicWindow::nameChanged, this,
[ this ](const QString &name) { m_nameAction->setText("&" + name); });
m_cachedStyle = styleSheet();
setObjectName("DynamicWindow");
}
DynamicWindow::~DynamicWindow() = default;
void DynamicWindow::closeWindow() {}
QString DynamicWindow::name() const {
return m_name;
}
void DynamicWindow::setName(const QString &name) {
m_name = name;
emit nameChanged(name);
}
QToolBar *DynamicWindow::toolBar() const {
return m_toolBar;
}
void DynamicWindow::focusInEvent(QFocusEvent *event) {
// highlight current window
setStyleSheet("#DynamicWindow{border:1px solid blue}");
QWidget::focusInEvent(event);
}
void DynamicWindow::focusOutEvent(QFocusEvent *event) {
setStyleSheet(m_cachedStyle);
QWidget::focusOutEvent(event);
}
void DynamicWindow::renameWindow() {
auto windowName = RenameDialog::getName(tr("Edit name..."), this);
if (windowName.isEmpty()) {
return;
}
setName(windowName);
}