1 /***************************************************************************
2 * Copyright (C) 2007 by Peter Penz <peter.penz@gmx.at> *
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. *
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. *
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 ***************************************************************************/
20 #include "dolphincolumnview.h"
22 #include "dolphinmodel.h"
23 #include "dolphincontroller.h"
24 #include "dolphinsettings.h"
26 #include "dolphin_columnmodesettings.h"
28 #include <kcolorutils.h>
29 #include <kcolorscheme.h>
30 #include <kdirlister.h>
32 #include <QAbstractProxyModel>
33 #include <QApplication>
39 * Represents one column inside the DolphinColumnView and has been
40 * extended to respect view options and hovering information.
42 class ColumnWidget
: public QListView
45 ColumnWidget(QWidget
* parent
,
46 DolphinColumnView
* columnView
,
48 virtual ~ColumnWidget();
50 /** Sets the size of the icons. */
51 void setDecorationSize(const QSize
& size
);
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.
58 void setActive(bool active
);
59 bool isActive() const;
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.
66 void setChildUrl(const KUrl
& url
);
67 const KUrl
& childUrl() const;
69 /** Sets the directory URL that is shown inside the column widget. */
70 void setUrl(const KUrl
& url
);
72 /** Returns the directory URL that is shown inside the column widget. */
73 inline const KUrl
& url() const;
76 virtual QStyleOptionViewItem
viewOptions() const;
77 virtual void dragEnterEvent(QDragEnterEvent
* event
);
78 virtual void dragLeaveEvent(QDragLeaveEvent
* event
);
79 virtual void dragMoveEvent(QDragMoveEvent
* event
);
80 virtual void dropEvent(QDropEvent
* event
);
81 virtual void paintEvent(QPaintEvent
* event
);
82 virtual void mousePressEvent(QMouseEvent
* event
);
83 virtual void keyPressEvent(QKeyEvent
* event
);
84 virtual void contextMenuEvent(QContextMenuEvent
* event
);
85 virtual void selectionChanged(const QItemSelection
& selected
, const QItemSelection
& deselected
);
88 /** Used by ColumnWidget::setActive(). */
91 /** Used by ColumnWidget::setActive(). */
96 DolphinColumnView
* m_view
;
97 KUrl m_url
; // URL of the directory that is shown
98 KUrl m_childUrl
; // URL of the next column that is shown
99 QStyleOptionViewItem m_viewOptions
;
101 bool m_dragging
; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
102 QRect m_dropRect
; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
105 ColumnWidget::ColumnWidget(QWidget
* parent
,
106 DolphinColumnView
* columnView
,
116 setMouseTracking(true);
117 viewport()->setAttribute(Qt::WA_Hover
);
118 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
119 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn
);
120 setSelectionBehavior(SelectItems
);
121 setSelectionMode(QAbstractItemView::ExtendedSelection
);
122 setDragDropMode(QAbstractItemView::DragDrop
);
123 setDropIndicatorShown(false);
124 setFocusPolicy(Qt::NoFocus
);
126 // apply the column mode settings to the widget
127 const ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
128 Q_ASSERT(settings
!= 0);
130 m_viewOptions
= QListView::viewOptions();
132 QFont
font(settings
->fontFamily(), settings
->fontSize());
133 font
.setItalic(settings
->italicFont());
134 font
.setBold(settings
->boldFont());
135 m_viewOptions
.font
= font
;
137 const int iconSize
= settings
->iconSize();
138 m_viewOptions
.decorationSize
= QSize(iconSize
, iconSize
);
140 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
141 setItemDelegate(delegate
);
145 connect(this, SIGNAL(entered(const QModelIndex
&)),
146 m_view
->m_controller
, SLOT(emitItemEntered(const QModelIndex
&)));
147 connect(this, SIGNAL(viewportEntered()),
148 m_view
->m_controller
, SLOT(emitViewportEntered()));
151 ColumnWidget::~ColumnWidget()
155 void ColumnWidget::setDecorationSize(const QSize
& size
)
157 m_viewOptions
.decorationSize
= size
;
161 void ColumnWidget::setActive(bool active
)
163 if (m_active
== active
) {
176 inline bool ColumnWidget::isActive() const
181 inline void ColumnWidget::setChildUrl(const KUrl
& url
)
186 inline const KUrl
& ColumnWidget::childUrl() const
191 inline void ColumnWidget::setUrl(const KUrl
& url
)
196 const KUrl
& ColumnWidget::url() const
201 QStyleOptionViewItem
ColumnWidget::viewOptions() const
203 return m_viewOptions
;
206 void ColumnWidget::dragEnterEvent(QDragEnterEvent
* event
)
208 if (event
->mimeData()->hasUrls()) {
209 event
->acceptProposedAction();
215 void ColumnWidget::dragLeaveEvent(QDragLeaveEvent
* event
)
217 QListView::dragLeaveEvent(event
);
219 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
221 setDirtyRegion(m_dropRect
);
224 void ColumnWidget::dragMoveEvent(QDragMoveEvent
* event
)
226 QListView::dragMoveEvent(event
);
228 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
229 const QModelIndex index
= indexAt(event
->pos());
230 setDirtyRegion(m_dropRect
);
231 m_dropRect
= visualRect(index
);
232 setDirtyRegion(m_dropRect
);
235 void ColumnWidget::dropEvent(QDropEvent
* event
)
237 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
238 if (!urls
.isEmpty()) {
239 event
->acceptProposedAction();
240 m_view
->m_controller
->indicateDroppedUrls(urls
,
242 indexAt(event
->pos()),
245 QListView::dropEvent(event
);
249 void ColumnWidget::paintEvent(QPaintEvent
* event
)
251 if (!m_childUrl
.isEmpty()) {
252 // indicate the shown URL of the next column by highlighting the shown folder item
253 const QModelIndex dirIndex
= m_view
->m_dolphinModel
->indexForUrl(m_childUrl
);
254 const QModelIndex proxyIndex
= m_view
->m_proxyModel
->mapFromSource(dirIndex
);
255 if (proxyIndex
.isValid() && !selectionModel()->isSelected(proxyIndex
)) {
256 const QRect itemRect
= visualRect(proxyIndex
);
257 QPainter
painter(viewport());
260 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).foreground().color();
262 painter
.setPen(Qt::NoPen
);
263 painter
.setBrush(color
);
264 painter
.drawRect(itemRect
);
270 QListView::paintEvent(event
);
272 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
274 const QBrush
& brush
= m_viewOptions
.palette
.brush(QPalette::Normal
, QPalette::Highlight
);
275 DolphinController::drawHoverIndication(viewport(), m_dropRect
, brush
);
279 void ColumnWidget::mousePressEvent(QMouseEvent
* event
)
282 m_view
->requestActivation(this);
285 QListView::mousePressEvent(event
);
288 void ColumnWidget::keyPressEvent(QKeyEvent
* event
)
290 QListView::keyPressEvent(event
);
292 const QItemSelectionModel
* selModel
= selectionModel();
293 const QModelIndex currentIndex
= selModel
->currentIndex();
294 const bool triggerItem
= currentIndex
.isValid()
295 && (event
->key() == Qt::Key_Return
)
296 && (selModel
->selectedIndexes().count() <= 1);
298 m_view
->m_controller
->triggerItem(currentIndex
);
302 void ColumnWidget::contextMenuEvent(QContextMenuEvent
* event
)
305 m_view
->requestActivation(this);
308 QListView::contextMenuEvent(event
);
310 const QModelIndex index
= indexAt(event
->pos());
311 if (index
.isValid() || m_active
) {
312 // Only open a context menu above an item or if the mouse is above
313 // the active column.
314 const QPoint pos
= m_view
->viewport()->mapFromGlobal(event
->globalPos());
315 m_view
->m_controller
->triggerContextMenuRequest(pos
);
319 void ColumnWidget::selectionChanged(const QItemSelection
& selected
, const QItemSelection
& deselected
)
321 QListView::selectionChanged(selected
, deselected
);
323 QItemSelectionModel
* selModel
= m_view
->selectionModel();
324 selModel
->select(selected
, QItemSelectionModel::Select
);
325 selModel
->select(deselected
, QItemSelectionModel::Deselect
);
328 void ColumnWidget::activate()
330 if (m_view
->hasFocus()) {
331 setFocus(Qt::OtherFocusReason
);
333 m_view
->setFocusProxy(this);
335 // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
336 // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
337 // necessary connecting the signal 'singleClick()' or 'doubleClick'.
338 if (KGlobalSettings::singleClick()) {
339 connect(this, SIGNAL(clicked(const QModelIndex
&)),
340 m_view
->m_controller
, SLOT(triggerItem(const QModelIndex
&)));
342 connect(this, SIGNAL(doubleClicked(const QModelIndex
&)),
343 m_view
->m_controller
, SLOT(triggerItem(const QModelIndex
&)));
346 const QColor bgColor
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
347 QPalette palette
= viewport()->palette();
348 palette
.setColor(viewport()->backgroundRole(), bgColor
);
349 viewport()->setPalette(palette
);
351 if (!m_childUrl
.isEmpty()) {
352 // assure that the current index is set on the index that represents
354 const QModelIndex dirIndex
= m_view
->m_dolphinModel
->indexForUrl(m_childUrl
);
355 const QModelIndex proxyIndex
= m_view
->m_proxyModel
->mapFromSource(dirIndex
);
356 selectionModel()->setCurrentIndex(proxyIndex
, QItemSelectionModel::Current
);
362 void ColumnWidget::deactivate()
364 // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
365 // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
366 // necessary connecting the signal 'singleClick()' or 'doubleClick'.
367 if (KGlobalSettings::singleClick()) {
368 disconnect(this, SIGNAL(clicked(const QModelIndex
&)),
369 m_view
->m_controller
, SLOT(triggerItem(const QModelIndex
&)));
371 disconnect(this, SIGNAL(doubleClicked(const QModelIndex
&)),
372 m_view
->m_controller
, SLOT(triggerItem(const QModelIndex
&)));
375 const QPalette palette
= m_view
->viewport()->palette();
376 viewport()->setPalette(palette
);
378 selectionModel()->clear();
384 DolphinColumnView::DolphinColumnView(QWidget
* parent
, DolphinController
* controller
) :
385 QAbstractItemView(parent
),
386 m_controller(controller
),
387 m_restoreActiveColumnFocus(false),
395 Q_ASSERT(controller
!= 0);
397 setAcceptDrops(true);
398 setDragDropMode(QAbstractItemView::DragDrop
);
399 setDropIndicatorShown(false);
400 setSelectionMode(ExtendedSelection
);
402 connect(this, SIGNAL(entered(const QModelIndex
&)),
403 controller
, SLOT(emitItemEntered(const QModelIndex
&)));
404 connect(this, SIGNAL(viewportEntered()),
405 controller
, SLOT(emitViewportEntered()));
406 connect(controller
, SIGNAL(zoomIn()),
407 this, SLOT(zoomIn()));
408 connect(controller
, SIGNAL(zoomOut()),
409 this, SLOT(zoomOut()));
410 connect(controller
, SIGNAL(urlChanged(const KUrl
&)),
411 this, SLOT(showColumn(const KUrl
&)));
413 connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
414 this, SLOT(moveContentHorizontally(int)));
416 ColumnWidget
* column
= new ColumnWidget(viewport(), this, m_controller
->url());
417 m_columns
.append(column
);
418 setActiveColumnIndex(0);
420 updateDecorationSize();
422 m_animation
= new QTimeLine(500, this);
423 connect(m_animation
, SIGNAL(frameChanged(int)), horizontalScrollBar(), SLOT(setValue(int)));
425 // dim the background of the viewport
426 QColor bgColor
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
427 const QColor fgColor
= KColorScheme(QPalette::Active
, KColorScheme::View
).foreground().color();
428 bgColor
= KColorUtils::mix(bgColor
, fgColor
, 0.04);
430 QPalette palette
= viewport()->palette();
431 palette
.setColor(viewport()->backgroundRole(), bgColor
);
432 viewport()->setPalette(palette
);
435 DolphinColumnView::~DolphinColumnView()
439 QModelIndex
DolphinColumnView::indexAt(const QPoint
& point
) const
441 foreach (ColumnWidget
* column
, m_columns
) {
442 const QPoint topLeft
= column
->frameGeometry().topLeft();
443 const QPoint
adjustedPoint(point
.x() - topLeft
.x(), point
.y() - topLeft
.y());
444 const QModelIndex index
= column
->indexAt(adjustedPoint
);
445 if (index
.isValid()) {
450 return QModelIndex();
453 void DolphinColumnView::scrollTo(const QModelIndex
& index
, ScrollHint hint
)
455 activeColumn()->scrollTo(index
, hint
);
458 QRect
DolphinColumnView::visualRect(const QModelIndex
& index
) const
460 return activeColumn()->visualRect(index
);
463 void DolphinColumnView::setModel(QAbstractItemModel
* model
)
465 if (m_dolphinModel
!= 0) {
466 m_dolphinModel
->disconnect(this);
469 m_proxyModel
= static_cast<QAbstractProxyModel
*>(model
);
470 m_dolphinModel
= static_cast<DolphinModel
*>(m_proxyModel
->sourceModel());
471 connect(m_dolphinModel
, SIGNAL(expand(const QModelIndex
&)),
472 this, SLOT(triggerReloadColumns(const QModelIndex
&)));
474 activeColumn()->setModel(model
);
475 QAbstractItemView::setModel(model
);
478 void DolphinColumnView::reload()
480 // Due to the reloading of the model all columns will be reset to show
481 // the same content as the first column. As this is not wanted, all columns
482 // except of the first column are temporary hidden until the root index can
484 m_restoreActiveColumnFocus
= false;
485 QList
<ColumnWidget
*>::iterator start
= m_columns
.begin() + 1;
486 QList
<ColumnWidget
*>::iterator end
= m_columns
.end();
487 for (QList
<ColumnWidget
*>::iterator it
= start
; it
!= end
; ++it
) {
488 ColumnWidget
* column
= (*it
);
489 if (column
->isActive() && column
->hasFocus()) {
490 // because of hiding the column, it will lose the focus
491 // -> remember that the focus should be restored after reloading
492 m_restoreActiveColumnFocus
= true;
497 // all columns are hidden, now reload the directory lister
498 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
499 connect(dirLister
, SIGNAL(completed()),
500 this, SLOT(expandToActiveUrl()));
501 const KUrl rootUrl
= m_columns
[0]->url();
502 dirLister
->openUrl(rootUrl
, false, true);
505 void DolphinColumnView::showColumn(const KUrl
& url
)
507 const KUrl
& rootUrl
= m_columns
[0]->url();
508 if (!rootUrl
.isParentOf(url
)) {
509 // the URL is no child URL of the column view, hence do nothing
513 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
514 const KUrl dirListerUrl
= dirLister
->url();
515 if (dirListerUrl
!= rootUrl
) {
516 // It is possible that root URL of the directory lister is adjusted
517 // after creating the column widget (e. g. when restoring the history
518 // having a different root URL than the controller indicates).
519 m_columns
[0]->setUrl(dirListerUrl
);
523 foreach (ColumnWidget
* column
, m_columns
) {
524 if (column
->url() == url
) {
525 // the column represents already the requested URL, hence activate it
526 requestActivation(column
);
528 } else if (!column
->url().isParentOf(url
)) {
529 // the column is no parent of the requested URL, hence
530 // just delete all remaining columns
531 if (columnIndex
> 0) {
532 QList
<ColumnWidget
*>::iterator start
= m_columns
.begin() + columnIndex
;
533 QList
<ColumnWidget
*>::iterator end
= m_columns
.end();
534 for (QList
<ColumnWidget
*>::iterator it
= start
; it
!= end
; ++it
) {
535 (*it
)->deleteLater();
537 m_columns
.erase(start
, end
);
539 const int maxIndex
= m_columns
.count() - 1;
540 Q_ASSERT(maxIndex
>= 0);
541 if (m_index
> maxIndex
) {
550 // Create missing columns. Assuming that the path is "/home/peter/Temp/" and
551 // the target path is "/home/peter/Temp/a/b/c/", then the columns "a", "b" and
552 // "c" will be created.
553 const int lastIndex
= m_columns
.count() - 1;
554 Q_ASSERT(lastIndex
>= 0);
556 const KUrl
& activeUrl
= m_columns
[lastIndex
]->url();
557 Q_ASSERT(activeUrl
.isParentOf(url
));
558 Q_ASSERT(activeUrl
!= url
);
560 QString path
= activeUrl
.url(KUrl::AddTrailingSlash
);
561 const QString targetPath
= url
.url(KUrl::AddTrailingSlash
);
563 columnIndex
= lastIndex
;
564 int slashIndex
= path
.count('/');
565 bool hasSubPath
= (slashIndex
>= 0);
567 const QString subPath
= targetPath
.section('/', slashIndex
, slashIndex
);
568 if (subPath
.isEmpty()) {
571 path
+= subPath
+ '/';
574 const KUrl childUrl
= KUrl(path
);
575 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(KUrl(path
));
576 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
578 m_columns
[columnIndex
]->setChildUrl(childUrl
);
581 ColumnWidget
* column
= new ColumnWidget(viewport(), this, childUrl
);
582 column
->setModel(model());
583 column
->setRootIndex(proxyIndex
);
584 column
->setActive(false);
586 m_columns
.append(column
);
588 // Before invoking layoutColumns() the column must be set visible temporary.
589 // To prevent a flickering the initial geometry is set to a hidden position.
590 column
->setGeometry(QRect(-1, -1, 1, 1));
595 // the layout is finished, now let the column be invisible until it
596 // gets a valid root index due to expandToActiveUrl()
601 // set the last column as active column without modifying the controller
602 // and hence the history
603 activeColumn()->setActive(false);
604 m_index
= columnIndex
;
605 activeColumn()->setActive(true);
610 bool DolphinColumnView::isIndexHidden(const QModelIndex
& index
) const
613 return false;//activeColumn()->isIndexHidden(index);
616 QModelIndex
DolphinColumnView::moveCursor(CursorAction cursorAction
, Qt::KeyboardModifiers modifiers
)
618 // Parts of this code have been taken from QColumnView::moveCursor().
619 // Copyright (C) 1992-2007 Trolltech ASA.
623 return QModelIndex();
626 const QModelIndex current
= currentIndex();
627 if (isRightToLeft()) {
628 if (cursorAction
== MoveLeft
) {
629 cursorAction
= MoveRight
;
630 } else if (cursorAction
== MoveRight
) {
631 cursorAction
= MoveLeft
;
635 switch (cursorAction
) {
638 setActiveColumnIndex(m_index
- 1);
643 if (m_index
< m_columns
.count() - 1) {
644 setActiveColumnIndex(m_index
+ 1);
652 return QModelIndex();
655 void DolphinColumnView::setSelection(const QRect
& rect
, QItemSelectionModel::SelectionFlags flags
)
659 //activeColumn()->setSelection(rect, flags);
662 QRegion
DolphinColumnView::visualRegionForSelection(const QItemSelection
& selection
) const
665 return QRegion(); //activeColumn()->visualRegionForSelection(selection);
668 int DolphinColumnView::horizontalOffset() const
673 int DolphinColumnView::verticalOffset() const
678 void DolphinColumnView::mousePressEvent(QMouseEvent
* event
)
680 m_controller
->triggerActivation();
681 QAbstractItemView::mousePressEvent(event
);
684 void DolphinColumnView::resizeEvent(QResizeEvent
* event
)
686 QAbstractItemView::resizeEvent(event
);
691 void DolphinColumnView::zoomIn()
693 if (isZoomInPossible()) {
694 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
695 // TODO: get rid of K3Icon sizes
696 switch (settings
->iconSize()) {
697 case K3Icon::SizeSmall
: settings
->setIconSize(K3Icon::SizeMedium
); break;
698 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeLarge
); break;
699 default: Q_ASSERT(false); break;
701 updateDecorationSize();
705 void DolphinColumnView::zoomOut()
707 if (isZoomOutPossible()) {
708 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
709 // TODO: get rid of K3Icon sizes
710 switch (settings
->iconSize()) {
711 case K3Icon::SizeLarge
: settings
->setIconSize(K3Icon::SizeMedium
); break;
712 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeSmall
); break;
713 default: Q_ASSERT(false); break;
715 updateDecorationSize();
719 void DolphinColumnView::moveContentHorizontally(int x
)
725 void DolphinColumnView::updateDecorationSize()
727 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
728 const int iconSize
= settings
->iconSize();
730 foreach (QObject
* object
, viewport()->children()) {
731 if (object
->inherits("QListView")) {
732 ColumnWidget
* widget
= static_cast<ColumnWidget
*>(object
);
733 widget
->setDecorationSize(QSize(iconSize
, iconSize
));
737 m_controller
->setZoomInPossible(isZoomInPossible());
738 m_controller
->setZoomOutPossible(isZoomOutPossible());
743 void DolphinColumnView::expandToActiveUrl()
745 const int lastIndex
= m_columns
.count() - 1;
746 Q_ASSERT(lastIndex
>= 0);
747 const KUrl
& activeUrl
= m_columns
[lastIndex
]->url();
748 const KUrl rootUrl
= m_dolphinModel
->dirLister()->url();
749 if (rootUrl
.isParentOf(activeUrl
) && (rootUrl
!= activeUrl
)) {
750 m_dolphinModel
->expandToUrl(activeUrl
);
755 void DolphinColumnView::triggerReloadColumns(const QModelIndex
& index
)
758 // the reloading of the columns may not be done in the context of this slot
759 QMetaObject::invokeMethod(this, "reloadColumns", Qt::QueuedConnection
);
762 void DolphinColumnView::reloadColumns()
764 const int end
= m_columns
.count() - 2; // next to last column
765 for (int i
= 0; i
<= end
; ++i
) {
766 ColumnWidget
* nextColumn
= m_columns
[i
+ 1];
767 const QModelIndex rootIndex
= nextColumn
->rootIndex();
768 if (rootIndex
.isValid()) {
771 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(m_columns
[i
]->childUrl());
772 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
773 if (proxyIndex
.isValid()) {
774 nextColumn
->setRootIndex(proxyIndex
);
776 if (nextColumn
->isActive() && m_restoreActiveColumnFocus
) {
777 nextColumn
->setFocus();
778 m_restoreActiveColumnFocus
= false;
783 assureVisibleActiveColumn();
786 bool DolphinColumnView::isZoomInPossible() const
788 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
789 return settings
->iconSize() < K3Icon::SizeLarge
;
792 bool DolphinColumnView::isZoomOutPossible() const
794 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
795 return settings
->iconSize() > K3Icon::SizeSmall
;
798 void DolphinColumnView::setActiveColumnIndex(int index
)
800 if (m_index
== index
) {
804 const bool hasActiveColumn
= (m_index
>= 0);
805 if (hasActiveColumn
) {
806 m_columns
[m_index
]->setActive(false);
810 m_columns
[m_index
]->setActive(true);
812 m_controller
->setUrl(m_columns
[m_index
]->url());
815 void DolphinColumnView::layoutColumns()
818 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
819 const int columnWidth
= settings
->columnWidth();
820 foreach (ColumnWidget
* column
, m_columns
) {
821 column
->setGeometry(QRect(x
, 0, columnWidth
, viewport()->height()));
826 void DolphinColumnView::updateScrollBar()
828 int contentWidth
= 0;
829 foreach (ColumnWidget
* column
, m_columns
) {
830 contentWidth
+= column
->width();
833 horizontalScrollBar()->setPageStep(contentWidth
);
834 horizontalScrollBar()->setRange(0, contentWidth
- viewport()->width());
837 void DolphinColumnView::assureVisibleActiveColumn()
839 const int viewportWidth
= viewport()->width();
840 const int x
= activeColumn()->x();
841 const int width
= activeColumn()->width();
842 if (x
+ width
> viewportWidth
) {
843 int newContentX
= m_contentX
- x
- width
+ viewportWidth
;
844 if (newContentX
> 0) {
847 m_animation
->setFrameRange(-m_contentX
, -newContentX
);
848 m_animation
->start();
850 const int newContentX
= m_contentX
- x
;
851 m_animation
->setFrameRange(-m_contentX
, -newContentX
);
852 m_animation
->start();
856 void DolphinColumnView::requestActivation(ColumnWidget
* column
)
858 if (column
->isActive()) {
859 assureVisibleActiveColumn();
862 foreach (ColumnWidget
* currColumn
, m_columns
) {
863 if (currColumn
== column
) {
864 setActiveColumnIndex(index
);
865 assureVisibleActiveColumn();
873 void DolphinColumnView::deleteInactiveChildColumns()
875 QList
<ColumnWidget
*>::iterator start
= m_columns
.begin() + m_index
+ 1;
876 QList
<ColumnWidget
*>::iterator end
= m_columns
.end();
877 for (QList
<ColumnWidget
*>::iterator it
= start
; it
!= end
; ++it
) {
878 (*it
)->deleteLater();
880 m_columns
.erase(start
, end
);
883 #include "dolphincolumnview.moc"