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