QObject(parent),
m_view(parent),
m_toggle(0),
- m_connected(false)
+ m_connected(false),
+ m_appliedPointingHandCursor(false)
{
connect(parent, SIGNAL(entered(const QModelIndex&)),
this, SLOT(slotEntered(const QModelIndex&)));
m_toggle->hide();
connect(m_toggle, SIGNAL(clicked(bool)),
this, SLOT(setItemSelected(bool)));
+ m_toggle->installEventFilter(this);
m_view->viewport()->installEventFilter(this);
}
bool SelectionManager::eventFilter(QObject* watched, QEvent* event)
{
- Q_ASSERT(watched == m_view->viewport());
- if (event->type() == QEvent::MouseButtonPress) {
- // Set the toggle invisible, if a mouse button has been pressed
- // outside the toggle boundaries. This e.g. assures, that the toggle
- // gets invisible during dragging items.
- const QRect toggleBounds(m_toggle->mapToGlobal(QPoint(0, 0)), m_toggle->size());
- m_toggle->setVisible(toggleBounds.contains(QCursor::pos()));
+ if (watched == m_view->viewport()) {
+ switch (event->type()) {
+ case QEvent::Leave:
+ m_toggle->hide();
+ break;
+
+ case QEvent::MouseButtonPress: {
+ // Set the toggle invisible, if a mouse button has been pressed
+ // outside the toggle boundaries. This e.g. assures, that the toggle
+ // gets invisible during dragging items.
+ const QRect toggleBounds(m_toggle->mapToGlobal(QPoint(0, 0)), m_toggle->size());
+ m_toggle->setVisible(toggleBounds.contains(QCursor::pos()));
+ break;
+ }
+
+ default:
+ break;
+ }
+ } else if (watched == m_toggle) {
+ switch (event->type()) {
+ case QEvent::Hide:
+ // If the toggle button gets hidden, the cursor is not above the item
+ // anymore and the shape must get restored
+ restoreCursor();
+ break;
+
+ case QEvent::Enter:
+ QApplication::changeOverrideCursor(Qt::ArrowCursor);
+ break;
+
+ case QEvent::Leave:
+ QApplication::changeOverrideCursor(Qt::PointingHandCursor);
+ break;
+
+ default:
+ break;
+ }
}
+
return QObject::eventFilter(watched, event);
}
(index.column() == DolphinModel::Name) &&
(QApplication::mouseButtons() == Qt::NoButton);
if (showToggle) {
+ applyPointingHandCursor();
+
m_toggle->setUrl(urlForIndex(index));
if (!m_connected) {
return proxyModel->mapFromSource(dirIndex);
}
+
+void SelectionManager::applyPointingHandCursor()
+{
+ if (!m_appliedPointingHandCursor) {
+ QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor));
+ m_appliedPointingHandCursor = true;
+ }
+}
+
+void SelectionManager::restoreCursor()
+{
+ if (m_appliedPointingHandCursor) {
+ QApplication::restoreOverrideCursor();
+ m_appliedPointingHandCursor = false;
+ }
+}
+
#include "selectionmanager.moc"
private:
KUrl urlForIndex(const QModelIndex& index) const;
const QModelIndex indexForUrl(const KUrl& url) const;
+ void applyPointingHandCursor();
+ void restoreCursor();
private:
QAbstractItemView* m_view;
SelectionToggle* m_toggle;
bool m_connected;
+ bool m_appliedPointingHandCursor;
};
#endif
#include <QTimer>
#include <QTimeLine>
+#include <kdebug.h>
+
SelectionToggle::SelectionToggle(QWidget* parent) :
QAbstractButton(parent),
m_isHovered(false),
m_leftMouseButtonPressed(false),
- m_appliedArrowCursor(false),
m_fadingValue(0),
m_margin(0),
m_icon(),
bool SelectionToggle::eventFilter(QObject* obj, QEvent* event)
{
- if (obj == parent()) {
- switch (event->type()) {
- case QEvent::Leave:
- hide();
- break;
-
- case QEvent::MouseMove:
- if (m_leftMouseButtonPressed) {
- // Don't forward mouse move events to the viewport,
- // otherwise a rubberband selection will be shown when
- // clicking on the selection toggle and moving the mouse
- // above the viewport.
- return true;
- }
- break;
-
- default:
- break;
- }
+ if ((obj == parent()) && (event->type() == QEvent::MouseMove) && m_leftMouseButtonPressed) {
+ // Don't forward mouse move events to the viewport,
+ // otherwise a rubberband selection will be shown when
+ // clicking on the selection toggle and moving the mouse
+ // above the viewport.
+ return true;
}
return QAbstractButton::eventFilter(obj, event);
{
QAbstractButton::enterEvent(event);
- if (!m_appliedArrowCursor) {
- m_appliedArrowCursor = true;
- // Apply the arrow asynchronously. This is required for
- // the following usecase:
- // 1. Cursor is above the viewport left beside an item
- // 2. Cursor is moved above the item, so that the selection-toggle
- // and the item are entered equally.
- // In this situation it is not defined who gets the enter-event first.
- // As the selection-toggle is above the item, it should overwrite possible
- // cursor changes done by the item.
- QTimer::singleShot(0, this, SLOT(applyArrowCursor()));
- }
-
// if the mouse cursor is above the selection toggle, display
// it immediately without fading timer
m_isHovered = true;
{
QAbstractButton::leaveEvent(event);
- if (m_appliedArrowCursor) {
- // Reset the cursor asynchronously. See SelectionToggle::enterEvent()
- // for a more information.
- m_appliedArrowCursor = false;
- QTimer::singleShot(0, this, SLOT(restoreCursor()));
- }
-
m_isHovered = false;
update();
}
setIconOverlay(isChecked());
}
-void SelectionToggle::applyArrowCursor()
-{
- QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
-}
-
-void SelectionToggle::restoreCursor()
-{
- QApplication::restoreOverrideCursor();
-}
-
void SelectionToggle::startFading()
{
Q_ASSERT(m_fadingTimeLine == 0);
void setIconOverlay(bool checked);
void refreshIcon();
- void applyArrowCursor();
- void restoreCursor();
-
private:
void startFading();
void stopFading();
private:
bool m_isHovered;
bool m_leftMouseButtonPressed;
- bool m_appliedArrowCursor;
int m_fadingValue;
int m_margin;
QPixmap m_icon;
DolphinViewController* dolphinViewController,
const ViewModeController* viewModeController) :
QObject(view),
- m_appliedPointingHandCursor(false),
m_view(view),
m_dolphinViewController(dolphinViewController),
m_toolTipManager(0),
this, SLOT(slotNameFilterChanged(const QString&)));
view->viewport()->installEventFilter(this);
-
- // Apply a pointing-hand cursor when hovering files
- connect(view, SIGNAL(entered(const QModelIndex&)), SLOT(applyPointingHandCursor()));
- connect(view, SIGNAL(viewportEntered()), SLOT(restoreCursor()));
- connect(viewModeController, SIGNAL(urlChanged(const KUrl&)), SLOT(restoreCursor()));
}
ViewExtensionsFactory::~ViewExtensionsFactory()
bool ViewExtensionsFactory::eventFilter(QObject* watched, QEvent* event)
{
Q_UNUSED(watched);
-
- switch (event->type()) {
- case QEvent::Wheel:
- if (m_selectionManager != 0) {
- m_selectionManager->reset();
- }
- break;
-
- case QEvent::Leave:
- restoreCursor();
- break;
-
- default: break;
+ if ((event->type() == QEvent::Wheel) && (m_selectionManager != 0)) {
+ m_selectionManager->reset();
}
-
return false;
}
m_dolphinViewController->requestActivation();
}
-void ViewExtensionsFactory::applyPointingHandCursor()
-{
- if (!m_appliedPointingHandCursor && !(QApplication::mouseButtons() & Qt::LeftButton)) {
- QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor));
- m_appliedPointingHandCursor = true;
- }
-}
-
-void ViewExtensionsFactory::restoreCursor()
-{
- if (m_appliedPointingHandCursor) {
- QApplication::restoreOverrideCursor();
- m_appliedPointingHandCursor = false;
- }
-}
-
DolphinSortFilterProxyModel* ViewExtensionsFactory::proxyModel() const
{
return static_cast<DolphinSortFilterProxyModel*>(m_view->model());
void slotNameFilterChanged(const QString& nameFilter);
void slotRequestVersionControlActions(const KFileItemList& items);
void requestActivation();
- void applyPointingHandCursor();
- void restoreCursor();
private:
DolphinSortFilterProxyModel* proxyModel() const;
private:
- bool m_appliedPointingHandCursor;
QAbstractItemView* m_view;
DolphinViewController* m_dolphinViewController;
ToolTipManager* m_toolTipManager;