1 /* ColorCode, a free MasterMind clone with built in solver
2  * Copyright (C) 2009  Dirk Laebisch
3  * http://www.laebisch.com/
4  *
5  * ColorCode is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * ColorCode 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with ColorCode. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef PEGROW_H
20 #define PEGROW_H
21 
22 #include <QObject>
23 #include <QColor>
24 #include <QPen>
25 #include <QRadialGradient>
26 #include <QGraphicsItem>
27 #include <iostream>
28 #include <vector>
29 #include "colorcode.h"
30 
31 class ColorPeg;
32 
33 class PegRow : public QObject, public QGraphicsItem
34 {
35     Q_OBJECT
36     Q_INTERFACES(QGraphicsItem)
37 
38 public:
39     PegRow(QObject* parent = 0);
40     ~PegRow();
41 
42     int GetIx() const;
43     bool IsActive() const;
44     int GetPegCnt() const;
45     ColorPeg** GetPegs();
46     std::vector<int> GetSolution() const;
47     void SetIx(const int ix);
48     void SetPegCnt(const int pegcnt);
49     void SetGameMode(const int gamemode);
50     void SetActive(const bool b);
51     bool SnapCP(ColorPeg* cp);
52     void ForceSnap(ColorPeg* cp, int posix);
53     void RemovePeg(ColorPeg* cp);
54 
55     void CloseRow();
56     void OpenRow();
57     void ClearRow();
58     void Reset(const int pegcnt, const int gamemode);
59 
60     void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
61     QRectF boundingRect() const;
62     QPainterPath shape() const;
63 
64 signals:
65     void RowSolutionSignal(int ix);
66     void RemovePegSignal(ColorPeg* cp);
67 
68 protected:
69     std::vector<int> mSolution;
70 
71     QColor mPend;
72     QColor mPenl;
73     QColor mGrad0;
74     QColor mGrad1;
75     bool mIsActive;
76     bool mSolved;
77     int mIx;
78     int mPegCnt;
79     int mGameMode;
80     int mXOffs;
81 
82     virtual void SetXOffs();
83 
84     void CheckSolution();
85     ColorPeg** mColorPegs;
86     QRectF outlineRect() const;
87 
88 };
89 
90 #endif // PEGROW_H
91