Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/dvscrollwidget.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
Toshihiro Shimizu 890ddd
#include "toonzqt/freelayout.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qlayout></qlayout>
Toshihiro Shimizu 890ddd
#include <qpushbutton></qpushbutton>
Toshihiro Shimizu 890ddd
#include <qpropertyanimation></qpropertyanimation>
Toshihiro Shimizu 890ddd
#include <qresizeevent></qresizeevent>
Toshihiro Shimizu 890ddd
#include <qmouseevent></qmouseevent>
Toshihiro Shimizu 890ddd
#include <qtimer></qtimer>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// STD includes
Toshihiro Shimizu 890ddd
#include <numeric></numeric>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//****************************************************************************
Toshihiro Shimizu 890ddd
//    Local namespace stuff
Toshihiro Shimizu 890ddd
//****************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class ScrollLayout : public DummyLayout
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	DvScrollWidget *m_scrollWidget;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	ScrollLayout(DvScrollWidget *scrollWidget)
Toshihiro Shimizu 890ddd
		: m_scrollWidget(scrollWidget)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		assert(m_scrollWidget);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QSize minimumSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		struct locals {
Toshihiro Shimizu 890ddd
			inline static QSize expand(const QSize &size, const QLayoutItem *item)
Toshihiro Shimizu 890ddd
			{
Toshihiro Shimizu 890ddd
				return size.expandedTo(item->minimumSize());
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		QSize minSize = std::accumulate(m_items.begin(), m_items.end(),
Toshihiro Shimizu 890ddd
										QSize(), locals::expand);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return (m_scrollWidget->getOrientation() == Qt::Horizontal) ? QSize(0, minSize.height()) : QSize(minSize.width(), 0);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QSize maximumSize() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		struct locals {
Toshihiro Shimizu 890ddd
			inline static QSize bound(const QSize &size, const QLayoutItem *item)
Toshihiro Shimizu 890ddd
			{
Toshihiro Shimizu 890ddd
				return size.boundedTo(item->minimumSize());
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		QSize maxSize = std::accumulate(m_items.begin(), m_items.end(),
Toshihiro Shimizu 890ddd
										QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX), locals::bound);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		return (m_scrollWidget->getOrientation() == Qt::Horizontal) ? QSize(QWIDGETSIZE_MAX, maxSize.height()) : QSize(maxSize.width(), QWIDGETSIZE_MAX);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setGeometry(const QRect &r)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		const Qt::Orientation orientation = m_scrollWidget->getOrientation();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		QList<qlayoutitem *="">::const_iterator it, iEnd = m_items.end();</qlayoutitem>
Toshihiro Shimizu 890ddd
		for (it = m_items.begin(); it != iEnd; ++it) {
Toshihiro Shimizu 890ddd
			QLayoutItem *item = *it;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			QSize targetSize = item->sizeHint();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if (orientation & item->expandingDirections()) {
Toshihiro Shimizu 890ddd
				if (orientation & Qt::Horizontal)
Toshihiro Shimizu 890ddd
					targetSize.setWidth(r.width());
Toshihiro Shimizu 890ddd
				else
Toshihiro Shimizu 890ddd
					targetSize.setHeight(r.height());
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			const QSize &minSize = item->minimumSize(),
Toshihiro Shimizu 890ddd
						&maxSize = item->maximumSize();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			targetSize.setWidth(tcrop(targetSize.width(), minSize.width(), maxSize.width()));
Toshihiro Shimizu 890ddd
			targetSize.setHeight(tcrop(targetSize.height(), minSize.height(), maxSize.height()));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			const QRect &geom = item->geometry();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			if (geom.size() != targetSize)
Toshihiro Shimizu 890ddd
				item->setGeometry(QRect(geom.topLeft(), targetSize));
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_scrollWidget->scroll(0); // Refresh scroll buttons visibility
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==============================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
qreal heldScrollEasing(qreal progress)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//Equilibrate sum of Linear and InQuad
Toshihiro Shimizu 890ddd
	return 0.5 * progress * (1.0 + progress);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//****************************************************************************
Toshihiro Shimizu 890ddd
//    DvScrollWidget implementation
Toshihiro Shimizu 890ddd
//****************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
DvScrollWidget::DvScrollWidget(QWidget *parent, Qt::Orientation orientation)
Toshihiro Shimizu 890ddd
	: QFrame(parent), m_content(0), m_animation(0), m_clickEase(QEasingCurve::OutCubic), m_holdEase(QEasingCurve::Linear), m_backwardTimer(new QTimer(this)), m_forwardTimer(new QTimer(this)), m_pressed(false), m_heldRelease(false), m_heldClick(false)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	ScrollLayout *scrollLayout = new ScrollLayout(this);
Toshihiro Shimizu 890ddd
	setLayout(scrollLayout);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// At the toolbar sides, add scroll buttons
Toshihiro Shimizu 890ddd
	m_scrollBackward = new QPushButton(this);	  // NOTE: Not being managed by the scroll layout.
Toshihiro Shimizu 890ddd
	m_scrollBackward->setFixedSize(24, 24);		   //       It's not necessary. They are not part
Toshihiro Shimizu 890ddd
	m_scrollBackward->setFocusPolicy(Qt::NoFocus); //       of the content.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_scrollForward = new QPushButton(this); //       Observe that the parent widget must
Toshihiro Shimizu 890ddd
	m_scrollForward->setFixedSize(24, 24);   //       therefore be explicitly supplied.
Toshihiro Shimizu 890ddd
	m_scrollForward->setFocusPolicy(Qt::NoFocus);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setOrientation(orientation);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_scrollBackward->move(0, 0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_backwardTimer->setInterval(450);
Toshihiro Shimizu 890ddd
	m_forwardTimer->setInterval(450);
Toshihiro Shimizu 890ddd
	m_backwardTimer->setSingleShot(true);
Toshihiro Shimizu 890ddd
	m_forwardTimer->setSingleShot(true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	connect(m_scrollBackward, SIGNAL(clicked(bool)), this, SLOT(scrollBackward()));
Toshihiro Shimizu 890ddd
	connect(m_scrollForward, SIGNAL(clicked(bool)), this, SLOT(scrollForward()));
Toshihiro Shimizu 890ddd
	connect(m_backwardTimer, SIGNAL(timeout()), this, SLOT(holdBackward()));
Toshihiro Shimizu 890ddd
	connect(m_forwardTimer, SIGNAL(timeout()), this, SLOT(holdForward()));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	connect(m_scrollBackward, SIGNAL(pressed()), m_backwardTimer, SLOT(start()));
Toshihiro Shimizu 890ddd
	connect(m_scrollForward, SIGNAL(pressed()), m_forwardTimer, SLOT(start()));
Toshihiro Shimizu 890ddd
	connect(m_scrollBackward, SIGNAL(released()), this, SLOT(releaseBackward()));
Toshihiro Shimizu 890ddd
	connect(m_scrollForward, SIGNAL(released()), this, SLOT(releaseForward()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DvScrollWidget::setWidget(QWidget *widget)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// Delete currently set widget, if any
Toshihiro Shimizu 890ddd
	QLayout *lay = layout();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	while (QLayoutItem *item = lay->takeAt(0)) // Should be 1 item only - while is just to be pedant
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		assert(item->widget());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		delete item->widget(); // The item DOES NOT own the widget.
Toshihiro Shimizu 890ddd
		delete item;		   // The parent widget (this) does - this
Toshihiro Shimizu 890ddd
	}						   // is by Qt's manual.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Add widget
Toshihiro Shimizu 890ddd
	lay->addWidget(widget);
Toshihiro Shimizu 890ddd
	m_content = widget;
Toshihiro Shimizu 890ddd
	m_content->lower(); // Needs to be below the scroll buttons.
Toshihiro Shimizu 890ddd
						// Seemingly not working on Mac (see showEvent).
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	assert(widget->parent() == this);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Use animations to make scrolling 'smooth'
Toshihiro Shimizu 890ddd
	delete m_animation;
Toshihiro Shimizu 890ddd
	m_animation = new QPropertyAnimation(m_content, "pos");
Toshihiro Shimizu 890ddd
	connect(m_animation, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)),
Toshihiro Shimizu 890ddd
			this, SLOT(updateButtonsVisibility()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DvScrollWidget::setOrientation(Qt::Orientation orientation)
Toshihiro Shimizu 890ddd
{
Campbell Barton 5ea53c
	if ((m_horizontal = (orientation == Qt::Horizontal))) {
Toshihiro Shimizu 890ddd
		setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_scrollBackward->setObjectName("ScrollLeftButton");
Toshihiro Shimizu 890ddd
		m_scrollForward->setObjectName("ScrollRightButton");
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		m_scrollBackward->setObjectName("ScrollUpButton");
Toshihiro Shimizu 890ddd
		m_scrollForward->setObjectName("ScrollDownButton");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Qt::Orientation DvScrollWidget::getOrientation() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_horizontal ? Qt::Horizontal : Qt::Vertical;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DvScrollWidget::setEasing(QEasingCurve clickEase, QEasingCurve holdPressEase)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_clickEase = clickEase;
Toshihiro Shimizu 890ddd
	m_holdEase = holdPressEase;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DvScrollWidget::scroll(int dx, int duration, QEasingCurve ease)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_content)
Toshihiro Shimizu 890ddd
		scrollTo(m_horizontal ? m_content->x() + dx : m_content->y() + dx, duration, ease);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DvScrollWidget::scrollTo(int pos, int duration, QEasingCurve ease)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_content)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Retrieve the contents' bounds
Toshihiro Shimizu 890ddd
	QRect bounds(m_content->pos(), m_content->size());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QPoint newPos;
Toshihiro Shimizu 890ddd
	if (m_horizontal) {
Toshihiro Shimizu 890ddd
		newPos = QPoint(pos, 0);
Toshihiro Shimizu 890ddd
		int minPos = width() - bounds.width();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (newPos.x() <= minPos)
Toshihiro Shimizu 890ddd
			newPos.setX(minPos);
Toshihiro Shimizu 890ddd
		if (newPos.x() >= 0)
Toshihiro Shimizu 890ddd
			newPos.setX(0);
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		newPos = QPoint(0, pos);
Toshihiro Shimizu 890ddd
		int minPos = height() - bounds.height();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (newPos.y() <= minPos)
Toshihiro Shimizu 890ddd
			newPos.setY(minPos);
Toshihiro Shimizu 890ddd
		if (newPos.y() >= 0)
Toshihiro Shimizu 890ddd
			newPos.setY(0);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (duration > 0) {
Toshihiro Shimizu 890ddd
		m_animation->stop();
Toshihiro Shimizu 890ddd
		m_animation->setEasingCurve(ease);
Toshihiro Shimizu 890ddd
		m_animation->setStartValue(bounds.topLeft());
Toshihiro Shimizu 890ddd
		m_animation->setEndValue(newPos);
Toshihiro Shimizu 890ddd
		m_animation->setDuration(duration);
Toshihiro Shimizu 890ddd
		m_animation->start();
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		m_content->move(newPos);
Toshihiro Shimizu 890ddd
		updateButtonsVisibility();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DvScrollWidget::updateButtonsVisibility()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if ((!m_content) || (m_animation->state() == QPropertyAnimation::Running))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QRect bounds(m_content->pos(), m_content->size());
Toshihiro Shimizu 890ddd
	if (m_horizontal) {
Toshihiro Shimizu 890ddd
		if (bounds.right() <= width()) {
Toshihiro Shimizu 890ddd
			m_scrollForward->setDown(false);
Toshihiro Shimizu 890ddd
			m_scrollForward->hide();
Toshihiro Shimizu 890ddd
			m_heldRelease = m_heldClick = false;
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			m_scrollForward->show();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (bounds.left() >= 0) {
Toshihiro Shimizu 890ddd
			m_scrollBackward->setDown(false);
Toshihiro Shimizu 890ddd
			m_scrollBackward->hide();
Toshihiro Shimizu 890ddd
			m_heldRelease = m_heldClick = false;
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			m_scrollBackward->show();
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		if (bounds.bottom() <= height()) {
Toshihiro Shimizu 890ddd
			m_scrollForward->setDown(false);
Toshihiro Shimizu 890ddd
			m_scrollForward->hide();
Toshihiro Shimizu 890ddd
			m_heldRelease = m_heldClick = false;
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			m_scrollForward->show();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (bounds.top() >= 0) {
Toshihiro Shimizu 890ddd
			m_scrollBackward->setDown(false);
Toshihiro Shimizu 890ddd
			m_scrollBackward->hide();
Toshihiro Shimizu 890ddd
			m_heldRelease = m_heldClick = false;
Toshihiro Shimizu 890ddd
		} else
Toshihiro Shimizu 890ddd
			m_scrollBackward->show();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DvScrollWidget::showEvent(QShowEvent *se)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	// These are necessary on Mac.
Toshihiro Shimizu 890ddd
	m_scrollBackward->raise();
Toshihiro Shimizu 890ddd
	m_scrollForward->raise();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DvScrollWidget::resizeEvent(QResizeEvent *re)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QWidget::resizeEvent(re);
Toshihiro Shimizu 890ddd
	scroll(0);
Toshihiro Shimizu 890ddd
	if (m_horizontal) {
Toshihiro Shimizu 890ddd
		m_scrollBackward->setFixedSize(m_scrollBackward->width(), height());
Toshihiro Shimizu 890ddd
		m_scrollForward->setFixedSize(m_scrollForward->width(), height());
Toshihiro Shimizu 890ddd
		m_scrollForward->move(re->size().width() - m_scrollForward->width(), 0);
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		m_scrollBackward->setFixedSize(width(), m_scrollBackward->height());
Toshihiro Shimizu 890ddd
		m_scrollForward->setFixedSize(width(), m_scrollForward->height());
Toshihiro Shimizu 890ddd
		m_scrollForward->move(0, re->size().height() - m_scrollForward->height());
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DvScrollWidget::mousePressEvent(QMouseEvent *me)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_pressed = true;
Toshihiro Shimizu 890ddd
	m_mousePos = m_horizontal ? me->x() : me->y();
Toshihiro Shimizu 890ddd
	me->accept();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DvScrollWidget::mouseMoveEvent(QMouseEvent *me)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_pressed)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_horizontal) {
Toshihiro Shimizu 890ddd
		scroll(me->x() - m_mousePos);
Toshihiro Shimizu 890ddd
		m_mousePos = me->x();
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		scroll(me->y() - m_mousePos);
Toshihiro Shimizu 890ddd
		m_mousePos = me->y();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	me->accept();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DvScrollWidget::mouseReleaseEvent(QMouseEvent *me)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_pressed = false;
Toshihiro Shimizu 890ddd
	me->accept();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DvScrollWidget::holdBackward()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_content)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_heldRelease = m_heldClick = true;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QRect bounds(m_content->pos(), m_content->size());
Toshihiro Shimizu 890ddd
	int spaceLeft = -(m_horizontal ? bounds.left() : bounds.top());
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QEasingCurve ease;
Toshihiro Shimizu 890ddd
	ease.setCustomType(&heldScrollEasing);
Toshihiro Shimizu 890ddd
	scrollTo(0, spaceLeft * 10, ease); // 100 pix per second
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DvScrollWidget::holdForward()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_content)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_heldRelease = m_heldClick = true;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QRect bounds(m_content->pos(), m_content->size());
Toshihiro Shimizu 890ddd
	int pos = m_horizontal ? width() - bounds.width() : height() - bounds.height();
Toshihiro Shimizu 890ddd
	int spaceLeft = (m_horizontal ? bounds.left() : bounds.top()) - pos;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QEasingCurve ease;
Toshihiro Shimizu 890ddd
	ease.setCustomType(&heldScrollEasing);
Toshihiro Shimizu 890ddd
	scrollTo(pos, spaceLeft * 10, ease); // 100 pix per second
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DvScrollWidget::releaseBackward()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_backwardTimer->stop();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_heldRelease)
Toshihiro Shimizu 890ddd
		m_animation->stop();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_heldRelease = false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DvScrollWidget::releaseForward()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_forwardTimer->stop();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (m_heldRelease)
Toshihiro Shimizu 890ddd
		m_animation->stop();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_heldRelease = false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DvScrollWidget::scrollBackward()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_heldClick)
Toshihiro Shimizu 890ddd
		scroll(0.5 * (m_horizontal ? width() : height()), 300);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_heldClick = false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void DvScrollWidget::scrollForward()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_heldClick)
Toshihiro Shimizu 890ddd
		scroll(-0.5 * (m_horizontal ? width() : height()), 300);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_heldClick = false;
Toshihiro Shimizu 890ddd
}