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 COLORPEG_H 20 #define COLORPEG_H 21 22 #include <QColor> 23 #include <QPen> 24 #include <QRadialGradient> 25 #include <QGraphicsItem> 26 #include <iostream> 27 #include <vector> 28 #include "colorcode.h" 29 #include "pegrow.h" 30 #include "rowhint.h" 31 #include "settings.h" 32 33 34 class ColorPeg : public QObject, public QGraphicsItem 35 { 36 Q_OBJECT 37 Q_INTERFACES(QGraphicsItem) 38 39 public: 40 ColorPeg(QObject* parent = 0); 41 ~ColorPeg(); 42 43 int mId; 44 void SetId(int id); 45 46 void SetPegType(PegType* pt); 47 void SetPegRow(PegRow* pr); 48 49 QRectF boundingRect() const; 50 QPainterPath shape() const; 51 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget); 52 53 void SetType(const int t); 54 void SetPaused(const bool b); 55 void SetEnabled(const bool b); 56 void SetIndicator(const bool b, const int t, const bool c); 57 void SetCursorShape( Qt::CursorShape shape = Qt::ArrowCursor, const bool force = false); 58 PegType* GetPegType(); 59 int GetType() const; 60 QColor GetPenColor() const; 61 QColor GetBrushColor() const; 62 bool GetIsDragged() const; 63 64 bool IsBtn() const; 65 int GetSort() const; 66 void SetBtn(bool b); 67 void Reset(); 68 void ForceRelease(); 69 70 signals: 71 void PegReleasedSignal(ColorPeg* cp); 72 void PegPressSignal(ColorPeg* cp); 73 void PegSortSignal(ColorPeg* cp); 74 75 protected: 76 PegType* mPegType; 77 QVariant itemChange(GraphicsItemChange change, const QVariant &value); 78 79 void mousePressEvent(QGraphicsSceneMouseEvent* e); 80 void mouseReleaseEvent(QGraphicsSceneMouseEvent* e); 81 82 private: 83 static const QFont mFont; 84 static QFont GetLetterFont(); 85 static const QBrush mShadowBrush; 86 static QBrush GetShadowBrush(); 87 static const QBrush mOutlineBrush; 88 static QBrush GetOutlineBrush(); 89 static const QBrush mGlossyBrush; 90 static QBrush GetGlossyBrush(); 91 static const QBrush mNeutralBrush; 92 static QBrush GetNeutralBrush(); 93 94 QRectF GetColorRect() const; 95 QRectF outlineRect() const; 96 void SetIsDragged(bool b); 97 98 PegRow* mPegRow; 99 100 const QBrush mBrush; 101 102 int mType; 103 int mSort; 104 bool mIsBtn; 105 bool mIsDragged; 106 bool mShowIndicator; 107 int mIndicatorType; 108 bool mHideColor; 109 bool mEnabledBuff; 110 }; 111 112 113 114 #endif // COLORPEG_H 115