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 setVerticalScrollMode(QAbstractItemView::ScrollPerPixel
);
121 setSelectionBehavior(SelectItems
);
122 setSelectionMode(QAbstractItemView::ExtendedSelection
);
123 setDragDropMode(QAbstractItemView::DragDrop
);
124 setDropIndicatorShown(false);
125 setFocusPolicy(Qt::NoFocus
);
127 // apply the column mode settings to the widget
128 const ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
129 Q_ASSERT(settings
!= 0);
131 m_viewOptions
= QListView::viewOptions();
133 QFont
font(settings
->fontFamily(), settings
->fontSize());
134 font
.setItalic(settings
->italicFont());
135 font
.setBold(settings
->boldFont());
136 m_viewOptions
.font
= font
;
138 const int iconSize
= settings
->iconSize();
139 m_viewOptions
.decorationSize
= QSize(iconSize
, iconSize
);
141 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
142 setItemDelegate(delegate
);
146 connect(this, SIGNAL(entered(const QModelIndex
&)),
147 m_view
->m_controller
, SLOT(emitItemEntered(const QModelIndex
&)));
148 connect(this, SIGNAL(viewportEntered()),
149 m_view
->m_controller
, SLOT(emitViewportEntered()));
152 ColumnWidget::~ColumnWidget()
156 void ColumnWidget::setDecorationSize(const QSize
& size
)
158 m_viewOptions
.decorationSize
= size
;
162 void ColumnWidget::setActive(bool active
)
164 if (m_active
== active
) {
177 inline bool ColumnWidget::isActive() const
182 inline void ColumnWidget::setChildUrl(const KUrl
& url
)
187 inline const KUrl
& ColumnWidget::childUrl() const
192 inline void ColumnWidget::setUrl(const KUrl
& url
)
197 const KUrl
& ColumnWidget::url() const
202 QStyleOptionViewItem
ColumnWidget::viewOptions() const
204 return m_viewOptions
;
207 void ColumnWidget::dragEnterEvent(QDragEnterEvent
* event
)
209 if (event
->mimeData()->hasUrls()) {
210 event
->acceptProposedAction();
216 void ColumnWidget::dragLeaveEvent(QDragLeaveEvent
* event
)
218 QListView::dragLeaveEvent(event
);
220 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
222 setDirtyRegion(m_dropRect
);
225 void ColumnWidget::dragMoveEvent(QDragMoveEvent
* event
)
227 QListView::dragMoveEvent(event
);
229 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
230 const QModelIndex index
= indexAt(event
->pos());
231 setDirtyRegion(m_dropRect
);
232 m_dropRect
= visualRect(index
);
233 setDirtyRegion(m_dropRect
);
236 void ColumnWidget::dropEvent(QDropEvent
* event
)
238 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
239 if (!urls
.isEmpty()) {
240 event
->acceptProposedAction();
241 m_view
->m_controller
->indicateDroppedUrls(urls
,
243 indexAt(event
->pos()),
246 QListView::dropEvent(event
);
250 void ColumnWidget::paintEvent(QPaintEvent
* event
)
252 if (!m_childUrl
.isEmpty()) {
253 // indicate the shown URL of the next column by highlighting the shown folder item
254 const QModelIndex dirIndex
= m_view
->m_dolphinModel
->indexForUrl(m_childUrl
);
255 const QModelIndex proxyIndex
= m_view
->m_proxyModel
->mapFromSource(dirIndex
);
256 if (proxyIndex
.isValid() && !selectionModel()->isSelected(proxyIndex
)) {
257 const QRect itemRect
= visualRect(proxyIndex
);
258 QPainter
painter(viewport());
261 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).foreground().color();
263 painter
.setPen(Qt::NoPen
);
264 painter
.setBrush(color
);
265 painter
.drawRect(itemRect
);
271 QListView::paintEvent(event
);
273 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
275 const QBrush
& brush
= m_viewOptions
.palette
.brush(QPalette::Normal
, QPalette::Highlight
);
276 DolphinController::drawHoverIndication(viewport(), m_dropRect
, brush
);
280 void ColumnWidget::mousePressEvent(QMouseEvent
* event
)
283 m_view
->requestActivation(this);
286 QListView::mousePressEvent(event
);
289 void ColumnWidget::keyPressEvent(QKeyEvent
* event
)
291 QListView::keyPressEvent(event
);
293 const QItemSelectionModel
* selModel
= selectionModel();
294 const QModelIndex currentIndex
= selModel
->currentIndex();
295 const bool triggerItem
= currentIndex
.isValid()
296 && (event
->key() == Qt::Key_Return
)
297 && (selModel
->selectedIndexes().count() <= 1);
299 m_view
->m_controller
->triggerItem(currentIndex
);
303 void ColumnWidget::contextMenuEvent(QContextMenuEvent
* event
)
306 m_view
->requestActivation(this);
309 QListView::contextMenuEvent(event
);
311 const QModelIndex index
= indexAt(event
->pos());
312 if (index
.isValid() || m_active
) {
313 // Only open a context menu above an item or if the mouse is above
314 // the active column.
315 const QPoint pos
= m_view
->viewport()->mapFromGlobal(event
->globalPos());
316 m_view
->m_controller
->triggerContextMenuRequest(pos
);
320 void ColumnWidget::selectionChanged(const QItemSelection
& selected
, const QItemSelection
& deselected
)
322 QListView::selectionChanged(selected
, deselected
);
324 QItemSelectionModel
* selModel
= m_view
->selectionModel();
325 selModel
->select(selected
, QItemSelectionModel::Select
);
326 selModel
->select(deselected
, QItemSelectionModel::Deselect
);
329 void ColumnWidget::activate()
331 if (m_view
->hasFocus()) {
332 setFocus(Qt::OtherFocusReason
);
334 m_view
->setFocusProxy(this);
336 // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
337 // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
338 // necessary connecting the signal 'singleClick()' or 'doubleClick'.
339 if (KGlobalSettings::singleClick()) {
340 connect(this, SIGNAL(clicked(const QModelIndex
&)),
341 m_view
->m_controller
, SLOT(triggerItem(const QModelIndex
&)));
343 connect(this, SIGNAL(doubleClicked(const QModelIndex
&)),
344 m_view
->m_controller
, SLOT(triggerItem(const QModelIndex
&)));
347 const QColor bgColor
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
348 QPalette palette
= viewport()->palette();
349 palette
.setColor(viewport()->backgroundRole(), bgColor
);
350 viewport()->setPalette(palette
);
352 if (!m_childUrl
.isEmpty()) {
353 // assure that the current index is set on the index that represents
355 const QModelIndex dirIndex
= m_view
->m_dolphinModel
->indexForUrl(m_childUrl
);
356 const QModelIndex proxyIndex
= m_view
->m_proxyModel
->mapFromSource(dirIndex
);
357 selectionModel()->setCurrentIndex(proxyIndex
, QItemSelectionModel::Current
);
363 void ColumnWidget::deactivate()
365 // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
366 // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
367 // necessary connecting the signal 'singleClick()' or 'doubleClick'.
368 if (KGlobalSettings::singleClick()) {
369 disconnect(this, SIGNAL(clicked(const QModelIndex
&)),
370 m_view
->m_controller
, SLOT(triggerItem(const QModelIndex
&)));
372 disconnect(this, SIGNAL(doubleClicked(const QModelIndex
&)),
373 m_view
->m_controller
, SLOT(triggerItem(const QModelIndex
&)));
376 const QPalette palette
= m_view
->viewport()->palette();
377 viewport()->setPalette(palette
);
379 selectionModel()->clear();
385 DolphinColumnView::DolphinColumnView(QWidget
* parent
, DolphinController
* controller
) :
386 QAbstractItemView(parent
),
387 m_controller(controller
),
388 m_restoreActiveColumnFocus(false),
396 Q_ASSERT(controller
!= 0);
398 setAcceptDrops(true);
399 setDragDropMode(QAbstractItemView::DragDrop
);
400 setDropIndicatorShown(false);
401 setSelectionMode(ExtendedSelection
);
403 connect(this, SIGNAL(entered(const QModelIndex
&)),
404 controller
, SLOT(emitItemEntered(const QModelIndex
&)));
405 connect(this, SIGNAL(viewportEntered()),
406 controller
, SLOT(emitViewportEntered()));
407 connect(controller
, SIGNAL(zoomIn()),
408 this, SLOT(zoomIn()));
409 connect(controller
, SIGNAL(zoomOut()),
410 this, SLOT(zoomOut()));
411 connect(controller
, SIGNAL(urlChanged(const KUrl
&)),
412 this, SLOT(showColumn(const KUrl
&)));
414 connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
415 this, SLOT(moveContentHorizontally(int)));
417 ColumnWidget
* column
= new ColumnWidget(viewport(), this, m_controller
->url());
418 m_columns
.append(column
);
419 setActiveColumnIndex(0);
421 updateDecorationSize();
423 m_animation
= new QTimeLine(500, this);
424 connect(m_animation
, SIGNAL(frameChanged(int)), horizontalScrollBar(), SLOT(setValue(int)));
426 // dim the background of the viewport
427 QColor bgColor
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
428 const QColor fgColor
= KColorScheme(QPalette::Active
, KColorScheme::View
).foreground().color();
429 bgColor
= KColorUtils::mix(bgColor
, fgColor
, 0.04);
431 QPalette palette
= viewport()->palette();
432 palette
.setColor(viewport()->backgroundRole(), bgColor
);
433 viewport()->setPalette(palette
);
436 DolphinColumnView::~DolphinColumnView()
440 QModelIndex
DolphinColumnView::indexAt(const QPoint
& point
) const
442 foreach (ColumnWidget
* column
, m_columns
) {
443 const QPoint topLeft
= column
->frameGeometry().topLeft();
444 const QPoint
adjustedPoint(point
.x() - topLeft
.x(), point
.y() - topLeft
.y());
445 const QModelIndex index
= column
->indexAt(adjustedPoint
);
446 if (index
.isValid()) {
451 return QModelIndex();
454 void DolphinColumnView::scrollTo(const QModelIndex
& index
, ScrollHint hint
)
456 activeColumn()->scrollTo(index
, hint
);
459 QRect
DolphinColumnView::visualRect(const QModelIndex
& index
) const
461 return activeColumn()->visualRect(index
);
464 void DolphinColumnView::setModel(QAbstractItemModel
* model
)
466 if (m_dolphinModel
!= 0) {
467 m_dolphinModel
->disconnect(this);
470 m_proxyModel
= static_cast<QAbstractProxyModel
*>(model
);
471 m_dolphinModel
= static_cast<DolphinModel
*>(m_proxyModel
->sourceModel());
472 connect(m_dolphinModel
, SIGNAL(expand(const QModelIndex
&)),
473 this, SLOT(triggerReloadColumns(const QModelIndex
&)));
475 activeColumn()->setModel(model
);
476 QAbstractItemView::setModel(model
);
479 void DolphinColumnView::reload()
481 // Due to the reloading of the model all columns will be reset to show
482 // the same content as the first column. As this is not wanted, all columns
483 // except of the first column are temporary hidden until the root index can
485 m_restoreActiveColumnFocus
= false;
486 QList
<ColumnWidget
*>::iterator start
= m_columns
.begin() + 1;
487 QList
<ColumnWidget
*>::iterator end
= m_columns
.end();
488 for (QList
<ColumnWidget
*>::iterator it
= start
; it
!= end
; ++it
) {
489 ColumnWidget
* column
= (*it
);
490 if (column
->isActive() && column
->hasFocus()) {
491 // because of hiding the column, it will lose the focus
492 // -> remember that the focus should be restored after reloading
493 m_restoreActiveColumnFocus
= true;
498 // all columns are hidden, now reload the directory lister
499 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
500 connect(dirLister
, SIGNAL(completed()),
501 this, SLOT(expandToActiveUrl()));
502 const KUrl rootUrl
= m_columns
[0]->url();
503 dirLister
->openUrl(rootUrl
, false, true);
506 void DolphinColumnView::invertSelection()
508 // TODO: this approach of inverting the selection is quite slow. It should
509 // be possible to speedup the implementation by using QItemSelection, but
510 // all adempts have failed yet...
512 ColumnWidget
* column
= activeColumn();
513 QItemSelectionModel
* selModel
= column
->selectionModel();
515 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
516 const KFileItemList list
= dirLister
->itemsForDir(column
->url());
517 foreach (KFileItem
* item
, list
) {
518 const QModelIndex index
= m_dolphinModel
->indexForUrl(item
->url());
519 selModel
->select(m_proxyModel
->mapFromSource(index
), QItemSelectionModel::Toggle
);
523 void DolphinColumnView::showColumn(const KUrl
& url
)
525 const KUrl
& rootUrl
= m_columns
[0]->url();
526 if (!rootUrl
.isParentOf(url
)) {
527 // the URL is no child URL of the column view, hence clear all columns
528 // and reset the root column
529 QList
<ColumnWidget
*>::iterator start
= m_columns
.begin() + 1;
530 QList
<ColumnWidget
*>::iterator end
= m_columns
.end();
531 for (QList
<ColumnWidget
*>::iterator it
= start
; it
!= end
; ++it
) {
532 (*it
)->deleteLater();
534 m_columns
.erase(start
, end
);
536 m_columns
[0]->setActive(true);
537 m_columns
[0]->setUrl(url
);
538 assureVisibleActiveColumn();
542 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
543 const KUrl dirListerUrl
= dirLister
->url();
544 if (dirListerUrl
!= rootUrl
) {
545 // It is possible that root URL of the directory lister is adjusted
546 // after creating the column widget (e. g. when restoring the history
547 // having a different root URL than the controller indicates).
548 m_columns
[0]->setUrl(dirListerUrl
);
552 foreach (ColumnWidget
* column
, m_columns
) {
553 if (column
->url() == url
) {
554 // the column represents already the requested URL, hence activate it
555 requestActivation(column
);
557 } else if (!column
->url().isParentOf(url
)) {
558 // the column is no parent of the requested URL, hence
559 // just delete all remaining columns
560 if (columnIndex
> 0) {
561 QList
<ColumnWidget
*>::iterator start
= m_columns
.begin() + columnIndex
;
562 QList
<ColumnWidget
*>::iterator end
= m_columns
.end();
563 for (QList
<ColumnWidget
*>::iterator it
= start
; it
!= end
; ++it
) {
564 (*it
)->deleteLater();
566 m_columns
.erase(start
, end
);
568 const int maxIndex
= m_columns
.count() - 1;
569 Q_ASSERT(maxIndex
>= 0);
570 if (m_index
> maxIndex
) {
579 // Create missing columns. Assuming that the path is "/home/peter/Temp/" and
580 // the target path is "/home/peter/Temp/a/b/c/", then the columns "a", "b" and
581 // "c" will be created.
582 const int lastIndex
= m_columns
.count() - 1;
583 Q_ASSERT(lastIndex
>= 0);
585 const KUrl
& activeUrl
= m_columns
[lastIndex
]->url();
586 Q_ASSERT(activeUrl
.isParentOf(url
));
587 Q_ASSERT(activeUrl
!= url
);
589 QString path
= activeUrl
.url(KUrl::AddTrailingSlash
);
590 const QString targetPath
= url
.url(KUrl::AddTrailingSlash
);
592 columnIndex
= lastIndex
;
593 int slashIndex
= path
.count('/');
594 bool hasSubPath
= (slashIndex
>= 0);
596 const QString subPath
= targetPath
.section('/', slashIndex
, slashIndex
);
597 if (subPath
.isEmpty()) {
600 path
+= subPath
+ '/';
603 const KUrl childUrl
= KUrl(path
);
604 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(KUrl(path
));
605 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
607 m_columns
[columnIndex
]->setChildUrl(childUrl
);
610 ColumnWidget
* column
= new ColumnWidget(viewport(), this, childUrl
);
611 column
->setVerticalScrollMode(ColumnWidget::ScrollPerPixel
);
612 column
->setHorizontalScrollMode(ColumnWidget::ScrollPerPixel
);
613 column
->setModel(model());
614 column
->setRootIndex(proxyIndex
);
615 column
->setActive(false);
617 m_columns
.append(column
);
619 // Before invoking layoutColumns() the column must be set visible temporary.
620 // To prevent a flickering the initial geometry is set to a hidden position.
621 column
->setGeometry(QRect(-1, -1, 1, 1));
626 // the layout is finished, now let the column be invisible until it
627 // gets a valid root index due to expandToActiveUrl()
632 // set the last column as active column without modifying the controller
633 // and hence the history
634 activeColumn()->setActive(false);
635 m_index
= columnIndex
;
636 activeColumn()->setActive(true);
638 connect(dirLister
, SIGNAL(completed()),
639 this, SLOT(expandToActiveUrl()));
640 dirLister
->openUrl(rootUrl
, false, true);
643 void DolphinColumnView::selectAll()
645 activeColumn()->selectAll();
648 bool DolphinColumnView::isIndexHidden(const QModelIndex
& index
) const
651 return false;//activeColumn()->isIndexHidden(index);
654 QModelIndex
DolphinColumnView::moveCursor(CursorAction cursorAction
, Qt::KeyboardModifiers modifiers
)
656 // Parts of this code have been taken from QColumnView::moveCursor().
657 // Copyright (C) 1992-2007 Trolltech ASA.
661 return QModelIndex();
664 const QModelIndex current
= currentIndex();
665 if (isRightToLeft()) {
666 if (cursorAction
== MoveLeft
) {
667 cursorAction
= MoveRight
;
668 } else if (cursorAction
== MoveRight
) {
669 cursorAction
= MoveLeft
;
673 switch (cursorAction
) {
676 setActiveColumnIndex(m_index
- 1);
681 if (m_index
< m_columns
.count() - 1) {
682 setActiveColumnIndex(m_index
+ 1);
690 return QModelIndex();
693 void DolphinColumnView::setSelection(const QRect
& rect
, QItemSelectionModel::SelectionFlags flags
)
697 //activeColumn()->setSelection(rect, flags);
700 QRegion
DolphinColumnView::visualRegionForSelection(const QItemSelection
& selection
) const
703 return QRegion(); //activeColumn()->visualRegionForSelection(selection);
706 int DolphinColumnView::horizontalOffset() const
711 int DolphinColumnView::verticalOffset() const
716 void DolphinColumnView::mousePressEvent(QMouseEvent
* event
)
718 m_controller
->triggerActivation();
719 QAbstractItemView::mousePressEvent(event
);
722 void DolphinColumnView::resizeEvent(QResizeEvent
* event
)
724 QAbstractItemView::resizeEvent(event
);
729 void DolphinColumnView::zoomIn()
731 if (isZoomInPossible()) {
732 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
733 // TODO: get rid of K3Icon sizes
734 switch (settings
->iconSize()) {
735 case K3Icon::SizeSmall
: settings
->setIconSize(K3Icon::SizeMedium
); break;
736 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeLarge
); break;
737 default: Q_ASSERT(false); break;
739 updateDecorationSize();
743 void DolphinColumnView::zoomOut()
745 if (isZoomOutPossible()) {
746 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
747 // TODO: get rid of K3Icon sizes
748 switch (settings
->iconSize()) {
749 case K3Icon::SizeLarge
: settings
->setIconSize(K3Icon::SizeMedium
); break;
750 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeSmall
); break;
751 default: Q_ASSERT(false); break;
753 updateDecorationSize();
757 void DolphinColumnView::moveContentHorizontally(int x
)
763 void DolphinColumnView::updateDecorationSize()
765 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
766 const int iconSize
= settings
->iconSize();
768 foreach (QObject
* object
, viewport()->children()) {
769 if (object
->inherits("QListView")) {
770 ColumnWidget
* widget
= static_cast<ColumnWidget
*>(object
);
771 widget
->setDecorationSize(QSize(iconSize
, iconSize
));
775 m_controller
->setZoomInPossible(isZoomInPossible());
776 m_controller
->setZoomOutPossible(isZoomOutPossible());
781 void DolphinColumnView::expandToActiveUrl()
783 disconnect(m_dolphinModel
->dirLister(), SIGNAL(completed()),
784 this, SLOT(expandToActiveUrl()));
786 const int lastIndex
= m_columns
.count() - 1;
787 Q_ASSERT(lastIndex
>= 0);
788 const KUrl
& activeUrl
= m_columns
[lastIndex
]->url();
789 const KUrl rootUrl
= m_dolphinModel
->dirLister()->url();
790 const bool expand
= rootUrl
.isParentOf(activeUrl
)
791 && !rootUrl
.equals(activeUrl
, KUrl::CompareWithoutTrailingSlash
);
793 m_dolphinModel
->expandToUrl(activeUrl
);
798 void DolphinColumnView::triggerReloadColumns(const QModelIndex
& index
)
801 // the reloading of the columns may not be done in the context of this slot
802 QMetaObject::invokeMethod(this, "reloadColumns", Qt::QueuedConnection
);
805 void DolphinColumnView::reloadColumns()
807 const int end
= m_columns
.count() - 2; // next to last column
808 for (int i
= 0; i
<= end
; ++i
) {
809 ColumnWidget
* nextColumn
= m_columns
[i
+ 1];
811 const QModelIndex rootIndex
= nextColumn
->rootIndex();
812 if (rootIndex
.isValid()) {
815 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(m_columns
[i
]->childUrl());
816 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
817 if (proxyIndex
.isValid()) {
818 nextColumn
->setRootIndex(proxyIndex
);
820 if (nextColumn
->isActive() && m_restoreActiveColumnFocus
) {
821 nextColumn
->setFocus();
822 m_restoreActiveColumnFocus
= false;
827 assureVisibleActiveColumn();
830 bool DolphinColumnView::isZoomInPossible() const
832 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
833 return settings
->iconSize() < K3Icon::SizeLarge
;
836 bool DolphinColumnView::isZoomOutPossible() const
838 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
839 return settings
->iconSize() > K3Icon::SizeSmall
;
842 void DolphinColumnView::setActiveColumnIndex(int index
)
844 if (m_index
== index
) {
848 const bool hasActiveColumn
= (m_index
>= 0);
849 if (hasActiveColumn
) {
850 m_columns
[m_index
]->setActive(false);
854 m_columns
[m_index
]->setActive(true);
856 m_controller
->setUrl(m_columns
[m_index
]->url());
859 void DolphinColumnView::layoutColumns()
862 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
863 const int columnWidth
= settings
->columnWidth();
864 foreach (ColumnWidget
* column
, m_columns
) {
865 column
->setGeometry(QRect(x
, 0, columnWidth
, viewport()->height()));
870 void DolphinColumnView::updateScrollBar()
872 int contentWidth
= 0;
873 foreach (ColumnWidget
* column
, m_columns
) {
874 contentWidth
+= column
->width();
877 horizontalScrollBar()->setPageStep(contentWidth
);
878 horizontalScrollBar()->setRange(0, contentWidth
- viewport()->width());
881 void DolphinColumnView::assureVisibleActiveColumn()
883 const int viewportWidth
= viewport()->width();
884 const int x
= activeColumn()->x();
885 const int width
= activeColumn()->width();
886 if (x
+ width
> viewportWidth
) {
887 int newContentX
= m_contentX
- x
- width
+ viewportWidth
;
888 if (newContentX
> 0) {
891 m_animation
->setFrameRange(-m_contentX
, -newContentX
);
892 m_animation
->start();
894 const int newContentX
= m_contentX
- x
;
895 m_animation
->setFrameRange(-m_contentX
, -newContentX
);
896 m_animation
->start();
900 void DolphinColumnView::requestActivation(ColumnWidget
* column
)
902 if (column
->isActive()) {
903 assureVisibleActiveColumn();
906 foreach (ColumnWidget
* currColumn
, m_columns
) {
907 if (currColumn
== column
) {
908 setActiveColumnIndex(index
);
909 assureVisibleActiveColumn();
917 #include "dolphincolumnview.moc"