/***************************************************************************
- * Copyright (C) 2008 by Peter Penz <peter.penz@gmx.at> *
+ * Copyright (C) 2008 by Peter Penz <peter.penz19@gmail.com> *
* *
* 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 *
#include "selectiontoggle.h"
-#include <kglobalsettings.h>
-#include <kicon.h>
-#include <kiconloader.h>
-#include <kiconeffect.h>
-#include <klocale.h>
+#include <KGlobalSettings>
+#include <KIcon>
+#include <KIconLoader>
+#include <KIconEffect>
+#include <KLocale>
#include <QApplication>
#include <QPainter>
#include <QTimer>
#include <QTimeLine>
+#include <KDebug>
+
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;
- if (m_fadingTimeLine != 0) {
+ if (m_fadingTimeLine) {
m_fadingTimeLine->stop();
}
m_fadingValue = 255;
{
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();
}
{
m_fadingValue = value;
if (m_fadingValue >= 255) {
- Q_ASSERT(m_fadingTimeLine != 0);
+ Q_ASSERT(m_fadingTimeLine);
m_fadingTimeLine->stop();
}
update();
setIconOverlay(isChecked());
}
-void SelectionToggle::applyArrowCursor()
-{
- QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
-}
-
-void SelectionToggle::restoreCursor()
-{
- QApplication::restoreOverrideCursor();
-}
-
void SelectionToggle::startFading()
{
- Q_ASSERT(m_fadingTimeLine == 0);
+ Q_ASSERT(!m_fadingTimeLine);
const bool animate = KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects;
const int duration = animate ? 600 : 1;
void SelectionToggle::stopFading()
{
- if (m_fadingTimeLine != 0) {
+ if (m_fadingTimeLine) {
m_fadingTimeLine->stop();
delete m_fadingTimeLine;
m_fadingTimeLine = 0;