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 column
->setVerticalScrollMode(ColumnWidget::ScrollPerPixel
);
418 column
->setHorizontalScrollMode(ColumnWidget::ScrollPerPixel
);
419 m_columns
.append(column
);
420 setActiveColumnIndex(0);
422 updateDecorationSize();
424 m_animation
= new QTimeLine(500, this);
425 connect(m_animation
, SIGNAL(frameChanged(int)), horizontalScrollBar(), SLOT(setValue(int)));
427 // dim the background of the viewport
428 QColor bgColor
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
429 const QColor fgColor
= KColorScheme(QPalette::Active
, KColorScheme::View
).foreground().color();
430 bgColor
= KColorUtils::mix(bgColor
, fgColor
, 0.04);
432 QPalette palette
= viewport()->palette();
433 palette
.setColor(viewport()->backgroundRole(), bgColor
);
434 viewport()->setPalette(palette
);
437 DolphinColumnView::~DolphinColumnView()
441 QModelIndex
DolphinColumnView::indexAt(const QPoint
& point
) const
443 foreach (ColumnWidget
* column
, m_columns
) {
444 const QPoint topLeft
= column
->frameGeometry().topLeft();
445 const QPoint
adjustedPoint(point
.x() - topLeft
.x(), point
.y() - topLeft
.y());
446 const QModelIndex index
= column
->indexAt(adjustedPoint
);
447 if (index
.isValid()) {
452 return QModelIndex();
455 void DolphinColumnView::scrollTo(const QModelIndex
& index
, ScrollHint hint
)
457 activeColumn()->scrollTo(index
, hint
);
460 QRect
DolphinColumnView::visualRect(const QModelIndex
& index
) const
462 return activeColumn()->visualRect(index
);
465 void DolphinColumnView::setModel(QAbstractItemModel
* model
)
467 if (m_dolphinModel
!= 0) {
468 m_dolphinModel
->disconnect(this);
471 m_proxyModel
= static_cast<QAbstractProxyModel
*>(model
);
472 m_dolphinModel
= static_cast<DolphinModel
*>(m_proxyModel
->sourceModel());
473 connect(m_dolphinModel
, SIGNAL(expand(const QModelIndex
&)),
474 this, SLOT(triggerReloadColumns(const QModelIndex
&)));
476 activeColumn()->setModel(model
);
477 QAbstractItemView::setModel(model
);
480 void DolphinColumnView::reload()
482 // Due to the reloading of the model all columns will be reset to show
483 // the same content as the first column. As this is not wanted, all columns
484 // except of the first column are temporary hidden until the root index can
486 m_restoreActiveColumnFocus
= false;
487 QList
<ColumnWidget
*>::iterator start
= m_columns
.begin() + 1;
488 QList
<ColumnWidget
*>::iterator end
= m_columns
.end();
489 for (QList
<ColumnWidget
*>::iterator it
= start
; it
!= end
; ++it
) {
490 ColumnWidget
* column
= (*it
);
491 if (column
->isActive() && column
->hasFocus()) {
492 // because of hiding the column, it will lose the focus
493 // -> remember that the focus should be restored after reloading
494 m_restoreActiveColumnFocus
= true;
499 // all columns are hidden, now reload the directory lister
500 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
501 connect(dirLister
, SIGNAL(completed()),
502 this, SLOT(expandToActiveUrl()));
503 const KUrl rootUrl
= m_columns
[0]->url();
504 dirLister
->openUrl(rootUrl
, false, true);
507 void DolphinColumnView::showColumn(const KUrl
& url
)
509 const KUrl
& rootUrl
= m_columns
[0]->url();
510 if (!rootUrl
.isParentOf(url
)) {
511 // the URL is no child URL of the column view, hence clear all columns
512 // and reset the root column
513 QList
<ColumnWidget
*>::iterator start
= m_columns
.begin() + 1;
514 QList
<ColumnWidget
*>::iterator end
= m_columns
.end();
515 for (QList
<ColumnWidget
*>::iterator it
= start
; it
!= end
; ++it
) {
516 (*it
)->deleteLater();
518 m_columns
.erase(start
, end
);
520 m_columns
[0]->setActive(true);
521 m_columns
[0]->setUrl(url
);
522 assureVisibleActiveColumn();
526 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
527 const KUrl dirListerUrl
= dirLister
->url();
528 if (dirListerUrl
!= rootUrl
) {
529 // It is possible that root URL of the directory lister is adjusted
530 // after creating the column widget (e. g. when restoring the history
531 // having a different root URL than the controller indicates).
532 m_columns
[0]->setUrl(dirListerUrl
);
536 foreach (ColumnWidget
* column
, m_columns
) {
537 if (column
->url() == url
) {
538 // the column represents already the requested URL, hence activate it
539 requestActivation(column
);
541 } else if (!column
->url().isParentOf(url
)) {
542 // the column is no parent of the requested URL, hence
543 // just delete all remaining columns
544 if (columnIndex
> 0) {
545 QList
<ColumnWidget
*>::iterator start
= m_columns
.begin() + columnIndex
;
546 QList
<ColumnWidget
*>::iterator end
= m_columns
.end();
547 for (QList
<ColumnWidget
*>::iterator it
= start
; it
!= end
; ++it
) {
548 (*it
)->deleteLater();
550 m_columns
.erase(start
, end
);
552 const int maxIndex
= m_columns
.count() - 1;
553 Q_ASSERT(maxIndex
>= 0);
554 if (m_index
> maxIndex
) {
563 // Create missing columns. Assuming that the path is "/home/peter/Temp/" and
564 // the target path is "/home/peter/Temp/a/b/c/", then the columns "a", "b" and
565 // "c" will be created.
566 const int lastIndex
= m_columns
.count() - 1;
567 Q_ASSERT(lastIndex
>= 0);
569 const KUrl
& activeUrl
= m_columns
[lastIndex
]->url();
570 Q_ASSERT(activeUrl
.isParentOf(url
));
571 Q_ASSERT(activeUrl
!= url
);
573 QString path
= activeUrl
.url(KUrl::AddTrailingSlash
);
574 const QString targetPath
= url
.url(KUrl::AddTrailingSlash
);
576 columnIndex
= lastIndex
;
577 int slashIndex
= path
.count('/');
578 bool hasSubPath
= (slashIndex
>= 0);
580 const QString subPath
= targetPath
.section('/', slashIndex
, slashIndex
);
581 if (subPath
.isEmpty()) {
584 path
+= subPath
+ '/';
587 const KUrl childUrl
= KUrl(path
);
588 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(KUrl(path
));
589 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
591 m_columns
[columnIndex
]->setChildUrl(childUrl
);
594 ColumnWidget
* column
= new ColumnWidget(viewport(), this, childUrl
);
595 column
->setVerticalScrollMode(ColumnWidget::ScrollPerPixel
);
596 column
->setHorizontalScrollMode(ColumnWidget::ScrollPerPixel
);
597 column
->setModel(model());
598 column
->setRootIndex(proxyIndex
);
599 column
->setActive(false);
601 m_columns
.append(column
);
603 // Before invoking layoutColumns() the column must be set visible temporary.
604 // To prevent a flickering the initial geometry is set to a hidden position.
605 column
->setGeometry(QRect(-1, -1, 1, 1));
610 // the layout is finished, now let the column be invisible until it
611 // gets a valid root index due to expandToActiveUrl()
616 // set the last column as active column without modifying the controller
617 // and hence the history
618 activeColumn()->setActive(false);
619 m_index
= columnIndex
;
620 activeColumn()->setActive(true);
625 bool DolphinColumnView::isIndexHidden(const QModelIndex
& index
) const
628 return false;//activeColumn()->isIndexHidden(index);
631 QModelIndex
DolphinColumnView::moveCursor(CursorAction cursorAction
, Qt::KeyboardModifiers modifiers
)
633 // Parts of this code have been taken from QColumnView::moveCursor().
634 // Copyright (C) 1992-2007 Trolltech ASA.
638 return QModelIndex();
641 const QModelIndex current
= currentIndex();
642 if (isRightToLeft()) {
643 if (cursorAction
== MoveLeft
) {
644 cursorAction
= MoveRight
;
645 } else if (cursorAction
== MoveRight
) {
646 cursorAction
= MoveLeft
;
650 switch (cursorAction
) {
653 setActiveColumnIndex(m_index
- 1);
658 if (m_index
< m_columns
.count() - 1) {
659 setActiveColumnIndex(m_index
+ 1);
667 return QModelIndex();
670 void DolphinColumnView::setSelection(const QRect
& rect
, QItemSelectionModel::SelectionFlags flags
)
674 //activeColumn()->setSelection(rect, flags);
677 QRegion
DolphinColumnView::visualRegionForSelection(const QItemSelection
& selection
) const
680 return QRegion(); //activeColumn()->visualRegionForSelection(selection);
683 int DolphinColumnView::horizontalOffset() const
688 int DolphinColumnView::verticalOffset() const
693 void DolphinColumnView::mousePressEvent(QMouseEvent
* event
)
695 m_controller
->triggerActivation();
696 QAbstractItemView::mousePressEvent(event
);
699 void DolphinColumnView::resizeEvent(QResizeEvent
* event
)
701 QAbstractItemView::resizeEvent(event
);
706 void DolphinColumnView::zoomIn()
708 if (isZoomInPossible()) {
709 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
710 // TODO: get rid of K3Icon sizes
711 switch (settings
->iconSize()) {
712 case K3Icon::SizeSmall
: settings
->setIconSize(K3Icon::SizeMedium
); break;
713 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeLarge
); break;
714 default: Q_ASSERT(false); break;
716 updateDecorationSize();
720 void DolphinColumnView::zoomOut()
722 if (isZoomOutPossible()) {
723 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
724 // TODO: get rid of K3Icon sizes
725 switch (settings
->iconSize()) {
726 case K3Icon::SizeLarge
: settings
->setIconSize(K3Icon::SizeMedium
); break;
727 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeSmall
); break;
728 default: Q_ASSERT(false); break;
730 updateDecorationSize();
734 void DolphinColumnView::moveContentHorizontally(int x
)
740 void DolphinColumnView::updateDecorationSize()
742 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
743 const int iconSize
= settings
->iconSize();
745 foreach (QObject
* object
, viewport()->children()) {
746 if (object
->inherits("QListView")) {
747 ColumnWidget
* widget
= static_cast<ColumnWidget
*>(object
);
748 widget
->setDecorationSize(QSize(iconSize
, iconSize
));
752 m_controller
->setZoomInPossible(isZoomInPossible());
753 m_controller
->setZoomOutPossible(isZoomOutPossible());
758 void DolphinColumnView::expandToActiveUrl()
760 const int lastIndex
= m_columns
.count() - 1;
761 Q_ASSERT(lastIndex
>= 0);
762 const KUrl
& activeUrl
= m_columns
[lastIndex
]->url();
763 const KUrl rootUrl
= m_dolphinModel
->dirLister()->url();
764 const bool expand
= rootUrl
.isParentOf(activeUrl
)
765 && !rootUrl
.equals(activeUrl
, KUrl::CompareWithoutTrailingSlash
);
767 m_dolphinModel
->expandToUrl(activeUrl
);
772 void DolphinColumnView::triggerReloadColumns(const QModelIndex
& index
)
775 // the reloading of the columns may not be done in the context of this slot
776 QMetaObject::invokeMethod(this, "reloadColumns", Qt::QueuedConnection
);
779 void DolphinColumnView::reloadColumns()
781 const int end
= m_columns
.count() - 2; // next to last column
782 for (int i
= 0; i
<= end
; ++i
) {
783 ColumnWidget
* nextColumn
= m_columns
[i
+ 1];
785 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
786 dirLister
->updateDirectory(nextColumn
->url());
788 const QModelIndex rootIndex
= nextColumn
->rootIndex();
789 if (rootIndex
.isValid()) {
792 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(m_columns
[i
]->childUrl());
793 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
794 if (proxyIndex
.isValid()) {
795 nextColumn
->setRootIndex(proxyIndex
);
797 if (nextColumn
->isActive() && m_restoreActiveColumnFocus
) {
798 nextColumn
->setFocus();
799 m_restoreActiveColumnFocus
= false;
804 assureVisibleActiveColumn();
807 bool DolphinColumnView::isZoomInPossible() const
809 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
810 return settings
->iconSize() < K3Icon::SizeLarge
;
813 bool DolphinColumnView::isZoomOutPossible() const
815 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
816 return settings
->iconSize() > K3Icon::SizeSmall
;
819 void DolphinColumnView::setActiveColumnIndex(int index
)
821 if (m_index
== index
) {
825 const bool hasActiveColumn
= (m_index
>= 0);
826 if (hasActiveColumn
) {
827 m_columns
[m_index
]->setActive(false);
831 m_columns
[m_index
]->setActive(true);
833 m_controller
->setUrl(m_columns
[m_index
]->url());
836 void DolphinColumnView::layoutColumns()
839 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
840 const int columnWidth
= settings
->columnWidth();
841 foreach (ColumnWidget
* column
, m_columns
) {
842 column
->setGeometry(QRect(x
, 0, columnWidth
, viewport()->height()));
847 void DolphinColumnView::updateScrollBar()
849 int contentWidth
= 0;
850 foreach (ColumnWidget
* column
, m_columns
) {
851 contentWidth
+= column
->width();
854 horizontalScrollBar()->setPageStep(contentWidth
);
855 horizontalScrollBar()->setRange(0, contentWidth
- viewport()->width());
858 void DolphinColumnView::assureVisibleActiveColumn()
860 const int viewportWidth
= viewport()->width();
861 const int x
= activeColumn()->x();
862 const int width
= activeColumn()->width();
863 if (x
+ width
> viewportWidth
) {
864 int newContentX
= m_contentX
- x
- width
+ viewportWidth
;
865 if (newContentX
> 0) {
868 m_animation
->setFrameRange(-m_contentX
, -newContentX
);
869 m_animation
->start();
871 const int newContentX
= m_contentX
- x
;
872 m_animation
->setFrameRange(-m_contentX
, -newContentX
);
873 m_animation
->start();
877 void DolphinColumnView::requestActivation(ColumnWidget
* column
)
879 if (column
->isActive()) {
880 assureVisibleActiveColumn();
883 foreach (ColumnWidget
* currColumn
, m_columns
) {
884 if (currColumn
== column
) {
885 setActiveColumnIndex(index
);
886 assureVisibleActiveColumn();
894 #include "dolphincolumnview.moc"