File indexing completed on 2024-09-01 03:55:04
0001 /* 0002 This file is part of the KDE games lskat program 0003 SPDX-FileCopyrightText: 2006 Martin Heni <kde@heni-online.de> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef LSKAT_GAMEVIEW_H 0009 #define LSKAT_GAMEVIEW_H 0010 0011 // Qt includes 0012 #include <QElapsedTimer> 0013 #include <QGraphicsScene> 0014 #include <QGraphicsSceneMouseEvent> 0015 #include <QGraphicsTextItem> 0016 #include <QGraphicsView> 0017 #include <QList> 0018 #include <QPoint> 0019 #include <QResizeEvent> 0020 #include <QSize> 0021 #include <QWidget> 0022 0023 // Forward declaration 0024 class ThemeManager; 0025 0026 /** 0027 * The view object which shows the graphics in a 0028 * Qt graphics view. 0029 */ 0030 class GameView : public QGraphicsView 0031 { 0032 Q_OBJECT 0033 0034 public: 0035 /** 0036 * Constructor for the canvas view. 0037 * @param size The canvas fixed size 0038 * @param advancePeriod The canvas advance period 0039 * @param scene The graphics scene 0040 * @param theme The theme manager 0041 * @param parent The parent window 0042 */ 0043 GameView(const QSize &size, int advancePeriod, QGraphicsScene *scene, ThemeManager *theme, QWidget *parent = nullptr); 0044 0045 /** 0046 * Destructor. 0047 */ 0048 ~GameView() override; 0049 0050 protected: 0051 /** 0052 * React to mouse clicks. 0053 * @param event The mouse event 0054 */ 0055 void mouseReleaseEvent(QMouseEvent *event) override; 0056 0057 public Q_SLOTS: 0058 /** 0059 * The update and advance for the canvas. 0060 * This is called by a timer at regular intervals. 0061 */ 0062 void updateAndAdvance(); 0063 0064 /** 0065 * Rescale the theme (update theme SVG graphics). 0066 */ 0067 void rescaleTheme(); 0068 0069 Q_SIGNALS: 0070 /** 0071 * Emit the signal on mouse clicks. 0072 * @param point The mouse coordinate. 0073 */ 0074 void signalLeftMousePress(QPoint point); 0075 0076 protected: 0077 /** 0078 * Will be called by the Qt View when its contents are resized. 0079 * We adapt the canvas then. 0080 * @param e The resize event 0081 */ 0082 void resizeEvent(QResizeEvent *e) override; 0083 0084 /** 0085 * Paint function for the widget, temporary fix while we wait for QGV 4.3 0086 * @param event The paint event 0087 */ 0088 void paintEvent(QPaintEvent *event) override; 0089 0090 /** 0091 * Overwritten Qt function. 0092 */ 0093 void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[], const QStyleOptionGraphicsItem options[]) override; 0094 0095 private: 0096 // Theme manager 0097 ThemeManager *mTheme; 0098 // Theme queue 0099 QList<int> mThemeQueue; 0100 // Theme offset queue 0101 QList<QPoint> mThemeOffset; 0102 // Active input offset 0103 QPoint mInputOffset; 0104 // Theme queue delay time [ms] 0105 QElapsedTimer mTimeStart; 0106 // Debug frame rate sprite 0107 QGraphicsTextItem *mFrameSprite; 0108 // Time between updates 0109 int mDisplayUpdateTime; 0110 // Average update times 0111 QList<int> mDrawTimes; 0112 }; 0113 0114 #endif // LSKAT_GAMEVIEW_H