File: background.cpp

package info (click to toggle)
colorcode 0.8.5-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,224 kB
  • sloc: cpp: 8,331; makefile: 57
file content (142 lines) | stat: -rw-r--r-- 4,778 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* ColorCode, a free MasterMind clone with built in solver
 * Copyright (C) 2009  Dirk Laebisch
 * http://www.laebisch.com/
 *
 * ColorCode 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 3 of the License, or
 * (at your option) any later version.
 *
 * ColorCode 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 ColorCode. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QtWidgets>

#include "background.h"
#include "pegfactory.h"

using namespace std;

BackGround::BackGround(QObject*)
{
    setCacheMode(QGraphicsItem::DeviceCoordinateCache);
    setAcceptedMouseButtons(0);

    QLinearGradient topgrad(0, 16, 0, 129);
    topgrad.setColorAt(0.0, QColor(0xf8, 0xf8, 0xf8));
    topgrad.setColorAt(0.6, QColor(0xb8, 0xb9, 0xbb));
    topgrad.setColorAt(1, QColor(0xd4, 0xd5, 0xd7));
    mTopGrad = QBrush(topgrad);

    QLinearGradient botgrad(0, 530, 0, 557);
    botgrad.setColorAt(0.0, QColor("#d4d5d7"));
    botgrad.setColorAt(0.3, QColor("#cecfd1"));
    botgrad.setColorAt(1.0, QColor("#b0b1b3"));
    mBotGrad = QBrush(botgrad);

    QLinearGradient lgrad(0, 190, 320, 370);
    lgrad.setColorAt(0.0, QColor(0xff, 0xff, 0xff, 0xa0));
    lgrad.setColorAt(0.49, QColor(0xff, 0xff, 0xff, 0xa0));
    lgrad.setColorAt(0.50, QColor(0, 0, 0, 0x80));
    lgrad.setColorAt(1.0, QColor(0, 0, 0, 0x80));
    mFramePen = QPen(QBrush(lgrad), 1);

    mPend = QColor("#646568");
    mPenl = QColor("#ecedef");
    mGrad0 = QColor("#cccdcf");
    mGrad1 = QColor("#fcfdff");

    mPend.setAlpha(0x32);
    mPenl.setAlpha(0x50);
    mGrad0.setAlpha(0x32);
    mGrad1.setAlpha(0x32);
}

BackGround::~BackGround()
{
    scene()->removeItem(this);
}

QRectF BackGround::boundingRect() const
{
    const int margin = 1;
    return outlineRect().adjusted(-margin, -margin, +margin, +margin);
}

QRectF BackGround::outlineRect() const
{
    return QRectF(0.0, 0.0, 320.0, 560.0);
}

void BackGround::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /* widget */)
{
    int i;

    painter->setPen(Qt::NoPen);

    QRectF cr = QRectF(3, 3, 314, 554);
    QPainterPath cpath;
    cpath.addRoundedRect(cr, 10.1, 10.1);
    painter->setClipPath(cpath);
    painter->setClipping(true);
    
    painter->setBrush(mTopGrad);
    painter->drawRect(QRect(4, 4, 312, 125));
    painter->setBrush(QBrush(QColor("#707173")));
    painter->drawRect(QRect(1, 129, 318, 1));

    painter->setPen(Qt::NoPen);
    for (i = 0; i < 10; ++i)
    {
        painter->setBrush(QBrush(QColor("#9e9fa0")));
        painter->drawRect(QRect(1, i * 40 + 130, 318, 1));
        QLinearGradient rowgrad(0, i * 40 + 131, 0, i * 40 + 169);
        rowgrad.setColorAt(0.0, QColor("#9a9b9d"));
        rowgrad.setColorAt(1.0, QColor("#949597"));
        painter->setBrush(QBrush(rowgrad));
        painter->drawRect(QRect(1, i * 40 + 131, 318, 38));
        painter->setBrush(QBrush(QColor("#88898b")));
        painter->drawRect(QRect(1, i * 40 + 169, 318, 1));

        painter->setBrush(QBrush(mPenl));
        painter->drawRect(QRectF(277, i * 40 + 130, 39, 1));
        painter->drawRect(QRectF(277, i * 40 + 130, 1, 39));
        painter->setBrush(QBrush(mPend));
        painter->drawRect(QRectF(277, i * 40 + 130 + 39, 40, 1));
        painter->drawRect(QRectF(277 + 39, i * 40 + 130, 1, 40));

        QRadialGradient grad(QPointF(277 + 10, i * 40 + 130 + 10), 100);
        grad.setColorAt(0, mGrad0);
        grad.setColorAt(1, mGrad1);
        painter->setBrush(QBrush(grad));
        painter->drawRect(QRectF(277 + 1, i * 40 + 131, 38.0, 38.0));

        painter->setBrush(Qt::NoBrush);
        QPointF x0 = QPointF(PegFactory::XPOS_BTNS_COL, i * 40 + 130 + 2);
        QLinearGradient lgrad(x0, QPointF(x0.x() + 36, x0.y() + 36));
        lgrad.setColorAt(0.0, QColor(0, 0, 0, 0x80));
        lgrad.setColorAt(1.0, QColor(0xff, 0xff, 0xff, 0xa0));
        painter->setPen(QPen(QBrush(lgrad), 0.5));
        painter->drawEllipse(QRectF(x0.x(), x0.y(), 36, 36));
        painter->setPen(Qt::NoPen);
    }

    painter->setBrush(mBotGrad);
    painter->drawRect(QRect(1, 531, 318, 27));
    painter->setBrush(QBrush(QColor("#eff0f2")));
    painter->drawRect(QRect(1, 530, 318, 1));

    painter->setClipping(false);

    QRectF r = QRectF(3.5, 3.5, 313, 553);
    painter->setBrush(Qt::NoBrush);
    painter->setPen(mFramePen);
    painter->drawRoundedRect(r, 9.8, 9.8);
}