kdeprint Library API Documentation

mydialogbase.cpp

00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (c) 2001 Michael Goffioul <goffioul@imec.be>
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License version 2 as published by the Free Software Foundation.
00008  *
00009  *  This library is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *  Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Library General Public License
00015  *  along with this library; see the file COPYING.LIB.  If not, write to
00016  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  *  Boston, MA 02111-1307, USA.
00018  **/
00019 
00020 #include "mydialogbase.h"
00021 
00022 #include <qlabel.h>
00023 #include <klistview.h>
00024 #include <qheader.h>
00025 #include <qpushbutton.h>
00026 #include <qwidgetstack.h>
00027 #include <qsplitter.h>
00028 #include <qlayout.h>
00029 #include <qpixmap.h>
00030 #include <qwhatsthis.h>
00031 #include <qstringlist.h>
00032 
00033 #include <kseparator.h>
00034 #include <klocale.h>
00035 
00036 class MyPage : public QListViewItem
00037 {
00038 public:
00039         MyPage(QListView *lv, const QString& hdr, const QString& txt, const QPixmap& icon, QWidget *w);
00040         MyPage(QListViewItem *item, const QString& hdr, const QString& txt, const QPixmap& icon, QWidget *w);
00041         ~MyPage();
00042 
00043         QWidget* getPage() const { return widget_; }
00044         const QString& getHeader() const { return header_; }
00045 
00046 private:
00047         QString header_;
00048         QWidget *widget_;
00049 };
00050 
00051 MyPage::MyPage(QListView *lv, const QString& hdr, const QString& txt, const QPixmap& icon, QWidget *w)
00052         : QListViewItem(lv,txt), header_(hdr), widget_(w)
00053 {
00054         setPixmap(0, icon);
00055 }
00056 
00057 MyPage::MyPage(QListViewItem *item, const QString& hdr, const QString& txt, const QPixmap& icon, QWidget *w)
00058         : QListViewItem(item,txt), header_(hdr), widget_(w)
00059 {
00060         setPixmap(0, icon);
00061 }
00062 
00063 MyPage::~MyPage()
00064 {
00065 }
00066 
00067 //------------------------------------------------------------------------------------------------
00068 
00069 MyDialogBase::MyDialogBase(QWidget *parent, const char *name)
00070         : KDialog(parent, name, true)
00071 {
00072         tree_ = new KListView(this);
00073         tree_->addColumn("");
00074         tree_->setRootIsDecorated(false);
00075         tree_->header()->hide();
00076         tree_->setFrameStyle(QFrame::WinPanel|QFrame::Sunken);
00077         tree_->setLineWidth(1);
00078         tree_->setSorting(-1);
00079         connect(tree_, SIGNAL(selectionChanged(QListViewItem*)), SLOT(slotItemSelected(QListViewItem*)));
00080 
00081         QWidget         *right_ = new QWidget(this);
00082 
00083         title_ = new QLabel("Title", right_);
00084 
00085         KSeparator* sep1 = new KSeparator( KSeparator::HLine, right_);
00086         sep1->setFixedHeight(5);
00087 
00088         stack_ = new QWidgetStack(right_);
00089 
00090         KSeparator* sep2 = new KSeparator( KSeparator::HLine, this);
00091         sep2->setFixedHeight(15);
00092 
00093         QPushButton     *ok_ = new QPushButton(i18n("OK"), this);
00094         QPushButton     *cancel_ = new QPushButton(i18n("Cancel"), this);
00095         QPushButton     *apply_ = new QPushButton(i18n("Apply"), this);
00096         QPushButton     *help_ = new QPushButton(i18n("Short Help"), this);
00097         connect(ok_, SIGNAL(clicked()), SLOT(slotOk()));
00098         connect(cancel_, SIGNAL(clicked()), SLOT(slotCancel()));
00099         connect(apply_, SIGNAL(clicked()), SLOT(slotApply()));
00100         connect(help_, SIGNAL(clicked()), SLOT(slotHelp()));
00101         ok_->setDefault(true);
00102 
00103         QVBoxLayout     *mainLayout = new QVBoxLayout(this, 10, 0);
00104     QHBoxLayout *panelLayout = new QHBoxLayout(0, 0, 5);
00105         QHBoxLayout     *btnLayout = new QHBoxLayout(0, 0, 10);
00106         QVBoxLayout     *rightLayout = new QVBoxLayout(right_, 5, 0);
00107     mainLayout->addLayout(panelLayout, 1);
00108     panelLayout->addWidget(tree_, 0);
00109     panelLayout->addWidget(right_, 1);
00110         mainLayout->addWidget(sep2, 0);
00111         mainLayout->addLayout(btnLayout, 0);
00112         btnLayout->addWidget(help_, 0);
00113         btnLayout->addStretch(1);
00114         btnLayout->addWidget(ok_, 0);
00115         btnLayout->addWidget(apply_, 0);
00116         btnLayout->addWidget(cancel_, 0);
00117         rightLayout->addWidget(title_, 0);
00118         rightLayout->addWidget(sep1, 0);
00119         rightLayout->addWidget(stack_, 1);
00120 }
00121 
00122 MyDialogBase::~MyDialogBase()
00123 {
00124 }
00125 
00126 void MyDialogBase::slotOk()
00127 {
00128         accept();
00129 }
00130 
00131 void MyDialogBase::slotCancel()
00132 {
00133         reject();
00134 }
00135 
00136 void MyDialogBase::slotApply()
00137 {
00138 }
00139 
00140 void MyDialogBase::slotItemSelected(QListViewItem *item)
00141 {
00142         if (!item) return;
00143         MyPage  *page = (MyPage*)item;
00144         QString txt = "<b>" + page->getHeader() + "</b>";
00145         title_->setText(txt);
00146         stack_->raiseWidget(page->getPage());
00147 }
00148 
00149 QListViewItem* MyDialogBase::findParent(const QStringList& path)
00150 {
00151         if (path.count() == 1) return 0;
00152         QListViewItem   *item = tree_->firstChild();
00153         uint            index(0);
00154         while (item && index < path.count()-1)
00155         {
00156                 if (item->text(0) == path[index])
00157                 {
00158                         index++;
00159                         if (index == path.count()-1) break;
00160                         item = item->firstChild();
00161                 }
00162                 else item = item->nextSibling();
00163         }
00164         return item;
00165 }
00166 
00167 void MyDialogBase::addPage(const QStringList& path, const QString& header, const QPixmap& icon, QWidget *w)
00168 {
00169         if (path.count() < 1)
00170         {
00171                 qWarning("Unable to add page without a valid path");
00172                 return;
00173         }
00174         MyPage  *page;
00175         QListViewItem   *parent = findParent(path);
00176         bool    first = (tree_->childCount() == 0);
00177         if (parent)
00178         {
00179                 page = new MyPage(parent, header, path.last(), icon, w);
00180                 parent->setOpen(true);
00181         }
00182         else
00183                 page = new MyPage(tree_, header, path.last(), icon, w);
00184         w->reparent(stack_, QPoint(0,0));
00185         if (first) tree_->setCurrentItem(page);
00186         else w->hide();
00187 
00188     tree_->setFixedWidth(tree_->sizeHint().width());
00189 }
00190 
00191 void MyDialogBase::slotHelp()
00192 {
00193         QWhatsThis::enterWhatsThisMode();
00194 }
00195 #include "mydialogbase.moc"
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.2.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Feb 4 12:36:25 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003