-/*
- * General implementation notes
- * ----------------------------
- *
- * In Qt4.3 the QColumnView widget has a default behavior regarding the
- * active column and the selection handling, which leads to some usability
- * problems within Dolphin:
- *
- * - No matter which mouse button has been clicked: If the mouse is above
- * a folder, the folder content will be loaded in the next column. The problem
- * is that this column also will marked as 'active column' within QColumnView,
- * hence it is not possible to select more than one folder within a column.
- *
- * - The currently opened folder is not always marked in the left column when
- * doing drag & drop and selections inside other columns.
- *
- * - The currently active column is visually not recognizable.
- *
- * - It is not possible for derived classes to remove inactive columns.
- *
- * DolphinView tries to bypass those points, but this required some workarounds:
- *
- * - QColumnView internally maps the selection model from the ColumnView to the
- * active column. As the active column from the Dolphin perspective is different
- * as the active column from QColumnView, the selection model is adjusted on
- * each interaction by the methods QColumnWidget::obtainSelectionModel(),
- * QColumnWidget::releaseSelectionModel() and QColumnView::requestSelectionModel().
- * QColumnView offers no hook to adjust this behavior, so those methods have to
- * be invoked throughout the code...
- *
- * - Some copy/paste code from QColumnView is part of DolphinColumnView::createColumn(), but Qt 4.4
- * will offer a solution for this.
- *
- * - The mousePressEvent() has been customized to prevent that folders are loaded on each
- * mouse click.
- *
- * We'll try to give some input for Trolltech if the Dolphin solution is stable enough, so hopefully
- * some workarounds can be removed when switching to Qt 4.4 or later.
- */
-
-/**
- * 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;
-
- inline const KUrl& url() const;
-
- /**
- * Obtains the selection model from the column view. This assures that
- * selections of the column view will always applied to the active column.
- */
- void obtainSelectionModel();
-
- /**
- * Releases the selection model from the column view and replaces it by
- * a custom selection model.
- */
- void releaseSelectionModel();
-
-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 mousePressEvent(QMouseEvent* event);
- virtual void mouseMoveEvent(QMouseEvent* event);
- virtual void mouseReleaseEvent(QMouseEvent* event);
- virtual void paintEvent(QPaintEvent* event);
- virtual void contextMenuEvent(QContextMenuEvent* event);
-
-protected slots:
- 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;
- bool m_swallowMouseMoveEvents;
- DolphinColumnView* m_view;
- KUrl m_url;
- 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_swallowMouseMoveEvents(false),
- m_view(columnView),
- m_url(url),
- m_childUrl(),
- m_dragging(false),
- m_dropRect()
-{
- setMouseTracking(true);
- viewport()->setAttribute(Qt::WA_Hover);
-
- // 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);
-
- activate();
-}
-
-ColumnWidget::~ColumnWidget()
-{
-}
-
-void ColumnWidget::setDecorationSize(const QSize& size)
-{
- m_viewOptions.decorationSize = size;
- doItemsLayout();
+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);
+
+ connect(this, SIGNAL(viewportEntered()),
+ 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(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)));
+
+ DolphinColumnWidget* column = new DolphinColumnWidget(viewport(), this, m_controller->url());
+ m_columns.append(column);
+ setActiveColumnIndex(0);
+
+ m_emptyViewport = new QFrame(viewport());
+ m_emptyViewport->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
+
+ updateDecorationSize(view->showPreview());
+ updateColumnsBackground(true);