diff options
| author | Peter Penz <[email protected]> | 2007-07-28 22:27:58 +0000 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2007-07-28 22:27:58 +0000 |
| commit | dcac8012b6a2e63bf7526d8c27d2442906afed32 (patch) | |
| tree | fff107e6dd8737f4ac6f72e214fde238746df4d3 /src/dolphincolumnview.cpp | |
| parent | 2e5379158e74250d37b7a536881ef2b8dbef4b3b (diff) | |
temporary fixes until MultiSelection will be implemented
svn path=/trunk/KDE/kdebase/apps/; revision=693752
Diffstat (limited to 'src/dolphincolumnview.cpp')
| -rw-r--r-- | src/dolphincolumnview.cpp | 141 |
1 files changed, 89 insertions, 52 deletions
diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index c702b8a62..e3e084718 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -26,6 +26,7 @@ #include <kcolorutils.h> #include <kcolorscheme.h> +#include <kdirlister.h> #include <kdirmodel.h> #include <QAbstractProxyModel> @@ -56,6 +57,13 @@ public: inline const KUrl& url() const; + /** + * Updates the selection that the folder gets selected which represents + * the URL \a url. If \a url is empty, the selection of the column widget + * gets cleared. + */ + void updateSelection(const KUrl& url); + protected: virtual QStyleOptionViewItem viewOptions() const; virtual void dragEnterEvent(QDragEnterEvent* event); @@ -93,10 +101,6 @@ ColumnWidget::ColumnWidget(QWidget* parent, m_dragging(false), m_dropRect() { - setAcceptDrops(true); - setDragDropMode(QAbstractItemView::DragDrop); - setDropIndicatorShown(false); - setMouseTracking(true); viewport()->setAttribute(Qt::WA_Hover); @@ -152,6 +156,31 @@ const KUrl& ColumnWidget::url() const return m_url; } +void ColumnWidget::updateSelection(const KUrl& url) +{ + setSelectionMode(SingleSelection); + QItemSelectionModel* selModel = selectionModel(); + if (url.isEmpty()) { + selModel->clear(); + return; + } + + const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(m_view->model()); + const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel()); + const QModelIndex dirIndex = dirModel->indexForUrl(url); + const QModelIndex proxyIndex = proxyModel->mapFromSource(dirIndex); + + const QItemSelection selection = selModel->selection(); + const bool isIndexSelected = selModel->isSelected(proxyIndex); + + if (!m_active && ((selection.count() > 1) || !isIndexSelected)) { + selModel->clear(); + } + if (!isIndexSelected) { + selModel->select(proxyIndex, QItemSelectionModel::Select); + } +} + QStyleOptionViewItem ColumnWidget::viewOptions() const { return m_viewOptions; @@ -201,7 +230,14 @@ void ColumnWidget::dropEvent(QDropEvent* event) void ColumnWidget::mousePressEvent(QMouseEvent* event) { + if (m_active) { + selectionModel()->clear(); + QListView::mousePressEvent(event); + return; + } + QListView::mousePressEvent(event); + const QModelIndex index = indexAt(event->pos()); bool requestActivation = false; @@ -238,7 +274,9 @@ void ColumnWidget::paintEvent(QPaintEvent* event) void ColumnWidget::contextMenuEvent(QContextMenuEvent* event) { - m_view->requestActivation(this); + if (!m_active) { + m_view->requestActivation(this); + } QListView::contextMenuEvent(event); @@ -258,7 +296,6 @@ void ColumnWidget::activate() palette.setColor(viewport()->backgroundRole(), bgColor); viewport()->setPalette(palette); - setSelectionMode(MultiSelection); update(); } @@ -272,7 +309,6 @@ void ColumnWidget::deactivate() palette.setColor(viewport()->backgroundRole(), bgColor); viewport()->setPalette(palette); - setSelectionMode(SingleSelection); update(); } @@ -287,7 +323,7 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* control setAcceptDrops(true); setDragDropMode(QAbstractItemView::DragDrop); setDropIndicatorShown(false); - setSelectionMode(MultiSelection); + setSelectionMode(SingleSelection); if (KGlobalSettings::singleClick()) { connect(this, SIGNAL(clicked(const QModelIndex&)), @@ -401,6 +437,20 @@ void DolphinColumnView::dropEvent(QDropEvent* event) QColumnView::dropEvent(event); } +void DolphinColumnView::showEvent(QShowEvent* event) +{ + QColumnView::showEvent(event); + if (!event->spontaneous()) { + // QColumnView might clear the selection for folders that are shown in the next column. + // As this is not wanted the selection is updated if the directory lister has been completed. + const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(model()); + const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel()); + KDirLister* dirLister = dirModel->dirLister(); + connect(dirLister, SIGNAL(completed()), + this, SLOT(updateSelections())); + } +} + void DolphinColumnView::zoomIn() { if (isZoomInPossible()) { @@ -445,31 +495,23 @@ void DolphinColumnView::updateColumnsState(const KUrl& url) } } -bool DolphinColumnView::isZoomInPossible() const -{ - ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); - return settings->iconSize() < K3Icon::SizeLarge; -} -bool DolphinColumnView::isZoomOutPossible() const +void DolphinColumnView::updateDecorationSize() { ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); - return settings->iconSize() > K3Icon::SizeSmall; -} + const int iconSize = settings->iconSize(); -void DolphinColumnView::requestActivation(QWidget* column) -{ foreach (QObject* object, viewport()->children()) { if (object->inherits("QListView")) { ColumnWidget* widget = static_cast<ColumnWidget*>(object); - const bool isActive = (widget == column); - widget->setActive(isActive); - if (isActive) { - m_controller->setUrl(widget->url()); - } - } + widget->setDecorationSize(QSize(iconSize, iconSize)); + } } - updateSelections(); + + m_controller->setZoomInPossible(isZoomInPossible()); + m_controller->setZoomOutPossible(isZoomOutPossible()); + + doItemsLayout(); } void DolphinColumnView::updateSelections() @@ -479,46 +521,41 @@ void DolphinColumnView::updateSelections() if (object->inherits("QListView")) { ColumnWidget* widget = static_cast<ColumnWidget*>(object); if (previousWidget != 0) { - const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(model()); - const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel()); - const QModelIndex dirIndex = dirModel->indexForUrl(widget->url()); - const QModelIndex proxyIndex = proxyModel->mapFromSource(dirIndex); - - QItemSelectionModel* selModel = previousWidget->selectionModel(); - const QItemSelection selection = selModel->selection(); - const bool isIndexSelected = selModel->isSelected(proxyIndex); - - const bool clearSelection = !previousWidget->isActive() && - ((selection.count() > 1) || !isIndexSelected); - if (clearSelection) { - selModel->clear(); - } - if (!isIndexSelected) { - selModel->select(proxyIndex, QItemSelectionModel::Select); - } + previousWidget->updateSelection(widget->url()); } - previousWidget = widget; } } + if (previousWidget != 0) { + previousWidget->updateSelection(KUrl()); + } } -void DolphinColumnView::updateDecorationSize() +bool DolphinColumnView::isZoomInPossible() const { ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); - const int iconSize = settings->iconSize(); + return settings->iconSize() < K3Icon::SizeLarge; +} +bool DolphinColumnView::isZoomOutPossible() const +{ + ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); + return settings->iconSize() > K3Icon::SizeSmall; +} + +void DolphinColumnView::requestActivation(QWidget* column) +{ foreach (QObject* object, viewport()->children()) { if (object->inherits("QListView")) { ColumnWidget* widget = static_cast<ColumnWidget*>(object); - widget->setDecorationSize(QSize(iconSize, iconSize)); - } + const bool isActive = (widget == column); + widget->setActive(isActive); + if (isActive) { + m_controller->setUrl(widget->url()); + } + } } - - m_controller->setZoomInPossible(isZoomInPossible()); - m_controller->setZoomOutPossible(isZoomOutPossible()); - - doItemsLayout(); + updateSelections(); } #include "dolphincolumnview.moc" |
