diff options
| author | Peter Penz <[email protected]> | 2011-11-26 01:05:58 +0100 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-11-26 01:16:31 +0100 |
| commit | 362817d1834f2ada3ea4552a25fa39bbbb540f8c (patch) | |
| tree | 706f316224397b44f95516ba857bb8d380a0bb47 /src/views | |
| parent | bf1a8f989e75a50c9a5c839e69573a87ab9ad934 (diff) | |
Folders Panel fixes
The following functionality from Dolphin 1.x has
been ported to the new view-engine:
- Allow expanding/collapsing of items
- Automatically select the current item
- Context menu for items
Related improvements to the view-engine:
- Make the expanding/collapsing interface already accessible
in the base classes KItemModelBase and KItemListView. If
no expanding/collapsing is supported at all by derived models
(which is usually the default case) simply not reimplementing
those 3 methods is sufficient and it does not introduce an
additional complexity like in QAbstractItemModel/QModelIndex.
- Automatically handle the expanding/collapsing in KItemListController.
This also includes the key-handling, which is quite special for
expandable items.
- Don't let KItemListView automatically scroll to the current item
if the current item got changed. The automatic scrolling should
only be done if the current item has been changed by the user.
Hence this functionality has been moved to the KItemListController
which currently only triggers the automatic scrolling if the current
item has been changed by the keyboard (we might extend the usecases
later if required).
Diffstat (limited to 'src/views')
| -rw-r--r-- | src/views/dolphinview.cpp | 12 | ||||
| -rw-r--r-- | src/views/dolphinview.h | 1 | ||||
| -rw-r--r-- | src/views/dolphinviewautoscroller.cpp | 223 | ||||
| -rw-r--r-- | src/views/dolphinviewautoscroller.h | 79 |
4 files changed, 0 insertions, 315 deletions
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index c5c13e97f..379cd9f90 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -141,7 +141,6 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) : connect(controller, SIGNAL(itemContextMenuRequested(int,QPointF)), this, SLOT(slotItemContextMenuRequested(int,QPointF))); connect(controller, SIGNAL(viewContextMenuRequested(QPointF)), this, SLOT(slotViewContextMenuRequested(QPointF))); connect(controller, SIGNAL(headerContextMenuRequested(QPointF)), this, SLOT(slotHeaderContextMenuRequested(QPointF))); - connect(controller, SIGNAL(itemExpansionToggleClicked(int)), this, SLOT(slotItemExpansionToggleClicked(int))); connect(controller, SIGNAL(itemHovered(int)), this, SLOT(slotItemHovered(int))); connect(controller, SIGNAL(itemUnhovered(int)), this, SLOT(slotItemUnhovered(int))); connect(controller, SIGNAL(itemDropEvent(int,QGraphicsSceneDragDropEvent*)), this, SLOT(slotItemDropEvent(int,QGraphicsSceneDragDropEvent*))); @@ -788,17 +787,6 @@ void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos) delete menu.data(); } -void DolphinView::slotItemExpansionToggleClicked(int index) -{ - // TODO: When doing a model->setExpanded(false) it should - // be checked here whether the current index is part of the - // closed sub-tree. If this is the case, the current index - // should be adjusted to the parent index. - KFileItemModel* model = fileItemModel(); - const bool expanded = model->isExpanded(index); - model->setExpanded(index, !expanded); -} - void DolphinView::slotItemHovered(int index) { const KFileItem item = fileItemModel()->fileItem(index); diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h index 2bbdf2b71..e0be25e42 100644 --- a/src/views/dolphinview.h +++ b/src/views/dolphinview.h @@ -559,7 +559,6 @@ private slots: void slotItemContextMenuRequested(int index, const QPointF& pos); void slotViewContextMenuRequested(const QPointF& pos); void slotHeaderContextMenuRequested(const QPointF& pos); - void slotItemExpansionToggleClicked(int index); void slotItemHovered(int index); void slotItemUnhovered(int index); void slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event); diff --git a/src/views/dolphinviewautoscroller.cpp b/src/views/dolphinviewautoscroller.cpp deleted file mode 100644 index 5b338cc37..000000000 --- a/src/views/dolphinviewautoscroller.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Peter Penz <[email protected]> * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "dolphinviewautoscroller.h" - -#include <QAbstractItemView> -#include <QApplication> -#include <QCursor> -#include <QEvent> -#include <QMouseEvent> -#include <QScrollBar> -#include <QTimer> -#include <math.h> - -DolphinViewAutoScroller::DolphinViewAutoScroller(QAbstractItemView* parent) : - QObject(parent), - m_rubberBandSelection(false), - m_keyPressed(false), - m_initializedTimestamp(false), - m_horizontalScrollInc(0), - m_verticalScrollInc(0), - m_itemView(parent), - m_timer(0), - m_timestamp() -{ - m_itemView->setAutoScroll(false); - m_itemView->viewport()->installEventFilter(this); - m_itemView->installEventFilter(this); - - m_timer = new QTimer(this); - m_timer->setSingleShot(false); - m_timer->setInterval(1000 / 25); // 25 frames per second - connect(m_timer, SIGNAL(timeout()), this, SLOT(scrollViewport())); -} - -DolphinViewAutoScroller::~DolphinViewAutoScroller() -{ -} - -bool DolphinViewAutoScroller::isActive() const -{ - return m_timer->isActive(); -} - -void DolphinViewAutoScroller::handleCurrentIndexChange(const QModelIndex& current, - const QModelIndex& previous) -{ - // When the autoscroller is inactive and a key has been pressed, it must be - // assured that the current item stays visible. The check whether the previous - // item is valid is important because of #197951. The keypress check is done - // because of #199833. - if (current.isValid() && (previous.isValid() || m_keyPressed) && !isActive()) { - m_itemView->scrollTo(current); - } -} - -bool DolphinViewAutoScroller::eventFilter(QObject* watched, QEvent* event) -{ - if (watched == m_itemView->viewport()) { - switch (event->type()) { - case QEvent::MouseButtonPress: - if (static_cast<QMouseEvent*>(event)->button() == Qt::LeftButton) { - m_rubberBandSelection = true; - } - break; - - case QEvent::MouseMove: - if (m_rubberBandSelection) { - triggerAutoScroll(); - } - break; - - case QEvent::MouseButtonRelease: - m_rubberBandSelection = false; - stopAutoScroll(); - break; - - case QEvent::DragEnter: - case QEvent::DragMove: - m_rubberBandSelection = false; - triggerAutoScroll(); - break; - - case QEvent::Drop: - case QEvent::DragLeave: - m_rubberBandSelection = false; - stopAutoScroll(); - break; - - default: - break; - } - } else if (watched == m_itemView) { - switch (event->type()) { - case QEvent::KeyPress: - m_keyPressed = true; - break; - - case QEvent::KeyRelease: - m_keyPressed = false; - break; - - default: - break; - } - } - - return QObject::eventFilter(watched, event); -} - -void DolphinViewAutoScroller::scrollViewport() -{ - if (m_timestamp.elapsed() < QApplication::startDragTime()) { - return; - } - - QScrollBar* verticalScrollBar = m_itemView->verticalScrollBar(); - if (verticalScrollBar) { - const int value = verticalScrollBar->value(); - verticalScrollBar->setValue(value + m_verticalScrollInc); - - } - QScrollBar* horizontalScrollBar = m_itemView->horizontalScrollBar(); - if (horizontalScrollBar) { - const int value = horizontalScrollBar->value(); - horizontalScrollBar->setValue(value + m_horizontalScrollInc); - - } - - if (m_rubberBandSelection) { - // The scrolling does not lead to an update of the rubberband - // selection. Fake a mouse move event to let the QAbstractItemView - // update the rubberband. - QWidget* viewport = m_itemView->viewport(); - const QPoint pos = viewport->mapFromGlobal(QCursor::pos()); - QMouseEvent event(QEvent::MouseMove, pos, Qt::LeftButton, Qt::LeftButton, QApplication::keyboardModifiers()); - QCoreApplication::sendEvent(viewport, &event); - } -} - -void DolphinViewAutoScroller::triggerAutoScroll() -{ - const bool verticalScrolling = m_itemView->verticalScrollBar() && - m_itemView->verticalScrollBar()->isVisible(); - const bool horizontalScrolling = m_itemView->horizontalScrollBar() && - m_itemView->horizontalScrollBar()->isVisible(); - if (!verticalScrolling && !horizontalScrolling) { - // no scrollbars are shown at all, so no autoscrolling is necessary - stopAutoScroll(); - return; - } - - QWidget* viewport = m_itemView->viewport(); - const QPoint pos = viewport->mapFromGlobal(QCursor::pos()); - if (verticalScrolling) { - m_verticalScrollInc = calculateScrollIncrement(pos.y(), viewport->height()); - } - if (horizontalScrolling) { - m_horizontalScrollInc = calculateScrollIncrement(pos.x(), viewport->width()); - } - - if (m_timer->isActive()) { - if ((m_horizontalScrollInc == 0) && (m_verticalScrollInc == 0)) { - stopAutoScroll(); - } - } else if ((m_horizontalScrollInc != 0) || (m_verticalScrollInc != 0)) { - if (!m_initializedTimestamp) { - m_initializedTimestamp = true; - m_timestamp.start(); - } - m_timer->start(); - } -} - -void DolphinViewAutoScroller::stopAutoScroll() -{ - m_timer->stop(); - m_horizontalScrollInc = 0; - m_verticalScrollInc = 0; - m_initializedTimestamp = false; -} - -int DolphinViewAutoScroller::calculateScrollIncrement(int cursorPos, int rangeSize) const -{ - int inc = 0; - - const int minSpeed = 4; - const int maxSpeed = 768; - const int speedLimiter = 48; - const int autoScrollBorder = 64; - - if (cursorPos < autoScrollBorder) { - inc = -minSpeed + qAbs(cursorPos - autoScrollBorder) * (cursorPos - autoScrollBorder) / speedLimiter; - if (inc < -maxSpeed) { - inc = -maxSpeed; - } - } else if (cursorPos > rangeSize - autoScrollBorder) { - inc = minSpeed + qAbs(cursorPos - rangeSize + autoScrollBorder) * (cursorPos - rangeSize + autoScrollBorder) / speedLimiter; - if (inc > maxSpeed) { - inc = maxSpeed; - } - } - - return inc; -} - -#include "dolphinviewautoscroller.moc" diff --git a/src/views/dolphinviewautoscroller.h b/src/views/dolphinviewautoscroller.h deleted file mode 100644 index 04d91a8f6..000000000 --- a/src/views/dolphinviewautoscroller.h +++ /dev/null @@ -1,79 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Peter Penz <[email protected]> * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef DOLPHINVIEWAUTOSCROLLER_H -#define DOLPHINVIEWAUTOSCROLLER_H - -#include <QTime> -#include <QObject> - -class QAbstractItemView; -class QModelIndex; -class QTimer; - -/** - * @brief Assures that an autoscrolling is done for item views. - * - * This is a workaround as QAbstractItemView::setAutoScroll() is not usable - * when selecting items (see Qt issue #214542). - */ -class DolphinViewAutoScroller : public QObject -{ - Q_OBJECT - -public: - DolphinViewAutoScroller(QAbstractItemView* parent); - virtual ~DolphinViewAutoScroller(); - bool isActive() const; - - /** - * Must be invoked by the parent item view, when QAbstractItemView::currentChanged() - * has been called. Assures that the current item stays visible when it has been - * changed by the keyboard. - */ - void handleCurrentIndexChange(const QModelIndex& current, const QModelIndex& previous); - -protected: - virtual bool eventFilter(QObject* watched, QEvent* event); - -private slots: - void scrollViewport(); - -private: - void triggerAutoScroll(); - void stopAutoScroll(); - - /** - * Calculates the scroll increment dependent from - * the cursor position \a cursorPos and the range 0 - \a rangeSize - 1. - */ - int calculateScrollIncrement(int cursorPos, int rangeSize) const; - -private: - bool m_rubberBandSelection; - bool m_keyPressed; - bool m_initializedTimestamp; - int m_horizontalScrollInc; - int m_verticalScrollInc; - QAbstractItemView* m_itemView; - QTimer* m_timer; - QTime m_timestamp; -}; - -#endif |
