KDE3Support
k3aboutdialog.cpp
Go to the documentation of this file.
00001 /* 00002 * This file is part of the KDE Libraries 00003 * Copyright (C) 1999-2001 Mirko Boehm <mirko@kde.org> and 00004 * Espen Sand <espensa@online.no> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Library General Public License 00017 * along with this library; see the file COPYING.LIB. If not, write to 00018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 * 00021 */ 00022 00023 #include "k3aboutdialog.h" 00024 #include "k3aboutdialog_p.h" 00025 #include <kdeversion.h> 00026 #include <QtGui/QClipboard> 00027 #include <QtGui/QImage> 00028 #include <QtGui/QLabel> 00029 #include <QtCore/QDebug> 00030 #include <QtGui/QLayout> 00031 #include <QtCore/QObject> 00032 #include <QtGui/QPainter> 00033 #include <QtCore/QRect> 00034 #include <QtGui/QTabWidget> 00035 #include <QtGui/QTabBar> 00036 #include <QScrollArea> 00037 #include <QtGui/QApplication> 00038 #include <QtGui/QTextBrowser> 00039 #include <QtGui/QStyle> 00040 00041 #include <kglobal.h> 00042 #include <kglobalsettings.h> 00043 #include <klocale.h> 00044 #include <kiconloader.h> 00045 #include <kdebug.h> 00046 #include <ktextedit.h> 00047 00048 #ifndef Q_MOC_RUN 00049 template class QList<K3AboutContributor *>; 00050 #endif 00051 00052 #define WORKTEXT_IDENTATION 16 00053 #define Grid 3 00054 00055 // ############################################################## 00056 // MOC OUTPUT FILES: 00057 #include "k3aboutdialog.moc" 00058 #include "k3aboutdialog_p.moc" 00059 // ############################################################## 00060 00061 class K3AboutContributor::Private 00062 { 00063 public: 00064 Private(K3AboutContributor *_parent) 00065 : parent(_parent) 00066 { 00067 } 00068 00069 K3AboutContributor *parent; 00070 QLabel *label[4]; 00071 QLabel *text[4]; 00072 bool showHeader; 00073 bool showBold; 00074 00075 void updateLayout(); 00076 }; 00077 00078 void K3AboutContributor::Private::updateLayout() 00079 { 00080 delete parent->layout(); 00081 00082 int row = 0; 00083 if (!text[0]->text().isEmpty()) { ++row; } 00084 if (!text[1]->text().isEmpty()) { ++row; } 00085 if (!text[2]->text().isEmpty()) { ++row; } 00086 if (!text[3]->text().isEmpty()) { ++row; } 00087 00088 QGridLayout *gbox; 00089 if (row == 0) 00090 { 00091 gbox = new QGridLayout(parent); 00092 gbox->setSpacing(1); 00093 for (int i=0; i<4; ++i) 00094 { 00095 label[i]->hide(); 00096 text[i]->hide(); 00097 } 00098 } 00099 else 00100 { 00101 if (text[0]->text().isEmpty() && !showHeader) 00102 { 00103 gbox = new QGridLayout(parent); 00104 gbox->setMargin(parent->frameWidth()+1); 00105 gbox->setSpacing(2); 00106 } 00107 else 00108 { 00109 gbox = new QGridLayout(parent); 00110 gbox->setMargin(parent->frameWidth()+1); 00111 gbox->setSpacing(2); 00112 if (!showHeader) 00113 { 00114 gbox->addItem(new QSpacerItem(KDialog::spacingHint()*2, 0), 0, 0); 00115 } 00116 gbox->setColumnStretch(1, 10); 00117 } 00118 00119 for (int i=0, r=0; i<4; ++i) 00120 { 00121 label[i]->setFixedHeight(parent->fontMetrics().lineSpacing()); 00122 if (i != 3) 00123 { 00124 text[i]->setFixedHeight(parent->fontMetrics().lineSpacing()); 00125 } 00126 00127 if (!text[i]->text().isEmpty()) 00128 { 00129 if (showHeader) 00130 { 00131 gbox->addWidget(label[i], r, 0, Qt::AlignLeft); 00132 gbox->addWidget(text[i], r, 1, Qt::AlignLeft ); 00133 label[i]->show(); 00134 text[i]->show(); 00135 } 00136 else 00137 { 00138 label[i]->hide(); 00139 if (!i) 00140 { 00141 gbox->addWidget(text[i], r, 0, 1, 2, Qt::AlignLeft); 00142 } 00143 else 00144 { 00145 gbox->addWidget(text[i], r, 1, Qt::AlignLeft ); 00146 } 00147 text[i]->show(); 00148 } 00149 ++r; 00150 } 00151 else 00152 { 00153 label[i]->hide(); 00154 text[i]->hide(); 00155 } 00156 } 00157 } 00158 00159 gbox->activate(); 00160 parent->setMinimumSize(parent->sizeHint()); 00161 } 00162 00163 K3AboutContributor::K3AboutContributor(QWidget *_parent, 00164 const QString &_name,const QString &_email, 00165 const QString &_url, const QString &_work, 00166 bool showHeader, bool showFrame, 00167 bool showBold) 00168 : QFrame(_parent), d(new Private(this)) 00169 { 00170 if (showFrame) 00171 setFrameStyle(QFrame::Panel | QFrame::Plain); 00172 00173 d->showHeader = showHeader; 00174 d->showBold = showBold; 00175 for (int i=0; i < 4; ++i) { 00176 d->label[i] = new QLabel(this); 00177 d->label[i]->setOpenExternalLinks(true); 00178 d->label[i]->setTextInteractionFlags(Qt::LinksAccessibleByMouse); 00179 d->text[i] = new QLabel(this); 00180 d->text[i]->setOpenExternalLinks(true); 00181 d->text[i]->setTextInteractionFlags(Qt::LinksAccessibleByMouse); 00182 } 00183 00184 setName(_name, i18n("Author"), false); 00185 setEmail(_email, i18n("Email"), false); 00186 setUrl(_url, i18n("Homepage"), false); 00187 setWork(_work, i18n("Task"), false); 00188 00189 d->label[3]->setAlignment(Qt::AlignTop); 00190 00191 fontChange(font()); 00192 d->updateLayout(); 00193 } 00194 00195 K3AboutContributor::~K3AboutContributor() 00196 { 00197 delete d; 00198 } 00199 00200 void K3AboutContributor::setName(const QString &_text, const QString &_header, 00201 bool _update) 00202 { 00203 d->label[0]->setText(_header); 00204 d->text[0]->setText(_text); 00205 if (_update) { d->updateLayout(); } 00206 } 00207 00208 00209 void K3AboutContributor::setEmail(const QString &_text, const QString &_header, 00210 bool _update) 00211 { 00212 if (_text.isEmpty()) 00213 return; 00214 d->label[1]->setText(_header); 00215 d->text[1]->setText(QString("<a href=\"mailto:%1\">%1</a>").arg(_text)); 00216 if (_update) { d->updateLayout(); } 00217 } 00218 00219 void K3AboutContributor::setUrl(const QString &_text, const QString &_header, 00220 bool _update) 00221 { 00222 if (_text.isEmpty()) 00223 return; 00224 d->label[2]->setText(_header); 00225 d->text[2]->setText(QString("<a href=\"%1\">%1</a>").arg(_text)); 00226 if (_update) { d->updateLayout(); } 00227 } 00228 00229 void K3AboutContributor::setWork(const QString &_text, const QString &_header, 00230 bool _update) 00231 { 00232 d->label[3]->setText(_header); 00233 d->text[3]->setText(_text); 00234 if (_update) { d->updateLayout(); } 00235 } 00236 00237 QString K3AboutContributor::name() const 00238 { 00239 return d->text[0]->text(); 00240 } 00241 00242 QString K3AboutContributor::email() const 00243 { 00244 return d->text[1]->text(); 00245 } 00246 00247 QString K3AboutContributor::url() const 00248 { 00249 return d->text[2]->text(); 00250 } 00251 00252 QString K3AboutContributor::work() const 00253 { 00254 return d->text[3]->text(); 00255 } 00256 00257 void K3AboutContributor::fontChange(const QFont &/*oldFont*/) 00258 { 00259 if (d->showBold) 00260 { 00261 QFont f(font()); 00262 f.setBold(true); 00263 d->text[0]->setFont(f); 00264 } 00265 update(); 00266 } 00267 00268 QSize K3AboutContributor::sizeHint(void) const 00269 { 00270 return minimumSizeHint(); 00271 } 00272 00273 // 00274 // Internal widget for the K3AboutDialog class. 00275 // 00276 K3AboutContainerBase::K3AboutContainerBase(int layoutType, QWidget *_parent) 00277 : QWidget(_parent), 00278 mImageLabel(0), mTitleLabel(0), mIconLabel(0),mVersionLabel(0), 00279 mAuthorLabel(0), mImageFrame(0),mPageTab(0),mPlainSpace(0),d(0) 00280 { 00281 mTopLayout = new QVBoxLayout(this); 00282 mTopLayout->setMargin(0); 00283 mTopLayout->setSpacing(KDialog::spacingHint()); 00284 00285 if (layoutType & K3AboutDialog::ImageOnly) 00286 { 00287 layoutType &= ~(K3AboutDialog::ImageLeft|K3AboutDialog::ImageRight|K3AboutDialog::Tabbed|K3AboutDialog::Plain); 00288 } 00289 if (layoutType & K3AboutDialog::ImageLeft) 00290 { 00291 layoutType &= ~K3AboutDialog::ImageRight; 00292 } 00293 00294 if (layoutType & K3AboutDialog::Title) 00295 { 00296 mTitleLabel = new QLabel(this); 00297 mTitleLabel->setObjectName("title"); 00298 mTitleLabel->setAlignment(Qt::AlignCenter); 00299 mTopLayout->addWidget(mTitleLabel); 00300 mTopLayout->addSpacing(KDialog::spacingHint()); 00301 } 00302 00303 if (layoutType & K3AboutDialog::Product) 00304 { 00305 QFrame* const productArea = new QFrame(this); 00306 productArea->setFrameStyle( QFrame::StyledPanel ); 00307 productArea->setFrameShadow( QFrame::Plain ); 00308 productArea->setBackgroundRole(QPalette::Base); 00309 productArea->setAutoFillBackground(true); 00310 00311 00312 QHBoxLayout* const hbox = new QHBoxLayout(); 00313 hbox->setMargin(3); 00314 hbox->setSpacing(KDialog::spacingHint()); 00315 00316 mIconLabel = new QLabel(productArea); 00317 hbox->addWidget(mIconLabel, 0, Qt::AlignLeft|Qt::AlignHCenter); 00318 00319 QVBoxLayout* const vbox = new QVBoxLayout(); 00320 if (!vbox) { return; } 00321 00322 mVersionLabel = new QLabel(productArea); 00323 mVersionLabel->setObjectName("version"); 00324 mAuthorLabel = new QLabel(productArea); 00325 mAuthorLabel->setObjectName("author"); 00326 vbox->addWidget(mVersionLabel); 00327 vbox->addWidget(mAuthorLabel); 00328 vbox->setMargin(3); 00329 00330 hbox->addLayout(vbox); 00331 00332 if ( QApplication::isRightToLeft() ) 00333 hbox->insertStretch(0 /* add stretch at start */ , 1); 00334 else 00335 hbox->insertStretch(-1 /* add stretch at end */ , 1); 00336 00337 productArea->setLayout(hbox); 00338 00339 mTopLayout->addWidget(productArea, 0); 00340 } 00341 00342 QHBoxLayout* const hbox = new QHBoxLayout(); 00343 if (!hbox) { return; } 00344 mTopLayout->addLayout(hbox, 10); 00345 00346 if (layoutType & K3AboutDialog::ImageLeft) 00347 { 00348 QVBoxLayout* vbox = new QVBoxLayout(); 00349 hbox->addLayout(vbox); 00350 vbox->addSpacing(1); 00351 mImageFrame = new QFrame(this); 00352 mImageFrame->setAutoFillBackground(true); 00353 setImageFrame(true); 00354 vbox->addWidget(mImageFrame); 00355 vbox->addSpacing(1); 00356 00357 vbox = new QVBoxLayout(mImageFrame); 00358 vbox->setSpacing(1); 00359 mImageLabel = new QLabel(mImageFrame); 00360 vbox->addStretch(10); 00361 vbox->addWidget(mImageLabel); 00362 vbox->addStretch(10); 00363 vbox->activate(); 00364 } 00365 00366 if (layoutType & K3AboutDialog::Tabbed) 00367 { 00368 mPageTab = new QTabWidget(this); 00369 if (!mPageTab) { return; } 00370 mPageTab->setUsesScrollButtons(false); 00371 hbox->addWidget(mPageTab, 10); 00372 } 00373 else if (layoutType & K3AboutDialog::ImageOnly) 00374 { 00375 mImageFrame = new QFrame(this); 00376 mImageFrame->setAutoFillBackground(true); 00377 setImageFrame(true); 00378 hbox->addWidget(mImageFrame, 10); 00379 00380 QGridLayout* const gbox = new QGridLayout(mImageFrame); 00381 gbox->setMargin(1); 00382 gbox->setSpacing(0); 00383 gbox->setRowStretch(0, 10); 00384 gbox->setRowStretch(2, 10); 00385 gbox->setColumnStretch(0, 10); 00386 gbox->setColumnStretch(2, 10); 00387 00388 mImageLabel = new QLabel(mImageFrame); 00389 gbox->addWidget(mImageLabel, 1, 1); 00390 gbox->activate(); 00391 } 00392 else 00393 { 00394 mPlainSpace = new QFrame(this); 00395 if (!mPlainSpace) { return; } 00396 hbox->addWidget(mPlainSpace, 10); 00397 } 00398 00399 if (layoutType & K3AboutDialog::ImageRight) 00400 { 00401 QVBoxLayout *vbox = new QVBoxLayout(); 00402 hbox->addLayout(vbox); 00403 vbox->addSpacing(1); 00404 mImageFrame = new QFrame(this); 00405 mImageFrame->setAutoFillBackground(true); 00406 setImageFrame(true); 00407 vbox->addWidget(mImageFrame); 00408 vbox->addSpacing(1); 00409 00410 vbox = new QVBoxLayout(mImageFrame); 00411 vbox->setSpacing(1); 00412 mImageLabel = new QLabel(mImageFrame); 00413 vbox->addStretch(10); 00414 vbox->addWidget(mImageLabel); 00415 vbox->addStretch(10); 00416 vbox->activate(); 00417 } 00418 00419 fontChange(font()); 00420 } 00421 00422 QSize K3AboutContainerBase::sizeHint() const 00423 { 00424 return minimumSize().expandedTo(QSize(QWidget::sizeHint().width(), 0)); 00425 } 00426 00427 void K3AboutContainerBase::fontChange(const QFont &/*oldFont*/) 00428 { 00429 if (mTitleLabel) 00430 { 00431 QFont f(KGlobalSettings::generalFont()); 00432 f.setBold(true); 00433 int fs = f.pointSize(); 00434 if (fs == -1) 00435 fs = QFontInfo(f).pointSize(); 00436 f.setPointSize(fs+2); // Lets not make it too big 00437 mTitleLabel->setFont(f); 00438 } 00439 00440 if (mVersionLabel) 00441 { 00442 QFont f(KGlobalSettings::generalFont()); 00443 mVersionLabel->setFont(f); 00444 mAuthorLabel->setFont(f); 00445 mVersionLabel->parentWidget()->layout()->activate(); 00446 } 00447 00448 update(); 00449 } 00450 00451 QFrame *K3AboutContainerBase::addTextPage(const QString &title, 00452 const QString &text, 00453 bool richText, int numLines) 00454 { 00455 QFrame *const page = addEmptyPage(title); 00456 if (!page) { return 0; } 00457 if (numLines <= 0) { numLines = 10; } 00458 00459 QVBoxLayout* const vbox = new QVBoxLayout(page); 00460 vbox->setSpacing(KDialog::spacingHint()); 00461 00462 if (richText) 00463 { 00464 QTextBrowser *browser = new QTextBrowser(page); 00465 browser->setFrameStyle( QFrame::NoFrame ); 00466 browser->setOpenExternalLinks(true); 00467 browser->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 00468 browser->setHtml(text); 00469 browser->setMinimumHeight(fontMetrics().lineSpacing()*numLines); 00470 00471 vbox->addWidget(browser); 00472 } 00473 else 00474 { 00475 KTextEdit *const textEdit = new KTextEdit(page); 00476 textEdit->setFrameStyle( QFrame::NoFrame ); 00477 textEdit->setObjectName("text"); 00478 textEdit->setReadOnly(true); 00479 textEdit->setMinimumHeight(fontMetrics().lineSpacing()*numLines); 00480 textEdit->setLineWrapMode(QTextEdit::NoWrap); 00481 vbox->addWidget(textEdit); 00482 } 00483 00484 return page; 00485 } 00486 00487 QFrame *K3AboutContainerBase::addLicensePage(const QString &title, 00488 const QString &text, int numLines) 00489 { 00490 QFrame *const page = addEmptyPage(title); 00491 if (!page) { return 0; } 00492 if (numLines <= 0) { numLines = 10; } 00493 00494 QVBoxLayout* const vbox = new QVBoxLayout(page); 00495 vbox->setSpacing(KDialog::spacingHint()); 00496 00497 vbox->setMargin(0); 00498 00499 KTextEdit* const textEdit = new KTextEdit(page); 00500 textEdit->setFrameStyle(QFrame::NoFrame); 00501 textEdit->setObjectName("license"); 00502 textEdit->setFont(KGlobalSettings::fixedFont()); 00503 textEdit->setReadOnly(true); 00504 textEdit->setLineWrapMode(QTextEdit::NoWrap); 00505 textEdit->setPlainText(text); 00506 textEdit->setMinimumHeight(fontMetrics().lineSpacing()*numLines); 00507 vbox->addWidget(textEdit); 00508 return page; 00509 } 00510 00511 00512 K3AboutContainer *K3AboutContainerBase::addContainerPage(const QString &title, 00513 Qt::Alignment childAlignment, 00514 Qt::Alignment innerAlignment) 00515 { 00516 if (!mPageTab) 00517 { 00518 kDebug(291) << "addPage: " << "Invalid layout"; 00519 return 0; 00520 } 00521 00522 K3AboutContainer* const container = new K3AboutContainer(0, 00523 KDialog::spacingHint(), KDialog::spacingHint(), childAlignment, 00524 innerAlignment); 00525 mPageTab->addTab(container, title); 00526 return container; 00527 } 00528 00529 00530 K3AboutContainer *K3AboutContainerBase::addScrolledContainerPage( 00531 const QString &title, 00532 Qt::Alignment childAlignment, 00533 Qt::Alignment innerAlignment) 00534 { 00535 if (!mPageTab) 00536 { 00537 kDebug(291) << "addPage: " << "Invalid layout"; 00538 return 0; 00539 } 00540 00541 QFrame *const page = addEmptyPage(title); 00542 QVBoxLayout* const vbox = new QVBoxLayout(page); 00543 vbox->setSpacing(KDialog::spacingHint()); 00544 vbox->setMargin(0); 00545 00546 QScrollArea* const scrollView = new QScrollArea(page); 00547 scrollView->setFrameStyle(QFrame::Plain); 00548 vbox->addWidget(scrollView); 00549 00550 K3AboutContainer* const container = new K3AboutContainer(scrollView, 00551 KDialog::spacingHint(), KDialog::spacingHint(), childAlignment, 00552 innerAlignment); 00553 scrollView->setWidget(container); 00554 return container; 00555 } 00556 00557 00558 QFrame *K3AboutContainerBase::addEmptyPage(const QString &title) 00559 { 00560 if (!mPageTab) 00561 { 00562 kDebug(291) << "addPage: " << "Invalid layout"; 00563 return 0; 00564 } 00565 00566 QFrame *const page = new QFrame(); 00567 page->setObjectName(title.toLatin1()); 00568 page->setFrameStyle(QFrame::NoFrame); 00569 00570 mPageTab->addTab(page, title); 00571 return page; 00572 } 00573 00574 00575 K3AboutContainer *K3AboutContainerBase::addContainer(Qt::Alignment childAlignment, 00576 Qt::Alignment innerAlignment) 00577 { 00578 K3AboutContainer* const container = new K3AboutContainer(this, 00579 0, KDialog::spacingHint(), childAlignment, innerAlignment); 00580 container->setObjectName("container"); 00581 mTopLayout->addWidget(container, 0, childAlignment); 00582 return container; 00583 } 00584 00585 00586 00587 void K3AboutContainerBase::setTitle(const QString &title) 00588 { 00589 if (!mTitleLabel) 00590 { 00591 kDebug(291) << "setTitle: " << "Invalid layout"; 00592 return; 00593 } 00594 mTitleLabel->setText(title); 00595 } 00596 00597 00598 void K3AboutContainerBase::setImage(const QString &fileName) 00599 { 00600 if (!mImageLabel) 00601 { 00602 kDebug(291) << "setImage: " << "Invalid layout"; 00603 return; 00604 } 00605 if (fileName.isNull()) 00606 { 00607 return; 00608 } 00609 00610 const QPixmap logo(fileName); 00611 if (!logo.isNull()) 00612 mImageLabel->setPixmap(logo); 00613 00614 mImageFrame->layout()->activate(); 00615 } 00616 00617 void K3AboutContainerBase::setProgramLogo(const QString &fileName) 00618 { 00619 if (fileName.isNull()) 00620 { 00621 return; 00622 } 00623 00624 const QPixmap logo(fileName); 00625 setProgramLogo(logo); 00626 } 00627 00628 void K3AboutContainerBase::setProgramLogo(const QPixmap &pixmap) 00629 { 00630 if (!mIconLabel) 00631 { 00632 kDebug(291) << "setProgramLogo: " << "Invalid layout"; 00633 return; 00634 } 00635 if (!pixmap.isNull()) 00636 { 00637 mIconLabel->setPixmap(pixmap); 00638 } 00639 } 00640 00641 void K3AboutContainerBase::setImageBackgroundColor(const QColor &color) 00642 { 00643 if (mImageFrame) 00644 { 00645 QPalette palette(mImageFrame->palette()); 00646 palette.setColor(QPalette::Window, color); 00647 mImageFrame->setPalette(palette); 00648 } 00649 } 00650 00651 00652 void K3AboutContainerBase::setImageFrame(bool state) 00653 { 00654 if (mImageFrame) 00655 { 00656 if (state) 00657 { 00658 mImageFrame->setFrameStyle(QFrame::Panel | QFrame::Sunken); 00659 mImageFrame->setLineWidth(1); 00660 } 00661 else 00662 { 00663 mImageFrame->setFrameStyle(QFrame::NoFrame); 00664 mImageFrame->setLineWidth(0); 00665 } 00666 } 00667 } 00668 00669 00670 void K3AboutContainerBase::setProduct(const QString &appName, 00671 const QString &version, 00672 const QString &author, 00673 const QString &year) 00674 { 00675 if (!mIconLabel) 00676 { 00677 kDebug(291) << "setProduct: " << "Invalid layout"; 00678 return; 00679 } 00680 00681 int size = IconSize(KIconLoader::Desktop); 00682 mIconLabel->setPixmap(qApp->windowIcon().pixmap(size,size)); 00683 00684 const QString msg1 = i18n("<html><font size=\"5\">%1</font><br/><b>version %2</b><br/>Using KDE %3</html>", appName, version, 00685 QLatin1String(KDE_VERSION_STRING)); 00686 const QString msg2 = !year.isEmpty() ? i18n("%1 %2, %3", QChar(0xA9), year, 00687 author) : QLatin1String(""); 00688 00689 //if (!year.isEmpty()) 00690 // msg2 = i18n("%1 %2, %3").arg(QChar(0xA9)).arg(year).arg(author); 00691 00692 mVersionLabel->setText(msg1); 00693 mAuthorLabel->setText(msg2); 00694 if (msg2.isEmpty()) 00695 { 00696 mAuthorLabel->hide(); 00697 } 00698 00699 mIconLabel->parentWidget()->layout()->activate(); 00700 } 00701 00702 class K3AboutContainer::Private 00703 { 00704 public: 00705 QVBoxLayout *vbox; 00706 Qt::Alignment alignment; 00707 }; 00708 00709 K3AboutContainer::K3AboutContainer(QWidget *parent, 00710 int margin, int spacing, 00711 Qt::Alignment childAlignment, 00712 Qt::Alignment innerAlignment) 00713 : QFrame(parent), d(new Private) 00714 { 00715 d->alignment = innerAlignment; 00716 00717 setFrameStyle(QFrame::NoFrame); 00718 00719 QGridLayout* const gbox = new QGridLayout(this); 00720 gbox->setMargin(margin); 00721 gbox->setMargin(spacing); 00722 if (childAlignment & Qt::AlignHCenter) 00723 { 00724 gbox->setColumnStretch(0, 10); 00725 gbox->setColumnStretch(2, 10); 00726 } 00727 else if (childAlignment & Qt::AlignRight) 00728 { 00729 gbox->setColumnStretch(0, 10); 00730 } 00731 else 00732 { 00733 gbox->setColumnStretch(2, 10); 00734 } 00735 00736 if (childAlignment & Qt::AlignVCenter) 00737 { 00738 gbox->setRowStretch(0, 10); 00739 gbox->setRowStretch(2, 10); 00740 } 00741 else if (childAlignment & Qt::AlignRight) 00742 { 00743 gbox->setRowStretch(0, 10); 00744 } 00745 else 00746 { 00747 gbox->setRowStretch(2, 10); 00748 } 00749 00750 d->vbox = new QVBoxLayout(); 00751 d->vbox->setSpacing(spacing); 00752 gbox->addLayout(d->vbox, 1, 1); 00753 gbox->activate(); 00754 } 00755 00756 K3AboutContainer::~K3AboutContainer() 00757 { 00758 delete d; 00759 } 00760 00761 QSize K3AboutContainer::sizeHint(void) const 00762 { 00763 // 00764 // The size is computed by adding the sizeHint().height() of all 00765 // widget children and taking the width of the widest child and adding 00766 // layout()->margin() and layout()->spacing() 00767 // 00768 00769 QSize total_size; 00770 00771 int numChild = 0; 00772 const QList<QObject*> l = children(); // silence please 00773 foreach (QObject *o, l) { 00774 if (o->isWidgetType()) 00775 { 00776 ++numChild; 00777 QWidget* const w= static_cast<QWidget *>(o); 00778 00779 QSize s = w->minimumSize(); 00780 if (s.isEmpty()) 00781 { 00782 s = w->minimumSizeHint(); 00783 if (s.isEmpty()) 00784 { 00785 s = w->sizeHint(); 00786 if (s.isEmpty()) 00787 { 00788 s = QSize(100, 100); // Default size 00789 } 00790 } 00791 } 00792 total_size.setHeight(total_size.height() + s.height()); 00793 if (s.width() > total_size.width()) { total_size.setWidth(s.width()); } 00794 } 00795 } 00796 00797 if (numChild > 0) 00798 { 00799 // 00800 // Seems I have to add 1 to the height to properly show the border 00801 // of the last entry if layout()->margin() is 0 00802 // 00803 00804 total_size.setHeight(total_size.height() + layout()->spacing()*(numChild-1)); 00805 total_size += QSize(layout()->margin()*2, layout()->margin()*2 + 1); 00806 } 00807 else 00808 { 00809 total_size = QSize(1, 1); 00810 } 00811 return total_size; 00812 } 00813 00814 00815 QSize K3AboutContainer::minimumSizeHint(void) const 00816 { 00817 return sizeHint(); 00818 } 00819 00820 void K3AboutContainer::addWidget(QWidget *widget) 00821 { 00822 widget->setParent(this); 00823 00824 d->vbox->addWidget(widget, 0, d->alignment); 00825 const QSize s(sizeHint()); 00826 setMinimumSize(s); 00827 00828 const QList<QObject*> l = children(); // silence please 00829 foreach (QObject *o, l) { 00830 if (o->isWidgetType()) 00831 { 00832 static_cast<QWidget *>(o)->setMinimumWidth(s.width()); 00833 } 00834 } 00835 00836 } 00837 00838 void K3AboutContainer::addPerson(const QString &_name, const QString &_email, 00839 const QString &_url, const QString &_task, 00840 bool showHeader, bool showFrame,bool showBold) 00841 { 00842 00843 K3AboutContributor* const cont = new K3AboutContributor(this, 00844 _name, _email, _url, _task, showHeader, showFrame, showBold); 00845 cont->setObjectName("pers"); 00846 addWidget(cont); 00847 } 00848 00849 00850 void K3AboutContainer::addTitle(const QString &title, Qt::Alignment alignment, 00851 bool showFrame, bool showBold) 00852 { 00853 00854 QLabel* const label = new QLabel(title, this); 00855 label->setObjectName("title"); 00856 if (showBold ) 00857 { 00858 QFont labelFont(font()); 00859 labelFont.setBold(true); 00860 label->setFont(labelFont); 00861 } 00862 if (showFrame) 00863 label->setFrameStyle(QFrame::Panel | QFrame::Raised); 00864 00865 label->setAlignment(alignment); 00866 addWidget(label); 00867 } 00868 00869 00870 void K3AboutContainer::addImage(const QString &fileName, Qt::Alignment alignment) 00871 { 00872 if (fileName.isNull()) 00873 { 00874 return; 00875 } 00876 00877 QLabel* const label = new QLabel(this); 00878 label->setObjectName("image"); 00879 const QImage logo(fileName); 00880 if (!logo.isNull()) 00881 { 00882 QPixmap pix; 00883 pix = QPixmap::fromImage(logo, 0); 00884 label->setPixmap(pix); 00885 } 00886 label->setAlignment(alignment); 00887 addWidget(label); 00888 } 00889 00890 K3AboutWidget::K3AboutWidget(QWidget *_parent) 00891 : QWidget(_parent), 00892 version(new QLabel(this)), 00893 cont(new QLabel(this)), 00894 logo(new QLabel(this)), 00895 author(new K3AboutContributor(this)), 00896 maintainer(new K3AboutContributor(this)), 00897 showMaintainer(false), 00898 d(0) 00899 { 00900 cont->setText(i18n("Other Contributors:")); 00901 logo->setText(i18n("(No logo available)")); 00902 logo->setFrameStyle(QFrame::Panel | QFrame::Raised); 00903 version->setAlignment(Qt::AlignCenter); 00904 } 00905 00906 00907 void K3AboutWidget::adjust() 00908 { 00909 int cx, cy, tempx; 00910 int maintWidth, maintHeight; 00911 QSize total_size; 00912 // ----- 00913 if (showMaintainer) 00914 { 00915 total_size=maintainer->sizeHint(); 00916 maintWidth=total_size.width(); 00917 maintHeight=total_size.height(); 00918 } else { 00919 maintWidth=0; 00920 maintHeight=0; 00921 } 00922 total_size=author->sizeHint(); 00923 logo->adjustSize(); 00924 cy=version->sizeHint().height()+Grid; 00925 cx=logo->width(); 00926 tempx=qMax(total_size.width(), maintWidth); 00927 cx+=Grid+tempx; 00928 cx=qMax(cx, version->sizeHint().width()); 00929 cy+=qMax(logo->height(), 00930 total_size.height()+(showMaintainer ? Grid+maintHeight : 0)); 00931 // ----- 00932 if (!contributors.isEmpty()) 00933 { 00934 cx=qMax(cx, cont->sizeHint().width()); 00935 cy+=cont->sizeHint().height()+Grid; 00936 foreach(K3AboutContributor* currEntry, contributors) 00937 { 00938 cy+=currEntry->sizeHint().height(); 00939 } 00940 } 00941 // ----- 00942 setMinimumSize(cx, cy); 00943 } 00944 00945 void K3AboutWidget::setLogo(const QPixmap& i) 00946 { 00947 logo->setPixmap(i); 00948 } 00949 00950 void K3AboutWidget::setAuthor(const QString &_name, const QString &_email, 00951 const QString &_url, const QString &_w) 00952 { 00953 author->setName(_name); 00954 author->setEmail(_email); 00955 author->setUrl(_url); 00956 author->setWork(_w); 00957 } 00958 00959 void K3AboutWidget::setMaintainer(const QString &_name, const QString &_email, 00960 const QString &_url, const QString &_w) 00961 { 00962 maintainer->setName(_name); 00963 maintainer->setEmail(_email); 00964 maintainer->setWork(_w); 00965 maintainer->setUrl(_url); 00966 showMaintainer=true; 00967 } 00968 00969 void K3AboutWidget::addContributor(const QString &_name, const QString &_email, 00970 const QString &_url, const QString &_w) 00971 { 00972 K3AboutContributor* const c=new K3AboutContributor(this); 00973 // ----- 00974 c->setName(_name); 00975 c->setEmail(_email); 00976 c->setUrl(_url); 00977 c->setWork(_w); 00978 contributors.append(c); 00979 } 00980 00981 void K3AboutWidget::setVersion(const QString &_name) 00982 { 00983 version->setText(_name); 00984 } 00985 00986 void K3AboutWidget::resizeEvent(QResizeEvent*) 00987 { 00988 int _x=0, _y, cx, tempx, tempy; 00989 // ----- set version label geometry: 00990 version->setGeometry(0, 0, width(), version->sizeHint().height()); 00991 _y=version->height()+Grid; 00992 // ----- move logo to correct position: 00993 logo->adjustSize(); 00994 logo->move(0, _y); 00995 // ----- move author and maintainer right to it: 00996 tempx=logo->width()+Grid; 00997 cx=width()-tempx; 00998 author->setGeometry 00999 (tempx, _y, cx, author->sizeHint().height()); 01000 maintainer->setGeometry 01001 (tempx, _y+author->height()+Grid, cx, maintainer->sizeHint().height()); 01002 01003 _y+=qMax(logo->height(), 01004 author->height()+(showMaintainer ? Grid+maintainer->height() : 0)); 01005 // ----- 01006 if (!contributors.isEmpty()) 01007 { 01008 tempy=cont->sizeHint().height(); 01009 cont->setGeometry(0, _y, width(), tempy); 01010 cont->show(); 01011 _y+=tempy+Grid; 01012 } else { 01013 cont->hide(); 01014 } 01015 foreach(K3AboutContributor *currEntry, contributors) 01016 { 01017 tempy=currEntry->sizeHint().height(); 01018 // y+=Grid; 01019 currEntry->setGeometry(_x, _y, width(), tempy); 01020 _y+=tempy; 01021 } 01022 if (showMaintainer) 01023 { 01024 maintainer->show(); 01025 } else { 01026 maintainer->hide(); 01027 } 01028 } 01029 01030 K3AboutDialog::K3AboutDialog(QWidget *_parent) 01031 : KDialog(_parent), 01032 mAbout(new K3AboutWidget(this)), mContainerBase(0), d(0) 01033 { 01034 setButtons(Ok); 01035 setModal(true); 01036 setMainWidget(mAbout); 01037 } 01038 01039 K3AboutDialog::K3AboutDialog(int layoutType, const QString &_caption, QWidget *_parent) 01040 : KDialog(_parent), 01041 mAbout(0), d(0) 01042 { 01043 setModal(true); 01044 setPlainCaption(i18n("About %1", _caption)); 01045 01046 mContainerBase = new K3AboutContainerBase(layoutType, this); 01047 setMainWidget(mContainerBase); 01048 } 01049 01050 01051 void K3AboutDialog::show(void) 01052 { 01053 adjust(); 01054 if (mContainerBase) { mContainerBase->show(); } 01055 QDialog::show(); 01056 } 01057 01058 01059 void K3AboutDialog::show(QWidget * /*centerParent*/) 01060 { 01061 adjust(); 01062 if (mContainerBase) { mContainerBase->show(); } 01063 QDialog::show(); 01064 } 01065 01066 void K3AboutDialog::adjust() 01067 { 01068 if (!mAbout) 01069 return; 01070 01071 mAbout->adjust(); 01072 resize(sizeHint()); 01073 } 01074 01075 void K3AboutDialog::setLogo(const QPixmap& i) 01076 { 01077 if (!mAbout) 01078 return; 01079 01080 mAbout->setLogo(i); 01081 } 01082 01083 void K3AboutDialog::setMaintainer(const QString &_name, const QString &_email, 01084 const QString &_url, const QString &_w) 01085 { 01086 if (!mAbout) 01087 return; 01088 01089 mAbout->setMaintainer(_name, _email, _url, _w); 01090 } 01091 01092 void K3AboutDialog::setAuthor(const QString &_name, const QString &_email, 01093 const QString &_url, const QString &_work) 01094 { 01095 if (!mAbout) 01096 return; 01097 01098 mAbout->setAuthor(_name, _email, _url, _work); 01099 } 01100 01101 void K3AboutDialog::addContributor(const QString &_name, const QString &_email, 01102 const QString &_url, const QString &_w) 01103 { 01104 if (!mAbout) 01105 return; 01106 01107 mAbout->addContributor(_name, _email, _url, _w); 01108 } 01109 01110 void K3AboutDialog::setVersion(const QString &_name) 01111 { 01112 if (!mAbout) 01113 return; 01114 01115 mAbout->setVersion(_name); 01116 } 01117 01118 QFrame *K3AboutDialog::addTextPage(const QString &title, const QString &text, 01119 bool richText, int numLines) 01120 { 01121 if (!mContainerBase) { return 0; } 01122 return mContainerBase->addTextPage(title, text, richText, numLines); 01123 } 01124 01125 QFrame *K3AboutDialog::addLicensePage(const QString &title, const QString &text, 01126 int numLines) 01127 { 01128 if (!mContainerBase) { return 0; } 01129 return mContainerBase->addLicensePage(title, text, numLines); 01130 } 01131 01132 K3AboutContainer *K3AboutDialog::addContainerPage(const QString &title, 01133 Qt::Alignment childAlignment, Qt::Alignment innerAlignment) 01134 { 01135 if (!mContainerBase) { return 0; } 01136 return mContainerBase->addContainerPage(title, childAlignment, 01137 innerAlignment); 01138 } 01139 01140 K3AboutContainer *K3AboutDialog::addScrolledContainerPage(const QString &title, 01141 Qt::Alignment childAlignment, Qt::Alignment innerAlignment) 01142 { 01143 if (!mContainerBase) { return 0; } 01144 return mContainerBase->addScrolledContainerPage(title, childAlignment, 01145 innerAlignment); 01146 } 01147 01148 QFrame *K3AboutDialog::addPage(const QString &title) 01149 { 01150 if (!mContainerBase) { return 0; } 01151 return mContainerBase->addEmptyPage(title); 01152 } 01153 01154 01155 K3AboutContainer *K3AboutDialog::addContainer(Qt::Alignment childAlignment, 01156 Qt::Alignment innerAlignment) 01157 { 01158 if (!mContainerBase) { return 0; } 01159 return mContainerBase->addContainer(childAlignment, innerAlignment); 01160 } 01161 01162 01163 void K3AboutDialog::setTitle(const QString &title) 01164 { 01165 if (!mContainerBase) { return; } 01166 mContainerBase->setTitle(title); 01167 } 01168 01169 void K3AboutDialog::setImage(const QString &fileName) 01170 { 01171 if (!mContainerBase) { return; } 01172 mContainerBase->setImage(fileName); 01173 } 01174 01175 void K3AboutDialog::setProgramLogo(const QString &fileName) 01176 { 01177 if (!mContainerBase) { return; } 01178 mContainerBase->setProgramLogo(fileName); 01179 } 01180 01181 void K3AboutDialog::setProgramLogo(const QPixmap &pixmap) 01182 { 01183 if (!mContainerBase) { return; } 01184 mContainerBase->setProgramLogo(pixmap); 01185 } 01186 01187 void K3AboutDialog::setImageBackgroundColor(const QColor &color) 01188 { 01189 if (!mContainerBase) { return; } 01190 mContainerBase->setImageBackgroundColor(color); 01191 } 01192 01193 void K3AboutDialog::setImageFrame(bool state) 01194 { 01195 if (!mContainerBase) { return; } 01196 mContainerBase->setImageFrame(state); 01197 } 01198 01199 void K3AboutDialog::setProduct(const QString &appName, const QString &version, 01200 const QString &author, const QString &year) 01201 { 01202 if (!mContainerBase) { return; } 01203 mContainerBase->setProduct(appName, version, author, year); 01204 } 01205 01206 void K3AboutDialog::imageUrl(QWidget *_parent, const QString &_caption, 01207 const QString &_path, const QColor &_imageColor, 01208 const QString &_url) 01209 { 01210 K3AboutDialog a(ImageOnly, QString(), _parent); 01211 a.setButtons(Close); 01212 a.setDefaultButton(Close); 01213 a.setObjectName("image"); 01214 a.setPlainCaption(_caption); 01215 a.setImage(_path); 01216 a.setImageBackgroundColor(_imageColor); 01217 01218 K3AboutContainer* const c = a.addContainer(Qt::AlignCenter, Qt::AlignCenter); 01219 if (c) 01220 { 01221 c->addPerson(QString(), QString(), _url, QString()); 01222 } 01223 a.exec(); 01224 } 01225
KDE 4.6 API Reference