|
Packit Bot |
052d53 |
/*************************************************************************
|
|
Packit Bot |
052d53 |
* Copyright (C) 2014 by Hugo Pereira Da Costa <hugo.pereira@free.fr> *
|
|
Packit Bot |
052d53 |
* *
|
|
Packit Bot |
052d53 |
* This program is free software; you can redistribute it and/or modify *
|
|
Packit Bot |
052d53 |
* it under the terms of the GNU General Public License as published by *
|
|
Packit Bot |
052d53 |
* the Free Software Foundation; either version 2 of the License, or *
|
|
Packit Bot |
052d53 |
* (at your option) any later version. *
|
|
Packit Bot |
052d53 |
* *
|
|
Packit Bot |
052d53 |
* This program is distributed in the hope that it will be useful, *
|
|
Packit Bot |
052d53 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
Packit Bot |
052d53 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
Packit Bot |
052d53 |
* GNU General Public License for more details. *
|
|
Packit Bot |
052d53 |
* *
|
|
Packit Bot |
052d53 |
* You should have received a copy of the GNU General Public License *
|
|
Packit Bot |
052d53 |
* along with this program; if not, write to the *
|
|
Packit Bot |
052d53 |
* Free Software Foundation, Inc., *
|
|
Packit Bot |
052d53 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
|
Packit Bot |
052d53 |
*************************************************************************/
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
#include "adwaitascrollbardata.h"
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
#include <QHoverEvent>
|
|
Packit Bot |
052d53 |
#include <QScrollBar>
|
|
Packit Bot |
052d53 |
#include <QStyleOptionSlider>
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
Q_GUI_EXPORT QStyleOptionSlider qt_qscrollbarStyleOption(QScrollBar *);
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
namespace Adwaita
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//______________________________________________
|
|
Packit Bot |
052d53 |
ScrollBarData::ScrollBarData(QObject *parent, QWidget *target, int duration)
|
|
Packit Bot |
052d53 |
: WidgetStateData(parent, target, duration)
|
|
Packit Bot |
052d53 |
, _position(-1, -1)
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
target->installEventFilter(this);
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
_addLineData._animation = new Animation(duration, this);
|
|
Packit Bot |
052d53 |
_subLineData._animation = new Animation(duration, this);
|
|
Packit Bot |
052d53 |
_grooveData._animation = new Animation(duration, this);
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
connect(addLineAnimation().data(), SIGNAL(finished()), SLOT(clearAddLineRect()));
|
|
Packit Bot |
052d53 |
connect(subLineAnimation().data(), SIGNAL(finished()), SLOT(clearSubLineRect()));
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
// setup animation
|
|
Packit Bot |
052d53 |
setupAnimation(addLineAnimation(), "addLineOpacity");
|
|
Packit Bot |
052d53 |
setupAnimation(subLineAnimation(), "subLineOpacity");
|
|
Packit Bot |
052d53 |
setupAnimation(grooveAnimation(), "grooveOpacity");
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//______________________________________________
|
|
Packit Bot |
052d53 |
bool ScrollBarData::eventFilter(QObject *object, QEvent *event)
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
if (object != target().data()) {
|
|
Packit Bot |
052d53 |
return WidgetStateData::eventFilter(object, event);
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
// check event type
|
|
Packit Bot |
052d53 |
switch (event->type()) {
|
|
Packit Bot |
052d53 |
case QEvent::HoverEnter:
|
|
Packit Bot |
052d53 |
setGrooveHovered(true);
|
|
Packit Bot |
052d53 |
grooveAnimation().data()->setDirection(Animation::Forward);
|
|
Packit Bot |
052d53 |
if (!grooveAnimation().data()->isRunning()) {
|
|
Packit Bot |
052d53 |
grooveAnimation().data()->start();
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
case QEvent::HoverMove:
|
|
Packit Bot |
052d53 |
hoverMoveEvent(object, event);
|
|
Packit Bot |
052d53 |
break;
|
|
Packit Bot |
052d53 |
case QEvent::HoverLeave:
|
|
Packit Bot |
052d53 |
setGrooveHovered(false);
|
|
Packit Bot |
052d53 |
grooveAnimation().data()->setDirection(Animation::Backward);
|
|
Packit Bot |
052d53 |
if (!grooveAnimation().data()->isRunning()) {
|
|
Packit Bot |
052d53 |
grooveAnimation().data()->start();
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
hoverLeaveEvent(object, event);
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
break;
|
|
Packit Bot |
052d53 |
default:
|
|
Packit Bot |
052d53 |
break;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
return WidgetStateData::eventFilter(object, event);
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//______________________________________________
|
|
Packit Bot |
052d53 |
const Animation::Pointer &ScrollBarData::animation(QStyle::SubControl subcontrol) const
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
switch (subcontrol) {
|
|
Packit Bot |
052d53 |
case QStyle::SC_ScrollBarSlider:
|
|
Packit Bot |
052d53 |
return animation();
|
|
Packit Bot |
052d53 |
case QStyle::SC_ScrollBarAddLine:
|
|
Packit Bot |
052d53 |
return addLineAnimation();
|
|
Packit Bot |
052d53 |
case QStyle::SC_ScrollBarSubLine:
|
|
Packit Bot |
052d53 |
return subLineAnimation();
|
|
Packit Bot |
052d53 |
case QStyle::SC_ScrollBarGroove:
|
|
Packit Bot |
052d53 |
return grooveAnimation();
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
return animation();
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//______________________________________________
|
|
Packit Bot |
052d53 |
qreal ScrollBarData::opacity(QStyle::SubControl subcontrol) const
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
switch (subcontrol) {
|
|
Packit Bot |
052d53 |
case QStyle::SC_ScrollBarSlider:
|
|
Packit Bot |
052d53 |
return opacity();
|
|
Packit Bot |
052d53 |
case QStyle::SC_ScrollBarAddLine:
|
|
Packit Bot |
052d53 |
return addLineOpacity();
|
|
Packit Bot |
052d53 |
case QStyle::SC_ScrollBarSubLine:
|
|
Packit Bot |
052d53 |
return subLineOpacity();
|
|
Packit Bot |
052d53 |
case QStyle::SC_ScrollBarGroove:
|
|
Packit Bot |
052d53 |
return grooveOpacity();
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
return 0;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//______________________________________________
|
|
Packit Bot |
052d53 |
void ScrollBarData::hoverMoveEvent(QObject *object, QEvent *event)
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
// try cast object to scrollbar
|
|
Packit Bot |
052d53 |
QScrollBar *scrollBar(qobject_cast<QScrollBar *>(object));
|
|
Packit Bot |
052d53 |
if (!scrollBar || scrollBar->isSliderDown()) {
|
|
Packit Bot |
052d53 |
return;
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
// retrieve scrollbar option
|
|
Packit Bot |
052d53 |
QStyleOptionSlider opt(qt_qscrollbarStyleOption(scrollBar));
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
// cast event
|
|
Packit Bot |
052d53 |
QHoverEvent *hoverEvent = static_cast<QHoverEvent *>(event);
|
|
Packit Bot |
052d53 |
QStyle::SubControl hoverControl = scrollBar->style()->hitTestComplexControl(QStyle::CC_ScrollBar, &opt, hoverEvent->pos(), scrollBar);
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
// update hover state
|
|
Packit Bot |
052d53 |
updateAddLineArrow(hoverControl);
|
|
Packit Bot |
052d53 |
updateSubLineArrow(hoverControl);
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
// store position
|
|
Packit Bot |
052d53 |
_position = hoverEvent->pos();
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//______________________________________________
|
|
Packit Bot |
052d53 |
void ScrollBarData::hoverLeaveEvent(QObject *, QEvent *)
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
// reset hover state
|
|
Packit Bot |
052d53 |
updateSubLineArrow(QStyle::SC_None);
|
|
Packit Bot |
052d53 |
updateAddLineArrow(QStyle::SC_None);
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
// reset mouse position
|
|
Packit Bot |
052d53 |
_position = QPoint(-1, -1);
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//_____________________________________________________________________
|
|
Packit Bot |
052d53 |
void ScrollBarData::updateSubLineArrow(QStyle::SubControl hoverControl)
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
if (hoverControl == QStyle::SC_ScrollBarSubLine) {
|
|
Packit Bot |
052d53 |
if (!subLineArrowHovered()) {
|
|
Packit Bot |
052d53 |
setSubLineArrowHovered(true);
|
|
Packit Bot |
052d53 |
if (enabled()) {
|
|
Packit Bot |
052d53 |
subLineAnimation().data()->setDirection(Animation::Forward);
|
|
Packit Bot |
052d53 |
if (!subLineAnimation().data()->isRunning()) {
|
|
Packit Bot |
052d53 |
subLineAnimation().data()->start();
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
} else {
|
|
Packit Bot |
052d53 |
setDirty();
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
} else {
|
|
Packit Bot |
052d53 |
if (subLineArrowHovered()) {
|
|
Packit Bot |
052d53 |
setSubLineArrowHovered(false);
|
|
Packit Bot |
052d53 |
if (enabled()) {
|
|
Packit Bot |
052d53 |
subLineAnimation().data()->setDirection(Animation::Backward);
|
|
Packit Bot |
052d53 |
if (!subLineAnimation().data()->isRunning()) {
|
|
Packit Bot |
052d53 |
subLineAnimation().data()->start();
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
} else {
|
|
Packit Bot |
052d53 |
setDirty();
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
//_____________________________________________________________________
|
|
Packit Bot |
052d53 |
void ScrollBarData::updateAddLineArrow(QStyle::SubControl hoverControl)
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
if (hoverControl == QStyle::SC_ScrollBarAddLine) {
|
|
Packit Bot |
052d53 |
if (!addLineArrowHovered()) {
|
|
Packit Bot |
052d53 |
setAddLineArrowHovered(true);
|
|
Packit Bot |
052d53 |
if (enabled()) {
|
|
Packit Bot |
052d53 |
addLineAnimation().data()->setDirection(Animation::Forward);
|
|
Packit Bot |
052d53 |
if (!addLineAnimation().data()->isRunning()) {
|
|
Packit Bot |
052d53 |
addLineAnimation().data()->start();
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
} else {
|
|
Packit Bot |
052d53 |
setDirty();
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
} else {
|
|
Packit Bot |
052d53 |
if (addLineArrowHovered()) {
|
|
Packit Bot |
052d53 |
setAddLineArrowHovered(false);
|
|
Packit Bot |
052d53 |
if (enabled()) {
|
|
Packit Bot |
052d53 |
addLineAnimation().data()->setDirection(Animation::Backward);
|
|
Packit Bot |
052d53 |
if (!addLineAnimation().data()->isRunning()) {
|
|
Packit Bot |
052d53 |
addLineAnimation().data()->start();
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
} else {
|
|
Packit Bot |
052d53 |
setDirty();
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
} // namespace Adwaita
|