tahoma2d/toonz/sources/include/toonzqt/dvscrollwidget.h

126 lines
3.5 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef DVSCROLLWIDGET_H
#define DVSCROLLWIDGET_H
// TnzCore includes
#include "tcommon.h"
// Qt includes
#include <QFrame>
#include <QEasingCurve>
#undef DVAPI
#undef DVVAR
#ifdef TOONZQT_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
//====================================================
// Forward declarations
class FreeLayout;
class QPropertyAnimation;
class QPushButton;
class QTimer;
//====================================================
//****************************************************************************
// DvScrollWidget class
//****************************************************************************
/*!
\brief The DvScrollWidget class is a QScrollArea-like container
widget for monodirectional scrolling.
2016-06-15 18:43:10 +12:00
\details Unlike a QScrollArea, scrolling is enforced using directional
buttons
at the side of the content whose activation performs animated
scrolling
2016-03-19 06:57:51 +13:00
by half a widget in the represented direction.
2016-06-15 18:43:10 +12:00
Alternatively, free-scroll is available by default where mouse
events
2016-03-19 06:57:51 +13:00
are un-accepted by the content's child widgets.
2016-06-15 18:43:10 +12:00
The push buttons at the side of the content appear only when there
is
available content space in that direction. They are \a empty by
default,
2016-03-19 06:57:51 +13:00
but can be filled in or styled with a style sheet.
In the latter case, they are given an object name dependent on the
2016-06-15 18:43:10 +12:00
scroll orientation - in the form
<TT>Scroll<Left/Right/Up/Down>Button</TT>.
2016-03-19 06:57:51 +13:00
\note The default size QSizePolicy for DvScrollWidget is \p Preferred in
the orientation direction, and \p Fixed in the other.
\sa The FreeLayout class.
*/
class DVAPI DvScrollWidget final : public QFrame {
2016-06-15 18:43:10 +12:00
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QWidget *m_content;
QPushButton *m_scrollBackward, *m_scrollForward;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QPropertyAnimation *m_animation;
QEasingCurve m_clickEase, m_holdEase;
QTimer *m_backwardTimer, *m_forwardTimer;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int m_mousePos;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool m_horizontal, m_pressed, m_heldRelease, m_heldClick;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
DvScrollWidget(QWidget *parent = 0, Qt::Orientation = Qt::Horizontal);
~DvScrollWidget() {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
/*! \remark Ownership is \a transferred to this class. Any previously set
widget
is deleted before being replaced. */
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setWidget(QWidget *widget); //!< Sets the scrollable content widget.
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
/*! \note Function setOrientation() restores the widget's <I>size policy</I>
to
\p Preferred in the specified direction, and \p Fixed in the other. */
void setOrientation(Qt::Orientation orientation);
Qt::Orientation getOrientation() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setEasing(QEasingCurve clickEase, QEasingCurve holdPressEase);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void scroll(int dx, int duration = 0,
QEasingCurve easing = QEasingCurve(QEasingCurve::OutCubic));
void scrollTo(int pos, int duration = 0,
QEasingCurve easing = QEasingCurve(QEasingCurve::OutCubic));
2016-03-19 06:57:51 +13:00
public slots:
2016-06-15 18:43:10 +12:00
void scrollBackward();
void scrollForward();
2016-03-19 06:57:51 +13:00
protected:
2016-06-19 20:06:29 +12:00
void resizeEvent(QResizeEvent *re) override;
void mousePressEvent(QMouseEvent *me) override;
void mouseMoveEvent(QMouseEvent *me) override;
void mouseReleaseEvent(QMouseEvent *me) override;
void showEvent(QShowEvent *se) override;
2016-03-19 06:57:51 +13:00
protected slots:
2016-06-15 18:43:10 +12:00
void updateButtonsVisibility();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void holdBackward();
void holdForward();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void releaseBackward();
void releaseForward();
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
#endif // DVSCROLLWIDGET_H