X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/ea548584637bf0f6da5d8dac0e7172a4cdc1fc50..ec00f379dc42b00a64ab1af25bb4bb1a06bd7449:/src/dolphiniconsview.cpp diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index 5c4f56008..37f0bf172 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -25,9 +25,7 @@ #include "dolphin_iconsmodesettings.h" -#include -#include -#include +#include #include #include @@ -35,14 +33,16 @@ #include DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) : - KListView(parent), + KCategorizedView(parent), m_controller(controller), - m_dragging(false) + 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); @@ -53,8 +53,6 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle connect(this, SIGNAL(doubleClicked(const QModelIndex&)), controller, SLOT(triggerItem(const QModelIndex&))); } - connect(this, SIGNAL(activated(const QModelIndex&)), - controller, SLOT(triggerItem(const QModelIndex&))); connect(this, SIGNAL(entered(const QModelIndex&)), controller, SLOT(emitItemEntered(const QModelIndex&))); connect(this, SIGNAL(viewportEntered()), @@ -72,7 +70,7 @@ 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()); @@ -97,6 +95,35 @@ DolphinIconsView::~DolphinIconsView() { } +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 { return m_viewOptions; @@ -104,12 +131,13 @@ QStyleOptionViewItem DolphinIconsView::viewOptions() const void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event) { - KListView::contextMenuEvent(event); + KCategorizedView::contextMenuEvent(event); m_controller->triggerContextMenuRequest(event->pos()); } void DolphinIconsView::mousePressEvent(QMouseEvent* event) { + m_controller->triggerActivation(); if (!indexAt(event->pos()).isValid()) { const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers(); if (!(modifier & Qt::ShiftModifier) && !(modifier & Qt::ControlModifier)) { @@ -117,13 +145,7 @@ void DolphinIconsView::mousePressEvent(QMouseEvent* event) } } - KListView::mousePressEvent(event); -} - -void DolphinIconsView::mouseReleaseEvent(QMouseEvent* event) -{ - KListView::mouseReleaseEvent(event); - m_controller->triggerActivation(); + KCategorizedView::mousePressEvent(event); } void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event) @@ -136,7 +158,7 @@ void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event) void DolphinIconsView::dragLeaveEvent(QDragLeaveEvent* event) { - KListView::dragLeaveEvent(event); + KCategorizedView::dragLeaveEvent(event); // TODO: remove this code when the issue #160611 is solved in Qt 4.4 m_dragging = false; @@ -145,7 +167,7 @@ void DolphinIconsView::dragLeaveEvent(QDragLeaveEvent* event) void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event) { - KListView::dragMoveEvent(event); + KCategorizedView::dragMoveEvent(event); // TODO: remove this code when the issue #160611 is solved in Qt 4.4 const QModelIndex index = indexAt(event->pos()); @@ -156,31 +178,27 @@ void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event) void DolphinIconsView::dropEvent(QDropEvent* event) { - const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData()); - if (!urls.isEmpty()) { - m_controller->indicateDroppedUrls(urls, - indexAt(event->pos()), - event->source()); - event->acceptProposedAction(); + 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(); + } } - KListView::dropEvent(event); + KCategorizedView::dropEvent(event); m_dragging = false; } void DolphinIconsView::paintEvent(QPaintEvent* event) { - KListView::paintEvent(event); + KCategorizedView::paintEvent(event); + // TODO: remove this code when the issue #160611 is solved in Qt 4.4 if (m_dragging) { - // TODO: remove this code when the issue #160611 is solved in Qt 4.4 - QPainter painter(viewport()); - painter.save(); - QBrush brush(m_viewOptions.palette.brush(QPalette::Normal, QPalette::Highlight)); - QColor color = brush.color(); - color.setAlpha(64); - brush.setColor(color); - painter.fillRect(m_dropRect, brush); - painter.restore(); + const QBrush& brush = m_viewOptions.palette.brush(QPalette::Normal, QPalette::Highlight); + DolphinController::drawHoverIndication(viewport(), m_dropRect, brush); } } @@ -334,6 +352,8 @@ void DolphinIconsView::updateGridSize(bool showPreview, bool showAdditionalInfo) const int spacing = settings->gridSpacing(); setGridSize(QSize(itemWidth + spacing, itemHeight + spacing)); + m_itemSize = QSize(itemWidth, itemHeight); + m_controller->setZoomInPossible(isZoomInPossible()); m_controller->setZoomOutPossible(isZoomOutPossible()); }