X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/f11c699fa203dd2cde0e85c63a6d186e3fa6a3de..86d9c40ab71df5b8bd5063251337d5ca0c22380a:/src/dolphincontroller.cpp diff --git a/src/dolphincontroller.cpp b/src/dolphincontroller.cpp index ebd85e021..81cec2868 100644 --- a/src/dolphincontroller.cpp +++ b/src/dolphincontroller.cpp @@ -18,18 +18,21 @@ ***************************************************************************/ #include "dolphincontroller.h" +#include "zoomlevelinfo.h" -#include +#include +#include +#include +#include +#include DolphinController::DolphinController(DolphinView* dolphinView) : QObject(dolphinView), - m_showHiddenFiles(false), - m_showPreview(false), - m_zoomInPossible(false), - m_zoomOutPossible(false), -//m_additionalInfoCount(0), + m_zoomLevel(0), + m_mouseButtons(Qt::NoButton), m_url(), - m_dolphinView(dolphinView) + m_dolphinView(dolphinView), + m_itemView(0) { } @@ -45,6 +48,24 @@ void DolphinController::setUrl(const KUrl& url) } } +void DolphinController::setItemView(QAbstractItemView* view) +{ + if (m_itemView != 0) { + disconnect(m_itemView, SIGNAL(pressed(const QModelIndex&)), + 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(updateMouseButtonState())); + } +} + void DolphinController::triggerUrlChangeRequest(const KUrl& url) { if (m_url != url) { @@ -63,12 +84,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, - QWidget* source) + QDropEvent* event) { - emit urlsDropped(urls, destPath, destItem, source); + emit urlsDropped(destItem, destPath, event); } @@ -87,80 +107,100 @@ void DolphinController::indicateAdditionalInfoChange(const KFileItemDelegate::In emit additionalInfoChanged(info); } -void DolphinController::setShowHiddenFiles(bool show) +void DolphinController::indicateActivationChange(bool active) { - if (m_showHiddenFiles != show) { - m_showHiddenFiles = show; - emit showHiddenFilesChanged(show); - } + emit activationChanged(active); } -void DolphinController::setShowPreview(bool show) +void DolphinController::setZoomLevel(int level) { - if (m_showPreview != show) { - m_showPreview = show; - emit showPreviewChanged(show); + Q_ASSERT(level >= ZoomLevelInfo::minimumLevel()); + Q_ASSERT(level <= ZoomLevelInfo::maximumLevel()); + if (level != m_zoomLevel) { + m_zoomLevel = level; + emit zoomLevelChanged(m_zoomLevel); } } -/*void DolphinController::setAdditionalInfoCount(int count) +void DolphinController::handleKeyPressEvent(QKeyEvent* event) { - if (m_additionalInfoCount != count) { - m_additionalInfoCount = count; - emit additionalInfoCountChanged(count); - } -}*/ + Q_ASSERT(m_itemView != 0); -void DolphinController::indicateActivationChange(bool active) -{ - emit activationChanged(active); + const QItemSelectionModel* selModel = m_itemView->selectionModel(); + const QModelIndex currentIndex = selModel->currentIndex(); + const bool trigger = currentIndex.isValid() + && ((event->key() == Qt::Key_Return) + || (event->key() == Qt::Key_Enter)) + && (selModel->selectedIndexes().count() > 0); + if (trigger) { + const QModelIndexList indexList = selModel->selectedIndexes(); + foreach (const QModelIndex& index, indexList) { + emit itemTriggered(itemForIndex(index)); + } + } } -void DolphinController::triggerZoomIn() +void DolphinController::replaceUrlByClipboard() { - emit zoomIn(); + const QClipboard* clipboard = QApplication::clipboard(); + QString text; + if (clipboard->mimeData(QClipboard::Selection)->hasText()) { + text = clipboard->mimeData(QClipboard::Selection)->text(); + } else if (clipboard->mimeData(QClipboard::Clipboard)->hasText()) { + text = clipboard->mimeData(QClipboard::Clipboard)->text(); + } + if (!text.isEmpty() && QDir::isAbsolutePath(text)) { + m_dolphinView->setUrl(KUrl(text)); + } } -void DolphinController::triggerZoomOut() +void DolphinController::emitHideToolTip() { - emit zoomOut(); + emit hideToolTip(); } -void DolphinController::drawHoverIndication(QWidget* widget, - const QRect& bounds, - const QBrush& brush) +KFileItem DolphinController::itemForIndex(const QModelIndex& index) const { - QPainter painter(widget); - painter.save(); - QBrush blendedBrush(brush); - QColor color = blendedBrush.color(); - color.setAlpha(64); - blendedBrush.setColor(color); + Q_ASSERT(m_itemView != 0); - const int radius = 10; - QPainterPath path(QPointF(bounds.left(), bounds.top() + radius)); - path.quadTo(bounds.left(), bounds.top(), bounds.left() + radius, bounds.top()); - path.lineTo(bounds.right() - radius, bounds.top()); - path.quadTo(bounds.right(), bounds.top(), bounds.right(), bounds.top() + radius); - path.lineTo(bounds.right(), bounds.bottom() - radius); - path.quadTo(bounds.right(), bounds.bottom(), bounds.right() - radius, bounds.bottom()); - path.lineTo(bounds.left() + radius, bounds.bottom()); - path.quadTo(bounds.left(), bounds.bottom(), bounds.left(), bounds.bottom() - radius); - path.closeSubpath(); + QAbstractProxyModel* proxyModel = static_cast(m_itemView->model()); + KDirModel* dirModel = static_cast(proxyModel->sourceModel()); + const QModelIndex dirIndex = proxyModel->mapToSource(index); + return dirModel->itemForIndex(dirIndex); +} - painter.setRenderHint(QPainter::Antialiasing); - painter.fillPath(path, blendedBrush); - painter.restore(); +void DolphinController::triggerItem(const QModelIndex& index) +{ + if (m_mouseButtons & Qt::LeftButton) { + const KFileItem item = itemForIndex(index); + if (index.isValid() && (index.column() == KDirModel::Name)) { + emit itemTriggered(item); + } else { + m_itemView->clearSelection(); + emit itemEntered(KFileItem()); + } + } } -void DolphinController::triggerItem(const KFileItem& item) +void DolphinController::requestTab(const QModelIndex& index) { - emit itemTriggered(item); + 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 KFileItem& item) +void DolphinController::emitItemEntered(const QModelIndex& index) { - emit itemEntered(item); + KFileItem item = itemForIndex(index); + if (!item.isNull()) { + emit itemEntered(item); + } } void DolphinController::emitViewportEntered() @@ -168,4 +208,9 @@ void DolphinController::emitViewportEntered() emit viewportEntered(); } +void DolphinController::updateMouseButtonState() +{ + m_mouseButtons = QApplication::mouseButtons(); +} + #include "dolphincontroller.moc"