]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphindockwidget.cpp
Update kconf update script version to 6
[dolphin.git] / src / dolphindockwidget.cpp
1 /*
2 * SPDX-FileCopyrightText: 2010 Peter Penz <peter.penz19@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #include "dolphindockwidget.h"
8
9 #include <QEvent>
10 #include <QStyle>
11
12 namespace
13 {
14 // Disable the 'Floatable' feature, i.e., the possibility to drag the
15 // dock widget out of the main window. This works around problems like
16 // https://bugs.kde.org/show_bug.cgi?id=288629
17 // https://bugs.kde.org/show_bug.cgi?id=322299
18 const QDockWidget::DockWidgetFeatures DefaultDockWidgetFeatures = QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable;
19 }
20
21 // Empty titlebar for the dock widgets when "Lock Layout" has been activated.
22 class DolphinDockTitleBar : public QWidget
23 {
24 Q_OBJECT
25
26 public:
27 explicit DolphinDockTitleBar(QWidget *parent = nullptr)
28 : QWidget(parent)
29 {
30 }
31 ~DolphinDockTitleBar() override
32 {
33 }
34
35 QSize minimumSizeHint() const override
36 {
37 return QSize(0, 0);
38 }
39
40 QSize sizeHint() const override
41 {
42 return minimumSizeHint();
43 }
44 };
45
46 DolphinDockWidget::DolphinDockWidget(const QString &title, QWidget *parent, Qt::WindowFlags flags)
47 : QDockWidget(title, parent, flags)
48 , m_locked(false)
49 , m_dockTitleBar(nullptr)
50 {
51 setFeatures(DefaultDockWidgetFeatures);
52 }
53
54 DolphinDockWidget::~DolphinDockWidget()
55 {
56 }
57
58 void DolphinDockWidget::setLocked(bool lock)
59 {
60 if (lock != m_locked) {
61 m_locked = lock;
62
63 if (lock) {
64 if (!m_dockTitleBar) {
65 m_dockTitleBar = new DolphinDockTitleBar(this);
66 }
67 setTitleBarWidget(m_dockTitleBar);
68 setFeatures(QDockWidget::DockWidgetClosable);
69 } else {
70 setTitleBarWidget(nullptr);
71 setFeatures(DefaultDockWidgetFeatures);
72 }
73 }
74 }
75
76 bool DolphinDockWidget::isLocked() const
77 {
78 return m_locked;
79 }
80
81 bool DolphinDockWidget::event(QEvent *event)
82 {
83 switch (event->type()) {
84 case QEvent::Show:
85 case QEvent::Hide:
86 if (event->spontaneous()) {
87 // The Dolphin window has been minimized or restored. We do not want this to be interpreted like a user was toggling the visibility of this widget.
88 // We return here so no QDockWidget::visibilityChanged() signal is emitted. This does not seem to happen either way on Wayland.
89 return true;
90 }
91 [[fallthrough]];
92 default:
93 return QDockWidget::event(event);
94 }
95 }
96
97 #include "dolphindockwidget.moc"
98 #include "moc_dolphindockwidget.cpp"