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 #include <QtWidgets>
19 
20 #include "background.h"
21 #include "pegfactory.h"
22 
23 using namespace std;
24 
BackGround(QObject *)25 BackGround::BackGround(QObject*)
26 {
27     setCacheMode(QGraphicsItem::DeviceCoordinateCache);
28     setAcceptedMouseButtons(0);
29 
30     QLinearGradient topgrad(0, 16, 0, 129);
31     topgrad.setColorAt(0.0, QColor(0xf8, 0xf8, 0xf8));
32     topgrad.setColorAt(0.6, QColor(0xb8, 0xb9, 0xbb));
33     topgrad.setColorAt(1, QColor(0xd4, 0xd5, 0xd7));
34     mTopGrad = QBrush(topgrad);
35 
36     QLinearGradient botgrad(0, 530, 0, 557);
37     botgrad.setColorAt(0.0, QColor("#d4d5d7"));
38     botgrad.setColorAt(0.3, QColor("#cecfd1"));
39     botgrad.setColorAt(1.0, QColor("#b0b1b3"));
40     mBotGrad = QBrush(botgrad);
41 
42     QLinearGradient lgrad(0, 190, 320, 370);
43     lgrad.setColorAt(0.0, QColor(0xff, 0xff, 0xff, 0xa0));
44     lgrad.setColorAt(0.49, QColor(0xff, 0xff, 0xff, 0xa0));
45     lgrad.setColorAt(0.50, QColor(0, 0, 0, 0x80));
46     lgrad.setColorAt(1.0, QColor(0, 0, 0, 0x80));
47     mFramePen = QPen(QBrush(lgrad), 1);
48 
49     mPend = QColor("#646568");
50     mPenl = QColor("#ecedef");
51     mGrad0 = QColor("#cccdcf");
52     mGrad1 = QColor("#fcfdff");
53 
54     mPend.setAlpha(0x32);
55     mPenl.setAlpha(0x50);
56     mGrad0.setAlpha(0x32);
57     mGrad1.setAlpha(0x32);
58 }
59 
~BackGround()60 BackGround::~BackGround()
61 {
62     scene()->removeItem(this);
63 }
64 
boundingRect() const65 QRectF BackGround::boundingRect() const
66 {
67     const int margin = 1;
68     return outlineRect().adjusted(-margin, -margin, +margin, +margin);
69 }
70 
outlineRect() const71 QRectF BackGround::outlineRect() const
72 {
73     return QRectF(0.0, 0.0, 320.0, 560.0);
74 }
75 
paint(QPainter * painter,const QStyleOptionGraphicsItem *,QWidget *)76 void BackGround::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /* widget */)
77 {
78     int i;
79 
80     painter->setPen(Qt::NoPen);
81 
82     QRectF cr = QRectF(3, 3, 314, 554);
83     QPainterPath cpath;
84     cpath.addRoundedRect(cr, 10.1, 10.1);
85     painter->setClipPath(cpath);
86     painter->setClipping(true);
87 
88     painter->setBrush(mTopGrad);
89     painter->drawRect(QRect(4, 4, 312, 125));
90     painter->setBrush(QBrush(QColor("#707173")));
91     painter->drawRect(QRect(1, 129, 318, 1));
92 
93     painter->setPen(Qt::NoPen);
94     for (i = 0; i < 10; ++i)
95     {
96         painter->setBrush(QBrush(QColor("#9e9fa0")));
97         painter->drawRect(QRect(1, i * 40 + 130, 318, 1));
98         QLinearGradient rowgrad(0, i * 40 + 131, 0, i * 40 + 169);
99         rowgrad.setColorAt(0.0, QColor("#9a9b9d"));
100         rowgrad.setColorAt(1.0, QColor("#949597"));
101         painter->setBrush(QBrush(rowgrad));
102         painter->drawRect(QRect(1, i * 40 + 131, 318, 38));
103         painter->setBrush(QBrush(QColor("#88898b")));
104         painter->drawRect(QRect(1, i * 40 + 169, 318, 1));
105 
106         painter->setBrush(QBrush(mPenl));
107         painter->drawRect(QRectF(277, i * 40 + 130, 39, 1));
108         painter->drawRect(QRectF(277, i * 40 + 130, 1, 39));
109         painter->setBrush(QBrush(mPend));
110         painter->drawRect(QRectF(277, i * 40 + 130 + 39, 40, 1));
111         painter->drawRect(QRectF(277 + 39, i * 40 + 130, 1, 40));
112 
113         QRadialGradient grad(QPointF(277 + 10, i * 40 + 130 + 10), 100);
114         grad.setColorAt(0, mGrad0);
115         grad.setColorAt(1, mGrad1);
116         painter->setBrush(QBrush(grad));
117         painter->drawRect(QRectF(277 + 1, i * 40 + 131, 38.0, 38.0));
118 
119         painter->setBrush(Qt::NoBrush);
120         QPointF x0 = QPointF(PegFactory::XPOS_BTNS_COL, i * 40 + 130 + 2);
121         QLinearGradient lgrad(x0, QPointF(x0.x() + 36, x0.y() + 36));
122         lgrad.setColorAt(0.0, QColor(0, 0, 0, 0x80));
123         lgrad.setColorAt(1.0, QColor(0xff, 0xff, 0xff, 0xa0));
124         painter->setPen(QPen(QBrush(lgrad), 0.5));
125         painter->drawEllipse(QRectF(x0.x(), x0.y(), 36, 36));
126         painter->setPen(Qt::NoPen);
127     }
128 
129     painter->setBrush(mBotGrad);
130     painter->drawRect(QRect(1, 531, 318, 27));
131     painter->setBrush(QBrush(QColor("#eff0f2")));
132     painter->drawRect(QRect(1, 530, 318, 1));
133 
134     painter->setClipping(false);
135 
136     QRectF r = QRectF(3.5, 3.5, 313, 553);
137     painter->setBrush(Qt::NoBrush);
138     painter->setPen(mFramePen);
139     painter->drawRoundedRect(r, 9.8, 9.8);
140 }
141 
142 
143