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 inline 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 setVerticalScrollMode(QAbstractItemView::ScrollPerPixel
);
122 setSelectionBehavior(SelectItems
);
123 setSelectionMode(QAbstractItemView::ExtendedSelection
);
124 setDragDropMode(QAbstractItemView::DragDrop
);
125 setDropIndicatorShown(false);
126 setFocusPolicy(Qt::NoFocus
);
128 // apply the column mode settings to the widget
129 const ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
130 Q_ASSERT(settings
!= 0);
132 m_viewOptions
= QListView::viewOptions();
134 QFont
font(settings
->fontFamily(), settings
->fontSize());
135 font
.setItalic(settings
->italicFont());
136 font
.setBold(settings
->boldFont());
137 m_viewOptions
.font
= font
;
139 const int iconSize
= settings
->iconSize();
140 m_viewOptions
.decorationSize
= QSize(iconSize
, iconSize
);
142 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
143 setItemDelegate(delegate
);
147 connect(this, SIGNAL(entered(const QModelIndex
&)),
148 m_view
->m_controller
, SLOT(emitItemEntered(const QModelIndex
&)));
149 connect(this, SIGNAL(viewportEntered()),
150 m_view
->m_controller
, SLOT(emitViewportEntered()));
153 ColumnWidget::~ColumnWidget()
157 void ColumnWidget::setDecorationSize(const QSize
& size
)
159 m_viewOptions
.decorationSize
= size
;
163 void ColumnWidget::setActive(bool active
)
165 if (m_active
== active
) {
178 inline bool ColumnWidget::isActive() const
183 inline void ColumnWidget::setChildUrl(const KUrl
& url
)
188 inline const KUrl
& ColumnWidget::childUrl() const
193 inline void ColumnWidget::setUrl(const KUrl
& url
)
198 const KUrl
& ColumnWidget::url() const
203 QStyleOptionViewItem
ColumnWidget::viewOptions() const
205 return m_viewOptions
;
208 void ColumnWidget::dragEnterEvent(QDragEnterEvent
* event
)
210 if (event
->mimeData()->hasUrls()) {
211 event
->acceptProposedAction();
217 void ColumnWidget::dragLeaveEvent(QDragLeaveEvent
* event
)
219 QListView::dragLeaveEvent(event
);
221 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
223 setDirtyRegion(m_dropRect
);
226 void ColumnWidget::dragMoveEvent(QDragMoveEvent
* event
)
228 QListView::dragMoveEvent(event
);
230 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
231 const QModelIndex index
= indexAt(event
->pos());
232 setDirtyRegion(m_dropRect
);
233 m_dropRect
= visualRect(index
);
234 setDirtyRegion(m_dropRect
);
237 void ColumnWidget::dropEvent(QDropEvent
* event
)
239 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
240 if (!urls
.isEmpty()) {
241 event
->acceptProposedAction();
242 m_view
->m_controller
->indicateDroppedUrls(urls
,
244 indexAt(event
->pos()),
247 QListView::dropEvent(event
);
251 void ColumnWidget::paintEvent(QPaintEvent
* event
)
253 if (!m_childUrl
.isEmpty()) {
254 // indicate the shown URL of the next column by highlighting the shown folder item
255 const QModelIndex dirIndex
= m_view
->m_dolphinModel
->indexForUrl(m_childUrl
);
256 const QModelIndex proxyIndex
= m_view
->m_proxyModel
->mapFromSource(dirIndex
);
257 if (proxyIndex
.isValid() && !selectionModel()->isSelected(proxyIndex
)) {
258 const QRect itemRect
= visualRect(proxyIndex
);
259 QPainter
painter(viewport());
262 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).foreground().color();
264 painter
.setPen(Qt::NoPen
);
265 painter
.setBrush(color
);
266 painter
.drawRect(itemRect
);
272 QListView::paintEvent(event
);
274 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
276 const QBrush
& brush
= m_viewOptions
.palette
.brush(QPalette::Normal
, QPalette::Highlight
);
277 DolphinController::drawHoverIndication(viewport(), m_dropRect
, brush
);
281 void ColumnWidget::mousePressEvent(QMouseEvent
* event
)
284 m_view
->requestActivation(this);
287 QListView::mousePressEvent(event
);
290 void ColumnWidget::keyPressEvent(QKeyEvent
* event
)
292 QListView::keyPressEvent(event
);
294 const QItemSelectionModel
* selModel
= selectionModel();
295 const QModelIndex currentIndex
= selModel
->currentIndex();
296 const bool triggerItem
= currentIndex
.isValid()
297 && (event
->key() == Qt::Key_Return
)
298 && (selModel
->selectedIndexes().count() <= 1);
300 m_view
->m_controller
->triggerItem(currentIndex
);
304 void ColumnWidget::contextMenuEvent(QContextMenuEvent
* event
)
307 m_view
->requestActivation(this);
310 QListView::contextMenuEvent(event
);
312 const QModelIndex index
= indexAt(event
->pos());
313 if (index
.isValid() || m_active
) {
314 // Only open a context menu above an item or if the mouse is above
315 // the active column.
316 const QPoint pos
= m_view
->viewport()->mapFromGlobal(event
->globalPos());
317 m_view
->m_controller
->triggerContextMenuRequest(pos
);
321 void ColumnWidget::selectionChanged(const QItemSelection
& selected
, const QItemSelection
& deselected
)
323 QListView::selectionChanged(selected
, deselected
);
325 QItemSelectionModel
* selModel
= m_view
->selectionModel();
326 selModel
->select(selected
, QItemSelectionModel::Select
);
327 selModel
->select(deselected
, QItemSelectionModel::Deselect
);
330 void ColumnWidget::activate()
332 if (m_view
->hasFocus()) {
333 setFocus(Qt::OtherFocusReason
);
335 m_view
->setFocusProxy(this);
337 // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
338 // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
339 // necessary connecting the signal 'singleClick()' or 'doubleClick'.
340 if (KGlobalSettings::singleClick()) {
341 connect(this, SIGNAL(clicked(const QModelIndex
&)),
342 m_view
->m_controller
, SLOT(triggerItem(const QModelIndex
&)));
344 connect(this, SIGNAL(doubleClicked(const QModelIndex
&)),
345 m_view
->m_controller
, SLOT(triggerItem(const QModelIndex
&)));
348 const QColor bgColor
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
349 QPalette palette
= viewport()->palette();
350 palette
.setColor(viewport()->backgroundRole(), bgColor
);
351 viewport()->setPalette(palette
);
353 if (!m_childUrl
.isEmpty()) {
354 // assure that the current index is set on the index that represents
356 const QModelIndex dirIndex
= m_view
->m_dolphinModel
->indexForUrl(m_childUrl
);
357 const QModelIndex proxyIndex
= m_view
->m_proxyModel
->mapFromSource(dirIndex
);
358 selectionModel()->setCurrentIndex(proxyIndex
, QItemSelectionModel::Current
);
364 void ColumnWidget::deactivate()
366 // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
367 // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
368 // necessary connecting the signal 'singleClick()' or 'doubleClick'.
369 if (KGlobalSettings::singleClick()) {
370 disconnect(this, SIGNAL(clicked(const QModelIndex
&)),
371 m_view
->m_controller
, SLOT(triggerItem(const QModelIndex
&)));
373 disconnect(this, SIGNAL(doubleClicked(const QModelIndex
&)),
374 m_view
->m_controller
, SLOT(triggerItem(const QModelIndex
&)));
377 const QPalette palette
= m_view
->viewport()->palette();
378 viewport()->setPalette(palette
);
380 selectionModel()->clear();
386 DolphinColumnView::DolphinColumnView(QWidget
* parent
, DolphinController
* controller
) :
387 QAbstractItemView(parent
),
388 m_controller(controller
),
389 m_restoreActiveColumnFocus(false),
390 m_dirListerCompleted(false),
398 Q_ASSERT(controller
!= 0);
400 setAcceptDrops(true);
401 setDragDropMode(QAbstractItemView::DragDrop
);
402 setDropIndicatorShown(false);
403 setSelectionMode(ExtendedSelection
);
405 connect(this, SIGNAL(entered(const QModelIndex
&)),
406 controller
, SLOT(emitItemEntered(const QModelIndex
&)));
407 connect(this, SIGNAL(viewportEntered()),
408 controller
, SLOT(emitViewportEntered()));
409 connect(controller
, SIGNAL(zoomIn()),
410 this, SLOT(zoomIn()));
411 connect(controller
, SIGNAL(zoomOut()),
412 this, SLOT(zoomOut()));
413 connect(controller
, SIGNAL(urlChanged(const KUrl
&)),
414 this, SLOT(showColumn(const KUrl
&)));
416 connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
417 this, SLOT(moveContentHorizontally(int)));
419 ColumnWidget
* column
= new ColumnWidget(viewport(), this, m_controller
->url());
420 m_columns
.append(column
);
421 setActiveColumnIndex(0);
423 updateDecorationSize();
425 m_animation
= new QTimeLine(500, this);
426 connect(m_animation
, SIGNAL(frameChanged(int)), horizontalScrollBar(), SLOT(setValue(int)));
428 // dim the background of the viewport
429 QColor bgColor
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
430 const QColor fgColor
= KColorScheme(QPalette::Active
, KColorScheme::View
).foreground().color();
431 bgColor
= KColorUtils::mix(bgColor
, fgColor
, 0.04);
433 QPalette palette
= viewport()->palette();
434 palette
.setColor(viewport()->backgroundRole(), bgColor
);
435 viewport()->setPalette(palette
);
438 DolphinColumnView::~DolphinColumnView()
442 QModelIndex
DolphinColumnView::indexAt(const QPoint
& point
) const
444 foreach (ColumnWidget
* column
, m_columns
) {
445 const QPoint topLeft
= column
->frameGeometry().topLeft();
446 const QPoint
adjustedPoint(point
.x() - topLeft
.x(), point
.y() - topLeft
.y());
447 const QModelIndex index
= column
->indexAt(adjustedPoint
);
448 if (index
.isValid()) {
453 return QModelIndex();
456 void DolphinColumnView::scrollTo(const QModelIndex
& index
, ScrollHint hint
)
458 activeColumn()->scrollTo(index
, hint
);
461 QRect
DolphinColumnView::visualRect(const QModelIndex
& index
) const
463 return activeColumn()->visualRect(index
);
466 void DolphinColumnView::setModel(QAbstractItemModel
* model
)
468 if (m_dolphinModel
!= 0) {
469 m_dolphinModel
->disconnect(this);
472 m_proxyModel
= static_cast<QAbstractProxyModel
*>(model
);
473 m_dolphinModel
= static_cast<DolphinModel
*>(m_proxyModel
->sourceModel());
474 connect(m_dolphinModel
, SIGNAL(expand(const QModelIndex
&)),
475 this, SLOT(triggerReloadColumns(const QModelIndex
&)));
477 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
478 connect(dirLister
, SIGNAL(started(const KUrl
&)),
479 this, SLOT(slotDirListerStarted(const KUrl
&)));
480 connect(dirLister
, SIGNAL(completed()),
481 this, SLOT(slotDirListerCompleted()));
483 activeColumn()->setModel(model
);
484 QAbstractItemView::setModel(model
);
487 void DolphinColumnView::invertSelection()
489 // TODO: this approach of inverting the selection is quite slow. It should
490 // be possible to speedup the implementation by using QItemSelection, but
491 // all adempts have failed yet...
493 ColumnWidget
* column
= activeColumn();
494 QItemSelectionModel
* selModel
= column
->selectionModel();
496 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
497 const KFileItemList list
= dirLister
->itemsForDir(column
->url());
498 foreach (KFileItem
* item
, list
) {
499 const QModelIndex index
= m_dolphinModel
->indexForUrl(item
->url());
500 selModel
->select(m_proxyModel
->mapFromSource(index
), QItemSelectionModel::Toggle
);
504 void DolphinColumnView::reload()
506 // Due to the reloading of the model all columns will be reset to show
507 // the same content as the first column. As this is not wanted, all columns
508 // except of the first column are temporary hidden until the root index can
510 m_restoreActiveColumnFocus
= false;
511 QList
<ColumnWidget
*>::iterator start
= m_columns
.begin() + 1;
512 QList
<ColumnWidget
*>::iterator end
= m_columns
.end();
513 for (QList
<ColumnWidget
*>::iterator it
= start
; it
!= end
; ++it
) {
514 ColumnWidget
* column
= (*it
);
515 if (column
->isActive() && column
->hasFocus()) {
516 // because of hiding the column, it will lose the focus
517 // -> remember that the focus should be restored after reloading
518 m_restoreActiveColumnFocus
= true;
523 // all columns are hidden, now reload the directory lister
524 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
525 const KUrl
& rootUrl
= m_columns
[0]->url();
526 dirLister
->openUrl(rootUrl
, false, true);
530 void DolphinColumnView::showColumn(const KUrl
& url
)
532 const KUrl
& rootUrl
= m_columns
[0]->url();
533 if (!rootUrl
.isParentOf(url
)) {
534 // the URL is no child URL of the column view, hence clear all columns
535 // and reset the root column
536 QList
<ColumnWidget
*>::iterator start
= m_columns
.begin() + 1;
537 QList
<ColumnWidget
*>::iterator end
= m_columns
.end();
538 for (QList
<ColumnWidget
*>::iterator it
= start
; it
!= end
; ++it
) {
539 (*it
)->deleteLater();
541 m_columns
.erase(start
, end
);
543 m_columns
[0]->setActive(true);
544 m_columns
[0]->setUrl(url
);
545 assureVisibleActiveColumn();
549 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
550 const KUrl dirListerUrl
= dirLister
->url();
551 if (dirListerUrl
!= rootUrl
) {
552 // It is possible that root URL of the directory lister is adjusted
553 // after creating the column widget (e. g. when restoring the history
554 // having a different root URL than the controller indicates).
555 m_columns
[0]->setUrl(dirListerUrl
);
559 foreach (ColumnWidget
* column
, m_columns
) {
560 if (column
->url() == url
) {
561 // the column represents already the requested URL, hence activate it
562 requestActivation(column
);
564 } else if (!column
->url().isParentOf(url
)) {
565 // the column is no parent of the requested URL, hence
566 // just delete all remaining columns
567 if (columnIndex
> 0) {
568 QList
<ColumnWidget
*>::iterator start
= m_columns
.begin() + columnIndex
;
569 QList
<ColumnWidget
*>::iterator end
= m_columns
.end();
570 for (QList
<ColumnWidget
*>::iterator it
= start
; it
!= end
; ++it
) {
571 (*it
)->deleteLater();
573 m_columns
.erase(start
, end
);
575 const int maxIndex
= m_columns
.count() - 1;
576 Q_ASSERT(maxIndex
>= 0);
577 if (m_index
> maxIndex
) {
586 // Create missing columns. Assuming that the path is "/home/peter/Temp/" and
587 // the target path is "/home/peter/Temp/a/b/c/", then the columns "a", "b" and
588 // "c" will be created.
589 const int lastIndex
= m_columns
.count() - 1;
590 Q_ASSERT(lastIndex
>= 0);
592 const KUrl
& activeUrl
= m_columns
[lastIndex
]->url();
593 Q_ASSERT(activeUrl
.isParentOf(url
));
594 Q_ASSERT(activeUrl
!= url
);
596 QString path
= activeUrl
.url(KUrl::AddTrailingSlash
);
597 const QString targetPath
= url
.url(KUrl::AddTrailingSlash
);
599 columnIndex
= lastIndex
;
600 int slashIndex
= path
.count('/');
601 bool hasSubPath
= (slashIndex
>= 0);
603 const QString subPath
= targetPath
.section('/', slashIndex
, slashIndex
);
604 if (subPath
.isEmpty()) {
607 path
+= subPath
+ '/';
610 const KUrl childUrl
= KUrl(path
);
611 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(KUrl(path
));
612 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
614 m_columns
[columnIndex
]->setChildUrl(childUrl
);
617 ColumnWidget
* column
= new ColumnWidget(viewport(), this, childUrl
);
618 column
->setModel(model());
619 column
->setRootIndex(proxyIndex
);
620 column
->setActive(false);
622 m_columns
.append(column
);
624 // Before invoking layoutColumns() the column must be set visible temporary.
625 // To prevent a flickering the initial geometry is set to a hidden position.
626 column
->setGeometry(QRect(-1, -1, 1, 1));
631 // the layout is finished, now let the column be invisible until it
632 // gets a valid root index due to expandToActiveUrl()
637 // set the last column as active column without modifying the controller
638 // and hence the history
639 activeColumn()->setActive(false);
640 m_index
= columnIndex
;
641 activeColumn()->setActive(true);
644 void DolphinColumnView::selectAll()
646 activeColumn()->selectAll();
649 bool DolphinColumnView::isIndexHidden(const QModelIndex
& index
) const
652 return false;//activeColumn()->isIndexHidden(index);
655 QModelIndex
DolphinColumnView::moveCursor(CursorAction cursorAction
, Qt::KeyboardModifiers modifiers
)
657 // Parts of this code have been taken from QColumnView::moveCursor().
658 // Copyright (C) 1992-2007 Trolltech ASA.
662 return QModelIndex();
665 const QModelIndex current
= currentIndex();
666 if (isRightToLeft()) {
667 if (cursorAction
== MoveLeft
) {
668 cursorAction
= MoveRight
;
669 } else if (cursorAction
== MoveRight
) {
670 cursorAction
= MoveLeft
;
674 switch (cursorAction
) {
677 setActiveColumnIndex(m_index
- 1);
682 if (m_index
< m_columns
.count() - 1) {
683 setActiveColumnIndex(m_index
+ 1);
691 return QModelIndex();
694 void DolphinColumnView::setSelection(const QRect
& rect
, QItemSelectionModel::SelectionFlags flags
)
698 //activeColumn()->setSelection(rect, flags);
701 QRegion
DolphinColumnView::visualRegionForSelection(const QItemSelection
& selection
) const
704 return QRegion(); //activeColumn()->visualRegionForSelection(selection);
707 int DolphinColumnView::horizontalOffset() const
712 int DolphinColumnView::verticalOffset() const
717 void DolphinColumnView::mousePressEvent(QMouseEvent
* event
)
719 m_controller
->triggerActivation();
720 QAbstractItemView::mousePressEvent(event
);
723 void DolphinColumnView::resizeEvent(QResizeEvent
* event
)
725 QAbstractItemView::resizeEvent(event
);
730 void DolphinColumnView::zoomIn()
732 if (isZoomInPossible()) {
733 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
734 // TODO: get rid of K3Icon sizes
735 switch (settings
->iconSize()) {
736 case K3Icon::SizeSmall
: settings
->setIconSize(K3Icon::SizeMedium
); break;
737 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeLarge
); break;
738 default: Q_ASSERT(false); break;
740 updateDecorationSize();
744 void DolphinColumnView::zoomOut()
746 if (isZoomOutPossible()) {
747 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
748 // TODO: get rid of K3Icon sizes
749 switch (settings
->iconSize()) {
750 case K3Icon::SizeLarge
: settings
->setIconSize(K3Icon::SizeMedium
); break;
751 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeSmall
); break;
752 default: Q_ASSERT(false); break;
754 updateDecorationSize();
758 void DolphinColumnView::moveContentHorizontally(int x
)
764 void DolphinColumnView::updateDecorationSize()
766 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
767 const int iconSize
= settings
->iconSize();
769 foreach (QObject
* object
, viewport()->children()) {
770 if (object
->inherits("QListView")) {
771 ColumnWidget
* widget
= static_cast<ColumnWidget
*>(object
);
772 widget
->setDecorationSize(QSize(iconSize
, iconSize
));
776 m_controller
->setZoomInPossible(isZoomInPossible());
777 m_controller
->setZoomOutPossible(isZoomOutPossible());
782 void DolphinColumnView::expandToActiveUrl()
784 const int lastIndex
= m_columns
.count() - 1;
785 Q_ASSERT(lastIndex
>= 0);
786 const KUrl
& activeUrl
= m_columns
[lastIndex
]->url();
787 const KUrl rootUrl
= m_dolphinModel
->dirLister()->url();
788 const bool expand
= m_dirListerCompleted
789 && rootUrl
.isParentOf(activeUrl
)
790 && !rootUrl
.equals(activeUrl
, KUrl::CompareWithoutTrailingSlash
);
792 m_dolphinModel
->expandToUrl(activeUrl
);
797 void DolphinColumnView::triggerUpdateColumns(const QModelIndex
& index
)
800 // the updating of the columns may not be done in the context of this slot
801 QMetaObject::invokeMethod(this, "updateColumns", Qt::QueuedConnection
);
804 void DolphinColumnView::updateColumns()
806 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
807 foreach (ColumnWidget
* column
, m_columns
) {
808 dirLister
->updateDirectory(column
->url());
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;
830 assureVisibleActiveColumn();
833 void DolphinColumnView::slotDirListerStarted(const KUrl
& url
)
836 m_dirListerCompleted
= false;
839 void DolphinColumnView::slotDirListerCompleted()
841 m_dirListerCompleted
= true;
842 QMetaObject::invokeMethod(this, "expandToActiveUrl", Qt::QueuedConnection
);
845 bool DolphinColumnView::isZoomInPossible() const
847 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
848 return settings
->iconSize() < K3Icon::SizeLarge
;
851 bool DolphinColumnView::isZoomOutPossible() const
853 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
854 return settings
->iconSize() > K3Icon::SizeSmall
;
857 void DolphinColumnView::setActiveColumnIndex(int index
)
859 if (m_index
== index
) {
863 const bool hasActiveColumn
= (m_index
>= 0);
864 if (hasActiveColumn
) {
865 m_columns
[m_index
]->setActive(false);
869 m_columns
[m_index
]->setActive(true);
871 m_controller
->setUrl(m_columns
[m_index
]->url());
874 void DolphinColumnView::layoutColumns()
877 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
878 const int columnWidth
= settings
->columnWidth();
879 foreach (ColumnWidget
* column
, m_columns
) {
880 column
->setGeometry(QRect(x
, 0, columnWidth
, viewport()->height()));
885 void DolphinColumnView::updateScrollBar()
887 int contentWidth
= 0;
888 foreach (ColumnWidget
* column
, m_columns
) {
889 contentWidth
+= column
->width();
892 horizontalScrollBar()->setPageStep(contentWidth
);
893 horizontalScrollBar()->setRange(0, contentWidth
- viewport()->width());
896 void DolphinColumnView::assureVisibleActiveColumn()
898 const int viewportWidth
= viewport()->width();
899 const int x
= activeColumn()->x();
900 const int width
= activeColumn()->width();
901 if (x
+ width
> viewportWidth
) {
902 int newContentX
= m_contentX
- x
- width
+ viewportWidth
;
903 if (newContentX
> 0) {
906 m_animation
->setFrameRange(-m_contentX
, -newContentX
);
907 m_animation
->start();
909 const int newContentX
= m_contentX
- x
;
910 m_animation
->setFrameRange(-m_contentX
, -newContentX
);
911 m_animation
->start();
915 void DolphinColumnView::requestActivation(ColumnWidget
* column
)
917 if (column
->isActive()) {
918 assureVisibleActiveColumn();
921 foreach (ColumnWidget
* currColumn
, m_columns
) {
922 if (currColumn
== column
) {
923 setActiveColumnIndex(index
);
924 assureVisibleActiveColumn();
932 #include "dolphincolumnview.moc"