┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2007-07-28 22:27:58 +0000
committerPeter Penz <[email protected]>2007-07-28 22:27:58 +0000
commitdcac8012b6a2e63bf7526d8c27d2442906afed32 (patch)
treefff107e6dd8737f4ac6f72e214fde238746df4d3 /src
parent2e5379158e74250d37b7a536881ef2b8dbef4b3b (diff)
temporary fixes until MultiSelection will be implemented
svn path=/trunk/KDE/kdebase/apps/; revision=693752
Diffstat (limited to 'src')
-rw-r--r--src/dolphincolumnview.cpp141
-rw-r--r--src/dolphincolumnview.h25
2 files changed, 102 insertions, 64 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"
diff --git a/src/dolphincolumnview.h b/src/dolphincolumnview.h
index 274b71195..59bb805fe 100644
--- a/src/dolphincolumnview.h
+++ b/src/dolphincolumnview.h
@@ -46,6 +46,7 @@ protected:
virtual void mousePressEvent(QMouseEvent* event);
virtual void dragEnterEvent(QDragEnterEvent* event);
virtual void dropEvent(QDropEvent* event);
+ virtual void showEvent(QShowEvent* event);
private slots:
void zoomIn();
@@ -59,15 +60,13 @@ private slots:
*/
void updateColumnsState(const KUrl& url);
-private:
- bool isZoomInPossible() const;
- bool isZoomOutPossible() const;
-
/**
- * Requests the activation for the column \a column. The URL
- * navigator will be changed to represent the column.
+ * Updates the size of the decoration dependent on the
+ * icon size of the ColumnModeSettings. The controller
+ * will get informed about possible zoom in/zoom out
+ * operations.
*/
- void requestActivation(QWidget* column);
+ void updateDecorationSize();
/**
* Updates the selections of all columns to assure that
@@ -76,13 +75,15 @@ private:
*/
void updateSelections();
+private:
+ bool isZoomInPossible() const;
+ bool isZoomOutPossible() const;
+
/**
- * Updates the size of the decoration dependent on the
- * icon size of the ColumnModeSettings. The controller
- * will get informed about possible zoom in/zoom out
- * operations.
+ * Requests the activation for the column \a column. The URL
+ * navigator will be changed to represent the column.
*/
- void updateDecorationSize();
+ void requestActivation(QWidget* column);
private:
DolphinController* m_controller;