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 #include <QtWidgets>
20 #include "solutionrow.h"
21
22 using namespace std;
23
SolutionRow(QObject *)24 SolutionRow::SolutionRow(QObject*)
25 {
26 setCacheMode(QGraphicsItem::DeviceCoordinateCache);
27 InitGraphics();
28 }
29
~SolutionRow()30 SolutionRow::~SolutionRow()
31 {
32 }
33
InitGraphics()34 void SolutionRow::InitGraphics()
35 {
36 mRect = QRectF(0.5, 0.5, 219, 39);
37 mRectC = QRectF(2, 2, 216, 36);
38
39 QLinearGradient solgrad(0, 0, 0, 40);
40 solgrad.setColorAt(0.0, QColor("#9fa0a2"));
41 solgrad.setColorAt(1.0, QColor("#8c8d8f"));
42 mBgBrush = QBrush(solgrad);
43
44 QLinearGradient framegrad(0, 0, 0, 40);
45 framegrad.setColorAt(0.0, QColor("#4e4f51"));
46 framegrad.setColorAt(1.0, QColor("#ebecee"));
47 mFramePen = QPen(QBrush(framegrad), 1);
48
49 mFont = QFont("Arial", 22, QFont::Bold, false);
50 mFont.setStyleHint(QFont::SansSerif);
51 mFont.setPixelSize(29);
52 }
53
SetXOffs()54 void SolutionRow::SetXOffs()
55 {
56 mXOffs = 110 - mPegCnt * 20;
57 }
58
boundingRect() const59 QRectF SolutionRow::boundingRect() const
60 {
61 const double margin = 0.5;
62 return mRect.adjusted(-margin, -margin, 2 * margin, 2 * margin);
63 }
64
paint(QPainter * painter,const QStyleOptionGraphicsItem *,QWidget *)65 void SolutionRow::paint(QPainter *painter, const QStyleOptionGraphicsItem* , QWidget* )
66 {
67 if (mPegCnt == 0)
68 {
69 return;
70 }
71
72 int i;
73 painter->setBrush(mBgBrush);
74 painter->setPen(mFramePen);
75 painter->drawRoundedRect(mRect, 20, 20);
76
77 QPainterPath cpath;
78 cpath.addRoundedRect(mRectC, 19, 19);
79 painter->setClipPath(cpath);
80
81 painter->setRenderHint(QPainter::TextAntialiasing, true);
82
83 int x0 = (220 - mPegCnt * 40) / 2;
84 int xpos;
85 for (i = 0; i <= mPegCnt; ++i)
86 {
87 xpos = x0 + i * 40;
88 painter->setPen(Qt::NoPen);
89 painter->setBrush(QBrush(QColor(0x7d, 0x7e, 0x80, 0x80)));
90 painter->drawRect(xpos - 1, 1, 1, 38);
91 painter->setBrush(QBrush(QColor(0xc3, 0xc4, 0xc6, 0x80)));
92 painter->drawRect(xpos, 1, 1, 38);
93
94 if (i < mPegCnt)
95 {
96 painter->setPen(QPen(QColor("#ff9933")));
97 painter->setFont(mFont);
98 painter->drawText(QRectF(xpos + 3.0, 3.0, 34.0, 34.0), Qt::AlignCenter, QString('?'));
99 }
100 }
101 }
102