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 // TODO: enable ScrollPerPixel again as soon as a Qt-patch
121 // is supplied which fixes a possible crash
122 //setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
123 setSelectionBehavior(SelectItems
);
124 setSelectionMode(QAbstractItemView::ExtendedSelection
);
125 setDragDropMode(QAbstractItemView::DragDrop
);
126 setDropIndicatorShown(false);
127 setFocusPolicy(Qt::NoFocus
);
129 // apply the column mode settings to the widget
130 const ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
131 Q_ASSERT(settings
!= 0);
133 m_viewOptions
= QListView::viewOptions();
135 QFont
font(settings
->fontFamily(), settings
->fontSize());
136 font
.setItalic(settings
->italicFont());
137 font
.setBold(settings
->boldFont());
138 m_viewOptions
.font
= font
;
140 const int iconSize
= settings
->iconSize();
141 m_viewOptions
.decorationSize
= QSize(iconSize
, iconSize
);
143 KFileItemDelegate
* delegate
= new KFileItemDelegate(this);
144 setItemDelegate(delegate
);
148 connect(this, SIGNAL(entered(const QModelIndex
&)),
149 m_view
->m_controller
, SLOT(emitItemEntered(const QModelIndex
&)));
150 connect(this, SIGNAL(viewportEntered()),
151 m_view
->m_controller
, SLOT(emitViewportEntered()));
154 ColumnWidget::~ColumnWidget()
158 void ColumnWidget::setDecorationSize(const QSize
& size
)
160 m_viewOptions
.decorationSize
= size
;
164 void ColumnWidget::setActive(bool active
)
166 if (m_active
== active
) {
179 inline bool ColumnWidget::isActive() const
184 inline void ColumnWidget::setChildUrl(const KUrl
& url
)
189 inline const KUrl
& ColumnWidget::childUrl() const
194 inline void ColumnWidget::setUrl(const KUrl
& url
)
199 const KUrl
& ColumnWidget::url() const
204 QStyleOptionViewItem
ColumnWidget::viewOptions() const
206 return m_viewOptions
;
209 void ColumnWidget::dragEnterEvent(QDragEnterEvent
* event
)
211 if (event
->mimeData()->hasUrls()) {
212 event
->acceptProposedAction();
218 void ColumnWidget::dragLeaveEvent(QDragLeaveEvent
* event
)
220 QListView::dragLeaveEvent(event
);
222 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
224 setDirtyRegion(m_dropRect
);
227 void ColumnWidget::dragMoveEvent(QDragMoveEvent
* event
)
229 QListView::dragMoveEvent(event
);
231 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
232 const QModelIndex index
= indexAt(event
->pos());
233 setDirtyRegion(m_dropRect
);
234 m_dropRect
= visualRect(index
);
235 setDirtyRegion(m_dropRect
);
238 void ColumnWidget::dropEvent(QDropEvent
* event
)
240 const KUrl::List urls
= KUrl::List::fromMimeData(event
->mimeData());
241 if (!urls
.isEmpty()) {
242 event
->acceptProposedAction();
243 m_view
->m_controller
->indicateDroppedUrls(urls
,
245 indexAt(event
->pos()),
248 QListView::dropEvent(event
);
252 void ColumnWidget::paintEvent(QPaintEvent
* event
)
254 if (!m_childUrl
.isEmpty()) {
255 // indicate the shown URL of the next column by highlighting the shown folder item
256 const QModelIndex dirIndex
= m_view
->m_dolphinModel
->indexForUrl(m_childUrl
);
257 const QModelIndex proxyIndex
= m_view
->m_proxyModel
->mapFromSource(dirIndex
);
258 if (proxyIndex
.isValid() && !selectionModel()->isSelected(proxyIndex
)) {
259 const QRect itemRect
= visualRect(proxyIndex
);
260 QPainter
painter(viewport());
263 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).foreground().color();
265 painter
.setPen(Qt::NoPen
);
266 painter
.setBrush(color
);
267 painter
.drawRect(itemRect
);
273 QListView::paintEvent(event
);
275 // TODO: remove this code when the issue #160611 is solved in Qt 4.4
277 const QBrush
& brush
= m_viewOptions
.palette
.brush(QPalette::Normal
, QPalette::Highlight
);
278 DolphinController::drawHoverIndication(viewport(), m_dropRect
, brush
);
282 void ColumnWidget::mousePressEvent(QMouseEvent
* event
)
285 m_view
->requestActivation(this);
288 QListView::mousePressEvent(event
);
291 void ColumnWidget::keyPressEvent(QKeyEvent
* event
)
293 QListView::keyPressEvent(event
);
295 const QItemSelectionModel
* selModel
= selectionModel();
296 const QModelIndex currentIndex
= selModel
->currentIndex();
297 const bool triggerItem
= currentIndex
.isValid()
298 && (event
->key() == Qt::Key_Return
)
299 && (selModel
->selectedIndexes().count() <= 1);
301 m_view
->triggerItem(currentIndex
);
305 void ColumnWidget::contextMenuEvent(QContextMenuEvent
* event
)
308 m_view
->requestActivation(this);
311 QListView::contextMenuEvent(event
);
313 const QModelIndex index
= indexAt(event
->pos());
314 if (index
.isValid() || m_active
) {
315 // Only open a context menu above an item or if the mouse is above
316 // the active column.
317 const QPoint pos
= m_view
->viewport()->mapFromGlobal(event
->globalPos());
318 m_view
->m_controller
->triggerContextMenuRequest(pos
);
322 void ColumnWidget::selectionChanged(const QItemSelection
& selected
, const QItemSelection
& deselected
)
324 QListView::selectionChanged(selected
, deselected
);
326 QItemSelectionModel
* selModel
= m_view
->selectionModel();
327 selModel
->select(selected
, QItemSelectionModel::Select
);
328 selModel
->select(deselected
, QItemSelectionModel::Deselect
);
331 void ColumnWidget::activate()
333 if (m_view
->hasFocus()) {
334 setFocus(Qt::OtherFocusReason
);
336 m_view
->setFocusProxy(this);
338 // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
339 // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
340 // necessary connecting the signal 'singleClick()' or 'doubleClick'.
341 if (KGlobalSettings::singleClick()) {
342 connect(this, SIGNAL(clicked(const QModelIndex
&)),
343 m_view
, SLOT(triggerItem(const QModelIndex
&)));
345 connect(this, SIGNAL(doubleClicked(const QModelIndex
&)),
346 m_view
, SLOT(triggerItem(const QModelIndex
&)));
349 const QColor bgColor
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
350 QPalette palette
= viewport()->palette();
351 palette
.setColor(viewport()->backgroundRole(), bgColor
);
352 viewport()->setPalette(palette
);
354 if (!m_childUrl
.isEmpty()) {
355 // assure that the current index is set on the index that represents
357 const QModelIndex dirIndex
= m_view
->m_dolphinModel
->indexForUrl(m_childUrl
);
358 const QModelIndex proxyIndex
= m_view
->m_proxyModel
->mapFromSource(dirIndex
);
359 selectionModel()->setCurrentIndex(proxyIndex
, QItemSelectionModel::Current
);
365 void ColumnWidget::deactivate()
367 // TODO: Connecting to the signal 'activated()' is not possible, as kstyle
368 // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is
369 // necessary connecting the signal 'singleClick()' or 'doubleClick'.
370 if (KGlobalSettings::singleClick()) {
371 disconnect(this, SIGNAL(clicked(const QModelIndex
&)),
372 m_view
, SLOT(triggerItem(const QModelIndex
&)));
374 disconnect(this, SIGNAL(doubleClicked(const QModelIndex
&)),
375 m_view
, SLOT(triggerItem(const QModelIndex
&)));
378 const QPalette palette
= m_view
->viewport()->palette();
379 viewport()->setPalette(palette
);
381 selectionModel()->clear();
387 DolphinColumnView::DolphinColumnView(QWidget
* parent
, DolphinController
* controller
) :
388 QAbstractItemView(parent
),
389 m_controller(controller
),
390 m_restoreActiveColumnFocus(false),
391 m_initializedDirLister(false),
399 Q_ASSERT(controller
!= 0);
401 setAcceptDrops(true);
402 setDragDropMode(QAbstractItemView::DragDrop
);
403 setDropIndicatorShown(false);
404 setSelectionMode(ExtendedSelection
);
406 connect(this, SIGNAL(entered(const QModelIndex
&)),
407 controller
, SLOT(emitItemEntered(const QModelIndex
&)));
408 connect(this, SIGNAL(viewportEntered()),
409 controller
, SLOT(emitViewportEntered()));
410 connect(controller
, SIGNAL(zoomIn()),
411 this, SLOT(zoomIn()));
412 connect(controller
, SIGNAL(zoomOut()),
413 this, SLOT(zoomOut()));
414 connect(controller
, SIGNAL(urlChanged(const KUrl
&)),
415 this, SLOT(showColumn(const KUrl
&)));
417 connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
418 this, SLOT(moveContentHorizontally(int)));
420 ColumnWidget
* column
= new ColumnWidget(viewport(), this, m_controller
->url());
421 m_columns
.append(column
);
422 setActiveColumnIndex(0);
424 updateDecorationSize();
426 m_animation
= new QTimeLine(500, this);
427 connect(m_animation
, SIGNAL(frameChanged(int)), horizontalScrollBar(), SLOT(setValue(int)));
429 // dim the background of the viewport
430 QColor bgColor
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
431 const QColor fgColor
= KColorScheme(QPalette::Active
, KColorScheme::View
).foreground().color();
432 bgColor
= KColorUtils::mix(bgColor
, fgColor
, 0.04);
434 QPalette palette
= viewport()->palette();
435 palette
.setColor(viewport()->backgroundRole(), bgColor
);
436 viewport()->setPalette(palette
);
439 DolphinColumnView::~DolphinColumnView()
443 QModelIndex
DolphinColumnView::indexAt(const QPoint
& point
) const
445 foreach (ColumnWidget
* column
, m_columns
) {
446 const QPoint topLeft
= column
->frameGeometry().topLeft();
447 const QPoint
adjustedPoint(point
.x() - topLeft
.x(), point
.y() - topLeft
.y());
448 const QModelIndex index
= column
->indexAt(adjustedPoint
);
449 if (index
.isValid()) {
454 return QModelIndex();
457 void DolphinColumnView::scrollTo(const QModelIndex
& index
, ScrollHint hint
)
459 activeColumn()->scrollTo(index
, hint
);
462 QRect
DolphinColumnView::visualRect(const QModelIndex
& index
) const
464 return activeColumn()->visualRect(index
);
467 void DolphinColumnView::setModel(QAbstractItemModel
* model
)
469 if (m_dolphinModel
!= 0) {
470 m_dolphinModel
->disconnect(this);
473 m_proxyModel
= static_cast<QAbstractProxyModel
*>(model
);
474 m_dolphinModel
= static_cast<DolphinModel
*>(m_proxyModel
->sourceModel());
475 connect(m_dolphinModel
, SIGNAL(expand(const QModelIndex
&)),
476 this, SLOT(triggerReloadColumns(const QModelIndex
&)));
478 activeColumn()->setModel(model
);
479 QAbstractItemView::setModel(model
);
482 void DolphinColumnView::invertSelection()
484 // TODO: this approach of inverting the selection is quite slow. It should
485 // be possible to speedup the implementation by using QItemSelection, but
486 // all adempts have failed yet...
488 ColumnWidget
* column
= activeColumn();
489 QItemSelectionModel
* selModel
= column
->selectionModel();
491 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
492 const KFileItemList list
= dirLister
->itemsForDir(column
->url());
493 foreach (KFileItem
* item
, list
) {
494 const QModelIndex index
= m_dolphinModel
->indexForUrl(item
->url());
495 selModel
->select(m_proxyModel
->mapFromSource(index
), QItemSelectionModel::Toggle
);
499 void DolphinColumnView::reload()
501 // Due to the reloading of the model all columns will be reset to show
502 // the same content as the first column. As this is not wanted, all columns
503 // except of the first column are temporary hidden until the root index can
505 m_restoreActiveColumnFocus
= false;
506 QList
<ColumnWidget
*>::iterator start
= m_columns
.begin() + 1;
507 QList
<ColumnWidget
*>::iterator end
= m_columns
.end();
508 for (QList
<ColumnWidget
*>::iterator it
= start
; it
!= end
; ++it
) {
509 ColumnWidget
* column
= (*it
);
510 if (column
->isActive() && column
->hasFocus()) {
511 // because of hiding the column, it will lose the focus
512 // -> remember that the focus should be restored after reloading
513 m_restoreActiveColumnFocus
= true;
518 // all columns are hidden, now reload the directory lister
519 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
520 connect(dirLister
, SIGNAL(completed()),
521 this, SLOT(expandToActiveUrl()));
522 const KUrl
& rootUrl
= m_columns
[0]->url();
523 m_initializedDirLister
= dirLister
->openUrl(m_columns
[0]->url(), false, true);
527 void DolphinColumnView::showColumn(const KUrl
& url
)
529 const KUrl
& rootUrl
= m_columns
[0]->url();
530 if (!rootUrl
.isParentOf(url
)) {
531 // the URL is no child URL of the column view, hence clear all columns
532 // and reset the root column
533 QList
<ColumnWidget
*>::iterator start
= m_columns
.begin() + 1;
534 QList
<ColumnWidget
*>::iterator end
= m_columns
.end();
535 for (QList
<ColumnWidget
*>::iterator it
= start
; it
!= end
; ++it
) {
536 (*it
)->deleteLater();
538 m_columns
.erase(start
, end
);
540 m_columns
[0]->setActive(true);
541 m_columns
[0]->setUrl(url
);
542 assureVisibleActiveColumn();
546 KDirLister
* dirLister
= m_dolphinModel
->dirLister();
547 const KUrl dirListerUrl
= dirLister
->url();
548 if (dirListerUrl
!= rootUrl
) {
549 // It is possible that root URL of the directory lister is adjusted
550 // after creating the column widget (e. g. when restoring the history
551 // having a different root URL than the controller indicates).
552 m_columns
[0]->setUrl(dirListerUrl
);
556 foreach (ColumnWidget
* column
, m_columns
) {
557 if (column
->url() == url
) {
558 // the column represents already the requested URL, hence activate it
559 requestActivation(column
);
561 } else if (!column
->url().isParentOf(url
)) {
562 // the column is no parent of the requested URL, hence
563 // just delete all remaining columns
564 if (columnIndex
> 0) {
565 QList
<ColumnWidget
*>::iterator start
= m_columns
.begin() + columnIndex
;
566 QList
<ColumnWidget
*>::iterator end
= m_columns
.end();
567 for (QList
<ColumnWidget
*>::iterator it
= start
; it
!= end
; ++it
) {
568 (*it
)->deleteLater();
570 m_columns
.erase(start
, end
);
572 const int maxIndex
= m_columns
.count() - 1;
573 Q_ASSERT(maxIndex
>= 0);
574 if (m_index
> maxIndex
) {
583 // Create missing columns. Assuming that the path is "/home/peter/Temp/" and
584 // the target path is "/home/peter/Temp/a/b/c/", then the columns "a", "b" and
585 // "c" will be created.
586 const int lastIndex
= m_columns
.count() - 1;
587 Q_ASSERT(lastIndex
>= 0);
589 const KUrl
& activeUrl
= m_columns
[lastIndex
]->url();
590 Q_ASSERT(activeUrl
.isParentOf(url
));
591 Q_ASSERT(activeUrl
!= url
);
593 QString path
= activeUrl
.url(KUrl::AddTrailingSlash
);
594 const QString targetPath
= url
.url(KUrl::AddTrailingSlash
);
596 columnIndex
= lastIndex
;
597 int slashIndex
= path
.count('/');
598 bool hasSubPath
= (slashIndex
>= 0);
600 const QString subPath
= targetPath
.section('/', slashIndex
, slashIndex
);
601 if (subPath
.isEmpty()) {
604 path
+= subPath
+ '/';
607 const KUrl childUrl
= KUrl(path
);
608 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(KUrl(path
));
609 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
611 m_columns
[columnIndex
]->setChildUrl(childUrl
);
614 ColumnWidget
* column
= new ColumnWidget(viewport(), this, childUrl
);
615 column
->setVerticalScrollMode(ColumnWidget::ScrollPerPixel
);
616 column
->setHorizontalScrollMode(ColumnWidget::ScrollPerPixel
);
617 column
->setModel(model());
618 column
->setRootIndex(proxyIndex
);
619 column
->setActive(false);
621 m_columns
.append(column
);
623 // Before invoking layoutColumns() the column must be set visible temporary.
624 // To prevent a flickering the initial geometry is set to a hidden position.
625 column
->setGeometry(QRect(-1, -1, 1, 1));
630 // the layout is finished, now let the column be invisible until it
631 // gets a valid root index due to expandToActiveUrl()
636 // set the last column as active column without modifying the controller
637 // and hence the history
638 activeColumn()->setActive(false);
639 m_index
= columnIndex
;
640 activeColumn()->setActive(true);
642 if (m_initializedDirLister
) {
643 // expanding the active URL may only be done if the directory lister
644 // has been initialized
645 QMetaObject::invokeMethod(this, "expandToActiveUrl", Qt::QueuedConnection
);
647 QMetaObject::invokeMethod(this, "reload", Qt::QueuedConnection
);
651 void DolphinColumnView::selectAll()
653 activeColumn()->selectAll();
656 bool DolphinColumnView::isIndexHidden(const QModelIndex
& index
) const
659 return false;//activeColumn()->isIndexHidden(index);
662 QModelIndex
DolphinColumnView::moveCursor(CursorAction cursorAction
, Qt::KeyboardModifiers modifiers
)
664 // Parts of this code have been taken from QColumnView::moveCursor().
665 // Copyright (C) 1992-2007 Trolltech ASA.
669 return QModelIndex();
672 const QModelIndex current
= currentIndex();
673 if (isRightToLeft()) {
674 if (cursorAction
== MoveLeft
) {
675 cursorAction
= MoveRight
;
676 } else if (cursorAction
== MoveRight
) {
677 cursorAction
= MoveLeft
;
681 switch (cursorAction
) {
684 setActiveColumnIndex(m_index
- 1);
689 if (m_index
< m_columns
.count() - 1) {
690 setActiveColumnIndex(m_index
+ 1);
698 return QModelIndex();
701 void DolphinColumnView::setSelection(const QRect
& rect
, QItemSelectionModel::SelectionFlags flags
)
705 //activeColumn()->setSelection(rect, flags);
708 QRegion
DolphinColumnView::visualRegionForSelection(const QItemSelection
& selection
) const
711 return QRegion(); //activeColumn()->visualRegionForSelection(selection);
714 int DolphinColumnView::horizontalOffset() const
719 int DolphinColumnView::verticalOffset() const
724 void DolphinColumnView::mousePressEvent(QMouseEvent
* event
)
726 m_controller
->triggerActivation();
727 QAbstractItemView::mousePressEvent(event
);
730 void DolphinColumnView::resizeEvent(QResizeEvent
* event
)
732 QAbstractItemView::resizeEvent(event
);
737 void DolphinColumnView::zoomIn()
739 if (isZoomInPossible()) {
740 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
741 // TODO: get rid of K3Icon sizes
742 switch (settings
->iconSize()) {
743 case K3Icon::SizeSmall
: settings
->setIconSize(K3Icon::SizeMedium
); break;
744 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeLarge
); break;
745 default: Q_ASSERT(false); break;
747 updateDecorationSize();
751 void DolphinColumnView::zoomOut()
753 if (isZoomOutPossible()) {
754 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
755 // TODO: get rid of K3Icon sizes
756 switch (settings
->iconSize()) {
757 case K3Icon::SizeLarge
: settings
->setIconSize(K3Icon::SizeMedium
); break;
758 case K3Icon::SizeMedium
: settings
->setIconSize(K3Icon::SizeSmall
); break;
759 default: Q_ASSERT(false); break;
761 updateDecorationSize();
765 void DolphinColumnView::moveContentHorizontally(int x
)
771 void DolphinColumnView::updateDecorationSize()
773 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
774 const int iconSize
= settings
->iconSize();
776 foreach (QObject
* object
, viewport()->children()) {
777 if (object
->inherits("QListView")) {
778 ColumnWidget
* widget
= static_cast<ColumnWidget
*>(object
);
779 widget
->setDecorationSize(QSize(iconSize
, iconSize
));
783 m_controller
->setZoomInPossible(isZoomInPossible());
784 m_controller
->setZoomOutPossible(isZoomOutPossible());
789 void DolphinColumnView::expandToActiveUrl()
791 disconnect(m_dolphinModel
->dirLister(), SIGNAL(completed()),
792 this, SLOT(expandToActiveUrl()));
794 const int lastIndex
= m_columns
.count() - 1;
795 Q_ASSERT(lastIndex
>= 0);
796 const KUrl
& activeUrl
= m_columns
[lastIndex
]->url();
797 const KUrl rootUrl
= m_dolphinModel
->dirLister()->url();
798 const bool expand
= rootUrl
.isParentOf(activeUrl
)
799 && !rootUrl
.equals(activeUrl
, KUrl::CompareWithoutTrailingSlash
);
801 m_dolphinModel
->expandToUrl(activeUrl
);
806 void DolphinColumnView::triggerReloadColumns(const QModelIndex
& index
)
809 // the reloading of the columns may not be done in the context of this slot
810 QMetaObject::invokeMethod(this, "reloadColumns", Qt::QueuedConnection
);
813 void DolphinColumnView::reloadColumns()
815 const int end
= m_columns
.count() - 2; // next to last column
816 for (int i
= 0; i
<= end
; ++i
) {
817 ColumnWidget
* nextColumn
= m_columns
[i
+ 1];
819 const QModelIndex rootIndex
= nextColumn
->rootIndex();
820 if (rootIndex
.isValid()) {
823 const QModelIndex dirIndex
= m_dolphinModel
->indexForUrl(m_columns
[i
]->childUrl());
824 const QModelIndex proxyIndex
= m_proxyModel
->mapFromSource(dirIndex
);
825 if (proxyIndex
.isValid()) {
826 nextColumn
->setRootIndex(proxyIndex
);
828 if (nextColumn
->isActive() && m_restoreActiveColumnFocus
) {
829 nextColumn
->setFocus();
830 m_restoreActiveColumnFocus
= false;
835 assureVisibleActiveColumn();
838 void DolphinColumnView::triggerItem(const QModelIndex
& index
)
840 m_initializedDirLister
= true;
841 m_controller
->triggerItem(index
);
844 bool DolphinColumnView::isZoomInPossible() const
846 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
847 return settings
->iconSize() < K3Icon::SizeLarge
;
850 bool DolphinColumnView::isZoomOutPossible() const
852 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
853 return settings
->iconSize() > K3Icon::SizeSmall
;
856 void DolphinColumnView::setActiveColumnIndex(int index
)
858 if (m_index
== index
) {
862 const bool hasActiveColumn
= (m_index
>= 0);
863 if (hasActiveColumn
) {
864 m_columns
[m_index
]->setActive(false);
868 m_columns
[m_index
]->setActive(true);
870 m_controller
->setUrl(m_columns
[m_index
]->url());
873 void DolphinColumnView::layoutColumns()
876 ColumnModeSettings
* settings
= DolphinSettings::instance().columnModeSettings();
877 const int columnWidth
= settings
->columnWidth();
878 foreach (ColumnWidget
* column
, m_columns
) {
879 column
->setGeometry(QRect(x
, 0, columnWidth
, viewport()->height()));
884 void DolphinColumnView::updateScrollBar()
886 int contentWidth
= 0;
887 foreach (ColumnWidget
* column
, m_columns
) {
888 contentWidth
+= column
->width();
891 horizontalScrollBar()->setPageStep(contentWidth
);
892 horizontalScrollBar()->setRange(0, contentWidth
- viewport()->width());
895 void DolphinColumnView::assureVisibleActiveColumn()
897 const int viewportWidth
= viewport()->width();
898 const int x
= activeColumn()->x();
899 const int width
= activeColumn()->width();
900 if (x
+ width
> viewportWidth
) {
901 int newContentX
= m_contentX
- x
- width
+ viewportWidth
;
902 if (newContentX
> 0) {
905 m_animation
->setFrameRange(-m_contentX
, -newContentX
);
906 m_animation
->start();
908 const int newContentX
= m_contentX
- x
;
909 m_animation
->setFrameRange(-m_contentX
, -newContentX
);
910 m_animation
->start();
914 void DolphinColumnView::requestActivation(ColumnWidget
* column
)
916 if (column
->isActive()) {
917 assureVisibleActiveColumn();
920 foreach (ColumnWidget
* currColumn
, m_columns
) {
921 if (currColumn
== column
) {
922 setActiveColumnIndex(index
);
923 assureVisibleActiveColumn();
931 #include "dolphincolumnview.moc"