]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphindockwidget.cpp
Merge remote-tracking branch 'origin/KDE/4.12' into KDE/4.13
[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 public:
36 DolphinDockTitleBar(QWidget* parent = 0) : QWidget(parent) {}
37 virtual ~DolphinDockTitleBar() {}
38
39 virtual QSize minimumSizeHint() const
40 {
41 const int border = style()->pixelMetric(QStyle::PM_DockWidgetTitleBarButtonMargin);
42 return QSize(border, border);
43 }
44
45 virtual QSize sizeHint() const
46 {
47 return minimumSizeHint();
48 }
49 };
50
51 DolphinDockWidget::DolphinDockWidget(const QString& title, QWidget* parent, Qt::WindowFlags flags) :
52 QDockWidget(title, parent, flags),
53 m_locked(false),
54 m_dockTitleBar(0)
55 {
56 setFeatures(DefaultDockWidgetFeatures);
57 }
58
59 DolphinDockWidget::DolphinDockWidget(QWidget* parent, Qt::WindowFlags flags) :
60 QDockWidget(parent, flags),
61 m_locked(false),
62 m_dockTitleBar(0)
63 {
64 setFeatures(DefaultDockWidgetFeatures);
65 }
66
67 DolphinDockWidget::~DolphinDockWidget()
68 {
69 }
70
71 void DolphinDockWidget::setLocked(bool lock)
72 {
73 if (lock != m_locked) {
74 m_locked = lock;
75
76 if (lock) {
77 if (!m_dockTitleBar) {
78 m_dockTitleBar = new DolphinDockTitleBar(this);
79 }
80 setTitleBarWidget(m_dockTitleBar);
81 setFeatures(QDockWidget::NoDockWidgetFeatures);
82 } else {
83 setTitleBarWidget(0);
84 setFeatures(DefaultDockWidgetFeatures);
85 }
86 }
87 }
88
89 bool DolphinDockWidget::isLocked() const
90 {
91 return m_locked;
92 }
93
94 #include "dolphindockwidget.moc"