]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Lock panels per default and allow to unlock them like in Amarok.
authorPeter Penz <peter.penz19@gmail.com>
Fri, 31 Dec 2010 10:59:46 +0000 (10:59 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Fri, 31 Dec 2010 10:59:46 +0000 (10:59 +0000)
BUG: 229811
FIXED-IN: 4.7.0

svn path=/trunk/KDE/kdebase/apps/; revision=1210424

14 files changed:
src/CMakeLists.txt
src/dolphindockwidget.cpp [new file with mode: 0644]
src/dolphindockwidget.h [new file with mode: 0644]
src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/panels/filter/filterpanel.cpp
src/panels/filter/filterpanel.h
src/panels/folders/treeviewcontextmenu.cpp
src/panels/information/informationpanel.cpp
src/panels/information/informationpanelcontent.cpp
src/panels/information/informationpanelcontent.h
src/panels/panel.cpp
src/panels/panel.h
src/settings/dolphin_generalsettings.kcfg

index 4d442bbcde9dc6c1ac4f41aadd5aab04d02ef3ce..a8bcce2529d95938ee40a551613ad142c10b9182 100644 (file)
@@ -96,6 +96,7 @@ install(FILES views/versioncontrol/fileviewversioncontrolplugin.desktop DESTINAT
 
 set(dolphin_SRCS
     dolphinapplication.cpp
+    dolphindockwidget.cpp
     dolphinmainwindow.cpp
     dolphinnewfilemenu.cpp
     dolphinviewcontainer.cpp
diff --git a/src/dolphindockwidget.cpp b/src/dolphindockwidget.cpp
new file mode 100644 (file)
index 0000000..f7ee16f
--- /dev/null
@@ -0,0 +1,82 @@
+/***************************************************************************
+ *   Copyright (C) 2010 by Peter Penz <peter.penz19@gmail.com>             *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+
+#include "dolphindockwidget.h"
+
+#include <QStyle>
+
+ // Empty titlebar for the dock widgets when "Lock Layout" has been activated.
+class DolphinDockTitleBar : public QWidget
+{
+public:
+    DolphinDockTitleBar(QWidget* parent = 0) : QWidget(parent) {}
+    virtual ~DolphinDockTitleBar() {}
+
+    virtual QSize minimumSizeHint() const
+    {
+        const int border = style()->pixelMetric(QStyle::PM_DockWidgetTitleBarButtonMargin);
+        return QSize(border, border);
+    }
+
+    virtual QSize sizeHint() const
+    {
+        return minimumSizeHint();
+    }
+};
+
+DolphinDockWidget::DolphinDockWidget(const QString& title, QWidget* parent, Qt::WindowFlags flags) :
+    QDockWidget(title, parent, flags),
+    m_locked(false),
+    m_dockTitleBar(0)
+{
+}
+
+DolphinDockWidget::DolphinDockWidget(QWidget* parent, Qt::WindowFlags flags) :
+    QDockWidget(parent, flags),
+    m_locked(false),
+    m_dockTitleBar(0)
+{
+}
+
+DolphinDockWidget::~DolphinDockWidget()
+{
+}
+
+void DolphinDockWidget::setLocked(bool lock)
+{
+    if (lock != m_locked) {
+        m_locked = lock;
+
+        if (lock) {
+            if (m_dockTitleBar == 0) {
+                m_dockTitleBar = new DolphinDockTitleBar(this);
+            }
+            setTitleBarWidget(m_dockTitleBar);
+        } else {
+            setTitleBarWidget(0);
+        }
+    }
+}
+
+bool DolphinDockWidget::isLocked() const
+{
+    return m_locked;
+}
+
+#include "dolphindockwidget.moc"
diff --git a/src/dolphindockwidget.h b/src/dolphindockwidget.h
new file mode 100644 (file)
index 0000000..8f110c6
--- /dev/null
@@ -0,0 +1,50 @@
+/***************************************************************************
+ *   Copyright (C) 2010 by Peter Penz <peter.penz19@gmail.com>             *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+
+
+#ifndef DOLPHIN_DOCK_WIDGET_H
+#define DOLPHIN_DOCK_WIDGET_H
+
+#include <QDockWidget>
+
+/**
+ * @brief Extends QDockWidget to be able to get locked.
+ */
+class DolphinDockWidget : public QDockWidget
+{
+    Q_OBJECT
+
+public:
+    DolphinDockWidget(const QString& title, QWidget* parent = 0, Qt::WindowFlags flags = 0);
+    DolphinDockWidget(QWidget* parent = 0, Qt::WindowFlags flags = 0);
+    virtual ~DolphinDockWidget();
+
+    /**
+     * @param lock If \a lock is true, the title bar of the dock-widget will get hidden so
+     *             that it is not possible for the user anymore to move or undock the dock-widget.
+     */
+    void setLocked(bool lock);
+    bool isLocked() const;
+
+private:
+    bool m_locked;
+    QWidget* m_dockTitleBar;
+};
+
+#endif
index 46b28cada484aa22f3806d9207237277eb77aaf4..64f26387f84ac11c53a9a2564dff7d65c46e7c76 100644 (file)
@@ -24,6 +24,7 @@
 #include <config-nepomuk.h>
 
 #include "dolphinapplication.h"
+#include "dolphindockwidget.h"
 #include "dolphincontextmenu.h"
 #include "dolphinnewfilemenu.h"
 #include "dolphinviewcontainer.h"
@@ -56,6 +57,7 @@
 #include <kconfig.h>
 #include <kdesktopfile.h>
 #include <kdeversion.h>
+#include <kdualaction.h>
 #include <kfiledialog.h>
 #include <kfileplacesmodel.h>
 #include <kglobal.h>
@@ -89,7 +91,6 @@
 #include <QKeyEvent>
 #include <QClipboard>
 #include <QSplitter>
-#include <QDockWidget>
 #include <kacceleratormanager.h>
 
 /*
@@ -866,6 +867,21 @@ void DolphinMainWindow::replaceLocation()
     lineEdit->setSelection(0, text.length());
 }
 
+void DolphinMainWindow::togglePanelLockState()
+{
+    GeneralSettings* generalSettings = DolphinSettings::instance().generalSettings();
+
+    const bool newLockState = !generalSettings->lockPanels();
+    foreach (QObject* child, children()) {
+        DolphinDockWidget* dock = qobject_cast<DolphinDockWidget*>(child);
+        if (dock != 0) {
+            dock->setLocked(newLockState);
+        }
+    }
+
+    generalSettings->setLockPanels(newLockState);
+}
+
 void DolphinMainWindow::goBack()
 {
     clearStatusBar();
@@ -1580,11 +1596,23 @@ void DolphinMainWindow::setupActions()
 
 void DolphinMainWindow::setupDockWidgets()
 {
-    // setup "Information"
-    QDockWidget* infoDock = new QDockWidget(i18nc("@title:window", "Information"));
+    const bool lock = DolphinSettings::instance().generalSettings()->lockPanels();
+
+    KDualAction* lockLayoutAction = actionCollection()->add<KDualAction>("lock_panels");
+    lockLayoutAction->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
+    lockLayoutAction->setActiveIcon(KIcon("object-unlocked"));
+    lockLayoutAction->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
+    lockLayoutAction->setInactiveIcon(KIcon("object-locked"));
+    lockLayoutAction->setActive(lock);
+    connect(lockLayoutAction, SIGNAL(triggered()), this, SLOT(togglePanelLockState()));
+
+    // Setup "Information"
+    DolphinDockWidget* infoDock = new DolphinDockWidget(i18nc("@title:window", "Information"));
+    infoDock->setLocked(lock);
     infoDock->setObjectName("infoDock");
     infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
     Panel* infoPanel = new InformationPanel(infoDock);
+    infoPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
     connect(infoPanel, SIGNAL(urlActivated(KUrl)), this, SLOT(handleUrl(KUrl)));
     infoDock->setWidget(infoPanel);
 
@@ -1601,11 +1629,13 @@ void DolphinMainWindow::setupDockWidgets()
     connect(this, SIGNAL(requestItemInfo(KFileItem)),
             infoPanel, SLOT(requestDelayedItemInfo(KFileItem)));
 
-    // setup "Folders"
-    QDockWidget* foldersDock = new QDockWidget(i18nc("@title:window", "Folders"));
+    // Setup "Folders"
+    DolphinDockWidget* foldersDock = new DolphinDockWidget(i18nc("@title:window", "Folders"));
+    foldersDock->setLocked(lock);
     foldersDock->setObjectName("foldersDock");
     foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
     FoldersPanel* foldersPanel = new FoldersPanel(foldersDock);
+    foldersPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
     foldersDock->setWidget(foldersPanel);
 
     QAction* foldersAction = foldersDock->toggleViewAction();
@@ -1619,12 +1649,14 @@ void DolphinMainWindow::setupDockWidgets()
     connect(foldersPanel, SIGNAL(changeUrl(KUrl, Qt::MouseButtons)),
             this, SLOT(handlePlacesClick(KUrl, Qt::MouseButtons)));
 
-    // setup "Terminal"
+    // Setup "Terminal"
 #ifndef Q_OS_WIN
-    QDockWidget* terminalDock = new QDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
+    DolphinDockWidget* terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
+    terminalDock->setLocked(lock);
     terminalDock->setObjectName("terminalDock");
     terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
     Panel* terminalPanel = new TerminalPanel(terminalDock);
+    terminalPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
     terminalDock->setWidget(terminalPanel);
 
     connect(terminalPanel, SIGNAL(hideTerminalPanel()), terminalDock, SLOT(hide()));
@@ -1639,12 +1671,14 @@ void DolphinMainWindow::setupDockWidgets()
             terminalPanel, SLOT(setUrl(KUrl)));
 #endif
 
-    // setup "Filter"
+    // Setup "Filter"
 #ifdef HAVE_NEPOMUK
-    QDockWidget* filterDock = new QDockWidget(i18nc("@title:window", "Filter"));
+    DolphinDockWidget* filterDock = new DolphinDockWidget(i18nc("@title:window", "Filter"));
+    filterDock->setLocked(lock);
     filterDock->setObjectName("filterDock");
     filterDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
     Panel* filterPanel = new FilterPanel(filterDock);
+    filterPanel->setCustomContextMenuActions(QList<QAction*>() << lockLayoutAction);
     connect(filterPanel, SIGNAL(urlActivated(KUrl)), this, SLOT(handleUrl(KUrl)));
     filterDock->setWidget(filterPanel);
 
@@ -1669,15 +1703,17 @@ void DolphinMainWindow::setupDockWidgets()
 #endif
     }
 
-    // setup "Places"
-    QDockWidget* placesDock = new QDockWidget(i18nc("@title:window", "Places"));
+    // Setup "Places"
+    DolphinDockWidget* placesDock = new DolphinDockWidget(i18nc("@title:window", "Places"));
+    placesDock->setLocked(lock);
     placesDock->setObjectName("placesDock");
     placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
 
     PlacesPanel* placesPanel = new PlacesPanel(placesDock);
-    placesDock->setWidget(placesPanel);
     placesPanel->setModel(DolphinSettings::instance().placesModel());
     placesPanel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    connect(placesPanel, SIGNAL(lockChangeRequested(bool)), this, SLOT(slotPanelLockChangeRequested(bool)));
+    placesDock->setWidget(placesPanel);
 
     QAction* placesAction = placesDock->toggleViewAction();
     placesAction->setShortcut(Qt::Key_F9);
@@ -1690,6 +1726,7 @@ void DolphinMainWindow::setupDockWidgets()
     connect(this, SIGNAL(urlChanged(KUrl)),
             placesPanel, SLOT(setUrl(KUrl)));
 
+    // Add actions into the "Panels" menu
     KActionMenu* panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
     actionCollection()->addAction("panels", panelsMenu);
     panelsMenu->setDelayed(false);
@@ -1702,6 +1739,8 @@ void DolphinMainWindow::setupDockWidgets()
 #ifdef HAVE_NEPOMUK
     panelsMenu->addAction(filterAction);
 #endif
+    panelsMenu->addSeparator();
+    panelsMenu->addAction(lockLayoutAction);
 }
 
 void DolphinMainWindow::updateEditActions()
index 9a57b545238613aaffc08b6d98b75f5f52a9821a..4d45d2d65a78cf1b6005c72d0ce4ce7261fa071c 100644 (file)
@@ -264,6 +264,11 @@ private slots:
      */
     void replaceLocation();
 
+    /**
+     * Toggles the state of the panels between a locked and unlocked layout.
+     */
+    void togglePanelLockState();
+
     /** Goes back on step of the URL history. */
     void goBack();
 
index 021a2d3b8ec19b5360c702fb104789e63be5dac2..d13d6e5207e7ecac87f48131770d231b9bcd0b2c 100644 (file)
@@ -39,6 +39,7 @@
 #include <kfileitem.h>
 #include <kio/jobclasses.h>
 #include <kio/job.h>
+#include <kmenu.h>
 
 #include <QPushButton>
 #include <QShowEvent>
@@ -140,6 +141,18 @@ void FilterPanel::showEvent(QShowEvent* event)
     Panel::showEvent(event);
 }
 
+void FilterPanel::contextMenuEvent(QContextMenuEvent* event)
+{
+    Panel::contextMenuEvent(event);
+
+    QWeakPointer<KMenu> popup = new KMenu(this);
+    foreach (QAction* action, customContextMenuActions()) {
+        popup.data()->addAction(action);
+    }
+    popup.data()->exec(QCursor::pos());
+    delete popup.data();
+}
+
 void FilterPanel::slotSetUrlStatFinished(KJob* job)
 {
     m_lastSetUrlStatJob = 0;
index c574d618e8f96e125550502a9afa0cf1b9311a4e..574a9f389e275329c42899386febb500e5132183 100644 (file)
@@ -52,6 +52,9 @@ protected:
     /** @see QWidget::showEvent() */
     virtual void showEvent(QShowEvent* event);
 
+    /** @see QWidget::contextMenuEvent() */
+    virtual void contextMenuEvent(QContextMenuEvent* event);
+
 private slots:
     void slotSetUrlStatFinished(KJob*);
     void slotQueryTermChanged(const Nepomuk::Query::Term& term);
index de93e096c1d5b59eea2258987b61185b67ba8bd3..5c9151df0603055ffe2578f822b6b200036d805d 100644 (file)
@@ -128,6 +128,10 @@ void TreeViewContextMenu::open()
     popup->addAction(autoScrollingAction);
     connect(autoScrollingAction, SIGNAL(toggled(bool)), this, SLOT(setAutoScrolling(bool)));
 
+    popup->addSeparator();
+    foreach (QAction* action, m_parent->customContextMenuActions()) {
+        popup->addAction(action);
+    }
 
     popup->exec(QCursor::pos());
     popup->deleteLater();
index 0fd67b2b6ee03fd40c8e22616ef00f12031d6627..6681dc30dbf6998b8f6283c6b87efb92a7e3939d 100644 (file)
@@ -167,7 +167,8 @@ void InformationPanel::resizeEvent(QResizeEvent* event)
 
 void InformationPanel::contextMenuEvent(QContextMenuEvent* event)
 {
-    m_content->configureSettings();
+    // TODO: Move code from InformationPanelContent::configureSettings() here
+    m_content->configureSettings(customContextMenuActions());
     Panel::contextMenuEvent(event);
 }
 
index 371bdaf9699b47a106a575bfd2d82dde670c6898..f8a72fb70401177bdbe9441af4f174fbbc10e2c6 100644 (file)
@@ -265,7 +265,7 @@ bool InformationPanelContent::eventFilter(QObject* obj, QEvent* event)
     return QWidget::eventFilter(obj, event);
 }
 
-void InformationPanelContent::configureSettings()
+void InformationPanelContent::configureSettings(const QList<QAction*>& customContextMenuActions)
 {
     KMenu popup(this);
 
@@ -277,6 +277,11 @@ void InformationPanelContent::configureSettings()
     QAction* configureAction = popup.addAction(i18nc("@action:inmenu", "Configure..."));
     configureAction->setIcon(KIcon("configure"));
 
+    popup.addSeparator();
+    foreach (QAction* action, customContextMenuActions) {
+        popup.addAction(action);
+    }
+
     // Open the popup and adjust the settings for the
     // selected action.
     QAction* action = popup.exec(QCursor::pos());
index f918b8582a8233ec54ad1f72c5d4809fd37bd612..c41f4043f17192258b21d0bf36721fb5f414b5fb 100644 (file)
@@ -61,8 +61,10 @@ public:
     /**
      * Opens a menu which allows to configure which meta information
      * should be shown.
+     *
+     * TODO: Move this code to the class InformationPanel
      */
-    void configureSettings();
+    void configureSettings(const QList<QAction*>& customContextMenuActions);
 
 signals:
     void urlActivated( const KUrl& url );
index 6d11422d8a6cbea1a1dc45cd29f46abc2408d0ed..e90970c6ee2c05666195cb1721e7de0961cdcdae 100644 (file)
@@ -23,7 +23,8 @@
 
 Panel::Panel(QWidget* parent) :
     QWidget(parent),
-    m_url(KUrl())
+    m_url(),
+    m_customContextMenuActions()
 {
 }
 
@@ -36,6 +37,16 @@ KUrl Panel::url() const
     return m_url;
 }
 
+void Panel::setCustomContextMenuActions(const QList<QAction*>& actions)
+{
+    m_customContextMenuActions = actions;
+}
+
+QList<QAction*> Panel::customContextMenuActions() const
+{
+    return m_customContextMenuActions;
+}
+
 void Panel::setUrl(const KUrl& url)
 {
     if (url.equals(m_url, KUrl::CompareWithoutTrailingSlash)) {
index 11558e2defc5fa1d70a38004ba9032322f47c7ff..83ed3da3bb5b4677dead079fd04720ce627cd45f 100644 (file)
@@ -27,6 +27,9 @@
 
 /**
  * @brief Base widget for all panels that can be docked on the window borders.
+ *
+ * Derived panels should provide a context menu that at least offers the
+ * actions from Panel::customContextMenuActions().
  */
 class Panel : public QWidget
 {
@@ -39,6 +42,14 @@ public:
     /** Returns the current set URL of the active Dolphin view. */
     KUrl url() const;
 
+    /**
+     * Sets custom context menu actions that are added to the panel specific
+     * context menu actions. Allows an application to apply custom actions to
+     * the panel.
+     */
+    void setCustomContextMenuActions(const QList<QAction*>& actions);
+    QList<QAction*> customContextMenuActions() const;
+
 public slots:
     /**
      * This is invoked every time the folder being displayed in the
@@ -58,6 +69,7 @@ protected:
 
 private:
     KUrl m_url;
+    QList<QAction*> m_customContextMenuActions;
 };
 
 #endif // PANEL_H
index b80b904422db54904496d2fb9227d36c510e511b..ee219d953064f11d3fe38fb8c710cbf87c1fa38e 100644 (file)
@@ -83,5 +83,9 @@
             <label>Show the space information in the statusbar</label>
             <default>false</default>
         </entry>
+        <entry name="LockPanels" type="Bool">
+            <label>Lock the layout of the panels</label>
+            <default>true</default>
+        </entry>
     </group>
 </kcfg>