File indexing completed on 2024-10-06 03:43:15

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2007 Urs Wolfer <uwolfer at kde.org>
0004     SPDX-FileCopyrightText: 2008 Friedrich W. H. Kossebau <kossebau@kde.org>
0005     SPDX-FileCopyrightText: 2010 Teo Mrnjavac <teo@kde.org>
0006     SPDX-FileCopyrightText: 2021 Julius Künzel <jk.kdedev@smartlab.uber.space>
0007 
0008     Parts of this class have been take from the KAboutApplication class, which was:
0009     SPDX-FileCopyrightText: 2000 Waldo Bastian <bastian@kde.org>
0010     SPDX-FileCopyrightText: 2000 Espen Sand <espen@kde.org>
0011 
0012     SPDX-License-Identifier: LGPL-2.0-only
0013 */
0014 
0015 #include "kaboutapplicationdialog.h"
0016 
0017 #include "kabstractaboutdialog_p.h"
0018 #include "klicensedialog_p.h"
0019 // KF
0020 #include <KAboutData>
0021 #include <KLocalizedString>
0022 #include <KWidgetItemDelegate>
0023 // Qt
0024 #include <QApplication>
0025 #include <QLabel>
0026 #include <QTabWidget>
0027 #include <QVBoxLayout>
0028 
0029 class KAboutApplicationDialogPrivate : public KAbstractAboutDialogPrivate
0030 {
0031 public:
0032     KAboutApplicationDialogPrivate(const KAboutData &aboutData, KAboutApplicationDialog *parent)
0033         : q(parent)
0034         , aboutData(aboutData)
0035     {
0036     }
0037 
0038     void init(KAboutApplicationDialog::Options opt);
0039 
0040 private:
0041     KAboutApplicationDialog *const q;
0042 
0043     const KAboutData aboutData;
0044 };
0045 
0046 KAboutApplicationDialog::KAboutApplicationDialog(const KAboutData &aboutData, QWidget *parent)
0047     : KAboutApplicationDialog(aboutData, NoOptions, parent)
0048 {
0049 }
0050 
0051 KAboutApplicationDialog::KAboutApplicationDialog(const KAboutData &aboutData, Options opt, QWidget *parent)
0052     : QDialog(parent)
0053     , d(new KAboutApplicationDialogPrivate(aboutData, this))
0054 {
0055     d->init(opt);
0056 }
0057 
0058 void KAboutApplicationDialogPrivate::init(KAboutApplicationDialog::Options opt)
0059 {
0060     q->setWindowTitle(i18nc("@title:window", "About %1", aboutData.displayName()));
0061 
0062     // Set up the title widget...
0063     QIcon titleIcon;
0064     if (aboutData.programLogo().canConvert<QPixmap>()) {
0065         titleIcon = QIcon(aboutData.programLogo().value<QPixmap>());
0066     } else if (aboutData.programLogo().canConvert<QImage>()) {
0067         titleIcon = QIcon(QPixmap::fromImage(aboutData.programLogo().value<QImage>()));
0068     } else if (aboutData.programLogo().canConvert<QIcon>()) {
0069         titleIcon = aboutData.programLogo().value<QIcon>();
0070     } else {
0071         titleIcon = qApp->windowIcon();
0072     }
0073 
0074     QWidget *titleWidget = createTitleWidget(titleIcon, aboutData.displayName(), aboutData.version(), q);
0075 
0076     // Then the tab bar...
0077     QTabWidget *tabWidget = new QTabWidget;
0078     tabWidget->setUsesScrollButtons(false);
0079 
0080     // Set up the first page...
0081     QWidget *aboutWidget = createAboutWidget(aboutData.shortDescription(), //
0082                                              aboutData.otherText(),
0083                                              aboutData.copyrightStatement(),
0084                                              aboutData.homepage(),
0085                                              aboutData.licenses(),
0086                                              q);
0087 
0088     tabWidget->addTab(aboutWidget, i18nc("@title:tab", "About"));
0089 
0090     // Components page
0091     if (!(opt & KAboutApplicationDialog::HideLibraries)) {
0092         QWidget *componentWidget = createComponentWidget(aboutData.components(), q);
0093 
0094         const QString componentPageTitle = i18nc("@title:tab", "Components");
0095         tabWidget->addTab(componentWidget, componentPageTitle);
0096     }
0097 
0098     // And here we go, authors page...
0099     const int authorCount = aboutData.authors().count();
0100     if (authorCount) {
0101         QWidget *authorWidget =
0102             createAuthorsWidget(aboutData.authors(), aboutData.customAuthorTextEnabled(), aboutData.customAuthorRichText(), aboutData.bugAddress(), q);
0103 
0104         const QString authorPageTitle = i18ncp("@title:tab", "Author", "Authors", authorCount);
0105         tabWidget->addTab(authorWidget, authorPageTitle);
0106     }
0107 
0108     // And credits page...
0109     if (!aboutData.credits().isEmpty()) {
0110         QWidget *creditWidget = createCreditWidget(aboutData.credits(), q);
0111         tabWidget->addTab(creditWidget, i18nc("@title:tab", "Thanks To"));
0112     }
0113 
0114     // Finally, the optional translators page...
0115     if (!(opt & KAboutApplicationDialog::HideTranslators) && !aboutData.translators().isEmpty()) {
0116         QWidget *translatorWidget = createTranslatorsWidget(aboutData.translators(), q);
0117 
0118         tabWidget->addTab(translatorWidget, i18nc("@title:tab", "Translation"));
0119     }
0120 
0121     createForm(titleWidget, tabWidget, q);
0122 }
0123 
0124 KAboutApplicationDialog::~KAboutApplicationDialog()
0125 {
0126     // The delegate wants to be deleted before the items it created, otherwise
0127     // complains bitterly about it
0128     qDeleteAll(findChildren<KWidgetItemDelegate *>());
0129 }
0130 
0131 #include "moc_kaboutapplicationdialog.cpp"