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() + "<br />";
00099
00100 if (!aboutData->otherText().isEmpty())
00101 aboutPageText += "<br />" + aboutData->otherText() + "<br />";
00102
00103 if (!aboutData->copyrightStatement().isEmpty())
00104 aboutPageText += "<br />" + aboutData->copyrightStatement() + "<br />";
00105
00106 if (!aboutData->homepage().isEmpty())
00107 aboutPageText += "<br />" + QString("<a href=\"%1\">%1</a>").arg(aboutData->homepage()) + "<br />";
00108
00109 QLabel *aboutLabel = new QLabel;
00110 aboutLabel->setWordWrap(true);
00111 aboutLabel->setOpenExternalLinks(true);
00112 aboutLabel->setText(aboutPageText.replace('\n', "<br />"));
00113 aboutLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
00114
00115 QVBoxLayout *aboutLayout = new QVBoxLayout;
00116 aboutLayout->addStretch();
00117 aboutLayout->addWidget(aboutLabel);
00118
00119 const int licenseCount = aboutData->licenses().count();
00120 for (int i = 0; i < licenseCount; ++i) {
00121 const KAboutLicense &license = aboutData->licenses().at(i);
00122
00123 QLabel *showLicenseLabel = new QLabel;
00124 showLicenseLabel->setText(QString("<a href=\"%1\">%2</a>").arg(QString::number(i),
00125 i18n("License: %1",
00126 license.name(KAboutData::FullName))));
00127 showLicenseLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
00128 connect(showLicenseLabel, SIGNAL(linkActivated(QString)), this, SLOT(_k_showLicense(QString)));
00129
00130 aboutLayout->addWidget(showLicenseLabel);
00131 }
00132
00133 aboutLayout->addStretch();
00134
00135 QWidget *aboutWidget = new QWidget(this);
00136 aboutWidget->setLayout(aboutLayout);
00137
00138 tabWidget->addTab(aboutWidget, i18n("&About"));
00139
00140 QPalette transparentBackgroundPalette;
00141 transparentBackgroundPalette.setColor(QPalette::Base, Qt::transparent);
00142
00143 int authorCount = aboutData->authors().count();
00144 if (authorCount) {
00145 QString authorPageText;
00146
00147 QString authorPageTitle = authorCount == 1 ? i18n("A&uthor") : i18n("A&uthors");
00148
00149 if (!aboutData->customAuthorTextEnabled() || !aboutData->customAuthorRichText().isEmpty()) {
00150 if (!aboutData->customAuthorTextEnabled()) {
00151 if (aboutData->bugAddress().isEmpty() || aboutData->bugAddress() == "submit@bugs.kde.org")
00152 authorPageText = i18n("Please use <a href=\"http://bugs.kde.org\">http://bugs.kde.org</a> to report bugs.\n");
00153 else {
00154 if(aboutData->authors().count() == 1 && (aboutData->authors().first().emailAddress() == aboutData->bugAddress())) {
00155 authorPageText = i18n("Please report bugs to <a href=\"mailto:%1\">%2</a>.\n",
00156 aboutData->authors().first().emailAddress(),
00157 aboutData->authors().first().emailAddress());
00158 }
00159 else {
00160 authorPageText = i18n("Please report bugs to <a href=\"mailto:%1\">%2</a>.\n",
00161 aboutData->bugAddress(), aboutData->bugAddress());
00162 }
00163 }
00164 }
00165 else
00166 authorPageText = aboutData->customAuthorRichText();
00167 }
00168
00169 authorPageText += "<br />";
00170
00171 QList<KAboutPerson> lst = aboutData->authors();
00172 for (int i = 0; i < lst.size(); ++i) {
00173 authorPageText += QString("<p style=\"margin: 0px;\">%1</p>").arg(lst.at(i).name());
00174 if (!lst.at(i).emailAddress().isEmpty())
00175 authorPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\"><a href=\"mailto:%1\">%1</a></p>").arg(lst.at(i).emailAddress());
00176 if (!lst.at(i).webAddress().isEmpty())
00177 authorPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\"><a href=\"%3\">%3</a></p>").arg(lst.at(i).webAddress());
00178 if (!lst.at(i).task().isEmpty())
00179 authorPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\">%4</p>").arg(lst.at(i).task());
00180 authorPageText += "<p style=\"margin: 0px;\"> </p>";
00181 }
00182
00183 KTextBrowser *authorTextBrowser = new KTextBrowser;
00184 authorTextBrowser->setFrameStyle(QFrame::NoFrame);
00185 authorTextBrowser->setPalette(transparentBackgroundPalette);
00186 authorTextBrowser->setHtml(authorPageText);
00187 tabWidget->addTab(authorTextBrowser, authorPageTitle);
00188 }
00189
00190 int creditsCount = aboutData->credits().count();
00191 if (creditsCount) {
00192 QString creditsPageText;
00193
00194 QList<KAboutPerson> lst = aboutData->credits();
00195 for (int i = 0; i < lst.size(); ++i) {
00196 creditsPageText += QString("<p style=\"margin: 0px;\">%1</p>").arg(lst.at(i).name());
00197 if (!lst.at(i).emailAddress().isEmpty())
00198 creditsPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\"><a href=\"mailto:%1\">%1</a></p>").arg(lst.at(i).emailAddress());
00199 if (!lst.at(i).webAddress().isEmpty())
00200 creditsPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\"><a href=\"%3\">%3</a></p>").arg(lst.at(i).webAddress());
00201 if (!lst.at(i).task().isEmpty())
00202 creditsPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\">%4</p>").arg(lst.at(i).task());
00203 creditsPageText += "<p style=\"margin: 0px;\"> </p>";
00204 }
00205
00206 KTextBrowser *creditsTextBrowser = new KTextBrowser;
00207 creditsTextBrowser->setFrameStyle(QFrame::NoFrame);
00208 creditsTextBrowser->setPalette(transparentBackgroundPalette);
00209 creditsTextBrowser->setHtml(creditsPageText);
00210 tabWidget->addTab(creditsTextBrowser, i18n("&Thanks To"));
00211 }
00212
00213 const QList<KAboutPerson> translatorList = aboutData->translators();
00214
00215 if(translatorList.count() > 0) {
00216 QString translatorPageText = QString();
00217
00218 QList<KAboutPerson>::ConstIterator it;
00219 for(it = translatorList.begin(); it != translatorList.end(); ++it) {
00220 translatorPageText += QString("<p style=\"margin: 0px;\">%1</p>").arg((*it).name());
00221 if (!(*it).emailAddress().isEmpty())
00222 translatorPageText += QString("<p style=\"margin: 0px; margin-left: 15px;\"><a href=\"mailto:%1\">%1</a></p>").arg((*it).emailAddress());
00223 translatorPageText += "<p style=\"margin: 0px;\"> </p>";
00224 }
00225
00226 translatorPageText += KAboutData::aboutTranslationTeam();
00227
00228 KTextBrowser *translatorTextBrowser = new KTextBrowser;
00229 translatorTextBrowser->setFrameStyle(QFrame::NoFrame);
00230 translatorTextBrowser->setPalette(transparentBackgroundPalette);
00231 translatorTextBrowser->setHtml(translatorPageText);
00232 tabWidget->addTab(translatorTextBrowser, i18n("T&ranslation"));
00233 }
00234
00235 QVBoxLayout *mainLayout = new QVBoxLayout;
00236 mainLayout->addWidget(titleWidget);
00237 mainLayout->addWidget(tabWidget);
00238 mainLayout->setMargin(0);
00239
00240 QWidget *mainWidget = new QWidget;
00241 mainWidget->setLayout(mainLayout);
00242
00243 setMainWidget(mainWidget);
00244 }
00245
00246 KAboutApplicationDialog::~KAboutApplicationDialog()
00247 {
00248 delete d;
00249 }
00250
00251 void KAboutApplicationDialog::Private::_k_showLicense( const QString &number )
00252 {
00253 KDialog *dialog = new KDialog(q);
00254
00255 dialog->setCaption(i18n("License Agreement"));
00256 dialog->setButtons(KDialog::Close);
00257 dialog->setDefaultButton(KDialog::Close);
00258
00259 QFont font = KGlobalSettings::fixedFont();
00260 QFontMetrics metrics(font);
00261
00262 const QString licenseText = aboutData->licenses().at(number.toInt()).text();
00263 KTextBrowser *licenseBrowser = new KTextBrowser;
00264 licenseBrowser->setFont(font);
00265 licenseBrowser->setLineWrapMode(QTextEdit::NoWrap);
00266 licenseBrowser->setText(licenseText);
00267
00268 dialog->setMainWidget(licenseBrowser);
00269
00270
00271
00272 qreal idealWidth = licenseBrowser->document()->idealWidth() + (2 * dialog->marginHint())
00273 + licenseBrowser->verticalScrollBar()->width() * 2;
00274
00275
00276 int idealHeight = metrics.height() * 30;
00277
00278 dialog->setInitialSize(dialog->sizeHint().expandedTo(QSize((int)idealWidth,idealHeight)));
00279 dialog->show();
00280 }
00281
00282 #include "kaboutapplicationdialog.moc"