X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/7fec7ff9a096d288b66fce2699c7b8bc71f6fbbb..d6488887ecf69d7f192b94de8dce34fae0b7eb76:/src/dolphiniconsview.cpp diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index 30dd7bb4d..61179a3ac 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -1,6 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * peter.penz@gmx.at * + * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -15,483 +14,373 @@ * 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., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include "dolphiniconsview.h" -#include -//Added by qt3to4: -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "dolphinview.h" -#include "viewproperties.h" -#include "dolphin.h" -#include "dolphinstatusbar.h" -#include "dolphinsettings.h" -#include "iconsmodesettings.h" -DolphinIconsView::DolphinIconsView(DolphinView* parent, LayoutMode layoutMode) : - KFileIconView(parent, 0), - m_previewIconSize(-1), - m_layoutMode(layoutMode), - m_dolphinView(parent) +#include "dolphincategorydrawer.h" +#include "dolphincontroller.h" +#include "dolphinsettings.h" +#include "dolphin_iconsmodesettings.h" +#include "draganddrophelper.h" + +#include +#include +#include + +#include +#include +#include +#include + +DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) : + KCategorizedView(parent), + m_controller(controller), + m_categoryDrawer(0), + m_itemSize(), + m_dragging(false), + m_dropRect() { - setAcceptDrops(true); - setMode(K3IconView::Execute); - setSelectionMode(KFile::Extended); - Dolphin& dolphin = Dolphin::mainWin(); - - connect(this, SIGNAL(onItem(Q3IconViewItem*)), - this, SLOT(slotOnItem(Q3IconViewItem*))); - connect(this, SIGNAL(onViewport()), - this, SLOT(slotOnViewport())); - connect(this, SIGNAL(contextMenuRequested(Q3IconViewItem*, const QPoint&)), - this, SLOT(slotContextMenuRequested(Q3IconViewItem*, const QPoint&))); - connect(this, SIGNAL(selectionChanged()), - &dolphin, SLOT(slotSelectionChanged())); - connect(&dolphin, SIGNAL(activeViewChanged()), - this, SLOT(slotActivationUpdate())); - connect(this, SIGNAL(itemRenamed(Q3IconViewItem*, const QString&)), - this, SLOT(slotItemRenamed(Q3IconViewItem*, const QString&))); - connect(this, SIGNAL(dropped(QDropEvent*, const KUrl::List&, const KUrl&)), - parent, SLOT(slotUrlListDropped(QDropEvent*, const KUrl::List&, const KUrl&))); - - QClipboard* clipboard = QApplication::clipboard(); - connect(clipboard, SIGNAL(dataChanged()), - this, SLOT(slotUpdateDisabledItems())); - - // KFileIconView creates two actions for zooming, which are directly connected to the - // slots KFileIconView::zoomIn() and KFileIconView::zoomOut(). As this behavior is not - // wanted and the slots are not virtual, the actions are disabled here. - KAction* zoomInAction = actionCollection()->action("zoomIn"); - assert(zoomInAction != 0); - zoomInAction->setEnabled(false); - - KAction* zoomOutAction = actionCollection()->action("zoomOut"); - assert(zoomOutAction != 0); - zoomOutAction->setEnabled(false); - - setItemsMovable(true); - setWordWrapIconText(true); - if (m_layoutMode == Previews) { - showPreviews(); + Q_ASSERT(controller != 0); + setViewMode(QListView::IconMode); + setResizeMode(QListView::Adjust); + setSpacing(KDialog::spacingHint()); + setMovement(QListView::Static); + setDragEnabled(true); + viewport()->setAcceptDrops(true); + + setMouseTracking(true); + viewport()->setAttribute(Qt::WA_Hover); + + // TODO: Connecting to the signal 'activated()' is not possible, as kstyle + // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is + // necessary connecting the signal 'singleClick()' or 'doubleClick' and to handle the + // RETURN-key in keyPressEvent(). + if (KGlobalSettings::singleClick()) { + connect(this, SIGNAL(clicked(const QModelIndex&)), + this, SLOT(triggerItem(const QModelIndex&))); + } else { + connect(this, SIGNAL(doubleClicked(const QModelIndex&)), + this, SLOT(triggerItem(const QModelIndex&))); } - refreshSettings(); -} - -DolphinIconsView::~DolphinIconsView() -{ -} - -void DolphinIconsView::setLayoutMode(LayoutMode mode) -{ - if (m_layoutMode != mode) { - m_layoutMode = mode; - refreshSettings(); + connect(this, SIGNAL(viewportEntered()), + controller, SLOT(emitViewportEntered())); + 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&))); + + // apply the icons mode settings to the widget + const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); + Q_ASSERT(settings != 0); + + m_viewOptions = KCategorizedView::viewOptions(); + m_viewOptions.showDecorationSelected = true; + + QFont font(settings->fontFamily(), settings->fontSize()); + font.setItalic(settings->italicFont()); + font.setBold(settings->boldFont()); + m_viewOptions.font = font; + + setWordWrap(settings->numberOfTextlines() > 1); + updateGridSize(view->showPreview(), 0); + + if (settings->arrangement() == QListView::TopToBottom) { + setFlow(QListView::LeftToRight); + m_viewOptions.decorationPosition = QStyleOptionViewItem::Top; + } else { + setFlow(QListView::TopToBottom); + m_viewOptions.decorationPosition = QStyleOptionViewItem::Left; + m_viewOptions.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter; } -} - -void DolphinIconsView::beginItemUpdates() -{ -} - -void DolphinIconsView::endItemUpdates() -{ - arrangeItemsInGrid(); - // TODO: KFileIconView does not emit any signal when the preview - // has been finished. Using a delay of 300 ms is a temporary workaround - // until the DolphinIconsView will implement the previews by it's own in - // future releases. - QTimer::singleShot(300, this, SLOT(slotUpdateDisabledItems())); + m_categoryDrawer = new DolphinCategoryDrawer(); + setCategoryDrawer(m_categoryDrawer); - const KFileIconViewItem* item = static_cast(firstItem()); - if (item != 0) { - setCurrentItem(item->fileInfo()); - } - - int index = 0; - const Q3ValueList history = m_dolphinView->urlHistory(index); - if (!history.isEmpty()) { - KFileView* fileView = static_cast(this); - fileView->setCurrentItem(history[index].currentFileName()); - setContentsPos(history[index].contentsX(), history[index].contentsY()); - } + setFocus(); } -void DolphinIconsView::refreshSettings() +DolphinIconsView::~DolphinIconsView() { - const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - assert(settings != 0); - - setIconSize(settings->iconSize()); - - const Q3IconView::Arrangement arrangement = settings->arrangement() == "LeftToRight" ? // TODO: use enum directly in settings - Q3IconView::LeftToRight : Q3IconView::TopToBottom; - const Q3IconView::ItemTextPos textPos = (arrangement == Q3IconView::LeftToRight) ? - Q3IconView::Bottom : - Q3IconView::Right; - setArrangement(arrangement); - setItemTextPos(textPos); - - // TODO: tempory crash; will get changed anyway for KDE 4 - /*setGridX(settings->gridWidth()); - setGridY(settings->gridHeight()); - setSpacing(settings->gridSpacing());*/ - - QFont adjustedFont(font()); - adjustedFont.setFamily(settings->fontFamily()); - adjustedFont.setPointSize(settings->fontSize()); - setFont(adjustedFont); - setIconTextHeight(settings->numberOfTexlines()); - - if (m_layoutMode == Previews) { - // There is no getter method for the current size in KFileIconView. To - // prevent a flickering the current size is stored in m_previewIconSize and - // setPreviewSize is only invoked if the size really has changed. - showPreviews(); - - const int size = settings->previewSize(); - if (size != m_previewIconSize) { - m_previewIconSize = size; - setPreviewSize(size); - } - } + delete m_categoryDrawer; + m_categoryDrawer = 0; } -void DolphinIconsView::zoomIn() +QRect DolphinIconsView::visualRect(const QModelIndex& index) const { - if (isZoomInPossible()) { - IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - const int textWidthHint = DolphinSettings::instance().textWidthHint(); // TODO: remove for KDE4 + const bool leftToRightFlow = (flow() == QListView::LeftToRight); - const int iconSize = increasedIconSize(settings->iconSize()); - settings->setIconSize(iconSize); + QRect itemRect = KCategorizedView::visualRect(index); + const int maxWidth = m_itemSize.width(); + const int maxHeight = m_itemSize.height(); - if (m_layoutMode == Previews) { - const int previewSize = increasedIconSize(settings->previewSize()); - settings->setPreviewSize(previewSize); + if (itemRect.width() > maxWidth) { + // assure that the maximum item width is not exceeded + if (leftToRightFlow) { + const int left = itemRect.left() + (itemRect.width() - maxWidth) / 2; + itemRect.setLeft(left); } - - DolphinSettings::instance().calculateGridSize(textWidthHint); // TODO: remove for KDE4 - ItemEffectsManager::zoomIn(); + itemRect.setWidth(maxWidth); } -} - -void DolphinIconsView::zoomOut() -{ - if (isZoomOutPossible()) { - IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - const int textWidthHint = DolphinSettings::instance().textWidthHint(); // TODO: remove for KDE4 - const int iconSize = decreasedIconSize(settings->iconSize()); - settings->setIconSize(iconSize); - - if (m_layoutMode == Previews) { - const int previewSize = decreasedIconSize(settings->previewSize()); - settings->setPreviewSize(previewSize); + if (itemRect.height() > maxHeight) { + // assure that the maximum item height is not exceeded + if (!leftToRightFlow) { + const int top = itemRect.top() + (itemRect.height() - maxHeight) / 2; + itemRect.setTop(top); } + itemRect.setHeight(maxHeight); + } - DolphinSettings::instance().calculateGridSize(textWidthHint); // TODO: remove for KDE4 - ItemEffectsManager::zoomOut(); + KCategorizedSortFilterProxyModel* proxyModel = dynamic_cast(model()); + if (leftToRightFlow && !proxyModel->isCategorizedModel()) { + // TODO: QListView::visualRect() calculates a wrong position of the items under + // certain circumstances (e. g. if the text is too long). This issue is bypassed + // by the following code (I'll try create a patch for Qt but as Dolphin must also work with + // Qt 4.3.0 this workaround must get applied at least for KDE 4.0). + const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); + const int margin = settings->gridSpacing(); + const int gridWidth = gridSize().width(); + const int gridIndex = (itemRect.left() - margin + 1) / gridWidth; + itemRect.moveLeft(gridIndex * gridWidth + margin); } + + return itemRect; } -bool DolphinIconsView::isZoomInPossible() const +QStyleOptionViewItem DolphinIconsView::viewOptions() const { - IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - const int size = (m_layoutMode == Icons) ? settings->iconSize() : settings->previewSize(); - return size < K3Icon::SizeEnormous; + return m_viewOptions; } -bool DolphinIconsView::isZoomOutPossible() const +void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event) { - IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - return settings->iconSize() > K3Icon::SizeSmall; + KCategorizedView::contextMenuEvent(event); + m_controller->triggerContextMenuRequest(event->pos()); } -void DolphinIconsView::arrangeItemsInGrid( bool updated ) +void DolphinIconsView::mousePressEvent(QMouseEvent* event) { - - KFileIconView::arrangeItemsInGrid(updated); - - if (m_layoutMode == Previews) { - // The class KFileIconView has a bug when the size of the previews differs from the size - // of the icons: For specific MIME types the y-position and the height is calculated in - // a wrong manner. The following code bypasses this issue. No bugreport has been submitted - // as this functionality is not used by any KDE3 application and the core developers are - // busy enough for KDE4 now :-) - - KFileIconViewItem* item = static_cast(Q3IconView::firstItem()); - QString mimetype; - while (item != 0) { - mimetype = item->fileInfo()->mimetype(); - const bool fixSize = mimetype.contains("text") || - mimetype.contains("application/x-"); - if (fixSize) { - item->setPixmapSize(QSize(m_previewIconSize, m_previewIconSize)); - } - item = static_cast(item->nextItem()); + m_controller->requestActivation(); + if (!indexAt(event->pos()).isValid()) { + const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers(); + if (!(modifier & Qt::ShiftModifier) && !(modifier & Qt::ControlModifier)) { + clearSelection(); } } -} -void DolphinIconsView::setContextPixmap(void* context, - const QPixmap& pixmap) -{ - reinterpret_cast(context)->setPixmap(pixmap); -} - -const QPixmap* DolphinIconsView::contextPixmap(void* context) -{ - return reinterpret_cast(context)->pixmap(); + KCategorizedView::mousePressEvent(event); } -void* DolphinIconsView::firstContext() +void DolphinIconsView::startDrag(Qt::DropActions supportedActions) { - return reinterpret_cast(firstItem()); + // TODO: invoking KCategorizedView::startDrag() should not be necessary, we'll + // fix this in KDE 4.1 + KCategorizedView::startDrag(supportedActions); + DragAndDropHelper::startDrag(this, supportedActions); } -void* DolphinIconsView::nextContext(void* context) +void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event) { - KFileIconViewItem* iconViewItem = reinterpret_cast(context); - return reinterpret_cast(iconViewItem->nextItem()); + if (event->mimeData()->hasUrls()) { + event->acceptProposedAction(); + } + m_dragging = true; } -KFileItem* DolphinIconsView::contextFileInfo(void* context) +void DolphinIconsView::dragLeaveEvent(QDragLeaveEvent* event) { - return reinterpret_cast(context)->fileInfo(); -} + KCategorizedView::dragLeaveEvent(event); -void DolphinIconsView::contentsMousePressEvent(QMouseEvent* event) -{ - KFileIconView::contentsMousePressEvent(event); - resetActivatedItem(); - emit signalRequestActivation(); - m_dolphinView->statusBar()->clear(); + // TODO: remove this code when the issue #160611 is solved in Qt 4.4 + m_dragging = false; + setDirtyRegion(m_dropRect); } -void DolphinIconsView::contentsMouseReleaseEvent(QMouseEvent* event) +void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event) { - KFileIconView::contentsMouseReleaseEvent(event); + KCategorizedView::dragMoveEvent(event); - // The KFileIconView does not send any selectionChanged signal if - // a selection is done by using the "select-during-button-pressed" feature. - // Hence inform Dolphin about the selection change manually: - Dolphin::mainWin().slotSelectionChanged(); -} + // TODO: remove this code when the issue #160611 is solved in Qt 4.4 + const QModelIndex index = indexAt(event->pos()); + setDirtyRegion(m_dropRect); -void DolphinIconsView::drawBackground(QPainter* painter, const QRect& rect) -{ - if (m_dolphinView->isActive()) { - KFileIconView::drawBackground(painter, rect); - } - else { - const QBrush brush(colorGroup().background()); - painter->fillRect(0, 0, width(), height(), brush); + m_dropRect.setSize(QSize()); // set as invalid + if (index.isValid()) { + const KFileItem item = itemForIndex(index); + if (!item.isNull() && item.isDir()) { + m_dropRect = visualRect(index); + } } + setDirtyRegion(m_dropRect); } -Q3DragObject* DolphinIconsView::dragObject() +void DolphinIconsView::dropEvent(QDropEvent* event) { - KUrl::List urls; - QListIterator it(*KFileView::selectedItems()); - while (it.hasNext()) { - KFileItem *item = it.next(); - urls.append(item->url()); - } - - QPixmap pixmap; - if(urls.count() > 1) { - pixmap = DesktopIcon("kmultiple", iconSize()); - } - else { - KFileIconViewItem* item = static_cast(currentItem()); - if ((item != 0) && (item->pixmap() != 0)) { - pixmap = *(item->pixmap()); + if (!selectionModel()->isSelected(indexAt(event->pos()))) { + const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData()); + if (!urls.isEmpty()) { + const QModelIndex index = indexAt(event->pos()); + const KFileItem item = itemForIndex(index); + m_controller->indicateDroppedUrls(urls, + m_controller->url(), + item); + event->acceptProposedAction(); } } - if (pixmap.isNull()) { - pixmap = currentFileItem()->pixmap(iconSize()); - } + KCategorizedView::dropEvent(event); - /* This should be ported to QMimeData - Q3DragObject* dragObj = new KUrlDrag(urls, widget()); - dragObj->setPixmap(pixmap); - return dragObj; - */ - return 0; + m_dragging = false; } -void DolphinIconsView::contentsDragEnterEvent(QDragEnterEvent* event) +void DolphinIconsView::paintEvent(QPaintEvent* event) { - // TODO: The method KFileIconView::contentsDragEnterEvent() does - // not allow drag and drop inside itself, which prevents the possability - // to move a file into a directory. As the method KFileIconView::acceptDrag() - // is not virtual, we must overwrite the method - // KFileIconView::contentsDragEnterEvent() and do some cut/copy/paste for this - // usecase. Corresponding to the documentation the method KFileIconView::acceptDrag() - // will get virtual in KDE 4, which will simplify the code. - - if (event->source() != this) { - KFileIconView::contentsDragEnterEvent(event); - return; - } + KCategorizedView::paintEvent(event); - KUrl::List uriList = KUrl::List::fromMimeData( event->mimeData() ); - const bool accept = !uriList.isEmpty() && - (event->action() == QDropEvent::Copy || - event->action() == QDropEvent::Move || - event->action() == QDropEvent::Link ); - if (accept) { - event->acceptAction(); - } - else { - event->ignore(); + // TODO: remove this code when the issue #160611 is solved in Qt 4.4 + if (m_dragging) { + const QBrush& brush = m_viewOptions.palette.brush(QPalette::Normal, QPalette::Highlight); + DragAndDropHelper::drawHoverIndication(viewport(), m_dropRect, brush); } } -void DolphinIconsView::contentsDragMoveEvent(QDragMoveEvent* event) +void DolphinIconsView::keyPressEvent(QKeyEvent* event) { - KFileIconView::contentsDragMoveEvent(event); - - // If a dragging is done above a directory, show the icon as 'active' for - // a visual feedback - KFileIconViewItem* item = static_cast(findItem(contentsToViewport(event->pos()))); - - bool showActive = false; - if (item != 0) { - const KFileItem* fileInfo = item->fileInfo(); - showActive = (fileInfo != 0) && fileInfo->isDir(); - } - - if (showActive) { - slotOnItem(item); - } - else { - slotOnViewport(); + KCategorizedView::keyPressEvent(event); + + const QItemSelectionModel* selModel = selectionModel(); + const QModelIndex currentIndex = selModel->currentIndex(); + const bool trigger = currentIndex.isValid() + && (event->key() == Qt::Key_Return) + && (selModel->selectedIndexes().count() <= 1); + if (trigger) { + triggerItem(currentIndex); } } -void DolphinIconsView::contentsDropEvent(QDropEvent* event) +void DolphinIconsView::triggerItem(const QModelIndex& index) { - // TODO: Most of the following code is a copy of - // KFileIconView::contentsDropEvent. See comment in - // DolphinIconsView::contentsDragEnterEvent for details. - - if (event->source() != this) { - KFileIconView::contentsDropEvent(event); - return; - } - - KFileIconViewItem* item = static_cast(findItem(contentsToViewport(event->pos()))); - KUrl::List urls = KUrl::List::fromMimeData( event->mimeData() ); - const bool accept = !urls.isEmpty() && - (event->action() == QDropEvent::Copy || - event->action() == QDropEvent::Move || - event->action() == QDropEvent::Link ) && - (item != 0); - if (!accept) { - return; - } - - KFileItem* fileItem = item->fileInfo(); - if (!fileItem->isDir()) { - // the file is not a directory, hence don't accept any drop - return; - } - emit dropped(event, fileItem); - if (!urls.isEmpty()) { - emit dropped(event, urls, fileItem != 0 ? fileItem->url() : KUrl()); - sig->dropURLs(fileItem, event, urls); - } + m_controller->triggerItem(itemForIndex(index)); } -void DolphinIconsView::slotOnItem(Q3IconViewItem* item) +void DolphinIconsView::slotEntered(const QModelIndex& index) { - assert(item != 0); - activateItem(reinterpret_cast(item)); - - KFileItem* fileItem = static_cast(item)->fileInfo(); - m_dolphinView->requestItemInfo(fileItem->url()); + m_controller->emitItemEntered(itemForIndex(index)); } -void DolphinIconsView::slotOnViewport() +void DolphinIconsView::slotShowPreviewChanged() { - resetActivatedItem(); - m_dolphinView->requestItemInfo(KUrl()); + const DolphinView* view = m_controller->dolphinView(); + const int infoCount = view->additionalInfo().count(); + updateGridSize(view->showPreview(), infoCount); } -void DolphinIconsView::slotContextMenuRequested(Q3IconViewItem* item, - const QPoint& pos) +void DolphinIconsView::slotAdditionalInfoChanged(const KFileItemDelegate::InformationList& info) { - KFileItem* fileInfo = 0; - if (item != 0) { - fileInfo = static_cast(item)->fileInfo(); - } - m_dolphinView->openContextMenu(fileInfo, pos); + const bool showPreview = m_controller->dolphinView()->showPreview(); + updateGridSize(showPreview, info.count()); } -void DolphinIconsView::slotItemRenamed(Q3IconViewItem* item, - const QString& name) +void DolphinIconsView::zoomIn() { - KFileItem* fileInfo = static_cast(item)->fileInfo(); - m_dolphinView->rename(KUrl(fileInfo->url()), name); + if (isZoomInPossible()) { + IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); + + const int oldIconSize = settings->iconSize(); + int newIconSize = oldIconSize; + + const bool showPreview = m_controller->dolphinView()->showPreview(); + if (showPreview) { + const int previewSize = increasedIconSize(settings->previewSize()); + settings->setPreviewSize(previewSize); + } else { + newIconSize = increasedIconSize(oldIconSize); + settings->setIconSize(newIconSize); + if (settings->previewSize() < newIconSize) { + // assure that the preview size is always >= the icon size + settings->setPreviewSize(newIconSize); + } + } + + // increase also the grid size + const int diff = newIconSize - oldIconSize; + settings->setItemWidth(settings->itemWidth() + diff); + settings->setItemHeight(settings->itemHeight() + diff); + + const int infoCount = m_controller->dolphinView()->additionalInfo().count(); + updateGridSize(showPreview, infoCount); + } } -void DolphinIconsView::slotActivationUpdate() +void DolphinIconsView::zoomOut() { - update(); + if (isZoomOutPossible()) { + IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - // TODO: there must be a simpler way to say - // "update all children" - const QList list = children(); - if (list.isEmpty()) { - return; - } + const int oldIconSize = settings->iconSize(); + int newIconSize = oldIconSize; - QListIterator it(list); - QObject* object = 0; - while (it.hasNext()) { - object = it.next(); - if (object->inherits("QWidget")) { - QWidget* widget = static_cast(object); - widget->update(); + const bool showPreview = m_controller->dolphinView()->showPreview(); + if (showPreview) { + const int previewSize = decreasedIconSize(settings->previewSize()); + settings->setPreviewSize(previewSize); + if (settings->iconSize() > previewSize) { + // assure that the icon size is always <= the preview size + newIconSize = previewSize; + settings->setIconSize(newIconSize); + } + } else { + newIconSize = decreasedIconSize(settings->iconSize()); + settings->setIconSize(newIconSize); } + + // decrease also the grid size + const int diff = oldIconSize - newIconSize; + settings->setItemWidth(settings->itemWidth() - diff); + settings->setItemHeight(settings->itemHeight() - diff); + + const int infoCount = m_controller->dolphinView()->additionalInfo().count(); + updateGridSize(showPreview, infoCount); } } -void DolphinIconsView::slotUpdateDisabledItems() +bool DolphinIconsView::isZoomInPossible() const { - updateDisabledItems(); + IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); + 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 bool showPreview = m_controller->dolphinView()->showPreview(); + const int size = showPreview ? settings->previewSize() : settings->iconSize(); + return size > KIconLoader::SizeSmall; } int DolphinIconsView::increasedIconSize(int size) const { 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: assert(false); break; + case KIconLoader::SizeSmall: incSize = KIconLoader::SizeSmallMedium; break; + case KIconLoader::SizeSmallMedium: incSize = KIconLoader::SizeMedium; break; + case KIconLoader::SizeMedium: incSize = KIconLoader::SizeLarge; break; + case KIconLoader::SizeLarge: incSize = KIconLoader::SizeHuge; break; + case KIconLoader::SizeHuge: incSize = KIconLoader::SizeEnormous; break; + default: Q_ASSERT(false); break; } return incSize; } @@ -500,14 +389,62 @@ int DolphinIconsView::decreasedIconSize(int size) const { 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: assert(false); break; + case KIconLoader::SizeSmallMedium: decSize = KIconLoader::SizeSmall; break; + case KIconLoader::SizeMedium: decSize = KIconLoader::SizeSmallMedium; break; + case KIconLoader::SizeLarge: decSize = KIconLoader::SizeMedium; break; + case KIconLoader::SizeHuge: decSize = KIconLoader::SizeLarge; break; + case KIconLoader::SizeEnormous: decSize = KIconLoader::SizeHuge; break; + default: Q_ASSERT(false); break; } return decSize; } +void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount) +{ + const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); + Q_ASSERT(settings != 0); + + int itemWidth = settings->itemWidth(); + int itemHeight = settings->itemHeight(); + int size = settings->iconSize(); + + if (showPreview) { + const int previewSize = settings->previewSize(); + const int diff = previewSize - size; + Q_ASSERT(diff >= 0); + itemWidth += diff; + itemHeight += diff; + + size = previewSize; + } + + Q_ASSERT(additionalInfoCount >= 0); + itemHeight += additionalInfoCount * m_viewOptions.font.pointSize() * 2; + + if (settings->arrangement() == QListView::TopToBottom) { + // The decoration width indirectly defines the maximum + // width for the text wrapping. To use the maximum item width + // for text wrapping, it is used as decoration width. + m_viewOptions.decorationSize = QSize(itemWidth, size); + } else { + m_viewOptions.decorationSize = QSize(size, size); + } + + const int spacing = settings->gridSpacing(); + setGridSize(QSize(itemWidth + spacing * 2, itemHeight + spacing)); + + m_itemSize = QSize(itemWidth, itemHeight); + + m_controller->setZoomInPossible(isZoomInPossible()); + m_controller->setZoomOutPossible(isZoomOutPossible()); +} + +KFileItem DolphinIconsView::itemForIndex(const QModelIndex& index) const +{ + QAbstractProxyModel* proxyModel = static_cast(model()); + KDirModel* dirModel = static_cast(proxyModel->sourceModel()); + const QModelIndex dirIndex = proxyModel->mapToSource(index); + return dirModel->itemForIndex(dirIndex); +} + #include "dolphiniconsview.moc"