]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphincolumnview.cpp
Dolphin is now QT3_SUPPORT free
[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 "dolphinmodel.h"
23 #include "dolphincontroller.h"
24 #include "dolphinsettings.h"
25
26 #include "dolphin_columnmodesettings.h"
27
28 #include <kcolorutils.h>
29 #include <kcolorscheme.h>
30 #include <kdirlister.h>
31
32 #include <QAbstractProxyModel>
33 #include <QApplication>
34 #include <QPoint>
35 #include <QScrollBar>
36 #include <QTimeLine>
37
38 /**
39 * Represents one column inside the DolphinColumnView and has been
40 * extended to respect view options and hovering information.
41 */
42 class ColumnWidget : public QListView
43 {
44 public:
45 ColumnWidget(QWidget* parent,
46 DolphinColumnView* columnView,
47 const KUrl& url);
48 virtual ~ColumnWidget();
49
50 /** Sets the size of the icons. */
51 void setDecorationSize(const QSize& size);
52
53 /**
54 * An active column is defined as column, which shows the same URL
55 * as indicated by the URL navigator. The active column is usually
56 * drawn in a lighter color. All operations are applied to this column.
57 */
58 void setActive(bool active);
59 inline bool isActive() const;
60
61 /**
62 * Sets the directory URL of the child column that is shown next to
63 * this column. This property is only used for a visual indication
64 * of the shown directory, it does not trigger a loading of the model.
65 */
66 inline void setChildUrl(const KUrl& url);
67 inline const KUrl& childUrl() const;
68
69 /**
70 * Returns the directory URL that is shown inside the column widget.
71 */
72 inline const KUrl& url() const;
73
74 protected:
75 virtual QStyleOptionViewItem viewOptions() const;
76 virtual void dragEnterEvent(QDragEnterEvent* event);
77 virtual void dragLeaveEvent(QDragLeaveEvent* event);
78 virtual void dragMoveEvent(QDragMoveEvent* event);
79 virtual void dropEvent(QDropEvent* event);
80 virtual void paintEvent(QPaintEvent* event);
81 virtual void mousePressEvent(QMouseEvent* event);
82 virtual void keyPressEvent(QKeyEvent* event);
83 virtual void contextMenuEvent(QContextMenuEvent* event);
84 virtual void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
85
86 private:
87 /** Used by ColumnWidget::setActive(). */
88 void activate();
89
90 /** Used by ColumnWidget::setActive(). */
91 void deactivate();
92
93 private:
94 bool m_active;
95 DolphinColumnView* m_view;
96 KUrl m_url; // URL of the directory that is shown
97 KUrl m_childUrl; // URL of the next column that is shown
98 QStyleOptionViewItem m_viewOptions;
99
100 bool m_dragging; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
101 QRect m_dropRect; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
102 };
103
104 ColumnWidget::ColumnWidget(QWidget* parent,
105 DolphinColumnView* columnView,
106 const KUrl& url) :
107 QListView(parent),
108 m_active(true),
109 m_view(columnView),
110 m_url(url),
111 m_childUrl(),
112 m_dragging(false),
113 m_dropRect()
114 {
115 setMouseTracking(true);
116 viewport()->setAttribute(Qt::WA_Hover);
117 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
118 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
119 setSelectionBehavior(SelectItems);
120 setSelectionMode(QAbstractItemView::ExtendedSelection);
121 setDragDropMode(QAbstractItemView::DragDrop);
122 setDropIndicatorShown(false);
123 setFocusPolicy(Qt::NoFocus);
124
125 // apply the column mode settings to the widget
126 const ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
127 Q_ASSERT(settings != 0);
128
129 m_viewOptions = QListView::viewOptions();
130
131 QFont font(settings->fontFamily(), settings->fontSize());
132 font.setItalic(settings->italicFont());
133 font.setBold(settings->boldFont());
134 m_viewOptions.font = font;
135
136 const int iconSize = settings->iconSize();
137 m_viewOptions.decorationSize = QSize(iconSize, iconSize);
138
139 KFileItemDelegate* delegate = new KFileItemDelegate(this);
140 setItemDelegate(delegate);
141
142 activate();
143
144 connect(this, SIGNAL(entered(const QModelIndex&)),
145 m_view->m_controller, SLOT(emitItemEntered(const QModelIndex&)));
146 connect(this, SIGNAL(viewportEntered()),
147 m_view->m_controller, SLOT(emitViewportEntered()));
148 }
149
150 ColumnWidget::~ColumnWidget()
151 {
152 }
153
154 void ColumnWidget::setDecorationSize(const QSize& size)
155 {
156 m_viewOptions.decorationSize = size;
157 doItemsLayout();
158 }
159
160 void ColumnWidget::setActive(bool active)
161 {
162 if (m_active == active) {
163 return;
164 }
165
166 m_active = active;
167
168 if (active) {
169 activate();
170 } else {
171 deactivate();
172 }
173 }
174
175 inline bool ColumnWidget::isActive() const
176 {
177 return m_active;
178 }
179
180 inline void ColumnWidget::setChildUrl(const KUrl& url)
181 {
182 m_childUrl = url;
183 }
184
185 inline const KUrl& ColumnWidget::childUrl() const
186 {
187 return m_childUrl;
188 }
189
190 const KUrl& ColumnWidget::url() const
191 {
192 return m_url;
193 }
194
195 QStyleOptionViewItem ColumnWidget::viewOptions() const
196 {
197 return m_viewOptions;
198 }
199
200 void ColumnWidget::dragEnterEvent(QDragEnterEvent* event)
201 {
202 if (event->mimeData()->hasUrls()) {
203 event->acceptProposedAction();
204 }
205
206 m_dragging = true;
207 }
208
209 void ColumnWidget::dragLeaveEvent(QDragLeaveEvent* event)
210 {
211 QListView::dragLeaveEvent(event);
212
213 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
214 m_dragging = false;
215 setDirtyRegion(m_dropRect);
216 }
217
218 void ColumnWidget::dragMoveEvent(QDragMoveEvent* event)
219 {
220 QListView::dragMoveEvent(event);
221
222 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
223 const QModelIndex index = indexAt(event->pos());
224 setDirtyRegion(m_dropRect);
225 m_dropRect = visualRect(index);
226 setDirtyRegion(m_dropRect);
227 }
228
229 void ColumnWidget::dropEvent(QDropEvent* event)
230 {
231 const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
232 if (!urls.isEmpty()) {
233 event->acceptProposedAction();
234 m_view->m_controller->indicateDroppedUrls(urls,
235 url(),
236 indexAt(event->pos()),
237 event->source());
238 }
239 QListView::dropEvent(event);
240 m_dragging = false;
241 }
242
243 void ColumnWidget::paintEvent(QPaintEvent* event)
244 {
245 if (!m_childUrl.isEmpty()) {
246 // indicate the shown URL of the next column by highlighting the shown folder item
247 const QModelIndex dirIndex = m_view->m_dolphinModel->indexForUrl(m_childUrl);
248 const QModelIndex proxyIndex = m_view->m_proxyModel->mapFromSource(dirIndex);
249 if (proxyIndex.isValid() && !selectionModel()->isSelected(proxyIndex)) {
250 const QRect itemRect = visualRect(proxyIndex);
251 QPainter painter(viewport());
252 painter.save();
253
254 QColor color = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color();
255 color.setAlpha(32);
256 painter.setPen(Qt::NoPen);
257 painter.setBrush(color);
258 painter.drawRect(itemRect);
259
260 painter.restore();
261 }
262 }
263
264 QListView::paintEvent(event);
265
266 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
267 if (m_dragging) {
268 const QBrush& brush = m_viewOptions.palette.brush(QPalette::Normal, QPalette::Highlight);
269 DolphinController::drawHoverIndication(viewport(), m_dropRect, brush);
270 }
271 }
272
273 void ColumnWidget::mousePressEvent(QMouseEvent* event)
274 {
275 if (!m_active) {
276 m_view->requestActivation(this);
277 }
278
279 QListView::mousePressEvent(event);
280 }
281
282 void ColumnWidget::keyPressEvent(QKeyEvent* event)
283 {
284 QListView::keyPressEvent(event);
285
286 const QItemSelectionModel* selModel = selectionModel();
287 const QModelIndex currentIndex = selModel->currentIndex();
288 const bool triggerItem = currentIndex.isValid()
289 && (event->key() == Qt::Key_Return)
290 && (selModel->selectedIndexes().count() <= 1);
291 if (triggerItem) {
292 m_view->triggerItem(currentIndex);
293 }
294 }
295
296 void ColumnWidget::contextMenuEvent(QContextMenuEvent* event)
297 {
298 if (!m_active) {
299 m_view->requestActivation(this);
300 }
301
302 QListView::contextMenuEvent(event);
303
304 const QModelIndex index = indexAt(event->pos());
305 if (index.isValid() || m_active) {
306 // Only open a context menu above an item or if the mouse is above
307 // the active column.
308 const QPoint pos = m_view->viewport()->mapFromGlobal(event->globalPos());
309 m_view->m_controller->triggerContextMenuRequest(pos);
310 }
311 }
312
313 void ColumnWidget::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
314 {
315 QListView::selectionChanged(selected, deselected);
316
317 QItemSelectionModel* selModel = m_view->selectionModel();
318 selModel->select(selected, QItemSelectionModel::Select);
319 selModel->select(deselected, QItemSelectionModel::Deselect);
320 }
321
322 void ColumnWidget::activate()
323 {
324 if (m_view->hasFocus()) {
325 setFocus(Qt::OtherFocusReason);
326 }
327 m_view->setFocusProxy(this);
328
329 // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
330 // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
331 // necessary connecting the signal 'singleClick()' or 'doubleClick'.
332 if (KGlobalSettings::singleClick()) {
333 connect(this, SIGNAL(clicked(const QModelIndex&)),
334 m_view, SLOT(triggerItem(const QModelIndex&)));
335 } else {
336 connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
337 m_view, SLOT(triggerItem(const QModelIndex&)));
338 }
339
340 const QColor bgColor = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
341 QPalette palette = viewport()->palette();
342 palette.setColor(viewport()->backgroundRole(), bgColor);
343 viewport()->setPalette(palette);
344
345 if (!m_childUrl.isEmpty()) {
346 // assure that the current index is set on the index that represents
347 // the child URL
348 const QModelIndex dirIndex = m_view->m_dolphinModel->indexForUrl(m_childUrl);
349 const QModelIndex proxyIndex = m_view->m_proxyModel->mapFromSource(dirIndex);
350 selectionModel()->setCurrentIndex(proxyIndex, QItemSelectionModel::Current);
351 }
352
353 update();
354 }
355
356 void ColumnWidget::deactivate()
357 {
358 // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
359 // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
360 // necessary connecting the signal 'singleClick()' or 'doubleClick'.
361 if (KGlobalSettings::singleClick()) {
362 disconnect(this, SIGNAL(clicked(const QModelIndex&)),
363 m_view, SLOT(triggerItem(const QModelIndex&)));
364 } else {
365 disconnect(this, SIGNAL(doubleClicked(const QModelIndex&)),
366 m_view, SLOT(triggerItem(const QModelIndex&)));
367 }
368
369 QColor bgColor = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
370 const QColor fgColor = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color();
371 bgColor = KColorUtils::mix(bgColor, fgColor, 0.04);
372
373 QPalette palette = viewport()->palette();
374 palette.setColor(viewport()->backgroundRole(), bgColor);
375 viewport()->setPalette(palette);
376
377 selectionModel()->clear();
378
379 update();
380 }
381
382 // ---
383
384 DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* controller) :
385 QAbstractItemView(parent),
386 m_controller(controller),
387 m_index(-1),
388 m_contentX(0),
389 m_columns(),
390 m_animation(0),
391 m_dolphinModel(0),
392 m_proxyModel(0)
393 {
394 Q_ASSERT(controller != 0);
395
396 setAcceptDrops(true);
397 setDragDropMode(QAbstractItemView::DragDrop);
398 setDropIndicatorShown(false);
399 setSelectionMode(ExtendedSelection);
400
401 connect(this, SIGNAL(entered(const QModelIndex&)),
402 controller, SLOT(emitItemEntered(const QModelIndex&)));
403 connect(this, SIGNAL(viewportEntered()),
404 controller, SLOT(emitViewportEntered()));
405 connect(controller, SIGNAL(zoomIn()),
406 this, SLOT(zoomIn()));
407 connect(controller, SIGNAL(zoomOut()),
408 this, SLOT(zoomOut()));
409 connect(controller, SIGNAL(urlChanged(const KUrl&)),
410 this, SLOT(showColumn(const KUrl&)));
411
412 connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
413 this, SLOT(moveContentHorizontally(int)));
414
415 ColumnWidget* column = new ColumnWidget(viewport(), this, m_controller->url());
416 m_columns.append(column);
417 setActiveColumnIndex(0);
418
419 updateDecorationSize();
420
421 m_animation = new QTimeLine(500, this);
422 connect(m_animation, SIGNAL(frameChanged(int)), horizontalScrollBar(), SLOT(setValue(int)));
423 }
424
425 DolphinColumnView::~DolphinColumnView()
426 {
427 }
428
429 QModelIndex DolphinColumnView::indexAt(const QPoint& point) const
430 {
431 foreach (ColumnWidget* column, m_columns) {
432 const QPoint topLeft = column->frameGeometry().topLeft();
433 const QPoint adjustedPoint(point.x() - topLeft.x(), point.y() - topLeft.y());
434 const QModelIndex index = column->indexAt(adjustedPoint);
435 if (index.isValid()) {
436 return index;
437 }
438 }
439
440 return QModelIndex();
441 }
442
443 void DolphinColumnView::scrollTo(const QModelIndex& index, ScrollHint hint)
444 {
445 activeColumn()->scrollTo(index, hint);
446 }
447
448 QRect DolphinColumnView::visualRect(const QModelIndex& index) const
449 {
450 return activeColumn()->visualRect(index);
451 }
452
453 void DolphinColumnView::setModel(QAbstractItemModel* model)
454 {
455 m_proxyModel = static_cast<const QAbstractProxyModel*>(model);
456 m_dolphinModel = static_cast<const DolphinModel*>(m_proxyModel->sourceModel());
457
458 activeColumn()->setModel(model);
459 QAbstractItemView::setModel(model);
460 }
461
462 bool DolphinColumnView::isIndexHidden(const QModelIndex& index) const
463 {
464 Q_UNUSED(index);
465 return false;//activeColumn()->isIndexHidden(index);
466 }
467
468 QModelIndex DolphinColumnView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
469 {
470 // Parts of this code have been taken from QColumnView::moveCursor().
471 // Copyright (C) 1992-2007 Trolltech ASA.
472
473 Q_UNUSED(modifiers);
474 if (model() == 0) {
475 return QModelIndex();
476 }
477
478 const QModelIndex current = currentIndex();
479 if (isRightToLeft()) {
480 if (cursorAction == MoveLeft) {
481 cursorAction = MoveRight;
482 } else if (cursorAction == MoveRight) {
483 cursorAction = MoveLeft;
484 }
485 }
486
487 switch (cursorAction) {
488 case MoveLeft:
489 if (m_index > 0) {
490 setActiveColumnIndex(m_index - 1);
491 }
492 break;
493
494 case MoveRight:
495 if (m_index < m_columns.count() - 1) {
496 setActiveColumnIndex(m_index + 1);
497 }
498 break;
499
500 default:
501 break;
502 }
503
504 return QModelIndex();
505 }
506
507 void DolphinColumnView::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags flags)
508 {
509 Q_UNUSED(rect);
510 Q_UNUSED(flags);
511 //activeColumn()->setSelection(rect, flags);
512 }
513
514 QRegion DolphinColumnView::visualRegionForSelection(const QItemSelection& selection) const
515 {
516 return QRegion(); //activeColumn()->visualRegionForSelection(selection);
517 }
518
519 int DolphinColumnView::horizontalOffset() const
520 {
521 return -m_contentX;
522 }
523
524 int DolphinColumnView::verticalOffset() const
525 {
526 return 0;
527 }
528
529 void DolphinColumnView::mousePressEvent(QMouseEvent* event)
530 {
531 m_controller->triggerActivation();
532 QAbstractItemView::mousePressEvent(event);
533 }
534
535 void DolphinColumnView::resizeEvent(QResizeEvent* event)
536 {
537 QAbstractItemView::resizeEvent(event);
538 layoutColumns();
539 updateScrollBar();
540 }
541
542 void DolphinColumnView::zoomIn()
543 {
544 if (isZoomInPossible()) {
545 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
546 // TODO: get rid of K3Icon sizes
547 switch (settings->iconSize()) {
548 case K3Icon::SizeSmall: settings->setIconSize(K3Icon::SizeMedium); break;
549 case K3Icon::SizeMedium: settings->setIconSize(K3Icon::SizeLarge); break;
550 default: Q_ASSERT(false); break;
551 }
552 updateDecorationSize();
553 }
554 }
555
556 void DolphinColumnView::zoomOut()
557 {
558 if (isZoomOutPossible()) {
559 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
560 // TODO: get rid of K3Icon sizes
561 switch (settings->iconSize()) {
562 case K3Icon::SizeLarge: settings->setIconSize(K3Icon::SizeMedium); break;
563 case K3Icon::SizeMedium: settings->setIconSize(K3Icon::SizeSmall); break;
564 default: Q_ASSERT(false); break;
565 }
566 updateDecorationSize();
567 }
568 }
569
570 void DolphinColumnView::triggerItem(const QModelIndex& index)
571 {
572 m_controller->triggerItem(index);
573
574 const Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers();
575 if ((modifiers & Qt::ControlModifier) || (modifiers & Qt::ShiftModifier)) {
576 return;
577 }
578
579 const KFileItem item = m_dolphinModel->itemForIndex(m_proxyModel->mapToSource(index));
580 if ((item.url() != activeColumn()->url()) && item.isDir()) {
581 deleteInactiveChildColumns();
582
583 const KUrl& childUrl = m_controller->url();
584 activeColumn()->setChildUrl(childUrl);
585
586 ColumnWidget* column = new ColumnWidget(viewport(), this, childUrl);
587 column->setModel(model());
588 column->setRootIndex(index);
589
590 m_columns.append(column);
591
592 setActiveColumnIndex(m_index + 1);
593
594 // Before invoking layoutColumns() the column must be shown. To prevent
595 // a flickering the initial geometry is set to be invisible.
596 column->setGeometry(QRect(-1, -1, 1, 1));
597 column->show();
598
599 layoutColumns();
600 updateScrollBar();
601 assureVisibleActiveColumn();
602 }
603 }
604
605 void DolphinColumnView::moveContentHorizontally(int x)
606 {
607 m_contentX = -x;
608 layoutColumns();
609 }
610
611 void DolphinColumnView::showColumn(const KUrl& url)
612 {
613 if (!m_columns[0]->url().isParentOf(url)) {
614 // the URL is no child URL of the column view, hence do nothing
615 return;
616 }
617
618 int columnIndex = 0;
619 foreach (ColumnWidget* column, m_columns) {
620 if (column->url() == url) {
621 // the column represents already the requested URL, hence activate it
622 requestActivation(column);
623 return;
624 } else if (!column->url().isParentOf(url)) {
625 // the column is no parent of the requested URL, hence it must
626 // be deleted and a new column must be loaded
627 if (columnIndex > 0) {
628 setActiveColumnIndex(columnIndex - 1);
629 deleteInactiveChildColumns();
630 }
631
632 const QModelIndex dirIndex = m_dolphinModel->indexForUrl(url);
633 if (dirIndex.isValid()) {
634 triggerItem(m_proxyModel->mapFromSource(dirIndex));
635 }
636 return;
637 }
638 ++columnIndex;
639 }
640
641 // no existing column has been replaced and a new column must be created
642 const QModelIndex dirIndex = m_dolphinModel->indexForUrl(url);
643 if (dirIndex.isValid()) {
644 triggerItem(m_proxyModel->mapFromSource(dirIndex));
645 }
646 }
647
648 void DolphinColumnView::updateDecorationSize()
649 {
650 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
651 const int iconSize = settings->iconSize();
652
653 foreach (QObject* object, viewport()->children()) {
654 if (object->inherits("QListView")) {
655 ColumnWidget* widget = static_cast<ColumnWidget*>(object);
656 widget->setDecorationSize(QSize(iconSize, iconSize));
657 }
658 }
659
660 m_controller->setZoomInPossible(isZoomInPossible());
661 m_controller->setZoomOutPossible(isZoomOutPossible());
662
663 doItemsLayout();
664 }
665
666 bool DolphinColumnView::isZoomInPossible() const
667 {
668 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
669 return settings->iconSize() < K3Icon::SizeLarge;
670 }
671
672 bool DolphinColumnView::isZoomOutPossible() const
673 {
674 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
675 return settings->iconSize() > K3Icon::SizeSmall;
676 }
677
678 void DolphinColumnView::setActiveColumnIndex(int index)
679 {
680 if (m_index == index) {
681 return;
682 }
683
684 const bool hasActiveColumn = (m_index >= 0);
685 if (hasActiveColumn) {
686 m_columns[m_index]->setActive(false);
687 }
688
689 m_index = index;
690 m_columns[m_index]->setActive(true);
691
692 m_controller->setUrl(m_columns[m_index]->url());
693 }
694
695 void DolphinColumnView::layoutColumns()
696 {
697 int x = m_contentX;
698 ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
699 const int columnWidth = settings->columnWidth();
700 foreach (ColumnWidget* column, m_columns) {
701 column->setGeometry(QRect(x, 0, columnWidth, viewport()->height()));
702 x += columnWidth;
703 }
704 }
705
706 void DolphinColumnView::updateScrollBar()
707 {
708 int contentWidth = 0;
709 foreach (ColumnWidget* column, m_columns) {
710 contentWidth += column->width();
711 }
712
713 horizontalScrollBar()->setPageStep(contentWidth);
714 horizontalScrollBar()->setRange(0, contentWidth - viewport()->width());
715 }
716
717 void DolphinColumnView::assureVisibleActiveColumn()
718 {
719 const int viewportWidth = viewport()->width();
720 const int x = activeColumn()->x();
721 const int width = activeColumn()->width();
722 if (x + width > viewportWidth) {
723 int newContentX = m_contentX - x - width + viewportWidth;
724 if (newContentX > 0) {
725 newContentX = 0;
726 }
727 m_animation->setFrameRange(-m_contentX, -newContentX);
728 m_animation->start();
729 } else if (x < 0) {
730 const int newContentX = m_contentX - x;
731 m_animation->setFrameRange(-m_contentX, -newContentX);
732 m_animation->start();
733 }
734 }
735
736 void DolphinColumnView::requestActivation(ColumnWidget* column)
737 {
738 if (column->isActive()) {
739 assureVisibleActiveColumn();
740 } else {
741 int index = 0;
742 foreach (ColumnWidget* currColumn, m_columns) {
743 if (currColumn == column) {
744 setActiveColumnIndex(index);
745 assureVisibleActiveColumn();
746 return;
747 }
748 ++index;
749 }
750 }
751 }
752
753 void DolphinColumnView::deleteInactiveChildColumns()
754 {
755 QList<ColumnWidget*>::iterator start = m_columns.begin() + m_index + 1;
756 QList<ColumnWidget*>::iterator end = m_columns.end();
757 for (QList<ColumnWidget*>::iterator it = start; it != end; ++it) {
758 (*it)->deleteLater();
759 }
760 m_columns.erase(start, end);
761 }
762
763 #include "dolphincolumnview.moc"