File indexing completed on 2024-05-26 04:08:16
0001 /*************************************************************************** 0002 * Copyright 2010 Stefan Majewsky <majewsky@gmx.net> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify * 0005 * it under the terms of the GNU Library General Public License * 0006 * version 2 as published by the Free Software Foundation * 0007 * * 0008 * This program is distributed in the hope that it will be useful, * 0009 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0011 * GNU Library General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU Library General Public * 0014 * License along with this program; if not, write to the * 0015 * Free Software Foundation, Inc., * 0016 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 0017 ***************************************************************************/ 0018 0019 #ifndef TAGARO_SCENE_H 0020 #define TAGARO_SCENE_H 0021 0022 #include <QGraphicsScene> 0023 0024 class KGameRenderer; 0025 class KGameRendererClient; 0026 0027 namespace Tagaro { 0028 0029 /** 0030 * @class Tagaro::Scene scene.h <Tagaro/Scene> 0031 * @brief QGraphicsScene with automatic viewport transform adjustments 0032 * 0033 * This QGraphicsScene subclass provides integration with Tagaro and 0034 * miscellaneous convenience features: 0035 * @li It acts as a Tagaro::RendererClient to fetch a scene background pixmap. 0036 * @li It can be used to keep the QGraphicsScene's sceneRect() in sync 0037 * with the rect() of a QGraphicsView instance (the "main view"). 0038 */ 0039 class Scene : public QGraphicsScene 0040 { 0041 Q_OBJECT 0042 public: 0043 ///Creates a new Tagaro::Scene instance. 0044 explicit Scene(QObject* parent = nullptr); 0045 ///@overload 0046 ///Initializes the renderer client for the scene background brush with 0047 ///the given renderer and sprite key. 0048 Scene(KGameRenderer* backgroundRenderer, const QString& backgroundSpriteKey, QObject* parent = nullptr); 0049 ///Destroys this Tagaro::Scene instance. 0050 ~Scene() override; 0051 0052 ///@return the main view of this scene 0053 QGraphicsView* mainView() const; 0054 ///Sets the main view of this scene (null by default). If set, the 0055 ///scene's sceneRect() will always be set equal to the view's rect(). 0056 ///The scene will then suppress manual changes to the sceneRect() as 0057 ///much as possible. 0058 /// 0059 ///This will also install this scene on the @a mainView. The behavior is 0060 ///undefined if you set another scene on this view while it is this 0061 ///scene's main view. 0062 void setMainView(QGraphicsView* mainView); 0063 0064 ///@return the renderer client for the scene's background brush 0065 ///Use this to modify the background brush. 0066 ///@warning Do not call setRenderSize() on this instance! The render 0067 ///size is managed by the scene. Use setBackgroundBrushRenderSize() 0068 ///instead. 0069 KGameRendererClient* backgroundBrushClient() const; 0070 ///@return the background brush's render size 0071 /// 0072 ///If the render size is determined from the size of the sceneRect() 0073 ///(the default), returns an invalid size. To determine the actual 0074 ///render size, use backgroundBrushClient()->renderSize(). 0075 QSize backgroundBrushRenderSize() const; 0076 ///Sets the background brush's render size. If you set this to a valid 0077 ///size, the background will be painted as a tiled pixmap of that size. 0078 ///If an invalid size is set (the default), determine the actual render 0079 ///size from the sceneRect(). 0080 void setBackgroundBrushRenderSize(const QSize& size); 0081 protected: 0082 bool eventFilter(QObject* watched, QEvent* event) override; 0083 private: 0084 struct Private; 0085 Private* const d; 0086 Q_PRIVATE_SLOT(d, void _k_updateSceneRect(const QRectF&)) 0087 }; 0088 0089 } //namespace Tagaro 0090 0091 #endif // TAGARO_SCENE_H