File indexing completed on 2025-07-06 04:27:02

0001 /*
0002     SPDX-FileCopyrightText: 2017 Nicolas Carion
0003     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005 
0006 #include "splash.hpp"
0007 #include <KLocalizedString>
0008 #include <QDebug>
0009 #include <QPainter>
0010 #include <QStyle>
0011 
0012 Splash::Splash()
0013     : QSplashScreen()
0014     , m_progress(0)
0015 {
0016     m_pixmap = QPixmap(":/pics/splash-background.png");
0017 
0018     // Set style for progressbar...
0019     m_pbStyle.initFrom(this);
0020     m_pbStyle.state = QStyle::State_Enabled;
0021     m_pbStyle.textVisible = false;
0022     m_pbStyle.minimum = 0;
0023     m_pbStyle.maximum = 100;
0024     m_pbStyle.progress = 0;
0025     m_pbStyle.invertedAppearance = false;
0026     m_pbStyle.rect = QRect(4, m_pixmap.height() - 24, m_pixmap.width() / 2, 20); // Where is it.
0027 
0028     // Add KDE branding to pixmap
0029     QPainter *paint = new QPainter(&m_pixmap);
0030     paint->setPen(Qt::white);
0031     QPixmap kde(":/pics/kde-logo.png");
0032     const int logoSize = 32;
0033     QPoint pos(12, 12);
0034     paint->drawPixmap(pos.x(), pos.y(), logoSize, logoSize, kde);
0035     paint->drawText(pos.x() + logoSize, pos.y() + (logoSize / 2) + paint->fontMetrics().strikeOutPos(), i18n("Made by KDE"));
0036     setPixmap(m_pixmap);
0037 }
0038 
0039 void Splash::increaseProgressMessage()
0040 {
0041     m_progress++;
0042     repaint();
0043 }
0044 
0045 void Splash::showProgressMessage(const QString &message, int max)
0046 {
0047     if (max > -1) {
0048         m_pbStyle.maximum = max;
0049         m_progress = 0;
0050     }
0051     if (!message.isEmpty()) {
0052         showMessage(message, Qt::AlignRight | Qt::AlignBottom, Qt::white);
0053     }
0054     repaint();
0055 }
0056 
0057 void Splash::drawContents(QPainter *painter)
0058 {
0059     QSplashScreen::drawContents(painter);
0060 
0061     if (m_progress > 0) {
0062         // Set style for progressbar and draw it
0063         m_pbStyle.progress = m_progress;
0064         // Draw it...
0065         style()->drawControl(QStyle::CE_ProgressBar, &m_pbStyle, painter, this);
0066     }
0067 }