X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/a5473c0cf255b5846ad85eebc043ebb6551e72d0..7eeb8dba6aeba09aa3dfa7fa5f0b00840d4d8317:/src/dolphiniconsview.cpp diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index 10ffd9d42..46c27cd28 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -32,7 +32,6 @@ #include #include -#include #include #include @@ -44,7 +43,7 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinSortFilterProxyModel* proxyModel) : KCategorizedView(parent), m_controller(controller), - m_categoryDrawer(0), + m_categoryDrawer(new DolphinCategoryDrawer(this)), m_extensionsFactory(0), m_font(), m_decorationSize(), @@ -79,8 +78,6 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, controller, SLOT(emitItemEntered(const QModelIndex&))); connect(this, SIGNAL(viewportEntered()), controller, SLOT(emitViewportEntered())); - connect(controller, SIGNAL(nameFilterChanged(const QString&)), - this, SLOT(setNameFilter(const QString&))); connect(controller, SIGNAL(zoomLevelChanged(int)), this, SLOT(setZoomLevel(int))); @@ -98,9 +95,10 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, m_font = KGlobalSettings::generalFont(); } else { m_font = QFont(settings->fontFamily(), - settings->fontSize(), + qRound(settings->fontSize()), settings->fontWeight(), settings->italicFont()); + m_font.setPointSizeF(settings->fontSize()); } setWordWrap(settings->numberOfTextlines() > 1); @@ -115,7 +113,7 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, m_displayAlignment = Qt::AlignLeft | Qt::AlignVCenter; } - m_categoryDrawer = new DolphinCategoryDrawer(); + connect(m_categoryDrawer, SIGNAL(actionRequested(int,QModelIndex)), this, SLOT(categoryDrawerActionRequested(int,QModelIndex))); setCategoryDrawer(m_categoryDrawer); setFocus(); @@ -123,14 +121,12 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, connect(KGlobalSettings::self(), SIGNAL(settingsChanged(int)), this, SLOT(slotGlobalSettingsChanged(int))); - m_extensionsFactory = new ViewExtensionsFactory(this, controller); updateGridSize(view->showPreview(), 0); + m_extensionsFactory = new ViewExtensionsFactory(this, controller); } DolphinIconsView::~DolphinIconsView() { - delete m_categoryDrawer; - m_categoryDrawer = 0; } void DolphinIconsView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight) @@ -149,6 +145,7 @@ QStyleOptionViewItem DolphinIconsView::viewOptions() const { QStyleOptionViewItem viewOptions = KCategorizedView::viewOptions(); viewOptions.font = m_font; + viewOptions.fontMetrics = QFontMetrics(m_font); viewOptions.decorationPosition = m_decorationPosition; viewOptions.decorationSize = m_decorationSize; viewOptions.displayAlignment = m_displayAlignment; @@ -175,14 +172,8 @@ void DolphinIconsView::mousePressEvent(QMouseEvent* event) setState(QAbstractItemView::DraggingState); } - 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(); - } + if (!index.isValid() && (QApplication::mouseButtons() & Qt::MidButton)) { + m_controller->replaceUrlByClipboard(); } KCategorizedView::mousePressEvent(event); @@ -202,12 +193,14 @@ void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event) void DolphinIconsView::dragLeaveEvent(QDragLeaveEvent* event) { - Q_UNUSED(event); + KCategorizedView::dragLeaveEvent(event); setDirtyRegion(m_dropRect); } void DolphinIconsView::dragMoveEvent(QDragMoveEvent* event) { + 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); @@ -234,6 +227,8 @@ void DolphinIconsView::dropEvent(QDropEvent* event) const QModelIndex index = indexAt(event->pos()); const KFileItem item = m_controller->itemForIndex(index); m_controller->indicateDroppedUrls(item, m_controller->url(), event); + // don't call KCategorizedView::dropEvent(event), as it moves + // the items which is not wanted } QModelIndex DolphinIconsView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) @@ -317,14 +312,8 @@ void DolphinIconsView::keyPressEvent(QKeyEvent* event) void DolphinIconsView::wheelEvent(QWheelEvent* event) { - // let Ctrl+wheel events propagate to the DolphinView for icon zooming - if (event->modifiers() & Qt::ControlModifier) { - event->ignore(); - return; - } - - horizontalScrollBar()->setSingleStep(m_itemSize.width() / 10); - verticalScrollBar()->setSingleStep(m_itemSize.height() / 10); + horizontalScrollBar()->setSingleStep(m_itemSize.width() / 5); + verticalScrollBar()->setSingleStep(m_itemSize.height() / 5); KCategorizedView::wheelEvent(event); // if the icons are aligned left to right, the vertical wheel event should @@ -385,12 +374,6 @@ void DolphinIconsView::slotAdditionalInfoChanged() updateGridSize(showPreview, view->additionalInfo().count()); } -void DolphinIconsView::setNameFilter(const QString& nameFilter) -{ - DolphinSortFilterProxyModel* proxyModel = static_cast(model()); - proxyModel->setFilterRegExp(nameFilter); -} - void DolphinIconsView::setZoomLevel(int level) { IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); @@ -439,6 +422,33 @@ void DolphinIconsView::slotGlobalSettingsChanged(int category) } } +void DolphinIconsView::categoryDrawerActionRequested(int action, const QModelIndex &index) +{ + const QSortFilterProxyModel *model = dynamic_cast(index.model()); + const QModelIndex topLeft = model->index(index.row(), modelColumn()); + QModelIndex bottomRight = topLeft; + const QString category = model->data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString(); + QModelIndex current = topLeft; + while (true) { + current = model->index(current.row() + 1, modelColumn()); + const QString curCategory = model->data(model->index(current.row(), index.column()), KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString(); + if (!current.isValid() || category != curCategory) { + break; + } + bottomRight = current; + } + switch (action) { + case DolphinCategoryDrawer::SelectAll: + selectionModel()->select(QItemSelection(topLeft, bottomRight), QItemSelectionModel::Select); + break; + case DolphinCategoryDrawer::UnselectAll: + selectionModel()->select(QItemSelection(topLeft, bottomRight), QItemSelectionModel::Deselect); + break; + default: + break; + } +} + void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount) { const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); @@ -458,7 +468,7 @@ void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount) } Q_ASSERT(additionalInfoCount >= 0); - itemHeight += additionalInfoCount * m_font.pointSize() * 2; + itemHeight += additionalInfoCount * QFontMetrics(m_font).height(); // Optimize the item size of the grid in a way to prevent large gaps on the // right border (= row arrangement) or the bottom border (= column arrangement).