]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphindetailsview.cpp
For the URL control of Dolphin and Konqueror to be LTR on RTL desktops (those are...
[dolphin.git] / src / dolphindetailsview.cpp
index b725b0da237451f7ea8fab7f9cd3a17febe1c5ce..0dfe2ddb57cd3638e274577710ce0ee4f35945c9 100644 (file)
@@ -60,6 +60,7 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
     Q_ASSERT(settings != 0);
     Q_ASSERT(controller != 0);
 
+    setLayoutDirection(Qt::LeftToRight);
     setAcceptDrops(true);
     setSortingEnabled(true);
     setUniformRowHeights(true);
@@ -100,27 +101,29 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
     if (KGlobalSettings::singleClick()) {
         connect(this, SIGNAL(clicked(const QModelIndex&)),
                 controller, SLOT(triggerItem(const QModelIndex&)));
-        if (DolphinSettings::instance().generalSettings()->showSelectionToggle()) {
-            m_selectionManager = new SelectionManager(this);
-            connect(m_selectionManager, SIGNAL(selectionChanged()),
-                    this, SLOT(requestActivation()));
-            connect(m_controller, SIGNAL(urlChanged(const KUrl&)),
-                    m_selectionManager, SLOT(reset()));
-         }
     } else {
         connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
                 controller, SLOT(triggerItem(const QModelIndex&)));
     }
+
+    if (DolphinSettings::instance().generalSettings()->showSelectionToggle()) {
+        m_selectionManager = new SelectionManager(this);
+        connect(m_selectionManager, SIGNAL(selectionChanged()),
+                this, SLOT(requestActivation()));
+        connect(m_controller, SIGNAL(urlChanged(const KUrl&)),
+                m_selectionManager, SLOT(reset()));
+    }
+
     connect(this, SIGNAL(entered(const QModelIndex&)),
             this, SLOT(slotEntered(const QModelIndex&)));
     connect(this, SIGNAL(viewportEntered()),
             controller, SLOT(emitViewportEntered()));
-    connect(controller, SIGNAL(zoomIn()),
-            this, SLOT(zoomIn()));
-    connect(controller, SIGNAL(zoomOut()),
-            this, SLOT(zoomOut()));
+    connect(controller, SIGNAL(zoomLevelChanged(int)),
+            this, SLOT(setZoomLevel(int)));
     connect(controller->dolphinView(), SIGNAL(additionalInfoChanged()),
             this, SLOT(updateColumnVisibility()));
+    connect(controller, SIGNAL(activationChanged(bool)),
+            this, SLOT(slotActivationChanged(bool)));
 
     if (settings->useSystemFont()) {
         m_font = KGlobalSettings::generalFont();
@@ -187,6 +190,7 @@ void DolphinDetailsView::mousePressEvent(QMouseEvent* event)
 {
     m_controller->requestActivation();
 
+    const QModelIndex current = currentIndex();
     QTreeView::mousePressEvent(event);
 
     m_expandingTogglePressed = false;
@@ -206,10 +210,17 @@ void DolphinDetailsView::mousePressEvent(QMouseEvent* event)
     }
 
     if (!index.isValid() || (index.column() != DolphinModel::Name)) {
+        if (QApplication::mouseButtons() & Qt::MidButton) {
+            m_controller->replaceUrlByClipboard();
+        }
+
         const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
         if (!(modifier & Qt::ShiftModifier) && !(modifier & Qt::ControlModifier)) {
             clearSelection();
         }
+
+        // restore the current index, other columns are handled as viewport area
+        selectionModel()->setCurrentIndex(current, QItemSelectionModel::Current);
     }
 
     if ((event->button() == Qt::LeftButton) && !m_expandingTogglePressed) {
@@ -265,7 +276,18 @@ void DolphinDetailsView::mouseMoveEvent(QMouseEvent* event)
 
 void DolphinDetailsView::mouseReleaseEvent(QMouseEvent* event)
 {
-    QTreeView::mouseReleaseEvent(event);
+    const QModelIndex index = indexAt(event->pos());
+    if (index.isValid() && (index.column() == DolphinModel::Name)) {
+        QTreeView::mouseReleaseEvent(event);
+    } else {
+        // don't change the current index if the cursor is released
+        // above any other column than the name column, as the other
+        // columns act as viewport
+        const QModelIndex current = currentIndex();
+        QTreeView::mouseReleaseEvent(event);
+        selectionModel()->setCurrentIndex(current, QItemSelectionModel::Current);
+    }
+
     m_expandingTogglePressed = false;
     if (m_showElasticBand) {
         updateElasticBand();
@@ -359,9 +381,13 @@ void DolphinDetailsView::paintEvent(QPaintEvent* event)
 
 void DolphinDetailsView::keyPressEvent(QKeyEvent* event)
 {
+    // If the Control modifier is pressed, a multiple selection
+    // is done and DolphinDetailsView::currentChanged() may not
+    // not change the selection in a custom way.
+    m_keyPressed = !(event->modifiers() & Qt::ControlModifier);
+
     QTreeView::keyPressEvent(event);
     m_controller->handleKeyPressEvent(event);
-    m_keyPressed = true;
 }
 
 void DolphinDetailsView::keyReleaseEvent(QKeyEvent* event)
@@ -440,12 +466,9 @@ void DolphinDetailsView::synchronizeSortingState(int column)
 
 void DolphinDetailsView::slotEntered(const QModelIndex& index)
 {
-    const QPoint pos = viewport()->mapFromGlobal(QCursor::pos());
-    const int nameColumnWidth = header()->sectionSize(DolphinModel::Name);
-    if (pos.x() < nameColumnWidth) {
+    if (index.column() == DolphinModel::Name) {
         m_controller->emitItemEntered(index);
-    }
-    else {
+    } else {
         m_controller->emitViewportEntered();
     }
 }
@@ -467,30 +490,13 @@ QRect DolphinDetailsView::elasticBandRect() const
     return QRect(topLeft, m_elasticBandDestination).normalized();
 }
 
-void DolphinDetailsView::zoomIn()
+void DolphinDetailsView::setZoomLevel(int level)
 {
-    if (isZoomInPossible()) {
-        DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
-        switch (settings->iconSize()) {
-        case KIconLoader::SizeSmall:  settings->setIconSize(KIconLoader::SizeMedium); break;
-        case KIconLoader::SizeMedium: settings->setIconSize(KIconLoader::SizeLarge); break;
-        default: Q_ASSERT(false); break;
-        }
-        updateDecorationSize();
-    }
-}
-
-void DolphinDetailsView::zoomOut()
-{
-    if (isZoomOutPossible()) {
-        DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
-        switch (settings->iconSize()) {
-        case KIconLoader::SizeLarge:  settings->setIconSize(KIconLoader::SizeMedium); break;
-        case KIconLoader::SizeMedium: settings->setIconSize(KIconLoader::SizeSmall); break;
-        default: Q_ASSERT(false); break;
-        }
-        updateDecorationSize();
-    }
+    const int size = DolphinController::iconSizeForZoomLevel(level);
+    DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
+    settings->setIconSize(size);
+    
+    updateDecorationSize();
 }
 
 void DolphinDetailsView::configureColumns(const QPoint& pos)
@@ -553,6 +559,11 @@ void DolphinDetailsView::slotHeaderSectionResized(int logicalIndex, int oldSize,
     }
 }
 
+void DolphinDetailsView::slotActivationChanged(bool active)
+{
+    setAlternatingRowColors(active);
+}
+
 void DolphinDetailsView::disableAutoResizing()
 {
     m_autoResize = false;
@@ -573,18 +584,6 @@ void DolphinDetailsView::updateFont()
     }
 }
 
-bool DolphinDetailsView::isZoomInPossible() const
-{
-    DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
-    return settings->iconSize() < KIconLoader::SizeLarge;
-}
-
-bool DolphinDetailsView::isZoomOutPossible() const
-{
-    DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
-    return settings->iconSize() > KIconLoader::SizeSmall;
-}
-
 void DolphinDetailsView::updateDecorationSize()
 {
     DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
@@ -592,9 +591,6 @@ void DolphinDetailsView::updateDecorationSize()
     setIconSize(QSize(iconSize, iconSize));
     m_decorationSize = QSize(iconSize, iconSize);
 
-    m_controller->setZoomInPossible(isZoomInPossible());
-    m_controller->setZoomOutPossible(isZoomOutPossible());
-
     if (m_selectionManager != 0) {
         m_selectionManager->reset();
     }