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 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 m_viewOptions
.showDecorationSelected
= true;
144 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
145 setItemDelegate(delegate
);
149 connect(this, SIGNAL(entered(const QModelIndex
&)),
150 m_view
->m_controller
, SLOT(emitItemEntered(const QModelIndex
&)));
151 connect(this, SIGNAL(viewportEntered()),
152 m_view
->m_controller
, SLOT(emitViewportEntered()));
155 ColumnWidget::~ColumnWidget()
159 void ColumnWidget::setDecorationSize(const QSize
& size
)
161 m_viewOptions
.decorationSize
= size
;
165 void ColumnWidget::setActive(bool active
)
167 if (m_active
== active
) {
180 inline bool ColumnWidget::isActive() const
185 inline void ColumnWidget::setChildUrl(const KUrl
& url
)
190 inline const KUrl
& ColumnWidget::childUrl() const
195 inline void ColumnWidget::setUrl(const KUrl
& url
)
200 inline const KUrl
& ColumnWidget::url() const
205 inline QStyleOptionViewItem
ColumnWidget::viewOptions() const
207 return m_viewOptions
;
210 void ColumnWidget::dragEnterEvent(QDragEnterEvent
* event
)
212 if (event
->mimeData()->hasUrls()) {
213 event
->acceptProposedAction();
219 void ColumnWidget::dragLeaveEvent(QDragLeaveEvent
* event
)
221 QListView::dragLeaveEvent(event
);
223 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
225 setDirtyRegion(m_dropRect
);
228 void ColumnWidget::dragMoveEvent(QDragMoveEvent
* event
)
230 QListView::dragMoveEvent(event
);
232 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
233 const QModelIndex index
= indexAt(event
->pos());
234 setDirtyRegion(m_dropRect
);
235 m_dropRect
= visualRect(index
);
236 setDirtyRegion(m_dropRect
);
239 void ColumnWidget::dropEvent(QDropEvent
* event
)
241 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
242 if (!urls
.isEmpty()) {
243 event
->acceptProposedAction();
244 m_view
->m_controller
->indicateDroppedUrls(urls
,
246 indexAt(event
->pos()),
249 QListView::dropEvent(event
);
253 void ColumnWidget::paintEvent(QPaintEvent
* event
)
255 if (!m_childUrl
.isEmpty()) {
256 // indicate the shown URL of the next column by highlighting the shown folder item
257 const QModelIndex dirIndex
= m_view
->m_dolphinModel
->indexForUrl(m_childUrl
);
258 const QModelIndex proxyIndex
= m_view
->m_proxyModel
->mapFromSource(dirIndex
);
259 if (proxyIndex
.isValid() && !selectionModel()->isSelected(proxyIndex
)) {
260 const QRect itemRect
= visualRect(proxyIndex
);
261 QPainter
painter(viewport());
264 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).foreground().color();
266 painter
.setPen(Qt::NoPen
);
267 painter
.setBrush(color
);
268 painter
.drawRect(itemRect
);
274 QListView::paintEvent(event
);
276 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
278 const QBrush
& brush
= m_viewOptions
.palette
.brush(QPalette::Normal
, QPalette::Highlight
);
279 DolphinController::drawHoverIndication(viewport(), m_dropRect
, brush
);
283 void ColumnWidget::mousePressEvent(QMouseEvent
* event
)
286 m_view
->requestActivation(this);
289 QListView::mousePressEvent(event
);
292 void ColumnWidget::keyPressEvent(QKeyEvent
* event
)
294 QListView::keyPressEvent(event
);
296 const QItemSelectionModel
* selModel
= selectionModel();
297 const QModelIndex currentIndex
= selModel
->currentIndex();
298 const bool triggerItem
= currentIndex
.isValid()
299 && (event
->key() == Qt::Key_Return
)
300 && (selModel
->selectedIndexes().count() <= 1);
302 m_view
->m_controller
->triggerItem(currentIndex
);
306 void ColumnWidget::contextMenuEvent(QContextMenuEvent
* event
)
309 m_view
->requestActivation(this);
312 QListView::contextMenuEvent(event
);
314 const QModelIndex index
= indexAt(event
->pos());
315 if (index
.isValid() || m_active
) {
316 // Only open a context menu above an item or if the mouse is above
317 // the active column.
318 const QPoint pos
= m_view
->viewport()->mapFromGlobal(event
->globalPos());
319 m_view
->m_controller
->triggerContextMenuRequest(pos
);
323 void ColumnWidget::selectionChanged(const QItemSelection
& selected
, const QItemSelection
& deselected
)
325 QListView::selectionChanged(selected
, deselected
);
327 QItemSelectionModel
* selModel
= m_view
->selectionModel();
328 selModel
->select(selected
, QItemSelectionModel::Select
);
329 selModel
->select(deselected
, QItemSelectionModel::Deselect
);
332 void ColumnWidget::activate()
334 if (m_view
->hasFocus()) {
335 setFocus(Qt::OtherFocusReason
);
337 m_view
->setFocusProxy(this);
339 // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
340 // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
341 // necessary connecting the signal 'singleClick()' or 'doubleClick'.
342 if (KGlobalSettings::singleClick()) {
343 connect(this, SIGNAL(clicked(const QModelIndex
&)),
344 m_view
->m_controller
, SLOT(triggerItem(const QModelIndex
&)));
346 connect(this, SIGNAL(doubleClicked(const QModelIndex
&)),
347 m_view
->m_controller
, SLOT(triggerItem(const QModelIndex
&)));
350 const QColor bgColor
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
351 QPalette palette
= viewport()->palette();
352 palette
.setColor(viewport()->backgroundRole(), bgColor
);
353 viewport()->setPalette(palette
);
355 if (!m_childUrl
.isEmpty()) {
356 // assure that the current index is set on the index that represents
358 const QModelIndex dirIndex
= m_view
->m_dolphinModel
->indexForUrl(m_childUrl
);
359 const QModelIndex proxyIndex
= m_view
->m_proxyModel
->mapFromSource(dirIndex
);
360 selectionModel()->setCurrentIndex(proxyIndex
, QItemSelectionModel::Current
);
366 void ColumnWidget::deactivate()
368 // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
369 // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
370 // necessary connecting the signal 'singleClick()' or 'doubleClick'.
371 if (KGlobalSettings::singleClick()) {
372 disconnect(this, SIGNAL(clicked(const QModelIndex
&)),
373 m_view
->m_controller
, SLOT(triggerItem(const QModelIndex
&)));
375 disconnect(this, SIGNAL(doubleClicked(const QModelIndex
&)),
376 m_view
->m_controller
, SLOT(triggerItem(const QModelIndex
&)));
379 const QPalette palette
= m_view
->viewport()->palette();
380 viewport()->setPalette(palette
);
382 selectionModel()->clear();
388 DolphinColumnView::DolphinColumnView(QWidget
* parent
, DolphinController
* controller
) :
389 QAbstractItemView(parent
),
390 m_controller(controller
),
391 m_restoreActiveColumnFocus(false),
392 m_dirListerCompleted(false),
400 Q_ASSERT(controller
!= 0);
402 setAcceptDrops(true);
403 setDragDropMode(QAbstractItemView::DragDrop
);
404 setDropIndicatorShown(false);
405 setSelectionMode(ExtendedSelection
);
407 connect(this, SIGNAL(entered(const QModelIndex
&)),
408 controller
, SLOT(emitItemEntered(const QModelIndex
&)));
409 connect(this, SIGNAL(viewportEntered()),
410 controller
, SLOT(emitViewportEntered()));
411 connect(controller
, SIGNAL(zoomIn()),
412 this, SLOT(zoomIn()));
413 connect(controller
, SIGNAL(zoomOut()),
414 this, SLOT(zoomOut()));
415 connect(controller
, SIGNAL(urlChanged(const KUrl
&)),
416 this, SLOT(showColumn(const KUrl
&)));
418 connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
419 this, SLOT(moveContentHorizontally(int)));
421 m_animation
= new QTimeLine(500, this);
422 connect(m_animation
, SIGNAL(frameChanged(int)), horizontalScrollBar(), SLOT(setValue(int)));
424 ColumnWidget
* column
= new ColumnWidget(viewport(), this, m_controller
->url());
425 m_columns
.append(column
);
426 setActiveColumnIndex(0);
428 updateDecorationSize();
430 // dim the background of the viewport
431 QColor bgColor
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
432 const QColor fgColor
= KColorScheme(QPalette::Active
, KColorScheme::View
).foreground().color();
433 bgColor
= KColorUtils::mix(bgColor
, fgColor
, 0.04);
435 QPalette palette
= viewport()->palette();
436 palette
.setColor(viewport()->backgroundRole(), bgColor
);
437 viewport()->setPalette(palette
);
440 DolphinColumnView::~DolphinColumnView()
444 QModelIndex
DolphinColumnView::indexAt(const QPoint
& point
) const
446 foreach (ColumnWidget
* column
, m_columns
) {
447 const QPoint topLeft
= column
->frameGeometry().topLeft();
448 const QPoint
adjustedPoint(point
.x() - topLeft
.x(), point
.y() - topLeft
.y());
449 const QModelIndex index
= column
->indexAt(adjustedPoint
);
450 if (index
.isValid()) {
455 return QModelIndex();
458 void DolphinColumnView::scrollTo(const QModelIndex
& index
, ScrollHint hint
)
460 activeColumn()->scrollTo(index
, hint
);
463 QRect
DolphinColumnView::visualRect(const QModelIndex
& index
) const
465 return activeColumn()->visualRect(index
);
468 void DolphinColumnView::setModel(QAbstractItemModel
* model
)
470 if (m_dolphinModel
!= 0) {
471 m_dolphinModel
->disconnect(this);
474 m_proxyModel
= static_cast<QAbstractProxyModel
*>(model
);
475 m_dolphinModel
= static_cast<DolphinModel
*>(m_proxyModel
->sourceModel());
476 connect(m_dolphinModel
, SIGNAL(expand(const QModelIndex
&)),
477 this, SLOT(triggerReloadColumns(const QModelIndex
&)));
479 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
480 connect(dirLister
, SIGNAL(started(const KUrl
&)),
481 this, SLOT(slotDirListerStarted(const KUrl
&)));
482 connect(dirLister
, SIGNAL(completed()),
483 this, SLOT(slotDirListerCompleted()));
485 activeColumn()->setModel(model
);
486 QAbstractItemView::setModel(model
);
489 void DolphinColumnView::invertSelection()
491 // TODO: this approach of inverting the selection is quite slow. It should
492 // be possible to speedup the implementation by using QItemSelection, but
493 // all adempts have failed yet...
495 ColumnWidget
* column
= activeColumn();
496 QItemSelectionModel
* selModel
= column
->selectionModel();
498 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
499 const KFileItemList list
= dirLister
->itemsForDir(column
->url());
500 foreach (KFileItem
* item
, list
) {
501 const QModelIndex index
= m_dolphinModel
->indexForUrl(item
->url());
502 selModel
->select(m_proxyModel
->mapFromSource(index
), QItemSelectionModel::Toggle
);
506 void DolphinColumnView::reload()
508 // Due to the reloading of the model all columns will be reset to show
509 // the same content as the first column. As this is not wanted, all columns
510 // except of the first column are temporary hidden until the root index can
512 m_restoreActiveColumnFocus
= false;
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 ColumnWidget
* column
= (*it
);
517 if (column
->isActive() && column
->hasFocus()) {
518 // because of hiding the column, it will lose the focus
519 // -> remember that the focus should be restored after reloading
520 m_restoreActiveColumnFocus
= true;
525 // all columns are hidden, now reload the directory lister
526 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
527 const KUrl
& rootUrl
= m_columns
[0]->url();
528 dirLister
->openUrl(rootUrl
, false, true);
532 void DolphinColumnView::showColumn(const KUrl
& url
)
534 const KUrl
& rootUrl
= m_columns
[0]->url();
535 if (!rootUrl
.isParentOf(url
)) {
536 // the URL is no child URL of the column view, hence clear all columns
537 // and reset the root column
538 QList
<ColumnWidget
*>::iterator start
= m_columns
.begin() + 1;
539 QList
<ColumnWidget
*>::iterator end
= m_columns
.end();
540 for (QList
<ColumnWidget
*>::iterator it
= start
; it
!= end
; ++it
) {
541 (*it
)->deleteLater();
543 m_columns
.erase(start
, end
);
545 m_columns
[0]->setActive(true);
546 m_columns
[0]->setUrl(url
);
547 assureVisibleActiveColumn();
551 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
552 const KUrl dirListerUrl
= dirLister
->url();
553 if (dirListerUrl
!= rootUrl
) {
554 // It is possible that root URL of the directory lister is adjusted
555 // after creating the column widget (e. g. when restoring the history
556 // having a different root URL than the controller indicates).
557 m_columns
[0]->setUrl(dirListerUrl
);
561 foreach (ColumnWidget
* column
, m_columns
) {
562 if (column
->url() == url
) {
563 // the column represents already the requested URL, hence activate it
564 requestActivation(column
);
566 } else if (!column
->url().isParentOf(url
)) {
567 // the column is no parent of the requested URL, hence
568 // just delete all remaining columns
569 if (columnIndex
> 0) {
570 QList
<ColumnWidget
*>::iterator start
= m_columns
.begin() + columnIndex
;
571 QList
<ColumnWidget
*>::iterator end
= m_columns
.end();
572 for (QList
<ColumnWidget
*>::iterator it
= start
; it
!= end
; ++it
) {
573 (*it
)->deleteLater();
575 m_columns
.erase(start
, end
);
577 const int maxIndex
= m_columns
.count() - 1;
578 Q_ASSERT(maxIndex
>= 0);
579 if (m_index
> maxIndex
) {
588 // Create missing columns. Assuming that the path is "/home/peter/Temp/" and
589 // the target path is "/home/peter/Temp/a/b/c/", then the columns "a", "b" and
590 // "c" will be created.
591 const int lastIndex
= m_columns
.count() - 1;
592 Q_ASSERT(lastIndex
>= 0);
594 const KUrl
& activeUrl
= m_columns
[lastIndex
]->url();
595 Q_ASSERT(activeUrl
.isParentOf(url
));
596 Q_ASSERT(activeUrl
!= url
);
598 QString path
= activeUrl
.url(KUrl::AddTrailingSlash
);
599 const QString targetPath
= url
.url(KUrl::AddTrailingSlash
);
601 columnIndex
= lastIndex
;
602 int slashIndex
= path
.count('/');
603 bool hasSubPath
= (slashIndex
>= 0);
605 const QString subPath
= targetPath
.section('/', slashIndex
, slashIndex
);
606 if (subPath
.isEmpty()) {
609 path
+= subPath
+ '/';
612 const KUrl childUrl
= KUrl(path
);
613 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(KUrl(path
));
614 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
616 m_columns
[columnIndex
]->setChildUrl(childUrl
);
619 ColumnWidget
* column
= new ColumnWidget(viewport(), this, childUrl
);
620 column
->setModel(model());
621 column
->setRootIndex(proxyIndex
);
622 column
->setActive(false);
624 m_columns
.append(column
);
626 // Before invoking layoutColumns() the column must be set visible temporary.
627 // To prevent a flickering the initial geometry is set to a hidden position.
628 column
->setGeometry(QRect(-1, -1, 1, 1));
633 // the layout is finished, now let the column be invisible until it
634 // gets a valid root index due to expandToActiveUrl()
639 // set the last column as active column without modifying the controller
640 // and hence the history
641 activeColumn()->setActive(false);
642 m_index
= columnIndex
;
643 activeColumn()->setActive(true);
644 assureVisibleActiveColumn();
647 void DolphinColumnView::selectAll()
649 activeColumn()->selectAll();
652 bool DolphinColumnView::isIndexHidden(const QModelIndex
& index
) const
655 return false;//activeColumn()->isIndexHidden(index);
658 QModelIndex
DolphinColumnView::moveCursor(CursorAction cursorAction
, Qt::KeyboardModifiers modifiers
)
660 // Parts of this code have been taken from QColumnView::moveCursor().
661 // Copyright (C) 1992-2007 Trolltech ASA.
665 return QModelIndex();
668 const QModelIndex current
= currentIndex();
669 if (isRightToLeft()) {
670 if (cursorAction
== MoveLeft
) {
671 cursorAction
= MoveRight
;
672 } else if (cursorAction
== MoveRight
) {
673 cursorAction
= MoveLeft
;
677 switch (cursorAction
) {
680 setActiveColumnIndex(m_index
- 1);
685 if (m_index
< m_columns
.count() - 1) {
686 setActiveColumnIndex(m_index
+ 1);
694 return QModelIndex();
697 void DolphinColumnView::setSelection(const QRect
& rect
, QItemSelectionModel::SelectionFlags flags
)
701 //activeColumn()->setSelection(rect, flags);
704 QRegion
DolphinColumnView::visualRegionForSelection(const QItemSelection
& selection
) const
707 return QRegion(); //activeColumn()->visualRegionForSelection(selection);
710 int DolphinColumnView::horizontalOffset() const
715 int DolphinColumnView::verticalOffset() const
720 void DolphinColumnView::mousePressEvent(QMouseEvent
* event
)
722 m_controller
->triggerActivation();
723 QAbstractItemView::mousePressEvent(event
);
726 void DolphinColumnView::resizeEvent(QResizeEvent
* event
)
728 QAbstractItemView::resizeEvent(event
);
733 void DolphinColumnView::zoomIn()
735 if (isZoomInPossible()) {
736 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
737 // TODO: get rid of K3Icon sizes
738 switch (settings
->iconSize()) {
739 case K3Icon::SizeSmall
: settings
->setIconSize(K3Icon::SizeMedium
); break;
740 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeLarge
); break;
741 default: Q_ASSERT(false); break;
743 updateDecorationSize();
747 void DolphinColumnView::zoomOut()
749 if (isZoomOutPossible()) {
750 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
751 // TODO: get rid of K3Icon sizes
752 switch (settings
->iconSize()) {
753 case K3Icon::SizeLarge
: settings
->setIconSize(K3Icon::SizeMedium
); break;
754 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeSmall
); break;
755 default: Q_ASSERT(false); break;
757 updateDecorationSize();
761 void DolphinColumnView::moveContentHorizontally(int x
)
763 m_contentX
= isRightToLeft() ? +x
: -x
;
767 void DolphinColumnView::updateDecorationSize()
769 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
770 const int iconSize
= settings
->iconSize();
772 foreach (QObject
* object
, viewport()->children()) {
773 if (object
->inherits("QListView")) {
774 ColumnWidget
* widget
= static_cast<ColumnWidget
*>(object
);
775 widget
->setDecorationSize(QSize(iconSize
, iconSize
));
779 m_controller
->setZoomInPossible(isZoomInPossible());
780 m_controller
->setZoomOutPossible(isZoomOutPossible());
785 void DolphinColumnView::expandToActiveUrl()
787 const int lastIndex
= m_columns
.count() - 1;
788 Q_ASSERT(lastIndex
>= 0);
789 const KUrl
& activeUrl
= m_columns
[lastIndex
]->url();
790 const KUrl rootUrl
= m_dolphinModel
->dirLister()->url();
791 const bool expand
= m_dirListerCompleted
792 && rootUrl
.isParentOf(activeUrl
)
793 && !rootUrl
.equals(activeUrl
, KUrl::CompareWithoutTrailingSlash
);
795 m_dolphinModel
->expandToUrl(activeUrl
);
800 void DolphinColumnView::triggerUpdateColumns(const QModelIndex
& index
)
803 // the updating of the columns may not be done in the context of this slot
804 QMetaObject::invokeMethod(this, "updateColumns", Qt::QueuedConnection
);
807 void DolphinColumnView::updateColumns()
809 const int end
= m_columns
.count() - 2; // next to last column
810 for (int i
= 0; i
<= end
; ++i
) {
811 ColumnWidget
* nextColumn
= m_columns
[i
+ 1];
812 const QModelIndex rootIndex
= nextColumn
->rootIndex();
813 if (rootIndex
.isValid()) {
816 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(m_columns
[i
]->childUrl());
817 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
818 if (proxyIndex
.isValid()) {
819 nextColumn
->setRootIndex(proxyIndex
);
821 if (nextColumn
->isActive() && m_restoreActiveColumnFocus
) {
822 nextColumn
->setFocus();
823 m_restoreActiveColumnFocus
= false;
830 void DolphinColumnView::slotDirListerStarted(const KUrl
& url
)
833 m_dirListerCompleted
= false;
836 void DolphinColumnView::slotDirListerCompleted()
838 m_dirListerCompleted
= true;
839 QMetaObject::invokeMethod(this, "expandToActiveUrl", Qt::QueuedConnection
);
842 bool DolphinColumnView::isZoomInPossible() const
844 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
845 return settings
->iconSize() < K3Icon::SizeLarge
;
848 bool DolphinColumnView::isZoomOutPossible() const
850 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
851 return settings
->iconSize() > K3Icon::SizeSmall
;
854 void DolphinColumnView::setActiveColumnIndex(int index
)
856 if (m_index
== index
) {
860 const bool hasActiveColumn
= (m_index
>= 0);
861 if (hasActiveColumn
) {
862 m_columns
[m_index
]->setActive(false);
866 m_columns
[m_index
]->setActive(true);
868 m_controller
->setUrl(m_columns
[m_index
]->url());
870 assureVisibleActiveColumn();
873 void DolphinColumnView::layoutColumns()
875 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
876 const int columnWidth
= settings
->columnWidth();
877 if (isRightToLeft()) {
878 int x
= viewport()->width() - columnWidth
+ m_contentX
;
879 foreach (ColumnWidget
* column
, m_columns
) {
880 column
->setGeometry(QRect(x
, 0, columnWidth
, viewport()->height()));
885 foreach (ColumnWidget
* column
, m_columns
) {
886 column
->setGeometry(QRect(x
, 0, columnWidth
, viewport()->height()));
892 void DolphinColumnView::updateScrollBar()
894 int contentWidth
= 0;
895 foreach (ColumnWidget
* column
, m_columns
) {
896 contentWidth
+= column
->width();
899 horizontalScrollBar()->setPageStep(contentWidth
);
900 horizontalScrollBar()->setRange(0, contentWidth
- viewport()->width());
903 void DolphinColumnView::assureVisibleActiveColumn()
905 const int viewportWidth
= viewport()->width();
906 const int x
= activeColumn()->x();
907 const int width
= activeColumn()->width();
908 if (x
+ width
> viewportWidth
) {
909 const int newContentX
= m_contentX
- x
- width
+ viewportWidth
;
910 if (isRightToLeft()) {
911 m_animation
->setFrameRange(m_contentX
, newContentX
);
913 m_animation
->setFrameRange(-m_contentX
, -newContentX
);
915 m_animation
->start();
917 const int newContentX
= m_contentX
- x
;
918 if (isRightToLeft()) {
919 m_animation
->setFrameRange(m_contentX
, newContentX
);
921 m_animation
->setFrameRange(-m_contentX
, -newContentX
);
923 m_animation
->start();
927 void DolphinColumnView::requestActivation(ColumnWidget
* column
)
929 if (column
->isActive()) {
930 assureVisibleActiveColumn();
933 foreach (ColumnWidget
* currColumn
, m_columns
) {
934 if (currColumn
== column
) {
935 setActiveColumnIndex(index
);
943 #include "dolphincolumnview.moc"