File indexing completed on 2024-05-19 04:29:02

0001 /*
0002  *  SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "kis_node_view_color_scheme.h"
0008 
0009 #include <QTreeView>
0010 #include <QStyle>
0011 
0012 #include <kis_painting_tweaks.h>
0013 #include <QApplication>
0014 
0015 #include <QGlobalStatic>
0016 #include <kis_config.h>
0017 Q_GLOBAL_STATIC(KisNodeViewColorScheme, s_instance)
0018 
0019 struct KisNodeViewColorScheme::Private
0020 {
0021     Private() {
0022         if (colorLabels.isEmpty()) {
0023             colorLabels << Qt::transparent;
0024             colorLabels << QColor(91,173,220);
0025             colorLabels << QColor(151,202,63);
0026             colorLabels << QColor(247,229,61);
0027             colorLabels << QColor(255,170,63);
0028             colorLabels << QColor(177,102,63);
0029             colorLabels << QColor(238,50,51);
0030             colorLabels << QColor(191,106,209);
0031             colorLabels << QColor(118,119,114);
0032 
0033             const QColor noLabelSetColor = qApp->palette().color(QPalette::Highlight);
0034             for (auto it = colorLabels.begin(); it != colorLabels.end(); ++it) {
0035                 KisPaintingTweaks::dragColor(&(*it), noLabelSetColor, 0.35);
0036             }
0037         }
0038     }
0039 
0040     static QVector<QColor> colorLabels;
0041 };
0042 
0043 QVector<QColor> KisNodeViewColorScheme::Private::colorLabels;
0044 
0045 
0046 KisNodeViewColorScheme::KisNodeViewColorScheme()
0047     : m_d(new Private)
0048 {
0049 }
0050 
0051 KisNodeViewColorScheme::~KisNodeViewColorScheme()
0052 {
0053 }
0054 
0055 KisNodeViewColorScheme* KisNodeViewColorScheme::instance()
0056 {
0057     return s_instance;
0058 }
0059 
0060 QColor KisNodeViewColorScheme::gridColor(const QStyleOptionViewItem &option, QTreeView *view) const
0061 {
0062     const int gridHint = view->style()->styleHint(QStyle::SH_Table_GridLineColor, &option, view);
0063     const QColor gridColor = static_cast<QRgb>(gridHint);
0064     return gridColor;
0065 }
0066 
0067 int KisNodeViewColorScheme::visibilitySize() const
0068 {
0069     return 16;
0070 }
0071 
0072 int KisNodeViewColorScheme::visibilityMargin() const
0073 {
0074     return 2;
0075 }
0076 
0077 
0078 int KisNodeViewColorScheme::thumbnailSize() const
0079 {
0080     KisConfig cfg(true);
0081     return cfg.layerThumbnailSize(false);
0082 }
0083 
0084 int KisNodeViewColorScheme::thumbnailMargin() const
0085 {
0086     return 3;
0087 }
0088 
0089 int KisNodeViewColorScheme::decorationSize() const
0090 {
0091     return 12;
0092 }
0093 
0094 int KisNodeViewColorScheme::decorationMargin() const
0095 {
0096     return 1;
0097 }
0098 
0099 
0100 int KisNodeViewColorScheme::textMargin() const
0101 {
0102     return 2;
0103 }
0104 
0105 
0106 int KisNodeViewColorScheme::iconSize() const
0107 {
0108     return 16;
0109 }
0110 
0111 int KisNodeViewColorScheme::iconMargin() const
0112 {
0113     return 1;
0114 }
0115 
0116 int KisNodeViewColorScheme::border() const
0117 {
0118     return 1;
0119 }
0120 
0121 int KisNodeViewColorScheme::rowHeight() const
0122 {
0123     return border() + 2 * thumbnailMargin() + thumbnailSize();
0124 }
0125 
0126 int KisNodeViewColorScheme::visibilityColumnWidth() const
0127 {
0128     return border() +
0129         2 * visibilityMargin() + visibilitySize() +
0130         border();
0131 }
0132 
0133 int KisNodeViewColorScheme::indentation() const
0134 {
0135     KisConfig cfg(true);
0136     int percentage = cfg.layerTreeIndentation();
0137     int absoluteMax = 2 * thumbnailMargin() + thumbnailSize() + border();
0138 
0139     return qMax(8, percentage*absoluteMax/100);
0140 }
0141 
0142 int KisNodeViewColorScheme::selectedButtonColumnWidth() const
0143 {
0144     return visibilityColumnWidth();
0145 }
0146 
0147 QRect KisNodeViewColorScheme::relVisibilityRect() const
0148 {
0149     return QRect(0, 0,
0150                  visibilitySize() + 2 * visibilityMargin() + 2 * border(),
0151                  visibilitySize() + 2 * visibilityMargin() + 1 * border());
0152 }
0153 
0154 QRect KisNodeViewColorScheme::relThumbnailRect() const
0155 {
0156     return QRect(0, 0,
0157                  thumbnailSize() + 2 * thumbnailMargin() + 2 * border(),
0158                  thumbnailSize() + 2 * thumbnailMargin() + 1 * border());
0159 }
0160 
0161 QRect KisNodeViewColorScheme::relDecorationRect() const
0162 {
0163     return QRect(0, 0,
0164                  decorationSize() + 2 * decorationMargin() + 2 * border(),
0165                  decorationSize() + 2 * decorationMargin() + 1 * border());
0166 }
0167 
0168 QRect KisNodeViewColorScheme::relExpandButtonRect() const
0169 {
0170     const int newY = rowHeight() - decorationMargin() - decorationSize();
0171     QRect rc = relDecorationRect();
0172     rc.moveTop(newY);
0173     return rc;
0174 }
0175 
0176 QColor KisNodeViewColorScheme::colorFromLabelIndex(int index) const
0177 {
0178     /**
0179      * We should ensure that the index of the overflowing range
0180      * will never be zero again.
0181      */
0182     if (index >= m_d->colorLabels.size()) {
0183         index = 1 + index % (m_d->colorLabels.size() - 1);
0184     } else {
0185         index = index % m_d->colorLabels.size();
0186     }
0187 
0188     return m_d->colorLabels[index];
0189 }
0190 
0191 QVector<QColor> KisNodeViewColorScheme::allColorLabels() const
0192 {
0193     return m_d->colorLabels;
0194 }