KDEUI
kaboutapplicationdialog.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2007 Urs Wolfer <uwolfer at kde.org> 00003 Copyright (C) 2008 Friedrich W. H. Kossebau <kossebau@kde.org> 00004 Copyright (C) 2010 Teo Mrnjavac <teo@kde.org> 00005 00006 Parts of this class have been take from the KAboutApplication class, which was 00007 Copyright (C) 2000 Waldo Bastian (bastian@kde.org) and Espen Sand (espen@kde.org) 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Library General Public 00011 License version 2 as published by the Free Software Foundation. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Library General Public License for more details. 00017 00018 You should have received a copy of the GNU Library General Public License 00019 along with this library; see the file COPYING.LIB. If not, write to 00020 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00021 Boston, MA 02110-1301, USA. 00022 */ 00023 00024 #include "kaboutapplicationdialog.h" 00025 00026 #include "kaboutapplicationpersonmodel_p.h" 00027 #include "kaboutapplicationpersonlistview_p.h" 00028 #include "kaboutapplicationpersonlistdelegate_p.h" 00029 #include "kdeui/icons/kiconloader.h" 00030 #include "kdeui/kernel/kapplication.h" 00031 #include "kdeui/kernel/kglobalsettings.h" 00032 #include "kdeui/widgets/ktextbrowser.h" 00033 #include "kdeui/widgets/ktitlewidget.h" 00034 00035 #include <kdecore/kernel/kaboutdata.h> 00036 #include <kdecore/kernel/kglobal.h> 00037 #include <kdecore/localization/klocale.h> 00038 00039 #include <QtGui/QLabel> 00040 #include <QtGui/QLayout> 00041 #include <QtGui/QPushButton> 00042 #include <QtGui/QScrollBar> 00043 #include <QtGui/QTabWidget> 00044 00045 class KAboutApplicationDialog::Private 00046 { 00047 public: 00048 Private(KAboutApplicationDialog *parent) 00049 : q(parent), 00050 aboutData(0) 00051 {} 00052 00053 void init( const KAboutData *aboutData, Options opt ); 00054 00055 void _k_showLicense( const QString &number ); 00056 00057 KAboutApplicationDialog *q; 00058 00059 const KAboutData *aboutData; 00060 }; 00061 00062 KAboutApplicationDialog::KAboutApplicationDialog(const KAboutData *aboutData, QWidget *parent) 00063 : KDialog(parent), 00064 d(new Private(this)) 00065 { 00066 d->init( aboutData, NoOptions ); 00067 } 00068 00069 KAboutApplicationDialog::KAboutApplicationDialog(const KAboutData *aboutData, Options opt, QWidget *parent) 00070 : KDialog(parent), 00071 d(new Private(this)) 00072 { 00073 d->init( aboutData, opt ); 00074 } 00075 00076 void KAboutApplicationDialog::Private::init( const KAboutData *ad, Options opt ) 00077 { 00078 if (ad == 0) 00079 ad = KGlobal::mainComponent().aboutData(); 00080 00081 aboutData = ad; 00082 00083 if (!aboutData) { 00084 QLabel *errorLabel = new QLabel(i18n("<qt>No information available.<br />" 00085 "The supplied KAboutData object does not exist.</qt>"), q); 00086 00087 errorLabel->setTextInteractionFlags(Qt::TextBrowserInteraction); 00088 q->setMainWidget(errorLabel); 00089 return; 00090 } 00091 00092 q->setPlainCaption(i18n("About %1", aboutData->programName())); 00093 q->setButtons(KDialog::Close); 00094 q->setDefaultButton(KDialog::Close); 00095 q->setModal(false); 00096 00097 //Set up the title widget... 00098 KTitleWidget *titleWidget = new KTitleWidget(q); 00099 00100 QIcon windowIcon; 00101 if (!aboutData->programIconName().isEmpty()) { 00102 windowIcon = KIcon(aboutData->programIconName()); 00103 } else { 00104 windowIcon = qApp->windowIcon(); 00105 } 00106 titleWidget->setPixmap(windowIcon.pixmap(64, 64), KTitleWidget::ImageLeft); 00107 if (aboutData->programLogo().canConvert<QPixmap>()) 00108 titleWidget->setPixmap(aboutData->programLogo().value<QPixmap>(), KTitleWidget::ImageLeft); 00109 else if (aboutData->programLogo().canConvert<QImage>()) 00110 titleWidget->setPixmap(QPixmap::fromImage(aboutData->programLogo().value<QImage>()), KTitleWidget::ImageLeft); 00111 00112 if ( opt & HideKdeVersion ) 00113 titleWidget->setText(i18n("<html><font size=\"5\">%1</font><br /><b>Version %2</b><br /> </html>", 00114 aboutData->programName(), aboutData->version())); 00115 else 00116 titleWidget->setText(i18nc("Program name, version and KDE platform version; do not translate 'Development Platform'", 00117 "<html><font size=\"5\">%1</font><br /><b>Version %2</b><br />Using KDE Development Platform %3</html>", 00118 aboutData->programName(), aboutData->version(), QString(KDE_VERSION_STRING))); 00119 00120 //Then the tab bar... 00121 QTabWidget *tabWidget = new QTabWidget; 00122 tabWidget->setUsesScrollButtons(false); 00123 00124 //Set up the first page... 00125 QString aboutPageText = aboutData->shortDescription() + '\n'; 00126 00127 if (!aboutData->otherText().isEmpty()) 00128 aboutPageText += '\n' + aboutData->otherText() + '\n'; 00129 00130 if (!aboutData->copyrightStatement().isEmpty()) 00131 aboutPageText += '\n' + aboutData->copyrightStatement() + '\n'; 00132 00133 if (!aboutData->homepage().isEmpty()) 00134 aboutPageText += '\n' + QString("<a href=\"%1\">%1</a>").arg(aboutData->homepage()) + '\n'; 00135 aboutPageText = aboutPageText.trimmed(); 00136 00137 QLabel *aboutLabel = new QLabel; 00138 aboutLabel->setWordWrap(true); 00139 aboutLabel->setOpenExternalLinks(true); 00140 aboutLabel->setText(aboutPageText.replace('\n', "<br />")); 00141 aboutLabel->setTextInteractionFlags(Qt::TextBrowserInteraction); 00142 00143 QVBoxLayout *aboutLayout = new QVBoxLayout; 00144 aboutLayout->addStretch(); 00145 aboutLayout->addWidget(aboutLabel); 00146 00147 const int licenseCount = aboutData->licenses().count(); 00148 for (int i = 0; i < licenseCount; ++i) { 00149 const KAboutLicense &license = aboutData->licenses().at(i); 00150 00151 QLabel *showLicenseLabel = new QLabel; 00152 showLicenseLabel->setText(QString("<a href=\"%1\">%2</a>").arg(QString::number(i), 00153 i18n("License: %1", 00154 license.name(KAboutData::FullName)))); 00155 showLicenseLabel->setTextInteractionFlags(Qt::TextBrowserInteraction); 00156 connect(showLicenseLabel, SIGNAL(linkActivated(QString)), q, SLOT(_k_showLicense(QString))); 00157 00158 aboutLayout->addWidget(showLicenseLabel); 00159 } 00160 00161 aboutLayout->addStretch(); 00162 00163 QWidget *aboutWidget = new QWidget(q); 00164 aboutWidget->setLayout(aboutLayout); 00165 00166 tabWidget->addTab(aboutWidget, i18n("&About")); 00167 00168 //Palette needed at least for translators... 00169 QPalette transparentBackgroundPalette; 00170 transparentBackgroundPalette.setColor(QPalette::Base, Qt::transparent); 00171 transparentBackgroundPalette.setColor(QPalette::Text, transparentBackgroundPalette.color(QPalette::WindowText)); 00172 00173 //And here we go, authors page... 00174 const int authorCount = aboutData->authors().count(); 00175 if (authorCount) { 00176 QWidget *authorWidget = new QWidget( q ); 00177 QVBoxLayout *authorLayout = new QVBoxLayout( authorWidget ); 00178 authorLayout->setMargin( 0 ); 00179 00180 if (!aboutData->customAuthorTextEnabled() || !aboutData->customAuthorRichText().isEmpty()) { 00181 QLabel *bugsLabel = new QLabel( authorWidget ); 00182 bugsLabel->setContentsMargins( 4, 2, 0, 4 ); 00183 bugsLabel->setOpenExternalLinks( true ); 00184 if (!aboutData->customAuthorTextEnabled()) { 00185 if (aboutData->bugAddress().isEmpty() || aboutData->bugAddress() == "submit@bugs.kde.org") 00186 bugsLabel->setText( i18n("Please use <a href=\"http://bugs.kde.org\">http://bugs.kde.org</a> to report bugs.\n") ); 00187 else { 00188 if( ( aboutData->authors().count() == 1 ) && 00189 ( aboutData->authors().first().emailAddress() == aboutData->bugAddress() ) ) { 00190 bugsLabel->setText( i18n("Please report bugs to <a href=\"mailto:%1\">%2</a>.\n", 00191 aboutData->authors().first().emailAddress(), 00192 aboutData->authors().first().emailAddress() ) ); 00193 } 00194 else { 00195 bugsLabel->setText( i18n("Please report bugs to <a href=\"mailto:%1\">%2</a>.\n", 00196 aboutData->bugAddress(), aboutData->bugAddress())); 00197 } 00198 } 00199 } 00200 else 00201 bugsLabel->setText( aboutData->customAuthorRichText() ); 00202 bugsLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ); 00203 authorLayout->addWidget( bugsLabel ); 00204 } 00205 00206 KDEPrivate::KAboutApplicationPersonModel *authorModel = 00207 new KDEPrivate::KAboutApplicationPersonModel( aboutData->authors(), 00208 aboutData->ocsProviderUrl(), 00209 authorWidget ); 00210 00211 KDEPrivate::KAboutApplicationPersonListView *authorView = 00212 new KDEPrivate::KAboutApplicationPersonListView( authorWidget ); 00213 00214 KDEPrivate::KAboutApplicationPersonListDelegate *authorDelegate = 00215 new KDEPrivate::KAboutApplicationPersonListDelegate( authorView, authorView ); 00216 00217 authorView->setModel( authorModel ); 00218 authorView->setItemDelegate( authorDelegate ); 00219 authorView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); 00220 authorLayout->addWidget( authorView ); 00221 00222 QString authorPageTitle = QString( ( authorCount == 1 ) ? i18n("A&uthor") : i18n("A&uthors") ); 00223 tabWidget->addTab( authorWidget, authorPageTitle ); 00224 } 00225 00226 //And credits page... 00227 const int creditsCount = aboutData->credits().count(); 00228 if (creditsCount) { 00229 QWidget *creditWidget = new QWidget( q ); 00230 QVBoxLayout *creditLayout = new QVBoxLayout( creditWidget ); 00231 creditLayout->setMargin( 0 ); 00232 00233 KDEPrivate::KAboutApplicationPersonModel *creditModel = 00234 new KDEPrivate::KAboutApplicationPersonModel( aboutData->credits(), 00235 aboutData->ocsProviderUrl(), 00236 creditWidget ); 00237 00238 KDEPrivate::KAboutApplicationPersonListView *creditView = 00239 new KDEPrivate::KAboutApplicationPersonListView( creditWidget ); 00240 00241 KDEPrivate::KAboutApplicationPersonListDelegate *creditDelegate = 00242 new KDEPrivate::KAboutApplicationPersonListDelegate( creditView, creditView ); 00243 00244 creditView->setModel( creditModel ); 00245 creditView->setItemDelegate( creditDelegate ); 00246 creditView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); 00247 creditLayout->addWidget( creditView ); 00248 00249 tabWidget->addTab( creditWidget, i18n("&Thanks To")); 00250 } 00251 00252 //Finally, the optional translators page... 00253 if ( !( opt & HideTranslators ) ) { 00254 const int translatorsCount = aboutData->translators().count(); 00255 if( translatorsCount ) { 00256 QWidget *translatorWidget = new QWidget( q ); 00257 QVBoxLayout *translatorLayout = new QVBoxLayout( translatorWidget ); 00258 translatorLayout->setMargin( 0 ); 00259 00260 KDEPrivate::KAboutApplicationPersonModel *translatorModel = 00261 new KDEPrivate::KAboutApplicationPersonModel( aboutData->translators(), 00262 aboutData->ocsProviderUrl(), 00263 translatorWidget ); 00264 00265 KDEPrivate::KAboutApplicationPersonListView *translatorView = 00266 new KDEPrivate::KAboutApplicationPersonListView( translatorWidget ); 00267 00268 KDEPrivate::KAboutApplicationPersonListDelegate *translatorDelegate = 00269 new KDEPrivate::KAboutApplicationPersonListDelegate( translatorView, translatorView ); 00270 00271 translatorView->setModel( translatorModel ); 00272 translatorView->setItemDelegate( translatorDelegate ); 00273 translatorView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); 00274 translatorLayout->addWidget( translatorView ); 00275 00276 QString aboutTranslationTeam = KAboutData::aboutTranslationTeam(); 00277 if( !aboutTranslationTeam.isEmpty() ) { 00278 QLabel *translationTeamLabel = new QLabel( translatorWidget ); 00279 translationTeamLabel->setContentsMargins( 4, 2, 4, 4 ); 00280 translationTeamLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ); 00281 translationTeamLabel->setWordWrap( true ); 00282 translationTeamLabel->setText( aboutTranslationTeam ); 00283 translatorLayout->addWidget( translationTeamLabel ); 00284 //TODO: this could be displayed as a view item to save space 00285 } 00286 00287 tabWidget->addTab( translatorWidget, i18n("T&ranslation")); 00288 } 00289 } 00290 00291 //And we jam everything together in a layout... 00292 QVBoxLayout *mainLayout = new QVBoxLayout; 00293 mainLayout->addWidget(titleWidget); 00294 mainLayout->addWidget(tabWidget); 00295 mainLayout->setMargin(0); 00296 00297 QWidget *mainWidget = new QWidget; 00298 mainWidget->setLayout(mainLayout); 00299 00300 q->setMainWidget(mainWidget); 00301 } 00302 00303 KAboutApplicationDialog::~KAboutApplicationDialog() 00304 { 00305 delete d; 00306 } 00307 00308 void KAboutApplicationDialog::Private::_k_showLicense( const QString &number ) 00309 { 00310 KDialog *dialog = new KDialog(q); 00311 00312 dialog->setCaption(i18n("License Agreement")); 00313 dialog->setButtons(KDialog::Close); 00314 dialog->setDefaultButton(KDialog::Close); 00315 00316 const QFont font = KGlobalSettings::fixedFont(); 00317 QFontMetrics metrics(font); 00318 00319 const QString licenseText = aboutData->licenses().at(number.toInt()).text(); 00320 KTextBrowser *licenseBrowser = new KTextBrowser; 00321 licenseBrowser->setFont(font); 00322 licenseBrowser->setLineWrapMode(QTextEdit::NoWrap); 00323 licenseBrowser->setText(licenseText); 00324 00325 dialog->setMainWidget(licenseBrowser); 00326 00327 // try to set up the dialog such that the full width of the 00328 // document is visible without horizontal scroll-bars being required 00329 const qreal idealWidth = licenseBrowser->document()->idealWidth() + (2 * dialog->marginHint()) 00330 + licenseBrowser->verticalScrollBar()->width() * 2; 00331 00332 // try to allow enough height for a reasonable number of lines to be shown 00333 const int idealHeight = metrics.height() * 30; 00334 00335 dialog->setInitialSize(dialog->sizeHint().expandedTo(QSize((int)idealWidth,idealHeight))); 00336 dialog->show(); 00337 } 00338 00339 #include "kaboutapplicationdialog.moc"
KDE 4.6 API Reference