-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathframelesswindow.h
72 lines (57 loc) · 1.82 KB
/
framelesswindow.h
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
70
71
72
#ifndef FRAMELESSWINDOW_H
#define FRAMELESSWINDOW_H
#include <QWidget>
#include <QPushButton>
#include <QLabel>
namespace h {
class FramelessWindowTitleBar : public QWidget
{
Q_OBJECT
public:
FramelessWindowTitleBar(QWidget *parent);
virtual void onWindowStateChanged(Qt::WindowState state) = 0;
virtual QWidget *maximizeButton() const = 0;
virtual void setTitle(const QString &title);
virtual void setIcon(const QIcon &icon);
protected:
void mousePressEvent(QMouseEvent *event) override;
void mouseDoubleClickEvent(QMouseEvent *event) override;
bool eventFilter(QObject *object, QEvent *event) override;
};
class FramelessWindowDefaultTitleBar : public FramelessWindowTitleBar
{
Q_OBJECT
public:
FramelessWindowDefaultTitleBar(QWidget *parent);
void onWindowStateChanged(Qt::WindowState state) override;
QWidget *maximizeButton() const override;
void setTitle(const QString &title) override;
void setIcon(const QIcon &icon) override;
private:
QLabel *m_iconLabel;
QLabel *m_titleLabel;
QPushButton *m_minimizeButton;
QPushButton *m_maximizeButton;
QPushButton *m_closeButton;
};
class FramelessWindow : public QWidget
{
Q_OBJECT
public:
FramelessWindow(QWidget *parent = nullptr);
~FramelessWindow();
void setTitleBarAndBodyWidget(FramelessWindowTitleBar *titleBar, QWidget *bodyWidget);
FramelessWindowTitleBar *titleBar() const;
protected:
bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override;
void changeEvent(QEvent *event) override;
// make title draggable
bool eventFilter(QObject *object, QEvent *event) override;
// config the window to be frameless
void configFrameless();
protected:
FramelessWindowTitleBar *m_titleBar;
QWidget *m_bodyWidget;
};
}
#endif // FRAMELESSWINDOW_H