From: Peter Penz Date: Tue, 6 Dec 2011 20:15:36 +0000 (+0100) Subject: Selection and current item fixes X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/9d5d18739fde76f2d606a4cc9f1e7cc442faa7e0?ds=inline Selection and current item fixes - Remember selection + current item when switching view-modes - Fix the current item indicator alignment for selections - Set the item as current item when the selection toggle has been clicked --- diff --git a/src/kitemviews/kfileitemlistwidget.cpp b/src/kitemviews/kfileitemlistwidget.cpp index 4eccf6862..c2e43e8e6 100644 --- a/src/kitemviews/kfileitemlistwidget.cpp +++ b/src/kitemviews/kfileitemlistwidget.cpp @@ -281,7 +281,7 @@ void KFileItemListWidget::setTextColor(const QColor& color) QColor KFileItemListWidget::textColor() const { - if (m_customTextColor.isValid()) { + if (m_customTextColor.isValid() && !isSelected()) { return m_customTextColor; } diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index b7b008545..e77de292a 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -187,7 +187,6 @@ bool KItemListController::keyPressEvent(QKeyEvent* event) } } - switch (key) { case Qt::Key_Home: index = 0; @@ -345,6 +344,7 @@ bool KItemListController::mousePressEvent(QGraphicsSceneMouseEvent* event, const m_selectionTogglePressed = m_view->isAboveSelectionToggle(m_pressedIndex, m_pressedMousePos); if (m_selectionTogglePressed) { m_selectionManager->setSelected(m_pressedIndex, 1, KItemListSelectionManager::Toggle); + m_selectionManager->setCurrentItem(m_pressedIndex); return true; } diff --git a/src/kitemviews/kitemlistwidget.cpp b/src/kitemviews/kitemlistwidget.cpp index 24840724c..687367adb 100644 --- a/src/kitemviews/kitemlistwidget.cpp +++ b/src/kitemviews/kitemlistwidget.cpp @@ -121,11 +121,22 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o if (isCurrent()) { QStyleOptionViewItemV4 viewItemOption; viewItemOption.initFrom(widget); - viewItemOption.rect = textRect().toRect(); + + const QRect iconBounds = iconRect().toRect(); + const QRect textBounds = textRect().toRect(); + if (iconBounds.bottom() >= textBounds.top()) { + viewItemOption.rect = textBounds; + } else { + // See KItemListWidget::drawItemStyleOption(): The selection rectangle + // gets decreased. + viewItemOption.rect = textBounds.adjusted(1, 1, -1, -1); + } + viewItemOption.state = QStyle::State_Enabled | QStyle::State_Item; if (m_selected) { viewItemOption.state |= QStyle::State_Selected; } + viewItemOption.viewItemPosition = QStyleOptionViewItemV4::OnlyOne; style()->drawPrimitive(QStyle::PE_FrameFocusRect, &viewItemOption, painter, widget); } @@ -428,17 +439,14 @@ void KItemListWidget::drawItemStyleOption(QPainter* painter, QWidget* widget, QS viewItemOption.state = styleState; viewItemOption.viewItemPosition = QStyleOptionViewItemV4::OnlyOne; - const bool drawMerged = (iconBounds.top() == textBounds.top() && - iconBounds.bottom() == textBounds.bottom()); - - if (drawMerged) { + if (iconBounds.bottom() >= textBounds.top()) { viewItemOption.rect = iconBounds | textBounds; widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget); } else { viewItemOption.rect = iconBounds; widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget); - viewItemOption.rect = textBounds.adjusted(2, 2, -2, -2); + viewItemOption.rect = textBounds.adjusted(1, 1, -1, -1); widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget); } } diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 94eed5cf3..d839c61a3 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -1135,6 +1135,11 @@ void DolphinView::applyViewProperties() // has been modified. const bool restoreModel = (model->count() > 0); if (restoreModel) { + const int currentItemIndex = m_container->controller()->selectionManager()->currentItem(); + if (currentItemIndex >= 0) { + m_currentItemUrl = model->fileItem(currentItemIndex).url(); + } + m_selectedUrls = selectedItems().urlList(); model->clear(); } diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h index 9111516b4..b8a1077f7 100644 --- a/src/views/dolphinview.h +++ b/src/views/dolphinview.h @@ -757,10 +757,11 @@ private: QTimer* m_selectionChangedTimer; - KUrl m_currentItemUrl; + KUrl m_currentItemUrl; // Used for making the view to remember the current URL after F5 QPoint m_restoredContentsPosition; KUrl m_createdItemUrl; // URL for a new item that got created by the "Create New..." menu - QList m_selectedUrls; // this is used for making the View to remember selections after F5 + + QList m_selectedUrls; // Used for making the view to remember selections after F5 VersionControlObserver* m_versionControlObserver;