]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphindockwidget.cpp
Merge branch 'release/20.08'
[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 <QStyle>
10
11 namespace {
12 // Disable the 'Floatable' feature, i.e., the possibility to drag the
13 // dock widget out of the main window. This works around problems like
14 // https://bugs.kde.org/show_bug.cgi?id=288629
15 // https://bugs.kde.org/show_bug.cgi?id=322299
16 const QDockWidget::DockWidgetFeatures DefaultDockWidgetFeatures = QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable;
17 }
18
19 // Empty titlebar for the dock widgets when "Lock Layout" has been activated.
20 class DolphinDockTitleBar : public QWidget
21 {
22 Q_OBJECT
23
24 public:
25 explicit DolphinDockTitleBar(QWidget* parent = nullptr) : QWidget(parent) {}
26 ~DolphinDockTitleBar() override {}
27
28 QSize minimumSizeHint() const override
29 {
30 const int border = style()->pixelMetric(QStyle::PM_DockWidgetTitleBarButtonMargin);
31 return QSize(border, border);
32 }
33
34 QSize sizeHint() const override
35 {
36 return minimumSizeHint();
37 }
38 };
39
40 DolphinDockWidget::DolphinDockWidget(const QString& title, QWidget* parent, Qt::WindowFlags flags) :
41 QDockWidget(title, parent, flags),
42 m_locked(false),
43 m_dockTitleBar(nullptr)
44 {
45 setFeatures(DefaultDockWidgetFeatures);
46 }
47
48 DolphinDockWidget::~DolphinDockWidget()
49 {
50 }
51
52 void DolphinDockWidget::setLocked(bool lock)
53 {
54 if (lock != m_locked) {
55 m_locked = lock;
56
57 if (lock) {
58 if (!m_dockTitleBar) {
59 m_dockTitleBar = new DolphinDockTitleBar(this);
60 }
61 setTitleBarWidget(m_dockTitleBar);
62 setFeatures(QDockWidget::NoDockWidgetFeatures);
63 } else {
64 setTitleBarWidget(nullptr);
65 setFeatures(DefaultDockWidgetFeatures);
66 }
67 }
68 }
69
70 bool DolphinDockWidget::isLocked() const
71 {
72 return m_locked;
73 }
74
75 #include "dolphindockwidget.moc"