| 1 | /* |
| 2 | This file is part of the KDE libraries |
| 3 | SPDX-FileCopyrightText: 2007 Urs Wolfer <uwolfer at kde.org> |
| 4 | SPDX-FileCopyrightText: 2008 Friedrich W. H. Kossebau <kossebau@kde.org> |
| 5 | SPDX-FileCopyrightText: 2010 Teo Mrnjavac <teo@kde.org> |
| 6 | SPDX-FileCopyrightText: 2021 Julius Künzel <jk.kdedev@smartlab.uber.space> |
| 7 | |
| 8 | Parts of this class have been take from the KAboutApplication class, which was: |
| 9 | SPDX-FileCopyrightText: 2000 Waldo Bastian <bastian@kde.org> |
| 10 | SPDX-FileCopyrightText: 2000 Espen Sand <espen@kde.org> |
| 11 | |
| 12 | SPDX-License-Identifier: LGPL-2.0-only |
| 13 | */ |
| 14 | |
| 15 | #include "kaboutapplicationdialog.h" |
| 16 | |
| 17 | #include "kabstractaboutdialog_p.h" |
| 18 | #include "klicensedialog_p.h" |
| 19 | // KF |
| 20 | #include <KAboutData> |
| 21 | #include <KLocalizedString> |
| 22 | #include <KWidgetItemDelegate> |
| 23 | // Qt |
| 24 | #include <QApplication> |
| 25 | #include <QLabel> |
| 26 | #include <QTabWidget> |
| 27 | #include <QVBoxLayout> |
| 28 | |
| 29 | class KAboutApplicationDialogPrivate : public KAbstractAboutDialogPrivate |
| 30 | { |
| 31 | public: |
| 32 | KAboutApplicationDialogPrivate(const KAboutData &aboutData, KAboutApplicationDialog *parent) |
| 33 | : q(parent) |
| 34 | , aboutData(aboutData) |
| 35 | { |
| 36 | } |
| 37 | |
| 38 | void init(KAboutApplicationDialog::Options opt); |
| 39 | |
| 40 | private: |
| 41 | KAboutApplicationDialog *const q; |
| 42 | |
| 43 | const KAboutData aboutData; |
| 44 | }; |
| 45 | |
| 46 | KAboutApplicationDialog::KAboutApplicationDialog(const KAboutData &aboutData, QWidget *parent) |
| 47 | : KAboutApplicationDialog(aboutData, NoOptions, parent) |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | KAboutApplicationDialog::KAboutApplicationDialog(const KAboutData &aboutData, Options opt, QWidget *parent) |
| 52 | : QDialog(parent) |
| 53 | , d(new KAboutApplicationDialogPrivate(aboutData, this)) |
| 54 | { |
| 55 | d->init(opt); |
| 56 | } |
| 57 | |
| 58 | void KAboutApplicationDialogPrivate::init(KAboutApplicationDialog::Options opt) |
| 59 | { |
| 60 | q->setWindowTitle(i18nc("@title:window" , "About %1" , aboutData.displayName())); |
| 61 | |
| 62 | // Set up the title widget... |
| 63 | QIcon titleIcon; |
| 64 | if (aboutData.programLogo().canConvert<QPixmap>()) { |
| 65 | titleIcon = QIcon(aboutData.programLogo().value<QPixmap>()); |
| 66 | } else if (aboutData.programLogo().canConvert<QImage>()) { |
| 67 | titleIcon = QIcon(QPixmap::fromImage(image: aboutData.programLogo().value<QImage>())); |
| 68 | } else if (aboutData.programLogo().canConvert<QIcon>()) { |
| 69 | titleIcon = aboutData.programLogo().value<QIcon>(); |
| 70 | } else { |
| 71 | titleIcon = qApp->windowIcon(); |
| 72 | } |
| 73 | |
| 74 | QWidget *titleWidget = createTitleWidget(icon: titleIcon, displayName: aboutData.displayName(), version: aboutData.version(), parent: q); |
| 75 | |
| 76 | // Then the tab bar... |
| 77 | QTabWidget *tabWidget = new QTabWidget; |
| 78 | tabWidget->setUsesScrollButtons(false); |
| 79 | |
| 80 | // Set up the first page... |
| 81 | QWidget *aboutWidget = createAboutWidget(shortDescription: aboutData.shortDescription(), // |
| 82 | otherText: aboutData.otherText(), |
| 83 | copyrightStatement: aboutData.copyrightStatement(), |
| 84 | homepage: aboutData.homepage(), |
| 85 | licenses: aboutData.licenses(), |
| 86 | parent: q); |
| 87 | |
| 88 | tabWidget->addTab(widget: aboutWidget, i18nc("@title:tab" , "About" )); |
| 89 | |
| 90 | // Components page |
| 91 | if (!(opt & KAboutApplicationDialog::HideLibraries)) { |
| 92 | QWidget *componentWidget = createComponentWidget(components: aboutData.components(), parent: q); |
| 93 | |
| 94 | const QString componentPageTitle = i18nc("@title:tab" , "Components" ); |
| 95 | tabWidget->addTab(widget: componentWidget, componentPageTitle); |
| 96 | } |
| 97 | |
| 98 | // And here we go, authors page... |
| 99 | const int authorCount = aboutData.authors().count(); |
| 100 | if (authorCount) { |
| 101 | QWidget *authorWidget = |
| 102 | createAuthorsWidget(authors: aboutData.authors(), customAuthorTextEnabled: aboutData.customAuthorTextEnabled(), customAuthorRichText: aboutData.customAuthorRichText(), bugAddress: aboutData.bugAddress(), parent: q); |
| 103 | |
| 104 | const QString authorPageTitle = i18ncp("@title:tab" , "Author" , "Authors" , authorCount); |
| 105 | tabWidget->addTab(widget: authorWidget, authorPageTitle); |
| 106 | } |
| 107 | |
| 108 | // And credits page... |
| 109 | if (!aboutData.credits().isEmpty()) { |
| 110 | QWidget *creditWidget = createCreditWidget(credits: aboutData.credits(), parent: q); |
| 111 | tabWidget->addTab(widget: creditWidget, i18nc("@title:tab" , "Thanks To" )); |
| 112 | } |
| 113 | |
| 114 | // Finally, the optional translators page... |
| 115 | if (!(opt & KAboutApplicationDialog::HideTranslators) && !aboutData.translators().isEmpty()) { |
| 116 | QWidget *translatorWidget = createTranslatorsWidget(translators: aboutData.translators(), parent: q); |
| 117 | |
| 118 | tabWidget->addTab(widget: translatorWidget, i18nc("@title:tab" , "Translation" )); |
| 119 | } |
| 120 | |
| 121 | createForm(titleWidget, tabWidget, dialog: q); |
| 122 | } |
| 123 | |
| 124 | KAboutApplicationDialog::~KAboutApplicationDialog() |
| 125 | { |
| 126 | // The delegate wants to be deleted before the items it created, otherwise |
| 127 | // complains bitterly about it |
| 128 | qDeleteAll(c: findChildren<KWidgetItemDelegate *>()); |
| 129 | } |
| 130 | |
| 131 | #include "moc_kaboutapplicationdialog.cpp" |
| 132 | |