KDEUI
kaboutapplicationdialog.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 _k_showLicense( const QString &number );
00049
00050 KAboutApplicationDialog *q;
00051
00052 const KAboutData *aboutData;
00053 };
00054
00055 KAboutApplicationDialog::KAboutApplicationDialog(const KAboutData *aboutData, QWidget *parent)
00056 : KDialog(parent),
00057 d(new Private(this))
00058 {
00059 if (aboutData == 0)
00060 aboutData = KGlobal::mainComponent().aboutData();
00061
00062 d->aboutData = aboutData;
00063
00064 if (!aboutData) {
00065 QLabel *errorLabel = new QLabel(i18n("<qt>No information available.<br />"
00066 "The supplied KAboutData object does not exist.</qt>"), this);
00067
00068 errorLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
00069 setMainWidget(errorLabel);
00070 return;
00071 }
00072
00073 setPlainCaption(i18n("About %1", aboutData->programName()));
00074 setButtons(KDialog::Close);
00075 setDefaultButton(KDialog::Close);
00076 setModal(false);
00077
00078 KTitleWidget *titleWidget = new KTitleWidget(this);
00079
00080 QIcon windowIcon;
00081 if (!aboutData->programIconName().isEmpty()) {
00082 windowIcon = KIcon(aboutData->programIconName());
00083 } else {
00084 windowIcon = qApp->windowIcon();
00085 }
00086 titleWidget->setPixmap(windowIcon.pixmap(64, 64), KTitleWidget::ImageLeft);
00087 if (aboutData->programLogo().canConvert<QPixmap>())
00088 titleWidget->setPixmap(aboutData->programLogo().value<QPixmap>(), KTitleWidget::ImageLeft);
00089 else if (aboutData->programLogo().canConvert<QImage>())
00090 titleWidget->setPixmap(QPixmap::fromImage(aboutData->programLogo().value<QImage>()), KTitleWidget::ImageLeft);
00091
00092 titleWidget->setText(i18n("<html><font size=\"5\">%1</font><br /><b>Version %2</b><br />Using KDE %3</html>",
00093 aboutData->programName(), aboutData->version(), QString(KDE_VERSION_STRING)));
00094
00095 QTabWidget *tabWidget = new QTabWidget;
00096 tabWidget->setUsesScrollButtons(false);
00097
00098 QString aboutPageText = aboutData->shortDescription() + '\n';
00099
00100 if (!aboutData->otherText().isEmpty())
00101 aboutPageText += '\n' + aboutData->otherText() + '\n';
00102
00103 if (!aboutData->copyrightStatement().isEmpty())
00104 aboutPageText += '\n' + aboutData->copyrightStatement() + '\n';
00105
00106 if (!aboutData->homepage().isEmpty())
00107 aboutPageText += '\n' + QString("<a href=\"%1\">%1</a>").arg(aboutData->homepage()) + '\n';
00108 aboutPageText = aboutPageText.trimmed();
00109
00110 QLabel *aboutLabel = new QLabel;
00111 aboutLabel->setWordWrap(true);
00112 aboutLabel->setOpenExternalLinks(true);
00113 aboutLabel->setText(aboutPageText.replace('\n', "<br />"));
00114 aboutLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
00115
00116 QVBoxLayout *aboutLayout = new QVBoxLayout;
00117 aboutLayout->addStretch();
00118 aboutLayout->addWidget(aboutLabel);
00119
00120 const int licenseCount = aboutData->licenses().count();
00121 for (int i = 0; i < licenseCount; ++i) {
00122 const KAboutLicense &license = aboutData->licenses().at(i);
00123
00124 QLabel *showLicenseLabel = new QLabel;
00125 showLicenseLabel->setText(QString("<a href=\"%1\">%2</a>").arg(QString::number(i),
00126 i18n("License: %1",
00127 license.name(KAboutData::FullName))));
00128 showLicenseLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
00129 connect(showLicenseLabel, SIGNAL(linkActivated(QString)), this, SLOT(_k_showLicense(QString)));
00130
00131 aboutLayout->addWidget(showLicenseLabel);
00132 }
00133
00134 aboutLayout->addStretch();
00135
00136 QWidget *aboutWidget = new QWidget(this);
00137 aboutWidget->setLayout(aboutLayout);
00138
00139 tabWidget->addTab(aboutWidget, i18n("&About"));
00140
00141 QPalette transparentBackgroundPalette;
00142 transparentBackgroundPalette.setColor(QPalette::Base, Qt::transparent);
00143
00144 const int authorCount = aboutData->authors().count();
00145 if (authorCount) {
00146 QString authorPageText;
00147
00148 QString authorPageTitle = authorCount == 1 ? i18n("A&uthor") : i18n("A&uthors");
00149
00150 if (!aboutData->customAuthorTextEnabled() || !aboutData->customAuthorRichText().isEmpty()) {
00151 if (!aboutData->customAuthorTextEnabled()) {
00152 if (aboutData->bugAddress().isEmpty() || aboutData->bugAddress() == "submit@bugs.kde.org")
00153 authorPageText = i18n("Please use <a href=\"http://bugs.kde.org\">http://bugs.kde.org</a> to report bugs.\n");
00154 else {
00155 if(aboutData->authors().count() == 1 && (aboutData->authors().first().emailAddress() == aboutData->bugAddress())) {
00156 authorPageText = i18n("Please report bugs to <a href=\"mailto:%1\">%2</a>.\n",
00157 aboutData->authors().first().emailAddress(),
00158 aboutData->authors().first().emailAddress());
00159 }
00160 else {
00161 authorPageText = i18n("Please report bugs to <a href=\"mailto:%1\">%2</a>.\n",
00162 aboutData->bugAddress(), aboutData->bugAddress());
00163 }
00164 }
00165 }
00166 else
00167 authorPageText = aboutData->customAuthorRichText();
00168 }
00169
00170 authorPageText += "<br />";
00171
00172 const QList<KAboutPerson> lst = aboutData->authors();
00173 for (int i = 0; i < lst.size(); ++i) {
00174 authorPageText += QString("<p style=\"margin: 0px;\">%1</p>").arg(lst.at(i).name());
00175 if (!lst.at(i).emailAddress().isEmpty())
00176 authorPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\"><a href=\"mailto:%1\">%1</a></p>").arg(lst.at(i).emailAddress());
00177 if (!lst.at(i).webAddress().isEmpty())
00178 authorPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\"><a href=\"%3\">%3</a></p>").arg(lst.at(i).webAddress());
00179 if (!lst.at(i).task().isEmpty())
00180 authorPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\">%4</p>").arg(lst.at(i).task());
00181 if (i < lst.size() - 1)
00182 authorPageText += "<p style=\"margin: 0px;\"> </p>";
00183 }
00184
00185 KTextBrowser *authorTextBrowser = new KTextBrowser;
00186 authorTextBrowser->setFrameStyle(QFrame::NoFrame);
00187 authorTextBrowser->setPalette(transparentBackgroundPalette);
00188 authorTextBrowser->setHtml(authorPageText);
00189 tabWidget->addTab(authorTextBrowser, authorPageTitle);
00190 }
00191
00192 const int creditsCount = aboutData->credits().count();
00193 if (creditsCount) {
00194 QString creditsPageText;
00195
00196 const QList<KAboutPerson> lst = aboutData->credits();
00197 for (int i = 0; i < lst.size(); ++i) {
00198 creditsPageText += QString("<p style=\"margin: 0px;\">%1</p>").arg(lst.at(i).name());
00199 if (!lst.at(i).emailAddress().isEmpty())
00200 creditsPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\"><a href=\"mailto:%1\">%1</a></p>").arg(lst.at(i).emailAddress());
00201 if (!lst.at(i).webAddress().isEmpty())
00202 creditsPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\"><a href=\"%3\">%3</a></p>").arg(lst.at(i).webAddress());
00203 if (!lst.at(i).task().isEmpty())
00204 creditsPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\">%4</p>").arg(lst.at(i).task());
00205 if (i < lst.size() - 1)
00206 creditsPageText += "<p style=\"margin: 0px;\"> </p>";
00207 }
00208
00209 KTextBrowser *creditsTextBrowser = new KTextBrowser;
00210 creditsTextBrowser->setFrameStyle(QFrame::NoFrame);
00211 creditsTextBrowser->setPalette(transparentBackgroundPalette);
00212 creditsTextBrowser->setHtml(creditsPageText);
00213 tabWidget->addTab(creditsTextBrowser, i18n("&Thanks To"));
00214 }
00215
00216 const QList<KAboutPerson> translatorList = aboutData->translators();
00217
00218 if(translatorList.count() > 0) {
00219 QString translatorPageText;
00220
00221 QList<KAboutPerson>::ConstIterator it;
00222 for(it = translatorList.begin(); it != translatorList.end(); ++it) {
00223 translatorPageText += QString("<p style=\"margin: 0px;\">%1</p>").arg((*it).name());
00224 if (!(*it).emailAddress().isEmpty())
00225 translatorPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\"><a href=\"mailto:%1\">%1</a></p>").arg((*it).emailAddress());
00226 translatorPageText += "<p style=\"margin: 0px;\"> </p>";
00227 }
00228
00229 translatorPageText += KAboutData::aboutTranslationTeam();
00230
00231 KTextBrowser *translatorTextBrowser = new KTextBrowser;
00232 translatorTextBrowser->setFrameStyle(QFrame::NoFrame);
00233 translatorTextBrowser->setPalette(transparentBackgroundPalette);
00234 translatorTextBrowser->setHtml(translatorPageText);
00235 tabWidget->addTab(translatorTextBrowser, i18n("T&ranslation"));
00236 }
00237
00238 QVBoxLayout *mainLayout = new QVBoxLayout;
00239 mainLayout->addWidget(titleWidget);
00240 mainLayout->addWidget(tabWidget);
00241 mainLayout->setMargin(0);
00242
00243 QWidget *mainWidget = new QWidget;
00244 mainWidget->setLayout(mainLayout);
00245
00246 setMainWidget(mainWidget);
00247 }
00248
00249 KAboutApplicationDialog::~KAboutApplicationDialog()
00250 {
00251 delete d;
00252 }
00253
00254 void KAboutApplicationDialog::Private::_k_showLicense( const QString &number )
00255 {
00256 KDialog *dialog = new KDialog(q);
00257
00258 dialog->setCaption(i18n("License Agreement"));
00259 dialog->setButtons(KDialog::Close);
00260 dialog->setDefaultButton(KDialog::Close);
00261
00262 const QFont font = KGlobalSettings::fixedFont();
00263 QFontMetrics metrics(font);
00264
00265 const QString licenseText = aboutData->licenses().at(number.toInt()).text();
00266 KTextBrowser *licenseBrowser = new KTextBrowser;
00267 licenseBrowser->setFont(font);
00268 licenseBrowser->setLineWrapMode(QTextEdit::NoWrap);
00269 licenseBrowser->setText(licenseText);
00270
00271 dialog->setMainWidget(licenseBrowser);
00272
00273
00274
00275 const qreal idealWidth = licenseBrowser->document()->idealWidth() + (2 * dialog->marginHint())
00276 + licenseBrowser->verticalScrollBar()->width() * 2;
00277
00278
00279 const int idealHeight = metrics.height() * 30;
00280
00281 dialog->setInitialSize(dialog->sizeHint().expandedTo(QSize((int)idealWidth,idealHeight)));
00282 dialog->show();
00283 }
00284
00285 #include "kaboutapplicationdialog.moc"