X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/ca7aaecbdbddb27f7442e69d2770b97b4307f338..4a5218b3671cfa637d66bc21c231d5d97670a3fc:/src/dolphincontroller.cpp diff --git a/src/dolphincontroller.cpp b/src/dolphincontroller.cpp index abbae6ec7..820d34a06 100644 --- a/src/dolphincontroller.cpp +++ b/src/dolphincontroller.cpp @@ -26,10 +26,11 @@ #include #include +Qt::MouseButtons DolphinController::m_mouseButtons = Qt::NoButton; + DolphinController::DolphinController(DolphinView* dolphinView) : QObject(dolphinView), m_zoomLevel(0), - m_openTab(false), m_url(), m_dolphinView(dolphinView), m_itemView(0) @@ -52,17 +53,17 @@ void DolphinController::setItemView(QAbstractItemView* view) { if (m_itemView != 0) { disconnect(m_itemView, SIGNAL(pressed(const QModelIndex&)), - this, SLOT(updateOpenTabState())); + this, SLOT(updateMouseButtonState())); } m_itemView = view; if (m_itemView != 0) { m_zoomLevel = ZoomLevelInfo::zoomLevelForIconSize(m_itemView->iconSize()); - + // TODO: this is a workaround until Qt-issue 176832 has been fixed connect(m_itemView, SIGNAL(pressed(const QModelIndex&)), - this, SLOT(updateOpenTabState())); + this, SLOT(updateMouseButtonState())); } } @@ -84,11 +85,11 @@ void DolphinController::requestActivation() emit activated(); } -void DolphinController::indicateDroppedUrls(const KUrl::List& urls, +void DolphinController::indicateDroppedUrls(const KFileItem& destItem, const KUrl& destPath, - const KFileItem& destItem) + QDropEvent* event) { - emit urlsDropped(urls, destPath, destItem); + emit urlsDropped(destItem, destPath, event); } @@ -128,13 +129,36 @@ void DolphinController::handleKeyPressEvent(QKeyEvent* event) const QItemSelectionModel* selModel = m_itemView->selectionModel(); const QModelIndex currentIndex = selModel->currentIndex(); - const bool trigger = currentIndex.isValid() - && (event->key() == Qt::Key_Return) - && (selModel->selectedIndexes().count() > 0); - if (trigger) { - const QModelIndexList indexList = selModel->selectedIndexes(); - foreach (const QModelIndex& index, indexList) { - triggerItem(index); + + if (currentIndex.isValid() && selModel->selectedIndexes().count() > 0) { + const int key = event->key(); + + if ((key == Qt::Key_Return) || (key == Qt::Key_Enter) || (key == Qt::Key_Right)) { + + const QModelIndexList indexList = selModel->selectedIndexes(); + const bool isColumnView = m_dolphinView->mode() == m_dolphinView->ColumnView; + + if (key == Qt::Key_Right) { + if (isColumnView) { + // If it is the right arrow key and in the column view-only. + KFileItem curFileItem; + foreach(const QModelIndex& index, indexList) { + curFileItem = itemForIndex(index); + if (!curFileItem.isFile()) { + /* We want + * to make sure that the selected item + * is only a folder. If we did not have this check, it would be possible to use + * the right arrow to open a file when in the column view */ + emit itemTriggered(curFileItem); + } + } + } + } else { + //Else it is Return or Enter keypress, so it is okay to perform the action of triggering, on files also. + foreach(const QModelIndex& index, indexList) { + emit itemTriggered(itemForIndex(index)); + } + } } } } @@ -153,6 +177,11 @@ void DolphinController::replaceUrlByClipboard() } } +void DolphinController::emitHideToolTip() +{ + emit hideToolTip(); +} + KFileItem DolphinController::itemForIndex(const QModelIndex& index) const { Q_ASSERT(m_itemView != 0); @@ -165,24 +194,30 @@ KFileItem DolphinController::itemForIndex(const QModelIndex& index) const void DolphinController::triggerItem(const QModelIndex& index) { - const bool openTab = m_openTab; - m_openTab = false; - - const KFileItem item = itemForIndex(index); - if (index.isValid() && (index.column() == KDirModel::Name)) { - if (openTab && (item.isDir() || m_dolphinView->isTabsForFilesEnabled())) { - emit tabRequested(item.url()); - } else { + if (m_mouseButtons & Qt::LeftButton) { + const KFileItem item = itemForIndex(index); + if (index.isValid() && (index.column() == KDirModel::Name)) { emit itemTriggered(item); - } - } else { - m_itemView->clearSelection(); - if (!openTab) { + } else { + m_itemView->clearSelection(); emit itemEntered(KFileItem()); } } } +void DolphinController::requestTab(const QModelIndex& index) +{ + if (m_mouseButtons & Qt::MidButton) { + const KFileItem item = itemForIndex(index); + const bool validRequest = index.isValid() && + (index.column() == KDirModel::Name) && + (item.isDir() || m_dolphinView->isTabsForFilesEnabled()); + if (validRequest) { + emit tabRequested(item.url()); + } + } +} + void DolphinController::emitItemEntered(const QModelIndex& index) { KFileItem item = itemForIndex(index); @@ -196,9 +231,9 @@ void DolphinController::emitViewportEntered() emit viewportEntered(); } -void DolphinController::updateOpenTabState() +void DolphinController::updateMouseButtonState() { - m_openTab = QApplication::mouseButtons() & Qt::MidButton; + m_mouseButtons = QApplication::mouseButtons(); } #include "dolphincontroller.moc"