File indexing completed on 2024-05-05 17:19:04
0001 /*************************************************************************** 0002 * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr 0003 * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 ***************************************************************************/ 0006 /** @file 0007 * A progress bar with colors. 0008 * 0009 * @author Stephane MANKOWSKI / Guillaume DE BURE 0010 */ 0011 #include "skgprogressbar.h" 0012 0013 #include <kcolorscheme.h> 0014 #include <qstringbuilder.h> 0015 0016 SKGProgressBar::SKGProgressBar(QWidget* iParent) 0017 : QProgressBar(iParent), m_negative(-1), m_neutral(-1), m_positive(-1) 0018 { 0019 // Define color style 0020 KColorScheme scheme(QPalette::Normal); 0021 QString negative = scheme.foreground(KColorScheme::NegativeText).color().name(); 0022 QString neutral = scheme.foreground(KColorScheme::NeutralText).color().name(); 0023 QString positive = scheme.foreground(KColorScheme::PositiveText).color().name(); 0024 0025 m_negativeStyleSheet = QStringLiteral(" QProgressBar { text-align: center; padding: 0.5px;} QProgressBar::chunk {text-align: center; border-radius:4px; background-color: ") % negative % ";}" % styleSheet(); 0026 m_neutralStyleSheet = QStringLiteral(" QProgressBar { text-align: center; padding: 0.5px;} QProgressBar::chunk {text-align: center; border-radius:4px; background-color: ") % neutral % ";}" % styleSheet(); 0027 m_positiveStyleSheet = QStringLiteral(" QProgressBar { text-align: center; padding: 0.5px;} QProgressBar::chunk {text-align: center; border-radius:4px; background-color: ") % positive % ";}" % styleSheet(); 0028 } 0029 0030 SKGProgressBar::~SKGProgressBar() 0031 = default; 0032 0033 void SKGProgressBar::setLimits(int negative, int neutral, int positive) 0034 { 0035 m_negative = negative; 0036 m_neutral = neutral; 0037 m_positive = positive; 0038 0039 setValue(value()); 0040 } 0041 0042 void SKGProgressBar::setValue(int iValue) 0043 { 0044 QProgressBar::setValue(iValue); 0045 if (m_negative <= m_positive) { 0046 if (iValue <= m_negative) { 0047 setStyleSheet(m_negativeStyleSheet); 0048 } else if (iValue <= m_neutral) { 0049 setStyleSheet(m_neutralStyleSheet); 0050 } else if (iValue <= m_positive) { 0051 setStyleSheet(m_positiveStyleSheet); 0052 } 0053 } else { 0054 if (iValue <= m_positive) { 0055 setStyleSheet(m_positiveStyleSheet); 0056 } else if (iValue <= m_neutral) { 0057 setStyleSheet(m_neutralStyleSheet); 0058 } else if (iValue <= m_negative) { 0059 setStyleSheet(m_negativeStyleSheet); 0060 } 0061 } 0062 } 0063 0064