X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/5252c12db4929886dbe502013e0a1fee6500f568..11289b4fc3efbc074b668d4516cd896f8ade9761:/src/dolphiniconsview.cpp diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index 2576abba8..0dd7dd719 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,495 +14,405 @@ * 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 "dolphin_generalsettings.h" +#include "draganddrophelper.h" +#include "selectionmanager.h" +#include "zoomlevelinfo.h" + +#include +#include +#include +#include + +#include +#include +#include + +DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) : + KCategorizedView(parent), + m_enableScrollTo(false), + m_controller(controller), + m_selectionManager(0), + m_categoryDrawer(0), + m_font(), + m_decorationSize(), + m_decorationPosition(QStyleOptionViewItem::Top), + m_displayAlignment(Qt::AlignHCenter), + m_itemSize(), + m_dropRect() { - setAcceptDrops(true); - setMode(KIconView::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); + setLayoutDirection(Qt::LeftToRight); + setViewMode(QListView::IconMode); + setResizeMode(QListView::Adjust); + setSpacing(KDialog::spacingHint()); + setMovement(QListView::Static); + setDragEnabled(true); + setEditTriggers(QAbstractItemView::NoEditTriggers); + viewport()->setAcceptDrops(true); + + setMouseTracking(true); + + // 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&)), + controller, SLOT(triggerItem(const QModelIndex&))); + } else { + connect(this, SIGNAL(doubleClicked(const QModelIndex&)), + controller, SLOT(triggerItem(const QModelIndex&))); } - refreshSettings(); -} -DolphinIconsView::~DolphinIconsView() -{ -} - -void DolphinIconsView::setLayoutMode(LayoutMode mode) -{ - if (m_layoutMode != mode) { - m_layoutMode = mode; - refreshSettings(); + if (DolphinSettings::instance().generalSettings()->showSelectionToggle()) { + m_selectionManager = new SelectionManager(this); + connect(m_selectionManager, SIGNAL(selectionChanged()), + this, SLOT(requestActivation())); + connect(m_controller, SIGNAL(urlChanged(const KUrl&)), + m_selectionManager, SLOT(reset())); } -} - -void DolphinIconsView::beginItemUpdates() -{ -} -void DolphinIconsView::endItemUpdates() -{ - arrangeItemsInGrid(); + connect(this, SIGNAL(entered(const QModelIndex&)), + controller, SLOT(emitItemEntered(const QModelIndex&))); + connect(this, SIGNAL(viewportEntered()), + controller, SLOT(emitViewportEntered())); + connect(controller, SIGNAL(zoomLevelChanged(int)), + this, SLOT(setZoomLevel(int))); - // 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())); + const DolphinView* view = controller->dolphinView(); + connect(view, SIGNAL(showPreviewChanged()), + this, SLOT(slotShowPreviewChanged())); + connect(view, SIGNAL(additionalInfoChanged()), + this, SLOT(slotAdditionalInfoChanged())); - const KFileIconViewItem* item = static_cast(firstItem()); - if (item != 0) { - setCurrentItem(item->fileInfo()); + // apply the icons mode settings to the widget + const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); + Q_ASSERT(settings != 0); + + if (settings->useSystemFont()) { + m_font = KGlobalSettings::generalFont(); + } else { + m_font = QFont(settings->fontFamily(), + settings->fontSize(), + settings->fontWeight(), + settings->italicFont()); } - 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()); + setWordWrap(settings->numberOfTextlines() > 1); + updateGridSize(view->showPreview(), 0); + + if (settings->arrangement() == QListView::TopToBottom) { + setFlow(QListView::LeftToRight); + m_decorationPosition = QStyleOptionViewItem::Top; + m_displayAlignment = Qt::AlignHCenter; + } else { + setFlow(QListView::TopToBottom); + m_decorationPosition = QStyleOptionViewItem::Left; + m_displayAlignment = Qt::AlignLeft | Qt::AlignVCenter; } + + m_categoryDrawer = new DolphinCategoryDrawer(); + setCategoryDrawer(m_categoryDrawer); + + setFocus(); + + connect(KGlobalSettings::self(), SIGNAL(kdisplayFontChanged()), + this, SLOT(updateFont())); } -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() +void DolphinIconsView::scrollTo(const QModelIndex& index, ScrollHint hint) { - if (isZoomInPossible()) { - IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - const int textWidthHint = DolphinSettings::instance().textWidthHint(); // TODO: remove for KDE4 - - const int iconSize = increasedIconSize(settings->iconSize()); - settings->setIconSize(iconSize); - - if (m_layoutMode == Previews) { - const int previewSize = increasedIconSize(settings->previewSize()); - settings->setPreviewSize(previewSize); - } - - DolphinSettings::instance().calculateGridSize(textWidthHint); // TODO: remove for KDE4 - ItemEffectsManager::zoomIn(); + // Enable the QListView implementation of scrollTo() only if it has been + // triggered by a key press. Otherwise QAbstractItemView wants to scroll to the current + // index each time the layout has been changed. This becomes an issue when + // previews are loaded and the scrollbar is used: the scrollbar will always + // be reset to 0 on each new preview. + if (m_enableScrollTo || (state() != QAbstractItemView::NoState)) { + KCategorizedView::scrollTo(index, hint); + m_enableScrollTo = false; } } -void DolphinIconsView::zoomOut() +void DolphinIconsView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight) { - 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); - } + KCategorizedView::dataChanged(topLeft, bottomRight); - DolphinSettings::instance().calculateGridSize(textWidthHint); // TODO: remove for KDE4 - ItemEffectsManager::zoomOut(); + KCategorizedSortFilterProxyModel* proxyModel = dynamic_cast(model()); + if ((flow() == QListView::LeftToRight) && !proxyModel->isCategorizedModel()) { + // bypass a QListView issue that items are not layout correctly if the decoration size of + // an index changes + scheduleDelayedItemsLayout(); } } -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 < KIcon::SizeEnormous; + QStyleOptionViewItem viewOptions = KCategorizedView::viewOptions(); + viewOptions.font = m_font; + viewOptions.decorationPosition = m_decorationPosition; + viewOptions.decorationSize = m_decorationSize; + viewOptions.displayAlignment = m_displayAlignment; + viewOptions.showDecorationSelected = true; + return viewOptions; } -bool DolphinIconsView::isZoomOutPossible() const +void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event) { - IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - return settings->iconSize() > KIcon::SizeSmall; + KCategorizedView::contextMenuEvent(event); + m_controller->triggerContextMenuRequest(event->pos()); } -void DolphinIconsView::arrangeItemsInGrid( bool updated ) +void DolphinIconsView::mousePressEvent(QMouseEvent* event) { + m_controller->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 + // not reproduce this issue with a Qt-only example yet to find the root cause. + // Issue description: start Dolphin, split the view and drag an item from the + // inactive view to the active view by a very fast mouse movement. Result: + // the item gets selected instead of being dragged... + setState(QAbstractItemView::DraggingState); + } - 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()); + if (!index.isValid()) { + if (QApplication::mouseButtons() & Qt::MidButton) { + m_controller->replaceUrlByClipboard(); + } + 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); + KCategorizedView::mousePressEvent(event); } -const QPixmap* DolphinIconsView::contextPixmap(void* context) +void DolphinIconsView::startDrag(Qt::DropActions supportedActions) { - return reinterpret_cast(context)->pixmap(); + // TODO: invoking KCategorizedView::startDrag() should not be necessary, we'll + // fix this in KDE 4.1 + KCategorizedView::startDrag(supportedActions); + DragAndDropHelper::instance().startDrag(this, supportedActions, m_controller); } -void* DolphinIconsView::firstContext() +void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event) { - return reinterpret_cast(firstItem()); + if (DragAndDropHelper::instance().isMimeDataSupported(event->mimeData())) { + event->acceptProposedAction(); + } } -void* DolphinIconsView::nextContext(void* context) +void DolphinIconsView::dragLeaveEvent(QDragLeaveEvent* event) { - KFileIconViewItem* iconViewItem = reinterpret_cast(context); - return reinterpret_cast(iconViewItem->nextItem()); + KCategorizedView::dragLeaveEvent(event); + setDirtyRegion(m_dropRect); } -KFileItem* DolphinIconsView::contextFileInfo(void* context) +void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event) { - return reinterpret_cast(context)->fileInfo(); -} + KCategorizedView::dragMoveEvent(event); + + // TODO: remove this code when the issue #160611 is solved in Qt 4.4 + const QModelIndex index = indexAt(event->pos()); + setDirtyRegion(m_dropRect); + + m_dropRect.setSize(QSize()); // set as invalid + if (index.isValid()) { + const KFileItem item = m_controller->itemForIndex(index); + if (!item.isNull() && item.isDir()) { + m_dropRect = visualRect(index); + } else { + m_dropRect.setSize(QSize()); // set as invalid + } + } + if (DragAndDropHelper::instance().isMimeDataSupported(event->mimeData())) { + // accept url drops, independently from the destination item + event->acceptProposedAction(); + } -void DolphinIconsView::contentsMousePressEvent(QMouseEvent* event) -{ - KFileIconView::contentsMousePressEvent(event); - resetActivatedItem(); - emit signalRequestActivation(); - m_dolphinView->statusBar()->clear(); + setDirtyRegion(m_dropRect); } -void DolphinIconsView::contentsMouseReleaseEvent(QMouseEvent* event) +void DolphinIconsView::dropEvent(QDropEvent* event) { - KFileIconView::contentsMouseReleaseEvent(event); + const QModelIndex index = indexAt(event->pos()); + const KFileItem item = m_controller->itemForIndex(index); + m_controller->indicateDroppedUrls(item, m_controller->url(), 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(); + KCategorizedView::dropEvent(event); } -void DolphinIconsView::drawBackground(QPainter* painter, const QRect& rect) +void DolphinIconsView::keyPressEvent(QKeyEvent* event) { - if (m_dolphinView->isActive()) { - KFileIconView::drawBackground(painter, rect); - } - else { - const QBrush brush(colorGroup().background()); - painter->fillRect(0, 0, width(), height(), brush); - } + KCategorizedView::keyPressEvent(event); + m_controller->handleKeyPressEvent(event); + m_enableScrollTo = true; // see DolphinIconsView::scrollTo() } -Q3DragObject* DolphinIconsView::dragObject() +void DolphinIconsView::wheelEvent(QWheelEvent* event) { - KURL::List urls; - KFileItemListIterator it(*KFileView::selectedItems()); - while (it.current() != 0) { - urls.append((*it)->url()); - ++it; + if (m_selectionManager != 0) { + m_selectionManager->reset(); } - 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()); - } + // let Ctrl+wheel events propagate to the DolphinView for icon zooming + if (event->modifiers() & Qt::ControlModifier) { + event->ignore(); + return; } - - if (pixmap.isNull()) { - pixmap = currentFileItem()->pixmap(iconSize()); + KCategorizedView::wheelEvent(event); + // if the icons are aligned left to right, the vertical wheel event should + // be applied to the horizontal scrollbar + const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); + const bool scrollHorizontal = (event->orientation() == Qt::Vertical) && + (settings->arrangement() == QListView::LeftToRight); + if (scrollHorizontal) { + QWheelEvent horizEvent(event->pos(), + event->delta(), + event->buttons(), + event->modifiers(), + Qt::Horizontal); + QApplication::sendEvent(horizontalScrollBar(), &horizEvent); } - - Q3DragObject* dragObj = new KURLDrag(urls, widget()); - dragObj->setPixmap(pixmap); - return dragObj; } -void DolphinIconsView::contentsDragEnterEvent(QDragEnterEvent* event) +void DolphinIconsView::showEvent(QShowEvent* 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; - } + KFileItemDelegate* delegate = dynamic_cast(itemDelegate()); + delegate->setMaximumSize(m_itemSize); - const bool accept = KURLDrag::canDecode(event) && - (event->action() == QDropEvent::Copy || - event->action() == QDropEvent::Move || - event->action() == QDropEvent::Link ); - if (accept) { - event->acceptAction(); - } - else { - event->ignore(); - } + KCategorizedView::showEvent(event); } -void DolphinIconsView::contentsDragMoveEvent(QDragMoveEvent* event) +void DolphinIconsView::leaveEvent(QEvent* 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(); - } + KCategorizedView::leaveEvent(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(); +} - if (showActive) { - slotOnItem(item); - } - else { - slotOnViewport(); - } +void DolphinIconsView::slotShowPreviewChanged() +{ + const DolphinView* view = m_controller->dolphinView(); + updateGridSize(view->showPreview(), additionalInfoCount()); } -void DolphinIconsView::contentsDropEvent(QDropEvent* event) +void DolphinIconsView::slotAdditionalInfoChanged() { - // TODO: Most of the following code is a copy of - // KFileIconView::contentsDropEvent. See comment in - // DolphinIconsView::contentsDragEnterEvent for details. + const DolphinView* view = m_controller->dolphinView(); + const bool showPreview = view->showPreview(); + updateGridSize(showPreview, view->additionalInfo().count()); +} - if (event->source() != this) { - KFileIconView::contentsDropEvent(event); - return; - } +void DolphinIconsView::setZoomLevel(int level) +{ + IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - KFileIconViewItem* item = static_cast(findItem(contentsToViewport(event->pos()))); - const bool accept = KURLDrag::canDecode(event) && - (event->action() == QDropEvent::Copy || - event->action() == QDropEvent::Move || - event->action() == QDropEvent::Link ) && - (item != 0); - if (!accept) { - return; - } + const int oldIconSize = settings->iconSize(); + int newIconSize = oldIconSize; - KFileItem* fileItem = item->fileInfo(); - if (!fileItem->isDir()) { - // the file is not a directory, hence don't accept any drop - return; + const bool showPreview = m_controller->dolphinView()->showPreview(); + if (showPreview) { + const int previewSize = ZoomLevelInfo::iconSizeForZoomLevel(level); + settings->setPreviewSize(previewSize); + } else { + newIconSize = ZoomLevelInfo::iconSizeForZoomLevel(level); + settings->setIconSize(newIconSize); } - emit dropped(event, fileItem); - KURL::List urls; - if (KURLDrag::decode(event, urls) && !urls.isEmpty()) { - emit dropped(event, urls, fileItem != 0 ? fileItem->url() : KURL()); - sig->dropURLs(fileItem, event, urls); - } -} -void DolphinIconsView::slotOnItem(Q3IconViewItem* item) -{ - assert(item != 0); - activateItem(reinterpret_cast(item)); + // increase also the grid size + const int diff = newIconSize - oldIconSize; + settings->setItemWidth(settings->itemWidth() + diff); + settings->setItemHeight(settings->itemHeight() + diff); - KFileItem* fileItem = static_cast(item)->fileInfo(); - m_dolphinView->requestItemInfo(fileItem->url()); + updateGridSize(showPreview, additionalInfoCount()); } -void DolphinIconsView::slotOnViewport() +void DolphinIconsView::requestActivation() { - resetActivatedItem(); - m_dolphinView->requestItemInfo(KURL()); + m_controller->requestActivation(); } -void DolphinIconsView::slotContextMenuRequested(Q3IconViewItem* item, - const QPoint& pos) +void DolphinIconsView::updateFont() { - KFileItem* fileInfo = 0; - if (item != 0) { - fileInfo = static_cast(item)->fileInfo(); + const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); + Q_ASSERT(settings != 0); + + if (settings->useSystemFont()) { + m_font = KGlobalSettings::generalFont(); } - m_dolphinView->openContextMenu(fileInfo, pos); } -void DolphinIconsView::slotItemRenamed(Q3IconViewItem* item, - const QString& name) +void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount) { - KFileItem* fileInfo = static_cast(item)->fileInfo(); - m_dolphinView->rename(KURL(fileInfo->url()), name); -} + const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); + Q_ASSERT(settings != 0); -void DolphinIconsView::slotActivationUpdate() -{ - update(); + int itemWidth = settings->itemWidth(); + int itemHeight = settings->itemHeight(); + int size = settings->iconSize(); - // TODO: there must be a simpler way to say - // "update all children" - const QObjectList* list = children(); - if (list == 0) { - return; + if (showPreview) { + const int previewSize = settings->previewSize(); + const int diff = previewSize - size; + itemWidth += diff; + itemHeight += diff; + + size = previewSize; } - QObjectListIterator it(*list); - QObject* object = 0; - while ((object = it.current()) != 0) { - if (object->inherits("QWidget")) { - QWidget* widget = static_cast(object); - widget->update(); - } - ++it; + Q_ASSERT(additionalInfoCount >= 0); + itemHeight += additionalInfoCount * m_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_decorationSize = QSize(itemWidth, size); + setIconSize(QSize(itemWidth, size)); + } else { + m_decorationSize = QSize(size, size); + setIconSize(QSize(size, size)); } -} -void DolphinIconsView::slotUpdateDisabledItems() -{ - updateDisabledItems(); -} + m_itemSize = QSize(itemWidth, itemHeight); -int DolphinIconsView::increasedIconSize(int size) const -{ - int incSize = 0; - switch (size) { - case KIcon::SizeSmall: incSize = KIcon::SizeSmallMedium; break; - case KIcon::SizeSmallMedium: incSize = KIcon::SizeMedium; break; - case KIcon::SizeMedium: incSize = KIcon::SizeLarge; break; - case KIcon::SizeLarge: incSize = KIcon::SizeHuge; break; - case KIcon::SizeHuge: incSize = KIcon::SizeEnormous; break; - default: assert(false); break; + const int spacing = settings->gridSpacing(); + setGridSize(QSize(itemWidth + spacing * 2, itemHeight + spacing)); + + KFileItemDelegate* delegate = dynamic_cast(itemDelegate()); + if (delegate != 0) { + delegate->setMaximumSize(m_itemSize); + } + + if (m_selectionManager != 0) { + m_selectionManager->reset(); } - return incSize; } -int DolphinIconsView::decreasedIconSize(int size) const +int DolphinIconsView::additionalInfoCount() const { - int decSize = 0; - switch (size) { - case KIcon::SizeSmallMedium: decSize = KIcon::SizeSmall; break; - case KIcon::SizeMedium: decSize = KIcon::SizeSmallMedium; break; - case KIcon::SizeLarge: decSize = KIcon::SizeMedium; break; - case KIcon::SizeHuge: decSize = KIcon::SizeLarge; break; - case KIcon::SizeEnormous: decSize = KIcon::SizeHuge; break; - default: assert(false); break; - } - return decSize; + const DolphinView* view = m_controller->dolphinView(); + return view->additionalInfo().count(); } #include "dolphiniconsview.moc"