#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 <kcolorutils.h>
-#include <kcolorscheme.h>
-#include <kdirlister.h>
+#include <kfilepreviewgenerator.h>
-#include <QAbstractProxyModel>
-#include <QApplication>
#include <QPoint>
#include <QScrollBar>
-#include <QTimer>
#include <QTimeLine>
-/**
- * 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);
- 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.
- */
- void setChildUrl(const KUrl& url);
- const KUrl& childUrl() const;
-
- /** Sets the directory URL that is shown inside the column widget. */
- void setUrl(const KUrl& url);
-
- /** Returns the directory URL that is shown inside the column widget. */
- 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);
- setDragDropMode(QAbstractItemView::DragDrop);
- setDropIndicatorShown(false);
- setFocusPolicy(Qt::NoFocus);
-
-// TODO: Remove this check when 4.3.2 is released and KDE requires it... this
-// check avoids a division by zero happening on versions before 4.3.1.
-// Right now KDE in theory can be shipped with Qt 4.3.0 and above.
-// ereslibre
-#if (QT_VERSION >= QT_VERSION_CHECK(4, 3, 2) || defined(QT_KDE_QT_COPY))
- setVerticalScrollMode(QListView::ScrollPerPixel);
- setHorizontalScrollMode(QListView::ScrollPerPixel);
-#endif
-
- // 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);
-
- m_viewOptions.showDecorationSelected = true;
-
- 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;
-
- if (active) {
- activate();
- } else {
- deactivate();
- }
-}
-
-inline bool ColumnWidget::isActive() const
-{
- return m_active;
-}
-
-inline void ColumnWidget::setChildUrl(const KUrl& url)
-{
- m_childUrl = url;
-}
-
-inline const KUrl& ColumnWidget::childUrl() const
-{
- return m_childUrl;
-}
-
-inline void ColumnWidget::setUrl(const KUrl& url)
-{
- m_url = url;
-}
-
-inline const KUrl& ColumnWidget::url() const
-{
- return m_url;
-}
-
-inline QStyleOptionViewItem ColumnWidget::viewOptions() const
-{
- return m_viewOptions;
-}
-
-void ColumnWidget::dragEnterEvent(QDragEnterEvent* event)
-{
- if (event->mimeData()->hasUrls()) {
- event->acceptProposedAction();
- }
-
- m_dragging = true;
-}
-
-void ColumnWidget::dragLeaveEvent(QDragLeaveEvent* event)
-{
- QListView::dragLeaveEvent(event);
-
- // TODO: remove this code when the issue #160611 is solved in Qt 4.4
- m_dragging = false;
- setDirtyRegion(m_dropRect);
-}
-
-void ColumnWidget::dragMoveEvent(QDragMoveEvent* event)
-{
- 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);
-}
-
-void ColumnWidget::dropEvent(QDropEvent* event)
-{
- 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;
-}
-
-void ColumnWidget::paintEvent(QPaintEvent* event)
-{
- 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();
-
- QColor color = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color();
- color.setAlpha(32);
- painter.setPen(Qt::NoPen);
- painter.setBrush(color);
- painter.drawRect(itemRect);
-
- 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);
- }
-}
-
-void ColumnWidget::mousePressEvent(QMouseEvent* event)
-{
- if (!m_active) {
- m_view->requestActivation(this);
- }
-
- QListView::mousePressEvent(event);
-}
-
-void ColumnWidget::keyPressEvent(QKeyEvent* event)
-{
- 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->m_controller->triggerItem(currentIndex);
- }
-}
-
-void ColumnWidget::contextMenuEvent(QContextMenuEvent* event)
-{
- 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);
- }
-}
-
-void ColumnWidget::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
-{
- QListView::selectionChanged(selected, deselected);
-
- QItemSelectionModel* selModel = m_view->selectionModel();
- selModel->select(selected, QItemSelectionModel::Select);
- selModel->select(deselected, QItemSelectionModel::Deselect);
-}
-
-void ColumnWidget::activate()
-{
- 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->m_controller, SLOT(triggerItem(const QModelIndex&)));
- } else {
- connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
- m_view->m_controller, 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();
-}
-
-void ColumnWidget::deactivate()
-{
- // 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->m_controller, SLOT(triggerItem(const QModelIndex&)));
- } else {
- disconnect(this, SIGNAL(doubleClicked(const QModelIndex&)),
- m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
- }
-
- 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_active(false),
m_index(-1),
m_contentX(0),
m_columns(),
+ m_emptyViewport(0),
m_animation(0),
- m_dolphinModel(0),
- m_proxyModel(0)
+ m_nameFilter()
{
Q_ASSERT(controller != 0);
setDragDropMode(QAbstractItemView::DragDrop);
setDropIndicatorShown(false);
setSelectionMode(ExtendedSelection);
+ setFocusPolicy(Qt::NoFocus);
+ setFrameShape(QFrame::NoFrame);
+ setLayoutDirection(Qt::LeftToRight);
- 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(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()));
connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
this, SLOT(moveContentHorizontally(int)));
m_animation = new QTimeLine(500, this);
connect(m_animation, SIGNAL(frameChanged(int)), horizontalScrollBar(), SLOT(setValue(int)));
- ColumnWidget* column = new ColumnWidget(viewport(), this, m_controller->url());
+ DolphinColumnWidget* column = new DolphinColumnWidget(viewport(), this, m_controller->url());
m_columns.append(column);
setActiveColumnIndex(0);
- updateDecorationSize();
-
- // 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);
+ m_emptyViewport = new QFrame(viewport());
+ m_emptyViewport->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
- QPalette palette = viewport()->palette();
- palette.setColor(viewport()->backgroundRole(), bgColor);
- viewport()->setPalette(palette);
+ updateDecorationSize(view->showPreview());
+ updateColumnsBackground(true);
}
DolphinColumnView::~DolphinColumnView()
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);
+ foreach (DolphinColumnWidget* column, m_columns) {
+ const QModelIndex index = column->indexAt(columnPosition(column, point));
if (index.isValid()) {
return index;
}
return QModelIndex();
}
+KFileItem DolphinColumnView::itemAt(const QPoint& point) const
+{
+ foreach (DolphinColumnWidget* column, m_columns) {
+ KFileItem item = column->itemAt(columnPosition(column, point));
+ if (!item.isNull()) {
+ return item;
+ }
+ }
+
+ return KFileItem();
+}
+
void DolphinColumnView::scrollTo(const QModelIndex& index, ScrollHint hint)
{
activeColumn()->scrollTo(index, hint);
return activeColumn()->visualRect(index);
}
-void DolphinColumnView::setModel(QAbstractItemModel* model)
+void DolphinColumnView::invertSelection()
{
- if (m_dolphinModel != 0) {
- m_dolphinModel->disconnect(this);
- }
-
- m_proxyModel = static_cast<QAbstractProxyModel*>(model);
- m_dolphinModel = static_cast<DolphinModel*>(m_proxyModel->sourceModel());
- connect(m_dolphinModel, SIGNAL(expand(const QModelIndex&)),
- this, SLOT(triggerReloadColumns(const QModelIndex&)));
+ QItemSelectionModel* selectionModel = activeColumn()->selectionModel();
+ const QAbstractItemModel* itemModel = selectionModel->model();
- KDirLister* dirLister = m_dolphinModel->dirLister();
- connect(dirLister, SIGNAL(completed()),
- this, SLOT(triggerExpandToActiveUrl()));
+ const QModelIndex topLeft = itemModel->index(0, 0);
+ const QModelIndex bottomRight = itemModel->index(itemModel->rowCount() - 1,
+ itemModel->columnCount() - 1);
- activeColumn()->setModel(model);
- QAbstractItemView::setModel(model);
+ const QItemSelection selection(topLeft, bottomRight);
+ selectionModel->select(selection, QItemSelectionModel::Toggle);
}
-void DolphinColumnView::invertSelection()
+void DolphinColumnView::reload()
{
- // TODO: this approach of inverting the selection is quite slow. It should
- // be possible to speedup the implementation by using QItemSelection, but
- // all adempts have failed yet...
-
- ColumnWidget* column = activeColumn();
- QItemSelectionModel* selModel = column->selectionModel();
-
- KDirLister* dirLister = m_dolphinModel->dirLister();
- const KFileItemList list = dirLister->itemsForDir(column->url());
- foreach (const KFileItem item, list) {
- const QModelIndex index = m_dolphinModel->indexForUrl(item.url());
- selModel->select(m_proxyModel->mapFromSource(index), QItemSelectionModel::Toggle);
+ foreach (DolphinColumnWidget* column, m_columns) {
+ column->reload();
}
}
-void DolphinColumnView::reload()
+void DolphinColumnView::setRootUrl(const KUrl& url)
+{
+ removeAllColumns();
+ m_columns[0]->setUrl(url);
+}
+
+void DolphinColumnView::setNameFilter(const QString& nameFilter)
{
- // 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<ColumnWidget*>::iterator start = m_columns.begin() + 1;
- QList<ColumnWidget*>::iterator end = m_columns.end();
- for (QList<ColumnWidget*>::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;
+ if (nameFilter != m_nameFilter) {
+ m_nameFilter = nameFilter;
+ foreach (DolphinColumnWidget* column, m_columns) {
+ column->setNameFilter(nameFilter);
}
- column->hide();
}
+}
- // all columns are hidden, now reload the directory lister
- KDirLister* dirLister = m_dolphinModel->dirLister();
- const KUrl& rootUrl = m_columns[0]->url();
- dirLister->openUrl(rootUrl, KDirLister::Reload);
- updateColumns();
+QString DolphinColumnView::nameFilter() const
+{
+ return m_nameFilter;
+}
+
+KUrl DolphinColumnView::rootUrl() const
+{
+ return m_columns[0]->url();
}
void DolphinColumnView::showColumn(const KUrl& url)
{
- const KUrl& rootUrl = m_columns[0]->url();
- if (!rootUrl.isParentOf(url)) {
- // the URL is no child URL of the column view, hence clear all columns
- // and reset the root column
- QList<ColumnWidget*>::iterator start = m_columns.begin() + 1;
- QList<ColumnWidget*>::iterator end = m_columns.end();
- for (QList<ColumnWidget*>::iterator it = start; it != end; ++it) {
- (*it)->deleteLater();
- }
- m_columns.erase(start, end);
- m_index = 0;
- m_columns[0]->setActive(true);
- m_columns[0]->setUrl(url);
- assureVisibleActiveColumn();
+ if (!rootUrl().isParentOf(url)) {
+ setRootUrl(url);
return;
}
- KDirLister* dirLister = m_dolphinModel->dirLister();
- const KUrl dirListerUrl = dirLister->url();
- if (dirListerUrl != rootUrl) {
- // It is possible that root URL of the directory lister is adjusted
- // after creating the column widget (e. g. when restoring the history
- // having a different root URL than the controller indicates).
- m_columns[0]->setUrl(dirListerUrl);
- }
-
int columnIndex = 0;
- foreach (ColumnWidget* column, m_columns) {
+ 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<ColumnWidget*>::iterator start = m_columns.begin() + columnIndex;
- QList<ColumnWidget*>::iterator end = m_columns.end();
- for (QList<ColumnWidget*>::iterator it = start; it != end; ++it) {
- (*it)->deleteLater();
+ QList<DolphinColumnWidget*>::iterator start = m_columns.begin() + columnIndex;
+ QList<DolphinColumnWidget*>::iterator end = m_columns.end();
+ for (QList<DolphinColumnWidget*>::iterator it = start; it != end; ++it) {
+ deleteColumn(*it);
}
m_columns.erase(start, end);
++slashIndex;
const KUrl childUrl = KUrl(path);
- const QModelIndex dirIndex = m_dolphinModel->indexForUrl(KUrl(path));
- const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
-
m_columns[columnIndex]->setChildUrl(childUrl);
columnIndex++;
- ColumnWidget* column = new ColumnWidget(viewport(), this, childUrl);
- column->setModel(model());
- column->setRootIndex(proxyIndex);
+ DolphinColumnWidget* column = new DolphinColumnWidget(viewport(), this, childUrl);
+ const QString filter = nameFilter();
+ if (!filter.isEmpty()) {
+ column->setNameFilter(filter);
+ }
column->setActive(false);
m_columns.append(column);
column->show();
layoutColumns();
updateScrollBar();
-
- // the layout is finished, now let the column be invisible until it
- // gets a valid root index due to expandToActiveUrl()
- column->hide();
}
}
assureVisibleActiveColumn();
}
+void DolphinColumnView::editItem(const KFileItem& item)
+{
+ activeColumn()->editItem(item);
+}
+
+KFileItemList DolphinColumnView::selectedItems() const
+{
+ return activeColumn()->selectedItems();
+}
+
+QMimeData* DolphinColumnView::selectionMimeData() const
+{
+ return activeColumn()->selectionMimeData();
+}
+
void DolphinColumnView::selectAll()
{
activeColumn()->selectAll();
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;
{
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
void DolphinColumnView::mousePressEvent(QMouseEvent* event)
{
- m_controller->triggerActivation();
+ m_controller->requestActivation();
QAbstractItemView::mousePressEvent(event);
}
QAbstractItemView::resizeEvent(event);
layoutColumns();
updateScrollBar();
+ assureVisibleActiveColumn();
}
-void DolphinColumnView::zoomIn()
+void DolphinColumnView::wheelEvent(QWheelEvent* event)
{
- if (isZoomInPossible()) {
- ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
- switch (settings->iconSize()) {
- case KIconLoader::SizeSmall: settings->setIconSize(KIconLoader::SizeMedium); break;
- case KIconLoader::SizeMedium: settings->setIconSize(KIconLoader::SizeLarge); 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::zoomOut()
+void DolphinColumnView::setZoomLevel(int level)
{
- if (isZoomOutPossible()) {
- ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
- switch (settings->iconSize()) {
- case KIconLoader::SizeLarge: settings->setIconSize(KIconLoader::SizeMedium); break;
- case KIconLoader::SizeMedium: settings->setIconSize(KIconLoader::SizeSmall); break;
- default: Q_ASSERT(false); break;
- }
- updateDecorationSize();
+ const int size = ZoomLevelInfo::iconSizeForZoomLevel(level);
+ ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
+
+ const bool showPreview = m_controller->dolphinView()->showPreview();
+ if (showPreview) {
+ settings->setPreviewSize(size);
+ } else {
+ settings->setIconSize(size);
}
+
+ updateDecorationSize(showPreview);
}
void DolphinColumnView::moveContentHorizontally(int x)
layoutColumns();
}
-void DolphinColumnView::updateDecorationSize()
+void DolphinColumnView::updateDecorationSize(bool showPreview)
{
ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
- const int iconSize = settings->iconSize();
+ const int iconSize = showPreview ? settings->previewSize() : settings->iconSize();
+ const QSize size(iconSize, iconSize);
+ setIconSize(size);
foreach (QObject* object, viewport()->children()) {
if (object->inherits("QListView")) {
- ColumnWidget* widget = static_cast<ColumnWidget*>(object);
- widget->setDecorationSize(QSize(iconSize, iconSize));
+ DolphinColumnWidget* widget = static_cast<DolphinColumnWidget*>(object);
+ widget->setDecorationSize(size);
}
}
- m_controller->setZoomInPossible(isZoomInPossible());
- m_controller->setZoomOutPossible(isZoomOutPossible());
-
doItemsLayout();
}
-void DolphinColumnView::expandToActiveUrl()
+void DolphinColumnView::updateColumnsBackground(bool active)
{
- const int lastIndex = m_columns.count() - 1;
- Q_ASSERT(lastIndex >= 0);
- const KUrl& activeUrl = m_columns[lastIndex]->url();
- const KUrl rootUrl = m_dolphinModel->dirLister()->url();
- const bool expand = rootUrl.isParentOf(activeUrl)
- && !rootUrl.equals(activeUrl, KUrl::CompareWithoutTrailingSlash);
- if (expand) {
- m_dolphinModel->expandToUrl(activeUrl);
+ if (active == m_active) {
+ return;
+ }
+
+ m_active = active;
+
+ // 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();
}
- updateColumns();
}
-void DolphinColumnView::triggerUpdateColumns(const QModelIndex& index)
+void DolphinColumnView::slotSortingChanged(DolphinView::Sorting sorting)
{
- Q_UNUSED(index);
- // the updating of the columns may not be done in the context of this slot
- QMetaObject::invokeMethod(this, "updateColumns", Qt::QueuedConnection);
+ foreach (DolphinColumnWidget* column, m_columns) {
+ column->setSorting(sorting);
+ }
}
-void DolphinColumnView::updateColumns()
+void DolphinColumnView::slotSortOrderChanged(Qt::SortOrder order)
{
- 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()) {
- nextColumn->show();
- } else {
- 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);
}
}
-void DolphinColumnView::triggerExpandToActiveUrl()
+void DolphinColumnView::slotSortFoldersFirstChanged(bool foldersFirst)
{
- QMetaObject::invokeMethod(this, "expandToActiveUrl", Qt::QueuedConnection);
+ foreach (DolphinColumnWidget* column, m_columns) {
+ column->setSortFoldersFirst(foldersFirst);
+ }
}
-bool DolphinColumnView::isZoomInPossible() const
+void DolphinColumnView::slotShowHiddenFilesChanged()
{
- ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
- return settings->iconSize() < KIconLoader::SizeLarge;
+ const bool show = m_controller->dolphinView()->showHiddenFiles();
+ foreach (DolphinColumnWidget* column, m_columns) {
+ column->setShowHiddenFiles(show);
+ }
}
-bool DolphinColumnView::isZoomOutPossible() const
+void DolphinColumnView::slotShowPreviewChanged()
{
- ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
- return settings->iconSize() > KIconLoader::SizeSmall;
+ const bool show = m_controller->dolphinView()->showPreview();
+ updateDecorationSize(show);
+ foreach (DolphinColumnWidget* column, m_columns) {
+ column->setShowPreview(show);
+ }
}
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()
{
+ const int gap = 4;
+
ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
const int columnWidth = settings->columnWidth();
+
+ QRect emptyViewportRect;
if (isRightToLeft()) {
int x = viewport()->width() - columnWidth + m_contentX;
- foreach (ColumnWidget* column, m_columns) {
- column->setGeometry(QRect(x, 0, columnWidth, viewport()->height()));
+ 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 (ColumnWidget* column, m_columns) {
- column->setGeometry(QRect(x, 0, columnWidth, viewport()->height()));
+ 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());
{
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) {
const int newContentX = m_contentX - x - width + viewportWidth;
if (isRightToLeft()) {
} else {
m_animation->setFrameRange(-m_contentX, -newContentX);
}
- m_animation->start();
+ if (m_animation->state() != QTimeLine::Running) {
+ m_animation->start();
+ }
} else if (x < 0) {
const int newContentX = m_contentX - x;
if (isRightToLeft()) {
} else {
m_animation->setFrameRange(-m_contentX, -newContentX);
}
- m_animation->start();
+ 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);
return;
}
}
+void DolphinColumnView::removeAllColumns()
+{
+ QList<DolphinColumnWidget*>::iterator start = m_columns.begin() + 1;
+ QList<DolphinColumnWidget*>::iterator end = m_columns.end();
+ for (QList<DolphinColumnWidget*>::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"