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

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 
00005    Parts of this class have been take from the KAboutApplication class, which was
00006    Copyright (C) 2000 Waldo Bastian (bastian@kde.org) and Espen Sand (espen@kde.org)
00007 
00008    This library is free software; you can redistribute it and/or
00009    modify it under the terms of the GNU Library General Public
00010    License version 2 as published by the Free Software Foundation.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include "kaboutapplicationdialog.h"
00024 
00025 #include <QLabel>
00026 #include <QLayout>
00027 #include <QPushButton>
00028 #include <QScrollBar>
00029 #include <QTabWidget>
00030 
00031 #include <kaboutdata.h>
00032 #include <kapplication.h>
00033 #include <kglobal.h>
00034 #include <kglobalsettings.h>
00035 #include <kiconloader.h>
00036 #include <klocale.h>
00037 #include <ktextbrowser.h>
00038 #include <ktitlewidget.h>
00039 
00040 class KAboutApplicationDialog::Private
00041 {
00042 public:
00043     Private(KAboutApplicationDialog *parent)
00044         : q(parent),
00045           aboutData(0)
00046     {}
00047 
00048     void init( const KAboutData *aboutData, Options opt );
00049 
00050     void _k_showLicense( const QString &number );
00051 
00052     KAboutApplicationDialog *q;
00053 
00054     const KAboutData *aboutData;
00055 };
00056 
00057 KAboutApplicationDialog::KAboutApplicationDialog(const KAboutData *aboutData, QWidget *parent)
00058   : KDialog(parent),
00059     d(new Private(this))
00060 {
00061     d->init( aboutData, NoOptions );
00062 }
00063 
00064 KAboutApplicationDialog::KAboutApplicationDialog(const KAboutData *aboutData, Options opt, QWidget *parent)
00065   : KDialog(parent),
00066     d(new Private(this))
00067 {
00068     d->init( aboutData, opt );
00069 }
00070 
00071 void KAboutApplicationDialog::Private::init( const KAboutData *ad, Options opt )
00072 {
00073     if (ad == 0)
00074         ad = KGlobal::mainComponent().aboutData();
00075 
00076     aboutData = ad;
00077 
00078     if (!aboutData) {
00079         QLabel *errorLabel = new QLabel(i18n("<qt>No information available.<br />"
00080                                              "The supplied KAboutData object does not exist.</qt>"), q);
00081 
00082         errorLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
00083         q->setMainWidget(errorLabel);
00084         return;
00085     }
00086 
00087     q->setPlainCaption(i18n("About %1", aboutData->programName()));
00088     q->setButtons(KDialog::Close);
00089     q->setDefaultButton(KDialog::Close);
00090     q->setModal(false);
00091 
00092     KTitleWidget *titleWidget = new KTitleWidget(q);
00093 
00094     QIcon windowIcon;
00095     if (!aboutData->programIconName().isEmpty()) {
00096         windowIcon = KIcon(aboutData->programIconName());
00097     } else {
00098         windowIcon = qApp->windowIcon();
00099     }
00100     titleWidget->setPixmap(windowIcon.pixmap(64, 64), KTitleWidget::ImageLeft);
00101     if (aboutData->programLogo().canConvert<QPixmap>())
00102         titleWidget->setPixmap(aboutData->programLogo().value<QPixmap>(), KTitleWidget::ImageLeft);
00103     else if (aboutData->programLogo().canConvert<QImage>())
00104         titleWidget->setPixmap(QPixmap::fromImage(aboutData->programLogo().value<QImage>()), KTitleWidget::ImageLeft);
00105 
00106     if ( opt & HideKdeVersion )
00107         titleWidget->setText(i18n("<html><font size=\"5\">%1</font><br /><b>Version %2</b><br />&nbsp;</html>",
00108                                   aboutData->programName(), aboutData->version()));
00109     else
00110         titleWidget->setText(i18n("<html><font size=\"5\">%1</font><br /><b>Version %2</b><br />Using KDE %3</html>",
00111                                   aboutData->programName(), aboutData->version(), QString(KDE_VERSION_STRING)));
00112 
00113     QTabWidget *tabWidget = new QTabWidget;
00114     tabWidget->setUsesScrollButtons(false);
00115 
00116     QString aboutPageText = aboutData->shortDescription() + '\n';
00117 
00118     if (!aboutData->otherText().isEmpty())
00119         aboutPageText += '\n' + aboutData->otherText() + '\n';
00120 
00121     if (!aboutData->copyrightStatement().isEmpty())
00122         aboutPageText += '\n' + aboutData->copyrightStatement() + '\n';
00123 
00124     if (!aboutData->homepage().isEmpty())
00125         aboutPageText += '\n' + QString("<a href=\"%1\">%1</a>").arg(aboutData->homepage()) + '\n';
00126     aboutPageText = aboutPageText.trimmed();
00127 
00128     QLabel *aboutLabel = new QLabel;
00129     aboutLabel->setWordWrap(true);
00130     aboutLabel->setOpenExternalLinks(true);
00131     aboutLabel->setText(aboutPageText.replace('\n', "<br />"));
00132     aboutLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
00133 
00134     QVBoxLayout *aboutLayout = new QVBoxLayout;
00135     aboutLayout->addStretch();
00136     aboutLayout->addWidget(aboutLabel);
00137 
00138     const int licenseCount = aboutData->licenses().count();
00139     for (int i = 0; i < licenseCount; ++i) {
00140         const KAboutLicense &license = aboutData->licenses().at(i);
00141 
00142         QLabel *showLicenseLabel = new QLabel;
00143         showLicenseLabel->setText(QString("<a href=\"%1\">%2</a>").arg(QString::number(i),
00144                                                                        i18n("License: %1",
00145                                                                             license.name(KAboutData::FullName))));
00146         showLicenseLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
00147         connect(showLicenseLabel, SIGNAL(linkActivated(QString)), q, SLOT(_k_showLicense(QString)));
00148 
00149         aboutLayout->addWidget(showLicenseLabel);
00150     }
00151 
00152     aboutLayout->addStretch();
00153 
00154     QWidget *aboutWidget = new QWidget(q);
00155     aboutWidget->setLayout(aboutLayout);
00156 
00157     tabWidget->addTab(aboutWidget, i18n("&About"));
00158 
00159     QPalette transparentBackgroundPalette;
00160     transparentBackgroundPalette.setColor(QPalette::Base, Qt::transparent);
00161     transparentBackgroundPalette.setColor(QPalette::Text, transparentBackgroundPalette.color(QPalette::WindowText));
00162 
00163     const int authorCount = aboutData->authors().count();
00164     if (authorCount) {
00165         QString authorPageText;
00166 
00167         QString authorPageTitle = authorCount == 1 ? i18n("A&uthor") : i18n("A&uthors");
00168 
00169         if (!aboutData->customAuthorTextEnabled() || !aboutData->customAuthorRichText().isEmpty()) {
00170             if (!aboutData->customAuthorTextEnabled()) {
00171                 if (aboutData->bugAddress().isEmpty() || aboutData->bugAddress() == "submit@bugs.kde.org")
00172                     authorPageText = i18n("Please use <a href=\"http://bugs.kde.org\">http://bugs.kde.org</a> to report bugs.\n");
00173                 else {
00174                     if(aboutData->authors().count() == 1 && (aboutData->authors().first().emailAddress() == aboutData->bugAddress())) {
00175                         authorPageText = i18n("Please report bugs to <a href=\"mailto:%1\">%2</a>.\n",
00176                                               aboutData->authors().first().emailAddress(),
00177                                               aboutData->authors().first().emailAddress());
00178                     }
00179                     else {
00180                         authorPageText = i18n("Please report bugs to <a href=\"mailto:%1\">%2</a>.\n",
00181                                               aboutData->bugAddress(), aboutData->bugAddress());
00182                     }
00183                 }
00184             }
00185             else
00186                 authorPageText = aboutData->customAuthorRichText();
00187         }
00188 
00189         authorPageText += "<br />";
00190 
00191         const QList<KAboutPerson> lst = aboutData->authors();
00192         for (int i = 0; i < lst.size(); ++i) {
00193             QString pname = i18nc("@item Author name in about dialog", "%1", lst.at(i).name());
00194             authorPageText += QString("<p style=\"margin: 0px;\">%1</p>").arg(pname);
00195             if (!lst.at(i).emailAddress().isEmpty())
00196                 authorPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\"><a href=\"mailto:%1\">%1</a></p>").arg(lst.at(i).emailAddress());
00197             if (!lst.at(i).webAddress().isEmpty())
00198                 authorPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\"><a href=\"%3\">%3</a></p>").arg(lst.at(i).webAddress());
00199             if (!lst.at(i).task().isEmpty())
00200                 authorPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\">%4</p>").arg(lst.at(i).task());
00201             if (i < lst.size() - 1)
00202                 authorPageText += "<p style=\"margin: 0px;\">&nbsp;</p>";
00203         }
00204 
00205         KTextBrowser *authorTextBrowser = new KTextBrowser;
00206         authorTextBrowser->setFrameStyle(QFrame::NoFrame);
00207         authorTextBrowser->setPalette(transparentBackgroundPalette);
00208         authorTextBrowser->setHtml(authorPageText);
00209         tabWidget->addTab(authorTextBrowser, authorPageTitle);
00210     }
00211 
00212     const int creditsCount = aboutData->credits().count();
00213     if (creditsCount) {
00214         QString creditsPageText;
00215 
00216         const QList<KAboutPerson> lst = aboutData->credits();
00217         for (int i = 0; i < lst.size(); ++i) {
00218             QString pname = i18nc("@item Contributor name in about dialog.", "%1", lst.at(i).name());
00219             creditsPageText += QString("<p style=\"margin: 0px;\">%1</p>").arg(pname);
00220             if (!lst.at(i).emailAddress().isEmpty())
00221                 creditsPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\"><a href=\"mailto:%1\">%1</a></p>").arg(lst.at(i).emailAddress());
00222             if (!lst.at(i).webAddress().isEmpty())
00223                 creditsPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\"><a href=\"%3\">%3</a></p>").arg(lst.at(i).webAddress());
00224             if (!lst.at(i).task().isEmpty())
00225                 creditsPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\">%4</p>").arg(lst.at(i).task());
00226             if (i < lst.size() - 1)
00227                 creditsPageText += "<p style=\"margin: 0px;\">&nbsp;</p>";
00228         }
00229 
00230         KTextBrowser *creditsTextBrowser = new KTextBrowser;
00231         creditsTextBrowser->setFrameStyle(QFrame::NoFrame);
00232         creditsTextBrowser->setPalette(transparentBackgroundPalette);
00233         creditsTextBrowser->setHtml(creditsPageText);
00234         tabWidget->addTab(creditsTextBrowser, i18n("&Thanks To"));
00235     }
00236 
00237     if ( !( opt & HideTranslators ) ) {
00238         const QList<KAboutPerson> translatorList = aboutData->translators();
00239 
00240         if(translatorList.count() > 0) {
00241             QString translatorPageText;
00242 
00243             QList<KAboutPerson>::ConstIterator it;
00244             for(it = translatorList.begin(); it != translatorList.end(); ++it) {
00245                 translatorPageText += QString("<p style=\"margin: 0px;\">%1</p>").arg((*it).name());
00246                 if (!(*it).emailAddress().isEmpty())
00247                     translatorPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\"><a href=\"mailto:%1\">%1</a></p>").arg((*it).emailAddress());
00248                 translatorPageText += "<p style=\"margin: 0px;\">&nbsp;</p>";
00249             }
00250 
00251             translatorPageText += KAboutData::aboutTranslationTeam();
00252 
00253             KTextBrowser *translatorTextBrowser = new KTextBrowser;
00254             translatorTextBrowser->setFrameStyle(QFrame::NoFrame);
00255             translatorTextBrowser->setPalette(transparentBackgroundPalette);
00256             translatorTextBrowser->setHtml(translatorPageText);
00257             tabWidget->addTab(translatorTextBrowser, i18n("T&ranslation"));
00258         }
00259     }
00260 
00261     QVBoxLayout *mainLayout = new QVBoxLayout;
00262     mainLayout->addWidget(titleWidget);
00263     mainLayout->addWidget(tabWidget);
00264     mainLayout->setMargin(0);
00265 
00266     QWidget *mainWidget = new QWidget;
00267     mainWidget->setLayout(mainLayout);
00268 
00269     q->setMainWidget(mainWidget);
00270 }
00271 
00272 KAboutApplicationDialog::~KAboutApplicationDialog()
00273 {
00274     delete d;
00275 }
00276 
00277 void KAboutApplicationDialog::Private::_k_showLicense( const QString &number )
00278 {
00279     KDialog *dialog = new KDialog(q);
00280 
00281     dialog->setCaption(i18n("License Agreement"));
00282     dialog->setButtons(KDialog::Close);
00283     dialog->setDefaultButton(KDialog::Close);
00284 
00285     const QFont font = KGlobalSettings::fixedFont();
00286     QFontMetrics metrics(font);
00287 
00288     const QString licenseText = aboutData->licenses().at(number.toInt()).text();
00289     KTextBrowser *licenseBrowser = new KTextBrowser;
00290     licenseBrowser->setFont(font);
00291     licenseBrowser->setLineWrapMode(QTextEdit::NoWrap);
00292     licenseBrowser->setText(licenseText);
00293 
00294     dialog->setMainWidget(licenseBrowser);
00295 
00296     // try to set up the dialog such that the full width of the
00297     // document is visible without horizontal scroll-bars being required
00298     const qreal idealWidth = licenseBrowser->document()->idealWidth() + (2 * dialog->marginHint())
00299         + licenseBrowser->verticalScrollBar()->width() * 2;
00300 
00301     // try to allow enough height for a reasonable number of lines to be shown
00302     const int idealHeight = metrics.height() * 30;
00303 
00304     dialog->setInitialSize(dialog->sizeHint().expandedTo(QSize((int)idealWidth,idealHeight)));
00305     dialog->show();
00306 }
00307 
00308 #include "kaboutapplicationdialog.moc"

KDEUI

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • 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
  • KUtils
  • Nepomuk
  • Plasma
  •     Sodep
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal