kcubewidget.h 2.96 KB
Newer Older
Stephan Kulow's avatar
Stephan Kulow committed
1 2 3
/* ****************************************************************************
  This file is part of the game 'KJumpingCube'

4
  Copyright (C) 1998-2000 by Matthias Kiefer
Stephan Kulow's avatar
Stephan Kulow committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18
                            <matthias.kiefer@gmx.de>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
Dirk Mueller's avatar
Dirk Mueller committed
19
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
Stephan Kulow's avatar
Stephan Kulow committed
20 21 22 23 24

**************************************************************************** */
#ifndef KCUBEWIDGET_H
#define KCUBEWIDGET_H

25
#include <QFrame>
26 27 28 29
#include "ai_globals.h"

enum SVGElement {Neutral, Player1, Player2, Pip, BlinkLight, BlinkDark,
                 FirstElement = Neutral, LastElement = BlinkDark};
Stephan Kulow's avatar
Stephan Kulow committed
30

31 32
class QMouseEvent;
class QPaintEvent;
Stephan Kulow's avatar
Stephan Kulow committed
33 34 35 36

/**
* 
*/
Ian Wadham's avatar
Ian Wadham committed
37
class KCubeWidget : public QFrame
Stephan Kulow's avatar
Stephan Kulow committed
38 39 40 41 42
{
   Q_OBJECT
         
public:
   /** constructs a new KCubeWidget*/
43
   explicit KCubeWidget (QWidget * parent = 0);
44 45 46 47 48 49 50
   virtual ~KCubeWidget();

   Player owner() { return m_owner; }
   int    value() { return m_value; }

   void setOwner   (Player newOwner); 
   void setValue   (int newValue);
Ian Wadham's avatar
Ian Wadham committed
51
   void setPixmaps (QList<QPixmap> * ptr);
52

Stephan Kulow's avatar
Stephan Kulow committed
53 54 55 56
   /** 
   * sets the coordinates of the Cube in a Cubebox;
   * needed for identification when clicked.
   */ 
57
   void setCoordinates (int row, int col, int limit);
Ian Wadham's avatar
Ian Wadham committed
58

Stephan Kulow's avatar
Stephan Kulow committed
59 60
   /** enables or disables possibility to click a cube*/
   static void enableClicks(bool flag);
61

62 63 64 65 66 67 68
   void setLight()   { blinking = Light; update(); }
   void setDark()    { blinking = Dark; update(); }
   void setNeutral() { blinking = None; update(); }
   bool isNeutral()  { return (blinking == None); }

   void shrink (qreal scale);
   void expand (qreal scale);
69
   void migrateDot (int rowDiff, int colDiff, int step, Player player);
70

Stephan Kulow's avatar
Stephan Kulow committed
71 72 73 74 75
public slots:
   /** resets the Cube to default values */
   virtual void reset();
   /** shows changed colors*/
   virtual void updateColors();
Ian Wadham's avatar
Ian Wadham committed
76

Stephan Kulow's avatar
Stephan Kulow committed
77
signals:
78
   void clicked (int row, int column);
Ian Wadham's avatar
Ian Wadham committed
79

Stephan Kulow's avatar
Stephan Kulow committed
80 81
protected:
   /** checks, if mouseclick was inside this cube*/
Laurent Montel's avatar
Laurent Montel committed
82
   void mouseReleaseEvent(QMouseEvent*) Q_DECL_OVERRIDE;
Ian Wadham's avatar
Ian Wadham committed
83

Jaison Lee's avatar
Jaison Lee committed
84
   /** refreshes the contents of the Cube */
Laurent Montel's avatar
Laurent Montel committed
85
   void paintEvent(QPaintEvent*) Q_DECL_OVERRIDE;
Stephan Kulow's avatar
Stephan Kulow committed
86 87

private:
88 89 90
   int m_row;
   int m_col;
   int m_limit;
91 92 93
   Player m_owner;
   int m_value;

94 95 96
   QList<QPixmap> * pixmaps;
   enum Blink {None, Light, Dark};
   Blink blinking;
Ian Wadham's avatar
Ian Wadham committed
97

Stephan Kulow's avatar
Stephan Kulow committed
98
   static bool _clicksAllowed;
99 100 101
   int   migrating;
   qreal m_rowDiff;
   qreal m_colDiff;
102
   Player m_player;
103 104
   qreal m_scale;
   qreal m_opacity;
Stephan Kulow's avatar
Stephan Kulow committed
105 106 107
};

#endif // KCUBEWIDGET_H