QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskStandardSymbol.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskStandardSymbol.h"
7#include "QskGraphic.h"
8
9#include <qpainter.h>
10#include <qpainterpath.h>
11
12static void qskOkGraphic( QPainter* painter )
13{
14 QPainterPath path;
15
16 path.moveTo( 14, 43 );
17 path.cubicTo( 13.5, 43, 12.25, 42.5, 11.75, 41.5 );
18
19 path.lineTo( 0, 20.5 );
20
21 path.cubicTo( 0, 19, 0, 17.25, 1.5, 16.5 );
22 path.cubicTo( 3, 15.75, 4.75, 16.25, 5.5, 17.75 );
23
24 path.lineTo( 14.75, 34 );
25
26 path.cubicTo( 17.25, 28.25, 20, 23.25, 22.75, 18.5 );
27 path.cubicTo( 26.75, 12.25, 31.25, 6.5, 38.25, 0.75 );
28
29 path.cubicTo( 39.5, 0, 41.25, 0, 42.25, 1 );
30 path.cubicTo( 43.25, 2.25, 43.25, 4, 42, 5.25 );
31 path.cubicTo( 35.50, 10.75, 31.5, 15.75, 27.75, 21.5 );
32 path.cubicTo( 24.25, 27.25, 21.25, 33.75, 16.75, 41.5 );
33 path.cubicTo( 16.25, 42.5, 15.25, 43, 14.25, 43 );
34
35 painter->setPen( Qt::NoPen );
36
37 painter->setBrush( QColor( 76, 175, 80 ) );
38 painter->drawPath( path );
39}
40
41static void qskCancelGraphic( QPainter* painter )
42{
43 QPainterPath path;
44
45 path.moveTo( 5, 0 );
46 path.lineTo( 20, 15 );
47 path.lineTo( 35, 0 );
48 path.lineTo( 40, 5 );
49 path.lineTo( 25, 20 );
50 path.lineTo( 40, 35 );
51 path.lineTo( 35, 40 );
52 path.lineTo( 20, 25 );
53 path.lineTo( 5, 40 );
54 path.lineTo( 0, 35 );
55 path.lineTo( 15, 20 );
56 path.lineTo( 0, 5 );
57
58 painter->setPen( Qt::NoPen );
59
60 painter->setBrush( QColor( Qt::red ) );
61 painter->drawPath( path );
62}
63
64static void qskCheckMarkGraphic( QPainter* painter )
65{
66 QPainterPath path;
67
68 path.moveTo( 0.0, 0.5 );
69 path.lineTo( 0.33, 1.0 );
70 path.lineTo( 1.0, 0.0 );
71
72 painter->setPen( QPen( Qt::black, 0.2 ) );
73 painter->drawPath( path );
74}
75
76static void qskCrossMarkGraphic( QPainter* painter )
77{
78 painter->setPen( QPen( Qt::black, 0.2 ) );
79 painter->drawLine( 0.0, 0.0, 1.0, 1.0 );
80 painter->drawLine( 0.0, 1.0, 1.0, 0.0 );
81}
82
83static void qskBulletGraphic( QPainter* painter )
84{
85 painter->setPen( QPen( Qt::black, 1.0 ) );
86 painter->drawEllipse( QRectF( 0.0, 0.0, 1.0, 1.0 ) );
87}
88
89static void qskTriangleGraphic( QPainter* painter,
90 qreal width, qreal height, int type )
91{
92 const QRectF rect( 0.0, 0.0, width, height );
93
94 QPainterPath path;
95
96 QPolygonF triangle;
97
98 switch( type )
99 {
100 case QskStandardSymbol::TriangleUp:
101 {
102 triangle += rect.bottomLeft();
103 triangle += QPointF( rect.center().x(), rect.top() );
104 triangle += rect.bottomRight();
105
106 break;
107 }
108 case QskStandardSymbol::TriangleDown:
109 {
110 triangle += rect.topLeft();
111 triangle += QPointF( rect.center().x(), rect.bottom() );
112 triangle += rect.topRight();
113
114 break;
115 }
116 case QskStandardSymbol::TriangleRight:
117 {
118 triangle += rect.bottomLeft();
119 triangle += QPointF( rect.right(), rect.center().y() );
120 triangle += rect.topLeft();
121
122 break;
123 }
124 case QskStandardSymbol::TriangleLeft:
125 {
126 triangle += rect.bottomRight();
127 triangle += QPointF( rect.left(), rect.center().y() );
128 triangle += rect.topRight();
129
130 break;
131 }
132 }
133
134 path.addPolygon( triangle );
135
136 painter->setPen( Qt::NoPen );
137 painter->setBrush( QColor( Qt::black ) );
138 painter->drawPath( path );
139}
140
141QskGraphic QskStandardSymbol::graphic( Type symbolType )
142{
143 static QskGraphic graphics[ SymbolTypeCount ];
144
145 if ( symbolType < 0 || symbolType >= SymbolTypeCount )
146 return QskGraphic();
147
148 if ( graphics[ symbolType ].isNull() )
149 {
150 QPainter painter( &graphics[ symbolType ] );
151 painter.setRenderHint( QPainter::Antialiasing, true );
152
153 switch ( symbolType )
154 {
155 case QskStandardSymbol::Ok:
156 {
157 qskOkGraphic( &painter );
158 break;
159 }
160 case QskStandardSymbol::Cancel:
161 {
162 qskCancelGraphic( &painter );
163 break;
164 }
165 case QskStandardSymbol::CheckMark:
166 {
167 qskCheckMarkGraphic( &painter );
168 break;
169 }
170 case QskStandardSymbol::CrossMark:
171 {
172 qskCrossMarkGraphic( &painter );
173 break;
174 }
175 case QskStandardSymbol::SegmentedBarCheckMark:
176 {
177 qskCheckMarkGraphic( &painter );
178 break;
179 }
180 case QskStandardSymbol::TriangleUp:
181 case QskStandardSymbol::TriangleDown:
182 {
183 qskTriangleGraphic( &painter, 2.0, 1.0, symbolType );
184 break;
185 }
186 case QskStandardSymbol::TriangleLeft:
187 case QskStandardSymbol::TriangleRight:
188 {
189 qskTriangleGraphic( &painter, 1.0, 2.0, symbolType );
190 break;
191 }
192 case QskStandardSymbol::Bullet:
193 {
194 qskBulletGraphic( &painter );
195 break;
196 }
197 case QskStandardSymbol::NoSymbol:
198 case QskStandardSymbol::SymbolTypeCount:
199 {
200 break;
201 }
202 }
203 }
204
205 return graphics[ symbolType ];
206}
207
208#include "moc_QskStandardSymbol.cpp"
A paint device for scalable graphics.
Definition QskGraphic.h:28