Pimcommon

whatsnewwidget.cpp
1/*
2 SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6#include "whatsnewwidget.h"
7
8#include <KLocalizedString>
9#include <QTextBrowser>
10#include <QVBoxLayout>
11
12namespace
13{
14constexpr int allVersion = -1;
15}
16using namespace PimCommon;
17WhatsNewWidget::WhatsNewWidget(const QList<PimCommon::WhatsNewInfo> &infos, QWidget *parent)
18 : QWidget{parent}
19 , mWhatsNewInfo(infos)
20 , mLabelInfo(new QTextBrowser(this))
21 , mWhatsNewComboBoxWidget(new WhatsNewComboBoxWidget(this))
22{
23 auto mainLayout = new QVBoxLayout(this);
24 mainLayout->setObjectName(QStringLiteral("mainLayout"));
25 mainLayout->setContentsMargins({});
26
27 mWhatsNewComboBoxWidget->setObjectName(QStringLiteral("mWhatsNewComboBoxWidget"));
28 mainLayout->addWidget(mWhatsNewComboBoxWidget);
29
30 mLabelInfo->setObjectName(QStringLiteral("mLabelInfo"));
31 mLabelInfo->setReadOnly(true);
32 mLabelInfo->setOpenExternalLinks(true);
33 mLabelInfo->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
34 connect(mWhatsNewComboBoxWidget, &WhatsNewComboBoxWidget::versionChanged, this, &WhatsNewWidget::slotVersionChanged);
35 mainLayout->addWidget(mLabelInfo);
36 fillComboBox();
37 mWhatsNewComboBoxWidget->initializeVersion(currentVersion());
38}
39
40WhatsNewWidget::~WhatsNewWidget() = default;
41
42void WhatsNewWidget::fillComboBox()
43{
44 mWhatsNewComboBoxWidget->addVersion(i18n("All Version"), allVersion);
45 for (int i = mWhatsNewInfo.count() - 1; i >= 0; i--) {
46 const WhatsNewInfo &info = mWhatsNewInfo.at(i);
47 mWhatsNewComboBoxWidget->addVersion(i18n("Version %1", info.version()), i);
48 }
49}
50
51int WhatsNewWidget::currentVersion() const
52{
53 return mWhatsNewInfo.count() - 1;
54}
55
56void WhatsNewWidget::updateInformations()
57{
58 slotVersionChanged(currentVersion());
59}
60
61QString WhatsNewWidget::generateStartEndHtml(const QString &str) const
62{
63 const QString message = QStringLiteral("<qt>") + str + QStringLiteral("</qt>");
64 return message;
65}
66
67void WhatsNewWidget::slotVersionChanged(int type)
68{
69 if (type == allVersion) { // All
70 QString message;
71 for (int i = mWhatsNewInfo.count() - 1; i >= 0; i--) {
72 const WhatsNewInfo &info = mWhatsNewInfo.at(i);
73 message += generateVersionHeader(i);
74 message += createVersionInformation(info);
75 }
76 mLabelInfo->setHtml(generateStartEndHtml(message));
77 } else {
78 const QString message = generateStartEndHtml(createVersionInformation(mWhatsNewInfo.at(type)));
79 mLabelInfo->setHtml(message);
80 }
81}
82
83QString WhatsNewWidget::importantChangeStr() const
84{
85 return QStringLiteral("<b>") + i18n("Important changes since last version:") + QStringLiteral("</b>");
86}
87
88QString WhatsNewWidget::featuresChangeStr() const
89{
90 return QStringLiteral("<b>") + i18n("Some of the new features in this release include:") + QStringLiteral("</b>");
91}
92
93QString WhatsNewWidget::bugFixingChangeStr() const
94{
95 return QStringLiteral("<b>") + i18n("Some bug fixing:") + QStringLiteral("</b>");
96}
97
98QString WhatsNewWidget::createVersionInformation(const WhatsNewInfo &info)
99{
100 QString message;
101 if (!info.changes().isEmpty()) {
102 message += importantChangeStr();
103 message += QStringLiteral("<ul>");
104 for (int i = 0, total = info.changes().count(); i < total; ++i) {
105 message += QStringLiteral("<li>%1</li>").arg(info.changes().at(i));
106 }
107 message += QStringLiteral("</ul>");
108 }
109
110 if (!info.newFeatures().isEmpty()) {
111 message += featuresChangeStr();
112 message += QStringLiteral("<ul>");
113 for (int i = 0, total = info.newFeatures().count(); i < total; ++i) {
114 message += QStringLiteral("<li>%1</li>").arg(info.newFeatures().at(i));
115 }
116 message += QStringLiteral("</ul>");
117 }
118
119 if (!info.bugFixings().isEmpty()) {
120 message += bugFixingChangeStr();
121 message += QStringLiteral("<ul>");
122 for (int i = 0, total = info.bugFixings().count(); i < total; ++i) {
123 message += QStringLiteral("<li>%1</li>").arg(info.bugFixings().at(i));
124 }
125 message += QStringLiteral("</ul>");
126 }
127 return message;
128}
129
130QString WhatsNewWidget::generateVersionHeader(int type) const
131{
132 if (type != allVersion) {
133 return QStringLiteral("<h1><i> Version %1 </i></h1><hr/><br>").arg(mWhatsNewInfo.at(type).version());
134 }
135 return {};
136}
137
138#include "moc_whatsnewwidget.cpp"
QString i18n(const char *text, const TYPE &arg...)
folderdialogacltab.h
const_reference at(qsizetype i) const const
qsizetype count() const const
bool isEmpty() const const
QString arg(Args &&... args) const const
TextSelectableByMouse
void setHtml(const QString &text)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.