• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • kdeui
  • dialogs
kaboutapplicationdialog.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 2007 Urs Wolfer <uwolfer at kde.org>
3 Copyright (C) 2008 Friedrich W. H. Kossebau <kossebau@kde.org>
4 Copyright (C) 2010 Teo Mrnjavac <teo@kde.org>
5
6 Parts of this class have been take from the KAboutApplication class, which was
7 Copyright (C) 2000 Waldo Bastian (bastian@kde.org) and Espen Sand (espen@kde.org)
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public
11 License version 2 as published by the Free Software Foundation.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
17
18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
22*/
23
24#include "kaboutapplicationdialog.h"
25
26#include "kaboutapplicationpersonmodel_p.h"
27#include "kaboutapplicationpersonlistview_p.h"
28#include "kaboutapplicationpersonlistdelegate_p.h"
29#include "kdeui/icons/kiconloader.h"
30#include "kdeui/kernel/kapplication.h"
31#include "kdeui/kernel/kglobalsettings.h"
32#include "kdeui/widgets/ktextbrowser.h"
33#include "kdeui/widgets/ktitlewidget.h"
34
35#include <kdecore/kernel/kaboutdata.h>
36#include <kdecore/kernel/kglobal.h>
37#include <kdecore/localization/klocale.h>
38
39#include <QtGui/QLabel>
40#include <QtGui/QLayout>
41#include <QtGui/QPushButton>
42#include <QtGui/QScrollBar>
43#include <QtGui/QTabWidget>
44
45class KAboutApplicationDialog::Private
46{
47public:
48 Private(KAboutApplicationDialog *parent)
49 : q(parent),
50 aboutData(0)
51 {}
52
53 void init( const KAboutData *aboutData, Options opt );
54
55 void _k_showLicense( const QString &number );
56
57 KAboutApplicationDialog *q;
58
59 const KAboutData *aboutData;
60};
61
62KAboutApplicationDialog::KAboutApplicationDialog(const KAboutData *aboutData, QWidget *parent)
63 : KDialog(parent),
64 d(new Private(this))
65{
66 d->init( aboutData, NoOptions );
67}
68
69KAboutApplicationDialog::KAboutApplicationDialog(const KAboutData *aboutData, Options opt, QWidget *parent)
70 : KDialog(parent),
71 d(new Private(this))
72{
73 d->init( aboutData, opt );
74}
75
76void KAboutApplicationDialog::Private::init( const KAboutData *ad, Options opt )
77{
78 if (ad == 0)
79 ad = KGlobal::mainComponent().aboutData();
80
81 aboutData = ad;
82
83 if (!aboutData) {
84 QLabel *errorLabel = new QLabel(i18n("<qt>No information available.<br />"
85 "The supplied KAboutData object does not exist.</qt>"), q);
86
87 errorLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
88 q->setMainWidget(errorLabel);
89 return;
90 }
91
92 q->setPlainCaption(i18n("About %1", aboutData->programName()));
93 q->setButtons(KDialog::Close);
94 q->setDefaultButton(KDialog::Close);
95 q->setModal(false);
96
97 //Set up the title widget...
98 KTitleWidget *titleWidget = new KTitleWidget(q);
99
100 QIcon windowIcon;
101 if (!aboutData->programIconName().isEmpty()) {
102 windowIcon = KIcon(aboutData->programIconName());
103 } else {
104 windowIcon = qApp->windowIcon();
105 }
106 titleWidget->setPixmap(windowIcon.pixmap(64, 64), KTitleWidget::ImageLeft);
107 if (aboutData->programLogo().canConvert<QPixmap>())
108 titleWidget->setPixmap(aboutData->programLogo().value<QPixmap>(), KTitleWidget::ImageLeft);
109 else if (aboutData->programLogo().canConvert<QImage>())
110 titleWidget->setPixmap(QPixmap::fromImage(aboutData->programLogo().value<QImage>()), KTitleWidget::ImageLeft);
111
112 if ( opt & HideKdeVersion )
113 titleWidget->setText(i18n("<html><font size=\"5\">%1</font><br /><b>Version %2</b><br />&nbsp;</html>",
114 aboutData->programName(), aboutData->version()));
115 else
116 titleWidget->setText(i18nc("Program name, version and KDE platform version; do not translate 'Development Platform'",
117 "<html><font size=\"5\">%1</font><br /><b>Version %2</b><br />Using KDE Development Platform %3</html>",
118 aboutData->programName(), aboutData->version(), QString(KDE_VERSION_STRING)));
119
120 //Then the tab bar...
121 QTabWidget *tabWidget = new QTabWidget;
122 tabWidget->setUsesScrollButtons(false);
123
124 //Set up the first page...
125 QString aboutPageText = aboutData->shortDescription() + '\n';
126
127 if (!aboutData->otherText().isEmpty())
128 aboutPageText += '\n' + aboutData->otherText() + '\n';
129
130 if (!aboutData->copyrightStatement().isEmpty())
131 aboutPageText += '\n' + aboutData->copyrightStatement() + '\n';
132
133 if (!aboutData->homepage().isEmpty())
134 aboutPageText += '\n' + QString("<a href=\"%1\">%1</a>").arg(aboutData->homepage()) + '\n';
135 aboutPageText = aboutPageText.trimmed();
136
137 QLabel *aboutLabel = new QLabel;
138 aboutLabel->setWordWrap(true);
139 aboutLabel->setOpenExternalLinks(true);
140 aboutLabel->setText(aboutPageText.replace('\n', "<br />"));
141 aboutLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
142
143 QVBoxLayout *aboutLayout = new QVBoxLayout;
144 aboutLayout->addStretch();
145 aboutLayout->addWidget(aboutLabel);
146
147 const int licenseCount = aboutData->licenses().count();
148 for (int i = 0; i < licenseCount; ++i) {
149 const KAboutLicense &license = aboutData->licenses().at(i);
150
151 QLabel *showLicenseLabel = new QLabel;
152 showLicenseLabel->setText(QString("<a href=\"%1\">%2</a>").arg(QString::number(i),
153 i18n("License: %1",
154 license.name(KAboutData::FullName))));
155 showLicenseLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
156 connect(showLicenseLabel, SIGNAL(linkActivated(QString)), q, SLOT(_k_showLicense(QString)));
157
158 aboutLayout->addWidget(showLicenseLabel);
159 }
160
161 aboutLayout->addStretch();
162
163 QWidget *aboutWidget = new QWidget(q);
164 aboutWidget->setLayout(aboutLayout);
165
166 tabWidget->addTab(aboutWidget, i18n("&About"));
167
168 //Palette needed at least for translators...
169 QPalette transparentBackgroundPalette;
170 transparentBackgroundPalette.setColor(QPalette::Base, Qt::transparent);
171 transparentBackgroundPalette.setColor(QPalette::Text, transparentBackgroundPalette.color(QPalette::WindowText));
172
173 //And here we go, authors page...
174 const int authorCount = aboutData->authors().count();
175 if (authorCount) {
176 QWidget *authorWidget = new QWidget( q );
177 QVBoxLayout *authorLayout = new QVBoxLayout( authorWidget );
178 authorLayout->setMargin( 0 );
179
180 if (!aboutData->customAuthorTextEnabled() || !aboutData->customAuthorRichText().isEmpty()) {
181 QLabel *bugsLabel = new QLabel( authorWidget );
182 bugsLabel->setContentsMargins( 4, 2, 0, 4 );
183 bugsLabel->setOpenExternalLinks( true );
184 if (!aboutData->customAuthorTextEnabled()) {
185 if (aboutData->bugAddress().isEmpty() || aboutData->bugAddress() == "submit@bugs.kde.org")
186 bugsLabel->setText( i18n("Please use <a href=\"http://bugs.kde.org\">http://bugs.kde.org</a> to report bugs.\n") );
187 else {
188 if( ( aboutData->authors().count() == 1 ) &&
189 ( aboutData->authors().first().emailAddress() == aboutData->bugAddress() ) ) {
190 bugsLabel->setText( i18n("Please report bugs to <a href=\"mailto:%1\">%2</a>.\n",
191 aboutData->authors().first().emailAddress(),
192 aboutData->authors().first().emailAddress() ) );
193 }
194 else {
195 bugsLabel->setText( i18n("Please report bugs to <a href=\"mailto:%1\">%2</a>.\n",
196 aboutData->bugAddress(), aboutData->bugAddress()));
197 }
198 }
199 }
200 else
201 bugsLabel->setText( aboutData->customAuthorRichText() );
202 bugsLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
203 authorLayout->addWidget( bugsLabel );
204 }
205
206 KDEPrivate::KAboutApplicationPersonModel *authorModel =
207 new KDEPrivate::KAboutApplicationPersonModel( aboutData->authors(),
208 aboutData->ocsProviderUrl(),
209 authorWidget );
210
211 KDEPrivate::KAboutApplicationPersonListView *authorView =
212 new KDEPrivate::KAboutApplicationPersonListView( authorWidget );
213
214 KDEPrivate::KAboutApplicationPersonListDelegate *authorDelegate =
215 new KDEPrivate::KAboutApplicationPersonListDelegate( authorView, authorView );
216
217 authorView->setModel( authorModel );
218 authorView->setItemDelegate( authorDelegate );
219 authorView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
220 authorLayout->addWidget( authorView );
221
222 QString authorPageTitle = QString( ( authorCount == 1 ) ? i18n("A&uthor") : i18n("A&uthors") );
223 tabWidget->addTab( authorWidget, authorPageTitle );
224 }
225
226 //And credits page...
227 const int creditsCount = aboutData->credits().count();
228 if (creditsCount) {
229 QWidget *creditWidget = new QWidget( q );
230 QVBoxLayout *creditLayout = new QVBoxLayout( creditWidget );
231 creditLayout->setMargin( 0 );
232
233 KDEPrivate::KAboutApplicationPersonModel *creditModel =
234 new KDEPrivate::KAboutApplicationPersonModel( aboutData->credits(),
235 aboutData->ocsProviderUrl(),
236 creditWidget );
237
238 KDEPrivate::KAboutApplicationPersonListView *creditView =
239 new KDEPrivate::KAboutApplicationPersonListView( creditWidget );
240
241 KDEPrivate::KAboutApplicationPersonListDelegate *creditDelegate =
242 new KDEPrivate::KAboutApplicationPersonListDelegate( creditView, creditView );
243
244 creditView->setModel( creditModel );
245 creditView->setItemDelegate( creditDelegate );
246 creditView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
247 creditLayout->addWidget( creditView );
248
249 tabWidget->addTab( creditWidget, i18n("&Thanks To"));
250 }
251
252 //Finally, the optional translators page...
253 if ( !( opt & HideTranslators ) ) {
254 const int translatorsCount = aboutData->translators().count();
255 if( translatorsCount ) {
256 QWidget *translatorWidget = new QWidget( q );
257 QVBoxLayout *translatorLayout = new QVBoxLayout( translatorWidget );
258 translatorLayout->setMargin( 0 );
259
260 KDEPrivate::KAboutApplicationPersonModel *translatorModel =
261 new KDEPrivate::KAboutApplicationPersonModel( aboutData->translators(),
262 aboutData->ocsProviderUrl(),
263 translatorWidget );
264
265 KDEPrivate::KAboutApplicationPersonListView *translatorView =
266 new KDEPrivate::KAboutApplicationPersonListView( translatorWidget );
267
268 KDEPrivate::KAboutApplicationPersonListDelegate *translatorDelegate =
269 new KDEPrivate::KAboutApplicationPersonListDelegate( translatorView, translatorView );
270
271 translatorView->setModel( translatorModel );
272 translatorView->setItemDelegate( translatorDelegate );
273 translatorView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
274 translatorLayout->addWidget( translatorView );
275
276 QString aboutTranslationTeam = KAboutData::aboutTranslationTeam();
277 if( !aboutTranslationTeam.isEmpty() ) {
278 QLabel *translationTeamLabel = new QLabel( translatorWidget );
279 translationTeamLabel->setContentsMargins( 4, 2, 4, 4 );
280 translationTeamLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
281 translationTeamLabel->setWordWrap( true );
282 translationTeamLabel->setText( aboutTranslationTeam );
283 translationTeamLabel->setOpenExternalLinks( true );
284 translatorLayout->addWidget( translationTeamLabel );
285 //TODO: this could be displayed as a view item to save space
286 }
287
288 tabWidget->addTab( translatorWidget, i18n("T&ranslation"));
289 }
290 }
291
292 //And we jam everything together in a layout...
293 QVBoxLayout *mainLayout = new QVBoxLayout;
294 mainLayout->addWidget(titleWidget);
295 mainLayout->addWidget(tabWidget);
296 mainLayout->setMargin(0);
297
298 QWidget *mainWidget = new QWidget;
299 mainWidget->setLayout(mainLayout);
300
301 q->setMainWidget(mainWidget);
302}
303
304KAboutApplicationDialog::~KAboutApplicationDialog()
305{
306 delete d;
307 // The delegate wants to be deleted before the items it created, otherwise
308 // complains bitterly about it
309 qDeleteAll(findChildren<KWidgetItemDelegate*>());
310}
311
312void KAboutApplicationDialog::Private::_k_showLicense( const QString &number )
313{
314 KDialog *dialog = new KDialog(q);
315 dialog->setAttribute( Qt::WA_DeleteOnClose );
316
317 dialog->setCaption(i18n("License Agreement"));
318 dialog->setButtons(KDialog::Close);
319 dialog->setDefaultButton(KDialog::Close);
320
321 const QFont font = KGlobalSettings::fixedFont();
322 QFontMetrics metrics(font);
323
324 const QString licenseText = aboutData->licenses().at(number.toInt()).text();
325 KTextBrowser *licenseBrowser = new KTextBrowser;
326 licenseBrowser->setFont(font);
327 licenseBrowser->setLineWrapMode(QTextEdit::NoWrap);
328 licenseBrowser->setText(licenseText);
329
330 dialog->setMainWidget(licenseBrowser);
331
332 // try to set up the dialog such that the full width of the
333 // document is visible without horizontal scroll-bars being required
334 const qreal idealWidth = licenseBrowser->document()->idealWidth() + (2 * dialog->marginHint())
335 + licenseBrowser->verticalScrollBar()->width() * 2;
336
337 // try to allow enough height for a reasonable number of lines to be shown
338 const int idealHeight = metrics.height() * 30;
339
340 dialog->setInitialSize(dialog->sizeHint().expandedTo(QSize((int)idealWidth,idealHeight)));
341 dialog->show();
342}
343
344#include "kaboutapplicationdialog.moc"
KAboutApplicationDialog
Standard "About Application" dialog box.
Definition: kaboutapplicationdialog.h:49
KAboutApplicationDialog::NoOptions
@ NoOptions
No options, show the standard about dialog.
Definition: kaboutapplicationdialog.h:60
KAboutApplicationDialog::KAboutApplicationDialog
KAboutApplicationDialog(const KAboutData *aboutData, Options opts, QWidget *parent=0)
Constructor.
Definition: kaboutapplicationdialog.cpp:69
KAboutApplicationDialog::~KAboutApplicationDialog
virtual ~KAboutApplicationDialog()
Definition: kaboutapplicationdialog.cpp:304
KAboutData
KAboutData::aboutTranslationTeam
static QString aboutTranslationTeam()
KAboutData::FullName
FullName
KAboutLicense
KAboutLicense::name
QString name(KAboutData::NameFormat formatName) const
KComponentData::aboutData
const KAboutData * aboutData() const
KDialog
A dialog base class with standard buttons and predefined layouts.
Definition: kdialog.h:129
KDialog::marginHint
static int marginHint()
Returns the number of pixels that should be used between a dialog edge and the outermost widget(s) ac...
Definition: kdialog.cpp:427
KDialog::setMainWidget
void setMainWidget(QWidget *widget)
Sets the main widget of the dialog.
Definition: kdialog.cpp:338
KDialog::setInitialSize
void setInitialSize(const QSize &size)
Convenience method.
Definition: kdialog.cpp:643
KDialog::sizeHint
virtual QSize sizeHint() const
Reimplemented from QDialog.
Definition: kdialog.cpp:359
KDialog::setButtons
void setButtons(ButtonCodes buttonMask)
Creates (or recreates) the button box and all the buttons in it.
Definition: kdialog.cpp:206
KDialog::Close
@ Close
Show Close-button. (this button closes the dialog)
Definition: kdialog.h:145
KDialog::setDefaultButton
void setDefaultButton(ButtonCode id)
Sets the button that will be activated when the Enter key is pressed.
Definition: kdialog.cpp:287
KDialog::setCaption
virtual void setCaption(const QString &caption)
Make a KDE compliant caption.
Definition: kdialog.cpp:469
KGlobalSettings::fixedFont
static QFont fixedFont()
Returns the default fixed font.
Definition: kglobalsettings.cpp:450
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:41
KTextBrowser
Extended QTextBrowser.
Definition: ktextbrowser.h:52
KTitleWidget
Standard title widget with a white background and round border.
Definition: ktitlewidget.h:62
KTitleWidget::ImageLeft
@ ImageLeft
Display the pixmap on the left.
Definition: ktitlewidget.h:78
KTitleWidget::setText
void setText(const QString &text, Qt::Alignment alignment=Qt::AlignLeft|Qt::AlignVCenter)
Definition: ktitlewidget.cpp:201
KTitleWidget::setPixmap
void setPixmap(const QPixmap &pixmap, ImageAlignment alignment=ImageRight)
Definition: ktitlewidget.cpp:231
QLabel
QTabWidget
QWidget
kaboutapplicationdialog.h
kaboutdata.h
kapplication.h
kglobal.h
kglobalsettings.h
kiconloader.h
klocale.h
i18n
QString i18n(const char *text)
i18nc
QString i18nc(const char *ctxt, const char *text)
ktextbrowser.h
ktitlewidget.h
KGlobal::mainComponent
const KComponentData & mainComponent()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal