X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/b60da9b67acbfe94e43bd631e4e685f366d53ec5..29c5ab3b74d26657c60b40770676be082caa953d:/src/dolphincolumnwidget.cpp diff --git a/src/dolphincolumnwidget.cpp b/src/dolphincolumnwidget.cpp index c552d70e1..e85c9491b 100644 --- a/src/dolphincolumnwidget.cpp +++ b/src/dolphincolumnwidget.cpp @@ -24,14 +24,14 @@ #include "dolphincontroller.h" #include "dolphindirlister.h" #include "dolphinsortfilterproxymodel.h" -#include "dolphinsettings.h" +#include "settings/dolphinsettings.h" #include "dolphinviewautoscroller.h" #include "dolphin_columnmodesettings.h" #include "dolphin_generalsettings.h" #include "draganddrophelper.h" #include "folderexpander.h" #include "selectionmanager.h" -#include "tooltipmanager.h" +#include "tooltips/tooltipmanager.h" #include #include @@ -55,6 +55,7 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent, m_active(true), m_view(columnView), m_selectionManager(0), + m_autoScroller(0), m_url(url), m_childUrl(), m_font(), @@ -63,6 +64,7 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent, m_dolphinModel(0), m_proxyModel(0), m_previewGenerator(0), + m_toolTipManager(0), m_dropRect() { setMouseTracking(true); @@ -77,8 +79,8 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent, setVerticalScrollMode(QListView::ScrollPerPixel); setHorizontalScrollMode(QListView::ScrollPerPixel); - - new DolphinViewAutoScroller(this); + + m_autoScroller = new DolphinViewAutoScroller(this); // apply the column mode settings to the widget const ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); @@ -124,6 +126,7 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent, const DolphinView* dolphinView = m_view->m_controller->dolphinView(); m_proxyModel->setSorting(dolphinView->sorting()); m_proxyModel->setSortOrder(dolphinView->sortOrder()); + m_proxyModel->setSortFoldersFirst(dolphinView->sortFoldersFirst()); setModel(m_proxyModel); @@ -139,14 +142,14 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent, m_previewGenerator->setPreviewShown(m_view->m_controller->dolphinView()->showPreview()); if (DolphinSettings::instance().generalSettings()->showToolTips()) { - new ToolTipManager(this, m_proxyModel); + m_toolTipManager = new ToolTipManager(this, m_proxyModel); } m_dirLister->openUrl(url, KDirLister::NoFlags); connect(KGlobalSettings::self(), SIGNAL(kdisplayFontChanged()), this, SLOT(updateFont())); - + FolderExpander* folderExpander = new FolderExpander(this, m_proxyModel); folderExpander->setEnabled(DolphinSettings::instance().generalSettings()->autoExpandFolders()); connect (folderExpander, SIGNAL(enterDir(const QModelIndex&)), @@ -168,7 +171,7 @@ void DolphinColumnWidget::setDecorationSize(const QSize& size) m_decorationSize = size; doItemsLayout(); if (m_previewGenerator != 0) { - m_previewGenerator->updatePreviews(); + m_previewGenerator->updateIcons(); } if (m_selectionManager != 0) { m_selectionManager->reset(); @@ -177,16 +180,18 @@ void DolphinColumnWidget::setDecorationSize(const QSize& size) void DolphinColumnWidget::setActive(bool active) { - if (m_active == active) { - return; + if (active && (m_view->focusProxy() != this)) { + m_view->setFocusProxy(this); } - m_active = active; + if (m_active != active) { + m_active = active; - if (active) { - activate(); - } else { - deactivate(); + if (active) { + activate(); + } else { + deactivate(); + } } } @@ -206,6 +211,11 @@ void DolphinColumnWidget::setSortOrder(Qt::SortOrder order) m_proxyModel->setSortOrder(order); } +void DolphinColumnWidget::setSortFoldersFirst(bool foldersFirst) +{ + m_proxyModel->setSortFoldersFirst(foldersFirst); +} + void DolphinColumnWidget::setShowHiddenFiles(bool show) { if (show != m_dirLister->showingDotFiles()) { @@ -386,7 +396,34 @@ void DolphinColumnWidget::keyPressEvent(QKeyEvent* event) { QListView::keyPressEvent(event); requestActivation(); - m_view->m_controller->handleKeyPressEvent(event); + + DolphinController* controller = m_view->m_controller; + controller->handleKeyPressEvent(event); + switch (event->key()) { + case Qt::Key_Right: { + // Special key handling for the column: A Key_Right should + // open a new column for the currently selected folder. + const QModelIndex index = currentIndex(); + const KFileItem item = controller->itemForIndex(index); + if (!item.isNull() && item.isDir()) { + controller->emitItemTriggered(item); + } + break; + } + + case Qt::Key_Escape: + selectionModel()->setCurrentIndex(selectionModel()->currentIndex(), + QItemSelectionModel::Current | + QItemSelectionModel::Clear); + break; + + default: + break; + } + + if (m_toolTipManager != 0) { + m_toolTipManager->hideTip(); + } } void DolphinColumnWidget::contextMenuEvent(QContextMenuEvent* event) @@ -405,6 +442,10 @@ void DolphinColumnWidget::contextMenuEvent(QContextMenuEvent* event) clearSelection(); } + if (m_toolTipManager != 0) { + m_toolTipManager->hideTip(); + } + const QPoint pos = m_view->viewport()->mapFromGlobal(event->globalPos()); Q_ASSERT(m_view->m_controller->itemView() == this); m_view->m_controller->triggerContextMenuRequest(pos); @@ -421,7 +462,7 @@ void DolphinColumnWidget::wheelEvent(QWheelEvent* event) event->ignore(); return; } - + const int height = m_decorationSize.height(); const int step = (height >= KIconLoader::SizeHuge) ? height / 10 : (KIconLoader::SizeHuge - height) / 2; verticalScrollBar()->setSingleStep(step); @@ -447,12 +488,42 @@ void DolphinColumnWidget::selectionChanged(const QItemSelection& selected, const selModel->select(deselected, QItemSelectionModel::Deselect); } +void DolphinColumnWidget::currentChanged(const QModelIndex& current, const QModelIndex& previous) +{ + QListView::currentChanged(current, previous); + if (current.isValid() && !m_autoScroller->isActive()) { + scrollTo(current); + } +} + void DolphinColumnWidget::slotEntered(const QModelIndex& index) { m_view->m_controller->setItemView(this); m_view->m_controller->emitItemEntered(index); } +void DolphinColumnWidget::slotClicked(const QModelIndex& index) +{ + DolphinController* controller = m_view->m_controller; + if (KGlobalSettings::singleClick()) { + controller->triggerItem(index); + } else { + // even when using double click, a directory should be opened + // after the first click + const KFileItem item = controller->itemForIndex(index); + if (!item.isNull() && item.isDir()) { + controller->triggerItem(index); + } + } +} + +void DolphinColumnWidget::slotDoubleClicked(const QModelIndex& index) +{ + if (!KGlobalSettings::singleClick()) { + m_view->m_controller->triggerItem(index); + } +} + void DolphinColumnWidget::requestActivation() { m_view->m_controller->setItemView(this); @@ -480,16 +551,14 @@ void DolphinColumnWidget::activate() connect(this, SIGNAL(clicked(const QModelIndex&)), m_view->m_controller, SLOT(requestTab(const QModelIndex&))); - if (KGlobalSettings::singleClick()) { - connect(this, SIGNAL(clicked(const QModelIndex&)), - m_view->m_controller, SLOT(triggerItem(const QModelIndex&))); - } else { - connect(this, SIGNAL(doubleClicked(const QModelIndex&)), - m_view->m_controller, SLOT(triggerItem(const QModelIndex&))); - } + connect(this, SIGNAL(clicked(const QModelIndex&)), + this, SLOT(slotClicked(const QModelIndex&))); + connect(this, SIGNAL(doubleClicked(const QModelIndex&)), + this, SLOT(slotDoubleClicked(const QModelIndex&))); - if (selectionModel() && selectionModel()->currentIndex().isValid()) + if (selectionModel() && selectionModel()->currentIndex().isValid()) { selectionModel()->setCurrentIndex(selectionModel()->currentIndex(), QItemSelectionModel::SelectCurrent); + } updateBackground(); } @@ -497,17 +566,12 @@ void DolphinColumnWidget::activate() void DolphinColumnWidget::deactivate() { clearFocus(); - - // TODO: Connecting to the signal 'activated()' is not possible, as kstyle - // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is - // necessary connecting the signal 'singleClick()' or 'doubleClick'. - if (KGlobalSettings::singleClick()) { - disconnect(this, SIGNAL(clicked(const QModelIndex&)), - m_view->m_controller, SLOT(triggerItem(const QModelIndex&))); - } else { - disconnect(this, SIGNAL(doubleClicked(const QModelIndex&)), - m_view->m_controller, SLOT(triggerItem(const QModelIndex&))); - } + disconnect(this, SIGNAL(clicked(const QModelIndex&)), + m_view->m_controller, SLOT(requestTab(const QModelIndex&))); + disconnect(this, SIGNAL(clicked(const QModelIndex&)), + this, SLOT(slotClicked(const QModelIndex&))); + disconnect(this, SIGNAL(doubleClicked(const QModelIndex&)), + this, SLOT(slotDoubleClicked(const QModelIndex&))); const QModelIndex current = selectionModel()->currentIndex(); selectionModel()->clear();