diff options
| author | Peter Penz <[email protected]> | 2007-03-01 19:36:37 +0000 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2007-03-01 19:36:37 +0000 |
| commit | a0cf8456fe171bd221025b3ff3677db4675390b5 (patch) | |
| tree | f75d81bc2bdc5b7c80b816fe09e6ecbfc12a3db4 /src | |
| parent | 84c32167c9c3082c7ce80ac613149a4f7596ba32 (diff) | |
Allow zooming in and zooming out in the icons view.
svn path=/trunk/KDE/kdebase/apps/; revision=638386
Diffstat (limited to 'src')
| -rw-r--r-- | src/dolphincontroller.cpp | 14 | ||||
| -rw-r--r-- | src/dolphincontroller.h | 16 | ||||
| -rw-r--r-- | src/dolphiniconsview.cpp | 93 | ||||
| -rw-r--r-- | src/dolphiniconsview.h | 13 | ||||
| -rw-r--r-- | src/dolphinmainwindow.cpp | 11 | ||||
| -rw-r--r-- | src/dolphinmainwindow.h | 2 | ||||
| -rw-r--r-- | src/dolphinview.cpp | 8 |
7 files changed, 143 insertions, 14 deletions
diff --git a/src/dolphincontroller.cpp b/src/dolphincontroller.cpp index e1d4c48e3..ea9c25211 100644 --- a/src/dolphincontroller.cpp +++ b/src/dolphincontroller.cpp @@ -21,7 +21,9 @@ DolphinController::DolphinController(QObject* parent) : QObject(parent), - m_showPreview(false) + m_showPreview(false), + m_zoomInPossible(false), + m_zoomOutPossible(false) { } @@ -65,6 +67,16 @@ void DolphinController::setShowPreview(bool showPreview) } } +void DolphinController::triggerZoomIn() +{ + emit zoomIn(); +} + +void DolphinController::triggerZoomOut() +{ + emit zoomOut(); +} + void DolphinController::triggerItem(const QModelIndex& index) { emit itemTriggered(index); diff --git a/src/dolphincontroller.h b/src/dolphincontroller.h index 08d12ea57..1bd283fd4 100644 --- a/src/dolphincontroller.h +++ b/src/dolphincontroller.h @@ -70,6 +70,14 @@ public: void setShowPreview(bool showPreview); bool showPreview() const { return m_showPreview; } + void triggerZoomIn(); + void setZoomInPossible(bool possible) { m_zoomInPossible = possible; } + bool isZoomInPossible() const { return m_zoomInPossible; } + + void triggerZoomOut(); + void setZoomOutPossible(bool possible) { m_zoomOutPossible = possible; } + bool isZoomOutPossible() const { return m_zoomOutPossible; } + public slots: void triggerItem(const QModelIndex& index); void indicateSelectionChange(); @@ -121,8 +129,16 @@ signals: /** Is emitted if the selection has been changed by the user. */ void selectionChanged(); + /** Is emitted if the view should zoom in. */ + void zoomIn(); + + /** Is emitted if the view should zoom out. */ + void zoomOut(); + private: bool m_showPreview; + bool m_zoomInPossible; + bool m_zoomOutPossible; KUrl m_url; }; diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index 1695b768e..ef4525065 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -24,7 +24,6 @@ #include "dolphin_iconsmodesettings.h" -#include <assert.h> #include <kdirmodel.h> #include <kfileitem.h> #include <kfileitemdelegate.h> @@ -43,15 +42,18 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle controller, SLOT(triggerItem(const QModelIndex&))); connect(controller, SIGNAL(showPreviewChanged(bool)), this, SLOT(updateGridSize(bool))); + connect(controller, SIGNAL(zoomIn()), + this, SLOT(zoomIn())); + connect(controller, SIGNAL(zoomOut()), + this, SLOT(zoomOut())); // apply the icons mode settings to the widget const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); Q_ASSERT(settings != 0); - setSpacing(settings->gridSpacing()); - m_viewOptions = QListView::viewOptions(); m_viewOptions.font = QFont(settings->fontFamily(), settings->fontSize()); + updateGridSize(controller->showPreview()); if (settings->arrangement() == QListView::TopToBottom) { @@ -132,6 +134,91 @@ void DolphinIconsView::updateGridSize(bool showPreview) m_viewOptions.decorationSize = QSize(size, size); setGridSize(QSize(gridWidth, gridHeight)); + + m_controller->setZoomInPossible(isZoomInPossible()); + m_controller->setZoomOutPossible(isZoomOutPossible()); +} + +void DolphinIconsView::zoomIn() +{ + if (isZoomInPossible()) { + IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); + + const bool showPreview = m_controller->showPreview(); + if (showPreview) { + const int previewSize = increasedIconSize(settings->previewSize()); + settings->setPreviewSize(previewSize); + } + else { + const int iconSize = increasedIconSize(settings->iconSize()); + settings->setIconSize(iconSize); + } + + updateGridSize(showPreview); + } +} + +void DolphinIconsView::zoomOut() +{ + if (isZoomOutPossible()) { + IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); + + const bool showPreview = m_controller->showPreview(); + if (showPreview) { + const int previewSize = decreasedIconSize(settings->previewSize()); + settings->setPreviewSize(previewSize); + } + else { + const int iconSize = decreasedIconSize(settings->iconSize()); + settings->setIconSize(iconSize); + } + + updateGridSize(showPreview); + } +} + +bool DolphinIconsView::isZoomInPossible() const +{ + IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); + const int size = m_controller->showPreview() ? settings->previewSize() : settings->iconSize(); + return size < K3Icon::SizeEnormous; +} + +bool DolphinIconsView::isZoomOutPossible() const +{ + IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); + const int size = m_controller->showPreview() ? settings->previewSize() : settings->iconSize(); + return size > K3Icon::SizeSmall; +} + +int DolphinIconsView::increasedIconSize(int size) const +{ + // TODO: get rid of K3Icon sizes + int incSize = 0; + switch (size) { + case K3Icon::SizeSmall: incSize = K3Icon::SizeSmallMedium; break; + case K3Icon::SizeSmallMedium: incSize = K3Icon::SizeMedium; break; + case K3Icon::SizeMedium: incSize = K3Icon::SizeLarge; break; + case K3Icon::SizeLarge: incSize = K3Icon::SizeHuge; break; + case K3Icon::SizeHuge: incSize = K3Icon::SizeEnormous; break; + default: Q_ASSERT(false); break; + } + return incSize; +} + +int DolphinIconsView::decreasedIconSize(int size) const +{ + // TODO: get rid of K3Icon sizes + int decSize = 0; + switch (size) { + case K3Icon::SizeSmallMedium: decSize = K3Icon::SizeSmall; break; + case K3Icon::SizeMedium: decSize = K3Icon::SizeSmallMedium; break; + case K3Icon::SizeLarge: decSize = K3Icon::SizeMedium; break; + case K3Icon::SizeHuge: decSize = K3Icon::SizeLarge; break; + case K3Icon::SizeEnormous: decSize = K3Icon::SizeHuge; break; + default: Q_ASSERT(false); break; + } + return decSize; } #include "dolphiniconsview.moc" diff --git a/src/dolphiniconsview.h b/src/dolphiniconsview.h index 22da7de21..db3d5d6cd 100644 --- a/src/dolphiniconsview.h +++ b/src/dolphiniconsview.h @@ -54,6 +54,19 @@ private slots: */ void updateGridSize(bool showPreview); + void zoomIn(); + void zoomOut(); + +private: + bool isZoomInPossible() const; + bool isZoomOutPossible() const; + + /** Returns the increased icon size for the size \a size. */ + int increasedIconSize(int size) const; + + /** Returns the decreased icon size for the size \a size. */ + int decreasedIconSize(int size) const; + private: DolphinController* m_controller; QStyleOptionViewItem m_viewOptions; diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index edb57ef7f..491411cb2 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -250,11 +250,11 @@ void DolphinMainWindow::slotViewModeChanged() updateViewActions();
}
-void DolphinMainWindow::slowShowPreviewChanged()
+void DolphinMainWindow::slotShowPreviewChanged()
{
- KToggleAction* showPreviewAction =
- static_cast<KToggleAction*>(actionCollection()->action("show_preview"));
- showPreviewAction->setChecked(m_activeView->showPreview());
+ // It is not enough to update the 'Show Preview' action, also
+ // the 'Zoom In' and 'Zoom Out' actions must be adapted.
+ updateViewActions();
}
void DolphinMainWindow::slotShowHiddenFilesChanged()
@@ -329,6 +329,7 @@ void DolphinMainWindow::slotHistoryChanged() void DolphinMainWindow::slotUrlChanged(const KUrl& url)
{
updateEditActions();
+ updateViewActions();
updateGoActions();
setCaption(url.fileName());
}
@@ -1349,7 +1350,7 @@ void DolphinMainWindow::connectViewSignals(int viewIndex) connect(view, SIGNAL(modeChanged()),
this, SLOT(slotViewModeChanged()));
connect(view, SIGNAL(showPreviewChanged()),
- this, SLOT(slowShowPreviewChanged()));
+ this, SLOT(slotShowPreviewChanged()));
connect(view, SIGNAL(showHiddenFilesChanged()),
this, SLOT(slotShowHiddenFilesChanged()));
connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)),
diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index 1b33c8cb0..137fdfc9e 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -320,7 +320,7 @@ private slots: void slotViewModeChanged(); /** Updates the state of the 'Show preview' menu action. */ - void slowShowPreviewChanged(); + void slotShowPreviewChanged(); /** Updates the state of the 'Show hidden files' menu action. */ void slotShowHiddenFilesChanged(); diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 81eaf21b4..fd6b1409e 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -376,22 +376,22 @@ bool DolphinView::isUrlEditable() const void DolphinView::zoomIn() { - //itemEffectsManager()->zoomIn(); + m_controller->triggerZoomIn(); } void DolphinView::zoomOut() { - //itemEffectsManager()->zoomOut(); + m_controller->triggerZoomOut(); } bool DolphinView::isZoomInPossible() const { - return false; //itemEffectsManager()->isZoomInPossible(); + return m_controller->isZoomInPossible(); } bool DolphinView::isZoomOutPossible() const { - return false; //itemEffectsManager()->isZoomOutPossible(); + return m_controller->isZoomOutPossible(); } void DolphinView::setSorting(Sorting sorting) |
