set(dolphin_SRCS
dolphinapplication.cpp
+ dolphindockwidget.cpp
dolphinmainwindow.cpp
dolphinnewfilemenu.cpp
dolphinviewcontainer.cpp
--- /dev/null
+/***************************************************************************
+ * 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"
--- /dev/null
+/***************************************************************************
+ * 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
#include <config-nepomuk.h>
#include "dolphinapplication.h"
+#include "dolphindockwidget.h"
#include "dolphincontextmenu.h"
#include "dolphinnewfilemenu.h"
#include "dolphinviewcontainer.h"
#include <kconfig.h>
#include <kdesktopfile.h>
#include <kdeversion.h>
+#include <kdualaction.h>
#include <kfiledialog.h>
#include <kfileplacesmodel.h>
#include <kglobal.h>
#include <QKeyEvent>
#include <QClipboard>
#include <QSplitter>
-#include <QDockWidget>
#include <kacceleratormanager.h>
/*
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();
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);
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();
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()));
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);
#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);
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);
#ifdef HAVE_NEPOMUK
panelsMenu->addAction(filterAction);
#endif
+ panelsMenu->addSeparator();
+ panelsMenu->addAction(lockLayoutAction);
}
void DolphinMainWindow::updateEditActions()
*/
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();
#include <kfileitem.h>
#include <kio/jobclasses.h>
#include <kio/job.h>
+#include <kmenu.h>
#include <QPushButton>
#include <QShowEvent>
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;
/** @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);
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();
void InformationPanel::contextMenuEvent(QContextMenuEvent* event)
{
- m_content->configureSettings();
+ // TODO: Move code from InformationPanelContent::configureSettings() here
+ m_content->configureSettings(customContextMenuActions());
Panel::contextMenuEvent(event);
}
return QWidget::eventFilter(obj, event);
}
-void InformationPanelContent::configureSettings()
+void InformationPanelContent::configureSettings(const QList<QAction*>& customContextMenuActions)
{
KMenu popup(this);
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());
/**
* 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 );
Panel::Panel(QWidget* parent) :
QWidget(parent),
- m_url(KUrl())
+ m_url(),
+ m_customContextMenuActions()
{
}
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)) {
/**
* @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
{
/** 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
private:
KUrl m_url;
+ QList<QAction*> m_customContextMenuActions;
};
#endif // PANEL_H
<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>