bookmarkssidebarpage.cpp
detailsviewsettingspage.cpp
dolphinapplication.cpp
+ dolphincontroller.cpp
dolphinmainwindow.cpp
dolphinnewmenu.cpp
dolphinview.cpp
--- /dev/null
+/***************************************************************************
+ * 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"
--- /dev/null
+/***************************************************************************
+ * 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
#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());
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()
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)
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)
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"
#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.
Q_OBJECT
public:
- explicit DolphinDetailsView(DolphinView* parent);
+ explicit DolphinDetailsView(QWidget* parent, DolphinController* controller);
virtual ~DolphinDetailsView();
protected:
void synchronizeSortingState(int column);
private:
- DolphinView* m_dolphinView;
+ DolphinController* m_controller;
};
#endif
/***************************************************************************
- * 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 *
***************************************************************************/
#include "dolphiniconsview.h"
-#include "dolphinmainwindow.h"
-#include "dolphinview.h"
+
+#include "dolphincontroller.h"
#include <assert.h>
#include <kdirmodel.h>
#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()
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)
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()) {
const KUrl& destination = (directory == 0) ? m_dolphinView->url() :
directory->url();
m_dolphinView->mainWindow()->dropUrls(urls, destination);
- }
+ }*/
}
#include "dolphiniconsview.moc"
/***************************************************************************
- * 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 *
#include <QListView>
+class DolphinController;
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:
virtual void dropEvent(QDropEvent* event);
private:
- DolphinView* m_dolphinView;
+ DolphinController* m_controller;
};
#endif
#include <konq_operations.h>
#include <kurl.h>
+#include "dolphincontroller.h"
#include "dolphinstatusbar.h"
#include "dolphinmainwindow.h"
#include "dolphindirlister.h"
m_mainWindow(mainWindow),
m_topLayout(0),
m_urlNavigator(0),
+ m_controller(0),
m_iconsView(0),
m_detailsView(0),
m_filterBar(0),
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;
void DolphinView::setUrl(const KUrl& url)
{
m_urlNavigator->setUrl(url);
+ m_controller->setUrl(url);
}
const KUrl& DolphinView::url() const
return m_urlNavigator->url();
}
-void DolphinView::requestActivation()
-{
- mainWindow()->setActiveView(this);
-}
-
bool DolphinView::isActive() const
{
return (mainWindow()->activeView() == this);
void DolphinView::setSorting(Sorting sorting)
{
if (sorting != this->sorting()) {
- ViewProperties props(url());
- props.setSorting(sorting);
-
- m_proxyModel->setSorting(sorting);
-
- emit sortingChanged(sorting);
+ updateSorting(sorting);
}
}
void DolphinView::setSortOrder(Qt::SortOrder order)
{
if (sortOrder() != order) {
- ViewProperties props(url());
- props.setSortOrder(order);
-
- m_proxyModel->setSortOrder(order);
-
- emit sortOrderChanged(order);
+ updateSortOrder(order);
}
}
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;
}
}
+void DolphinView::requestActivation()
+{
+ m_mainWindow->setActiveView(this);
+}
+
void DolphinView::changeNameFilter(const QString& nameFilter)
{
// The name filter of KDirLister does a 'hard' filtering, which
#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
// ... 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);
view->setItemDelegate(delegate);
new KMimeTypeResolver(view, m_dirModel);
+ m_topLayout->insertWidget(1, view);
- 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);
+ m_controller, SLOT(indicateSelectionChange()));
}
int DolphinView::columnIndex(Sorting sorting) const
#include <QVBoxLayout>
#include <QWidget>
+class DolphinController;
class FilterBar;
class KUrl;
class KDirModel;
/** 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;
/**
*/
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
*/
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);
*/
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);
QVBoxLayout* m_topLayout;
UrlNavigator* m_urlNavigator;
+ DolphinController* m_controller;
DolphinIconsView* m_iconsView;
DolphinDetailsView* m_detailsView;