File indexing completed on 2024-04-28 17:06:20

0001 /*
0002     SPDX-FileCopyrightText: 2010 Jan Lepper <krusader@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2010-2022 Krusader Krew <https://krusader.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "krerrordisplay.h"
0009 #include <stdio.h>
0010 
0011 #include "krcolorcache.h"
0012 
0013 KrErrorDisplay::KrErrorDisplay(QWidget *parent)
0014     : QLabel(parent)
0015     , _currentDim(100)
0016 {
0017     setAutoFillBackground(true);
0018     _startColor = QColor(240, 150, 150);
0019     QPalette p(palette());
0020     _targetColor = p.color(QPalette::Window);
0021     p.setColor(QPalette::Window, _startColor);
0022     setPalette(p);
0023 
0024     _dimTimer.setSingleShot(true);
0025     connect(&_dimTimer, &QTimer::timeout, this, &KrErrorDisplay::slotTimeout);
0026 }
0027 
0028 void KrErrorDisplay::setText(const QString &text)
0029 {
0030     QLabel::setText(text);
0031     _currentDim = 100;
0032 
0033     QPalette p(palette());
0034     p.setColor(QPalette::Window, _startColor);
0035     setPalette(p);
0036 
0037     _dimTimer.start(5000);
0038 }
0039 
0040 void KrErrorDisplay::slotTimeout()
0041 {
0042     _currentDim -= 2;
0043     dim();
0044     if (_currentDim > 0)
0045         _dimTimer.start(50);
0046 }
0047 
0048 void KrErrorDisplay::dim()
0049 {
0050     QPalette p(palette());
0051     p.setColor(QPalette::Window, KrColorCache::dimColor(_startColor, _currentDim, _targetColor));
0052     setPalette(p);
0053 }