aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/modelinglib/qmt/style/defaultstyleengine.cpp
blob: f2da9a9292c01906548fe253d8873695fb7c2a00 (plain)
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
/****************************************************************************
**
** Copyright (C) 2016 Jochen Becher
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/

#include "defaultstyleengine.h"

#include "defaultstyle.h"
#include "objectvisuals.h"
#include "styledobject.h"
#include "styledrelation.h"

#include "qmt/diagram/dclass.h"
#include "qmt/diagram/dpackage.h"
#include "qmt/diagram/dcomponent.h"
#include "qmt/diagram/ditem.h"
#include "qmt/diagram/dannotation.h"
#include "qmt/infrastructure/qmtassert.h"

#include <utils/algorithm.h>

#include <QSet>

namespace {

class DepthProperties
{
public:
    DepthProperties() = default;
    DepthProperties(qmt::DefaultStyleEngine::ElementType elementType,
                    qmt::DObject::VisualPrimaryRole visualPrimaryRole,
                    qmt::DObject::VisualSecondaryRole visualSecondaryRole)
        : m_elementType(elementType),
          m_visualPrimaryRole(visualPrimaryRole),
          m_visualSecondaryRole(visualSecondaryRole)
    {
    }

    qmt::DefaultStyleEngine::ElementType m_elementType = qmt::DefaultStyleEngine::TypeOther;
    qmt::DObject::VisualPrimaryRole m_visualPrimaryRole = qmt::DObject::PrimaryRoleNormal;
    qmt::DObject::VisualSecondaryRole m_visualSecondaryRole = qmt::DObject::SecondaryRoleNone;
};

} // namespace

namespace qmt {

// TODO use tuple instead of these 4 explicit key classes

class ObjectStyleKey
{
public:
    ObjectStyleKey() = default;

    ObjectStyleKey(StyleEngine::ElementType elementType, const ObjectVisuals &objectVisuals)
        : m_elementType(elementType),
          m_objectVisuals(objectVisuals)
    {
    }

    StyleEngine::ElementType m_elementType = StyleEngine::TypeOther;
    ObjectVisuals m_objectVisuals;
};

uint qHash(const ObjectStyleKey &styleKey)
{
    return ::qHash(styleKey.m_elementType) ^ qHash(styleKey.m_objectVisuals);
}

bool operator==(const ObjectStyleKey &lhs, const ObjectStyleKey &rhs)
{
    return lhs.m_elementType == rhs.m_elementType && lhs.m_objectVisuals == rhs.m_objectVisuals;
}

class RelationStyleKey
{
public:
    RelationStyleKey(StyleEngine::ElementType elementType = StyleEngine::TypeOther,
                     DObject::VisualPrimaryRole visualPrimaryRole = DObject::PrimaryRoleNormal)
        : m_elementType(elementType),
          m_visualPrimaryRole(visualPrimaryRole)
    {
    }

    StyleEngine::ElementType m_elementType = StyleEngine::TypeOther;
    DObject::VisualPrimaryRole m_visualPrimaryRole = DObject::PrimaryRoleNormal;
};

uint qHash(const RelationStyleKey &styleKey)
{
    return ::qHash(styleKey.m_elementType) ^ ::qHash(styleKey.m_visualPrimaryRole);
}

bool operator==(const RelationStyleKey &lhs, const RelationStyleKey &rhs)
{
    return lhs.m_elementType == rhs.m_elementType && lhs.m_visualPrimaryRole == rhs.m_visualPrimaryRole;
}

class AnnotationStyleKey
{
public:
    AnnotationStyleKey(DAnnotation::VisualRole visualRole = DAnnotation::RoleNormal)
        : m_visualRole(visualRole)
    {
    }

    DAnnotation::VisualRole m_visualRole = DAnnotation::RoleNormal;
};

uint qHash(const AnnotationStyleKey &styleKey)
{
    return ::qHash(styleKey.m_visualRole);
}

bool operator==(const AnnotationStyleKey &lhs, const AnnotationStyleKey &rhs)
{
    return lhs.m_visualRole == rhs.m_visualRole;
}

// TODO remove class if no attributes needed even with future extensions
class BoundaryStyleKey
{
};

uint qHash(const BoundaryStyleKey &styleKey)
{
    Q_UNUSED(styleKey)

    return 1;
}

bool operator==(const BoundaryStyleKey &lhs, const BoundaryStyleKey &rhs)
{
    Q_UNUSED(lhs)
    Q_UNUSED(rhs)

    return true;
}

// TODO remove class if no attributes needed even with future extensions
class SwimlaneStyleKey
{
};

uint qHash(const SwimlaneStyleKey &styleKey)
{
    Q_UNUSED(styleKey)

    return 1;
}

bool operator==(const SwimlaneStyleKey &lhs, const SwimlaneStyleKey &rhs)
{
    Q_UNUSED(lhs)
    Q_UNUSED(rhs)

    return true;
}

DefaultStyleEngine::DefaultStyleEngine()
{
}

DefaultStyleEngine::~DefaultStyleEngine()
{
    qDeleteAll(m_objectStyleMap);
    qDeleteAll(m_relationStyleMap);
    qDeleteAll(m_annotationStyleMap);
    qDeleteAll(m_boundaryStyleMap);
}

const Style *DefaultStyleEngine::applyStyle(const Style *baseStyle, StyleEngine::ElementType elementType,
                                            const StyleEngine::Parameters *parameters)
{
    switch (elementType) {
    case TypeAnnotation:
        return applyAnnotationStyle(baseStyle, DAnnotation::RoleNormal, parameters);
    case TypeBoundary:
        return applyBoundaryStyle(baseStyle, parameters);
    case TypeRelation:
        break;
    case TypeClass:
    case TypeComponent:
    case TypeItem:
    case TypePackage:
        return applyObjectStyle(
                    baseStyle, elementType,
                    ObjectVisuals(DObject::PrimaryRoleNormal, DObject::SecondaryRoleNone, false, QColor(), 0),
                    parameters);
    case TypeOther:
        break;
    case TypeSwimlane:
        return applySwimlaneStyle(baseStyle, parameters);
    }
    return baseStyle;
}

const Style *DefaultStyleEngine::applyObjectStyle(const Style *baseStyle, StyleEngine::ElementType elementType,
                                                  const ObjectVisuals &objectVisuals,
                                                  const StyleEngine::Parameters *parameters)
{
    ObjectStyleKey key(elementType, objectVisuals);
    const Style *derivedStyle = m_objectStyleMap.value(key);
    if (!derivedStyle) {
        int lineWidth = 1;

        QColor fillColor = DefaultStyleEngine::fillColor(elementType, objectVisuals);
        QColor lineColor = DefaultStyleEngine::lineColor(elementType, objectVisuals);
        QColor textColor = DefaultStyleEngine::textColor(elementType, objectVisuals);

        QFont normalFont = baseStyle->normalFont();
        QFont headerFont = baseStyle->normalFont();
        if (objectVisuals.isEmphasized()) {
            lineWidth = 2;
            headerFont.setBold(true);
        }

        auto style = new Style(baseStyle->type());
        QPen linePen = baseStyle->linePen();
        linePen.setColor(lineColor);
        linePen.setWidth(lineWidth);
        style->setLinePen(linePen);
        style->setInnerLinePen(linePen);
        style->setOuterLinePen(linePen);
        style->setExtraLinePen(linePen);
        style->setTextBrush(QBrush(textColor));
        if (objectVisuals.visualSecondaryRole() == DObject::SecondaryRoleOutline) {
            style->setFillBrush(QBrush(Qt::white));
        } else if (objectVisuals.visualSecondaryRole() == DObject::SecondaryRoleFlat) {
            style->setFillBrush(QBrush(fillColor));
        } else {
            if (!parameters->suppressGradients()) {
                QLinearGradient fillGradient(0.0, 0.0, 0.0, 1.0);
                fillGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
                fillGradient.setColorAt(0.0, fillColor.lighter(110));
                fillGradient.setColorAt(1.0, fillColor.darker(110));
                style->setFillBrush(QBrush(fillGradient));
            } else {
                style->setFillBrush(QBrush(fillColor));
            }
        }
        if (objectVisuals.visualSecondaryRole() == DObject::SecondaryRoleOutline)
            style->setExtraFillBrush(QBrush(Qt::white));
        else if (objectVisuals.visualSecondaryRole() == DObject::SecondaryRoleFlat)
            style->setExtraFillBrush(QBrush(fillColor));
        else
            style->setExtraFillBrush(QBrush(fillColor.darker(120)));
        style->setNormalFont(normalFont);
        style->setSmallFont(baseStyle->smallFont());
        style->setHeaderFont(headerFont);
        m_objectStyleMap.insert(key, style);
        derivedStyle = style;
    }

    return derivedStyle;
}

const Style *DefaultStyleEngine::applyObjectStyle(const Style *baseStyle, const StyledObject &styledObject,
                                                  const Parameters *parameters)
{
    ElementType elementType = objectType(styledObject.object());

    // find colliding elements which best match visual appearance of styled object
    DObject::VisualPrimaryRole styledVisualPrimaryRole = styledObject.objectVisuals().visualPrimaryRole();
    DObject::VisualSecondaryRole styledVisualSecondaryRole = styledObject.objectVisuals().visualSecondaryRole();
    QHash<int, DepthProperties> depths;
    foreach (const DObject *collidingObject, styledObject.collidingObjects()) {
        int collidingDepth = collidingObject->depth();
        if (collidingDepth < styledObject.object()->depth()) {
            ElementType collidingElementType = objectType(collidingObject);
            DObject::VisualPrimaryRole collidingVisualPrimaryRole = collidingObject->visualPrimaryRole();
            DObject::VisualSecondaryRole collidingVisualSecondaryRole = collidingObject->visualSecondaryRole();
            if (!depths.contains(collidingDepth)) {
                depths.insert(collidingDepth, DepthProperties(collidingElementType, collidingVisualPrimaryRole,
                                                              collidingVisualSecondaryRole));
            } else {
                bool updateProperties = false;
                DepthProperties properties = depths.value(collidingDepth);
                if (properties.m_elementType != elementType && collidingElementType == elementType) {
                    properties.m_elementType = collidingElementType;
                    properties.m_visualPrimaryRole = collidingVisualPrimaryRole;
                    properties.m_visualSecondaryRole = collidingVisualSecondaryRole;
                    updateProperties = true;
                } else if (properties.m_elementType == elementType && collidingElementType == elementType) {
                    if ((properties.m_visualPrimaryRole != styledVisualPrimaryRole
                         || properties.m_visualSecondaryRole != styledVisualSecondaryRole)
                            && collidingVisualPrimaryRole == styledVisualPrimaryRole
                            && collidingVisualSecondaryRole == styledVisualSecondaryRole) {
                        properties.m_visualPrimaryRole = collidingVisualPrimaryRole;
                        properties.m_visualSecondaryRole = collidingVisualSecondaryRole;
                        updateProperties = true;
                    }
                }
                if (updateProperties)
                    depths.insert(collidingDepth, properties);
            }
        }
    }
    int depth = 0;
    if (!depths.isEmpty()) {
        QList<int> keys = depths.keys();
        Utils::sort(keys);
        foreach (int d, keys) {
            DepthProperties properties = depths.value(d);
            if (properties.m_elementType == elementType
                    && areStackingRoles(properties.m_visualPrimaryRole, properties.m_visualSecondaryRole,
                                        styledVisualPrimaryRole, styledVisualSecondaryRole)) {
                ++depth;
            } else {
                depth = 0;
            }
        }
    }

    return applyObjectStyle(baseStyle, elementType,
                            ObjectVisuals(styledVisualPrimaryRole,
                                          styledVisualSecondaryRole,
                                          styledObject.objectVisuals().isEmphasized(),
                                          styledObject.objectVisuals().baseColor(),
                                          depth),
                            parameters);
}

const Style *DefaultStyleEngine::applyRelationStyle(const Style *baseStyle, const StyledRelation &styledRelation,
                                                    const Parameters *parameters)
{
    Q_UNUSED(parameters)

    ElementType elementType = objectType(styledRelation.endA());
    RelationStyleKey key(elementType, styledRelation.endA() ? styledRelation.endA()->visualPrimaryRole() : DObject::PrimaryRoleNormal);
    const Style *derivedStyle = m_relationStyleMap.value(key);
    if (!derivedStyle) {
        auto style = new Style(baseStyle->type());

        const DObject *object = styledRelation.endA();
        ObjectVisuals objectVisuals(object ? object->visualPrimaryRole() : DObject::PrimaryRoleNormal,
                                     object ? object->visualSecondaryRole() : DObject::SecondaryRoleNone,
                                     object ? object->isVisualEmphasized() : false,
                                     Qt::black, // TODO STyledRelation should get an EndAObjectVisuals
                                     object ? object->depth() : 0);
        QColor lineColor = DefaultStyleEngine::lineColor(objectType(object), objectVisuals);
        QColor fillColor = lineColor;

        QPen linePen = baseStyle->linePen();
        linePen.setWidth(1);
        linePen.setColor(lineColor);
        style->setLinePen(linePen);
        QBrush textBrush = baseStyle->textBrush();
        textBrush.setColor(QColor("black"));
        style->setTextBrush(textBrush);
        QBrush brush = baseStyle->fillBrush();
        brush.setColor(fillColor);
        brush.setStyle(Qt::SolidPattern);
        style->setFillBrush(brush);
        style->setNormalFont(baseStyle->normalFont());
        style->setSmallFont(baseStyle->smallFont());
        style->setHeaderFont(baseStyle->headerFont());
        m_relationStyleMap.insert(key, style);
        derivedStyle = style;
    }
    return derivedStyle;
}

const Style *DefaultStyleEngine::applyAnnotationStyle(const Style *baseStyle, const DAnnotation *annotation,
                                                      const Parameters *parameters)
{
    DAnnotation::VisualRole visualRole = annotation ? annotation->visualRole() : DAnnotation::RoleNormal;
    return applyAnnotationStyle(baseStyle, visualRole, parameters);
}

const Style *DefaultStyleEngine::applyBoundaryStyle(const Style *baseStyle, const DBoundary *boundary,
                                                    const Parameters *parameters)
{
    Q_UNUSED(boundary)

    return applyBoundaryStyle(baseStyle, parameters);
}

const Style *DefaultStyleEngine::applySwimlaneStyle(const Style *baseStyle, const DSwimlane *swimlane, const StyleEngine::Parameters *parameters)
{
    Q_UNUSED(swimlane)

    return applySwimlaneStyle(baseStyle, parameters);
}

const Style *DefaultStyleEngine::applyAnnotationStyle(const Style *baseStyle, DAnnotation::VisualRole visualRole,
                                                      const StyleEngine::Parameters *parameters)
{
    Q_UNUSED(parameters)

    AnnotationStyleKey key(visualRole);
    const Style *derivedStyle = m_annotationStyleMap.value(key);
    if (!derivedStyle) {
        auto style = new Style(baseStyle->type());
        QFont normalFont;
        QBrush textBrush = baseStyle->textBrush();
        switch (visualRole) {
        case DAnnotation::RoleNormal:
            normalFont = baseStyle->normalFont();
            break;
        case DAnnotation::RoleTitle:
            normalFont = baseStyle->headerFont();
            break;
        case DAnnotation::RoleSubtitle:
            normalFont = baseStyle->normalFont();
            normalFont.setItalic(true);
            break;
        case DAnnotation::RoleEmphasized:
            normalFont = baseStyle->normalFont();
            normalFont.setBold(true);
            break;
        case DAnnotation::RoleSoften:
            normalFont = baseStyle->normalFont();
            textBrush.setColor(Qt::gray);
            break;
        case DAnnotation::RoleFootnote:
            normalFont = baseStyle->smallFont();
            break;
        }
        style->setNormalFont(normalFont);
        style->setTextBrush(textBrush);
        m_annotationStyleMap.insert(key, style);
        derivedStyle = style;
    }
    return derivedStyle;
}

const Style *DefaultStyleEngine::applyBoundaryStyle(const Style *baseStyle, const StyleEngine::Parameters *parameters)
{
    Q_UNUSED(parameters)

    BoundaryStyleKey key;
    const Style *derivedStyle = m_boundaryStyleMap.value(key);
    if (!derivedStyle) {
        auto style = new Style(baseStyle->type());
        style->setNormalFont(baseStyle->normalFont());
        style->setTextBrush(baseStyle->textBrush());
        m_boundaryStyleMap.insert(key, style);
        derivedStyle = style;
    }
    return derivedStyle;
}

const Style *DefaultStyleEngine::applySwimlaneStyle(const Style *baseStyle, const StyleEngine::Parameters *parameters)
{
    Q_UNUSED(parameters)

    SwimlaneStyleKey key;
    const Style *derivedStyle = m_swimlaneStyleMap.value(key);
    if (!derivedStyle) {
        auto style = new Style(baseStyle->type());
        style->setNormalFont(baseStyle->normalFont());
        style->setTextBrush(baseStyle->textBrush());
        m_swimlaneStyleMap.insert(key, style);
        derivedStyle = style;
    }
    return derivedStyle;
}

DefaultStyleEngine::ElementType DefaultStyleEngine::objectType(const DObject *object)
{
    ElementType elementType;
    if (dynamic_cast<const DPackage *>(object))
        elementType = TypePackage;
    else if (dynamic_cast<const DComponent *>(object))
        elementType = TypeComponent;
    else if (dynamic_cast<const DClass *>(object))
        elementType = TypeClass;
    else if (dynamic_cast<const DItem *>(object))
        elementType = TypeItem;
    else
        elementType = TypeOther;
    return elementType;
}

bool DefaultStyleEngine::areStackingRoles(DObject::VisualPrimaryRole rhsPrimaryRole,
                                          DObject::VisualSecondaryRole rhsSecondaryRole,
                                          DObject::VisualPrimaryRole lhsPrimaryRole,
                                          DObject::VisualSecondaryRole lhsSecondaryRols)
{
    switch (rhsSecondaryRole) {
    case DObject::SecondaryRoleNone:
    case DObject::SecondaryRoleLighter:
    case DObject::SecondaryRoleDarker:
    case DObject::SecondaryRoleFlat:
        switch (lhsSecondaryRols) {
        case DObject::SecondaryRoleNone:
        case DObject::SecondaryRoleLighter:
        case DObject::SecondaryRoleDarker:
        case DObject::SecondaryRoleFlat:
            return lhsPrimaryRole == rhsPrimaryRole;
        case DObject::SecondaryRoleSoften:
        case DObject::SecondaryRoleOutline:
            return false;
        }
        break;
    case DObject::SecondaryRoleSoften:
    case DObject::SecondaryRoleOutline:
        return false;
    }
    return true;
}

QColor DefaultStyleEngine::baseColor(ElementType elementType, ObjectVisuals objectVisuals)
{
    if (objectVisuals.visualSecondaryRole() == DObject::SecondaryRoleOutline)
        return QColor(0xFF, 0xFF, 0xFF);

    QColor baseColor;

    if (objectVisuals.visualPrimaryRole() == DObject::PrimaryRoleNormal) {
        if (objectVisuals.baseColor().isValid()) {
            baseColor = objectVisuals.baseColor();
        } else {
            switch (elementType) {
            case TypePackage:
                baseColor = QColor(0x7C, 0x98, 0xAD);
                break;
            case TypeComponent:
                baseColor = QColor(0xA0, 0xA8, 0x91);
                break;
            case TypeClass:
                baseColor = QColor(0xE5, 0xA8, 0x58);
                break;
            case TypeItem:
                baseColor = QColor(0xB9, 0x95, 0xC6);
                break;
            case TypeRelation:
            case TypeAnnotation:
            case TypeBoundary:
            case TypeSwimlane:
            case TypeOther:
                baseColor = QColor(0xBF, 0x7D, 0x65);
                break;
            }
        }
    } else {
        static QColor customColors[] = {
            QColor(0xEE, 0x8E, 0x99).darker(110),  // ROLE_CUSTOM1,
            QColor(0x80, 0xAF, 0x47).lighter(130), // ROLE_CUSTOM2,
            QColor(0xFF, 0xA1, 0x5B).lighter(100), // ROLE_CUSTOM3,
            QColor(0x55, 0xC4, 0xCF).lighter(120), // ROLE_CUSTOM4,
            QColor(0xFF, 0xE1, 0x4B)               // ROLE_CUSTOM5,
        };

        int index = static_cast<int>(objectVisuals.visualPrimaryRole()) - static_cast<int>(DObject::PrimaryRoleCustom1);
        QMT_ASSERT(index >= 0 && index <= 4, return baseColor);
        baseColor = customColors[index];
    }

    switch (objectVisuals.visualSecondaryRole()) {
    case DObject::SecondaryRoleNone:
        break;
    case DObject::SecondaryRoleLighter:
        baseColor = baseColor.lighter(110);
        break;
    case DObject::SecondaryRoleDarker:
        baseColor = baseColor.darker(120);
        break;
    case DObject::SecondaryRoleSoften:
        baseColor = baseColor.lighter(300);
        break;
    case DObject::SecondaryRoleOutline:
        QMT_CHECK(false);
        break;
    case DObject::SecondaryRoleFlat:
        break;
    }

    return baseColor;
}

QColor DefaultStyleEngine::lineColor(ElementType elementType, const ObjectVisuals &objectVisuals)
{
    QColor lineColor;
    if (objectVisuals.visualSecondaryRole() == DObject::SecondaryRoleOutline)
        lineColor = Qt::black;
    else if (objectVisuals.visualSecondaryRole() == DObject::SecondaryRoleSoften)
        lineColor = Qt::gray;
    else
        lineColor = baseColor(elementType, objectVisuals).darker(200).lighter(150).darker(100 + objectVisuals.depth() * 10);
    return lineColor;
}

QColor DefaultStyleEngine::fillColor(ElementType elementType, const ObjectVisuals &objectVisuals)
{
    QColor fillColor;
    if (objectVisuals.visualSecondaryRole() == DObject::SecondaryRoleOutline)
        fillColor = Qt::white;
    else
        fillColor = baseColor(elementType, objectVisuals).lighter(150).darker(100 + objectVisuals.depth() * 10);
    return fillColor;
}

QColor DefaultStyleEngine::textColor(const DObject *object, int depth)
{
    Q_UNUSED(depth)

    QColor textColor;
    DObject::VisualPrimaryRole visualRole = object ? object->visualPrimaryRole() : DObject::PrimaryRoleNormal;
    if (visualRole == DObject::DeprecatedPrimaryRoleSoften)
        textColor = Qt::gray;
    else
        textColor = Qt::black;
    return textColor;
}

QColor DefaultStyleEngine::textColor(ElementType elementType, const ObjectVisuals &objectVisuals)
{
    Q_UNUSED(elementType)

    QColor textColor;
    if (objectVisuals.visualSecondaryRole() == DObject::SecondaryRoleSoften)
        textColor = Qt::gray;
    else
        textColor = Qt::black;
    return textColor;
}

} // namespace qmt