File indexing completed on 2022-11-22 14:07:13

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::showProgressMessage(const QString &message, int progress, int max)
0040 {
0041     if (max > -1) {
0042         m_pbStyle.maximum = max;
0043     }
0044     if (progress > 0) {
0045         m_progress++;
0046     }
0047     if (!message.isEmpty()) {
0048         showMessage(message, Qt::AlignRight | Qt::AlignBottom, Qt::white);
0049     }
0050     repaint();
0051 }
0052 
0053 void Splash::drawContents(QPainter *painter)
0054 {
0055     QSplashScreen::drawContents(painter);
0056 
0057     if (m_progress > 0) {
0058         // Set style for progressbar and draw it
0059         m_pbStyle.progress = m_progress;
0060         // Draw it...
0061         style()->drawControl(QStyle::CE_ProgressBar, &m_pbStyle, painter, this);
0062     }
0063 }