X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/d96a3338ba21a746602e160c238e0ae16dc3bbb5..29c5ab3b74d26657c60b40770676be082caa953d:/src/dolphincolumnview.cpp diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index 9f7eddefb..f34be92e9 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -19,482 +19,268 @@ #include "dolphincolumnview.h" -#include "dolphinmodel.h" +#include "dolphincolumnwidget.h" #include "dolphincontroller.h" -#include "dolphinsettings.h" +#include "settings/dolphinsettings.h" +#include "zoomlevelinfo.h" #include "dolphin_columnmodesettings.h" -#include -#include -#include +#include -#include -#include #include #include #include -/** - * Represents one column inside the DolphinColumnView and has been - * extended to respect view options and hovering information. - */ -class ColumnWidget : public QListView -{ -public: - ColumnWidget(QWidget* parent, - DolphinColumnView* columnView, - const KUrl& url); - virtual ~ColumnWidget(); - - /** Sets the size of the icons. */ - void setDecorationSize(const QSize& size); - - /** - * An active column is defined as column, which shows the same URL - * as indicated by the URL navigator. The active column is usually - * drawn in a lighter color. All operations are applied to this column. - */ - void setActive(bool active); - inline bool isActive() const; - - /** - * Sets the directory URL of the child column that is shown next to - * this column. This property is only used for a visual indication - * of the shown directory, it does not trigger a loading of the model. - */ - inline void setChildUrl(const KUrl& url); - inline const KUrl& childUrl() const; - - /** - * Returns the directory URL that is shown inside the column widget. - */ - inline const KUrl& url() const; - -protected: - virtual QStyleOptionViewItem viewOptions() const; - virtual void dragEnterEvent(QDragEnterEvent* event); - virtual void dragLeaveEvent(QDragLeaveEvent* event); - virtual void dragMoveEvent(QDragMoveEvent* event); - virtual void dropEvent(QDropEvent* event); - virtual void paintEvent(QPaintEvent* event); - virtual void mousePressEvent(QMouseEvent* event); - virtual void keyPressEvent(QKeyEvent* event); - virtual void contextMenuEvent(QContextMenuEvent* event); - virtual void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected); - -private: - /** Used by ColumnWidget::setActive(). */ - void activate(); - - /** Used by ColumnWidget::setActive(). */ - void deactivate(); - -private: - bool m_active; - DolphinColumnView* m_view; - KUrl m_url; // URL of the directory that is shown - KUrl m_childUrl; // URL of the next column that is shown - QStyleOptionViewItem m_viewOptions; - - bool m_dragging; // TODO: remove this property when the issue #160611 is solved in Qt 4.4 - QRect m_dropRect; // TODO: remove this property when the issue #160611 is solved in Qt 4.4 -}; - -ColumnWidget::ColumnWidget(QWidget* parent, - DolphinColumnView* columnView, - const KUrl& url) : - QListView(parent), - m_active(true), - m_view(columnView), - m_url(url), - m_childUrl(), - m_dragging(false), - m_dropRect() -{ - setMouseTracking(true); - viewport()->setAttribute(Qt::WA_Hover); - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - setSelectionBehavior(SelectItems); - setSelectionMode(QAbstractItemView::ExtendedSelection); +DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* controller) : + QAbstractItemView(parent), + m_controller(controller), + m_active(false), + m_index(-1), + m_contentX(0), + m_columns(), + m_emptyViewport(0), + m_animation(0), + m_nameFilter() +{ + Q_ASSERT(controller != 0); + + setAcceptDrops(true); setDragDropMode(QAbstractItemView::DragDrop); setDropIndicatorShown(false); + setSelectionMode(ExtendedSelection); setFocusPolicy(Qt::NoFocus); + setFrameShape(QFrame::NoFrame); + setLayoutDirection(Qt::LeftToRight); - // apply the column mode settings to the widget - const ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); - Q_ASSERT(settings != 0); - - m_viewOptions = QListView::viewOptions(); - - QFont font(settings->fontFamily(), settings->fontSize()); - font.setItalic(settings->italicFont()); - font.setBold(settings->boldFont()); - m_viewOptions.font = font; - - const int iconSize = settings->iconSize(); - m_viewOptions.decorationSize = QSize(iconSize, iconSize); - - KFileItemDelegate* delegate = new KFileItemDelegate(this); - setItemDelegate(delegate); - - activate(); - - connect(this, SIGNAL(entered(const QModelIndex&)), - m_view->m_controller, SLOT(emitItemEntered(const QModelIndex&))); connect(this, SIGNAL(viewportEntered()), - m_view->m_controller, SLOT(emitViewportEntered())); -} - -ColumnWidget::~ColumnWidget() -{ -} - -void ColumnWidget::setDecorationSize(const QSize& size) -{ - m_viewOptions.decorationSize = size; - doItemsLayout(); -} - -void ColumnWidget::setActive(bool active) -{ - if (m_active == active) { - return; - } - - m_active = active; + controller, SLOT(emitViewportEntered())); + connect(controller, SIGNAL(zoomLevelChanged(int)), + this, SLOT(setZoomLevel(int))); + connect(controller, SIGNAL(activationChanged(bool)), + this, SLOT(updateColumnsBackground(bool))); + + const DolphinView* view = controller->dolphinView(); + connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)), + this, SLOT(slotSortingChanged(DolphinView::Sorting))); + connect(view, SIGNAL(sortOrderChanged(Qt::SortOrder)), + this, SLOT(slotSortOrderChanged(Qt::SortOrder))); + connect(view, SIGNAL(sortFoldersFirstChanged(bool)), + this, SLOT(slotSortFoldersFirstChanged(bool))); + connect(view, SIGNAL(showHiddenFilesChanged()), + this, SLOT(slotShowHiddenFilesChanged())); + connect(view, SIGNAL(showPreviewChanged()), + this, SLOT(slotShowPreviewChanged())); - if (active) { - activate(); - } else { - deactivate(); - } -} + connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), + this, SLOT(moveContentHorizontally(int))); -inline bool ColumnWidget::isActive() const -{ - return m_active; -} + m_animation = new QTimeLine(500, this); + connect(m_animation, SIGNAL(frameChanged(int)), horizontalScrollBar(), SLOT(setValue(int))); -inline void ColumnWidget::setChildUrl(const KUrl& url) -{ - m_childUrl = url; -} + DolphinColumnWidget* column = new DolphinColumnWidget(viewport(), this, m_controller->url()); + m_columns.append(column); + setActiveColumnIndex(0); -inline const KUrl& ColumnWidget::childUrl() const -{ - return m_childUrl; -} + m_emptyViewport = new QFrame(viewport()); + m_emptyViewport->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); -const KUrl& ColumnWidget::url() const -{ - return m_url; + updateDecorationSize(view->showPreview()); + updateColumnsBackground(true); } -QStyleOptionViewItem ColumnWidget::viewOptions() const +DolphinColumnView::~DolphinColumnView() { - return m_viewOptions; } -void ColumnWidget::dragEnterEvent(QDragEnterEvent* event) +QModelIndex DolphinColumnView::indexAt(const QPoint& point) const { - if (event->mimeData()->hasUrls()) { - event->acceptProposedAction(); + foreach (DolphinColumnWidget* column, m_columns) { + const QModelIndex index = column->indexAt(columnPosition(column, point)); + if (index.isValid()) { + return index; + } } - m_dragging = true; + return QModelIndex(); } -void ColumnWidget::dragLeaveEvent(QDragLeaveEvent* event) +KFileItem DolphinColumnView::itemAt(const QPoint& point) const { - QListView::dragLeaveEvent(event); + foreach (DolphinColumnWidget* column, m_columns) { + KFileItem item = column->itemAt(columnPosition(column, point)); + if (!item.isNull()) { + return item; + } + } - // TODO: remove this code when the issue #160611 is solved in Qt 4.4 - m_dragging = false; - setDirtyRegion(m_dropRect); + return KFileItem(); } -void ColumnWidget::dragMoveEvent(QDragMoveEvent* event) +void DolphinColumnView::scrollTo(const QModelIndex& index, ScrollHint hint) { - QListView::dragMoveEvent(event); - - // TODO: remove this code when the issue #160611 is solved in Qt 4.4 - const QModelIndex index = indexAt(event->pos()); - setDirtyRegion(m_dropRect); - m_dropRect = visualRect(index); - setDirtyRegion(m_dropRect); + activeColumn()->scrollTo(index, hint); } -void ColumnWidget::dropEvent(QDropEvent* event) +QRect DolphinColumnView::visualRect(const QModelIndex& index) const { - const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData()); - if (!urls.isEmpty()) { - event->acceptProposedAction(); - m_view->m_controller->indicateDroppedUrls(urls, - url(), - indexAt(event->pos()), - event->source()); - } - QListView::dropEvent(event); - m_dragging = false; + return activeColumn()->visualRect(index); } -void ColumnWidget::paintEvent(QPaintEvent* event) +void DolphinColumnView::invertSelection() { - if (!m_childUrl.isEmpty()) { - // indicate the shown URL of the next column by highlighting the shown folder item - const QModelIndex dirIndex = m_view->m_dolphinModel->indexForUrl(m_childUrl); - const QModelIndex proxyIndex = m_view->m_proxyModel->mapFromSource(dirIndex); - if (proxyIndex.isValid() && !selectionModel()->isSelected(proxyIndex)) { - const QRect itemRect = visualRect(proxyIndex); - QPainter painter(viewport()); - painter.save(); + QItemSelectionModel* selectionModel = activeColumn()->selectionModel(); + const QAbstractItemModel* itemModel = selectionModel->model(); - QColor color = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color(); - color.setAlpha(32); - painter.setPen(Qt::NoPen); - painter.setBrush(color); - painter.drawRect(itemRect); + const QModelIndex topLeft = itemModel->index(0, 0); + const QModelIndex bottomRight = itemModel->index(itemModel->rowCount() - 1, + itemModel->columnCount() - 1); - painter.restore(); - } - } - - QListView::paintEvent(event); - - // TODO: remove this code when the issue #160611 is solved in Qt 4.4 - if (m_dragging) { - const QBrush& brush = m_viewOptions.palette.brush(QPalette::Normal, QPalette::Highlight); - DolphinController::drawHoverIndication(viewport(), m_dropRect, brush); - } + const QItemSelection selection(topLeft, bottomRight); + selectionModel->select(selection, QItemSelectionModel::Toggle); } -void ColumnWidget::mousePressEvent(QMouseEvent* event) +void DolphinColumnView::reload() { - if (!m_active) { - m_view->requestActivation(this); + foreach (DolphinColumnWidget* column, m_columns) { + column->reload(); } - - QListView::mousePressEvent(event); } -void ColumnWidget::keyPressEvent(QKeyEvent* event) +void DolphinColumnView::setRootUrl(const KUrl& url) { - QListView::keyPressEvent(event); - - const QItemSelectionModel* selModel = selectionModel(); - const QModelIndex currentIndex = selModel->currentIndex(); - const bool triggerItem = currentIndex.isValid() - && (event->key() == Qt::Key_Return) - && (selModel->selectedIndexes().count() <= 1); - if (triggerItem) { - m_view->triggerItem(currentIndex); - } + removeAllColumns(); + m_columns[0]->setUrl(url); } -void ColumnWidget::contextMenuEvent(QContextMenuEvent* event) +void DolphinColumnView::setNameFilter(const QString& nameFilter) { - if (!m_active) { - m_view->requestActivation(this); - } - - QListView::contextMenuEvent(event); - - const QModelIndex index = indexAt(event->pos()); - if (index.isValid() || m_active) { - // Only open a context menu above an item or if the mouse is above - // the active column. - const QPoint pos = m_view->viewport()->mapFromGlobal(event->globalPos()); - m_view->m_controller->triggerContextMenuRequest(pos); + if (nameFilter != m_nameFilter) { + m_nameFilter = nameFilter; + foreach (DolphinColumnWidget* column, m_columns) { + column->setNameFilter(nameFilter); + } } } -void ColumnWidget::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) +QString DolphinColumnView::nameFilter() const { - QListView::selectionChanged(selected, deselected); - - QItemSelectionModel* selModel = m_view->selectionModel(); - selModel->select(selected, QItemSelectionModel::Select); - selModel->select(deselected, QItemSelectionModel::Deselect); + return m_nameFilter; } -void ColumnWidget::activate() +KUrl DolphinColumnView::rootUrl() const { - if (m_view->hasFocus()) { - setFocus(Qt::OtherFocusReason); - } - m_view->setFocusProxy(this); - - // TODO: Connecting to the signal 'activated()' is not possible, as kstyle - // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is - // necessary connecting the signal 'singleClick()' or 'doubleClick'. - if (KGlobalSettings::singleClick()) { - connect(this, SIGNAL(clicked(const QModelIndex&)), - m_view, SLOT(triggerItem(const QModelIndex&))); - } else { - connect(this, SIGNAL(doubleClicked(const QModelIndex&)), - m_view, SLOT(triggerItem(const QModelIndex&))); - } - - const QColor bgColor = KColorScheme(QPalette::Active, KColorScheme::View).background().color(); - QPalette palette = viewport()->palette(); - palette.setColor(viewport()->backgroundRole(), bgColor); - viewport()->setPalette(palette); - - if (!m_childUrl.isEmpty()) { - // assure that the current index is set on the index that represents - // the child URL - const QModelIndex dirIndex = m_view->m_dolphinModel->indexForUrl(m_childUrl); - const QModelIndex proxyIndex = m_view->m_proxyModel->mapFromSource(dirIndex); - selectionModel()->setCurrentIndex(proxyIndex, QItemSelectionModel::Current); - } - - update(); + return m_columns[0]->url(); } -void ColumnWidget::deactivate() +void DolphinColumnView::showColumn(const KUrl& url) { - // TODO: Connecting to the signal 'activated()' is not possible, as kstyle - // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is - // necessary connecting the signal 'singleClick()' or 'doubleClick'. - if (KGlobalSettings::singleClick()) { - disconnect(this, SIGNAL(clicked(const QModelIndex&)), - m_view, SLOT(triggerItem(const QModelIndex&))); - } else { - disconnect(this, SIGNAL(doubleClicked(const QModelIndex&)), - m_view, SLOT(triggerItem(const QModelIndex&))); + if (!rootUrl().isParentOf(url)) { + setRootUrl(url); + return; } - const QPalette palette = m_view->viewport()->palette(); - viewport()->setPalette(palette); - - selectionModel()->clear(); - update(); -} - -// --- - -DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* controller) : - QAbstractItemView(parent), - m_controller(controller), - m_restoreActiveColumnFocus(false), - m_index(-1), - m_contentX(0), - m_columns(), - m_animation(0), - m_dolphinModel(0), - m_proxyModel(0) -{ - Q_ASSERT(controller != 0); - - setAcceptDrops(true); - setDragDropMode(QAbstractItemView::DragDrop); - setDropIndicatorShown(false); - setSelectionMode(ExtendedSelection); - - connect(this, SIGNAL(entered(const QModelIndex&)), - controller, SLOT(emitItemEntered(const QModelIndex&))); - connect(this, SIGNAL(viewportEntered()), - controller, SLOT(emitViewportEntered())); - connect(controller, SIGNAL(zoomIn()), - this, SLOT(zoomIn())); - connect(controller, SIGNAL(zoomOut()), - this, SLOT(zoomOut())); - connect(controller, SIGNAL(urlChanged(const KUrl&)), - this, SLOT(showColumn(const KUrl&))); - - connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), - this, SLOT(moveContentHorizontally(int))); - - ColumnWidget* column = new ColumnWidget(viewport(), this, m_controller->url()); - m_columns.append(column); - setActiveColumnIndex(0); - - updateDecorationSize(); + int columnIndex = 0; + foreach (DolphinColumnWidget* column, m_columns) { + if (column->url() == url) { + // the column represents already the requested URL, hence activate it + requestActivation(column); + layoutColumns(); + return; + } else if (!column->url().isParentOf(url)) { + // the column is no parent of the requested URL, hence + // just delete all remaining columns + if (columnIndex > 0) { + QList::iterator start = m_columns.begin() + columnIndex; + QList::iterator end = m_columns.end(); + for (QList::iterator it = start; it != end; ++it) { + deleteColumn(*it); + } + m_columns.erase(start, end); - m_animation = new QTimeLine(500, this); - connect(m_animation, SIGNAL(frameChanged(int)), horizontalScrollBar(), SLOT(setValue(int))); + const int maxIndex = m_columns.count() - 1; + Q_ASSERT(maxIndex >= 0); + if (m_index > maxIndex) { + m_index = maxIndex; + } + break; + } + } + ++columnIndex; + } - // dim the background of the viewport - QColor bgColor = KColorScheme(QPalette::Active, KColorScheme::View).background().color(); - const QColor fgColor = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color(); - bgColor = KColorUtils::mix(bgColor, fgColor, 0.04); + // Create missing columns. Assuming that the path is "/home/peter/Temp/" and + // the target path is "/home/peter/Temp/a/b/c/", then the columns "a", "b" and + // "c" will be created. + const int lastIndex = m_columns.count() - 1; + Q_ASSERT(lastIndex >= 0); - QPalette palette = viewport()->palette(); - palette.setColor(viewport()->backgroundRole(), bgColor); - viewport()->setPalette(palette); -} + const KUrl& activeUrl = m_columns[lastIndex]->url(); + Q_ASSERT(activeUrl.isParentOf(url)); + Q_ASSERT(activeUrl != url); + + QString path = activeUrl.url(KUrl::AddTrailingSlash); + const QString targetPath = url.url(KUrl::AddTrailingSlash); + + columnIndex = lastIndex; + int slashIndex = path.count('/'); + bool hasSubPath = (slashIndex >= 0); + while (hasSubPath) { + const QString subPath = targetPath.section('/', slashIndex, slashIndex); + if (subPath.isEmpty()) { + hasSubPath = false; + } else { + path += subPath + '/'; + ++slashIndex; + + const KUrl childUrl = KUrl(path); + m_columns[columnIndex]->setChildUrl(childUrl); + columnIndex++; + + DolphinColumnWidget* column = new DolphinColumnWidget(viewport(), this, childUrl); + const QString filter = nameFilter(); + if (!filter.isEmpty()) { + column->setNameFilter(filter); + } + column->setActive(false); -DolphinColumnView::~DolphinColumnView() -{ -} + m_columns.append(column); -QModelIndex DolphinColumnView::indexAt(const QPoint& point) const -{ - foreach (ColumnWidget* column, m_columns) { - const QPoint topLeft = column->frameGeometry().topLeft(); - const QPoint adjustedPoint(point.x() - topLeft.x(), point.y() - topLeft.y()); - const QModelIndex index = column->indexAt(adjustedPoint); - if (index.isValid()) { - return index; + // Before invoking layoutColumns() the column must be set visible temporary. + // To prevent a flickering the initial geometry is set to a hidden position. + column->setGeometry(QRect(-1, -1, 1, 1)); + column->show(); + layoutColumns(); + updateScrollBar(); } } - return QModelIndex(); + // set the last column as active column without modifying the controller + // and hence the history + activeColumn()->setActive(false); + m_index = columnIndex; + activeColumn()->setActive(true); + assureVisibleActiveColumn(); } -void DolphinColumnView::scrollTo(const QModelIndex& index, ScrollHint hint) +void DolphinColumnView::editItem(const KFileItem& item) { - activeColumn()->scrollTo(index, hint); + activeColumn()->editItem(item); } -QRect DolphinColumnView::visualRect(const QModelIndex& index) const +KFileItemList DolphinColumnView::selectedItems() const { - return activeColumn()->visualRect(index); + return activeColumn()->selectedItems(); } -void DolphinColumnView::setModel(QAbstractItemModel* model) +QMimeData* DolphinColumnView::selectionMimeData() const { - if (m_dolphinModel != 0) { - m_dolphinModel->disconnect(this); - } - - m_proxyModel = static_cast(model); - m_dolphinModel = static_cast(m_proxyModel->sourceModel()); - connect(m_dolphinModel, SIGNAL(expand(const QModelIndex&)), - this, SLOT(triggerReloadColumns(const QModelIndex&))); - - activeColumn()->setModel(model); - QAbstractItemView::setModel(model); + return activeColumn()->selectionMimeData(); } -void DolphinColumnView::reload() +void DolphinColumnView::selectAll() { - // Due to the reloading of the model all columns will be reset to show - // the same content as the first column. As this is not wanted, all columns - // except of the first column are temporary hidden until the root index can - // be updated again. - m_restoreActiveColumnFocus = false; - QList::iterator start = m_columns.begin() + 1; - QList::iterator end = m_columns.end(); - for (QList::iterator it = start; it != end; ++it) { - ColumnWidget* column = (*it); - if (column->isActive() && column->hasFocus()) { - // because of hiding the column, it will lose the focus - // -> remember that the focus should be restored after reloading - m_restoreActiveColumnFocus = true; - } - column->hide(); - column->setRootIndex(QModelIndex()); - } - - // all columns are hidden, now reload the directory lister - KDirLister* dirLister = m_dolphinModel->dirLister(); - connect(dirLister, SIGNAL(completed()), - this, SLOT(expandToActiveUrl())); - const KUrl baseUrl = m_columns[0]->url(); - dirLister->openUrl(baseUrl, false, true); + activeColumn()->selectAll(); } bool DolphinColumnView::isIndexHidden(const QModelIndex& index) const @@ -526,12 +312,14 @@ QModelIndex DolphinColumnView::moveCursor(CursorAction cursorAction, Qt::Keyboar case MoveLeft: if (m_index > 0) { setActiveColumnIndex(m_index - 1); + m_controller->triggerUrlChangeRequest(activeColumn()->url()); } break; case MoveRight: if (m_index < m_columns.count() - 1) { setActiveColumnIndex(m_index + 1); + m_controller->triggerUrlChangeRequest(m_columns[m_index]->url()); } break; @@ -546,13 +334,12 @@ void DolphinColumnView::setSelection(const QRect& rect, QItemSelectionModel::Sel { Q_UNUSED(rect); Q_UNUSED(flags); - //activeColumn()->setSelection(rect, flags); } QRegion DolphinColumnView::visualRegionForSelection(const QItemSelection& selection) const { Q_UNUSED(selection); - return QRegion(); //activeColumn()->visualRegionForSelection(selection); + return QRegion(); } int DolphinColumnView::horizontalOffset() const @@ -567,7 +354,7 @@ int DolphinColumnView::verticalOffset() const void DolphinColumnView::mousePressEvent(QMouseEvent* event) { - m_controller->triggerActivation(); + m_controller->requestActivation(); QAbstractItemView::mousePressEvent(event); } @@ -576,184 +363,115 @@ void DolphinColumnView::resizeEvent(QResizeEvent* event) QAbstractItemView::resizeEvent(event); layoutColumns(); updateScrollBar(); + assureVisibleActiveColumn(); } -void DolphinColumnView::zoomIn() -{ - if (isZoomInPossible()) { - ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); - // TODO: get rid of K3Icon sizes - switch (settings->iconSize()) { - case K3Icon::SizeSmall: settings->setIconSize(K3Icon::SizeMedium); break; - case K3Icon::SizeMedium: settings->setIconSize(K3Icon::SizeLarge); break; - default: Q_ASSERT(false); break; - } - updateDecorationSize(); - } -} - -void DolphinColumnView::zoomOut() +void DolphinColumnView::wheelEvent(QWheelEvent* event) { - if (isZoomOutPossible()) { - ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); - // TODO: get rid of K3Icon sizes - switch (settings->iconSize()) { - case K3Icon::SizeLarge: settings->setIconSize(K3Icon::SizeMedium); break; - case K3Icon::SizeMedium: settings->setIconSize(K3Icon::SizeSmall); break; - default: Q_ASSERT(false); break; - } - updateDecorationSize(); + // let Ctrl+wheel events propagate to the DolphinView for icon zooming + if ((event->modifiers() & Qt::ControlModifier) == Qt::ControlModifier) { + event->ignore(); + } else { + QAbstractItemView::wheelEvent(event); } } -void DolphinColumnView::triggerItem(const QModelIndex& index) +void DolphinColumnView::setZoomLevel(int level) { - m_controller->triggerItem(index); + const int size = ZoomLevelInfo::iconSizeForZoomLevel(level); + ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); - const Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers(); - if ((modifiers & Qt::ControlModifier) || (modifiers & Qt::ShiftModifier)) { - return; + const bool showPreview = m_controller->dolphinView()->showPreview(); + if (showPreview) { + settings->setPreviewSize(size); + } else { + settings->setIconSize(size); } - const KFileItem item = m_dolphinModel->itemForIndex(m_proxyModel->mapToSource(index)); - if ((item.url() != activeColumn()->url()) && item.isDir()) { - deleteInactiveChildColumns(); - - const KUrl& childUrl = m_controller->url(); - activeColumn()->setChildUrl(childUrl); - - ColumnWidget* column = new ColumnWidget(viewport(), this, childUrl); - column->setModel(model()); - column->setRootIndex(index); - - m_columns.append(column); - - setActiveColumnIndex(m_index + 1); - - // Before invoking layoutColumns() the column must be shown. To prevent - // a flickering the initial geometry is set to be invisible. - column->setGeometry(QRect(-1, -1, 1, 1)); - column->show(); - - layoutColumns(); - updateScrollBar(); - assureVisibleActiveColumn(); - } + updateDecorationSize(showPreview); } void DolphinColumnView::moveContentHorizontally(int x) { - m_contentX = -x; + m_contentX = isRightToLeft() ? +x : -x; layoutColumns(); } -void DolphinColumnView::showColumn(const KUrl& url) +void DolphinColumnView::updateDecorationSize(bool showPreview) { - if (!m_columns[0]->url().isParentOf(url)) { - // the URL is no child URL of the column view, hence do nothing - return; - } - - int columnIndex = 0; - foreach (ColumnWidget* column, m_columns) { - if (column->url() == url) { - // the column represents already the requested URL, hence activate it - requestActivation(column); - return; - } else if (!column->url().isParentOf(url)) { - // the column is no parent of the requested URL, hence it must - // be deleted and a new column must be loaded - if (columnIndex > 0) { - setActiveColumnIndex(columnIndex - 1); - deleteInactiveChildColumns(); - } + ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); + const int iconSize = showPreview ? settings->previewSize() : settings->iconSize(); + const QSize size(iconSize, iconSize); + setIconSize(size); - const QModelIndex dirIndex = m_dolphinModel->indexForUrl(url); - if (dirIndex.isValid()) { - triggerItem(m_proxyModel->mapFromSource(dirIndex)); - } - return; + foreach (QObject* object, viewport()->children()) { + if (object->inherits("QListView")) { + DolphinColumnWidget* widget = static_cast(object); + widget->setDecorationSize(size); } - ++columnIndex; } - // no existing column has been replaced and a new column must be created - const QModelIndex dirIndex = m_dolphinModel->indexForUrl(url); - if (dirIndex.isValid()) { - triggerItem(m_proxyModel->mapFromSource(dirIndex)); - } + doItemsLayout(); } -void DolphinColumnView::updateDecorationSize() +void DolphinColumnView::updateColumnsBackground(bool active) { - ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); - const int iconSize = settings->iconSize(); - - foreach (QObject* object, viewport()->children()) { - if (object->inherits("QListView")) { - ColumnWidget* widget = static_cast(object); - widget->setDecorationSize(QSize(iconSize, iconSize)); - } + if (active == m_active) { + return; } - m_controller->setZoomInPossible(isZoomInPossible()); - m_controller->setZoomOutPossible(isZoomOutPossible()); + m_active = active; - doItemsLayout(); + // dim the background of the viewport + const QPalette::ColorRole role = viewport()->backgroundRole(); + QColor background = viewport()->palette().color(role); + background.setAlpha(0); // make background transparent + + QPalette palette = viewport()->palette(); + palette.setColor(role, background); + viewport()->setPalette(palette); + + foreach (DolphinColumnWidget* column, m_columns) { + column->updateBackground(); + } } -void DolphinColumnView::expandToActiveUrl() +void DolphinColumnView::slotSortingChanged(DolphinView::Sorting sorting) { - const int lastIndex = m_columns.count() - 1; - Q_ASSERT(lastIndex >= 0); - const KUrl& activeUrl = m_columns[lastIndex]->url(); - const KUrl baseUrl = m_dolphinModel->dirLister()->url(); - if (baseUrl.isParentOf(activeUrl) && (baseUrl != activeUrl)) { - m_dolphinModel->expandToUrl(activeUrl); - reloadColumns(); + foreach (DolphinColumnWidget* column, m_columns) { + column->setSorting(sorting); } } -void DolphinColumnView::triggerReloadColumns(const QModelIndex& index) +void DolphinColumnView::slotSortOrderChanged(Qt::SortOrder order) { - Q_UNUSED(index); - disconnect(m_dolphinModel, SIGNAL(expand(const QModelIndex&)), - this, SLOT(triggerReloadColumns(const QModelIndex&))); - // the reloading of the columns may not be done in the context of this slot - QMetaObject::invokeMethod(this, "reloadColumns", Qt::QueuedConnection); -} - -void DolphinColumnView::reloadColumns() -{ - const int end = m_columns.count() - 2; // next to last column - for (int i = 0; i <= end; ++i) { - ColumnWidget* nextColumn = m_columns[i + 1]; - const QModelIndex rootIndex = nextColumn->rootIndex(); - if (!rootIndex.isValid()) { - const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_columns[i]->childUrl()); - const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); - if (proxyIndex.isValid()) { - nextColumn->setRootIndex(proxyIndex); - nextColumn->show(); - if (nextColumn->isActive() && m_restoreActiveColumnFocus) { - nextColumn->setFocus(); - m_restoreActiveColumnFocus = false; - } - } - } + foreach (DolphinColumnWidget* column, m_columns) { + column->setSortOrder(order); } } -bool DolphinColumnView::isZoomInPossible() const +void DolphinColumnView::slotSortFoldersFirstChanged(bool foldersFirst) { - ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); - return settings->iconSize() < K3Icon::SizeLarge; + foreach (DolphinColumnWidget* column, m_columns) { + column->setSortFoldersFirst(foldersFirst); + } } -bool DolphinColumnView::isZoomOutPossible() const +void DolphinColumnView::slotShowHiddenFilesChanged() { - ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); - return settings->iconSize() > K3Icon::SizeSmall; + const bool show = m_controller->dolphinView()->showHiddenFiles(); + foreach (DolphinColumnWidget* column, m_columns) { + column->setShowHiddenFiles(show); + } +} + +void DolphinColumnView::slotShowPreviewChanged() +{ + const bool show = m_controller->dolphinView()->showPreview(); + updateDecorationSize(show); + foreach (DolphinColumnWidget* column, m_columns) { + column->setShowPreview(show); + } } void DolphinColumnView::setActiveColumnIndex(int index) @@ -770,26 +488,45 @@ void DolphinColumnView::setActiveColumnIndex(int index) m_index = index; m_columns[m_index]->setActive(true); - m_controller->setUrl(m_columns[m_index]->url()); + assureVisibleActiveColumn(); } void DolphinColumnView::layoutColumns() { - int x = m_contentX; + const int gap = 4; + ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); const int columnWidth = settings->columnWidth(); - foreach (ColumnWidget* column, m_columns) { - column->setGeometry(QRect(x, 0, columnWidth, viewport()->height())); - x += columnWidth; + + QRect emptyViewportRect; + if (isRightToLeft()) { + int x = viewport()->width() - columnWidth + m_contentX; + foreach (DolphinColumnWidget* column, m_columns) { + column->setGeometry(QRect(x, 0, columnWidth - gap, viewport()->height())); + x -= columnWidth; + } + emptyViewportRect = QRect(0, 0, x + columnWidth - gap, viewport()->height()); + } else { + int x = m_contentX; + foreach (DolphinColumnWidget* column, m_columns) { + column->setGeometry(QRect(x, 0, columnWidth - gap, viewport()->height())); + x += columnWidth; + } + emptyViewportRect = QRect(x, 0, viewport()->width() - x - gap, viewport()->height()); + } + + if (emptyViewportRect.isValid()) { + m_emptyViewport->show(); + m_emptyViewport->setGeometry(emptyViewportRect); + } else { + m_emptyViewport->hide(); } } void DolphinColumnView::updateScrollBar() { - int contentWidth = 0; - foreach (ColumnWidget* column, m_columns) { - contentWidth += column->width(); - } + ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); + const int contentWidth = m_columns.count() * settings->columnWidth(); horizontalScrollBar()->setPageStep(contentWidth); horizontalScrollBar()->setRange(0, contentWidth - viewport()->width()); @@ -799,31 +536,43 @@ void DolphinColumnView::assureVisibleActiveColumn() { const int viewportWidth = viewport()->width(); const int x = activeColumn()->x(); - const int width = activeColumn()->width(); + + ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); + const int width = settings->columnWidth(); + if (x + width > viewportWidth) { - int newContentX = m_contentX - x - width + viewportWidth; - if (newContentX > 0) { - newContentX = 0; + const int newContentX = m_contentX - x - width + viewportWidth; + if (isRightToLeft()) { + m_animation->setFrameRange(m_contentX, newContentX); + } else { + m_animation->setFrameRange(-m_contentX, -newContentX); + } + if (m_animation->state() != QTimeLine::Running) { + m_animation->start(); } - m_animation->setFrameRange(-m_contentX, -newContentX); - m_animation->start(); } else if (x < 0) { const int newContentX = m_contentX - x; - m_animation->setFrameRange(-m_contentX, -newContentX); - m_animation->start(); + if (isRightToLeft()) { + m_animation->setFrameRange(m_contentX, newContentX); + } else { + m_animation->setFrameRange(-m_contentX, -newContentX); + } + if (m_animation->state() != QTimeLine::Running) { + m_animation->start(); + } } } -void DolphinColumnView::requestActivation(ColumnWidget* column) +void DolphinColumnView::requestActivation(DolphinColumnWidget* column) { + m_controller->setItemView(column); if (column->isActive()) { assureVisibleActiveColumn(); } else { int index = 0; - foreach (ColumnWidget* currColumn, m_columns) { + foreach (DolphinColumnWidget* currColumn, m_columns) { if (currColumn == column) { setActiveColumnIndex(index); - assureVisibleActiveColumn(); return; } ++index; @@ -831,14 +580,42 @@ void DolphinColumnView::requestActivation(ColumnWidget* column) } } -void DolphinColumnView::deleteInactiveChildColumns() +void DolphinColumnView::removeAllColumns() { - QList::iterator start = m_columns.begin() + m_index + 1; - QList::iterator end = m_columns.end(); - for (QList::iterator it = start; it != end; ++it) { - (*it)->deleteLater(); + QList::iterator start = m_columns.begin() + 1; + QList::iterator end = m_columns.end(); + for (QList::iterator it = start; it != end; ++it) { + deleteColumn(*it); } m_columns.erase(start, end); + m_index = 0; + m_columns[0]->setActive(true); + assureVisibleActiveColumn(); +} + +QPoint DolphinColumnView::columnPosition(DolphinColumnWidget* column, const QPoint& point) const +{ + const QPoint topLeft = column->frameGeometry().topLeft(); + return QPoint(point.x() - topLeft.x(), point.y() - topLeft.y()); +} + +void DolphinColumnView::deleteColumn(DolphinColumnWidget* column) +{ + if (column != 0) { + if (m_controller->itemView() == column) { + m_controller->setItemView(0); + } + // deleteWhenNotDragSource(column) does not necessarily delete column, + // and we want its preview generator destroyed immediately. + column->m_previewGenerator->deleteLater(); + column->m_previewGenerator = 0; + column->hide(); + // Prevent automatic destruction of column when this DolphinColumnView + // is destroyed. + column->setParent(0); + column->disconnect(); + emit requestColumnDeletion(column); + } } #include "dolphincolumnview.moc"