]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphindockwidget.cpp
don't use temporaries when uneeded
[dolphin.git] / src / dolphindockwidget.cpp
1 /***************************************************************************
2 * Copyright (C) 2010 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #include "dolphindockwidget.h"
21
22 #include <QStyle>
23
24 namespace {
25 // Disable the 'Floatable' feature, i.e., the possibility to drag the
26 // dock widget out of the main window. This works around problems like
27 // https://bugs.kde.org/show_bug.cgi?id=288629
28 // https://bugs.kde.org/show_bug.cgi?id=322299
29 const QDockWidget::DockWidgetFeatures DefaultDockWidgetFeatures = QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable;
30 }
31
32 // Empty titlebar for the dock widgets when "Lock Layout" has been activated.
33 class DolphinDockTitleBar : public QWidget
34 {
35 Q_OBJECT
36
37 public:
38 explicit DolphinDockTitleBar(QWidget* parent = nullptr) : QWidget(parent) {}
39 ~DolphinDockTitleBar() override {}
40
41 QSize minimumSizeHint() const override
42 {
43 const int border = style()->pixelMetric(QStyle::PM_DockWidgetTitleBarButtonMargin);
44 return QSize(border, border);
45 }
46
47 QSize sizeHint() const override
48 {
49 return minimumSizeHint();
50 }
51 };
52
53 DolphinDockWidget::DolphinDockWidget(const QString& title, QWidget* parent, Qt::WindowFlags flags) :
54 QDockWidget(title, parent, flags),
55 m_locked(false),
56 m_dockTitleBar(nullptr)
57 {
58 setFeatures(DefaultDockWidgetFeatures);
59 }
60
61 DolphinDockWidget::~DolphinDockWidget()
62 {
63 }
64
65 void DolphinDockWidget::setLocked(bool lock)
66 {
67 if (lock != m_locked) {
68 m_locked = lock;
69
70 if (lock) {
71 if (!m_dockTitleBar) {
72 m_dockTitleBar = new DolphinDockTitleBar(this);
73 }
74 setTitleBarWidget(m_dockTitleBar);
75 setFeatures(QDockWidget::NoDockWidgetFeatures);
76 } else {
77 setTitleBarWidget(nullptr);
78 setFeatures(DefaultDockWidgetFeatures);
79 }
80 }
81 }
82
83 bool DolphinDockWidget::isLocked() const
84 {
85 return m_locked;
86 }
87
88 #include "dolphindockwidget.moc"