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

KDEUI

  • sources
  • kde-4.14
  • kdelibs
  • 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 
45 class KAboutApplicationDialog::Private
46 {
47 public:
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 
62 KAboutApplicationDialog::KAboutApplicationDialog(const KAboutData *aboutData, QWidget *parent)
63  : KDialog(parent),
64  d(new Private(this))
65 {
66  d->init( aboutData, NoOptions );
67 }
68 
69 KAboutApplicationDialog::KAboutApplicationDialog(const KAboutData *aboutData, Options opt, QWidget *parent)
70  : KDialog(parent),
71  d(new Private(this))
72 {
73  d->init( aboutData, opt );
74 }
75 
76 void 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 
304 KAboutApplicationDialog::~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 
312 void 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"
KAboutLicense
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
i18n
QString i18n(const char *text)
ktextbrowser.h
QWidget
ktitlewidget.h
KDialog::setInitialSize
void setInitialSize(const QSize &size)
Convenience method.
Definition: kdialog.cpp:643
kapplication.h
QPalette::setColor
void setColor(ColorGroup group, ColorRole role, const QColor &color)
kglobalsettings.h
QLabel::setOpenExternalLinks
void setOpenExternalLinks(bool open)
QFont
QPalette::color
const QColor & color(ColorGroup group, ColorRole role) const
KAboutApplicationDialog
Standard "About Application" dialog box.
Definition: kaboutapplicationdialog.h:48
QWidget::setAttribute
void setAttribute(Qt::WidgetAttribute attribute, bool on)
QPixmap::fromImage
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
kiconloader.h
KComponentData::aboutData
const KAboutData * aboutData() const
KDialog
A dialog base class with standard buttons and predefined layouts.
Definition: kdialog.h:128
QFontMetrics
klocale.h
QTabWidget
KDialog::setCaption
virtual void setCaption(const QString &caption)
Make a KDE compliant caption.
Definition: kdialog.cpp:469
i18nc
QString i18nc(const char *ctxt, const char *text)
QIcon::pixmap
QPixmap pixmap(const QSize &size, Mode mode, State state) const
KDialog::setMainWidget
void setMainWidget(QWidget *widget)
Sets the main widget of the dialog.
Definition: kdialog.cpp:338
kaboutapplicationdialog.h
QWidget::width
width
kglobal.h
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QString::number
QString number(int n, int base)
QWidget::setLayout
void setLayout(QLayout *layout)
KDialog::Close
Show Close-button. (this button closes the dialog)
Definition: kdialog.h:145
KAboutApplicationDialog::NoOptions
No options, show the standard about dialog.
Definition: kaboutapplicationdialog.h:60
QString::toInt
int toInt(bool *ok, int base) const
QString::isEmpty
bool isEmpty() const
QTextDocument::idealWidth
qreal idealWidth() const
QString::trimmed
QString trimmed() const
QTabWidget::addTab
int addTab(QWidget *page, const QString &label)
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:40
QVBoxLayout
KAboutData
QLabel::setText
void setText(const QString &)
QString
KDialog::setButtons
void setButtons(ButtonCodes buttonMask)
Creates (or recreates) the button box and all the buttons in it.
Definition: kdialog.cpp:206
QAbstractScrollArea::verticalScrollBar
QScrollBar * verticalScrollBar() const
QLayout::setMargin
void setMargin(int margin)
QWidget::setSizePolicy
void setSizePolicy(QSizePolicy)
QPixmap
QTextEdit::document
QTextDocument * document() const
KAboutLicense::name
QString name(KAboutData::NameFormat formatName) const
QSize
QWidget::setFont
void setFont(const QFont &)
KDialog::setDefaultButton
void setDefaultButton(ButtonCode id)
Sets the button that will be activated when the Enter key is pressed.
Definition: kdialog.cpp:287
KTextBrowser
Extended QTextBrowser.
Definition: ktextbrowser.h:51
QImage
QTextEdit::setLineWrapMode
void setLineWrapMode(LineWrapMode mode)
QLabel::setTextInteractionFlags
void setTextInteractionFlags(QFlags< Qt::TextInteractionFlag > flags)
QString::replace
QString & replace(int position, int n, QChar after)
KAboutApplicationDialog::~KAboutApplicationDialog
virtual ~KAboutApplicationDialog()
Definition: kaboutapplicationdialog.cpp:304
KTitleWidget::ImageLeft
Display the pixmap on the left.
Definition: ktitlewidget.h:78
QTabWidget::setUsesScrollButtons
void setUsesScrollButtons(bool useButtons)
QBoxLayout::addStretch
void addStretch(int stretch)
QSize::expandedTo
QSize expandedTo(const QSize &otherSize) const
KAboutApplicationDialog::KAboutApplicationDialog
KAboutApplicationDialog(const KAboutData *aboutData, Options opts, QWidget *parent=0)
Constructor.
Definition: kaboutapplicationdialog.cpp:69
KAboutData::aboutTranslationTeam
static QString aboutTranslationTeam()
QString::at
const QChar at(int position) const
KAboutData::FullName
KGlobal::mainComponent
const KComponentData & mainComponent()
KTitleWidget
Standard title widget with a white background and round border.
Definition: ktitlewidget.h:61
KTitleWidget::setPixmap
void setPixmap(const QPixmap &pixmap, ImageAlignment alignment=ImageRight)
Definition: ktitlewidget.cpp:231
KDialog::sizeHint
virtual QSize sizeHint() const
Reimplemented from QDialog.
Definition: kdialog.cpp:359
QWidget::show
void show()
kaboutdata.h
KTitleWidget::setText
void setText(const QString &text, Qt::Alignment alignment=Qt::AlignLeft|Qt::AlignVCenter)
Definition: ktitlewidget.cpp:201
QLabel
QObject::parent
QObject * parent() const
QTextEdit::setText
void setText(const QString &text)
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QLabel::setWordWrap
void setWordWrap(bool on)
QPalette
KGlobalSettings::fixedFont
static QFont fixedFont()
Returns the default fixed font.
Definition: kglobalsettings.cpp:450
QIcon
QWidget::setContentsMargins
void setContentsMargins(int left, int top, int right, int bottom)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:23:58 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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