From bbf9faa05396d66b3dbe101a0c309459e3ffacb1 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Fri, 26 Oct 2007 19:02:33 +0000 Subject: [PATCH] Simplify DolphinController: don't remember the show-preview state in the controller and add an unnecessary additional signal; instead just read the state from the DolphinView svn path=/trunk/KDE/kdebase/apps/; revision=729726 --- src/dolphincolumnview.cpp | 13 ++++++++----- src/dolphincolumnview.h | 2 +- src/dolphincolumnwidget.cpp | 2 +- src/dolphincontroller.cpp | 9 --------- src/dolphincontroller.h | 22 ---------------------- src/dolphiniconsview.cpp | 32 +++++++++++++++++++------------- src/dolphiniconsview.h | 2 +- src/dolphinview.cpp | 16 +++++++++++----- src/dolphinview.h | 1 + 9 files changed, 42 insertions(+), 57 deletions(-) diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index 7f6b37830..f69dc207e 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -66,13 +66,15 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* control this, SLOT(zoomIn())); connect(controller, SIGNAL(zoomOut()), this, SLOT(zoomOut())); - connect(controller->dolphinView(), SIGNAL(showHiddenFilesChanged()), - this, SLOT(slotShowHiddenFilesChanged())); - connect(controller, SIGNAL(showPreviewChanged(bool)), - this, SLOT(slotShowPreviewChanged(bool))); connect(controller, SIGNAL(activationChanged(bool)), this, SLOT(updateColumnsBackground(bool))); + const DolphinView* view = controller->dolphinView(); + connect(view, SIGNAL(showHiddenFilesChanged()), + this, SLOT(slotShowHiddenFilesChanged())); + connect(view, SIGNAL(showPreviewChanged()), + this, SLOT(slotShowPreviewChanged())); + connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(moveContentHorizontally(int))); @@ -417,8 +419,9 @@ void DolphinColumnView::slotShowHiddenFilesChanged() } } -void DolphinColumnView::slotShowPreviewChanged(bool show) +void DolphinColumnView::slotShowPreviewChanged() { + const bool show = m_controller->dolphinView()->showPreview(); foreach (DolphinColumnWidget* column, m_columns) { column->setShowPreview(show); } diff --git a/src/dolphincolumnview.h b/src/dolphincolumnview.h index 1c972ad39..af393ce81 100644 --- a/src/dolphincolumnview.h +++ b/src/dolphincolumnview.h @@ -129,7 +129,7 @@ private slots: void updateColumnsBackground(bool active); void slotShowHiddenFilesChanged(); - void slotShowPreviewChanged(bool show); + void slotShowPreviewChanged(); private: bool isZoomInPossible() const; diff --git a/src/dolphincolumnwidget.cpp b/src/dolphincolumnwidget.cpp index c24ae50c2..c212e6ad8 100644 --- a/src/dolphincolumnwidget.cpp +++ b/src/dolphincolumnwidget.cpp @@ -336,7 +336,7 @@ void DolphinColumnWidget::generatePreviews(const KFileItemList& items) // TODO: same implementation as in DolphinView; create helper class // for generatePreviews(), showPreview() and isCutItem() - if (m_view->m_controller->showPreview()) { + if (m_view->m_controller->dolphinView()->showPreview()) { KIO::PreviewJob* job = KIO::filePreview(items, 128); connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)), this, SLOT(showPreview(const KFileItem&, const QPixmap&))); diff --git a/src/dolphincontroller.cpp b/src/dolphincontroller.cpp index bdb97170b..897d4266b 100644 --- a/src/dolphincontroller.cpp +++ b/src/dolphincontroller.cpp @@ -23,7 +23,6 @@ DolphinController::DolphinController(DolphinView* dolphinView) : QObject(dolphinView), - m_showPreview(false), m_zoomInPossible(false), m_zoomOutPossible(false), m_url(), @@ -85,14 +84,6 @@ void DolphinController::indicateAdditionalInfoChange(const KFileItemDelegate::In emit additionalInfoChanged(info); } -void DolphinController::setShowPreview(bool show) -{ - if (m_showPreview != show) { - m_showPreview = show; - emit showPreviewChanged(show); - } -} - void DolphinController::indicateActivationChange(bool active) { emit activationChanged(active); diff --git a/src/dolphincontroller.h b/src/dolphincontroller.h index d1b0799bf..c5f0e1a2b 100644 --- a/src/dolphincontroller.h +++ b/src/dolphincontroller.h @@ -159,14 +159,6 @@ public: */ void indicateAdditionalInfoChange(const KFileItemDelegate::InformationList& info); - /** - * Informs the view implementation about a change of the show preview - * state and is invoked by the abstract Dolphin view. - * The signal showPreviewChanged() is emitted. - */ - void setShowPreview(bool show); - bool showPreview() const; - /** * Informs the view implementation about a change of the activation * state and is invoked by the abstract Dolphin view. The signal @@ -290,14 +282,6 @@ signals: */ void additionalInfoChanged(const KFileItemDelegate::InformationList& info); - /** - * Is emitted if the state for showing previews has been - * changed to \a show by the abstract Dolphin view. - * The view implementation might connect to this signal if custom - * updates are required in this case. - */ - void showPreviewChanged(bool show); - /** * Is emitted if the activation state has been changed to \a active * by the abstract Dolphin view. @@ -341,7 +325,6 @@ signals: void zoomOut(); private: - bool m_showPreview; bool m_zoomInPossible; bool m_zoomOutPossible; KUrl m_url; @@ -358,11 +341,6 @@ inline const KUrl& DolphinController::url() const return m_url; } -inline bool DolphinController::showPreview() const -{ - return m_showPreview; -} - inline void DolphinController::setZoomInPossible(bool possible) { m_zoomInPossible = possible; diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index 5107d5697..30e47da89 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -61,15 +61,17 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle } connect(this, SIGNAL(viewportEntered()), controller, SLOT(emitViewportEntered())); - connect(controller, SIGNAL(showPreviewChanged(bool)), - this, SLOT(slotShowPreviewChanged(bool))); - connect(controller->dolphinView(), SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList&)), - this, SLOT(slotAdditionalInfoChanged(const KFileItemDelegate::InformationList&))); connect(controller, SIGNAL(zoomIn()), this, SLOT(zoomIn())); connect(controller, SIGNAL(zoomOut()), this, SLOT(zoomOut())); + const DolphinView* view = controller->dolphinView(); + connect(view, SIGNAL(showPreviewChanged()), + this, SLOT(slotShowPreviewChanged())); + connect(view, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList&)), + this, SLOT(slotAdditionalInfoChanged(const KFileItemDelegate::InformationList&))); + connect(this, SIGNAL(entered(const QModelIndex&)), this, SLOT(slotEntered(const QModelIndex&))); @@ -86,7 +88,7 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle m_viewOptions.font = font; setWordWrap(settings->numberOfTextlines() > 1); - updateGridSize(controller->showPreview(), 0); + updateGridSize(view->showPreview(), 0); if (settings->arrangement() == QListView::TopToBottom) { setFlow(QListView::LeftToRight); @@ -246,15 +248,17 @@ void DolphinIconsView::slotEntered(const QModelIndex& index) m_controller->emitItemEntered(itemForIndex(index)); } -void DolphinIconsView::slotShowPreviewChanged(bool showPreview) +void DolphinIconsView::slotShowPreviewChanged() { - const int infoCount = m_controller->dolphinView()->additionalInfo().count(); - updateGridSize(showPreview, infoCount); + const DolphinView* view = m_controller->dolphinView(); + const int infoCount = view->additionalInfo().count(); + updateGridSize(view->showPreview(), infoCount); } void DolphinIconsView::slotAdditionalInfoChanged(const KFileItemDelegate::InformationList& info) { - updateGridSize(m_controller->showPreview(), info.count()); + const bool showPreview = m_controller->dolphinView()->showPreview(); + updateGridSize(showPreview, info.count()); } void DolphinIconsView::zoomIn() @@ -265,7 +269,7 @@ void DolphinIconsView::zoomIn() const int oldIconSize = settings->iconSize(); int newIconSize = oldIconSize; - const bool showPreview = m_controller->showPreview(); + const bool showPreview = m_controller->dolphinView()->showPreview(); if (showPreview) { const int previewSize = increasedIconSize(settings->previewSize()); settings->setPreviewSize(previewSize); @@ -296,7 +300,7 @@ void DolphinIconsView::zoomOut() const int oldIconSize = settings->iconSize(); int newIconSize = oldIconSize; - const bool showPreview = m_controller->showPreview(); + const bool showPreview = m_controller->dolphinView()->showPreview(); if (showPreview) { const int previewSize = decreasedIconSize(settings->previewSize()); settings->setPreviewSize(previewSize); @@ -323,14 +327,16 @@ void DolphinIconsView::zoomOut() bool DolphinIconsView::isZoomInPossible() const { IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - const int size = m_controller->showPreview() ? settings->previewSize() : settings->iconSize(); + const bool showPreview = m_controller->dolphinView()->showPreview(); + const int size = showPreview ? settings->previewSize() : settings->iconSize(); return size < KIconLoader::SizeEnormous; } bool DolphinIconsView::isZoomOutPossible() const { IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - const int size = m_controller->showPreview() ? settings->previewSize() : settings->iconSize(); + const bool showPreview = m_controller->dolphinView()->showPreview(); + const int size = showPreview ? settings->previewSize() : settings->iconSize(); return size > KIconLoader::SizeSmall; } diff --git a/src/dolphiniconsview.h b/src/dolphiniconsview.h index 2b7d00bf0..ae0a6299d 100644 --- a/src/dolphiniconsview.h +++ b/src/dolphiniconsview.h @@ -64,7 +64,7 @@ protected: private slots: void triggerItem(const QModelIndex& index); void slotEntered(const QModelIndex& index); - void slotShowPreviewChanged(bool show); + void slotShowPreviewChanged(); void slotAdditionalInfoChanged(const KFileItemDelegate::InformationList& info); void zoomIn(); void zoomOut(); diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index c44afb219..c280b40d0 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -61,6 +61,7 @@ DolphinView::DolphinView(QWidget* parent, DolphinSortFilterProxyModel* proxyModel) : QWidget(parent), m_active(true), + m_showPreview(false), m_loadingDirectory(false), m_storedCategorizedSorting(false), m_mode(DolphinView::IconsView), @@ -227,11 +228,16 @@ DolphinView::Mode DolphinView::mode() const void DolphinView::setShowPreview(bool show) { + if (m_showPreview == show) { + return; + } + const KUrl viewPropsUrl = viewPropertiesUrl(); ViewProperties props(viewPropsUrl); props.setShowPreview(show); - m_controller->setShowPreview(show); + m_showPreview = show; + emit showPreviewChanged(); loadDirectory(viewPropsUrl, true); @@ -239,7 +245,7 @@ void DolphinView::setShowPreview(bool show) bool DolphinView::showPreview() const { - return m_controller->showPreview(); + return m_showPreview; } void DolphinView::setShowHiddenFiles(bool show) @@ -556,7 +562,7 @@ void DolphinView::triggerItem(const KFileItem& item) void DolphinView::generatePreviews(const KFileItemList& items) { - if (m_controller->showPreview()) { + if (m_controller->dolphinView()->showPreview()) { KIO::PreviewJob* job = KIO::filePreview(items, 128); connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)), this, SLOT(showPreview(const KFileItem&, const QPixmap&))); @@ -683,8 +689,8 @@ void DolphinView::applyViewProperties(const KUrl& url) } const bool showPreview = props.showPreview(); - if (showPreview != m_controller->showPreview()) { - m_controller->setShowPreview(showPreview); + if (showPreview != m_showPreview) { + m_showPreview = showPreview; emit showPreviewChanged(); } } diff --git a/src/dolphinview.h b/src/dolphinview.h index 9b56e85a8..442ff5a60 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -605,6 +605,7 @@ private: }; bool m_active; + bool m_showPreview; bool m_loadingDirectory; bool m_storedCategorizedSorting; Mode m_mode; -- 2.47.3