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>
40 * Represents one column inside the DolphinColumnView and has been
41 * extended to respect view options and hovering information.
43 class ColumnWidget
: public QListView
46 ColumnWidget(QWidget
* parent
,
47 DolphinColumnView
* columnView
,
49 virtual ~ColumnWidget();
51 /** Sets the size of the icons. */
52 void setDecorationSize(const QSize
& size
);
55 * An active column is defined as column, which shows the same URL
56 * as indicated by the URL navigator. The active column is usually
57 * drawn in a lighter color. All operations are applied to this column.
59 void setActive(bool active
);
60 bool isActive() const;
63 * Sets the directory URL of the child column that is shown next to
64 * this column. This property is only used for a visual indication
65 * of the shown directory, it does not trigger a loading of the model.
67 void setChildUrl(const KUrl
& url
);
68 const KUrl
& childUrl() const;
70 /** Sets the directory URL that is shown inside the column widget. */
71 void setUrl(const KUrl
& url
);
73 /** Returns the directory URL that is shown inside the column widget. */
74 const KUrl
& url() const;
77 virtual QStyleOptionViewItem
viewOptions() const;
78 virtual void dragEnterEvent(QDragEnterEvent
* event
);
79 virtual void dragLeaveEvent(QDragLeaveEvent
* event
);
80 virtual void dragMoveEvent(QDragMoveEvent
* event
);
81 virtual void dropEvent(QDropEvent
* event
);
82 virtual void paintEvent(QPaintEvent
* event
);
83 virtual void mousePressEvent(QMouseEvent
* event
);
84 virtual void keyPressEvent(QKeyEvent
* event
);
85 virtual void contextMenuEvent(QContextMenuEvent
* event
);
86 virtual void selectionChanged(const QItemSelection
& selected
, const QItemSelection
& deselected
);
89 /** Used by ColumnWidget::setActive(). */
92 /** Used by ColumnWidget::setActive(). */
97 DolphinColumnView
* m_view
;
98 KUrl m_url
; // URL of the directory that is shown
99 KUrl m_childUrl
; // URL of the next column that is shown
100 QStyleOptionViewItem m_viewOptions
;
102 bool m_dragging
; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
103 QRect m_dropRect
; // TODO: remove this property when the issue #160611 is solved in Qt 4.4
106 ColumnWidget::ColumnWidget(QWidget
* parent
,
107 DolphinColumnView
* columnView
,
117 setMouseTracking(true);
118 viewport()->setAttribute(Qt::WA_Hover
);
119 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff
);
120 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn
);
121 setSelectionBehavior(SelectItems
);
122 setSelectionMode(QAbstractItemView::ExtendedSelection
);
123 setDragDropMode(QAbstractItemView::DragDrop
);
124 setDropIndicatorShown(false);
125 setFocusPolicy(Qt::NoFocus
);
127 // TODO: Remove this check when 4.3.2 is released and KDE requires it... this
128 // check avoids a division by zero happening on versions before 4.3.1.
129 // Right now KDE in theory can be shipped with Qt 4.3.0 and above.
131 #if (QT_VERSION >= QT_VERSION_CHECK(4, 3, 2) || defined(QT_KDE_QT_COPY))
132 setVerticalScrollMode(QListView::ScrollPerPixel
);
133 setHorizontalScrollMode(QListView::ScrollPerPixel
);
136 // apply the column mode settings to the widget
137 const ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
138 Q_ASSERT(settings
!= 0);
140 m_viewOptions
= QListView::viewOptions();
142 QFont
font(settings
->fontFamily(), settings
->fontSize());
143 font
.setItalic(settings
->italicFont());
144 font
.setBold(settings
->boldFont());
145 m_viewOptions
.font
= font
;
147 const int iconSize
= settings
->iconSize();
148 m_viewOptions
.decorationSize
= QSize(iconSize
, iconSize
);
150 m_viewOptions
.showDecorationSelected
= true;
152 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
153 setItemDelegate(delegate
);
157 connect(this, SIGNAL(entered(const QModelIndex
&)),
158 m_view
->m_controller
, SLOT(emitItemEntered(const QModelIndex
&)));
159 connect(this, SIGNAL(viewportEntered()),
160 m_view
->m_controller
, SLOT(emitViewportEntered()));
163 ColumnWidget::~ColumnWidget()
167 void ColumnWidget::setDecorationSize(const QSize
& size
)
169 m_viewOptions
.decorationSize
= size
;
173 void ColumnWidget::setActive(bool active
)
175 if (m_active
== active
) {
188 inline bool ColumnWidget::isActive() const
193 inline void ColumnWidget::setChildUrl(const KUrl
& url
)
198 inline const KUrl
& ColumnWidget::childUrl() const
203 inline void ColumnWidget::setUrl(const KUrl
& url
)
208 inline const KUrl
& ColumnWidget::url() const
213 inline QStyleOptionViewItem
ColumnWidget::viewOptions() const
215 return m_viewOptions
;
218 void ColumnWidget::dragEnterEvent(QDragEnterEvent
* event
)
220 if (event
->mimeData()->hasUrls()) {
221 event
->acceptProposedAction();
227 void ColumnWidget::dragLeaveEvent(QDragLeaveEvent
* event
)
229 QListView::dragLeaveEvent(event
);
231 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
233 setDirtyRegion(m_dropRect
);
236 void ColumnWidget::dragMoveEvent(QDragMoveEvent
* event
)
238 QListView::dragMoveEvent(event
);
240 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
241 const QModelIndex index
= indexAt(event
->pos());
242 setDirtyRegion(m_dropRect
);
243 m_dropRect
= visualRect(index
);
244 setDirtyRegion(m_dropRect
);
247 void ColumnWidget::dropEvent(QDropEvent
* event
)
249 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
250 if (!urls
.isEmpty()) {
251 event
->acceptProposedAction();
252 m_view
->m_controller
->indicateDroppedUrls(urls
,
254 indexAt(event
->pos()),
257 QListView::dropEvent(event
);
261 void ColumnWidget::paintEvent(QPaintEvent
* event
)
263 if (!m_childUrl
.isEmpty()) {
264 // indicate the shown URL of the next column by highlighting the shown folder item
265 const QModelIndex dirIndex
= m_view
->m_dolphinModel
->indexForUrl(m_childUrl
);
266 const QModelIndex proxyIndex
= m_view
->m_proxyModel
->mapFromSource(dirIndex
);
267 if (proxyIndex
.isValid() && !selectionModel()->isSelected(proxyIndex
)) {
268 const QRect itemRect
= visualRect(proxyIndex
);
269 QPainter
painter(viewport());
272 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).foreground().color();
274 painter
.setPen(Qt::NoPen
);
275 painter
.setBrush(color
);
276 painter
.drawRect(itemRect
);
282 QListView::paintEvent(event
);
284 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
286 const QBrush
& brush
= m_viewOptions
.palette
.brush(QPalette::Normal
, QPalette::Highlight
);
287 DolphinController::drawHoverIndication(viewport(), m_dropRect
, brush
);
291 void ColumnWidget::mousePressEvent(QMouseEvent
* event
)
294 m_view
->requestActivation(this);
297 QListView::mousePressEvent(event
);
300 void ColumnWidget::keyPressEvent(QKeyEvent
* event
)
302 QListView::keyPressEvent(event
);
304 const QItemSelectionModel
* selModel
= selectionModel();
305 const QModelIndex currentIndex
= selModel
->currentIndex();
306 const bool triggerItem
= currentIndex
.isValid()
307 && (event
->key() == Qt::Key_Return
)
308 && (selModel
->selectedIndexes().count() <= 1);
310 m_view
->m_controller
->triggerItem(currentIndex
);
314 void ColumnWidget::contextMenuEvent(QContextMenuEvent
* event
)
317 m_view
->requestActivation(this);
320 QListView::contextMenuEvent(event
);
322 const QModelIndex index
= indexAt(event
->pos());
323 if (index
.isValid() || m_active
) {
324 // Only open a context menu above an item or if the mouse is above
325 // the active column.
326 const QPoint pos
= m_view
->viewport()->mapFromGlobal(event
->globalPos());
327 m_view
->m_controller
->triggerContextMenuRequest(pos
);
331 void ColumnWidget::selectionChanged(const QItemSelection
& selected
, const QItemSelection
& deselected
)
333 QListView::selectionChanged(selected
, deselected
);
335 QItemSelectionModel
* selModel
= m_view
->selectionModel();
336 selModel
->select(selected
, QItemSelectionModel::Select
);
337 selModel
->select(deselected
, QItemSelectionModel::Deselect
);
340 void ColumnWidget::activate()
342 if (m_view
->hasFocus()) {
343 setFocus(Qt::OtherFocusReason
);
345 m_view
->setFocusProxy(this);
347 // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
348 // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
349 // necessary connecting the signal 'singleClick()' or 'doubleClick'.
350 if (KGlobalSettings::singleClick()) {
351 connect(this, SIGNAL(clicked(const QModelIndex
&)),
352 m_view
->m_controller
, SLOT(triggerItem(const QModelIndex
&)));
354 connect(this, SIGNAL(doubleClicked(const QModelIndex
&)),
355 m_view
->m_controller
, SLOT(triggerItem(const QModelIndex
&)));
358 const QColor bgColor
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
359 QPalette palette
= viewport()->palette();
360 palette
.setColor(viewport()->backgroundRole(), bgColor
);
361 viewport()->setPalette(palette
);
363 if (!m_childUrl
.isEmpty()) {
364 // assure that the current index is set on the index that represents
366 const QModelIndex dirIndex
= m_view
->m_dolphinModel
->indexForUrl(m_childUrl
);
367 const QModelIndex proxyIndex
= m_view
->m_proxyModel
->mapFromSource(dirIndex
);
368 selectionModel()->setCurrentIndex(proxyIndex
, QItemSelectionModel::Current
);
374 void ColumnWidget::deactivate()
376 // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
377 // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
378 // necessary connecting the signal 'singleClick()' or 'doubleClick'.
379 if (KGlobalSettings::singleClick()) {
380 disconnect(this, SIGNAL(clicked(const QModelIndex
&)),
381 m_view
->m_controller
, SLOT(triggerItem(const QModelIndex
&)));
383 disconnect(this, SIGNAL(doubleClicked(const QModelIndex
&)),
384 m_view
->m_controller
, SLOT(triggerItem(const QModelIndex
&)));
387 const QPalette palette
= m_view
->viewport()->palette();
388 viewport()->setPalette(palette
);
390 selectionModel()->clear();
396 DolphinColumnView::DolphinColumnView(QWidget
* parent
, DolphinController
* controller
) :
397 QAbstractItemView(parent
),
398 m_controller(controller
),
399 m_restoreActiveColumnFocus(false),
407 Q_ASSERT(controller
!= 0);
409 setAcceptDrops(true);
410 setDragDropMode(QAbstractItemView::DragDrop
);
411 setDropIndicatorShown(false);
412 setSelectionMode(ExtendedSelection
);
414 connect(this, SIGNAL(entered(const QModelIndex
&)),
415 controller
, SLOT(emitItemEntered(const QModelIndex
&)));
416 connect(this, SIGNAL(viewportEntered()),
417 controller
, SLOT(emitViewportEntered()));
418 connect(controller
, SIGNAL(zoomIn()),
419 this, SLOT(zoomIn()));
420 connect(controller
, SIGNAL(zoomOut()),
421 this, SLOT(zoomOut()));
422 connect(controller
, SIGNAL(urlChanged(const KUrl
&)),
423 this, SLOT(showColumn(const KUrl
&)));
425 connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
426 this, SLOT(moveContentHorizontally(int)));
428 m_animation
= new QTimeLine(500, this);
429 connect(m_animation
, SIGNAL(frameChanged(int)), horizontalScrollBar(), SLOT(setValue(int)));
431 ColumnWidget
* column
= new ColumnWidget(viewport(), this, m_controller
->url());
432 m_columns
.append(column
);
433 setActiveColumnIndex(0);
435 updateDecorationSize();
437 // dim the background of the viewport
438 QColor bgColor
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
439 const QColor fgColor
= KColorScheme(QPalette::Active
, KColorScheme::View
).foreground().color();
440 bgColor
= KColorUtils::mix(bgColor
, fgColor
, 0.04);
442 QPalette palette
= viewport()->palette();
443 palette
.setColor(viewport()->backgroundRole(), bgColor
);
444 viewport()->setPalette(palette
);
447 DolphinColumnView::~DolphinColumnView()
451 QModelIndex
DolphinColumnView::indexAt(const QPoint
& point
) const
453 foreach (ColumnWidget
* column
, m_columns
) {
454 const QPoint topLeft
= column
->frameGeometry().topLeft();
455 const QPoint
adjustedPoint(point
.x() - topLeft
.x(), point
.y() - topLeft
.y());
456 const QModelIndex index
= column
->indexAt(adjustedPoint
);
457 if (index
.isValid()) {
462 return QModelIndex();
465 void DolphinColumnView::scrollTo(const QModelIndex
& index
, ScrollHint hint
)
467 activeColumn()->scrollTo(index
, hint
);
470 QRect
DolphinColumnView::visualRect(const QModelIndex
& index
) const
472 return activeColumn()->visualRect(index
);
475 void DolphinColumnView::setModel(QAbstractItemModel
* model
)
477 if (m_dolphinModel
!= 0) {
478 m_dolphinModel
->disconnect(this);
481 m_proxyModel
= static_cast<QAbstractProxyModel
*>(model
);
482 m_dolphinModel
= static_cast<DolphinModel
*>(m_proxyModel
->sourceModel());
483 connect(m_dolphinModel
, SIGNAL(expand(const QModelIndex
&)),
484 this, SLOT(triggerReloadColumns(const QModelIndex
&)));
486 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
487 connect(dirLister
, SIGNAL(completed()),
488 this, SLOT(triggerExpandToActiveUrl()));
490 activeColumn()->setModel(model
);
491 QAbstractItemView::setModel(model
);
494 void DolphinColumnView::invertSelection()
496 // TODO: this approach of inverting the selection is quite slow. It should
497 // be possible to speedup the implementation by using QItemSelection, but
498 // all adempts have failed yet...
500 ColumnWidget
* column
= activeColumn();
501 QItemSelectionModel
* selModel
= column
->selectionModel();
503 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
504 const KFileItemList list
= dirLister
->itemsForDir(column
->url());
505 foreach (const KFileItem item
, list
) {
506 const QModelIndex index
= m_dolphinModel
->indexForUrl(item
.url());
507 selModel
->select(m_proxyModel
->mapFromSource(index
), QItemSelectionModel::Toggle
);
511 void DolphinColumnView::reload()
513 // Due to the reloading of the model all columns will be reset to show
514 // the same content as the first column. As this is not wanted, all columns
515 // except of the first column are temporary hidden until the root index can
517 m_restoreActiveColumnFocus
= false;
518 QList
<ColumnWidget
*>::iterator start
= m_columns
.begin() + 1;
519 QList
<ColumnWidget
*>::iterator end
= m_columns
.end();
520 for (QList
<ColumnWidget
*>::iterator it
= start
; it
!= end
; ++it
) {
521 ColumnWidget
* column
= (*it
);
522 if (column
->isActive() && column
->hasFocus()) {
523 // because of hiding the column, it will lose the focus
524 // -> remember that the focus should be restored after reloading
525 m_restoreActiveColumnFocus
= true;
530 // all columns are hidden, now reload the directory lister
531 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
532 const KUrl
& rootUrl
= m_columns
[0]->url();
533 dirLister
->openUrl(rootUrl
, KDirLister::Reload
);
537 void DolphinColumnView::showColumn(const KUrl
& url
)
539 const KUrl
& rootUrl
= m_columns
[0]->url();
540 if (!rootUrl
.isParentOf(url
)) {
541 // the URL is no child URL of the column view, hence clear all columns
542 // and reset the root column
543 QList
<ColumnWidget
*>::iterator start
= m_columns
.begin() + 1;
544 QList
<ColumnWidget
*>::iterator end
= m_columns
.end();
545 for (QList
<ColumnWidget
*>::iterator it
= start
; it
!= end
; ++it
) {
546 (*it
)->deleteLater();
548 m_columns
.erase(start
, end
);
550 m_columns
[0]->setActive(true);
551 m_columns
[0]->setUrl(url
);
552 assureVisibleActiveColumn();
556 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
557 const KUrl dirListerUrl
= dirLister
->url();
558 if (dirListerUrl
!= rootUrl
) {
559 // It is possible that root URL of the directory lister is adjusted
560 // after creating the column widget (e. g. when restoring the history
561 // having a different root URL than the controller indicates).
562 m_columns
[0]->setUrl(dirListerUrl
);
566 foreach (ColumnWidget
* column
, m_columns
) {
567 if (column
->url() == url
) {
568 // the column represents already the requested URL, hence activate it
569 requestActivation(column
);
571 } else if (!column
->url().isParentOf(url
)) {
572 // the column is no parent of the requested URL, hence
573 // just delete all remaining columns
574 if (columnIndex
> 0) {
575 QList
<ColumnWidget
*>::iterator start
= m_columns
.begin() + columnIndex
;
576 QList
<ColumnWidget
*>::iterator end
= m_columns
.end();
577 for (QList
<ColumnWidget
*>::iterator it
= start
; it
!= end
; ++it
) {
578 (*it
)->deleteLater();
580 m_columns
.erase(start
, end
);
582 const int maxIndex
= m_columns
.count() - 1;
583 Q_ASSERT(maxIndex
>= 0);
584 if (m_index
> maxIndex
) {
593 // Create missing columns. Assuming that the path is "/home/peter/Temp/" and
594 // the target path is "/home/peter/Temp/a/b/c/", then the columns "a", "b" and
595 // "c" will be created.
596 const int lastIndex
= m_columns
.count() - 1;
597 Q_ASSERT(lastIndex
>= 0);
599 const KUrl
& activeUrl
= m_columns
[lastIndex
]->url();
600 Q_ASSERT(activeUrl
.isParentOf(url
));
601 Q_ASSERT(activeUrl
!= url
);
603 QString path
= activeUrl
.url(KUrl::AddTrailingSlash
);
604 const QString targetPath
= url
.url(KUrl::AddTrailingSlash
);
606 columnIndex
= lastIndex
;
607 int slashIndex
= path
.count('/');
608 bool hasSubPath
= (slashIndex
>= 0);
610 const QString subPath
= targetPath
.section('/', slashIndex
, slashIndex
);
611 if (subPath
.isEmpty()) {
614 path
+= subPath
+ '/';
617 const KUrl childUrl
= KUrl(path
);
618 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(KUrl(path
));
619 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
621 m_columns
[columnIndex
]->setChildUrl(childUrl
);
624 ColumnWidget
* column
= new ColumnWidget(viewport(), this, childUrl
);
625 column
->setModel(model());
626 column
->setRootIndex(proxyIndex
);
627 column
->setActive(false);
629 m_columns
.append(column
);
631 // Before invoking layoutColumns() the column must be set visible temporary.
632 // To prevent a flickering the initial geometry is set to a hidden position.
633 column
->setGeometry(QRect(-1, -1, 1, 1));
638 // the layout is finished, now let the column be invisible until it
639 // gets a valid root index due to expandToActiveUrl()
644 // set the last column as active column without modifying the controller
645 // and hence the history
646 activeColumn()->setActive(false);
647 m_index
= columnIndex
;
648 activeColumn()->setActive(true);
649 assureVisibleActiveColumn();
652 void DolphinColumnView::selectAll()
654 activeColumn()->selectAll();
657 bool DolphinColumnView::isIndexHidden(const QModelIndex
& index
) const
660 return false;//activeColumn()->isIndexHidden(index);
663 QModelIndex
DolphinColumnView::moveCursor(CursorAction cursorAction
, Qt::KeyboardModifiers modifiers
)
665 // Parts of this code have been taken from QColumnView::moveCursor().
666 // Copyright (C) 1992-2007 Trolltech ASA.
670 return QModelIndex();
673 const QModelIndex current
= currentIndex();
674 if (isRightToLeft()) {
675 if (cursorAction
== MoveLeft
) {
676 cursorAction
= MoveRight
;
677 } else if (cursorAction
== MoveRight
) {
678 cursorAction
= MoveLeft
;
682 switch (cursorAction
) {
685 setActiveColumnIndex(m_index
- 1);
690 if (m_index
< m_columns
.count() - 1) {
691 setActiveColumnIndex(m_index
+ 1);
699 return QModelIndex();
702 void DolphinColumnView::setSelection(const QRect
& rect
, QItemSelectionModel::SelectionFlags flags
)
706 //activeColumn()->setSelection(rect, flags);
709 QRegion
DolphinColumnView::visualRegionForSelection(const QItemSelection
& selection
) const
712 return QRegion(); //activeColumn()->visualRegionForSelection(selection);
715 int DolphinColumnView::horizontalOffset() const
720 int DolphinColumnView::verticalOffset() const
725 void DolphinColumnView::mousePressEvent(QMouseEvent
* event
)
727 m_controller
->triggerActivation();
728 QAbstractItemView::mousePressEvent(event
);
731 void DolphinColumnView::resizeEvent(QResizeEvent
* event
)
733 QAbstractItemView::resizeEvent(event
);
738 void DolphinColumnView::zoomIn()
740 if (isZoomInPossible()) {
741 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
742 switch (settings
->iconSize()) {
743 case KIconLoader::SizeSmall
: settings
->setIconSize(KIconLoader::SizeMedium
); break;
744 case KIconLoader::SizeMedium
: settings
->setIconSize(KIconLoader::SizeLarge
); break;
745 default: Q_ASSERT(false); break;
747 updateDecorationSize();
751 void DolphinColumnView::zoomOut()
753 if (isZoomOutPossible()) {
754 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
755 switch (settings
->iconSize()) {
756 case KIconLoader::SizeLarge
: settings
->setIconSize(KIconLoader::SizeMedium
); break;
757 case KIconLoader::SizeMedium
: settings
->setIconSize(KIconLoader::SizeSmall
); break;
758 default: Q_ASSERT(false); break;
760 updateDecorationSize();
764 void DolphinColumnView::moveContentHorizontally(int x
)
766 m_contentX
= isRightToLeft() ? +x
: -x
;
770 void DolphinColumnView::updateDecorationSize()
772 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
773 const int iconSize
= settings
->iconSize();
775 foreach (QObject
* object
, viewport()->children()) {
776 if (object
->inherits("QListView")) {
777 ColumnWidget
* widget
= static_cast<ColumnWidget
*>(object
);
778 widget
->setDecorationSize(QSize(iconSize
, iconSize
));
782 m_controller
->setZoomInPossible(isZoomInPossible());
783 m_controller
->setZoomOutPossible(isZoomOutPossible());
788 void DolphinColumnView::expandToActiveUrl()
790 const int lastIndex
= m_columns
.count() - 1;
791 Q_ASSERT(lastIndex
>= 0);
792 const KUrl
& activeUrl
= m_columns
[lastIndex
]->url();
793 const KUrl rootUrl
= m_dolphinModel
->dirLister()->url();
794 const bool expand
= rootUrl
.isParentOf(activeUrl
)
795 && !rootUrl
.equals(activeUrl
, KUrl::CompareWithoutTrailingSlash
);
797 m_dolphinModel
->expandToUrl(activeUrl
);
802 void DolphinColumnView::triggerUpdateColumns(const QModelIndex
& index
)
805 // the updating of the columns may not be done in the context of this slot
806 QMetaObject::invokeMethod(this, "updateColumns", Qt::QueuedConnection
);
809 void DolphinColumnView::updateColumns()
811 const int end
= m_columns
.count() - 2; // next to last column
812 for (int i
= 0; i
<= end
; ++i
) {
813 ColumnWidget
* nextColumn
= m_columns
[i
+ 1];
814 const QModelIndex rootIndex
= nextColumn
->rootIndex();
815 if (rootIndex
.isValid()) {
818 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(m_columns
[i
]->childUrl());
819 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
820 if (proxyIndex
.isValid()) {
821 nextColumn
->setRootIndex(proxyIndex
);
823 if (nextColumn
->isActive() && m_restoreActiveColumnFocus
) {
824 nextColumn
->setFocus();
825 m_restoreActiveColumnFocus
= false;
832 void DolphinColumnView::triggerExpandToActiveUrl()
834 QMetaObject::invokeMethod(this, "expandToActiveUrl", Qt::QueuedConnection
);
837 bool DolphinColumnView::isZoomInPossible() const
839 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
840 return settings
->iconSize() < KIconLoader::SizeLarge
;
843 bool DolphinColumnView::isZoomOutPossible() const
845 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
846 return settings
->iconSize() > KIconLoader::SizeSmall
;
849 void DolphinColumnView::setActiveColumnIndex(int index
)
851 if (m_index
== index
) {
855 const bool hasActiveColumn
= (m_index
>= 0);
856 if (hasActiveColumn
) {
857 m_columns
[m_index
]->setActive(false);
861 m_columns
[m_index
]->setActive(true);
863 m_controller
->setUrl(m_columns
[m_index
]->url());
865 assureVisibleActiveColumn();
868 void DolphinColumnView::layoutColumns()
870 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
871 const int columnWidth
= settings
->columnWidth();
872 if (isRightToLeft()) {
873 int x
= viewport()->width() - columnWidth
+ m_contentX
;
874 foreach (ColumnWidget
* column
, m_columns
) {
875 column
->setGeometry(QRect(x
, 0, columnWidth
, viewport()->height()));
880 foreach (ColumnWidget
* column
, m_columns
) {
881 column
->setGeometry(QRect(x
, 0, columnWidth
, viewport()->height()));
887 void DolphinColumnView::updateScrollBar()
889 int contentWidth
= 0;
890 foreach (ColumnWidget
* column
, m_columns
) {
891 contentWidth
+= column
->width();
894 horizontalScrollBar()->setPageStep(contentWidth
);
895 horizontalScrollBar()->setRange(0, contentWidth
- viewport()->width());
898 void DolphinColumnView::assureVisibleActiveColumn()
900 const int viewportWidth
= viewport()->width();
901 const int x
= activeColumn()->x();
902 const int width
= activeColumn()->width();
903 if (x
+ width
> viewportWidth
) {
904 const int newContentX
= m_contentX
- x
- width
+ viewportWidth
;
905 if (isRightToLeft()) {
906 m_animation
->setFrameRange(m_contentX
, newContentX
);
908 m_animation
->setFrameRange(-m_contentX
, -newContentX
);
910 m_animation
->start();
912 const int newContentX
= m_contentX
- x
;
913 if (isRightToLeft()) {
914 m_animation
->setFrameRange(m_contentX
, newContentX
);
916 m_animation
->setFrameRange(-m_contentX
, -newContentX
);
918 m_animation
->start();
922 void DolphinColumnView::requestActivation(ColumnWidget
* column
)
924 if (column
->isActive()) {
925 assureVisibleActiveColumn();
928 foreach (ColumnWidget
* currColumn
, m_columns
) {
929 if (currColumn
== column
) {
930 setActiveColumnIndex(index
);
938 #include "dolphincolumnview.moc"