kpilot Library API Documentation

uiDialog.cc

00001 /* uiDialog.cc                          KPilot
00002 **
00003 ** Copyright (C) 2001 by Dan Pilone
00004 **
00005 ** This defines a subclass of KDialogBase that handles the setup for
00006 ** KPilot -- and conduits -- configuration dialogs. It also provides
00007 ** some support for the default about-page in setup dialogs, for applications
00008 ** (like conduits) with no main window or menu.
00009 */
00010 
00011 /*
00012 ** This program is free software; you can redistribute it and/or modify
00013 ** it under the terms of the GNU Lesser General Public License as published by
00014 ** the Free Software Foundation; either version 2.1 of the License, or
00015 ** (at your option) any later version.
00016 **
00017 ** This program is distributed in the hope that it will be useful,
00018 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00020 ** GNU Lesser General Public License for more details.
00021 **
00022 ** You should have received a copy of the GNU Lesser General Public License
00023 ** along with this program in a file called COPYING; if not, write to
00024 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00025 ** MA 02111-1307, USA.
00026 */
00027 
00028 /*
00029 ** Bug reports and questions can be sent to kde-pim@kde.org
00030 */
00031 
00032 #include "options.h"
00033 
00034 #include <qtabwidget.h>
00035 #include <qlabel.h>
00036 #include <qlayout.h>
00037 #include <qhbox.h>
00038 #include <qtextview.h>
00039 #include <qpushbutton.h>
00040 
00041 #include <kaboutapplication.h>
00042 #include <kglobal.h>
00043 #include <kinstance.h>
00044 #include <kiconloader.h>
00045 #include <kactivelabel.h>
00046 
00047 #include "uiDialog.moc"
00048 
00049 UIDialog::UIDialog(QWidget * parent, const char *name,
00050     bool modal) :
00051     KDialogBase(parent, name, modal, QString::null,
00052         KDialogBase::Ok | KDialogBase::Cancel,
00053         KDialogBase::Ok, false),
00054     fP(0L)
00055 {
00056     FUNCTIONSETUP;
00057 
00058     fMainWidget = makeHBoxMainWidget();
00059 }
00060 
00061 UIDialog::UIDialog(QWidget *parent, const char *name,
00062     int buttonmask, bool modal) :
00063     KDialogBase(parent,name,modal,QString::null,
00064         buttonmask | KDialogBase::Ok,
00065         KDialogBase::Ok, false),
00066     fP(0L)
00067 {
00068     FUNCTIONSETUP;
00069     fMainWidget = makeHBoxMainWidget();
00070 }
00071 
00072 UIDialog::~UIDialog()
00073 {
00074     FUNCTIONSETUP;
00075 }
00076 
00077 /* static */ QPushButton *UIDialog::addAboutPage(QTabWidget *tw,
00078     KAboutData *ad,
00079     bool /* aboutbutton */)
00080 {
00081     FUNCTIONSETUP;
00082 
00083     Q_ASSERT(tw);
00084 
00085     QWidget *w = new QWidget(tw, "aboutpage");
00086     QPushButton *but = 0L;
00087 
00088     QString s;
00089     QLabel *text;
00090     KIconLoader *l = KGlobal::iconLoader();
00091     const KAboutData *p = ad ? ad : KGlobal::instance()->aboutData();
00092 
00093     QGridLayout *grid = new QGridLayout(w, 5, 4, SPACING);
00094 
00095     grid->addColSpacing(0, SPACING);
00096     grid->addColSpacing(4, SPACING);
00097 
00098 
00099 #ifdef DEBUG
00100     DEBUGKPILOT << fname
00101         << ": Looking for icon for "
00102         << p->appName()
00103         << endl;
00104 #endif
00105 
00106     QPixmap applicationIcon =
00107         l->loadIcon(QString::fromLatin1(p->appName()),
00108         KIcon::Desktop,
00109         0, KIcon::DefaultState, 0L,
00110         true);
00111 
00112     if (applicationIcon.isNull())
00113     {
00114 #ifdef DEBUG
00115         DEBUGKPILOT << fname
00116             << ": Looking for icon for "
00117             << "kpilot"
00118             << endl;
00119 #endif
00120         applicationIcon = l->loadIcon(QString::fromLatin1("kpilot"),
00121             KIcon::Desktop);
00122     }
00123 
00124     text = new QLabel(w);
00125     // Experiment with a long non-<qt> string. Use that to find
00126     // sensible widths for the columns.
00127     //
00128     text->setText(i18n("Send questions and comments to kde-pim@kde.org"));
00129     text->adjustSize();
00130 #ifdef DEBUG
00131     DEBUGKPILOT << fname
00132         << ": Text size "
00133         << text->size().width()
00134         << ","
00135         << text->size().height()
00136         << endl;
00137 #endif
00138     int linewidth = text->size().width();
00139     int lineheight = text->size().height();
00140 
00141     // Use the label to display the applciation icon
00142     text->setText(QString::null);
00143     text->setPixmap(applicationIcon);
00144     text->adjustSize();
00145     grid->addWidget(text, 0, 1);
00146 
00147 
00148     KActiveLabel *linktext = new KActiveLabel(w);
00149     grid->addRowSpacing(1,QMAX(100,6*lineheight));
00150     grid->addRowSpacing(2,QMAX(100,6*lineheight));
00151     grid->addColSpacing(2,SPACING+linewidth/2);
00152     grid->addColSpacing(3,SPACING+linewidth/2);
00153     grid->setRowStretch(1,50);
00154     grid->setRowStretch(2,50);
00155     grid->setColStretch(2,50);
00156     grid->setColStretch(3,50);
00157     linktext->setMinimumSize(linewidth,QMAX(260,60+12*lineheight));
00158     linktext->setFixedHeight(QMAX(260,60+12*lineheight));
00159     linktext->setVScrollBarMode(QScrollView::AlwaysOn);
00160     grid->addMultiCellWidget(linktext,0,2,2,3);
00161 
00162     // Now set the program and copyright information.
00163     s = CSL1("<h3>");
00164     s += p->programName();
00165     s += ' ';
00166     s += p->version();
00167     s += CSL1("</h3>");
00168     linktext->append(s);
00169     s = p->copyrightStatement() + CSL1("<br>");
00170     linktext->append(s);
00171     linktext->append(p->shortDescription() + CSL1("<br>"));
00172 
00173     if (!p->homepage().isEmpty())
00174     {
00175         s = QString::null;
00176         s += CSL1("<a href=\"%1\">").arg(p->homepage());
00177         s += p->homepage();
00178         s += CSL1("</a>");
00179         linktext->append(s);
00180     }
00181 
00182     s = QString::null;
00183     s += i18n("Send questions and comments to <a href=\"mailto:%1\">%2</a>.")
00184         .arg( CSL1("kde-pim@kde.org") )
00185         .arg( CSL1("kde-pim@kde.org") );
00186     s += ' ';
00187     s += i18n("Send bug reports to <a href=\"mailto:%1\">%2</a>.")
00188         .arg(p->bugAddress())
00189         .arg(p->bugAddress());
00190     s += ' ';
00191     s += i18n("For trademark information, see the "
00192         "<a href=\"help:/kpilot/trademarks.html\">KPilot User's Guide</a>.");
00193     s += CSL1("<br>");
00194     linktext->append(s);
00195     linktext->append(QString::null);
00196 
00197 
00198 
00199     QValueList<KAboutPerson> pl = p->authors();
00200     QValueList<KAboutPerson>::ConstIterator i;
00201 
00202     s = i18n("<b>Authors:</b> ");
00203 
00204     QString comma = CSL1(", ");
00205 
00206     unsigned int count=1;
00207     for (i=pl.begin(); i!=pl.end(); ++i)
00208     {
00209         s.append(CSL1("%1 (<i>%2</i>)%3")
00210             .arg((*i).name())
00211             .arg((*i).task())
00212             .arg(count<pl.count() ? comma : QString::null)
00213             );
00214         count++;
00215     }
00216     linktext->append(s);
00217 
00218     s = QString::null;
00219     pl = p->credits();
00220     if (pl.count()>0)
00221     {
00222         count=1;
00223         s.append(i18n("<b>Credits:</b> "));
00224         for (i=pl.begin(); i!=pl.end(); ++i)
00225         {
00226             s.append(CSL1("%1 (<i>%2</i>)%3")
00227                 .arg((*i).name())
00228                 .arg((*i).task())
00229                 .arg(count<pl.count() ? comma : QString::null)
00230                 );
00231             count++;
00232         }
00233     }
00234     linktext->append(s);
00235     linktext->ensureVisible(0,0);
00236 
00237 #ifdef DEBUG
00238     DEBUGKPILOT << fname
00239         << ": Size "
00240         << w->size().width()
00241         << ","
00242         << w->size().height()
00243         << endl;
00244 #endif
00245 
00246     w->adjustSize();
00247 #ifdef DEBUG
00248     DEBUGKPILOT << fname
00249         << ": Adjusted size "
00250         << w->size().width()
00251         << ","
00252         << w->size().height()
00253         << endl;
00254 #endif
00255 
00256     QSize sz = w->size();
00257 
00258     if (sz.width() < tw->size().width())
00259     {
00260         sz.setWidth(tw->size().width());
00261     }
00262     if (sz.height() < tw->size().height())
00263     {
00264         sz.setHeight(tw->size().height());
00265     }
00266 
00267 #ifdef DEBUG
00268     DEBUGKPILOT << fname
00269         << ": Final size "
00270         << sz.width()
00271         << ","
00272         << sz.height()
00273         << endl;
00274 #endif
00275 
00276     tw->resize(sz);
00277     tw->addTab(w, i18n("About"));
00278     tw->adjustSize();
00279     return but;
00280 }
00281 
00282 void UIDialog::addAboutPage(bool aboutbutton,KAboutData *ad)
00283 {
00284     FUNCTIONSETUP;
00285     QPushButton *but = addAboutPage(tabWidget(),ad,aboutbutton);
00286     if (but)
00287     {
00288         connect(but, SIGNAL(clicked()), this, SLOT(showAbout()));
00289     }
00290 }
00291 
00292 void UIDialog::setTabWidget(QTabWidget * w)
00293 {
00294     FUNCTIONSETUP;
00295 
00296     widget()->resize(w->size());
00297     fP = w;
00298 }
00299 
00300 /* slot */ void UIDialog::showAbout()
00301 {
00302     FUNCTIONSETUP;
00303     KAboutApplication *kap = new KAboutApplication(this);
00304 
00305     kap->exec();
00306     // Experience crashes when deleting kap
00307     //
00308     //
00309     // delete kap;
00310 }
00311 
00312 /* virtual slot */ void UIDialog::slotOk()
00313 {
00314     FUNCTIONSETUP;
00315 
00316     if (validate())
00317     {
00318         commitChanges();
00319         KDialogBase::slotOk();
00320     }
00321 }
KDE Logo
This file is part of the documentation for kpilot Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:36:50 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003