00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 KPushButton(KStdGuiItem::ok(),
this);
00094
QPushButton *cancel_ =
new KPushButton(KStdGuiItem::cancel(),
this);
00095
QPushButton *apply_ =
new KPushButton(KStdGuiItem::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"