Warning, file /plasma/latte-dock/app/settings/detailsdialog/schemescombobox.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2021 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "schemescombobox.h"
0007 
0008 // local
0009 #include "../generic/generictools.h"
0010 
0011 // Qt
0012 #include <QApplication>
0013 #include <QDebug>
0014 #include <QPalette>
0015 #include <QStyleOptionComboBox>
0016 #include <QStylePainter>
0017 
0018 namespace Latte {
0019 namespace Settings {
0020 
0021 const int MARGIN = 2;
0022 const int VERTMARGIN = 3;
0023 
0024 SchemesComboBox::SchemesComboBox(QWidget *parent)
0025     : QComboBox (parent)
0026 {
0027 }
0028 
0029 QColor SchemesComboBox::backgroundColor() const
0030 {
0031     return m_backgroundColor;
0032 }
0033 
0034 void SchemesComboBox::setBackgroundColor(const QColor &color)
0035 {
0036     if (m_backgroundColor == color) {
0037         return;
0038     }
0039 
0040     m_backgroundColor = color;
0041     update();
0042 }
0043 
0044 QColor SchemesComboBox::textColor() const
0045 {
0046     return m_textColor;
0047 }
0048 
0049 void SchemesComboBox::setTextColor(const QColor &color)
0050 {
0051     if (m_textColor == color) {
0052         return;
0053     }
0054 
0055     m_textColor = color;
0056     update();
0057 }
0058 
0059 
0060 void SchemesComboBox::paintEvent(QPaintEvent *event)
0061 {
0062     QStylePainter painter(this);
0063     painter.setPen(palette().color(QPalette::Text));
0064 
0065     // draw the combobox frame, focusrect and selected etc.
0066     QStyleOptionComboBox opt;
0067     initStyleOption(&opt);
0068 
0069     // background
0070     painter.drawComplexControl(QStyle::CC_ComboBox, opt);
0071 
0072     // icon
0073     QRect remained = Latte::remainedFromColorSchemeIcon(opt, Qt::AlignLeft, 3, 5);
0074     Latte::drawColorSchemeIcon(&painter, opt, m_textColor, m_backgroundColor, Qt::AlignLeft, 7, 6);
0075     opt.rect = remained;
0076 
0077     // adjust text place, move it a bit to the left
0078     QRect textRect;
0079     int textnegativepad = MARGIN + 1;
0080     if (qApp->layoutDirection() == Qt::LeftToRight) {
0081         textRect = QRect(remained.x() - textnegativepad, opt.rect.y(), remained.width() + 2*textnegativepad, opt.rect.height());
0082     } else {
0083         textRect = QRect(remained.x(), opt.rect.y(), remained.width() + 2 * textnegativepad, opt.rect.height());
0084     }
0085     opt.rect = textRect;
0086 
0087     // text
0088     painter.drawControl(QStyle::CE_ComboBoxLabel, opt);
0089 
0090 }
0091 
0092 
0093 }
0094 }