#include <kcolorutils.h>
#include <kcolorscheme.h>
+#include <kdirlister.h>
#include <kdirmodel.h>
#include <QAbstractProxyModel>
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);
m_dragging(false),
m_dropRect()
{
- setAcceptDrops(true);
- setDragDropMode(QAbstractItemView::DragDrop);
- setDropIndicatorShown(false);
-
setMouseTracking(true);
viewport()->setAttribute(Qt::WA_Hover);
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;
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;
void ColumnWidget::contextMenuEvent(QContextMenuEvent* event)
{
- m_view->requestActivation(this);
+ if (!m_active) {
+ m_view->requestActivation(this);
+ }
QListView::contextMenuEvent(event);
palette.setColor(viewport()->backgroundRole(), bgColor);
viewport()->setPalette(palette);
- setSelectionMode(MultiSelection);
update();
}
palette.setColor(viewport()->backgroundRole(), bgColor);
viewport()->setPalette(palette);
- setSelectionMode(SingleSelection);
update();
}
setAcceptDrops(true);
setDragDropMode(QAbstractItemView::DragDrop);
setDropIndicatorShown(false);
- setSelectionMode(MultiSelection);
+ setSelectionMode(SingleSelection);
if (KGlobalSettings::singleClick()) {
connect(this, SIGNAL(clicked(const QModelIndex&)),
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()) {
}
}
-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()
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"
virtual void mousePressEvent(QMouseEvent* event);
virtual void dragEnterEvent(QDragEnterEvent* event);
virtual void dropEvent(QDropEvent* event);
+ virtual void showEvent(QShowEvent* event);
private slots:
void zoomIn();
*/
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
*/
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;