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 transparentBackgroundPalette.setColor(QPalette::Text, transparentBackgroundPalette.color(QPalette::WindowText));
00144
00145 const int authorCount = aboutData->authors().count();
00146 if (authorCount) {
00147 QString authorPageText;
00148
00149 QString authorPageTitle = authorCount == 1 ? i18n("A&uthor") : i18n("A&uthors");
00150
00151 if (!aboutData->customAuthorTextEnabled() || !aboutData->customAuthorRichText().isEmpty()) {
00152 if (!aboutData->customAuthorTextEnabled()) {
00153 if (aboutData->bugAddress().isEmpty() || aboutData->bugAddress() == "submit@bugs.kde.org")
00154 authorPageText = i18n("Please use <a href=\"http://bugs.kde.org\">http://bugs.kde.org</a> to report bugs.\n");
00155 else {
00156 if(aboutData->authors().count() == 1 && (aboutData->authors().first().emailAddress() == aboutData->bugAddress())) {
00157 authorPageText = i18n("Please report bugs to <a href=\"mailto:%1\">%2</a>.\n",
00158 aboutData->authors().first().emailAddress(),
00159 aboutData->authors().first().emailAddress());
00160 }
00161 else {
00162 authorPageText = i18n("Please report bugs to <a href=\"mailto:%1\">%2</a>.\n",
00163 aboutData->bugAddress(), aboutData->bugAddress());
00164 }
00165 }
00166 }
00167 else
00168 authorPageText = aboutData->customAuthorRichText();
00169 }
00170
00171 authorPageText += "<br />";
00172
00173 const QList<KAboutPerson> lst = aboutData->authors();
00174 for (int i = 0; i < lst.size(); ++i) {
00175 QString pname = i18nc("@item Author name in about dialog", "%1", lst.at(i).name());
00176 authorPageText += QString("<p style=\"margin: 0px;\">%1</p>").arg(pname);
00177 if (!lst.at(i).emailAddress().isEmpty())
00178 authorPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\"><a href=\"mailto:%1\">%1</a></p>").arg(lst.at(i).emailAddress());
00179 if (!lst.at(i).webAddress().isEmpty())
00180 authorPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\"><a href=\"%3\">%3</a></p>").arg(lst.at(i).webAddress());
00181 if (!lst.at(i).task().isEmpty())
00182 authorPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\">%4</p>").arg(lst.at(i).task());
00183 if (i < lst.size() - 1)
00184 authorPageText += "<p style=\"margin: 0px;\"> </p>";
00185 }
00186
00187 KTextBrowser *authorTextBrowser = new KTextBrowser;
00188 authorTextBrowser->setFrameStyle(QFrame::NoFrame);
00189 authorTextBrowser->setPalette(transparentBackgroundPalette);
00190 authorTextBrowser->setHtml(authorPageText);
00191 tabWidget->addTab(authorTextBrowser, authorPageTitle);
00192 }
00193
00194 const int creditsCount = aboutData->credits().count();
00195 if (creditsCount) {
00196 QString creditsPageText;
00197
00198 const QList<KAboutPerson> lst = aboutData->credits();
00199 for (int i = 0; i < lst.size(); ++i) {
00200 QString pname = i18nc("@item Contributor name in about dialog.", "%1", lst.at(i).name());
00201 creditsPageText += QString("<p style=\"margin: 0px;\">%1</p>").arg(pname);
00202 if (!lst.at(i).emailAddress().isEmpty())
00203 creditsPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\"><a href=\"mailto:%1\">%1</a></p>").arg(lst.at(i).emailAddress());
00204 if (!lst.at(i).webAddress().isEmpty())
00205 creditsPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\"><a href=\"%3\">%3</a></p>").arg(lst.at(i).webAddress());
00206 if (!lst.at(i).task().isEmpty())
00207 creditsPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\">%4</p>").arg(lst.at(i).task());
00208 if (i < lst.size() - 1)
00209 creditsPageText += "<p style=\"margin: 0px;\"> </p>";
00210 }
00211
00212 KTextBrowser *creditsTextBrowser = new KTextBrowser;
00213 creditsTextBrowser->setFrameStyle(QFrame::NoFrame);
00214 creditsTextBrowser->setPalette(transparentBackgroundPalette);
00215 creditsTextBrowser->setHtml(creditsPageText);
00216 tabWidget->addTab(creditsTextBrowser, i18n("&Thanks To"));
00217 }
00218
00219 const QList<KAboutPerson> translatorList = aboutData->translators();
00220
00221 if(translatorList.count() > 0) {
00222 QString translatorPageText;
00223
00224 QList<KAboutPerson>::ConstIterator it;
00225 for(it = translatorList.begin(); it != translatorList.end(); ++it) {
00226 translatorPageText += QString("<p style=\"margin: 0px;\">%1</p>").arg((*it).name());
00227 if (!(*it).emailAddress().isEmpty())
00228 translatorPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\"><a href=\"mailto:%1\">%1</a></p>").arg((*it).emailAddress());
00229 translatorPageText += "<p style=\"margin: 0px;\"> </p>";
00230 }
00231
00232 translatorPageText += KAboutData::aboutTranslationTeam();
00233
00234 KTextBrowser *translatorTextBrowser = new KTextBrowser;
00235 translatorTextBrowser->setFrameStyle(QFrame::NoFrame);
00236 translatorTextBrowser->setPalette(transparentBackgroundPalette);
00237 translatorTextBrowser->setHtml(translatorPageText);
00238 tabWidget->addTab(translatorTextBrowser, i18n("T&ranslation"));
00239 }
00240
00241 QVBoxLayout *mainLayout = new QVBoxLayout;
00242 mainLayout->addWidget(titleWidget);
00243 mainLayout->addWidget(tabWidget);
00244 mainLayout->setMargin(0);
00245
00246 QWidget *mainWidget = new QWidget;
00247 mainWidget->setLayout(mainLayout);
00248
00249 setMainWidget(mainWidget);
00250 }
00251
00252 KAboutApplicationDialog::~KAboutApplicationDialog()
00253 {
00254 delete d;
00255 }
00256
00257 void KAboutApplicationDialog::Private::_k_showLicense( const QString &number )
00258 {
00259 KDialog *dialog = new KDialog(q);
00260
00261 dialog->setCaption(i18n("License Agreement"));
00262 dialog->setButtons(KDialog::Close);
00263 dialog->setDefaultButton(KDialog::Close);
00264
00265 const QFont font = KGlobalSettings::fixedFont();
00266 QFontMetrics metrics(font);
00267
00268 const QString licenseText = aboutData->licenses().at(number.toInt()).text();
00269 KTextBrowser *licenseBrowser = new KTextBrowser;
00270 licenseBrowser->setFont(font);
00271 licenseBrowser->setLineWrapMode(QTextEdit::NoWrap);
00272 licenseBrowser->setText(licenseText);
00273
00274 dialog->setMainWidget(licenseBrowser);
00275
00276
00277
00278 const qreal idealWidth = licenseBrowser->document()->idealWidth() + (2 * dialog->marginHint())
00279 + licenseBrowser->verticalScrollBar()->width() * 2;
00280
00281
00282 const int idealHeight = metrics.height() * 30;
00283
00284 dialog->setInitialSize(dialog->sizeHint().expandedTo(QSize((int)idealWidth,idealHeight)));
00285 dialog->show();
00286 }
00287
00288 #include "kaboutapplicationdialog.moc"