Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef SCREENBOARD_H
Toshihiro Shimizu 890ddd
#define SCREENBOARD_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tcommon.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qwidget></qwidget>
Toshihiro Shimizu 890ddd
#include <qlist></qlist>
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
Shinya Kitaoka 120a6e
namespace DVGui {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//****************************************************************************
Toshihiro Shimizu 890ddd
//    ScreenBoard class
Toshihiro Shimizu 890ddd
//****************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//! The ScreenBoard is a singleton class that allows self-drawing objects to
Toshihiro Shimizu 890ddd
//! be rendered on the whole desktop surface.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*! The Qt Framework does not provide a standard way to draw directly on the
Toshihiro Shimizu 890ddd
    desktop.
Toshihiro Shimizu 890ddd
\n\n
Toshihiro Shimizu 890ddd
    Typically, users have to allocate a QWidget to host any drawing command
Toshihiro Shimizu 890ddd
    to be rendered - but the rendering surface only covers the entirety of the
Toshihiro Shimizu 890ddd
    widget geometry, and nothing more.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
    Plus, the maximal drawing geometry should be known in advance when using a
Toshihiro Shimizu 890ddd
    host widget, or else heavy flickering will result from attempts to move
Toshihiro Shimizu 890ddd
    \a and resize the widget to cover new portions of the desktop.
Toshihiro Shimizu 890ddd
\n\n
Shinya Kitaoka 120a6e
    Another important use for the ScreenBoard is that of allowing dektop-wide
Shinya Kitaoka 120a6e
mouse
Toshihiro Shimizu 890ddd
    grabbing through the grabMouse() and releaseMouse() functions.
Toshihiro Shimizu 890ddd
\n\n
Toshihiro Shimizu 890ddd
    The ScreenBoard stores a private collection of static, inert and transparent
Toshihiro Shimizu 890ddd
     screen widgets <\I>, each overlapping a desktop screen, to be used as
Toshihiro Shimizu 890ddd
    drawable surfaces for self-drawing objects (ScreenBoard::Drawing instances)
Toshihiro Shimizu 890ddd
    that are added to the board.
Toshihiro Shimizu 890ddd
\n\n
Toshihiro Shimizu 890ddd
    Drawings can be added to the board by direct manipulation of the drawings()
Toshihiro Shimizu 890ddd
    container list.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
    Use the update() method to refresh the screen after drawing insertions or
Toshihiro Shimizu 890ddd
    removals.
Toshihiro Shimizu 890ddd
\n\n
Shinya Kitaoka 120a6e
    Screen widgets redirect any event they receive to drawings that accept
Shinya Kitaoka 120a6e
redirection
Toshihiro Shimizu 890ddd
    through the Drawings::accpetScreenEvents() method.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    The drawings() list sorting affects the order in which events from screen
Shinya Kitaoka 120a6e
widgets
Toshihiro Shimizu 890ddd
    are delivered to drawings.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    In particular, drawings'  stacking order <\I> is \b inverse to the their
Shinya Kitaoka 120a6e
list
Toshihiro Shimizu 890ddd
    ordering - so, paint events are received in \b reverse with respect to other
Toshihiro Shimizu 890ddd
    events. Event acceptance is ignored to determine event delivery to drawings.
Toshihiro Shimizu 890ddd
\n\n
Toshihiro Shimizu 890ddd
    Observe that upon every update() invocation, the screen widgets pool will
Toshihiro Shimizu 890ddd
    be refreshed to keep it to a minimum.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class DVAPI ScreenBoard final : public QObject {
Shinya Kitaoka 120a6e
  Q_OBJECT
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  class Drawing;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  class ScreenWidget;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QVector<screenwidget *=""> m_screenWidgets;</screenwidget>
Shinya Kitaoka 120a6e
  QList<drawing *=""> m_drawings;</drawing>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QCursor m_cursor;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool m_grabbing;
Shinya Kitaoka 120a6e
  bool m_mouseOnAScreen;
Shinya Kitaoka 120a6e
  bool m_updated;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  static ScreenBoard *instance();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const QList<drawing *=""> &drawings() const { return m_drawings; }</drawing>
Shinya Kitaoka 120a6e
  QList<drawing *=""> &drawings() { return m_drawings; }</drawing>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void grabMouse(
Shinya Kitaoka 120a6e
      const QCursor &cursor);  //!< Grabs mouse inputs across the whole desktop.
Shinya Kitaoka 120a6e
  void releaseMouse();         //!< Releases the mouse grab after grabMouse().
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool grabbingMouse() const {
Shinya Kitaoka 120a6e
    return m_grabbing;
Shinya Kitaoka 120a6e
  }  //!< Whether mouse grabbing is on.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  ScreenBoard();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void reallocScreenWidgets();
Shinya Kitaoka 120a6e
  void ensureMouseOnAScreen();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public slots:
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void update();  //!< Refreshes the screen widgets pool and updates them.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private slots:
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  friend class ScreenWidget;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void trackCursor();
Shinya Kitaoka 120a6e
  void doUpdate();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//****************************************************************************
Toshihiro Shimizu 890ddd
//    ScreenBoard::Drawing class
Toshihiro Shimizu 890ddd
//****************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//! ScreenDrawing is the base class for objects that can be painted directly
Toshihiro Shimizu 890ddd
//! in screen coordinates through the ScreenBoard.
Shinya Kitaoka 120a6e
class ScreenBoard::Drawing {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  //! Generic event handler for drawings.
Shinya Kitaoka 120a6e
  /*! Reimplement it to receive events from screen widgets other than paint
Shinya Kitaoka 120a6e
events.
Shinya Kitaoka 120a6e
Paint events are \b not received in this handler, since they must be delivered
Shinya Kitaoka 120a6e
in reverse order.
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  virtual void event(QWidget *widget, QEvent *e) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //! Paints the drawing on the specified screen widget. Use the widget's
Shinya Kitaoka 120a6e
  //! mapFromGlobal() function to match desktop coordinates to screen
Shinya Kitaoka 120a6e
  //! coordinates.
Shinya Kitaoka 120a6e
  virtual void paintEvent(QWidget *widget, QPaintEvent *pe) = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //! Returns whether the drawing is interested in events from the passed screen
Shinya Kitaoka 120a6e
  //! geometry.
Shinya Kitaoka 120a6e
  //! Accepting a screen causes a screen widget to be allocated in order to
Shinya Kitaoka 120a6e
  //! receive events.
Shinya Kitaoka 120a6e
  virtual bool acceptScreenEvents(const QRect &screenRect) const = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace DVGui
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // SCREENBOARD_H