-/**
- * 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. */
- 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);
- setDragDropMode(QAbstractItemView::DragDrop);
- setDropIndicatorShown(false);
- setFocusPolicy(Qt::NoFocus);
-
- // 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;
-
- 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;
-}
-
-const KUrl& ColumnWidget::url() const
-{
- return m_url;
-}
-
-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();
-}
-
-// ---
-