]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Selection and current item fixes
authorPeter Penz <peter.penz19@gmail.com>
Tue, 6 Dec 2011 20:15:36 +0000 (21:15 +0100)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 6 Dec 2011 20:17:01 +0000 (21:17 +0100)
- 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

src/kitemviews/kfileitemlistwidget.cpp
src/kitemviews/kitemlistcontroller.cpp
src/kitemviews/kitemlistwidget.cpp
src/views/dolphinview.cpp
src/views/dolphinview.h

index 4eccf686265c39500927aa92a91c734ef8bd15b2..c2e43e8e60436dd2755779a5899d80eec68846ee 100644 (file)
@@ -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;
     }
 
index b7b0085453886c0553f928da123cae937613bee8..e77de292ae48c2edb4df098fc816059b50a95d8d 100644 (file)
@@ -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;
     }
 
index 24840724cda08372679b3f5da57ca5e852f60017..687367adb9fffa04917a78aa2eb83ce1d00a1031 100644 (file)
@@ -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);
     }
 }
index 94eed5cf32c57f5bebd176ceac4e7fc9d1709e64..d839c61a3b73abae2e331d792f08bda57f35bd5d 100644 (file)
@@ -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();
         }
 
index 9111516b43ebaa8b346e6c8fffeafffd2011e4d6..b8a1077f7a17644e47528deda8cd121a08f17e8f 100644 (file)
@@ -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<KUrl> m_selectedUrls; // this is used for making the View to remember selections after F5
+
+    QList<KUrl> m_selectedUrls; // Used for making the view to remember selections after F5
     
     VersionControlObserver* m_versionControlObserver;