File indexing completed on 2024-04-28 04:02:06

0001 /*
0002     This file is part of the KDE games kwin4 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 DISPLAY_INTRO_H
0009 #define DISPLAY_INTRO_H
0010 
0011 // own
0012 #include "kwin4global.h"
0013 #include "thememanager.h"
0014 // KDEGames
0015 #define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API
0016 #include <libkdegamesprivate/kgame/kgameio.h>
0017 // Qt
0018 #include <QEvent>
0019 #include <QGraphicsPixmapItem>
0020 #include <QGraphicsScene>
0021 #include <QGraphicsTextItem>
0022 #include <QList>
0023 #include <QTimer>
0024 
0025 // Forward declaration
0026 class QGraphicsView;
0027 class PixmapSprite;
0028 class ButtonSprite;
0029 
0030 /**
0031  * The view object which shows the graphics of the welcome screen
0032  * animation.
0033  */
0034 class DisplayIntro : public QObject, public virtual Themeable
0035 {
0036     Q_OBJECT
0037 
0038 public:
0039     /**
0040      * Constructor for the intro display.
0041      *  @param scene         The graphics scene
0042      *  @param theme         The theme manager
0043      *  @param parent        The parent window
0044      */
0045     DisplayIntro(QGraphicsScene *scene, ThemeManager *theme, QGraphicsView *parent);
0046 
0047     /**
0048      * Destructor of the display.
0049      */
0050     ~DisplayIntro() override;
0051 
0052     /**
0053      * Start the animation.
0054      * @param delay An optional delay for the animation [ms]
0055      */
0056     void start(int delay = 1000);
0057 
0058     /**
0059      * Theme change method. The object has to completely redraw
0060      */
0061     void changeTheme() override;
0062 
0063     /**
0064      * Called from the view event viewportEvent() to handle mouse events.
0065      * NOTE: An own event handler is implemented  because the Qt4.3 QGraphicsView event
0066      *       handling system is faulty!!!! This can be moved to Qt events if they work.
0067      * @param event The event
0068      */
0069     void viewEvent(QEvent *event);
0070 
0071 protected:
0072     /**
0073      * Setup the sprite animation scripts.
0074      * @param restartTime Restart the time (debug, should be true)
0075      * @return The animation duration [ms].
0076      */
0077     int createAnimation(bool restartTime);
0078 
0079     /**
0080      * Put a global delay on the animation of all sprites. Could be caused by
0081      * slow SVG resizes.
0082      * @param duration Delay [ms]
0083      */
0084     void delaySprites(int duration);
0085 
0086 Q_SIGNALS:
0087     /**
0088      * Emit this signal if a new game is started from the intro display.
0089      * @param startPlayer Color of the starting player
0090      * @param input0      Input device of player 1
0091      * @param input1      Input device of player 2
0092      * @param aiLevel     Level for AI (-1: no change)
0093      */
0094     void signalQuickStart(COLOUR startPlayer, KGameIO::IOMode input0, KGameIO::IOMode input1, int aiLevel);
0095 
0096 protected Q_SLOTS:
0097     /**
0098      * Animation routine, called by a timer.
0099      */
0100     void advance();
0101 
0102     /**
0103      * A graphic button is pressed.
0104      * @param item The button
0105      * @param id   The button id
0106      */
0107     void buttonPressed(QGraphicsItem *item, int id);
0108 
0109     /**
0110      * Find a sprite for a given absolute widget coordinate.
0111      * @param pos The screen coordinate
0112      * @return The highest sprite under the position or null.
0113      */
0114     QGraphicsItem *findSprite(QPoint pos);
0115 
0116 private:
0117     // The theme manager
0118     ThemeManager *mTheme;
0119 
0120     // The graphics scene to write to
0121     QGraphicsScene *mScene;
0122 
0123     // List of all sprites used
0124     QList<QGraphicsItem *> mSprites;
0125 
0126     // The animation timer
0127     QTimer *mTimer;
0128 
0129     // The view
0130     QGraphicsView *mView;
0131 
0132     // Text items
0133     QGraphicsTextItem *mTextQuicklaunch;
0134     // Text items
0135     QGraphicsTextItem *mTextStartplayer;
0136     // Text items
0137     QGraphicsTextItem *mTextColor;
0138 
0139     // Buttons
0140     ButtonSprite *mStartButton[2];
0141     ButtonSprite *mPlayerButton[2];
0142 
0143     // Quick launch sprite
0144     PixmapSprite *mQuickLaunch;
0145 
0146     // Last event sprite
0147     QGraphicsItem *mLastMoveEvent;
0148 };
0149 
0150 #endif