-
Notifications
You must be signed in to change notification settings - Fork 0
/
basecentraldock.cpp
99 lines (84 loc) · 2.47 KB
/
basecentraldock.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "basecentraldock.h"
#include "centralwindow.h"
#include "projectCore/projectsmanager.h"
#include "projectCore/baseprojectcontroller.h"
#include <QContextMenuEvent>
BaseCentralDock::BaseCentralDock(const QString& title,
QMainWindow* parent ,
Qt::WindowFlags flags)
: QDockWidget(title, parent, flags), _flags(flags)
{
setObjectName(title);
setWindowTitle(title);
//Delete this object after closing the widget
setAttribute(Qt::WA_DeleteOnClose);
//Callback to open a widget in the form of a window
connect(this, SIGNAL(topLevelChanged(bool)), this, SLOT(onTopLevelChanged(bool)));
_menu = new QMenu(objectName(), this);
QAction *a = toggleViewAction();
a->setText(tr("Enabled"));
_menu->addAction(a);
}
QMenu *BaseCentralDock::getMenu()
{
return _menu;
}
Qt::DockWidgetArea BaseCentralDock::getDefaultArea() const
{
return Qt::TopDockWidgetArea;
}
//---public slots---
//---private slots
void BaseCentralDock::closeWidgetSlot(bool)
{
//Close this widget if exit button are pressed
close();
}
void BaseCentralDock::onTopLevelChanged(bool)
{
if(isFloating())
{
//Hide titlebar if it is available
if(titleBarWidget())
setTitleBarWidget(nullptr);
//Set flags for open as window
setWindowFlags(Qt::CustomizeWindowHint |
Qt::Window | Qt::WindowMinimizeButtonHint |
Qt::WindowMaximizeButtonHint |
Qt::WindowCloseButtonHint);
setMinimumSize(400, 400);
show();
}
else
{
//Recover flags
setWindowFlags(_flags);
//Return titlebar
if(_titleWidget){
setTitleBarWidget(_titleWidget);
titleBarWidget()->show();
}
}
}
//---Events---
void BaseCentralDock::closeEvent(QCloseEvent*)
{
//Remove this widget from parent window
CentralWindow* window = qobject_cast<CentralWindow*>(parent());
window->removeDockWidget(this);
projectsManager.getOpenedProject()->deleteCentralDock(this);
}
void BaseCentralDock::changeEvent(QEvent *event)
{
if(event->type() == QEvent::Type::WindowStateChange && isMinimized())
{
event->ignore();
setWindowState(Qt::WindowState::WindowNoState);
setFloating(!isFloating());
}
}
void BaseCentralDock::contextMenuEvent(QContextMenuEvent *event)
{
event->accept();
_menu->exec(event->globalPos());
}