File indexing completed on 2024-04-21 16:30:12

0001 /*
0002  * SPDX-FileCopyrightText: 2010 Peter Penz <peter.penz19@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "dolphindockwidget.h"
0008 
0009 #include <QStyle>
0010 
0011 namespace
0012 {
0013 // Disable the 'Floatable' feature, i.e., the possibility to drag the
0014 // dock widget out of the main window. This works around problems like
0015 // https://bugs.kde.org/show_bug.cgi?id=288629
0016 // https://bugs.kde.org/show_bug.cgi?id=322299
0017 const QDockWidget::DockWidgetFeatures DefaultDockWidgetFeatures = QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable;
0018 }
0019 
0020 // Empty titlebar for the dock widgets when "Lock Layout" has been activated.
0021 class DolphinDockTitleBar : public QWidget
0022 {
0023     Q_OBJECT
0024 
0025 public:
0026     explicit DolphinDockTitleBar(QWidget *parent = nullptr)
0027         : QWidget(parent)
0028     {
0029     }
0030     ~DolphinDockTitleBar() override
0031     {
0032     }
0033 
0034     QSize minimumSizeHint() const override
0035     {
0036         return QSize(0, 0);
0037     }
0038 
0039     QSize sizeHint() const override
0040     {
0041         return minimumSizeHint();
0042     }
0043 };
0044 
0045 DolphinDockWidget::DolphinDockWidget(const QString &title, QWidget *parent, Qt::WindowFlags flags)
0046     : QDockWidget(title, parent, flags)
0047     , m_locked(false)
0048     , m_dockTitleBar(nullptr)
0049 {
0050     setFeatures(DefaultDockWidgetFeatures);
0051 }
0052 
0053 DolphinDockWidget::~DolphinDockWidget()
0054 {
0055 }
0056 
0057 void DolphinDockWidget::setLocked(bool lock)
0058 {
0059     if (lock != m_locked) {
0060         m_locked = lock;
0061 
0062         if (lock) {
0063             if (!m_dockTitleBar) {
0064                 m_dockTitleBar = new DolphinDockTitleBar(this);
0065             }
0066             setTitleBarWidget(m_dockTitleBar);
0067             setFeatures(QDockWidget::DockWidgetClosable);
0068         } else {
0069             setTitleBarWidget(nullptr);
0070             setFeatures(DefaultDockWidgetFeatures);
0071         }
0072     }
0073 }
0074 
0075 bool DolphinDockWidget::isLocked() const
0076 {
0077     return m_locked;
0078 }
0079 
0080 #include "dolphindockwidget.moc"
0081 #include "moc_dolphindockwidget.cpp"