X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/5b5a7b8da8cb3ee6bbb9f7450c87fca5de41dc05..ec00f379dc42b00a64ab1af25bb4bb1a06bd7449:/src/dolphiniconsview.cpp diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index de66613be..37f0bf172 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -19,37 +19,48 @@ #include "dolphiniconsview.h" -#include "dolphinitemcategorizer.h" #include "dolphincontroller.h" #include "dolphinsettings.h" #include "dolphinitemcategorizer.h" #include "dolphin_iconsmodesettings.h" -#include -#include -#include +#include #include +#include +#include #include DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) : - KListView(parent), - m_controller(controller), - m_itemCategorizer(0) + KCategorizedView(parent), + m_controller(controller), + m_itemSize(), + m_dragging(false), + m_dropRect() { Q_ASSERT(controller != 0); setViewMode(QListView::IconMode); setResizeMode(QListView::Adjust); - + setSpacing(KDialog::spacingHint()); + setMouseTracking(true); viewport()->setAttribute(Qt::WA_Hover); - connect(this, SIGNAL(clicked(const QModelIndex&)), - controller, SLOT(triggerItem(const QModelIndex&))); - connect(this, SIGNAL(activated(const QModelIndex&)), - controller, SLOT(triggerItem(const QModelIndex&))); + 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&))); + } + connect(this, SIGNAL(entered(const QModelIndex&)), + controller, SLOT(emitItemEntered(const QModelIndex&))); + connect(this, SIGNAL(viewportEntered()), + controller, SLOT(emitViewportEntered())); connect(controller, SIGNAL(showPreviewChanged(bool)), - this, SLOT(updateGridSize(bool))); + this, SLOT(slotShowPreviewChanged(bool))); + connect(controller, SIGNAL(showAdditionalInfoChanged(bool)), + this, SLOT(slotShowAdditionalInfoChanged(bool))); connect(controller, SIGNAL(zoomIn()), this, SLOT(zoomIn())); connect(controller, SIGNAL(zoomOut()), @@ -59,14 +70,16 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); Q_ASSERT(settings != 0); - m_viewOptions = KListView::viewOptions(); + 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; - updateGridSize(controller->showPreview()); + setWordWrap(settings->numberOfTextlines() > 1); + updateGridSize(controller->showPreview(), controller->showAdditionalInfo()); if (settings->arrangement() == QListView::TopToBottom) { setFlow(QListView::LeftToRight); @@ -74,17 +87,41 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle } else { setFlow(QListView::TopToBottom); m_viewOptions.decorationPosition = QStyleOptionViewItem::Left; + m_viewOptions.displayAlignment = Qt::AlignLeft | Qt::AlignVCenter; } - - m_itemCategorizer = new DolphinItemCategorizer(); - // setItemCategorizer(m_itemCategorizer); } DolphinIconsView::~DolphinIconsView() { - setItemCategorizer(0); - delete m_itemCategorizer; - m_itemCategorizer = 0; +} + +QRect DolphinIconsView::visualRect(const QModelIndex& index) const +{ + const bool leftToRightFlow = (flow() == QListView::LeftToRight); + + QRect itemRect = KCategorizedView::visualRect(index); + const int maxWidth = m_itemSize.width(); + const int maxHeight = m_itemSize.height(); + + 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); + } + itemRect.setWidth(maxWidth); + } + + 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); + } + + return itemRect; } QStyleOptionViewItem DolphinIconsView::viewOptions() const @@ -94,14 +131,21 @@ QStyleOptionViewItem DolphinIconsView::viewOptions() const void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event) { - KListView::contextMenuEvent(event); + KCategorizedView::contextMenuEvent(event); m_controller->triggerContextMenuRequest(event->pos()); } -void DolphinIconsView::mouseReleaseEvent(QMouseEvent* event) +void DolphinIconsView::mousePressEvent(QMouseEvent* event) { - KListView::mouseReleaseEvent(event); m_controller->triggerActivation(); + if (!indexAt(event->pos()).isValid()) { + const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers(); + if (!(modifier & Qt::ShiftModifier) && !(modifier & Qt::ControlModifier)) { + clearSelection(); + } + } + + KCategorizedView::mousePressEvent(event); } void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event) @@ -109,44 +153,63 @@ void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event) if (event->mimeData()->hasUrls()) { event->acceptProposedAction(); } + m_dragging = true; } -void DolphinIconsView::dropEvent(QDropEvent* event) +void DolphinIconsView::dragLeaveEvent(QDragLeaveEvent* event) { - const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData()); - if (!urls.isEmpty()) { - m_controller->indicateDroppedUrls(urls, - indexAt(event->pos()), - event->source()); - event->acceptProposedAction(); - } - KListView::dropEvent(event); + KCategorizedView::dragLeaveEvent(event); + + // TODO: remove this code when the issue #160611 is solved in Qt 4.4 + m_dragging = false; + setDirtyRegion(m_dropRect); } -void DolphinIconsView::updateGridSize(bool showPreview) +void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event) { - const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); - Q_ASSERT(settings != 0); + KCategorizedView::dragMoveEvent(event); - int gridWidth = settings->gridWidth(); - int gridHeight = settings->gridHeight(); - int size = settings->iconSize(); + // 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 = visualRect(index); + setDirtyRegion(m_dropRect); +} - if (showPreview) { - const int previewSize = settings->previewSize(); - const int diff = previewSize - size; - Q_ASSERT(diff >= 0); - gridWidth += diff; - gridHeight += diff; +void DolphinIconsView::dropEvent(QDropEvent* event) +{ + if (!selectionModel()->isSelected(indexAt(event->pos()))) { + const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData()); + if (!urls.isEmpty()) { + m_controller->indicateDroppedUrls(urls, + indexAt(event->pos()), + event->source()); + event->acceptProposedAction(); + } + } + KCategorizedView::dropEvent(event); + m_dragging = false; +} - size = previewSize; +void DolphinIconsView::paintEvent(QPaintEvent* event) +{ + KCategorizedView::paintEvent(event); + + // 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); + DolphinController::drawHoverIndication(viewport(), m_dropRect, brush); } +} - m_viewOptions.decorationSize = QSize(size, size); - setGridSize(QSize(gridWidth, gridHeight)); +void DolphinIconsView::slotShowPreviewChanged(bool showPreview) +{ + updateGridSize(showPreview, m_controller->showAdditionalInfo()); +} - m_controller->setZoomInPossible(isZoomInPossible()); - m_controller->setZoomOutPossible(isZoomOutPossible()); +void DolphinIconsView::slotShowAdditionalInfoChanged(bool showAdditionalInfo) +{ + updateGridSize(m_controller->showPreview(), showAdditionalInfo); } void DolphinIconsView::zoomIn() @@ -172,10 +235,10 @@ void DolphinIconsView::zoomIn() // increase also the grid size const int diff = newIconSize - oldIconSize; - settings->setGridWidth(settings->gridWidth() + diff); - settings->setGridHeight(settings->gridHeight() + diff); + settings->setItemWidth(settings->itemWidth() + diff); + settings->setItemHeight(settings->itemHeight() + diff); - updateGridSize(showPreview); + updateGridSize(showPreview, m_controller->showAdditionalInfo()); } } @@ -203,10 +266,10 @@ void DolphinIconsView::zoomOut() // decrease also the grid size const int diff = oldIconSize - newIconSize; - settings->setGridWidth(settings->gridWidth() - diff); - settings->setGridHeight(settings->gridHeight() - diff); + settings->setItemWidth(settings->itemWidth() - diff); + settings->setItemHeight(settings->itemHeight() - diff); - updateGridSize(showPreview); + updateGridSize(showPreview, m_controller->showAdditionalInfo()); } } @@ -254,4 +317,45 @@ int DolphinIconsView::decreasedIconSize(int size) const return decSize; } +void DolphinIconsView::updateGridSize(bool showPreview, bool showAdditionalInfo) +{ + 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; + } + + if (showAdditionalInfo) { + itemHeight += 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, itemHeight + spacing)); + + m_itemSize = QSize(itemWidth, itemHeight); + + m_controller->setZoomInPossible(isZoomInPossible()); + m_controller->setZoomOutPossible(isZoomOutPossible()); +} + #include "dolphiniconsview.moc"