QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskSkinHintTableEditor.cpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#include "QskSkinHintTableEditor.h"
7#include "QskSkinHintTable.h"
8
9#include "QskArcMetrics.h"
10#include "QskMargins.h"
11#include "QskBoxShapeMetrics.h"
12#include "QskBoxBorderMetrics.h"
13#include "QskBoxBorderColors.h"
14#include "QskGraduationMetrics.h"
15#include "QskShadowMetrics.h"
16#include "QskStippleMetrics.h"
17#include "QskGraphic.h"
18#include "QskFontRole.h"
19
20namespace
21{
22 inline QskAspect::State lowestState( QskAspect::States mask )
23 {
24 using StateInt = typename std::underlying_type< QskAspect::State >::type;
25
26 const auto count = qCountTrailingZeroBits( static_cast< StateInt >( mask ) );
27 return static_cast< QskAspect::State >( 1 << count );
28 }
29
30 inline void setHintStateMask(
31 QskSkinHintTable* table, QskAspect aspect, const QVariant& hint,
32 bool noState, QskAspect::States states, QskAspect::States mask )
33 {
34 if ( mask == 0 )
35 {
36 if ( noState || states != 0 )
37 table->setHint( aspect | states, hint );
38
39 return;
40 }
41
42 const auto stateLow = lowestState( mask );
43
44 mask &= ~stateLow;
45
46 setHintStateMask( table, aspect, hint, noState, states, mask );
47 setHintStateMask( table, aspect, hint, noState, states | stateLow, mask );
48 }
49
50 inline bool removeHintStateMask(
51 QskSkinHintTable* table, QskAspect aspect,
52 bool noState, QskAspect::States states, QskAspect::States mask )
53 {
54 if ( mask == 0 )
55 {
56 if ( noState || states != 0 )
57 return table->removeHint( aspect | states );
58
59 return false;
60 }
61
62 const auto stateLow = lowestState( mask );
63
64 mask &= ~stateLow;
65
66 bool ret = removeHintStateMask( table, aspect, noState, states, mask );
67 ret |= removeHintStateMask( table, aspect, noState, states | stateLow, mask );
68
69 return ret;
70 }
71
72 inline QskAspect aspectPosition( QskAspect aspect )
73 {
74 return aspect | QskAspect::Position;
75 }
76
77 inline QskAspect aspectStrutSize( QskAspect aspect )
78 {
79 return aspect | QskAspect::StrutSize;
80 }
81
82 inline QskAspect aspectMargin( QskAspect aspect )
83 {
84 return aspect | QskAspect::Margin;
85 }
86
87 inline QskAspect aspectPadding( QskAspect aspect )
88 {
89 return aspect | QskAspect::Padding;
90 }
91
92 inline QskAspect aspectSpacing( QskAspect aspect )
93 {
94 return aspect | QskAspect::Spacing;
95 }
96
97 inline QskAspect aspectAlignment( QskAspect aspect )
98 {
99 return aspect | QskAspect::Alignment;
100 }
101
102 inline QskAspect aspectFontRole( QskAspect aspect )
103 {
104 return aspect | QskAspect::FontRole;
105 }
106
107 inline QskAspect aspectGraphicRole( QskAspect aspect )
108 {
109 return aspect | QskAspect::GraphicRole;
110 }
111
112 inline QskAspect aspectShape( QskAspect aspect )
113 {
114 return aspect | QskAspect::Shape;
115 }
116
117 inline QskAspect aspectBorder( QskAspect aspect )
118 {
119 return aspect | QskAspect::Border;
120 }
121
122 inline QskAspect aspectShadow( QskAspect aspect )
123 {
124 return aspect | QskAspect::Shadow;
125 }
126
127 inline QskAspect aspectOption( QskAspect aspect )
128 {
129 return aspect | QskAspect::Option;
130 }
131
132 inline QskAspect aspectSymbol( QskAspect aspect )
133 {
134 return aspect | QskAspect::Symbol;
135 }
136
137 inline QskAspect aspectStipple( QskAspect aspect )
138 {
139 return aspect | QskAspect::Style;
140 }
141
142 inline QskAspect aspectGraduation( QskAspect aspect )
143 {
144 return aspect | QskAspect::Graduation;
145 }
146}
147
148QskSkinHintTableEditor::QskSkinHintTableEditor( QskSkinHintTable* table )
149 : m_table( table )
150{
151}
152
153void QskSkinHintTableEditor::setTable( QskSkinHintTable* table )
154{
155 m_table = table;
156}
157
158QskSkinHintTable* QskSkinHintTableEditor::table() const
159{
160 return m_table;
161}
162
163void QskSkinHintTableEditor::setHint( QskAspect aspect,
164 const QVariant& hint, QskStateCombination combination )
165{
166 if ( combination.isNull() )
167 {
168 m_table->setHint( aspect, hint );
169 }
170 else
171 {
172 const bool noState =
173 ( combination.type() == QskStateCombination::CombinationNoState );
174
175 setHintStateMask( m_table, aspect, hint,
176 noState, QskAspect::States(), combination.states() );
177 }
178}
179
180bool QskSkinHintTableEditor::removeHint(
181 QskAspect aspect, QskStateCombination combination )
182{
183 if ( combination.isNull() )
184 {
185 return m_table->removeHint( aspect );
186 }
187 else
188 {
189 const bool noState =
190 ( combination.type() == QskStateCombination::CombinationNoState );
191
192 return removeHintStateMask( m_table, aspect,
193 noState, QskAspect::States(), combination.states() );
194 }
195}
196
197void QskSkinHintTableEditor::setFlag(
198 QskAspect aspect, int flag, QskStateCombination combination )
199{
200 setHint( aspect, flag, combination );
201}
202
203int QskSkinHintTableEditor::flag( QskAspect aspect ) const
204{
205 return hint< int >( aspect );
206}
207
208void QskSkinHintTableEditor::setMetric(
209 QskAspect aspect, qreal metric, QskStateCombination combination )
210{
211 setMetricHint( aspect, metric, combination );
212}
213
214qreal QskSkinHintTableEditor::metric( QskAspect aspect ) const
215{
216 return metricHint< qreal >( aspect );
217}
218
219void QskSkinHintTableEditor::setColor(
220 QskAspect aspect, Qt::GlobalColor color, QskStateCombination combination )
221{
222 setColorHint( aspect, QColor( color ), combination );
223}
224
225void QskSkinHintTableEditor::setColor(
226 QskAspect aspect, QRgb rgb, QskStateCombination combination )
227{
228 setColorHint( aspect, QColor::fromRgba( rgb ), combination );
229}
230
231void QskSkinHintTableEditor::setColor(
232 QskAspect aspect, const QColor& color, QskStateCombination combination )
233{
234 setColorHint( aspect, color, combination );
235}
236
237QColor QskSkinHintTableEditor::color( QskAspect aspect ) const
238{
239 return colorHint< QColor >( aspect );
240}
241
242void QskSkinHintTableEditor::setHGradient(
243 QskAspect aspect, const QColor& color1, const QColor& color2,
244 QskStateCombination combination )
245{
246 QskGradient gradient( color1, color2 );
247 gradient.setLinearDirection( Qt::Horizontal );
248
249 setGradient( aspect, gradient, combination );
250}
251
252void QskSkinHintTableEditor::setVGradient(
253 QskAspect aspect, const QColor& color1, const QColor& color2,
254 QskStateCombination combination )
255{
256 QskGradient gradient( color1, color2 );
257 gradient.setLinearDirection( Qt::Vertical );
258
259 setGradient( aspect, gradient, combination );
260}
261
262void QskSkinHintTableEditor::setGradient(
263 QskAspect aspect, const QColor& color1, const QColor& color2,
264 QskStateCombination combination )
265{
266 const QskGradient gradient( color1, color2 );
267 setColorHint( aspect, gradient, combination );
268}
269
270void QskSkinHintTableEditor::setGradient(
271 QskAspect aspect, const QskGradient& gradient,
272 QskStateCombination combination )
273{
274 setColorHint( aspect, gradient, combination );
275}
276
277QskGradient QskSkinHintTableEditor::gradient( QskAspect aspect ) const
278{
279 return colorHint< QskGradient >( aspect );
280}
281
282void QskSkinHintTableEditor::setPosition(
283 QskAspect aspect, qreal position, QskStateCombination combination )
284{
285 setMetricHint( aspectPosition( aspect ), position, combination );
286}
287
288bool QskSkinHintTableEditor::removePosition(
289 QskAspect aspect, QskStateCombination combination )
290{
291 return removeMetricHint( aspectPosition( aspect ), combination );
292}
293
294qreal QskSkinHintTableEditor::position( QskAspect aspect ) const
295{
296 return metricHint< qreal >( aspectPosition( aspect ) );
297}
298
299void QskSkinHintTableEditor::setStrutSize(
300 QskAspect aspect, const QSizeF& size, QskStateCombination combination )
301{
302 setMetricHint( aspectStrutSize( aspect ), size, combination );
303}
304
305void QskSkinHintTableEditor::setStrutSize(
306 QskAspect aspect, qreal width, qreal height, QskStateCombination combination )
307{
308 setMetricHint( aspectStrutSize( aspect ),
309 QSizeF( width, height ), combination );
310}
311
312bool QskSkinHintTableEditor::removeStrutSize(
313 QskAspect aspect, QskStateCombination combination )
314{
315 return removeMetricHint( aspectStrutSize( aspect ), combination );
316}
317
318QSizeF QskSkinHintTableEditor::strutSize( QskAspect aspect ) const
319{
320 return metricHint< QSizeF >( aspectStrutSize( aspect ) );
321}
322
323void QskSkinHintTableEditor::setMargin(
324 QskAspect aspect, const QskMargins& margins, QskStateCombination combination )
325{
326 setMetricHint( aspectMargin( aspect ), margins, combination );
327}
328
329void QskSkinHintTableEditor::setMargin( QskAspect aspect,
330 qreal left, qreal top, qreal right, qreal bottom,
331 QskStateCombination combination )
332{
333 const QskMargins margins( left, top, right, bottom );
334 setMetricHint( aspectMargin( aspect ), margins, combination );
335}
336
337bool QskSkinHintTableEditor::removeMargin(
338 QskAspect aspect, QskStateCombination combination )
339{
340 return removeMetricHint( aspectMargin( aspect ), combination );
341}
342
343QskMargins QskSkinHintTableEditor::margin( QskAspect aspect ) const
344{
345 return metricHint< QskMargins >( aspectMargin( aspect ) );
346}
347
348void QskSkinHintTableEditor::setPadding(
349 QskAspect aspect, const QskMargins& padding,
350 QskStateCombination combination )
351{
352 setMetricHint( aspectPadding( aspect ), padding, combination );
353}
354
355void QskSkinHintTableEditor::setPadding( QskAspect aspect,
356 qreal left, qreal top, qreal right, qreal bottom,
357 QskStateCombination combination )
358{
359 QskMargins padding( left, top, right, bottom );
360 setMetricHint( aspectPadding( aspect ), padding, combination );
361}
362
363bool QskSkinHintTableEditor::removePadding(
364 QskAspect aspect, QskStateCombination combination )
365{
366 return removeMetricHint( aspectPadding( aspect ), combination );
367}
368
369QskMargins QskSkinHintTableEditor::padding( QskAspect aspect ) const
370{
371 return metricHint< QskMargins >( aspectPadding( aspect ) );
372}
373
374void QskSkinHintTableEditor::setSpacing(
375 QskAspect aspect, qreal spacing, QskStateCombination combination )
376{
377 setMetricHint( aspectSpacing( aspect ), spacing, combination );
378}
379
380bool QskSkinHintTableEditor::removeSpacing(
381 QskAspect aspect, QskStateCombination combination )
382{
383 return removeMetricHint( aspectSpacing( aspect ), combination );
384}
385
386qreal QskSkinHintTableEditor::spacing( QskAspect aspect ) const
387{
388 return metricHint< qreal >( aspectSpacing( aspect ) );
389}
390
391void QskSkinHintTableEditor::setAlignment(
392 QskAspect aspect, Qt::Alignment alignment, QskStateCombination combination )
393{
394 setFlag( aspectAlignment( aspect ), alignment, combination );
395}
396
397bool QskSkinHintTableEditor::removeAlignment(
398 QskAspect aspect, QskStateCombination combination )
399{
400 return removeHint( aspectAlignment( aspect ), combination );
401}
402
403Qt::Alignment QskSkinHintTableEditor::alignment( QskAspect aspect ) const
404{
405 return hint< Qt::Alignment >( aspectAlignment( aspect ) );
406}
407
408void QskSkinHintTableEditor::setFontRole(
409 QskAspect aspect, const QskFontRole& fontRole, QskStateCombination combination )
410{
411 setHint( aspectFontRole( aspect ), fontRole, combination );
412}
413
414bool QskSkinHintTableEditor::removeFontRole(
415 QskAspect aspect, QskStateCombination combination )
416{
417 return removeHint( aspectFontRole( aspect ), combination );
418}
419
420QskFontRole QskSkinHintTableEditor::fontRole( QskAspect aspect ) const
421{
422 return hint< QskFontRole >( aspectFontRole( aspect ) );
423}
424
425void QskSkinHintTableEditor::setGraphicRole(
426 QskAspect aspect, int graphicRole, QskStateCombination combination )
427{
428 setHint( aspectGraphicRole( aspect ), graphicRole, combination );
429}
430
431bool QskSkinHintTableEditor::removeGraphicRole(
432 QskAspect aspect, QskStateCombination combination )
433{
434 return removeHint( aspectGraphicRole( aspect ), combination );
435}
436
437int QskSkinHintTableEditor::graphicRole( QskAspect aspect ) const
438{
439 return hint< int >( aspectGraphicRole( aspect ) );
440}
441
442void QskSkinHintTableEditor::setBoxShape(
443 QskAspect aspect, qreal radius, Qt::SizeMode sizeMode )
444{
445 setMetricHint( aspectShape( aspect ),
446 QskBoxShapeMetrics( radius, sizeMode ) );
447}
448
449void QskSkinHintTableEditor::setBoxShape( QskAspect aspect,
450 qreal topLeft, qreal topRight, qreal bottomLeft, qreal bottomRight,
451 Qt::SizeMode sizeMode )
452{
453 setMetricHint( aspectShape( aspect ),
454 QskBoxShapeMetrics( topLeft, topRight, bottomLeft, bottomRight, sizeMode ) );
455}
456
457void QskSkinHintTableEditor::setBoxShape(
458 QskAspect aspect, const QskBoxShapeMetrics& shape,
459 QskStateCombination combination )
460{
461 setMetricHint( aspectShape( aspect ), shape, combination );
462}
463
464bool QskSkinHintTableEditor::removeBoxShape(
465 QskAspect aspect, QskStateCombination combination )
466{
467 return removeMetricHint( aspectShape( aspect ), combination );
468}
469
470QskBoxShapeMetrics QskSkinHintTableEditor::boxShape( QskAspect aspect ) const
471{
472 return metricHint< QskBoxShapeMetrics >( aspectShape( aspect ) );
473}
474
475void QskSkinHintTableEditor::setBoxBorderMetrics( QskAspect aspect,
476 qreal borderWidth, Qt::SizeMode sizeMode )
477{
478 setMetricHint( aspectBorder( aspect ),
479 QskBoxBorderMetrics( borderWidth, sizeMode ) );
480}
481
482void QskSkinHintTableEditor::setBoxBorderMetrics( QskAspect aspect,
483 qreal left, qreal top, qreal right, qreal bottom, Qt::SizeMode sizeMode )
484{
485 setMetricHint( aspectBorder( aspect ),
486 QskBoxBorderMetrics( left, top, right, bottom, sizeMode ) );
487}
488
489void QskSkinHintTableEditor::setBoxBorderMetrics(
490 QskAspect aspect, const QskBoxBorderMetrics& borderMetrics,
491 QskStateCombination combination )
492{
493 setMetricHint( aspectBorder( aspect ), borderMetrics, combination );
494}
495
496bool QskSkinHintTableEditor::removeBoxBorderMetric(
497 QskAspect aspect, QskStateCombination combination )
498{
499 return removeMetricHint( aspectBorder( aspect ), combination );
500}
501
502QskBoxBorderMetrics QskSkinHintTableEditor::boxBorderMetrics( QskAspect aspect ) const
503{
504 return metricHint< QskBoxBorderMetrics >( aspectBorder( aspect ) );
505}
506
507void QskSkinHintTableEditor::setBoxBorderColors(
508 QskAspect aspect, const QskBoxBorderColors& borderColors,
509 QskStateCombination combination )
510{
511 setColorHint( aspectBorder( aspect ), borderColors, combination );
512}
513
514void QskSkinHintTableEditor::setBoxBorderColors( QskAspect aspect,
515 const QskGradient& left, const QskGradient& top, const QskGradient& right,
516 const QskGradient& bottom, QskStateCombination combination )
517{
518 setColorHint( aspectBorder( aspect ),
519 QskBoxBorderColors( left, top, right, bottom ), combination );
520}
521
522bool QskSkinHintTableEditor::removeBoxBorderColors(
523 QskAspect aspect, QskStateCombination combination )
524{
525 return removeColorHint( aspectBorder( aspect ), combination );
526}
527
528QskBoxBorderColors QskSkinHintTableEditor::boxBorderColors( QskAspect aspect ) const
529{
530 return colorHint< QskBoxBorderColors >( aspectBorder( aspect ) );
531}
532
533void QskSkinHintTableEditor::setShadowMetrics( QskAspect aspect,
534 qreal spreadRadius, qreal blurRadius, const QPointF& offset, Qt::SizeMode sizeMode )
535{
536 setMetricHint( aspectShadow( aspect ),
537 QskShadowMetrics( spreadRadius, blurRadius, offset, sizeMode ) );
538}
539
540void QskSkinHintTableEditor::setShadowMetrics( QskAspect aspect,
541 const QskShadowMetrics& metrics, QskStateCombination combination )
542{
543 setMetricHint( aspectShadow( aspect ), metrics, combination );
544}
545
546bool QskSkinHintTableEditor::removeShadowMetric(
547 QskAspect aspect, QskStateCombination combination )
548{
549 return removeMetricHint( aspectShadow( aspect ), combination );
550}
551
552QskShadowMetrics QskSkinHintTableEditor::shadowMetrics( QskAspect aspect ) const
553{
554 return metricHint< QskShadowMetrics >( aspectShadow( aspect ) );
555}
556
557void QskSkinHintTableEditor::setShadowColor( QskAspect aspect,
558 const QColor& color, QskStateCombination combination )
559{
560 setColorHint( aspectShadow( aspect ), color, combination );
561}
562
563void QskSkinHintTableEditor::setShadowColor( QskAspect aspect,
564 Qt::GlobalColor color, QskStateCombination combination )
565{
566 setColorHint( aspectShadow( aspect ), QColor( color ), combination );
567}
568
569void QskSkinHintTableEditor::setShadowColor( QskAspect aspect,
570 QRgb rgb, QskStateCombination combination )
571{
572 setColorHint( aspectShadow( aspect ), QColor::fromRgba( rgb ), combination );
573}
574
575bool QskSkinHintTableEditor::removeShadowColor(
576 QskAspect aspect, QskStateCombination combination )
577{
578 return removeColorHint( aspectShadow( aspect ), combination );
579}
580
581QColor QskSkinHintTableEditor::shadowColor( QskAspect aspect ) const
582{
583 return colorHint< QColor >( aspectShadow( aspect ) );
584}
585
586void QskSkinHintTableEditor::setArcMetrics( QskAspect aspect,
587 qreal startAngle, qreal spanAngle, qreal thickness, Qt::SizeMode sizeMode )
588{
589 setMetricHint( aspectShape( aspect ),
590 QskArcMetrics( startAngle, spanAngle, thickness, sizeMode ) );
591}
592
593void QskSkinHintTableEditor::setArcMetrics( QskAspect aspect,
594 const QskArcMetrics& arcMetrics, QskStateCombination combination )
595{
596 setMetricHint( aspectShape( aspect ), arcMetrics, combination );
597}
598
599bool QskSkinHintTableEditor::removeArcMetrics(
600 QskAspect aspect, QskStateCombination combination )
601{
602 return removeMetricHint( aspectShape( aspect ), combination );
603}
604
605QskArcMetrics QskSkinHintTableEditor::arcMetrics( QskAspect aspect ) const
606{
607 return metricHint< QskArcMetrics >( aspectShape( aspect ) );
608}
609
610void QskSkinHintTableEditor::setStippleMetrics( QskAspect aspect,
611 Qt::PenStyle penStyle, QskStateCombination combination )
612{
613 setStippleMetrics( aspect, QskStippleMetrics( penStyle ), combination );
614}
615
616void QskSkinHintTableEditor::setStippleMetrics( QskAspect aspect,
617 const QVector< qreal >& dashPattern, QskStateCombination combination )
618{
619 setStippleMetrics( aspect, QskStippleMetrics( dashPattern ), combination );
620}
621
622void QskSkinHintTableEditor::setStippleMetrics( QskAspect aspect,
623 const QskStippleMetrics& metrics, QskStateCombination combination )
624{
625 setMetricHint( aspectStipple( aspect ), metrics, combination );
626}
627
628bool QskSkinHintTableEditor::removeStippleMetrics(
629 QskAspect aspect, QskStateCombination combination )
630{
631 return removeMetricHint( aspectStipple( aspect ), combination );
632}
633
634QskStippleMetrics QskSkinHintTableEditor::stippleMetrics( QskAspect aspect ) const
635{
636 return metricHint< QskStippleMetrics >( aspectStipple( aspect ) );
637}
638
639void QskSkinHintTableEditor::setGraduationMetrics( QskAspect aspect,
640 const QskGraduationMetrics& metrics, QskStateCombination combination )
641{
642 setMetricHint( aspectGraduation( aspect ), metrics, combination );
643}
644
645bool QskSkinHintTableEditor::removeGraduationMetrics(
646 QskAspect aspect, QskStateCombination combination )
647{
648 return removeMetricHint( aspectGraduation( aspect ), combination );
649}
650
651QskGraduationMetrics QskSkinHintTableEditor::graduationMetrics( QskAspect aspect ) const
652{
653 return metricHint< QskGraduationMetrics >( aspectGraduation( aspect ) );
654}
655
656void QskSkinHintTableEditor::setTextOptions( QskAspect aspect,
657 Qt::TextElideMode elideMode, QskTextOptions::WrapMode wrapMode,
658 QskStateCombination combination )
659{
660 QskTextOptions options;
661 options.setElideMode( elideMode );
662 options.setWrapMode( wrapMode );
663
664 setTextOptions( aspect, options, combination );
665}
666
667void QskSkinHintTableEditor::setTextOptions( QskAspect aspect,
668 const QskTextOptions& textOptions, QskStateCombination combination )
669{
670 setHint( aspectOption( aspect ), textOptions, combination );
671}
672
673bool QskSkinHintTableEditor::removeTextOptions(
674 QskAspect aspect, QskStateCombination combination )
675{
676 return removeHint( aspectOption( aspect ), combination );
677}
678
679QskTextOptions QskSkinHintTableEditor::textOptions( QskAspect aspect ) const
680{
681 return hint< QskTextOptions >( aspectOption( aspect ) );
682}
683
684void QskSkinHintTableEditor::setSymbol( QskAspect aspect,
685 const QskGraphic& symbol, QskStateCombination combination )
686{
687 setHint( aspectSymbol( aspect ), symbol, combination );
688}
689
690bool QskSkinHintTableEditor::removeSymbol(
691 QskAspect aspect, QskStateCombination combination )
692{
693 return removeHint( aspectSymbol( aspect ), combination );
694}
695
696QskGraphic QskSkinHintTableEditor::symbol( QskAspect aspect ) const
697{
698 return hint< QskGraphic >( aspectSymbol( aspect ) );
699}
Lookup key for a QskSkinHintTable.
Definition QskAspect.h:15
@ GraphicRole
Definition QskAspect.h:56
A paint device for scalable graphics.
Definition QskGraphic.h:28