Changeset View
Changeset View
Standalone View
Standalone View
src/kmessagewidget.cpp
| Show All 13 Lines | |||||
| 14 | * Lesser General Public License for more details. | 14 | * Lesser General Public License for more details. | ||
| 15 | * | 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with this library; if not, write to the Free Software | 17 | * License along with this library; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
| 19 | * 02110-1301 USA | 19 | * 02110-1301 USA | ||
| 20 | */ | 20 | */ | ||
| 21 | #include "kmessagewidget.h" | 21 | #include "kmessagewidget.h" | ||
| 22 | #include "kthemesettings_p.h" | ||||
| 22 | 23 | | |||
| 23 | #include <QAction> | 24 | #include <QAction> | ||
| 24 | #include <QApplication> | 25 | #include <QApplication> | ||
| 25 | #include <QEvent> | 26 | #include <QEvent> | ||
| 26 | #include <QGridLayout> | 27 | #include <QGridLayout> | ||
| 27 | #include <QHBoxLayout> | 28 | #include <QHBoxLayout> | ||
| 28 | #include <QLabel> | 29 | #include <QLabel> | ||
| 29 | #include <QPainter> | 30 | #include <QPainter> | ||
| ▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Line(s) | 163 | if (q->isVisible()) { | |||
| 163 | q->setFixedHeight(content->sizeHint().height()); | 164 | q->setFixedHeight(content->sizeHint().height()); | ||
| 164 | } | 165 | } | ||
| 165 | q->updateGeometry(); | 166 | q->updateGeometry(); | ||
| 166 | } | 167 | } | ||
| 167 | 168 | | |||
| 168 | void KMessageWidgetPrivate::applyStyleSheet() | 169 | void KMessageWidgetPrivate::applyStyleSheet() | ||
| 169 | { | 170 | { | ||
| 170 | QColor bgBaseColor; | 171 | QColor bgBaseColor; | ||
| 172 | const QPalette palette = QGuiApplication::palette(); | ||||
broulik: Not using the widget's palette was intentional for Konsole or something I recall? | |||||
| 171 | 173 | | |||
| 172 | // We have to hardcode colors here because KWidgetsAddons is a tier 1 framework | 174 | // We cannot use KColorScheme here because KWidgetsAddons is a tier 1 framework | ||
| 173 | // and therefore can't depend on any other KDE Frameworks | 175 | // and therefore can't depend on any other KDE Frameworks. We thus try to get | ||
| 174 | // The following RGB color values come from the "default" scheme in kcolorscheme.cpp | 176 | // the RGB values that interest us directly from the theme definition for or from the | ||
broulik: *colors | |||||
| 177 | // global settings store, using KThemeSettings. | ||||
| 178 | // If that fails we use hardcoded values (from kcolorscheme.cpp), or palette.highlight | ||||
broulik: *If
*colors | |||||
| 179 | // (for Information). | ||||
| 180 | KThemeSettings settings(QStringLiteral("Colors:Window")); | ||||
| 175 | switch (messageType) { | 181 | switch (messageType) { | ||
| 176 | case KMessageWidget::Positive: | 182 | case KMessageWidget::Positive: | ||
| 177 | bgBaseColor.setRgb(39, 174, 96); // Window: ForegroundPositive | 183 | bgBaseColor = settings.readRgb(QStringLiteral("ForegroundPositive"), QColor(39, 174, 96)); | ||
| 178 | break; | 184 | break; | ||
| 179 | case KMessageWidget::Information: | 185 | case KMessageWidget::Information: | ||
| 180 | bgBaseColor.setRgb(61, 174, 233); // Window: ForegroundActive | 186 | bgBaseColor = settings.readRgb(QStringLiteral("ForegroundActive"), palette.highlight().color()); | ||
| 181 | break; | 187 | break; | ||
| 182 | case KMessageWidget::Warning: | 188 | case KMessageWidget::Warning: | ||
| 183 | bgBaseColor.setRgb(246, 116, 0); // Window: ForegroundNeutral | 189 | bgBaseColor = settings.readRgb(QStringLiteral("ForegroundNeutral"), QColor(246, 116, 0)); | ||
| 184 | break; | 190 | break; | ||
| 185 | case KMessageWidget::Error: | 191 | case KMessageWidget::Error: | ||
| 186 | bgBaseColor.setRgb(218, 68, 83); // Window: ForegroundNegative | 192 | bgBaseColor = settings.readRgb(QStringLiteral("ForegroundNegative"), QColor(218, 68, 83)); | ||
| 187 | break; | 193 | break; | ||
| 188 | } | 194 | } | ||
| 189 | const qreal bgBaseColorAlpha = 0.2; | 195 | const qreal bgBaseColorAlpha = 0.2; | ||
| 190 | bgBaseColor.setAlphaF(bgBaseColorAlpha); | | |||
| 191 | 196 | | |||
| 192 | const QPalette palette = QGuiApplication::palette(); | 197 | // also get the other values from the theme first for consistency (and to avoid possible artefacts | ||
| 193 | const QColor windowColor = palette.window().color(); | 198 | // just after a runtime theme change with KMessageWidget instances visible). | ||
| 194 | const QColor textColor = palette.text().color(); | 199 | const QColor windowColor = settings.readRgb(QStringLiteral("BackgroundNormal"), palette.window().color()); | ||
| 200 | QColor textColor = settings.readRgb(QStringLiteral("ForegroundNormal"), palette.text().color()); | ||||
broulik: Stray semi-colon | |||||
| 195 | const QColor border = bgBaseColor; | 201 | const QColor border = bgBaseColor; | ||
| 196 | 202 | | |||
| 197 | // Generate a final background color from overlaying bgBaseColor over windowColor | 203 | // Generate a final background color from overlaying bgBaseColor over windowColor | ||
| 198 | const int newRed = (bgBaseColor.red() * bgBaseColorAlpha) + (windowColor.red() * (1 - bgBaseColorAlpha)); | 204 | const int newRed = (bgBaseColor.red() * bgBaseColorAlpha) + (windowColor.red() * (1 - bgBaseColorAlpha)); | ||
| 199 | const int newGreen = (bgBaseColor.green() * bgBaseColorAlpha) + (windowColor.green() * (1 - bgBaseColorAlpha)); | 205 | const int newGreen = (bgBaseColor.green() * bgBaseColorAlpha) + (windowColor.green() * (1 - bgBaseColorAlpha)); | ||
| 200 | const int newBlue = (bgBaseColor.blue() * bgBaseColorAlpha) + (windowColor.blue() * (1 - bgBaseColorAlpha)); | 206 | const int newBlue = (bgBaseColor.blue() * bgBaseColorAlpha) + (windowColor.blue() * (1 - bgBaseColorAlpha)); | ||
| 201 | 207 | | |||
| 202 | const QColor bgFinalColor = QColor(newRed, newGreen, newBlue); | 208 | const QColor bgFinalColor = QColor(newRed, newGreen, newBlue); | ||
| ▲ Show 20 Lines • Show All 301 Lines • Show Last 20 Lines | |||||
Not using the widget's palette was intentional for Konsole or something I recall?