Toshihiro Shimizu 890ddd
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
Toshihiro Shimizu 890ddd
namespace DVGui
Toshihiro Shimizu 890ddd
{
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
Toshihiro Shimizu 890ddd
    Another important use for the ScreenBoard is that of allowing dektop-wide 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
Toshihiro Shimizu 890ddd
    Screen widgets redirect any event they receive to drawings that accept redirection
Toshihiro Shimizu 890ddd
    through the Drawings::accpetScreenEvents() method.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
    The drawings() list sorting affects the order in which events from screen widgets
Toshihiro Shimizu 890ddd
    are delivered to drawings.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
    In particular, drawings'  stacking order <\I> is \b inverse to the their 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
Toshihiro Shimizu 890ddd
class DVAPI ScreenBoard : public QObject
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	Q_OBJECT
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	class Drawing;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	class ScreenWidget;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QVector<screenwidget *=""> m_screenWidgets;</screenwidget>
Toshihiro Shimizu 890ddd
	QList<drawing *=""> m_drawings;</drawing>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QCursor m_cursor;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool m_grabbing;
Toshihiro Shimizu 890ddd
	bool m_mouseOnAScreen;
Toshihiro Shimizu 890ddd
	bool m_updated;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	static ScreenBoard *instance();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	const QList<drawing *=""> &drawings() const { return m_drawings; }</drawing>
Toshihiro Shimizu 890ddd
	QList<drawing *=""> &drawings() { return m_drawings; }</drawing>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void grabMouse(const QCursor &cursor); //!< Grabs mouse inputs across the whole desktop.
Toshihiro Shimizu 890ddd
	void releaseMouse();				   //!< Releases the mouse grab after grabMouse().
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool grabbingMouse() const { return m_grabbing; } //!< Whether mouse grabbing is on.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	ScreenBoard();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void reallocScreenWidgets();
Toshihiro Shimizu 890ddd
	void ensureMouseOnAScreen();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public slots:
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void update(); //!< Refreshes the screen widgets pool and updates them.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private slots:
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	friend class ScreenWidget;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void trackCursor();
Toshihiro Shimizu 890ddd
	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.
Toshihiro Shimizu 890ddd
class ScreenBoard::Drawing
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	//! Generic event handler for drawings.
Toshihiro Shimizu 890ddd
	/*! Reimplement it to receive events from screen widgets other than paint events.
Toshihiro Shimizu 890ddd
      Paint events are \b not received in this handler, since they must be delivered
Toshihiro Shimizu 890ddd
      in reverse order.
Toshihiro Shimizu 890ddd
  */
Toshihiro Shimizu 890ddd
	virtual void event(QWidget *widget, QEvent *e) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! Paints the drawing on the specified screen widget. Use the widget's
Toshihiro Shimizu 890ddd
	//! mapFromGlobal() function to match desktop coordinates to screen coordinates.
Toshihiro Shimizu 890ddd
	virtual void paintEvent(QWidget *widget, QPaintEvent *pe) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! Returns whether the drawing is interested in events from the passed screen geometry.
Toshihiro Shimizu 890ddd
	//! Accepting a screen causes a screen widget to be allocated in order to receive events.
Toshihiro Shimizu 890ddd
	virtual bool acceptScreenEvents(const QRect &screenRect) const = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} //namespace DVGui
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif //SCREENBOARD_H