]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincolumnview.cpp
* added some internal documentation to explain workarounds which seem to be necessary...
[dolphin.git] / src / dolphincolumnview.cpp
1 /***************************************************************************
2 * Copyright (C) 2007 by Peter Penz <peter.penz@gmx.at> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #include "dolphincolumnview.h"
21
22 #include "dolphincontroller.h"
23 #include "dolphinsettings.h"
24
25 #include "dolphin_columnmodesettings.h"
26
27 #include <kcolorutils.h>
28 #include <kcolorscheme.h>
29 #include <kdirlister.h>
30 #include <kdirmodel.h>
31
32 #include <QAbstractProxyModel>
33 #include <QApplication>
34 #include <QPoint>
35
36 /*
37 * General implementation notes
38 * ----------------------------
39 *
40 * In Qt4.3 the QColumnView widget has a default behavior regarding the
41 * active column and the selection handling, which leads to some usability
42 * problems within Dolphin:
43 *
44 * - No matter which mouse button has been clicked: If the mouse is above
45 * a folder, the folder content will be loaded in the next column. The problem
46 * is that this column also will marked as 'active column' within QColumnView,
47 * hence it is not possible to select more than one folder within a column.
48 *
49 * - The currently opened folder is not always marked in the left column when
50 * doing drag & drop and selections inside other columns.
51 *
52 * - The currently active column is visually not recognizable.
53 *
54 * - It is not possible for derived classes to remove inactive columns.
55 *
56 * DolphinView tries to bypass those points, but this required some workarounds:
57 *
58 * - QColumnView internally maps the selection model from the ColumnView to the
59 * active column. As the active column from the Dolphin perspective is different
60 * as the active column from QColumnView, the selection model is adjusted on
61 * each interaction by the methods QColumnWidget::obtainSelectionModel(),
62 * QColumnWidget::releaseSelectionModel() and QColumnView::requestSelectionModel().
63 * QColumnView offers no hook to adjust this behavior, so those methods have to
64 * be invoked throughout the code...
65 *
66 * - Some copy/paste code from QColumnView is part of DolphinColumnView::createColumn(), but Qt 4.4
67 * will offer a solution for this.
68 *
69 * - The mousePressEvent() has been customized to prevent that folders are loaded on each
70 * mouse click.
71 *
72 * We'll try to give some input for Trolltech if the Dolphin solution is stable enough, so hopefully
73 * some workarounds can be removed when switching to Qt 4.4 or later.
74 */
75
76 /**
77 * Represents one column inside the DolphinColumnView and has been
78 * extended to respect view options and hovering information.
79 */
80 class ColumnWidget : public QListView
81 {
82 public:
83 ColumnWidget(QWidget* parent,
84 DolphinColumnView* columnView,
85 const KUrl& url);
86 virtual ~ColumnWidget();
87
88 /** Sets the size of the icons. */
89 void setDecorationSize(const QSize& size);
90
91 /**
92 * An active column is defined as column, which shows the same URL
93 * as indicated by the URL navigator. The active column is usually
94 * drawn in a lighter color. All operations are applied to this column.
95 */
96 void setActive(bool active);
97 inline bool isActive() const;
98
99 inline const KUrl& url() const;
100
101 /**
102 * Obtains the selection model from the column view. This assures that
103 * selections of the column view will always applied to the active column.
104 */
105 void obtainSelectionModel();
106
107 /**
108 * Releases the selection model from the column view and replaces it by
109 * a custom selection model.
110 */
111 void releaseSelectionModel();
112
113 protected:
114 virtual QStyleOptionViewItem viewOptions() const;
115 virtual void dragEnterEvent(QDragEnterEvent* event);
116 virtual void dragLeaveEvent(QDragLeaveEvent* event);
117 virtual void dragMoveEvent(QDragMoveEvent* event);
118 virtual void dropEvent(QDropEvent* event);
119 virtual void mousePressEvent(QMouseEvent* event);
120 virtual void mouseMoveEvent(QMouseEvent* event);
121 virtual void mouseReleaseEvent(QMouseEvent* event);
122 virtual void paintEvent(QPaintEvent* event);
123 virtual void contextMenuEvent(QContextMenuEvent* event);
124
125 protected slots:
126 virtual void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
127
128 private:
129 /** Used by ColumnWidget::setActive(). */
130 void activate();
131
132 /** Used by ColumnWidget::setActive(). */
133 void deactivate();
134
135 private:
136 bool m_active;
137 bool m_swallowMouseMoveEvents;
138 DolphinColumnView* m_view;
139 KUrl m_url;
140 KUrl m_childUrl; // URL of the next column that is shown
141 QStyleOptionViewItem m_viewOptions;
142
143 bool m_dragging; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
144 QRect m_dropRect; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
145 };
146
147 ColumnWidget::ColumnWidget(QWidget* parent,
148 DolphinColumnView* columnView,
149 const KUrl& url) :
150 QListView(parent),
151 m_active(true),
152 m_swallowMouseMoveEvents(false),
153 m_view(columnView),
154 m_url(url),
155 m_childUrl(),
156 m_dragging(false),
157 m_dropRect()
158 {
159 setMouseTracking(true);
160 viewport()->setAttribute(Qt::WA_Hover);
161
162 // apply the column mode settings to the widget
163 const ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
164 Q_ASSERT(settings != 0);
165
166 m_viewOptions = QListView::viewOptions();
167
168 QFont font(settings->fontFamily(), settings->fontSize());
169 font.setItalic(settings->italicFont());
170 font.setBold(settings->boldFont());
171 m_viewOptions.font = font;
172
173 const int iconSize = settings->iconSize();
174 m_viewOptions.decorationSize = QSize(iconSize, iconSize);
175
176 activate();
177 }
178
179 ColumnWidget::~ColumnWidget()
180 {
181 }
182
183 void ColumnWidget::setDecorationSize(const QSize& size)
184 {
185 m_viewOptions.decorationSize = size;
186 doItemsLayout();
187 }
188
189 void ColumnWidget::setActive(bool active)
190 {
191 if (active) {
192 obtainSelectionModel();
193 } else {
194 releaseSelectionModel();
195 }
196
197 if (m_active == active) {
198 return;
199 }
200
201 m_active = active;
202
203 if (active) {
204 activate();
205 } else {
206 deactivate();
207 }
208 }
209
210 inline bool ColumnWidget::isActive() const
211 {
212 return m_active;
213 }
214
215 const KUrl& ColumnWidget::url() const
216 {
217 return m_url;
218 }
219
220 void ColumnWidget::obtainSelectionModel()
221 {
222 if (selectionModel() != m_view->selectionModel()) {
223 selectionModel()->deleteLater();
224 setSelectionModel(m_view->selectionModel());
225 clearSelection();
226 }
227 }
228
229 void ColumnWidget::releaseSelectionModel()
230 {
231 if (selectionModel() == m_view->selectionModel()) {
232 QItemSelectionModel* replacementModel = new QItemSelectionModel(model());
233 setSelectionModel(replacementModel);
234 }
235 }
236
237 QStyleOptionViewItem ColumnWidget::viewOptions() const
238 {
239 return m_viewOptions;
240 }
241
242 void ColumnWidget::dragEnterEvent(QDragEnterEvent* event)
243 {
244 if (event->mimeData()->hasUrls()) {
245 event->acceptProposedAction();
246 }
247
248 m_dragging = true;
249 }
250
251 void ColumnWidget::dragLeaveEvent(QDragLeaveEvent* event)
252 {
253 QListView::dragLeaveEvent(event);
254
255 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
256 m_dragging = false;
257 setDirtyRegion(m_dropRect);
258 }
259
260 void ColumnWidget::dragMoveEvent(QDragMoveEvent* event)
261 {
262 QListView::dragMoveEvent(event);
263
264 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
265 const QModelIndex index = indexAt(event->pos());
266 setDirtyRegion(m_dropRect);
267 m_dropRect = visualRect(index);
268 setDirtyRegion(m_dropRect);
269 }
270
271 void ColumnWidget::dropEvent(QDropEvent* event)
272 {
273 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
274 if (!urls.isEmpty()) {
275 event->acceptProposedAction();
276 m_view->m_controller->indicateDroppedUrls(urls,
277 indexAt(event->pos()),
278 event->source());
279 }
280 QListView::dropEvent(event);
281 m_dragging = false;
282 }
283
284 void ColumnWidget::mousePressEvent(QMouseEvent* event)
285 {
286 // On each mouse press event QColumnView triggers the loading of the
287 // current folder in the next column. This is not wanted for Dolphin when
288 // opening a context menu or when the CTRL modifier is pressed. Beside usability
289 // aspects the loading of the folder also implies losing the current selection,
290 // which makes it impossible to select folders from the current column. To bypass
291 // this behavior QListView::mousePressEvent() is not invoked in those cases, which
292 // is not a nice solution. Maybe another solution can be found in future versions
293 // of QColumnView.
294
295 m_view->requestSelectionModel(this);
296
297 bool swallowMousePressEvent = false;
298 const QModelIndex index = indexAt(event->pos());
299 if (index.isValid()) {
300 // a click on an item has been done
301 const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(m_view->model());
302 const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
303 const QModelIndex dirIndex = proxyModel->mapToSource(index);
304 KFileItem* item = dirModel->itemForIndex(dirIndex);
305 if (item != 0) {
306 QItemSelectionModel* selModel = selectionModel();
307
308 bool activate = true;
309 const Qt::KeyboardModifiers modifier = QApplication::keyboardModifiers();
310 if (modifier & Qt::ControlModifier) {
311 m_view->requestActivation(this);
312 if (!selModel->hasSelection()) {
313 // Assure to set the current index, so that a selection by the SHIFT key
314 // will work. TODO: If the index specifies a folder, the loading of the folder will
315 // be triggered by QColumnView although this is not wanted by Dolphin.
316 selModel->setCurrentIndex(index, QItemSelectionModel::Select);
317 }
318 selModel->select(index, QItemSelectionModel::Toggle);
319 swallowMousePressEvent = true;
320 } else if (item->isDir()) {
321 m_childUrl = item->url();
322 viewport()->update();
323
324 // Only request the activation if not the left button is pressed.
325 // The left button on a directory opens a new column, hence requesting
326 // an activation is useless as the new column will request the activation
327 // afterwards.
328 if (event->button() == Qt::LeftButton) {
329 activate = false;
330 }
331 }
332
333 if (activate) {
334 m_view->requestActivation(this);
335 }
336
337 // TODO: is the assumption OK that Qt::RightButton always represents the context menu button?
338 if (event->button() == Qt::RightButton) {
339 swallowMousePressEvent = true;
340 if (!selModel->isSelected(index)) {
341 clearSelection();
342 }
343 selModel->select(index, QItemSelectionModel::Select);
344 }
345 }
346 } else {
347 // a click on the viewport has been done
348 m_view->requestActivation(this);
349
350 // Swallow mouse move events if a click is done on the viewport. Otherwise the QColumnView
351 // triggers an unwanted loading of directories on hovering folder items.
352 m_swallowMouseMoveEvents = true;
353 clearSelection();
354 }
355
356 if (!swallowMousePressEvent) {
357 QListView::mousePressEvent(event);
358 }
359 }
360
361 void ColumnWidget::mouseMoveEvent(QMouseEvent* event)
362 {
363 // see description in ColumnView::mousePressEvent()
364 if (!m_swallowMouseMoveEvents) {
365 QListView::mouseMoveEvent(event);
366 }
367 }
368
369 void ColumnWidget::mouseReleaseEvent(QMouseEvent* event)
370 {
371 QListView::mouseReleaseEvent(event);
372 m_swallowMouseMoveEvents = false;
373 }
374
375
376 void ColumnWidget::paintEvent(QPaintEvent* event)
377 {
378 if (!m_childUrl.isEmpty()) {
379 // indicate the shown URL of the next column by highlighting the shown folder item
380 const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(m_view->model());
381 const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
382 const QModelIndex dirIndex = dirModel->indexForUrl(m_childUrl);
383 const QModelIndex proxyIndex = proxyModel->mapFromSource(dirIndex);
384 if (proxyIndex.isValid() && !selectionModel()->isSelected(proxyIndex)) {
385 const QRect itemRect = visualRect(proxyIndex);
386 QPainter painter(viewport());
387 painter.save();
388
389 QColor color = KColorScheme(KColorScheme::View).foreground();
390 color.setAlpha(32);
391 painter.setPen(Qt::NoPen);
392 painter.setBrush(color);
393 painter.drawRect(itemRect);
394
395 painter.restore();
396 }
397 }
398
399 QListView::paintEvent(event);
400
401 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
402 if (m_dragging) {
403 const QBrush& brush = m_viewOptions.palette.brush(QPalette::Normal, QPalette::Highlight);
404 DolphinController::drawHoverIndication(viewport(), m_dropRect, brush);
405 }
406 }
407
408 void ColumnWidget::contextMenuEvent(QContextMenuEvent* event)
409 {
410 if (!m_active) {
411 m_view->requestActivation(this);
412 }
413
414 QListView::contextMenuEvent(event);
415
416 const QModelIndex index = indexAt(event->pos());
417 if (index.isValid() || m_active) {
418 // Only open a context menu above an item or if the mouse is above
419 // the active column.
420 const QPoint pos = m_view->viewport()->mapFromGlobal(event->globalPos());
421 m_view->m_controller->triggerContextMenuRequest(pos);
422 }
423 }
424
425 void ColumnWidget::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
426 {
427 // inactive views should not have any selection
428 if (!m_active) {
429 clearSelection();
430 }
431 QListView::selectionChanged(selected, deselected);
432 }
433
434 void ColumnWidget::activate()
435 {
436 const QColor bgColor = KColorScheme(KColorScheme::View).background();
437 QPalette palette = viewport()->palette();
438 palette.setColor(viewport()->backgroundRole(), bgColor);
439 viewport()->setPalette(palette);
440
441 update();
442 }
443
444 void ColumnWidget::deactivate()
445 {
446 QColor bgColor = KColorScheme(KColorScheme::View).background();
447 const QColor fgColor = KColorScheme(KColorScheme::View).foreground();
448 bgColor = KColorUtils::mix(bgColor, fgColor, 0.04);
449
450 QPalette palette = viewport()->palette();
451 palette.setColor(viewport()->backgroundRole(), bgColor);
452 viewport()->setPalette(palette);
453
454 update();
455 }
456
457 // ---
458
459 DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* controller) :
460 QColumnView(parent),
461 m_controller(controller)
462 {
463 Q_ASSERT(controller != 0);
464
465 setAcceptDrops(true);
466 setDragDropMode(QAbstractItemView::DragDrop);
467 setDropIndicatorShown(false);
468 setSelectionMode(ExtendedSelection);
469
470 if (KGlobalSettings::singleClick()) {
471 connect(this, SIGNAL(clicked(const QModelIndex&)),
472 this, SLOT(triggerItem(const QModelIndex&)));
473 } else {
474 connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
475 this, SLOT(triggerItem(const QModelIndex&)));
476 }
477 connect(this, SIGNAL(entered(const QModelIndex&)),
478 controller, SLOT(emitItemEntered(const QModelIndex&)));
479 connect(this, SIGNAL(viewportEntered()),
480 controller, SLOT(emitViewportEntered()));
481 connect(controller, SIGNAL(zoomIn()),
482 this, SLOT(zoomIn()));
483 connect(controller, SIGNAL(zoomOut()),
484 this, SLOT(zoomOut()));
485 connect(controller, SIGNAL(urlChanged(const KUrl&)),
486 this, SLOT(updateColumnsState(const KUrl&)));
487
488 updateDecorationSize();
489 }
490
491 DolphinColumnView::~DolphinColumnView()
492 {
493 }
494
495 void DolphinColumnView::invertSelection()
496 {
497 selectActiveColumn(QItemSelectionModel::Toggle);
498 }
499
500 void DolphinColumnView::selectAll()
501 {
502 selectActiveColumn(QItemSelectionModel::Select);
503 }
504
505 QAbstractItemView* DolphinColumnView::createColumn(const QModelIndex& index)
506 {
507 // let the column widget be aware about its URL...
508 KUrl columnUrl;
509 if (viewport()->children().count() == 0) {
510 // For the first column widget the directory lister has not been started
511 // yet, hence use the URL from the controller instead.
512 columnUrl = m_controller->url();
513 } else {
514 const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(model());
515 const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
516
517 const QModelIndex dirModelIndex = proxyModel->mapToSource(index);
518 KFileItem* fileItem = dirModel->itemForIndex(dirModelIndex);
519 if (fileItem != 0) {
520 columnUrl = fileItem->url();
521 }
522 }
523
524 ColumnWidget* view = new ColumnWidget(viewport(), this, columnUrl);
525
526 // The following code has been copied 1:1 from QColumnView::createColumn().
527 // Copyright (C) 1992-2007 Trolltech ASA. In Qt 4.4 the new method
528 // QColumnView::initializeColumn() will be available for this.
529
530 view->setFrameShape(QFrame::NoFrame);
531 view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
532 view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
533 view->setMinimumWidth(100);
534 view->setAttribute(Qt::WA_MacShowFocusRect, false);
535
536 // copy the 'view' behavior
537 view->setDragDropMode(dragDropMode());
538 view->setDragDropOverwriteMode(dragDropOverwriteMode());
539 view->setDropIndicatorShown(showDropIndicator());
540 view->setAlternatingRowColors(alternatingRowColors());
541 view->setAutoScroll(hasAutoScroll());
542 view->setEditTriggers(editTriggers());
543 view->setHorizontalScrollMode(horizontalScrollMode());
544 view->setIconSize(iconSize());
545 view->setSelectionBehavior(selectionBehavior());
546 view->setSelectionMode(selectionMode());
547 view->setTabKeyNavigation(tabKeyNavigation());
548 view->setTextElideMode(textElideMode());
549 view->setVerticalScrollMode(verticalScrollMode());
550
551 view->setModel(model());
552
553 // set the delegate to be the columnview delegate
554 QAbstractItemDelegate* delegate = view->itemDelegate();
555 view->setItemDelegate(itemDelegate());
556 delete delegate;
557
558 view->setRootIndex(index);
559
560 if (model()->canFetchMore(index)) {
561 model()->fetchMore(index);
562 }
563
564 return view;
565 }
566
567 void DolphinColumnView::mousePressEvent(QMouseEvent* event)
568 {
569 m_controller->triggerActivation();
570 QColumnView::mousePressEvent(event);
571 }
572
573 void DolphinColumnView::dragEnterEvent(QDragEnterEvent* event)
574 {
575 if (event->mimeData()->hasUrls()) {
576 event->acceptProposedAction();
577 }
578 }
579
580 void DolphinColumnView::dropEvent(QDropEvent* event)
581 {
582 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
583 if (!urls.isEmpty()) {
584 m_controller->indicateDroppedUrls(urls,
585 indexAt(event->pos()),
586 event->source());
587 event->acceptProposedAction();
588 }
589 QColumnView::dropEvent(event);
590 }
591
592 void DolphinColumnView::zoomIn()
593 {
594 if (isZoomInPossible()) {
595 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
596 // TODO: get rid of K3Icon sizes
597 switch (settings->iconSize()) {
598 case K3Icon::SizeSmall: settings->setIconSize(K3Icon::SizeMedium); break;
599 case K3Icon::SizeMedium: settings->setIconSize(K3Icon::SizeLarge); break;
600 default: Q_ASSERT(false); break;
601 }
602 updateDecorationSize();
603 }
604 }
605
606 void DolphinColumnView::zoomOut()
607 {
608 if (isZoomOutPossible()) {
609 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
610 // TODO: get rid of K3Icon sizes
611 switch (settings->iconSize()) {
612 case K3Icon::SizeLarge: settings->setIconSize(K3Icon::SizeMedium); break;
613 case K3Icon::SizeMedium: settings->setIconSize(K3Icon::SizeSmall); break;
614 default: Q_ASSERT(false); break;
615 }
616 updateDecorationSize();
617 }
618 }
619
620 void DolphinColumnView::triggerItem(const QModelIndex& index)
621 {
622 m_controller->triggerItem(index);
623 updateColumnsState(m_controller->url());
624 }
625
626 void DolphinColumnView::updateColumnsState(const KUrl& url)
627 {
628 foreach (QObject* object, viewport()->children()) {
629 if (object->inherits("QListView")) {
630 ColumnWidget* widget = static_cast<ColumnWidget*>(object);
631 widget->setActive(widget->url() == url);
632 }
633 }
634 }
635
636
637 void DolphinColumnView::updateDecorationSize()
638 {
639 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
640 const int iconSize = settings->iconSize();
641
642 foreach (QObject* object, viewport()->children()) {
643 if (object->inherits("QListView")) {
644 ColumnWidget* widget = static_cast<ColumnWidget*>(object);
645 widget->setDecorationSize(QSize(iconSize, iconSize));
646 }
647 }
648
649 m_controller->setZoomInPossible(isZoomInPossible());
650 m_controller->setZoomOutPossible(isZoomOutPossible());
651
652 doItemsLayout();
653 }
654
655 bool DolphinColumnView::isZoomInPossible() const
656 {
657 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
658 return settings->iconSize() < K3Icon::SizeLarge;
659 }
660
661 bool DolphinColumnView::isZoomOutPossible() const
662 {
663 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
664 return settings->iconSize() > K3Icon::SizeSmall;
665 }
666
667 void DolphinColumnView::requestActivation(QWidget* column)
668 {
669 foreach (QObject* object, viewport()->children()) {
670 if (object->inherits("QListView")) {
671 ColumnWidget* widget = static_cast<ColumnWidget*>(object);
672 const bool isActive = (widget == column);
673 widget->setActive(isActive);
674 if (isActive) {
675 m_controller->setUrl(widget->url());
676 }
677 }
678 }
679 }
680
681 void DolphinColumnView::requestSelectionModel(QAbstractItemView* view)
682 {
683 foreach (QObject* object, viewport()->children()) {
684 if (object->inherits("QListView")) {
685 ColumnWidget* widget = static_cast<ColumnWidget*>(object);
686 if (widget == view) {
687 widget->obtainSelectionModel();
688 } else {
689 widget->releaseSelectionModel();
690 }
691 }
692 }
693 }
694
695 void DolphinColumnView::selectActiveColumn(QItemSelectionModel::SelectionFlags flags)
696 {
697 // TODO: this approach of selecting the active column is very slow. It should be
698 // possible to speedup the implementation by using QItemSelection, but all adempts
699 // have failed yet...
700
701 // assure that the selection model of the active column is set properly, otherwise
702 // no visual update of the selections is done
703 const KUrl& activeUrl = m_controller->url();
704 foreach (QObject* object, viewport()->children()) {
705 if (object->inherits("QListView")) {
706 ColumnWidget* widget = static_cast<ColumnWidget*>(object);
707 if (widget->url() == activeUrl) {
708 widget->obtainSelectionModel();
709 } else {
710 widget->releaseSelectionModel();
711 }
712 }
713 }
714
715 QItemSelectionModel* selModel = selectionModel();
716
717 const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(model());
718 const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
719 KDirLister* dirLister = dirModel->dirLister();
720
721 const KFileItemList list = dirLister->itemsForDir(activeUrl);
722 foreach (KFileItem* item, list) {
723 const QModelIndex index = dirModel->indexForUrl(item->url());
724 selModel->select(proxyModel->mapFromSource(index), flags);
725 }
726 }
727
728 #include "dolphincolumnview.moc"