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