Split the class DolphinController into the two classes DolphinViewController and ViewModeController.

The ViewModeController offers a defined interface to control view mode implementations like icons view, details view and column view. The DolphinViewController allows those view mode implementations to control the parent DolphinView in a limited way.

svn path=/trunk/KDE/kdebase/apps/; revision=1109228
This commit is contained in:
Peter Penz 2010-03-30 20:19:32 +00:00
parent 25ffe18e65
commit 47d3113922
20 changed files with 583 additions and 459 deletions

View file

@ -16,7 +16,6 @@ endif (Nepomuk_FOUND)
########### next target ###############
set(dolphinprivate_LIB_SRCS
dolphincontroller.cpp
dolphindetailsview.cpp
dolphiniconsview.cpp
dolphincolumnview.cpp
@ -30,6 +29,7 @@ set(dolphinprivate_LIB_SRCS
dolphinview.cpp
dolphinviewactionhandler.cpp
dolphinviewautoscroller.cpp
dolphinviewcontroller.cpp
dolphinremoteencoding.cpp
dolphindetailsviewexpander.cpp
draganddrophelper.cpp
@ -49,6 +49,7 @@ set(dolphinprivate_LIB_SRCS
versioncontrol/updateitemstatesthread.cpp
versioncontrol/versioncontrolobserver.cpp
viewextensionsfactory.cpp
viewmodecontroller.cpp
viewproperties.cpp
zoomlevelinfo.cpp
)

View file

@ -21,7 +21,7 @@
#include "dolphinmodel.h"
#include "dolphincolumnviewcontainer.h"
#include "dolphincontroller.h"
#include "dolphinviewcontroller.h"
#include "dolphindirlister.h"
#include "dolphinsortfilterproxymodel.h"
#include "settings/dolphinsettings.h"
@ -32,6 +32,7 @@
#include "folderexpander.h"
#include "tooltips/tooltipmanager.h"
#include "viewextensionsfactory.h"
#include "viewmodecontroller.h"
#include "zoomlevelinfo.h"
#include <kcolorscheme.h>
@ -92,11 +93,11 @@ DolphinColumnView::DolphinColumnView(QWidget* parent,
}
connect(this, SIGNAL(viewportEntered()),
m_container->m_controller, SLOT(emitViewportEntered()));
m_container->m_dolphinViewController, SLOT(emitViewportEntered()));
connect(this, SIGNAL(entered(const QModelIndex&)),
this, SLOT(slotEntered(const QModelIndex&)));
const DolphinView* dolphinView = m_container->m_controller->dolphinView();
const DolphinView* dolphinView = m_container->m_dolphinViewController->view();
connect(dolphinView, SIGNAL(showPreviewChanged()),
this, SLOT(slotShowPreviewChanged()));
@ -104,7 +105,7 @@ DolphinColumnView::DolphinColumnView(QWidget* parent,
m_dirLister->setAutoUpdate(true);
m_dirLister->setMainWindow(window());
m_dirLister->setDelayedMimeTypes(true);
const bool showHiddenFiles = m_container->m_controller->dolphinView()->showHiddenFiles();
const bool showHiddenFiles = m_container->m_dolphinViewController->view()->showHiddenFiles();
m_dirLister->setShowingDotFiles(showHiddenFiles);
m_dolphinModel = new DolphinModel(this);
@ -124,18 +125,19 @@ DolphinColumnView::DolphinColumnView(QWidget* parent,
connect(KGlobalSettings::self(), SIGNAL(kdisplayFontChanged()),
this, SLOT(updateFont()));
DolphinController* controller = m_container->m_controller;
connect(controller, SIGNAL(zoomLevelChanged(int)),
DolphinViewController* dolphinViewController = m_container->m_dolphinViewController;
connect(dolphinViewController, SIGNAL(zoomLevelChanged(int)),
this, SLOT(setZoomLevel(int)));
const QString nameFilter = controller->nameFilter();
const ViewModeController* viewModeController = m_container->m_viewModeController;
const QString nameFilter = viewModeController->nameFilter();
if (!nameFilter.isEmpty()) {
m_proxyModel->setFilterFixedString(nameFilter);
}
updateDecorationSize(dolphinView->showPreview());
updateBackground();
m_extensionsFactory = new ViewExtensionsFactory(this, controller);
m_extensionsFactory = new ViewExtensionsFactory(this, dolphinViewController, viewModeController);
m_dirLister->openUrl(url, KDirLister::NoFlags);
}
@ -222,7 +224,7 @@ QStyleOptionViewItem DolphinColumnView::viewOptions() const
void DolphinColumnView::startDrag(Qt::DropActions supportedActions)
{
DragAndDropHelper::instance().startDrag(this, supportedActions, m_container->m_controller);
DragAndDropHelper::instance().startDrag(this, supportedActions, m_container->m_dolphinViewController);
}
void DolphinColumnView::dragEnterEvent(QDragEnterEvent* event)
@ -249,8 +251,8 @@ void DolphinColumnView::dragMoveEvent(QDragMoveEvent* event)
m_dropRect.setSize(QSize()); // set as invalid
if (index.isValid()) {
m_container->m_controller->setItemView(this);
const KFileItem item = m_container->m_controller->itemForIndex(index);
m_container->m_dolphinViewController->setItemView(this);
const KFileItem item = m_container->m_dolphinViewController->itemForIndex(index);
if (!item.isNull() && item.isDir()) {
m_dropRect = visualRect(index);
}
@ -266,9 +268,9 @@ void DolphinColumnView::dragMoveEvent(QDragMoveEvent* event)
void DolphinColumnView::dropEvent(QDropEvent* event)
{
const QModelIndex index = indexAt(event->pos());
m_container->m_controller->setItemView(this);
const KFileItem item = m_container->m_controller->itemForIndex(index);
m_container->m_controller->indicateDroppedUrls(item, url(), event);
m_container->m_dolphinViewController->setItemView(this);
const KFileItem item = m_container->m_dolphinViewController->itemForIndex(index);
m_container->m_dolphinViewController->indicateDroppedUrls(item, url(), event);
QListView::dropEvent(event);
}
@ -297,7 +299,7 @@ void DolphinColumnView::mousePressEvent(QMouseEvent* event)
requestActivation();
if (!indexAt(event->pos()).isValid()) {
if (QApplication::mouseButtons() & Qt::MidButton) {
m_container->m_controller->replaceUrlByClipboard();
m_container->m_dolphinViewController->replaceUrlByClipboard();
}
} else if (event->button() == Qt::LeftButton) {
// TODO: see comment in DolphinIconsView::mousePressEvent()
@ -311,7 +313,7 @@ void DolphinColumnView::keyPressEvent(QKeyEvent* event)
QListView::keyPressEvent(event);
requestActivation();
DolphinController* controller = m_container->m_controller;
DolphinViewController* controller = m_container->m_dolphinViewController;
controller->handleKeyPressEvent(event);
switch (event->key()) {
case Qt::Key_Right: {
@ -340,7 +342,7 @@ void DolphinColumnView::contextMenuEvent(QContextMenuEvent* event)
{
requestActivation();
QListView::contextMenuEvent(event);
m_container->m_controller->triggerContextMenuRequest(event->pos());
m_container->m_dolphinViewController->triggerContextMenuRequest(event->pos());
}
void DolphinColumnView::wheelEvent(QWheelEvent* event)
@ -356,7 +358,7 @@ void DolphinColumnView::leaveEvent(QEvent* event)
// if the mouse is above an item and moved very fast outside the widget,
// no viewportEntered() signal might be emitted although the mouse has been moved
// above the viewport
m_container->m_controller->emitViewportEntered();
m_container->m_dolphinViewController->emitViewportEntered();
}
void DolphinColumnView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
@ -370,7 +372,7 @@ void DolphinColumnView::setZoomLevel(int level)
const int size = ZoomLevelInfo::iconSizeForZoomLevel(level);
ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
const bool showPreview = m_container->m_controller->dolphinView()->showPreview();
const bool showPreview = m_container->m_dolphinViewController->view()->showPreview();
if (showPreview) {
settings->setPreviewSize(size);
} else {
@ -382,13 +384,13 @@ void DolphinColumnView::setZoomLevel(int level)
void DolphinColumnView::slotEntered(const QModelIndex& index)
{
m_container->m_controller->setItemView(this);
m_container->m_controller->emitItemEntered(index);
m_container->m_dolphinViewController->setItemView(this);
m_container->m_dolphinViewController->emitItemEntered(index);
}
void DolphinColumnView::requestActivation()
{
m_container->m_controller->requestActivation();
m_container->m_dolphinViewController->requestActivation();
if (!m_active) {
m_container->requestActivation(this);
selectionModel()->clear();
@ -407,7 +409,7 @@ void DolphinColumnView::updateFont()
void DolphinColumnView::slotShowPreviewChanged()
{
const DolphinView* view = m_container->m_controller->dolphinView();
const DolphinView* view = m_container->m_dolphinViewController->view();
updateDecorationSize(view->showPreview());
}
@ -417,10 +419,10 @@ void DolphinColumnView::activate()
if (KGlobalSettings::singleClick()) {
connect(this, SIGNAL(clicked(const QModelIndex&)),
m_container->m_controller, SLOT(triggerItem(const QModelIndex&)));
m_container->m_dolphinViewController, SLOT(triggerItem(const QModelIndex&)));
} else {
connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
m_container->m_controller, SLOT(triggerItem(const QModelIndex&)));
m_container->m_dolphinViewController, SLOT(triggerItem(const QModelIndex&)));
}
if (selectionModel() && selectionModel()->currentIndex().isValid()) {
@ -435,10 +437,10 @@ void DolphinColumnView::deactivate()
clearFocus();
if (KGlobalSettings::singleClick()) {
disconnect(this, SIGNAL(clicked(const QModelIndex&)),
m_container->m_controller, SLOT(triggerItem(const QModelIndex&)));
m_container->m_dolphinViewController, SLOT(triggerItem(const QModelIndex&)));
} else {
disconnect(this, SIGNAL(doubleClicked(const QModelIndex&)),
m_container->m_controller, SLOT(triggerItem(const QModelIndex&)));
m_container->m_dolphinViewController, SLOT(triggerItem(const QModelIndex&)));
}
const QModelIndex current = selectionModel()->currentIndex();

View file

@ -19,13 +19,14 @@
#include "dolphincolumnviewcontainer.h"
#include "dolphin_columnmodesettings.h"
#include "dolphincolumnview.h"
#include "dolphincontroller.h"
#include "dolphinviewcontroller.h"
#include "dolphinsortfilterproxymodel.h"
#include "draganddrophelper.h"
#include "settings/dolphinsettings.h"
#include "dolphin_columnmodesettings.h"
#include "viewmodecontroller.h"
#include <QPoint>
#include <QScrollBar>
@ -33,9 +34,11 @@
#include <QTimer>
DolphinColumnViewContainer::DolphinColumnViewContainer(QWidget* parent,
DolphinController* controller) :
DolphinViewController* dolphinViewController,
const ViewModeController* viewModeController) :
QScrollArea(parent),
m_controller(controller),
m_dolphinViewController(dolphinViewController),
m_viewModeController(viewModeController),
m_active(false),
m_index(-1),
m_contentX(0),
@ -45,14 +48,15 @@ DolphinColumnViewContainer::DolphinColumnViewContainer(QWidget* parent,
m_dragSource(0),
m_activeUrlTimer(0)
{
Q_ASSERT(controller != 0);
Q_ASSERT(dolphinViewController != 0);
Q_ASSERT(viewModeController != 0);
setAcceptDrops(true);
setFocusPolicy(Qt::NoFocus);
setFrameShape(QFrame::NoFrame);
setLayoutDirection(Qt::LeftToRight);
connect(controller, SIGNAL(activationChanged(bool)),
connect(viewModeController, SIGNAL(activationChanged(bool)),
this, SLOT(updateColumnsBackground(bool)));
connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
@ -67,7 +71,7 @@ DolphinColumnViewContainer::DolphinColumnViewContainer(QWidget* parent,
connect(m_activeUrlTimer, SIGNAL(timeout()),
this, SLOT(updateActiveUrl()));
DolphinColumnView* column = new DolphinColumnView(viewport(), this, m_controller->url());
DolphinColumnView* column = new DolphinColumnView(viewport(), this, viewModeController->url());
m_columns.append(column);
setActiveColumnIndex(0);
@ -181,7 +185,7 @@ void DolphinColumnViewContainer::showColumn(const KUrl& url)
void DolphinColumnViewContainer::mousePressEvent(QMouseEvent* event)
{
m_controller->requestActivation();
m_dolphinViewController->requestActivation();
QScrollArea::mousePressEvent(event);
}
@ -243,7 +247,7 @@ void DolphinColumnViewContainer::updateColumnsBackground(bool active)
void DolphinColumnViewContainer::updateActiveUrl()
{
const KUrl activeUrl = m_columns[m_index]->url();
m_controller->setUrl(activeUrl);
m_dolphinViewController->requestUrlChange(activeUrl);
}
void DolphinColumnViewContainer::setActiveColumnIndex(int index)
@ -338,7 +342,7 @@ void DolphinColumnViewContainer::assureVisibleActiveColumn()
void DolphinColumnViewContainer::requestActivation(DolphinColumnView* column)
{
m_controller->setItemView(column);
m_dolphinViewController->setItemView(column);
if (column->isActive()) {
assureVisibleActiveColumn();
} else {
@ -378,8 +382,8 @@ void DolphinColumnViewContainer::deleteColumn(DolphinColumnView* column)
return;
}
if (m_controller->itemView() == column) {
m_controller->setItemView(0);
if (m_dolphinViewController->itemView() == column) {
m_dolphinViewController->setItemView(0);
}
// deleteWhenNotDragSource(column) does not necessarily delete column,
// and we want its preview generator destroyed immediately.

View file

@ -29,7 +29,7 @@
#include <QString>
class DolphinColumnView;
class DolphinController;
class DolphinViewController;
class QFrame;
class QTimeLine;
class QTimer;
@ -45,8 +45,18 @@ class DolphinColumnViewContainer : public QScrollArea
Q_OBJECT
public:
/**
* @param parent Parent widget.
* @param dolphinViewController Allows the DolphinColumnView to control the
* DolphinView in a limited way.
* @param viewModeController Controller that is used by the DolphinView
* to control the DolphinColumnView. The DolphinColumnView
* only has read access to the controller.
* @param model Directory that is shown.
*/
explicit DolphinColumnViewContainer(QWidget* parent,
DolphinController* controller);
DolphinViewController* dolphinViewController,
const ViewModeController* viewModeController);
virtual ~DolphinColumnViewContainer();
KUrl rootUrl() const;
@ -127,7 +137,8 @@ private:
void deleteColumn(DolphinColumnView* column);
private:
DolphinController* m_controller;
DolphinViewController* m_dolphinViewController;
const ViewModeController* m_viewModeController;
bool m_active;
int m_index;
int m_contentX;

View file

@ -21,13 +21,14 @@
#include "dolphindetailsview.h"
#include "dolphinmodel.h"
#include "dolphincontroller.h"
#include "dolphinviewcontroller.h"
#include "dolphinfileitemdelegate.h"
#include "settings/dolphinsettings.h"
#include "dolphinsortfilterproxymodel.h"
#include "dolphinviewautoscroller.h"
#include "draganddrophelper.h"
#include "viewextensionsfactory.h"
#include "viewmodecontroller.h"
#include "viewproperties.h"
#include "zoomlevelinfo.h"
@ -46,7 +47,8 @@
#include <QScrollBar>
DolphinDetailsView::DolphinDetailsView(QWidget* parent,
DolphinController* controller,
DolphinViewController* dolphinViewController,
const ViewModeController* viewModeController,
DolphinSortFilterProxyModel* proxyModel) :
QTreeView(parent),
m_autoResize(true),
@ -54,7 +56,8 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent,
m_keyPressed(false),
m_useDefaultIndexAt(true),
m_ignoreScrollTo(false),
m_controller(controller),
m_dolphinViewController(dolphinViewController),
m_viewModeController(viewModeController),
m_extensionsFactory(0),
m_expandableFoldersAction(0),
m_expandedUrls(),
@ -64,7 +67,8 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent,
{
const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
Q_ASSERT(settings != 0);
Q_ASSERT(controller != 0);
Q_ASSERT(dolphinViewController != 0);
Q_ASSERT(viewModeController != 0);
setLayoutDirection(Qt::LeftToRight);
setAcceptDrops(true);
@ -81,7 +85,7 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent,
setMouseTracking(true);
const ViewProperties props(controller->url());
const ViewProperties props(viewModeController->url());
setSortIndicatorSection(props.sorting());
setSortIndicatorOrder(props.sortOrder());
@ -102,24 +106,24 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent,
this, SLOT(setSortIndicatorOrder(Qt::SortOrder)));
connect(this, SIGNAL(clicked(const QModelIndex&)),
controller, SLOT(requestTab(const QModelIndex&)));
dolphinViewController, SLOT(requestTab(const QModelIndex&)));
if (KGlobalSettings::singleClick()) {
connect(this, SIGNAL(clicked(const QModelIndex&)),
controller, SLOT(triggerItem(const QModelIndex&)));
dolphinViewController, SLOT(triggerItem(const QModelIndex&)));
} else {
connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
controller, SLOT(triggerItem(const QModelIndex&)));
dolphinViewController, SLOT(triggerItem(const QModelIndex&)));
}
connect(this, SIGNAL(entered(const QModelIndex&)),
this, SLOT(slotEntered(const QModelIndex&)));
connect(this, SIGNAL(viewportEntered()),
controller, SLOT(emitViewportEntered()));
connect(controller, SIGNAL(zoomLevelChanged(int)),
dolphinViewController, SLOT(emitViewportEntered()));
connect(viewModeController, SIGNAL(zoomLevelChanged(int)),
this, SLOT(setZoomLevel(int)));
connect(controller->dolphinView(), SIGNAL(additionalInfoChanged()),
connect(dolphinViewController->view(), SIGNAL(additionalInfoChanged()),
this, SLOT(updateColumnVisibility()));
connect(controller, SIGNAL(activationChanged(bool)),
connect(viewModeController, SIGNAL(activationChanged(bool)),
this, SLOT(slotActivationChanged(bool)));
if (settings->useSystemFont()) {
@ -135,7 +139,7 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent,
setVerticalScrollMode(QTreeView::ScrollPerPixel);
setHorizontalScrollMode(QTreeView::ScrollPerPixel);
const DolphinView* view = controller->dolphinView();
const DolphinView* view = dolphinViewController->view();
connect(view, SIGNAL(showPreviewChanged()),
this, SLOT(slotShowPreviewChanged()));
@ -158,7 +162,7 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent,
updateDecorationSize(view->showPreview());
m_extensionsFactory = new ViewExtensionsFactory(this, controller);
m_extensionsFactory = new ViewExtensionsFactory(this, dolphinViewController, viewModeController);
m_extensionsFactory->fileItemDelegate()->setMinimizedNameColumn(true);
m_extensionsFactory->setAutoFolderExpandingEnabled(settings->expandableFolders());
}
@ -225,13 +229,13 @@ void DolphinDetailsView::contextMenuEvent(QContextMenuEvent* event)
DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
m_expandableFoldersAction->setChecked(settings->expandableFolders());
m_controller->triggerContextMenuRequest(event->pos(),
m_dolphinViewController->triggerContextMenuRequest(event->pos(),
QList<QAction*>() << m_expandableFoldersAction);
}
void DolphinDetailsView::mousePressEvent(QMouseEvent* event)
{
m_controller->requestActivation();
m_dolphinViewController->requestActivation();
const QModelIndex current = currentIndex();
QTreeView::mousePressEvent(event);
@ -249,7 +253,7 @@ void DolphinDetailsView::mousePressEvent(QMouseEvent* event)
if (!index.isValid() || (index.column() != DolphinModel::Name)) {
// the mouse press is done somewhere outside the filename column
if (QApplication::mouseButtons() & Qt::MidButton) {
m_controller->replaceUrlByClipboard();
m_dolphinViewController->replaceUrlByClipboard();
}
const Qt::KeyboardModifiers mod = QApplication::keyboardModifiers();
@ -336,7 +340,7 @@ void DolphinDetailsView::mouseReleaseEvent(QMouseEvent* event)
void DolphinDetailsView::startDrag(Qt::DropActions supportedActions)
{
DragAndDropHelper::instance().startDrag(this, supportedActions, m_controller);
DragAndDropHelper::instance().startDrag(this, supportedActions, m_dolphinViewController);
m_band.show = false;
}
@ -366,7 +370,7 @@ void DolphinDetailsView::dragMoveEvent(QDragMoveEvent* event)
setDirtyRegion(m_dropRect);
const QModelIndex index = indexAt(event->pos());
if (index.isValid() && (index.column() == DolphinModel::Name)) {
const KFileItem item = m_controller->itemForIndex(index);
const KFileItem item = m_dolphinViewController->itemForIndex(index);
if (!item.isNull() && item.isDir()) {
m_dropRect = visualRect(index);
} else {
@ -386,9 +390,9 @@ void DolphinDetailsView::dropEvent(QDropEvent* event)
const QModelIndex index = indexAt(event->pos());
KFileItem item;
if (index.isValid() && (index.column() == DolphinModel::Name)) {
item = m_controller->itemForIndex(index);
item = m_dolphinViewController->itemForIndex(index);
}
m_controller->indicateDroppedUrls(item, m_controller->url(), event);
m_dolphinViewController->indicateDroppedUrls(item, m_viewModeController->url(), event);
QTreeView::dropEvent(event);
}
@ -420,7 +424,7 @@ void DolphinDetailsView::keyPressEvent(QKeyEvent* event)
m_keyPressed = !(event->modifiers() & Qt::ControlModifier);
QTreeView::keyPressEvent(event);
m_controller->handleKeyPressEvent(event);
m_dolphinViewController->handleKeyPressEvent(event);
}
void DolphinDetailsView::keyReleaseEvent(QKeyEvent* event)
@ -466,7 +470,7 @@ bool DolphinDetailsView::eventFilter(QObject* watched, QEvent* event)
// if the mouse is above an item and moved very fast outside the widget,
// no viewportEntered() signal might be emitted although the mouse has been moved
// above the viewport
m_controller->emitViewportEntered();
m_dolphinViewController->emitViewportEntered();
}
return QTreeView::eventFilter(watched, event);
@ -484,7 +488,7 @@ QModelIndex DolphinDetailsView::indexAt(const QPoint& point) const
QRect DolphinDetailsView::visualRect(const QModelIndex& index) const
{
QRect rect = QTreeView::visualRect(index);
const KFileItem item = m_controller->itemForIndex(index);
const KFileItem item = m_dolphinViewController->itemForIndex(index);
if (!item.isNull()) {
const int width = DolphinFileItemDelegate::nameColumnWidth(item.text(), viewOptions());
rect.setWidth(width);
@ -530,16 +534,16 @@ void DolphinDetailsView::synchronizeSortingState(int column)
// invoked, but Dolphin is not informed about this.
DolphinView::Sorting sorting = DolphinSortFilterProxyModel::sortingForColumn(column);
const Qt::SortOrder sortOrder = header()->sortIndicatorOrder();
m_controller->indicateSortingChange(sorting);
m_controller->indicateSortOrderChange(sortOrder);
m_dolphinViewController->indicateSortingChange(sorting);
m_dolphinViewController->indicateSortOrderChange(sortOrder);
}
void DolphinDetailsView::slotEntered(const QModelIndex& index)
{
if (index.column() == DolphinModel::Name) {
m_controller->emitItemEntered(index);
m_dolphinViewController->emitItemEntered(index);
} else {
m_controller->emitViewportEntered();
m_dolphinViewController->emitViewportEntered();
}
}
@ -576,7 +580,7 @@ void DolphinDetailsView::setZoomLevel(int level)
const int size = ZoomLevelInfo::iconSizeForZoomLevel(level);
DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
const bool showPreview = m_controller->dolphinView()->showPreview();
const bool showPreview = m_dolphinViewController->view()->showPreview();
if (showPreview) {
settings->setPreviewSize(size);
} else {
@ -588,7 +592,7 @@ void DolphinDetailsView::setZoomLevel(int level)
void DolphinDetailsView::slotShowPreviewChanged()
{
const DolphinView* view = m_controller->dolphinView();
const DolphinView* view = m_dolphinViewController->view();
updateDecorationSize(view->showPreview());
}
@ -616,7 +620,7 @@ void DolphinDetailsView::configureSettings(const QPoint& pos)
const bool show = activatedAction->isChecked();
const int columnIndex = activatedAction->data().toInt();
KFileItemDelegate::InformationList list = m_controller->dolphinView()->additionalInfo();
KFileItemDelegate::InformationList list = m_dolphinViewController->view()->additionalInfo();
const KFileItemDelegate::Information info = infoForColumn(columnIndex);
if (show) {
Q_ASSERT(!list.contains(info));
@ -627,7 +631,7 @@ void DolphinDetailsView::configureSettings(const QPoint& pos)
list.removeAt(index);
}
m_controller->indicateAdditionalInfoChange(list);
m_dolphinViewController->indicateAdditionalInfoChange(list);
setColumnHidden(columnIndex, !show);
resizeColumns();
}
@ -642,7 +646,7 @@ void DolphinDetailsView::updateColumnVisibility()
const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
const QList<int> columnPositions = settings->columnPositions();
const KFileItemDelegate::InformationList list = m_controller->dolphinView()->additionalInfo();
const KFileItemDelegate::InformationList list = m_dolphinViewController->view()->additionalInfo();
for (int i = DolphinModel::Name; i <= DolphinModel::Version; ++i) {
const KFileItemDelegate::Information info = infoForColumn(i);
const bool hide = !list.contains(info) && (i != DolphinModel::Name);
@ -701,7 +705,7 @@ void DolphinDetailsView::disableAutoResizing()
void DolphinDetailsView::requestActivation()
{
m_controller->requestActivation();
m_dolphinViewController->requestActivation();
}
void DolphinDetailsView::slotGlobalSettingsChanged(int category)
@ -714,12 +718,12 @@ void DolphinDetailsView::slotGlobalSettingsChanged(int category)
m_font = KGlobalSettings::generalFont();
}
//Disconnect then reconnect, since the settings have been changed, the connection requirements may have also.
disconnect(this, SIGNAL(clicked(QModelIndex)), m_controller, SLOT(triggerItem(QModelIndex)));
disconnect(this, SIGNAL(doubleClicked(QModelIndex)), m_controller, SLOT(triggerItem(QModelIndex)));
disconnect(this, SIGNAL(clicked(QModelIndex)), m_dolphinViewController, SLOT(triggerItem(QModelIndex)));
disconnect(this, SIGNAL(doubleClicked(QModelIndex)), m_dolphinViewController, SLOT(triggerItem(QModelIndex)));
if (KGlobalSettings::singleClick()) {
connect(this, SIGNAL(clicked(QModelIndex)), m_controller, SLOT(triggerItem(QModelIndex)));
connect(this, SIGNAL(clicked(QModelIndex)), m_dolphinViewController, SLOT(triggerItem(QModelIndex)));
} else {
connect(this, SIGNAL(doubleClicked(QModelIndex)), m_controller, SLOT(triggerItem(QModelIndex)));
connect(this, SIGNAL(doubleClicked(QModelIndex)), m_dolphinViewController, SLOT(triggerItem(QModelIndex)));
}
}
@ -928,7 +932,7 @@ void DolphinDetailsView::setFoldersExpandable(bool expandable)
void DolphinDetailsView::slotExpanded(const QModelIndex& index)
{
KFileItem item = m_controller->itemForIndex(index);
KFileItem item = m_dolphinViewController->itemForIndex(index);
if (!item.isNull()) {
m_expandedUrls.insert(item.url());
}
@ -936,7 +940,7 @@ void DolphinDetailsView::slotExpanded(const QModelIndex& index)
void DolphinDetailsView::slotCollapsed(const QModelIndex& index)
{
KFileItem item = m_controller->itemForIndex(index);
KFileItem item = m_dolphinViewController->itemForIndex(index);
if (!item.isNull()) {
m_expandedUrls.remove(item.url());
}

View file

@ -25,7 +25,7 @@
#include <QTreeView>
#include <libdolphin_export.h>
class DolphinController;
class DolphinViewController;
class DolphinSortFilterProxyModel;
class ViewExtensionsFactory;
@ -42,8 +42,18 @@ class LIBDOLPHINPRIVATE_EXPORT DolphinDetailsView : public QTreeView
Q_OBJECT
public:
/**
* @param parent Parent widget.
* @param dolphinViewController Allows the DolphinDetailsView to control the
* DolphinView in a limited way.
* @param viewModeController Controller that is used by the DolphinView
* to control the DolphinDetailsView. The DolphinDetailsView
* only has read access to the controller.
* @param model Directory that is shown.
*/
explicit DolphinDetailsView(QWidget* parent,
DolphinController* controller,
DolphinViewController* dolphinViewController,
const ViewModeController* viewModeController,
DolphinSortFilterProxyModel* model);
virtual ~DolphinDetailsView();
@ -226,7 +236,8 @@ private:
bool m_useDefaultIndexAt : 1; // true, if QTreeView::indexAt() should be used
bool m_ignoreScrollTo : 1; // true if calls to scrollTo(...) should do nothing.
DolphinController* m_controller;
DolphinViewController* m_dolphinViewController;
const ViewModeController* m_viewModeController;
ViewExtensionsFactory* m_extensionsFactory;
QAction* m_expandableFoldersAction;

View file

@ -20,7 +20,7 @@
#include "dolphiniconsview.h"
#include "dolphincategorydrawer.h"
#include "dolphincontroller.h"
#include "dolphinviewcontroller.h"
#include "settings/dolphinsettings.h"
#include "dolphinsortfilterproxymodel.h"
#include "dolphin_iconsmodesettings.h"
@ -28,6 +28,7 @@
#include "draganddrophelper.h"
#include "selectionmanager.h"
#include "viewextensionsfactory.h"
#include "viewmodecontroller.h"
#include "zoomlevelinfo.h"
#include <kcategorizedsortfilterproxymodel.h>
@ -39,10 +40,12 @@
#include <QScrollBar>
DolphinIconsView::DolphinIconsView(QWidget* parent,
DolphinController* controller,
DolphinViewController* dolphinViewController,
const ViewModeController* viewModeController,
DolphinSortFilterProxyModel* proxyModel) :
KCategorizedView(parent),
m_controller(controller),
m_dolphinViewController(dolphinViewController),
m_viewModeController(viewModeController),
m_categoryDrawer(new DolphinCategoryDrawer(this)),
m_extensionsFactory(0),
m_font(),
@ -52,7 +55,9 @@ DolphinIconsView::DolphinIconsView(QWidget* parent,
m_itemSize(),
m_dropRect()
{
Q_ASSERT(controller != 0);
Q_ASSERT(dolphinViewController != 0);
Q_ASSERT(viewModeController != 0);
setModel(proxyModel);
setLayoutDirection(Qt::LeftToRight);
setViewMode(QListView::IconMode);
@ -65,23 +70,23 @@ DolphinIconsView::DolphinIconsView(QWidget* parent,
setMouseTracking(true);
connect(this, SIGNAL(clicked(const QModelIndex&)),
controller, SLOT(requestTab(const QModelIndex&)));
dolphinViewController, SLOT(requestTab(const QModelIndex&)));
if (KGlobalSettings::singleClick()) {
connect(this, SIGNAL(clicked(const QModelIndex&)),
controller, SLOT(triggerItem(const QModelIndex&)));
dolphinViewController, SLOT(triggerItem(const QModelIndex&)));
} else {
connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
controller, SLOT(triggerItem(const QModelIndex&)));
dolphinViewController, SLOT(triggerItem(const QModelIndex&)));
}
connect(this, SIGNAL(entered(const QModelIndex&)),
controller, SLOT(emitItemEntered(const QModelIndex&)));
dolphinViewController, SLOT(emitItemEntered(const QModelIndex&)));
connect(this, SIGNAL(viewportEntered()),
controller, SLOT(emitViewportEntered()));
connect(controller, SIGNAL(zoomLevelChanged(int)),
dolphinViewController, SLOT(emitViewportEntered()));
connect(viewModeController, SIGNAL(zoomLevelChanged(int)),
this, SLOT(setZoomLevel(int)));
const DolphinView* view = controller->dolphinView();
const DolphinView* view = dolphinViewController->view();
connect(view, SIGNAL(showPreviewChanged()),
this, SLOT(slotShowPreviewChanged()));
connect(view, SIGNAL(additionalInfoChanged()),
@ -122,7 +127,7 @@ DolphinIconsView::DolphinIconsView(QWidget* parent,
this, SLOT(slotGlobalSettingsChanged(int)));
updateGridSize(view->showPreview(), 0);
m_extensionsFactory = new ViewExtensionsFactory(this, controller);
m_extensionsFactory = new ViewExtensionsFactory(this, dolphinViewController, viewModeController);
}
DolphinIconsView::~DolphinIconsView()
@ -156,12 +161,12 @@ QStyleOptionViewItem DolphinIconsView::viewOptions() const
void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event)
{
KCategorizedView::contextMenuEvent(event);
m_controller->triggerContextMenuRequest(event->pos());
m_dolphinViewController->triggerContextMenuRequest(event->pos());
}
void DolphinIconsView::mousePressEvent(QMouseEvent* event)
{
m_controller->requestActivation();
m_dolphinViewController->requestActivation();
const QModelIndex index = indexAt(event->pos());
if (index.isValid() && (event->button() == Qt::LeftButton)) {
// TODO: It should not be necessary to manually set the dragging state, but I could
@ -173,7 +178,7 @@ void DolphinIconsView::mousePressEvent(QMouseEvent* event)
}
if (!index.isValid() && (QApplication::mouseButtons() & Qt::MidButton)) {
m_controller->replaceUrlByClipboard();
m_dolphinViewController->replaceUrlByClipboard();
}
KCategorizedView::mousePressEvent(event);
@ -181,7 +186,7 @@ void DolphinIconsView::mousePressEvent(QMouseEvent* event)
void DolphinIconsView::startDrag(Qt::DropActions supportedActions)
{
DragAndDropHelper::instance().startDrag(this, supportedActions, m_controller);
DragAndDropHelper::instance().startDrag(this, supportedActions, m_dolphinViewController);
}
void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
@ -207,7 +212,7 @@ void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event)
m_dropRect.setSize(QSize()); // set as invalid
if (index.isValid()) {
const KFileItem item = m_controller->itemForIndex(index);
const KFileItem item = m_dolphinViewController->itemForIndex(index);
if (!item.isNull() && item.isDir()) {
m_dropRect = visualRect(index);
} else {
@ -225,8 +230,8 @@ void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event)
void DolphinIconsView::dropEvent(QDropEvent* event)
{
const QModelIndex index = indexAt(event->pos());
const KFileItem item = m_controller->itemForIndex(index);
m_controller->indicateDroppedUrls(item, m_controller->url(), event);
const KFileItem item = m_dolphinViewController->itemForIndex(index);
m_dolphinViewController->indicateDroppedUrls(item, m_viewModeController->url(), event);
// don't call KCategorizedView::dropEvent(event), as it moves
// the items which is not wanted
}
@ -307,7 +312,7 @@ QModelIndex DolphinIconsView::moveCursor(CursorAction cursorAction, Qt::Keyboard
void DolphinIconsView::keyPressEvent(QKeyEvent* event)
{
KCategorizedView::keyPressEvent(event);
m_controller->handleKeyPressEvent(event);
m_dolphinViewController->handleKeyPressEvent(event);
}
void DolphinIconsView::wheelEvent(QWheelEvent* event)
@ -345,7 +350,7 @@ void DolphinIconsView::leaveEvent(QEvent* event)
// if the mouse is above an item and moved very fast outside the widget,
// no viewportEntered() signal might be emitted although the mouse has been moved
// above the viewport
m_controller->emitViewportEntered();
m_dolphinViewController->emitViewportEntered();
}
void DolphinIconsView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
@ -357,19 +362,19 @@ void DolphinIconsView::currentChanged(const QModelIndex& current, const QModelIn
void DolphinIconsView::resizeEvent(QResizeEvent* event)
{
KCategorizedView::resizeEvent(event);
const DolphinView* view = m_controller->dolphinView();
const DolphinView* view = m_dolphinViewController->view();
updateGridSize(view->showPreview(), view->additionalInfo().count());
}
void DolphinIconsView::slotShowPreviewChanged()
{
const DolphinView* view = m_controller->dolphinView();
const DolphinView* view = m_dolphinViewController->view();
updateGridSize(view->showPreview(), additionalInfoCount());
}
void DolphinIconsView::slotAdditionalInfoChanged()
{
const DolphinView* view = m_controller->dolphinView();
const DolphinView* view = m_dolphinViewController->view();
const bool showPreview = view->showPreview();
updateGridSize(showPreview, view->additionalInfo().count());
}
@ -381,7 +386,7 @@ void DolphinIconsView::setZoomLevel(int level)
const int oldIconSize = settings->iconSize();
int newIconSize = oldIconSize;
const bool showPreview = m_controller->dolphinView()->showPreview();
const bool showPreview = m_dolphinViewController->view()->showPreview();
if (showPreview) {
const int previewSize = ZoomLevelInfo::iconSizeForZoomLevel(level);
settings->setPreviewSize(previewSize);
@ -400,7 +405,7 @@ void DolphinIconsView::setZoomLevel(int level)
void DolphinIconsView::requestActivation()
{
m_controller->requestActivation();
m_dolphinViewController->requestActivation();
}
void DolphinIconsView::slotGlobalSettingsChanged(int category)
@ -413,12 +418,12 @@ void DolphinIconsView::slotGlobalSettingsChanged(int category)
m_font = KGlobalSettings::generalFont();
}
disconnect(this, SIGNAL(clicked(QModelIndex)), m_controller, SLOT(triggerItem(QModelIndex)));
disconnect(this, SIGNAL(doubleClicked(QModelIndex)), m_controller, SLOT(triggerItem(QModelIndex)));
disconnect(this, SIGNAL(clicked(QModelIndex)), m_dolphinViewController, SLOT(triggerItem(QModelIndex)));
disconnect(this, SIGNAL(doubleClicked(QModelIndex)), m_dolphinViewController, SLOT(triggerItem(QModelIndex)));
if (KGlobalSettings::singleClick()) {
connect(this, SIGNAL(clicked(QModelIndex)), m_controller, SLOT(triggerItem(QModelIndex)));
connect(this, SIGNAL(clicked(QModelIndex)), m_dolphinViewController, SLOT(triggerItem(QModelIndex)));
} else {
connect(this, SIGNAL(doubleClicked(QModelIndex)), m_controller, SLOT(triggerItem(QModelIndex)));
connect(this, SIGNAL(doubleClicked(QModelIndex)), m_dolphinViewController, SLOT(triggerItem(QModelIndex)));
}
}
@ -520,7 +525,7 @@ void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount)
int DolphinIconsView::additionalInfoCount() const
{
const DolphinView* view = m_controller->dolphinView();
const DolphinView* view = m_dolphinViewController->view();
return view->additionalInfo().count();
}

View file

@ -31,10 +31,11 @@
#include <libdolphin_export.h>
class DolphinController;
class DolphinViewController;
class DolphinCategoryDrawer;
class DolphinSortFilterProxyModel;
class ViewExtensionsFactory;
class ViewModeController;
/**
* @brief Represents the view, where each item is shown as an icon.
@ -47,8 +48,18 @@ class LIBDOLPHINPRIVATE_EXPORT DolphinIconsView : public KCategorizedView
Q_OBJECT
public:
/**
* @param parent Parent widget.
* @param dolphinViewController Allows the DolphinIconsView to control the
* DolphinView in a limited way.
* @param viewModeController Controller that is used by the DolphinView
* to control the DolphinIconsView. The DolphinIconsView
* only has read access to the controller.
* @param model Directory that is shown.
*/
explicit DolphinIconsView(QWidget* parent,
DolphinController* controller,
DolphinViewController* dolphinViewController,
const ViewModeController* viewModeController,
DolphinSortFilterProxyModel* proxyModel);
virtual ~DolphinIconsView();
@ -94,7 +105,8 @@ private:
int additionalInfoCount() const;
private:
DolphinController* m_controller;
DolphinViewController* m_dolphinViewController;
const ViewModeController* m_viewModeController;
DolphinCategoryDrawer* m_categoryDrawer;
ViewExtensionsFactory* m_extensionsFactory;

View file

@ -51,7 +51,7 @@
#include "dolphinmodel.h"
#include "dolphincolumnviewcontainer.h"
#include "dolphincontroller.h"
#include "dolphinviewcontroller.h"
#include "dolphindetailsview.h"
#include "dolphinfileitemdelegate.h"
#include "dolphinnewmenuobserver.h"
@ -62,6 +62,7 @@
#include "draganddrophelper.h"
#include "renamedialog.h"
#include "settings/dolphinsettings.h"
#include "viewmodecontroller.h"
#include "viewproperties.h"
#include "zoomlevelinfo.h"
#include "dolphindetailsviewexpander.h"
@ -88,7 +89,8 @@ DolphinView::DolphinView(QWidget* parent,
m_assureVisibleCurrentIndex(false),
m_mode(DolphinView::IconsView),
m_topLayout(0),
m_controller(0),
m_dolphinViewController(0),
m_viewModeController(0),
m_viewAccessor(proxyModel),
m_selectionModel(0),
m_selectionChangedTimer(0),
@ -103,34 +105,38 @@ DolphinView::DolphinView(QWidget* parent,
m_topLayout->setSpacing(0);
m_topLayout->setMargin(0);
m_controller = new DolphinController(this);
m_controller->setUrl(url);
m_dolphinViewController = new DolphinViewController(this);
connect(m_controller, SIGNAL(urlChanged(const KUrl&)),
m_viewModeController = new ViewModeController(this);
m_viewModeController->setUrl(url);
connect(m_viewModeController, SIGNAL(urlChanged(const KUrl&)),
this, SIGNAL(urlChanged(const KUrl&)));
connect(m_controller, SIGNAL(requestContextMenu(const QPoint&, const QList<QAction*>&)),
connect(m_dolphinViewController, SIGNAL(requestContextMenu(const QPoint&, const QList<QAction*>&)),
this, SLOT(openContextMenu(const QPoint&, const QList<QAction*>&)));
connect(m_controller, SIGNAL(urlsDropped(const KFileItem&, const KUrl&, QDropEvent*)),
connect(m_dolphinViewController, SIGNAL(urlsDropped(const KFileItem&, const KUrl&, QDropEvent*)),
this, SLOT(dropUrls(const KFileItem&, const KUrl&, QDropEvent*)));
connect(m_controller, SIGNAL(sortingChanged(DolphinView::Sorting)),
connect(m_dolphinViewController, SIGNAL(sortingChanged(DolphinView::Sorting)),
this, SLOT(updateSorting(DolphinView::Sorting)));
connect(m_controller, SIGNAL(sortOrderChanged(Qt::SortOrder)),
connect(m_dolphinViewController, SIGNAL(sortOrderChanged(Qt::SortOrder)),
this, SLOT(updateSortOrder(Qt::SortOrder)));
connect(m_controller, SIGNAL(sortFoldersFirstChanged(bool)),
connect(m_dolphinViewController, SIGNAL(sortFoldersFirstChanged(bool)),
this, SLOT(updateSortFoldersFirst(bool)));
connect(m_controller, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList&)),
connect(m_dolphinViewController, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList&)),
this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList&)));
connect(m_controller, SIGNAL(itemTriggered(const KFileItem&)),
connect(m_dolphinViewController, SIGNAL(itemTriggered(const KFileItem&)),
this, SLOT(triggerItem(const KFileItem&)));
connect(m_controller, SIGNAL(tabRequested(const KUrl&)),
connect(m_dolphinViewController, SIGNAL(tabRequested(const KUrl&)),
this, SIGNAL(tabRequested(const KUrl&)));
connect(m_controller, SIGNAL(activated()),
connect(m_dolphinViewController, SIGNAL(activated()),
this, SLOT(activate()));
connect(m_controller, SIGNAL(itemEntered(const KFileItem&)),
connect(m_dolphinViewController, SIGNAL(itemEntered(const KFileItem&)),
this, SLOT(showHoverInformation(const KFileItem&)));
connect(m_controller, SIGNAL(viewportEntered()),
connect(m_dolphinViewController, SIGNAL(viewportEntered()),
this, SLOT(clearHoverInformation()));
connect(m_dolphinViewController, SIGNAL(urlChangeRequested(KUrl)),
m_viewModeController, SLOT(setUrl(KUrl)));
KDirLister* dirLister = m_viewAccessor.dirLister();
connect(dirLister, SIGNAL(redirection(KUrl,KUrl)),
@ -160,9 +166,9 @@ DolphinView::~DolphinView()
{
}
const KUrl& DolphinView::url() const
KUrl DolphinView::url() const
{
return m_controller->url();
return m_viewModeController->url();
}
KUrl DolphinView::rootUrl() const
@ -202,7 +208,7 @@ void DolphinView::setActive(bool active)
emit activated();
}
m_controller->indicateActivationChange(active);
m_viewModeController->indicateActivationChange(active);
}
bool DolphinView::isActive() const
@ -216,7 +222,7 @@ void DolphinView::setMode(Mode mode)
return; // the wished mode is already set
}
const int oldZoomLevel = m_controller->zoomLevel();
const int oldZoomLevel = m_viewModeController->zoomLevel();
m_mode = mode;
// remember the currently selected items, so that they will
@ -353,14 +359,14 @@ void DolphinView::setZoomLevel(int level)
}
if (level != zoomLevel()) {
m_controller->setZoomLevel(level);
m_viewModeController->setZoomLevel(level);
emit zoomLevelChanged(level);
}
}
int DolphinView::zoomLevel() const
{
return m_controller->zoomLevel();
return m_viewModeController->zoomLevel();
}
void DolphinView::setSorting(Sorting sorting)
@ -437,7 +443,7 @@ void DolphinView::refresh()
m_ignoreViewProperties = false;
const bool oldActivationState = m_active;
const int oldZoomLevel = m_controller->zoomLevel();
const int oldZoomLevel = m_viewModeController->zoomLevel();
m_active = true;
createView();
@ -450,7 +456,7 @@ void DolphinView::refresh()
void DolphinView::setNameFilter(const QString& nameFilter)
{
m_controller->setNameFilter(nameFilter);
m_viewModeController->setNameFilter(nameFilter);
}
void DolphinView::calculateItemCount(int& fileCount,
@ -528,15 +534,15 @@ QString DolphinView::statusBarText() const
QList<QAction*> DolphinView::versionControlActions(const KFileItemList& items) const
{
return m_controller->versionControlActions(items);
return m_dolphinViewController->versionControlActions(items);
}
void DolphinView::setUrl(const KUrl& url)
{
if (m_controller->url() != url) {
if (m_viewModeController->url() != url) {
m_newFileNames.clear();
m_controller->setUrl(url); // emits urlChanged, which we forward
m_viewModeController->setUrl(url); // emits urlChanged, which we forward
m_viewAccessor.prepareUrlChange(url);
applyViewProperties();
loadDirectory(url);
@ -726,7 +732,7 @@ void DolphinView::setShowPreview(bool show)
props.setShowPreview(show);
m_showPreview = show;
const int oldZoomLevel = m_controller->zoomLevel();
const int oldZoomLevel = m_viewModeController->zoomLevel();
emit showPreviewChanged();
// Enabling or disabling the preview might change the icon size of the view.
@ -814,7 +820,7 @@ bool DolphinView::eventFilter(QObject* watched, QEvent* event)
switch (event->type()) {
case QEvent::FocusIn:
if (watched == m_viewAccessor.itemView()) {
m_controller->requestActivation();
m_dolphinViewController->requestActivation();
}
break;
@ -1223,7 +1229,7 @@ void DolphinView::applyViewProperties()
const Mode mode = props.viewMode();
if (m_mode != mode) {
const int oldZoomLevel = m_controller->zoomLevel();
const int oldZoomLevel = m_viewModeController->zoomLevel();
m_mode = mode;
createView();
@ -1277,7 +1283,7 @@ void DolphinView::applyViewProperties()
const bool showPreview = props.showPreview();
if (showPreview != m_showPreview) {
m_showPreview = showPreview;
const int oldZoomLevel = m_controller->zoomLevel();
const int oldZoomLevel = m_viewModeController->zoomLevel();
emit showPreviewChanged();
// Enabling or disabling the preview might change the icon size of the view.
@ -1299,14 +1305,14 @@ void DolphinView::createView()
deleteView();
Q_ASSERT(m_viewAccessor.itemView() == 0);
m_viewAccessor.createView(this, m_controller, m_mode);
m_viewAccessor.createView(this, m_dolphinViewController, m_viewModeController, m_mode);
QAbstractItemView* view = m_viewAccessor.itemView();
Q_ASSERT(view != 0);
view->installEventFilter(this);
view->viewport()->installEventFilter(this);
m_controller->setItemView(view);
m_dolphinViewController->setItemView(view);
// When changing the view mode, the selection is lost due to reinstantiating
// a new item view with a custom selection model. Pass the ownership of the
@ -1340,7 +1346,7 @@ void DolphinView::deleteView()
// disconnect all signal/slots
disconnect(view);
m_controller->disconnect(view);
m_viewModeController->disconnect(view);
view->disconnect();
m_viewAccessor.deleteView();
@ -1357,7 +1363,7 @@ void DolphinView::updateZoomLevel(int oldZoomLevel)
{
const int newZoomLevel = ZoomLevelInfo::zoomLevelForIconSize(m_viewAccessor.itemView()->iconSize());
if (oldZoomLevel != newZoomLevel) {
m_controller->setZoomLevel(newZoomLevel);
m_viewModeController->setZoomLevel(newZoomLevel);
emit zoomLevelChanged(newZoomLevel);
}
}
@ -1403,22 +1409,31 @@ DolphinView::ViewAccessor::~ViewAccessor()
}
void DolphinView::ViewAccessor::createView(QWidget* parent,
DolphinController* controller,
DolphinViewController* dolphinViewController,
const ViewModeController* viewModeController,
Mode mode)
{
Q_ASSERT(itemView() == 0);
switch (mode) {
case IconsView:
m_iconsView = new DolphinIconsView(parent, controller, m_proxyModel);
m_iconsView = new DolphinIconsView(parent,
dolphinViewController,
viewModeController,
m_proxyModel);
break;
case DetailsView:
m_detailsView = new DolphinDetailsView(parent, controller, m_proxyModel);
m_detailsView = new DolphinDetailsView(parent,
dolphinViewController,
viewModeController,
m_proxyModel);
break;
case ColumnView:
m_columnsContainer = new DolphinColumnViewContainer(parent, controller);
m_columnsContainer = new DolphinColumnViewContainer(parent,
dolphinViewController,
viewModeController);
break;
default:
@ -1563,7 +1578,7 @@ KDirLister* DolphinView::ViewAccessor::dirLister() const
void DolphinView::slotRedirection(const KUrl& oldUrl, const KUrl& newUrl)
{
emit redirection(oldUrl, newUrl);
m_controller->redirectToUrl(newUrl); // #186947
m_viewModeController->redirectToUrl(newUrl); // #186947
}
void DolphinView::restoreContentsPosition()

View file

@ -41,17 +41,18 @@
typedef KIO::FileUndoManager::CommandType CommandType;
class DolphinController;
class DolphinColumnViewContainer;
class DolphinDetailsView;
class DolphinIconsView;
class DolphinModel;
class DolphinSortFilterProxyModel;
class DolphinViewController;
class KFilePreviewGenerator;
class KAction;
class KActionCollection;
class KDirLister;
class KUrl;
class ViewModeController;
class ViewProperties;
class DolphinDetailsViewExpander;
@ -132,7 +133,7 @@ public:
* Returns the current active URL, where all actions are applied.
* The URL navigator is synchronized with this URL.
*/
const KUrl& url() const;
KUrl url() const;
/**
* Returns the root URL of the view, which is defined as the first
@ -727,7 +728,10 @@ private:
ViewAccessor(DolphinSortFilterProxyModel* proxyModel);
~ViewAccessor();
void createView(QWidget* parent, DolphinController* controller, Mode mode);
void createView(QWidget* parent,
DolphinViewController* dolphinViewController,
const ViewModeController* viewModeController,
Mode mode);
void deleteView();
/**
@ -786,7 +790,8 @@ private:
QVBoxLayout* m_topLayout;
DolphinController* m_controller;
DolphinViewController* m_dolphinViewController;
ViewModeController* m_viewModeController;
ViewAccessor m_viewAccessor;
QItemSelectionModel* m_selectionModel; // allow to switch views without losing the selection

View file

@ -48,9 +48,10 @@
#include <kurlnavigator.h>
#include <krun.h>
#include "dolphin_generalsettings.h"
#include "dolphinmodel.h"
#include "dolphincolumnview.h"
#include "dolphincontroller.h"
#include "dolphinviewcontroller.h"
#include "dolphinmainwindow.h"
#include "dolphindirlister.h"
#include "dolphinsortfilterproxymodel.h"
@ -58,10 +59,10 @@
#include "dolphiniconsview.h"
#include "draganddrophelper.h"
#include "filterbar.h"
#include "statusbar/dolphinstatusbar.h"
#include "viewproperties.h"
#include "settings/dolphinsettings.h"
#include "dolphin_generalsettings.h"
#include "statusbar/dolphinstatusbar.h"
#include "viewmodecontroller.h"
#include "viewproperties.h"
DolphinViewContainer::DolphinViewContainer(const KUrl& url, QWidget* parent) :
QWidget(parent),

View file

@ -1,5 +1,5 @@
/***************************************************************************
* Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
* Copyright (C) 2010 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 *
@ -14,10 +14,10 @@
* 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 *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "dolphincontroller.h"
#include "dolphinviewcontroller.h"
#include "zoomlevelinfo.h"
#include <kdirmodel.h>
@ -26,38 +26,31 @@
#include <QClipboard>
#include <QDir>
Qt::MouseButtons DolphinController::m_mouseButtons = Qt::NoButton;
Qt::MouseButtons DolphinViewController::m_mouseButtons = Qt::NoButton;
DolphinController::DolphinController(DolphinView* dolphinView) :
DolphinViewController::DolphinViewController(DolphinView* dolphinView) :
QObject(dolphinView),
m_zoomLevel(0),
m_nameFilter(),
m_url(),
m_dolphinView(dolphinView),
m_itemView(0),
m_versionControlActions()
{
}
DolphinController::~DolphinController()
DolphinViewController::~DolphinViewController()
{
}
void DolphinController::setUrl(const KUrl& url)
const DolphinView* DolphinViewController::view() const
{
if (m_url != url) {
m_url = url;
emit cancelPreviews();
emit urlChanged(url);
}
return m_dolphinView;
}
void DolphinController::redirectToUrl(const KUrl& url)
void DolphinViewController::requestUrlChange(const KUrl& url)
{
m_url = url;
emit urlChangeRequested(url);
}
void DolphinController::setItemView(QAbstractItemView* view)
void DolphinViewController::setItemView(QAbstractItemView* view)
{
if (m_itemView != 0) {
disconnect(m_itemView, SIGNAL(pressed(const QModelIndex&)),
@ -67,27 +60,30 @@ void DolphinController::setItemView(QAbstractItemView* view)
m_itemView = view;
if (m_itemView != 0) {
m_zoomLevel = ZoomLevelInfo::zoomLevelForIconSize(m_itemView->iconSize());
// TODO: this is a workaround until Qt-issue 176832 has been fixed
connect(m_itemView, SIGNAL(pressed(const QModelIndex&)),
this, SLOT(updateMouseButtonState()));
}
}
void DolphinController::triggerContextMenuRequest(const QPoint& pos,
QAbstractItemView* DolphinViewController::itemView() const
{
return m_itemView;
}
void DolphinViewController::triggerContextMenuRequest(const QPoint& pos,
const QList<QAction*>& customActions)
{
emit activated();
emit requestContextMenu(pos, customActions);
}
void DolphinController::requestActivation()
void DolphinViewController::requestActivation()
{
emit activated();
}
void DolphinController::indicateDroppedUrls(const KFileItem& destItem,
void DolphinViewController::indicateDroppedUrls(const KFileItem& destItem,
const KUrl& destPath,
QDropEvent* event)
{
@ -95,69 +91,41 @@ void DolphinController::indicateDroppedUrls(const KFileItem& destItem,
}
void DolphinController::indicateSortingChange(DolphinView::Sorting sorting)
void DolphinViewController::indicateSortingChange(DolphinView::Sorting sorting)
{
emit sortingChanged(sorting);
}
void DolphinController::indicateSortOrderChange(Qt::SortOrder order)
void DolphinViewController::indicateSortOrderChange(Qt::SortOrder order)
{
emit sortOrderChanged(order);
}
void DolphinController::indicateSortFoldersFirstChange(bool foldersFirst)
void DolphinViewController::indicateSortFoldersFirstChange(bool foldersFirst)
{
emit sortFoldersFirstChanged(foldersFirst);
}
void DolphinController::indicateAdditionalInfoChange(const KFileItemDelegate::InformationList& info)
void DolphinViewController::indicateAdditionalInfoChange(const KFileItemDelegate::InformationList& info)
{
emit additionalInfoChanged(info);
}
void DolphinController::indicateActivationChange(bool active)
{
emit activationChanged(active);
}
void DolphinController::setNameFilter(const QString& nameFilter)
{
if (nameFilter != m_nameFilter) {
m_nameFilter = nameFilter;
emit nameFilterChanged(nameFilter);
}
}
QString DolphinController::nameFilter() const
{
return m_nameFilter;
}
void DolphinController::setZoomLevel(int level)
{
Q_ASSERT(level >= ZoomLevelInfo::minimumLevel());
Q_ASSERT(level <= ZoomLevelInfo::maximumLevel());
if (level != m_zoomLevel) {
m_zoomLevel = level;
emit zoomLevelChanged(m_zoomLevel);
}
}
void DolphinController::setVersionControlActions(QList<QAction*> actions)
void DolphinViewController::setVersionControlActions(QList<QAction*> actions)
{
m_versionControlActions = actions;
}
QList<QAction*> DolphinController::versionControlActions(const KFileItemList& items)
QList<QAction*> DolphinViewController::versionControlActions(const KFileItemList& items)
{
emit requestVersionControlActions(items);
// All view implementations are connected with the signal requestVersionControlActions()
// (see ViewExtensionFactory) and will invoke DolphinController::setVersionControlActions(),
// (see ViewExtensionFactory) and will invoke DolphinViewController::setVersionControlActions(),
// so that the context dependent actions can be returned.
return m_versionControlActions;
}
void DolphinController::handleKeyPressEvent(QKeyEvent* event)
void DolphinViewController::handleKeyPressEvent(QKeyEvent* event)
{
Q_ASSERT(m_itemView != 0);
@ -194,7 +162,7 @@ void DolphinController::handleKeyPressEvent(QKeyEvent* event)
}
}
void DolphinController::replaceUrlByClipboard()
void DolphinViewController::replaceUrlByClipboard()
{
const QClipboard* clipboard = QApplication::clipboard();
QString text;
@ -208,17 +176,17 @@ void DolphinController::replaceUrlByClipboard()
}
}
void DolphinController::emitHideToolTip()
void DolphinViewController::requestToolTipHiding()
{
emit hideToolTip();
}
void DolphinController::emitItemTriggered(const KFileItem& item)
void DolphinViewController::emitItemTriggered(const KFileItem& item)
{
emit itemTriggered(item);
}
KFileItem DolphinController::itemForIndex(const QModelIndex& index) const
KFileItem DolphinViewController::itemForIndex(const QModelIndex& index) const
{
Q_ASSERT(m_itemView != 0);
@ -228,7 +196,7 @@ KFileItem DolphinController::itemForIndex(const QModelIndex& index) const
return dirModel->itemForIndex(dirIndex);
}
void DolphinController::triggerItem(const QModelIndex& index)
void DolphinViewController::triggerItem(const QModelIndex& index)
{
if (m_mouseButtons & Qt::LeftButton) {
const KFileItem item = itemForIndex(index);
@ -241,7 +209,7 @@ void DolphinController::triggerItem(const QModelIndex& index)
}
}
void DolphinController::requestTab(const QModelIndex& index)
void DolphinViewController::requestTab(const QModelIndex& index)
{
if (m_mouseButtons & Qt::MidButton) {
const KFileItem item = itemForIndex(index);
@ -254,7 +222,7 @@ void DolphinController::requestTab(const QModelIndex& index)
}
}
void DolphinController::emitItemEntered(const QModelIndex& index)
void DolphinViewController::emitItemEntered(const QModelIndex& index)
{
KFileItem item = itemForIndex(index);
if (!item.isNull()) {
@ -262,14 +230,14 @@ void DolphinController::emitItemEntered(const QModelIndex& index)
}
}
void DolphinController::emitViewportEntered()
void DolphinViewController::emitViewportEntered()
{
emit viewportEntered();
}
void DolphinController::updateMouseButtonState()
void DolphinViewController::updateMouseButtonState()
{
m_mouseButtons = QApplication::mouseButtons();
}
#include "dolphincontroller.moc"
#include "dolphinviewcontroller.moc"

View file

@ -1,5 +1,5 @@
/***************************************************************************
* Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
* Copyright (C) 2010 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 *
@ -14,11 +14,11 @@
* 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 *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#ifndef DOLPHINCONTROLLER_H
#define DOLPHINCONTROLLER_H
#ifndef DOLPHINVIEWCONTROLLER_H
#define DOLPHINVIEWCONTROLLER_H
#include <dolphinview.h>
#include <kurl.h>
@ -31,86 +31,44 @@ class KUrl;
class QPoint;
/**
* @brief Acts as mediator between the abstract Dolphin view and the view
* implementations.
* @brief Allows the view mode implementations (DolphinIconsView, DolphinDetailsView, DolphinColumnView)
* to do a limited control of the DolphinView.
*
* The abstract Dolphin view (see DolphinView) represents the parent of the controller.
* The lifetime of the controller is equal to the lifetime of the Dolphin view.
* The controller is passed to the current view implementation
* (see DolphinIconsView, DolphinDetailsView and DolphinColumnView)
* by passing it in the constructor and informing the controller about the change
* of the view implementation:
*
* \code
* QAbstractItemView* view = new DolphinIconsView(parent, controller);
* controller->setItemView(view);
* \endcode
*
* The communication of the view implementations to the abstract view is done by:
* - triggerContextMenuRequest()
* - requestActivation()
* - indicateDroppedUrls()
* - indicateSortingChange()
* - indicateSortOrderChanged()
* - indicateSortFoldersFirstChanged()
* - triggerItem()
* - requestTab()
* - handleKeyPressEvent()
* - emitItemEntered()
* - emitViewportEntered()
* - replaceUrlByClipboard()
* - hideToolTip()
* - setVersionControlActions()
*
* The communication of the abstract view to the view implementations is done by:
* - setUrl()
* - indicateActivationChange()
* - setNameFilter()
* - setZoomLevel()
* - versionControlActions()
* The DolphinView connects to the signals of DolphinViewController to react on changes
* that have been triggered by the view mode implementations. The view mode implementations
* have read access to the whole DolphinView by DolphinViewController::view(). Limited control of the
* DolphinView by the view mode implementations are defined by the public DolphinController methods.
*/
class LIBDOLPHINPRIVATE_EXPORT DolphinController : public QObject
class LIBDOLPHINPRIVATE_EXPORT DolphinViewController : public QObject
{
Q_OBJECT
public:
explicit DolphinController(DolphinView* dolphinView);
virtual ~DolphinController();
explicit DolphinViewController(DolphinView* dolphinView);
virtual ~DolphinViewController();
/**
* Allows read access for the view implementation to the abstract
* Dolphin view.
* Allows read access for the view mode implementation
* to the DolphinView.
*/
const DolphinView* dolphinView() const;
const DolphinView* view() const;
/**
* Sets the URL to \a url and emits the signal urlChanged() if
* \a url is different for the current URL. This method should
* be invoked by the abstract Dolphin view whenever the current
* URL has been changed.
* Requests the DolphinView to change the URL to \p url. The signal
* urlChangeRequested will be emitted.
*/
void setUrl(const KUrl& url);
const KUrl& url() const;
void requestUrlChange(const KUrl& url);
/**
* Sets the URL to \a url and does nothing else. Called when
* a redirection happens.
*/
void redirectToUrl(const KUrl& url);
/**
* Changes the current item view where the controller is working. This
* is only necessary for views like the tree view, where internally
* Changes the current view mode implementation where the controller is working.
* This is only necessary for views like the tree view, where internally
* several QAbstractItemView instances are used.
*/
void setItemView(QAbstractItemView* view);
QAbstractItemView* itemView() const;
/**
* Requests a context menu for the position \a pos. This method
* should be invoked by the view implementation when a context
* menu should be opened. The abstract Dolphin view itself
* Requests a context menu for the position \a pos. DolphinView
* takes care itself to get the selected items depending from
* \a pos. It is possible to define a custom list of actions for
* the context menu by \a customActions.
@ -119,17 +77,14 @@ public:
const QList<QAction*>& customActions = QList<QAction*>());
/**
* Requests an activation of the view and emits the signal
* activated(). This method should be invoked by the view implementation
* Requests an activation of the DolphinView and emits the signal
* activated(). This method should be invoked by the view mode implementation
* if e. g. a mouse click on the view has been done.
* After the activation has been changed, the view implementation
* might listen to the activationChanged() signal.
*/
void requestActivation();
/**
* Indicates that URLs are dropped above a destination. This method
* should be invoked by the view implementation. The abstract Dolphin view
* Indicates that URLs are dropped above a destination. The DolphinView
* will start the corresponding action (copy, move, link).
* @param destItem Item of the destination (can be null, see KFileItem::isNull()).
* @param destPath Path of the destination.
@ -140,110 +95,75 @@ public:
QDropEvent* event);
/**
* Informs the abstract Dolphin view about a sorting change done inside
* the view implementation. This method should be invoked by the view
* implementation (e. g. the details view uses this method in combination
* with the details header).
* Informs the DolphinView about a sorting change done inside
* the view mode implementation.
*/
void indicateSortingChange(DolphinView::Sorting sorting);
/**
* Informs the abstract Dolphin view about a sort order change done inside
* the view implementation. This method should be invoked by the view
* implementation (e. g. the details view uses this method in combination
* with the details header).
* Informs the DolphinView about a sort order change done inside
* the view mode implementation.
*/
void indicateSortOrderChange(Qt::SortOrder order);
/**
* Informs the abstract Dolphin view about a change between separate sorting
* Informs the DolphinView about a change between separate sorting
* (with folders first) and mixed sorting of files and folders done inside
* the view implementation. This method should be invoked by the view
* implementation (e. g. the details view uses this method in combination
* with the details header).
* the view mode implementation.
*/
void indicateSortFoldersFirstChange(bool foldersFirst);
/**
* Informs the abstract Dolphin view about an additional information change
* done inside the view implementation. This method should be invoked by the
* view implementation (e. g. the details view uses this method in combination
* with the details header).
* Informs the DolphinView about an additional information change
* done inside the view mode implementation.
*/
void indicateAdditionalInfoChange(const KFileItemDelegate::InformationList& info);
/**
* Informs the view implementation about a change of the activation
* state and is invoked by the abstract Dolphin view. The signal
* activationChanged() is emitted.
*/
void indicateActivationChange(bool active);
/**
* Sets the zoom level to \a level and emits the signal zoomLevelChanged().
* It must be assured that the used level is inside the range
* DolphinController::zoomLevelMinimum() and
* DolphinController::zoomLevelMaximum().
* Is invoked by the abstract Dolphin view.
*/
void setZoomLevel(int level);
int zoomLevel() const;
/**
* Sets the available version control actions. Is called by the view
* implementation as soon as the controller has send the signal
* mode implementation as soon as the DolphinView has requested them by the signal
* requestVersionControlActions().
*/
void setVersionControlActions(QList<QAction*> actions);
/**
* Returns the version control actions that are provided for the items \p items.
* Is called by the abstract Dolphin view to show the version control actions
* inside the context menu.
* Emits the signal requestVersionControlActions(). The view mode implementation
* listens to the signal and will invoke a DolphinViewController::setVersionControlActions()
* and the result will be returned.
*/
QList<QAction*> versionControlActions(const KFileItemList& items);
/**
* Sets the name filter to \a and emits the signal nameFilterChanged().
*/
void setNameFilter(const QString& nameFilter);
QString nameFilter() const;
/**
* Tells the view implementation to zoom out by emitting the signal zoomOut()
* and is invoked by the abstract Dolphin view.
*/
void triggerZoomOut();
/**
* Should be invoked in each view implementation whenever a key has been
* Must be be invoked in each view mode implementation whenever a key has been
* pressed. If the selection model of \a view is not empty and
* the return key has been pressed, the selected items will get triggered.
*/
void handleKeyPressEvent(QKeyEvent* event);
/**
* Replaces the URL of the abstract Dolphin view with the content
* Replaces the URL of the DolphinView with the content
* of the clipboard as URL. If the clipboard contains no text,
* nothing will be done.
*/
void replaceUrlByClipboard();
/** Emits the signal hideToolTip(). */
void emitHideToolTip();
/**
* Requests the view mode implementation to hide tooltips.
*/
void requestToolTipHiding();
/**
* Emits the signal itemTriggered() for the item \a item.
* The method can be used by the view implementations to
* The method can be used by the view mode implementations to
* trigger an item directly without mouse interaction.
* If the item triggering is done by the mouse, it is recommended
* to use QAbstractItemView::triggerItem(), as this will check
* to use DolphinViewController::triggerItem(), as this will check
* the used mouse buttons to execute the correct action.
*/
void emitItemTriggered(const KFileItem& item);
/**
* Returns the file item for the proxy index \a index of the view \a view.
* Returns the file item for the proxy index \a index of the DolphinView.
*/
KFileItem itemForIndex(const QModelIndex& index) const;
@ -252,7 +172,7 @@ public slots:
* Emits the signal itemTriggered() if the file item for the index \a index
* is not null and the left mouse button has been pressed. If the item is
* null, the signal itemEntered() is emitted.
* The method should be invoked by the view implementations whenever the
* The method should be invoked by the view mode implementations whenever the
* user has triggered an item with the mouse (see
* QAbstractItemView::clicked() or QAbstractItemView::doubleClicked()).
*/
@ -261,33 +181,27 @@ public slots:
/**
* Emits the signal tabRequested(), if the file item for the index \a index
* represents a directory and when the middle mouse button has been pressed.
* The method should be invoked by the view implementation.
*/
void requestTab(const QModelIndex& index);
/**
* Emits the signal itemEntered() if the file item for the index \a index
* is not null. The method should be invoked by the view implementation
* is not null. The method should be invoked by the view mode implementation
* whenever the mouse cursor is above an item.
*/
void emitItemEntered(const QModelIndex& index);
/**
* Emits the signal viewportEntered(). The method should be invoked by
* the view implementation whenever the mouse cursor is above the viewport.
* the view mode implementation whenever the mouse cursor is above the viewport.
*/
void emitViewportEntered();
signals:
/**
* Is emitted if the URL for the Dolphin controller has been changed
* to \a url.
*/
void urlChanged(const KUrl& url);
void urlChangeRequested(const KUrl& url);
/**
* Is emitted if a context menu should be opened (see triggerContextMenuRequest()).
* The abstract Dolphin view connects to this signal and will open the context menu.
* @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
@ -299,8 +213,6 @@ signals:
/**
* Is emitted if the view has been activated by e. g. a mouse click.
* The abstract Dolphin view connects to this signal to know the
* destination view for the menu actions.
*/
void activated();
@ -316,43 +228,35 @@ signals:
/**
* Is emitted if the sorting has been changed to \a sorting by
* the view implementation (see indicateSortingChanged().
* The abstract Dolphin view connects to
* the view mode implementation (see indicateSortingChanged().
* The DolphinView connects to
* this signal to update its menu action.
*/
void sortingChanged(DolphinView::Sorting sorting);
/**
* Is emitted if the sort order has been changed to \a order
* by the view implementation (see indicateSortOrderChanged().
* The abstract Dolphin view connects
* by the view mode implementation (see indicateSortOrderChanged().
* The DolphinView connects
* to this signal to update its menu actions.
*/
void sortOrderChanged(Qt::SortOrder order);
/**
* Is emitted if 'sort folders first' has been changed to \a foldersFirst
* by the view implementation (see indicateSortOrderChanged().
* The abstract Dolphin view connects
* by the view mode implementation (see indicateSortOrderChanged().
* The DolphinView connects
* to this signal to update its menu actions.
*/
void sortFoldersFirstChanged(bool foldersFirst);
/**
* Is emitted if the additional info has been changed to \a info
* by the view implementation. The abstract Dolphin view connects
* by the view mode implementation. The DolphinView connects
* to this signal to update its menu actions.
*/
void additionalInfoChanged(const KFileItemDelegate::InformationList& info);
/**
* Is emitted if the activation state has been changed to \a active
* by the abstract Dolphin view.
* The view implementation might connect to this signal if custom
* updates are required in this case.
*/
void activationChanged(bool active);
/**
* Is emitted if the item \a item should be triggered. The abstract
* Dolphin view connects to this signal. If the item represents a directory,
@ -364,7 +268,6 @@ signals:
/**
* Is emitted if the mouse cursor has entered the item
* given by \a index (see emitItemEntered()).
* The abstract Dolphin view connects to this signal.
*/
void itemEntered(const KFileItem& item);
@ -376,24 +279,12 @@ signals:
/**
* Is emitted if the mouse cursor has entered
* the viewport (see emitViewportEntered()).
* The abstract Dolphin view connects to this signal.
*/
void viewportEntered();
/**
* Is emitted if the view should respect the name filter \a nameFilter. The view
* implementation must connect to this signal if it supports name filters.
*/
void nameFilterChanged(const QString& nameFilter);
/**
* Is emitted if the view should change the zoom to \a level. The view implementation
* must connect to this signal if it supports zooming.
*/
void zoomLevelChanged(int level);
/**
* Is emitted if the abstract view should hide an open tooltip.
* Is emitted, if DolphinViewController::requestToolTipHiding() is invoked
* and requests to hide all tooltips.
*/
void hideToolTip();
@ -403,9 +294,9 @@ signals:
void cancelPreviews();
/**
* Requests the view implementation to invoke DolphinController::setVersionControlActions(),
* so that they can be returned with DolphinController::versionControlActions() for
* the abstract Dolphin view.
* Requests the view mode implementation to invoke DolphinViewController::setVersionControlActions(),
* so that they can be returned with DolphinViewController::versionControlActions() for
* the DolphinView.
*/
void requestVersionControlActions(const KFileItemList& items);
@ -413,33 +304,11 @@ private slots:
void updateMouseButtonState();
private:
int m_zoomLevel;
QString m_nameFilter;
static Qt::MouseButtons m_mouseButtons; // TODO: this is a workaround until Qt-issue 176832 has been fixed
KUrl m_url;
DolphinView* m_dolphinView;
QAbstractItemView* m_itemView;
QList<QAction*> m_versionControlActions;
};
inline const DolphinView* DolphinController::dolphinView() const
{
return m_dolphinView;
}
inline const KUrl& DolphinController::url() const
{
return m_url;
}
inline QAbstractItemView* DolphinController::itemView() const
{
return m_itemView;
}
inline int DolphinController::zoomLevel() const
{
return m_zoomLevel;
}
#endif

View file

@ -20,7 +20,7 @@
#include "draganddrophelper.h"
#include "dolphiniconsview.h"
#include "dolphincontroller.h"
#include "dolphinviewcontroller.h"
#include <kdirmodel.h>
#include <kfileitem.h>
@ -53,7 +53,7 @@ bool DragAndDropHelper::isMimeDataSupported(const QMimeData* mimeData) const
void DragAndDropHelper::startDrag(QAbstractItemView* itemView,
Qt::DropActions supportedActions,
DolphinController* controller)
DolphinViewController* dolphinViewController)
{
// Do not start a new drag until the previous one has been finished.
// This is a (possibly temporary) fix for bug #187884.
@ -70,8 +70,8 @@ void DragAndDropHelper::startDrag(QAbstractItemView* itemView,
return;
}
if (controller != 0) {
controller->emitHideToolTip();
if (dolphinViewController != 0) {
dolphinViewController->requestToolTipHiding();
}
QDrag* drag = new QDrag(itemView);

View file

@ -24,7 +24,7 @@
#include "libdolphin_export.h"
#include <QObject>
class DolphinController;
class DolphinViewController;
class KFileItem;
class KUrl;
class QDropEvent;
@ -57,7 +57,7 @@ public:
*/
void startDrag(QAbstractItemView* itemView,
Qt::DropActions supportedActions,
DolphinController* controller = 0);
DolphinViewController* dolphinViewController = 0);
/**
* Returns true if and only if the view \a itemView was the last view to

View file

@ -19,9 +19,10 @@
#include "paneltreeview.h"
#include "dolphincontroller.h"
#include "dolphinviewcontroller.h"
#include "dolphinmodel.h"
#include "draganddrophelper.h"
#include "viewmodecontroller.h"
#include <kfileitemdelegate.h>
#include <QKeyEvent>

View file

@ -19,16 +19,17 @@
#include "viewextensionsfactory.h"
#include "dolphincontroller.h"
#include "dolphinfileitemdelegate.h"
#include "dolphinsortfilterproxymodel.h"
#include "dolphinview.h"
#include "dolphinviewcontroller.h"
#include "dolphinviewautoscroller.h"
#include "folderexpander.h"
#include "selectionmanager.h"
#include "settings/dolphinsettings.h"
#include "tooltips/tooltipmanager.h"
#include "versioncontrol/versioncontrolobserver.h"
#include "viewmodecontroller.h"
#include "dolphin_generalsettings.h"
@ -38,10 +39,11 @@
#include <QAbstractItemView>
ViewExtensionsFactory::ViewExtensionsFactory(QAbstractItemView* view,
DolphinController* controller) :
DolphinViewController* dolphinViewController,
const ViewModeController* viewModeController) :
QObject(view),
m_view(view),
m_controller(controller),
m_dolphinViewController(dolphinViewController),
m_toolTipManager(0),
m_previewGenerator(0),
m_selectionManager(0),
@ -58,19 +60,19 @@ ViewExtensionsFactory::ViewExtensionsFactory(QAbstractItemView* view,
DolphinSortFilterProxyModel* proxyModel = static_cast<DolphinSortFilterProxyModel*>(view->model());
m_toolTipManager = new ToolTipManager(view, proxyModel);
connect(controller, SIGNAL(hideToolTip()),
connect(viewModeController, SIGNAL(hideToolTip()),
m_toolTipManager, SLOT(hideTip()));
}
// initialize preview generator
Q_ASSERT(view->iconSize().isValid());
m_previewGenerator = new KFilePreviewGenerator(view);
m_previewGenerator->setPreviewShown(controller->dolphinView()->showPreview());
connect(controller, SIGNAL(zoomLevelChanged(int)),
m_previewGenerator->setPreviewShown(dolphinViewController->view()->showPreview());
connect(viewModeController, SIGNAL(zoomLevelChanged(int)),
this, SLOT(slotZoomLevelChanged()));
connect(controller, SIGNAL(cancelPreviews()),
connect(viewModeController, SIGNAL(cancelPreviews()),
this, SLOT(cancelPreviews()));
connect(controller->dolphinView(), SIGNAL(showPreviewChanged()),
connect(dolphinViewController->view(), SIGNAL(showPreviewChanged()),
this, SLOT(slotShowPreviewChanged()));
// initialize selection manager
@ -78,7 +80,7 @@ ViewExtensionsFactory::ViewExtensionsFactory(QAbstractItemView* view,
m_selectionManager = new SelectionManager(view);
connect(m_selectionManager, SIGNAL(selectionChanged()),
this, SLOT(requestActivation()));
connect(controller, SIGNAL(urlChanged(const KUrl&)),
connect(viewModeController, SIGNAL(urlChanged(const KUrl&)),
m_selectionManager, SLOT(reset()));
}
@ -91,7 +93,7 @@ ViewExtensionsFactory::ViewExtensionsFactory(QAbstractItemView* view,
view->setItemDelegate(m_fileItemDelegate);
// initialize version control observer
const DolphinView* dolphinView = controller->dolphinView();
const DolphinView* dolphinView = dolphinViewController->view();
m_versionControlObserver = new VersionControlObserver(view);
connect(m_versionControlObserver, SIGNAL(infoMessage(const QString&)),
dolphinView, SIGNAL(infoMessage(const QString&)));
@ -99,7 +101,7 @@ ViewExtensionsFactory::ViewExtensionsFactory(QAbstractItemView* view,
dolphinView, SIGNAL(errorMessage(const QString&)));
connect(m_versionControlObserver, SIGNAL(operationCompletedMessage(const QString&)),
dolphinView, SIGNAL(operationCompletedMessage(const QString&)));
connect(controller, SIGNAL(requestVersionControlActions(const KFileItemList&)),
connect(dolphinViewController, SIGNAL(requestVersionControlActions(const KFileItemList&)),
this, SLOT(slotRequestVersionControlActions(const KFileItemList&)));
// react on view property changes
@ -118,10 +120,10 @@ ViewExtensionsFactory::ViewExtensionsFactory(QAbstractItemView* view,
m_folderExpander = new FolderExpander(view, proxyModel());
m_folderExpander->setEnabled(settings->autoExpandFolders());
connect(m_folderExpander, SIGNAL(enterDir(const QModelIndex&)),
controller, SLOT(triggerItem(const QModelIndex&)));
dolphinViewController, SLOT(triggerItem(const QModelIndex&)));
// react on namefilter changes
connect(controller, SIGNAL(nameFilterChanged(const QString&)),
connect(viewModeController, SIGNAL(nameFilterChanged(const QString&)),
this, SLOT(slotNameFilterChanged(const QString&)));
view->viewport()->installEventFilter(this);
@ -175,7 +177,7 @@ void ViewExtensionsFactory::cancelPreviews()
void ViewExtensionsFactory::slotShowPreviewChanged()
{
const bool show = m_controller->dolphinView()->showPreview();
const bool show = m_dolphinViewController->view()->showPreview();
m_previewGenerator->setPreviewShown(show);
}
@ -186,7 +188,7 @@ void ViewExtensionsFactory::slotShowHiddenFilesChanged()
dirLister->stop();
const bool show = m_controller->dolphinView()->showHiddenFiles();
const bool show = m_dolphinViewController->view()->showHiddenFiles();
dirLister->setShowingDotFiles(show);
const KUrl url = dirLister->url();
@ -225,12 +227,12 @@ void ViewExtensionsFactory::slotRequestVersionControlActions(const KFileItemList
} else {
actions = m_versionControlObserver->contextMenuActions(items);
}
m_controller->setVersionControlActions(actions);
m_dolphinViewController->setVersionControlActions(actions);
}
void ViewExtensionsFactory::requestActivation()
{
m_controller->requestActivation();
m_dolphinViewController->requestActivation();
}
DolphinSortFilterProxyModel* ViewExtensionsFactory::proxyModel() const

View file

@ -24,7 +24,6 @@
#include "dolphinview.h"
class DolphinController;
class DolphinFileItemDelegate;
class DolphinSortFilterProxyModel;
class DolphinViewAutoScroller;
@ -35,6 +34,7 @@ class SelectionManager;
class ToolTipManager;
class QAbstractItemView;
class VersionControlObserver;
class ViewModeController;
/**
* @brief Responsible for creating extensions like tooltips and previews
@ -51,7 +51,8 @@ class ViewExtensionsFactory : public QObject
public:
explicit ViewExtensionsFactory(QAbstractItemView* view,
DolphinController* controller);
DolphinViewController* dolphinViewController,
const ViewModeController* viewModeController);
virtual ~ViewExtensionsFactory();
/**
@ -90,7 +91,7 @@ private:
private:
QAbstractItemView* m_view;
DolphinController* m_controller;
DolphinViewController* m_dolphinViewController;
ToolTipManager* m_toolTipManager;
KFilePreviewGenerator* m_previewGenerator;
SelectionManager* m_selectionManager;

View file

@ -0,0 +1,88 @@
/***************************************************************************
* Copyright (C) 2010 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 "viewmodecontroller.h"
#include "zoomlevelinfo.h"
ViewModeController::ViewModeController(QObject* parent) :
QObject(parent),
m_zoomLevel(0),
m_nameFilter(),
m_url()
{
}
ViewModeController::~ViewModeController()
{
}
KUrl ViewModeController::url() const
{
return m_url;
}
void ViewModeController::redirectToUrl(const KUrl& url)
{
m_url = url;
}
void ViewModeController::indicateActivationChange(bool active)
{
emit activationChanged(active);
}
void ViewModeController::setNameFilter(const QString& nameFilter)
{
if (nameFilter != m_nameFilter) {
m_nameFilter = nameFilter;
emit nameFilterChanged(nameFilter);
}
}
QString ViewModeController::nameFilter() const
{
return m_nameFilter;
}
void ViewModeController::setZoomLevel(int level)
{
Q_ASSERT(level >= ZoomLevelInfo::minimumLevel());
Q_ASSERT(level <= ZoomLevelInfo::maximumLevel());
if (level != m_zoomLevel) {
m_zoomLevel = level;
emit zoomLevelChanged(m_zoomLevel);
}
}
int ViewModeController::zoomLevel() const
{
return m_zoomLevel;
}
void ViewModeController::setUrl(const KUrl& url)
{
if (m_url != url) {
m_url = url;
emit cancelPreviews();
emit urlChanged(url);
}
}
#include "viewmodecontroller.moc"

124
src/viewmodecontroller.h Normal file
View file

@ -0,0 +1,124 @@
/***************************************************************************
* Copyright (C) 2010 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 VIEWMODECONTROLLER_H
#define VIEWMODECONTROLLER_H
#include <dolphinview.h>
#include <kurl.h>
#include <QObject>
#include <libdolphin_export.h>
/**
* @brief Allows the DolphinView to control the view implementations for the
* different view modes.
*
* The view implementations (DolphinIconsView, DolphinDetailsView, DolphinColumnView)
* connect to signals of the ViewModeController to react on changes. The view
* implementations get only read-access to the ViewModeController.
*/
class LIBDOLPHINPRIVATE_EXPORT ViewModeController : public QObject
{
Q_OBJECT
public:
explicit ViewModeController(QObject* parent = 0);
virtual ~ViewModeController();
/**
* @return URL that is shown by the view mode implementation.
*/
KUrl url() const;
/**
* Sets the URL to \a url and does nothing else. Called when
* a redirection happens. See ViewModeController::setUrl()
*/
void redirectToUrl(const KUrl& url);
/**
* Informs the view mode implementation about a change of the activation
* state by emitting the signal activationChanged().
*/
void indicateActivationChange(bool active);
/**
* Sets the zoom level to \a level and emits the signal zoomLevelChanged().
* It must be assured that the used level is inside the range
* ViewModeController::zoomLevelMinimum() and
* ViewModeController::zoomLevelMaximum().
*/
void setZoomLevel(int level);
int zoomLevel() const;
/**
* Sets the name filter to \a and emits the signal nameFilterChanged().
*/
void setNameFilter(const QString& nameFilter);
QString nameFilter() const;
/**
* Requests the view mode implementation to hide tooltips.
*/
void requestToolTipHiding();
public slots:
/**
* Sets the URL to \a url and emits the signals cancelPreviews() and
* urlChanged() if \a url is different for the current URL.
*/
void setUrl(const KUrl& url);
signals:
/**
* Is emitted if the URL has been changed by ViewModeController::setUrl().
*/
void urlChanged(const KUrl& url);
/**
* Is emitted, if ViewModeController::indicateActivationChange() has been
* invoked. The view mode implementation may update its visual state
* to represent the activation state.
*/
void activationChanged(bool active);
/**
* Is emitted if the name filter has been changed by
* ViewModeController::setNameFilter().
*/
void nameFilterChanged(const QString& nameFilter);
/**
* Is emitted if the zoom level has been changed by
* ViewModeController::setZoomLevel().
*/
void zoomLevelChanged(int level);
/**
* Is emitted if pending previews should be canceled (e. g. because of an URL change).
*/
void cancelPreviews();
private:
int m_zoomLevel;
QString m_nameFilter;
KUrl m_url;
};
#endif