]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincolumnview.cpp
SVN_SILENT made messages (.desktop file)
[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.isNull()) {
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(QPalette::Active, KColorScheme::View).foreground().color();
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(QPalette::Active, KColorScheme::View).background().color();
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(QPalette::Active, KColorScheme::View).background().color();
447 const QColor fgColor = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color();
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 // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
471 // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
472 // necessary connecting the signal 'singleClick()' or 'doubleClick'.
473 if (KGlobalSettings::singleClick()) {
474 connect(this, SIGNAL(clicked(const QModelIndex&)),
475 this, SLOT(triggerItem(const QModelIndex&)));
476 } else {
477 connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
478 this, SLOT(triggerItem(const QModelIndex&)));
479 }
480 connect(this, SIGNAL(entered(const QModelIndex&)),
481 controller, SLOT(emitItemEntered(const QModelIndex&)));
482 connect(this, SIGNAL(viewportEntered()),
483 controller, SLOT(emitViewportEntered()));
484 connect(controller, SIGNAL(zoomIn()),
485 this, SLOT(zoomIn()));
486 connect(controller, SIGNAL(zoomOut()),
487 this, SLOT(zoomOut()));
488 connect(controller, SIGNAL(urlChanged(const KUrl&)),
489 this, SLOT(updateColumnsState(const KUrl&)));
490
491 updateDecorationSize();
492 }
493
494 DolphinColumnView::~DolphinColumnView()
495 {
496 }
497
498 void DolphinColumnView::invertSelection()
499 {
500 selectActiveColumn(QItemSelectionModel::Toggle);
501 }
502
503 void DolphinColumnView::selectAll()
504 {
505 selectActiveColumn(QItemSelectionModel::Select);
506 }
507
508 QAbstractItemView* DolphinColumnView::createColumn(const QModelIndex& index)
509 {
510 // let the column widget be aware about its URL...
511 KUrl columnUrl;
512 if (viewport()->children().count() == 0) {
513 // For the first column widget the directory lister has not been started
514 // yet, hence use the URL from the controller instead.
515 columnUrl = m_controller->url();
516 } else {
517 const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(model());
518 const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
519
520 const QModelIndex dirModelIndex = proxyModel->mapToSource(index);
521 KFileItem fileItem = dirModel->itemForIndex(dirModelIndex);
522 if (!fileItem.isNull()) {
523 columnUrl = fileItem.url();
524 }
525 }
526
527 ColumnWidget* view = new ColumnWidget(viewport(), this, columnUrl);
528
529 // The following code has been copied 1:1 from QColumnView::createColumn().
530 // Copyright (C) 1992-2007 Trolltech ASA. In Qt 4.4 the new method
531 // QColumnView::initializeColumn() will be available for this.
532
533 view->setFrameShape(QFrame::NoFrame);
534 view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
535 view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
536 view->setMinimumWidth(100);
537 view->setAttribute(Qt::WA_MacShowFocusRect, false);
538
539 // copy the 'view' behavior
540 view->setDragDropMode(dragDropMode());
541 view->setDragDropOverwriteMode(dragDropOverwriteMode());
542 view->setDropIndicatorShown(showDropIndicator());
543 view->setAlternatingRowColors(alternatingRowColors());
544 view->setAutoScroll(hasAutoScroll());
545 view->setEditTriggers(editTriggers());
546 view->setHorizontalScrollMode(horizontalScrollMode());
547 view->setIconSize(iconSize());
548 view->setSelectionBehavior(selectionBehavior());
549 view->setSelectionMode(selectionMode());
550 view->setTabKeyNavigation(tabKeyNavigation());
551 view->setTextElideMode(textElideMode());
552 view->setVerticalScrollMode(verticalScrollMode());
553
554 view->setModel(model());
555
556 // set the delegate to be the columnview delegate
557 QAbstractItemDelegate* delegate = view->itemDelegate();
558 view->setItemDelegate(itemDelegate());
559 delete delegate;
560
561 view->setRootIndex(index);
562
563 if (model()->canFetchMore(index)) {
564 model()->fetchMore(index);
565 }
566
567 return view;
568 }
569
570 void DolphinColumnView::mousePressEvent(QMouseEvent* event)
571 {
572 m_controller->triggerActivation();
573 QColumnView::mousePressEvent(event);
574 }
575
576 void DolphinColumnView::dragEnterEvent(QDragEnterEvent* event)
577 {
578 if (event->mimeData()->hasUrls()) {
579 event->acceptProposedAction();
580 }
581 }
582
583 void DolphinColumnView::dropEvent(QDropEvent* event)
584 {
585 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
586 if (!urls.isEmpty()) {
587 m_controller->indicateDroppedUrls(urls,
588 indexAt(event->pos()),
589 event->source());
590 event->acceptProposedAction();
591 }
592 QColumnView::dropEvent(event);
593 }
594
595 void DolphinColumnView::zoomIn()
596 {
597 if (isZoomInPossible()) {
598 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
599 // TODO: get rid of K3Icon sizes
600 switch (settings->iconSize()) {
601 case K3Icon::SizeSmall: settings->setIconSize(K3Icon::SizeMedium); break;
602 case K3Icon::SizeMedium: settings->setIconSize(K3Icon::SizeLarge); break;
603 default: Q_ASSERT(false); break;
604 }
605 updateDecorationSize();
606 }
607 }
608
609 void DolphinColumnView::zoomOut()
610 {
611 if (isZoomOutPossible()) {
612 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
613 // TODO: get rid of K3Icon sizes
614 switch (settings->iconSize()) {
615 case K3Icon::SizeLarge: settings->setIconSize(K3Icon::SizeMedium); break;
616 case K3Icon::SizeMedium: settings->setIconSize(K3Icon::SizeSmall); break;
617 default: Q_ASSERT(false); break;
618 }
619 updateDecorationSize();
620 }
621 }
622
623 void DolphinColumnView::triggerItem(const QModelIndex& index)
624 {
625 m_controller->triggerItem(index);
626 updateColumnsState(m_controller->url());
627 }
628
629 void DolphinColumnView::updateColumnsState(const KUrl& url)
630 {
631 foreach (QObject* object, viewport()->children()) {
632 if (object->inherits("QListView")) {
633 ColumnWidget* widget = static_cast<ColumnWidget*>(object);
634 widget->setActive(widget->url() == url);
635 }
636 }
637 }
638
639
640 void DolphinColumnView::updateDecorationSize()
641 {
642 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
643 const int iconSize = settings->iconSize();
644
645 foreach (QObject* object, viewport()->children()) {
646 if (object->inherits("QListView")) {
647 ColumnWidget* widget = static_cast<ColumnWidget*>(object);
648 widget->setDecorationSize(QSize(iconSize, iconSize));
649 }
650 }
651
652 m_controller->setZoomInPossible(isZoomInPossible());
653 m_controller->setZoomOutPossible(isZoomOutPossible());
654
655 doItemsLayout();
656 }
657
658 bool DolphinColumnView::isZoomInPossible() const
659 {
660 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
661 return settings->iconSize() < K3Icon::SizeLarge;
662 }
663
664 bool DolphinColumnView::isZoomOutPossible() const
665 {
666 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
667 return settings->iconSize() > K3Icon::SizeSmall;
668 }
669
670 void DolphinColumnView::requestActivation(QWidget* column)
671 {
672 foreach (QObject* object, viewport()->children()) {
673 if (object->inherits("QListView")) {
674 ColumnWidget* widget = static_cast<ColumnWidget*>(object);
675 const bool isActive = (widget == column);
676 widget->setActive(isActive);
677 if (isActive) {
678 m_controller->setUrl(widget->url());
679 }
680 }
681 }
682 }
683
684 void DolphinColumnView::requestSelectionModel(QAbstractItemView* view)
685 {
686 foreach (QObject* object, viewport()->children()) {
687 if (object->inherits("QListView")) {
688 ColumnWidget* widget = static_cast<ColumnWidget*>(object);
689 if (widget == view) {
690 widget->obtainSelectionModel();
691 } else {
692 widget->releaseSelectionModel();
693 }
694 }
695 }
696 }
697
698 void DolphinColumnView::selectActiveColumn(QItemSelectionModel::SelectionFlags flags)
699 {
700 // TODO: this approach of selecting the active column is very slow. It should be
701 // possible to speedup the implementation by using QItemSelection, but all adempts
702 // have failed yet...
703
704 // assure that the selection model of the active column is set properly, otherwise
705 // no visual update of the selections is done
706 const KUrl& activeUrl = m_controller->url();
707 foreach (QObject* object, viewport()->children()) {
708 if (object->inherits("QListView")) {
709 ColumnWidget* widget = static_cast<ColumnWidget*>(object);
710 if (widget->url() == activeUrl) {
711 widget->obtainSelectionModel();
712 } else {
713 widget->releaseSelectionModel();
714 }
715 }
716 }
717
718 QItemSelectionModel* selModel = selectionModel();
719
720 const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(model());
721 const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel());
722 KDirLister* dirLister = dirModel->dirLister();
723
724 const KFileItemList list = dirLister->itemsForDir(activeUrl);
725 foreach (KFileItem* item, list) {
726 const QModelIndex index = dirModel->indexForUrl(item->url());
727 selModel->select(proxyModel->mapFromSource(index), flags);
728 }
729 }
730
731 #include "dolphincolumnview.moc"