diff options
| author | David Faure <[email protected]> | 2007-10-10 23:01:35 +0000 |
|---|---|---|
| committer | David Faure <[email protected]> | 2007-10-10 23:01:35 +0000 |
| commit | 8d4fb3608927960d9e45e672ce1cbe1fa3a548f9 (patch) | |
| tree | fe8691ccdb83ece1bcfc6b9beabf218b5d7607c5 /src/dolphinpart.cpp | |
| parent | 3b8c3c1b1e2d05d09aca2de0b0bf922fb9530b0d (diff) | |
DolphinPart: provide a way to switch between view modes in konqueror.
Factorized those actions between dolphinmainwindow and dolphinpart (see new methods in dolphinview), and simplified mainwindow code by using the signal from the action group and the QVariant data of the actions (standard Qt4 solution for a group of actions).
svn path=/trunk/KDE/kdebase/apps/; revision=723871
Diffstat (limited to 'src/dolphinpart.cpp')
| -rw-r--r-- | src/dolphinpart.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index 092d2e14a..31cde2931 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -18,6 +18,9 @@ */ #include "dolphinpart.h" +#include <kactioncollection.h> +#include <ktoggleaction.h> +#include <QActionGroup> #include "dolphinsortfilterproxymodel.h" #include "dolphinview.h" #include "dolphinmodel.h" @@ -67,6 +70,8 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi m_proxyModel); setWidget(m_view); + setXMLFile("dolphinpart.rc"); + connect(m_view, SIGNAL(infoMessage(QString)), this, SLOT(slotInfoMessage(QString))); connect(m_view, SIGNAL(errorMessage(QString)), @@ -81,7 +86,11 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QStringLi connect(m_view, SIGNAL(requestItemInfo(KFileItem)), this, SLOT(slotRequestItemInfo(KFileItem))); - // TODO provide a way to switch from iconview to listview (and others) + createActions(); + updateViewActions(); + + // TODO provide these actions in the menu, merged with the existing view-mode-actions somehow + // [Q_PROPERTY introspection?] // TODO connect to urlsDropped @@ -102,6 +111,24 @@ DolphinPart::~DolphinPart() delete m_dirLister; } +void DolphinPart::createActions() +{ + QActionGroup* viewModeActions = new QActionGroup(this); + viewModeActions->addAction(DolphinView::iconsModeAction(actionCollection())); + viewModeActions->addAction(DolphinView::detailsModeAction(actionCollection())); + viewModeActions->addAction(DolphinView::columnsModeAction(actionCollection())); + connect(viewModeActions, SIGNAL(triggered(QAction*)), this, SLOT(slotViewModeActionTriggered(QAction*))); +} + +void DolphinPart::updateViewActions() +{ + QAction* action = actionCollection()->action(m_view->currentViewModeActionName()); + if (action != 0) { + KToggleAction* toggleAction = static_cast<KToggleAction*>(action); + toggleAction->setChecked(true); + } +} + KAboutData* DolphinPart::createAboutData() { return new KAboutData("dolphinpart", 0, ki18nc("@title", "Dolphin Part"), "0.1"); @@ -191,4 +218,10 @@ void DolphinPart::slotOpenContextMenu(const KFileItem& _item, const KUrl&) emit m_extension->popupMenu( QCursor::pos(), items, KParts::OpenUrlArguments(), KParts::BrowserArguments(), popupFlags ); } +void DolphinPart::slotViewModeActionTriggered(QAction* action) +{ + const DolphinView::Mode mode = action->data().value<DolphinView::Mode>(); + m_view->setMode(mode); +} + #include "dolphinpart.moc" |
