KDEGames

kgameio.h
1 /*
2  This file is part of the KDE games library
3  Copyright (C) 2001 Martin Heni (kde at heni-online.de)
4  Copyright (C) 2001 Andreas Beckermann ([email protected])
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #ifndef __KGAMEIO_H__
22 #define __KGAMEIO_H__
23 
24 #include <QString>
25 #include <QObject>
26 
27 #include "libkdegamesprivate_export.h"
28 
29 class QEvent;
30 class QGraphicsScene;
31 class QKeyEvent;
32 class QMouseEvent;
33 class KPlayer;
34 class KGame;
35 class KGameIOPrivate;
36 class KGameKeyIOPrivate;
37 class KGameMouseIOPrivate;
38 class KGameProcessIOPrivate;
39 class KGameComputerIOPrivate;
40 
65 class KDEGAMESPRIVATE_EXPORT KGameIO : public QObject
66 {
67  Q_OBJECT
68 
69 public:
73  KGameIO();
74  explicit KGameIO(KPlayer*);
75  virtual ~KGameIO();
76 
80  void Debug();
81 
85  enum IOMode {GenericIO=1,KeyIO=2,MouseIO=4,ProcessIO=8,ComputerIO=16};
92  virtual int rtti() const = 0; // Computer, network, local, ...
93 
99  KPlayer *player() const;
100 
105  KGame* game() const;
106 
114  void setPlayer(KPlayer *p);
115 
125  virtual void initIO(KPlayer *p);
126 
136  virtual void notifyTurn(bool b);
137 
141  bool sendInput(QDataStream& stream, bool transmit = true, quint32 sender = 0);
142 
143 Q_SIGNALS:
175  void signalPrepareTurn(QDataStream & stream, bool turn, KGameIO *io, bool * send);
176 
177 
178 private:
179  friend class KGameIOPrivate;
180  KGameIOPrivate *const d;
181 
183 };
184 
192 class KDEGAMESPRIVATE_EXPORT KGameKeyIO : public KGameIO
193 {
194  Q_OBJECT
195 
196 public:
217  explicit KGameKeyIO(QWidget *parent);
218  virtual ~KGameKeyIO();
219 
225  int rtti() const override;
226 
227 Q_SIGNALS:
249  void signalKeyEvent(KGameIO *io,QDataStream &stream,QKeyEvent *m,bool *eatevent);
250 
251 protected:
255  bool eventFilter( QObject *o, QEvent *e ) override;
256 
257 private:
258  friend class KGameKeyIOPrivate;
259  KGameKeyIOPrivate *const d;
260 
262 };
263 
271 class KDEGAMESPRIVATE_EXPORT KGameMouseIO : public KGameIO
272 {
273  Q_OBJECT
274 
275 public:
291  explicit KGameMouseIO(QWidget *parent,bool trackmouse=false);
292  explicit KGameMouseIO(QGraphicsScene *parent,bool trackmouse=false);
293  virtual ~KGameMouseIO();
294 
300  void setMouseTracking(bool b);
306  int rtti() const override;
307 
308 Q_SIGNALS:
328  void signalMouseEvent(KGameIO *io,QDataStream &stream,QMouseEvent *m,bool *eatevent);
329 
330 protected:
334  bool eventFilter( QObject *o, QEvent *e ) override;
335 
336 private:
337  friend class KGameMouseIOPrivate;
338  KGameMouseIOPrivate *const d;
339 
341 };
342 
343 
353 class KDEGAMESPRIVATE_EXPORT KGameProcessIO : public KGameIO
354 {
355  Q_OBJECT
356 
357 public:
373  explicit KGameProcessIO(const QString& name);
374 
378  virtual ~KGameProcessIO();
379 
385  int rtti() const override;
386 
397  void sendMessage(QDataStream &stream,int msgid, quint32 receiver, quint32 sender);
398 
409  void sendSystemMessage(QDataStream &stream, int msgid, quint32 receiver, quint32 sender);
410 
419  void initIO(KPlayer *p) override;
420 
430  void notifyTurn(bool turn) override;
431 
432  protected:
436  void sendAllMessages(QDataStream &stream,int msgid, quint32 receiver, quint32 sender, bool usermsg);
437 
438  protected Q_SLOTS:
442  void receivedMessage(const QByteArray& receiveBuffer);
443 
444 
445 Q_SIGNALS:
469  void signalProcessQuery(QDataStream &stream,KGameProcessIO *me);
470 
481  void signalIOAdded(KGameIO *game,QDataStream &stream,KPlayer *p,bool *send);
482 
486  void signalReceivedStderr(const QString &msg);
487 
488 private:
489  friend class KGameProcessIOPrivate;
490  KGameProcessIOPrivate *const d;
491 
493 };
494 
513 class KDEGAMESPRIVATE_EXPORT KGameComputerIO : public KGameIO
514 {
515  Q_OBJECT
516 
517 public:
522  KGameComputerIO();
523  explicit KGameComputerIO(KPlayer* player);
524  ~KGameComputerIO();
525 
526  int rtti() const override;
527 
532  void setReactionPeriod(int advanceCalls);
533  int reactionPeriod() const;
534 
538  void setAdvancePeriod(int ms);
539 
540  void stopAdvancePeriod();
541 
554  void pause(int calls = -1);
555 
560  void unpause();
561 
562 public Q_SLOTS:
578  virtual void advance();
579 
580 Q_SIGNALS:
585  void signalReaction();
586 
587 protected:
591  virtual void reaction();
592 
593 private:
594  friend class KGameComputerIOPrivate;
595  KGameComputerIOPrivate *const d;
596 
598 };
599 
600 
601 #endif
virtual void notifyTurn(bool b)
Notifies the IO device that the player&#39;s setTurn had been called Called by KPlayer.
Definition: kgameio.cpp:94
The KGameProcessIO class.
Definition: kgameio.h:353
The KGameMouseIO class.
Definition: kgameio.h:271
IOMode
Identifies the KGameIO via the rtti function.
Definition: kgameio.h:85
virtual bool eventFilter(QObject *watched, QEvent *event)
virtual void initIO(KPlayer *p)
Init this device by setting the player and e.g.
Definition: kgameio.cpp:89
Base class for a game player.
Definition: kplayer.h:69
Q_DISABLE_COPY(Class)
The main KDE game object.
Definition: kgame.h:64
KGameIO variant for real-time games.
Definition: kgameio.h:513
The KGameKeyIO class.
Definition: kgameio.h:192
virtual int rtti() const =0
Run time identification.
Base class for IO devices for games.
Definition: kgameio.h:65
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Nov 26 2020 22:36:18 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.