-
Notifications
You must be signed in to change notification settings - Fork 15
/
titlebar.cpp
66 lines (55 loc) · 1.58 KB
/
titlebar.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
56
57
58
59
60
61
62
63
64
65
66
#include "stdafx.h"
#include "titlebar.h"
#include "windows.h"
#include <QDebug>
TitleBar::TitleBar(QWidget* parent)
: QWidget(parent)
{
//resize(1360, 38);
setFixedHeight(TITLE_HEIGHT);
setAttribute(Qt::WA_StyledBackground);
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
QLabel* logoLabel = new QLabel(this);
logoLabel->setObjectName("logoLabel");
layout->addWidget(logoLabel);
layout->addStretch(1);
QToolButton* minToolButton = new QToolButton(this);
minToolButton->setObjectName("minToolButton");
connect(minToolButton, &QToolButton::clicked, this->window(), &QWidget::showMinimized);
layout->addWidget(minToolButton);
QToolButton* maxToolButton = new QToolButton(this);
maxToolButton->setObjectName("maxToolButton");
connect(maxToolButton, &QToolButton::clicked, this, &TitleBar::toggleMaxState);
maxToolButton->setProperty("MaxState", false);
layout->addWidget(maxToolButton);
QToolButton* closeToolButton = new QToolButton(this);
closeToolButton->setObjectName("closeToolButton");
connect(closeToolButton, &QToolButton::clicked, this->window(), &QWidget::close);
layout->addWidget(closeToolButton);
}
TitleBar::~TitleBar()
{
}
void TitleBar::mouseDoubleClickEvent(QMouseEvent* event)
{
toggleMaxState();
}
void TitleBar::mousePressEvent(QMouseEvent* event)
{
ReleaseCapture();
SendMessage((HWND)window()->winId(), WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
event->ignore();
}
void TitleBar::toggleMaxState()
{
if (window()->isMaximized())
{
window()->showNormal();
}
else
{
window()->showMaximized();
}
}