1
0
mirror of https://invent.kde.org/system/dolphin synced 2024-07-04 17:30:55 +00:00

Step one for having DolphinParts for the icons and details view, which can be used by Konqueror. TODO: currently dropping of items is deactivated, as I want to wait for Davids feedback whether the direction is ok.

svn path=/trunk/KDE/kdebase/apps/; revision=633703
This commit is contained in:
Peter Penz 2007-02-14 21:54:24 +00:00
parent 8134fd34d5
commit c91365ab8d
9 changed files with 313 additions and 105 deletions

View File

@ -14,6 +14,7 @@ set(dolphin_SRCS
bookmarkssidebarpage.cpp
detailsviewsettingspage.cpp
dolphinapplication.cpp
dolphincontroller.cpp
dolphinmainwindow.cpp
dolphinnewmenu.cpp
dolphinview.cpp

63
src/dolphincontroller.cpp Normal file
View File

@ -0,0 +1,63 @@
/***************************************************************************
* Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
* *
* 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 "dolphincontroller.h"
DolphinController::DolphinController(QObject* parent) :
QObject(parent)
{
}
DolphinController::~DolphinController()
{
}
void DolphinController::triggerContextMenuRequest(const QPoint& pos,
const QPoint& globalPos)
{
emit activated();
emit requestContextMenu(pos, globalPos);
}
void DolphinController::triggerActivation()
{
emit activated();
}
void DolphinController::indicateSortingChange(DolphinView::Sorting sorting)
{
emit sortingChanged(sorting);
}
void DolphinController::indicateSortOrderChange(Qt::SortOrder order)
{
emit sortOrderChanged(order);
}
void DolphinController::triggerItem(const QModelIndex& index)
{
emit itemTriggered(index);
}
void DolphinController::indicateSelectionChange()
{
emit selectionChanged();
}
#include "dolphincontroller.moc"

110
src/dolphincontroller.h Normal file
View File

@ -0,0 +1,110 @@
/***************************************************************************
* Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
* *
* 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 DOLPHINCONTROLLER_H
#define DOLPHINCONTROLLER_H
#include <dolphinview.h>
#include <kurl.h>
#include <QObject>
class KUrl;
class QModelIndex;
class QPoint;
/**
* @brief Allows to control Dolphin views and to react on state changes.
*
* One instance of a DolphinController can be assigned to a variable number of
* Dolphin views (DolphinIconsView, DolphinDetailsView) by passing it in
* the constructor:
*
* \code
* DolphinController* controller = new DolphinController(parent);
* DolphinDetailsView* detailsView = new DolphinDetailsView(parent, controller);
* DolphinIconsView* iconsView = new DolphinIconsView(parent, controller);
* \endcode
*
* The Dolphin view assures that the controller gets informed about selection changes,
* when an item should be triggered and a lot more. The controller emits the corresponding signals
* so that the receiver may react on those changes.
*/
class DolphinController : public QObject
{
Q_OBJECT
public:
explicit DolphinController(QObject* parent);
virtual ~DolphinController();
void setUrl(const KUrl& url) { m_url = url; }
const KUrl& url() const { return m_url; }
void triggerContextMenuRequest(const QPoint& pos,
const QPoint& globalPos);
void triggerActivation();
void indicateSortingChange(DolphinView::Sorting sorting);
void indicateSortOrderChange(Qt::SortOrder order);
public slots:
void triggerItem(const QModelIndex& index);
void indicateSelectionChange();
signals:
/**
* Is emitted if a context menu should be opened.
* @param pos Position relative to the view widget where the
* context menu should be opened. It is recommended
* to get the corresponding model index from
* this position.
* @param globalPos Global position where the context menu should
* be opened.
*/
void requestContextMenu(const QPoint& pos,
const QPoint& globalPos);
/**
* Is emitted if the view has been activated by e. g. a mouse click.
*/
void activated();
/** Is emitted if the sorting has been changed to \a sorting. */
void sortingChanged(DolphinView::Sorting sorting);
/** Is emitted if the sort order has been changed to \a sort order. */
void sortOrderChanged(Qt::SortOrder order);
/**
* Is emitted if the item with the index \a index should be triggered.
* Usually triggering on a directory opens the directory, triggering
* on a file opens the corresponding application.
*/
void itemTriggered(const QModelIndex& index);
/** Is emitted if the selection has been changed by the user. */
void selectionChanged();
private:
KUrl m_url;
};
#endif

View File

@ -20,27 +20,26 @@
#include "dolphindetailsview.h"
#include "dolphinmainwindow.h"
#include "dolphincontroller.h"
#include "dolphinsortfilterproxymodel.h"
#include "dolphinview.h"
#include "viewproperties.h"
#include <assert.h>
#include <kdirmodel.h>
#include <QHeaderView>
DolphinDetailsView::DolphinDetailsView(DolphinView* parent) :
DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* controller) :
QTreeView(parent),
m_dolphinView(parent)
m_controller(controller)
{
assert(parent != 0);
assert(controller != 0);
setAcceptDrops(true);
setRootIsDecorated(false);
setSortingEnabled(true);
setUniformRowHeights(true);
const ViewProperties props(parent->url());
const ViewProperties props(controller->url());
setSortIndicatorSection(props.sorting());
setSortIndicatorOrder(props.sortOrder());
@ -51,6 +50,9 @@ DolphinDetailsView::DolphinDetailsView(DolphinView* parent) :
this, SLOT(setSortIndicatorSection(DolphinView::Sorting)));
connect(parent, SIGNAL(sortOrderChanged(Qt::SortOrder)),
this, SLOT(setSortIndicatorOrder(Qt::SortOrder)));
connect(this, SIGNAL(clicked(const QModelIndex&)),
controller, SLOT(triggerItem(const QModelIndex&)));
}
DolphinDetailsView::~DolphinDetailsView()
@ -89,21 +91,14 @@ QStyleOptionViewItem DolphinDetailsView::viewOptions() const
void DolphinDetailsView::contextMenuEvent(QContextMenuEvent* event)
{
QTreeView::contextMenuEvent(event);
KFileItem* item = 0;
const QModelIndex index = indexAt(event->pos());
if (index.isValid()) {
item = m_dolphinView->fileItem(index);
}
m_dolphinView->openContextMenu(item, event->globalPos());
m_controller->triggerContextMenuRequest(event->pos(),
event->globalPos());
}
void DolphinDetailsView::mouseReleaseEvent(QMouseEvent* event)
{
QTreeView::mouseReleaseEvent(event);
m_dolphinView->declareViewActive();
m_controller->triggerActivation();
}
void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
@ -115,15 +110,18 @@ void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
void DolphinDetailsView::dropEvent(QDropEvent* event)
{
const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
QTreeView::dropEvent(event);
// TODO: temporary deactivated until DolphinController will support this
/*const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
if (!urls.isEmpty()) {
event->acceptProposedAction();
// TODO: handle dropping above a directory
const KUrl& destination = m_dolphinView->url();
m_dolphinView->mainWindow()->dropUrls(urls, destination);
}
const KUrl& destination = m_controller->url();
m_controller->emitDropUrlsSignal(urls, destination);
}*/
}
void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting)
@ -141,23 +139,11 @@ void DolphinDetailsView::setSortIndicatorOrder(Qt::SortOrder sortOrder)
void DolphinDetailsView::synchronizeSortingState(int column)
{
// The sorting has already been changed in QTreeView if this slot is
// invoked, but Dolphin was not informed about this. This is bypassed by changing
// the sorting and sort order to a temporary other value and readjust it again.
// invoked, but Dolphin is not informed about this.
DolphinView::Sorting sorting = DolphinSortFilterProxyModel::sortingForColumn(column);
const Qt::SortOrder sortOrder = header()->sortIndicatorOrder();
// temporary adjust the sorting and sort order to different values...
const DolphinView::Sorting tempSorting = (sorting == DolphinView::SortByName) ?
DolphinView::SortBySize :
DolphinView::SortByName;
m_dolphinView->setSorting(tempSorting);
const Qt::SortOrder tempSortOrder = (sortOrder == Qt::Ascending) ?
Qt::Descending : Qt::Ascending;
m_dolphinView->setSortOrder(tempSortOrder);
// ... so that setting them again results in storing the new setting.
m_dolphinView->setSorting(sorting);
m_dolphinView->setSortOrder(sortOrder);
m_controller->indicateSortingChange(sorting);
m_controller->indicateSortOrderChange(sortOrder);
}
#include "dolphindetailsview.moc"

View File

@ -24,6 +24,8 @@
#include <dolphinview.h>
#include <QTreeView>
class DolphinController;
/**
* @brief Represents the details view which shows the name, size,
* date, permissions, owner and group of an item.
@ -37,7 +39,7 @@ class DolphinDetailsView : public QTreeView
Q_OBJECT
public:
explicit DolphinDetailsView(DolphinView* parent);
explicit DolphinDetailsView(QWidget* parent, DolphinController* controller);
virtual ~DolphinDetailsView();
protected:
@ -69,7 +71,7 @@ private slots:
void synchronizeSortingState(int column);
private:
DolphinView* m_dolphinView;
DolphinController* m_controller;
};
#endif

View File

@ -1,6 +1,5 @@
/***************************************************************************
* Copyright (C) 2006 by Peter Penz *
* peter.penz@gmx.at *
* Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
* *
* 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 *
@ -19,8 +18,8 @@
***************************************************************************/
#include "dolphiniconsview.h"
#include "dolphinmainwindow.h"
#include "dolphinview.h"
#include "dolphincontroller.h"
#include <assert.h>
#include <kdirmodel.h>
@ -28,11 +27,20 @@
#include <QAbstractProxyModel>
DolphinIconsView::DolphinIconsView(DolphinView* parent) :
DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) :
QListView(parent),
m_dolphinView(parent)
m_controller(controller)
{
assert(controller != 0);
setResizeMode(QListView::Adjust);
// TODO: read out settings
setViewMode(QListView::IconMode);
setSpacing(32);
connect(this, SIGNAL(clicked(const QModelIndex&)),
controller, SLOT(triggerItem(const QModelIndex&)));
}
DolphinIconsView::~DolphinIconsView()
@ -57,21 +65,14 @@ QStyleOptionViewItem DolphinIconsView::viewOptions() const
void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event)
{
QListView::contextMenuEvent(event);
KFileItem* item = 0;
const QModelIndex index = indexAt(event->pos());
if (index.isValid()) {
item = m_dolphinView->fileItem(index);
}
m_dolphinView->openContextMenu(item, event->globalPos());
m_controller->triggerContextMenuRequest(event->pos(),
event->globalPos());
}
void DolphinIconsView::mouseReleaseEvent(QMouseEvent* event)
{
QListView::mouseReleaseEvent(event);
m_dolphinView->declareViewActive();
m_controller->triggerActivation();
}
void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
@ -83,7 +84,10 @@ void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
void DolphinIconsView::dropEvent(QDropEvent* event)
{
KFileItem* directory = 0;
QListView::dropEvent(event);
// TODO: temporary deactivated until DolphinController will support this
/* KFileItem* directory = 0;
bool dropIntoDirectory = false;
const QModelIndex index = indexAt(event->pos());
if (index.isValid()) {
@ -104,7 +108,7 @@ void DolphinIconsView::dropEvent(QDropEvent* event)
const KUrl& destination = (directory == 0) ? m_dolphinView->url() :
directory->url();
m_dolphinView->mainWindow()->dropUrls(urls, destination);
}
}*/
}
#include "dolphiniconsview.moc"

View File

@ -1,6 +1,5 @@
/***************************************************************************
* Copyright (C) 2006 by Peter Penz *
* peter.penz@gmx.at *
* Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
* *
* 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 *
@ -23,6 +22,7 @@
#include <QListView>
class DolphinController;
class DolphinView;
/**
@ -30,15 +30,13 @@ class DolphinView;
*
* It is also possible that instead of the icon a preview of the item
* content is shown.
*
* @author Peter Penz
*/
class DolphinIconsView : public QListView
{
Q_OBJECT
public:
explicit DolphinIconsView(DolphinView* parent);
explicit DolphinIconsView(QWidget* parent, DolphinController* controller);
virtual ~DolphinIconsView();
protected:
@ -49,7 +47,7 @@ protected:
virtual void dropEvent(QDropEvent* event);
private:
DolphinView* m_dolphinView;
DolphinController* m_controller;
};
#endif

View File

@ -37,6 +37,7 @@
#include <konq_operations.h>
#include <kurl.h>
#include "dolphincontroller.h"
#include "dolphinstatusbar.h"
#include "dolphinmainwindow.h"
#include "dolphindirlister.h"
@ -63,6 +64,7 @@ DolphinView::DolphinView(DolphinMainWindow* mainWindow,
m_mainWindow(mainWindow),
m_topLayout(0),
m_urlNavigator(0),
m_controller(0),
m_iconsView(0),
m_detailsView(0),
m_filterBar(0),
@ -109,6 +111,20 @@ DolphinView::DolphinView(DolphinMainWindow* mainWindow,
m_proxyModel = new DolphinSortFilterProxyModel(this);
m_proxyModel->setSourceModel(m_dirModel);
m_controller = new DolphinController(this);
connect(m_controller, SIGNAL(requestContextMenu(const QPoint&, const QPoint&)),
this, SLOT(openContextMenu(const QPoint&, const QPoint&)));
connect(m_controller, SIGNAL(sortingChanged(DolphinView::Sorting)),
this, SLOT(updateSorting(DolphinView::Sorting)));
connect(m_controller, SIGNAL(sortOrderChanged(Qt::SortOrder)),
this, SLOT(updateSortOrder(Qt::SortOrder)));
connect(m_controller, SIGNAL(itemTriggered(const QModelIndex&)),
this, SLOT(triggerItem(const QModelIndex&)));
connect(m_controller, SIGNAL(selectionChanged()),
this, SLOT(emitSelectionChangedSignal()));
connect(m_controller, SIGNAL(activated()),
this, SLOT(requestActivation()));
createView();
m_iconSize = K3Icon::SizeMedium;
@ -137,6 +153,7 @@ DolphinView::~DolphinView()
void DolphinView::setUrl(const KUrl& url)
{
m_urlNavigator->setUrl(url);
m_controller->setUrl(url);
}
const KUrl& DolphinView::url() const
@ -144,11 +161,6 @@ const KUrl& DolphinView::url() const
return m_urlNavigator->url();
}
void DolphinView::requestActivation()
{
mainWindow()->setActiveView(this);
}
bool DolphinView::isActive() const
{
return (mainWindow()->activeView() == this);
@ -371,12 +383,7 @@ bool DolphinView::isZoomOutPossible() const
void DolphinView::setSorting(Sorting sorting)
{
if (sorting != this->sorting()) {
ViewProperties props(url());
props.setSorting(sorting);
m_proxyModel->setSorting(sorting);
emit sortingChanged(sorting);
updateSorting(sorting);
}
}
@ -388,12 +395,7 @@ DolphinView::Sorting DolphinView::sorting() const
void DolphinView::setSortOrder(Qt::SortOrder order)
{
if (sortOrder() != order) {
ViewProperties props(url());
props.setSortOrder(order);
m_proxyModel->setSortOrder(order);
emit sortOrderChanged(order);
updateSortOrder(order);
}
}
@ -484,12 +486,6 @@ KFileItem* DolphinView::fileItem(const QModelIndex index) const
return m_dirModel->itemForIndex(dirModelIndex);
}
void DolphinView::openContextMenu(KFileItem* fileInfo, const QPoint& pos)
{
DolphinContextMenu contextMenu(this, fileInfo, pos);
contextMenu.open();
}
void DolphinView::rename(const KUrl& source, const QString& newName)
{
bool ok = false;
@ -829,6 +825,11 @@ void DolphinView::updateStatusBar()
}
}
void DolphinView::requestActivation()
{
m_mainWindow->setActiveView(this);
}
void DolphinView::changeNameFilter(const QString& nameFilter)
{
// The name filter of KDirLister does a 'hard' filtering, which
@ -854,6 +855,39 @@ void DolphinView::changeNameFilter(const QString& nameFilter)
#endif
}
void DolphinView::openContextMenu(const QPoint& pos, const QPoint& globalPos)
{
KFileItem* item = 0;
const QModelIndex index = itemView()->indexAt(pos);
if (index.isValid()) {
item = fileItem(index);
}
DolphinContextMenu contextMenu(this, item, globalPos);
contextMenu.open();
}
void DolphinView::updateSorting(DolphinView::Sorting sorting)
{
ViewProperties props(url());
props.setSorting(sorting);
m_proxyModel->setSorting(sorting);
emit sortingChanged(sorting);
}
void DolphinView::updateSortOrder(Qt::SortOrder order)
{
ViewProperties props(url());
props.setSortOrder(order);
m_proxyModel->setSortOrder(order);
emit sortOrderChanged(order);
}
void DolphinView::createView()
{
// delete current view
@ -872,22 +906,17 @@ void DolphinView::createView()
// ... and recreate it representing the current mode
switch (m_mode) {
case IconsView:
m_iconsView = new DolphinIconsView(this);
m_iconsView->setViewMode(QListView::IconMode);
m_iconsView->setSpacing(32);
m_iconsView = new DolphinIconsView(this, m_controller);
view = m_iconsView;
// TODO: read out view settings
break;
case DetailsView:
m_detailsView = new DolphinDetailsView(this);
m_detailsView = new DolphinDetailsView(this, m_controller);
view = m_detailsView;
// TODO: read out view settings
break;
}
view->setModel(m_proxyModel);
view->setSelectionMode(QAbstractItemView::ExtendedSelection);
KFileItemDelegate* delegate = new KFileItemDelegate(this);
@ -895,13 +924,10 @@ void DolphinView::createView()
view->setItemDelegate(delegate);
new KMimeTypeResolver(view, m_dirModel);
connect(view, SIGNAL(clicked(const QModelIndex&)),
this, SLOT(triggerItem(const QModelIndex&)));
connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
this, SLOT(emitSelectionChangedSignal()));
m_topLayout->insertWidget(1, view);
connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
m_controller, SLOT(indicateSelectionChange()));
}
int DolphinView::columnIndex(Sorting sorting) const

View File

@ -36,6 +36,7 @@
#include <QVBoxLayout>
#include <QWidget>
class DolphinController;
class FilterBar;
class KUrl;
class KDirModel;
@ -120,7 +121,10 @@ public:
/** Returns the current active URL. */
const KUrl& url() const;
void requestActivation();
/**
* Returns true if the view is active and hence all actions are
* applied to this view.
*/
bool isActive() const;
/**
@ -237,13 +241,6 @@ public:
*/
KFileItem* fileItem(const QModelIndex index) const;
/**
* Opens the context menu for the item indicated by \a fileInfo
* on the position \a pos. If 0 is passed for the file info, a context
* menu for the viewport is opened.
*/
void openContextMenu(KFileItem* fileInfo, const QPoint& pos);
/**
* Renames the filename of the source URL by the new file name.
* If the new file name already exists, a dialog is opened which
@ -348,6 +345,12 @@ public slots:
*/
void updateStatusBar();
/**
* Requests the main window to set this view as active view, which
* means that all actions are applied to this view.
*/
void requestActivation();
signals:
/** Is emitted if URL of the view has been changed to \a url. */
void urlChanged(const KUrl& url);
@ -427,6 +430,20 @@ private slots:
*/
void changeNameFilter(const QString& nameFilter);
void openContextMenu(const QPoint& pos, const QPoint& globalPos);
/**
* Updates the view properties of the current URL to the
* sorting given by \a sorting.
*/
void updateSorting(DolphinView::Sorting sorting);
/**
* Updates the view properties of the current URL to the
* sort order given by \a order.
*/
void updateSortOrder(Qt::SortOrder order);
private:
void startDirLister(const KUrl& url, bool reload = false);
@ -477,6 +494,7 @@ private:
QVBoxLayout* m_topLayout;
UrlNavigator* m_urlNavigator;
DolphinController* m_controller;
DolphinIconsView* m_iconsView;
DolphinDetailsView* m_detailsView;