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 
00046 #include "uiDialog.moc"
00047 
00048 UIDialog::UIDialog(QWidget * parent, const char *name,
00049         bool modal) :
00050         KDialogBase(parent, name, modal, QString::null,
00051                 KDialogBase::Ok | KDialogBase::Cancel, 
00052                 KDialogBase::Ok, false), 
00053         fP(0L)
00054 {
00055         FUNCTIONSETUP;
00056 
00057         fMainWidget = makeHBoxMainWidget();
00058 }
00059 
00060 UIDialog::~UIDialog()
00061 {
00062         FUNCTIONSETUP;
00063 }
00064 
00065 void UIDialog::addAboutPage(bool aboutbutton,KAboutData *ad)
00066 {
00067         FUNCTIONSETUP;
00068         ASSERT(tabWidget());
00069 
00070         QWidget *w = new QWidget(tabWidget(), "aboutpage");
00071 
00072         QString s;
00073         QLabel *text;
00074         KIconLoader *l = KGlobal::iconLoader();
00075         const KAboutData *p = ad ? ad : KGlobal::instance()->aboutData();
00076         
00077         QGridLayout *grid = new QGridLayout(w, 5, 4, SPACING);
00078 
00079         grid->addColSpacing(0, SPACING);
00080         grid->addColSpacing(4, SPACING);
00081 
00082 
00083 #ifdef DEBUG
00084         DEBUGKPILOT << fname
00085                 << ": Looking for icon for "
00086                 << p->appName()
00087                 << endl;
00088 #endif
00089 
00090         QPixmap applicationIcon =
00091                 l->loadIcon(QString::fromLatin1(p->appName()),
00092                 KIcon::Desktop,
00093                 0, KIcon::DefaultState, 0L,
00094                 true);
00095 
00096         if (applicationIcon.isNull())
00097         {
00098 #ifdef DEBUG
00099                 DEBUGKPILOT << fname
00100                         << ": Looking for icon for "
00101                         << "kpilot"
00102                         << endl;
00103 #endif
00104                 applicationIcon = l->loadIcon(QString::fromLatin1("kpilot"), 
00105                         KIcon::Desktop);
00106         }
00107 
00108         text = new QLabel(w);
00109         text->setPixmap(applicationIcon);
00110         text->adjustSize();
00111         grid->addWidget(text, 0, 1);
00112 
00113 
00114         text = new QLabel(w);
00115         s = QString::null;
00116         s += p->programName();
00117         s += ' ';
00118         s += p->version();
00119         s += '\n';
00120         s += p->copyrightStatement();
00121         text->setText(s);
00122         grid->addMultiCellWidget(text, 0, 0, 2, 3);
00123 
00124         text = new QLabel(w);
00125         s = p->shortDescription();
00126         text->setText(s);
00127         grid->addMultiCellWidget(text, 1, 1, 2, 3);
00128 
00129         text = new QLabel(w);
00130         // Experiment with a long non-<qt> string. Use that to find
00131         // sensible widths for the columns.
00132         //
00133         text->setText(i18n("Send questions and comments to kde-pim@kde.org"));
00134         text->adjustSize();
00135 #ifdef DEBUG
00136         DEBUGKPILOT << fname
00137                 << ": Text size "
00138                 << text->size().width()
00139                 << ","
00140                 << text->size().height()
00141                 << endl;
00142 #endif
00143         grid->addColSpacing(2,SPACING+text->size().width()/2);
00144         grid->addColSpacing(3,SPACING+text->size().width()/2);
00145 
00146         s = "<qt>";
00147         if (!p->homepage().isEmpty())
00148         {
00149                 s += p->homepage();
00150                 s += CSL1("<br>");
00151         }
00152         s += i18n("Send questions and comments to <i>kde-pim@kde.org</i>");
00153         s += CSL1("<br>");
00154         s += i18n("Send bug reports to <i>%1</i>").arg(p->bugAddress());
00155         s += CSL1("</qt>");
00156 
00157         text->setText(s);
00158         grid->addMultiCellWidget(text, 2, 2, 2, 3);
00159 
00160 
00161 
00162         if (aboutbutton)
00163         {
00164                 QPushButton *but = new QPushButton(i18n("More About"),
00165                         w);
00166 
00167                 connect(but, SIGNAL(clicked()), this, SLOT(showAbout()));
00168                 but->adjustSize();
00169                 grid->addWidget(but, 4, 2);
00170                 grid->setRowStretch(3, 100);
00171         }
00172         else
00173         {
00174                 QValueList<KAboutPerson> l = p->authors();
00175                 QValueList<KAboutPerson>::ConstIterator i;
00176                 s = i18n("<qt><b>Authors:</b> ");
00177 
00178                 QString comma = CSL1(", ");
00179                 
00180                 unsigned int count=1;
00181                 for (i=l.begin(); i!=l.end(); ++i)
00182                 {
00183                         s.append(CSL1("%1 (<i>%2</i>)%3")
00184                                 .arg((*i).name())
00185                                 .arg((*i).task())
00186                                 .arg(count<l.count() ? comma : QString::null)
00187                                 );
00188                         count++;
00189                 }
00190 
00191                 l = p->credits();
00192                 if (l.count()>0)
00193                 {
00194                         count=1;
00195                         s.append(i18n("<br><b>Credits:</b> "));
00196                         for (i=l.begin(); i!=l.end(); ++i)
00197                         {
00198                                 s.append(CSL1("%1 (<i>%2</i>)%3")
00199                                         .arg((*i).name())
00200                                         .arg((*i).task())
00201                                         .arg(count<l.count() ? comma : QString::null)
00202                                         );
00203                                 count++;
00204                         }
00205                 }
00206 
00207 
00208                 s.append(CSL1("</qt>"));
00209 
00210                 text = new QLabel(w);
00211                 text->setText(s);
00212                 text->adjustSize();
00213 
00214                 grid->addMultiCellWidget(text,4,4,2,3);
00215 
00216                 grid->setRowStretch(4,100);
00217                 grid->addRowSpacing(5,SPACING);
00218         }
00219 
00220 
00221         grid->setColStretch(3, 100);
00222 
00223 #ifdef DEBUG
00224         DEBUGKPILOT << fname
00225                 << ": Size "
00226                 << w->size().width()
00227                 << ","
00228                 << w->size().height()
00229                 << endl;
00230 #endif
00231 
00232         w->adjustSize();
00233 #ifdef DEBUG
00234         DEBUGKPILOT << fname
00235                 << ": Adjusted size "
00236                 << w->size().width()
00237                 << ","
00238                 << w->size().height()
00239                 << endl;
00240 #endif
00241 
00242         QSize sz = w->size();
00243 
00244         if (sz.width() < tabWidget()->size().width())
00245         {
00246                 sz.setWidth(tabWidget()->size().width());
00247         }
00248         if (sz.height() < tabWidget()->size().height())
00249         {
00250                 sz.setHeight(tabWidget()->size().height());
00251         }
00252 
00253 #ifdef DEBUG
00254         DEBUGKPILOT << fname
00255                 << ": Final size "
00256                 << sz.width()
00257                 << ","
00258                 << sz.height()
00259                 << endl;
00260 #endif
00261 
00262         tabWidget()->resize(sz);
00263         tabWidget()->addTab(w, i18n("About"));
00264 
00265 }
00266 
00267 void UIDialog::setTabWidget(QTabWidget * w)
00268 {
00269         FUNCTIONSETUP;
00270 
00271         widget()->resize(w->size());
00272         fP = w;
00273 }
00274 
00275 /* slot */ void UIDialog::showAbout()
00276 {
00277         FUNCTIONSETUP;
00278         KAboutApplication *kap = new KAboutApplication(this);
00279 
00280         kap->exec();
00281         // Experience crashes when deleting kap
00282         //
00283         //
00284         // delete kap;
00285 }
00286 
00287 /* virtual slot */ void UIDialog::slotOk()
00288 {
00289         FUNCTIONSETUP;
00290 
00291         if (validate())
00292         {
00293                 commitChanges();
00294                 KDialogBase::slotOk();
00295         }
00296 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:15 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001