00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "form.h"
00021
00022 #include <QtCore/QByteRef>
00023 #include <QtCore/QBuffer>
00024 #include <QtCore/QRegExp>
00025 #include <QtCore/QFile>
00026 #include <QtCore/QArgument>
00027 #include <QtCore/QMetaEnum>
00028 #include <QtGui/QKeyEvent>
00029 #include <QtGui/QDialog>
00030 #include <QtGui/QBoxLayout>
00031 #include <QtGui/QStackedLayout>
00032 #include <QtGui/QSizePolicy>
00033 #include <QtGui/QApplication>
00034 #include <QtGui/QProgressBar>
00035
00036 #include <QtGui/QTextBrowser>
00037 #include <QUiLoader>
00038 #include <QtDesigner/QFormBuilder>
00039 #include <QTextCursor>
00040 #include <QTextBlock>
00041
00042 #include <kdebug.h>
00043 #include <klocale.h>
00044 #include <kurl.h>
00045 #include <kpushbutton.h>
00046
00047
00048
00049 #include <kicon.h>
00050 #include <kaction.h>
00051 #include <kactioncollection.h>
00052 #include <kmessagebox.h>
00053 #include <kpluginloader.h>
00054 #include <kpluginfactory.h>
00055 #include <kparts/part.h>
00056
00057
00058
00059
00060 #include <kfilewidget.h>
00061 #include <kurlcombobox.h>
00062 #include <kshell.h>
00063 #include <widgets/ksqueezedtextlabel.h>
00064
00065 extern "C"
00066 {
00067 KDE_EXPORT QObject* krossmodule()
00068 {
00069 return new Kross::FormModule();
00070 }
00071 }
00072
00073 using namespace Kross;
00074
00075
00076
00077
00078
00079 FormListView::FormListView(QWidget* parent) : QListWidget(parent) {}
00080 FormListView::~FormListView() {}
00081 void FormListView::clear() { QListWidget::clear(); }
00082 void FormListView::remove(int index) { delete QListWidget::item(index); }
00083 void FormListView::addItem(const QString& text) { QListWidget::addItem(text); }
00084 int FormListView::count() { return QListWidget::count(); }
00085 int FormListView::current() { return QListWidget::currentRow(); }
00086 void FormListView::setCurrent(int row) { QListWidget::setCurrentRow(row); }
00087 QString FormListView::text(int row) {
00088 QListWidgetItem *item = QListWidget::item(row);
00089 return item ? item->text() : QString();
00090 }
00091
00092
00093
00094
00095
00096 namespace Kross {
00097
00099 class FormFileWidget::Private
00100 {
00101 public:
00102 KFileWidget* filewidget;
00103 QString filename;
00104 };
00105
00106 }
00107
00108 FormFileWidget::FormFileWidget(QWidget* parent, const QString& startDirOrVariable)
00109 : QWidget(parent), d(new Private())
00110 {
00111 QVBoxLayout* layout = new QVBoxLayout(this);
00112 layout->setSpacing(0);
00113 layout->setMargin(0);
00114 setLayout(layout);
00115
00116 d->filewidget = new KFileWidget(KUrl(startDirOrVariable), this);
00117 layout->addWidget( d->filewidget );
00118
00119
00120
00121
00122 QObject::connect(d->filewidget, SIGNAL(fileSelected(const QString&)), this, SLOT(slotFileSelected(const QString&)));
00123
00124 QObject::connect(d->filewidget, SIGNAL(fileSelected(const QString&)), this, SIGNAL(fileSelected(const QString&)));
00125 QObject::connect(d->filewidget, SIGNAL(fileHighlighted(const QString&)), this, SIGNAL(fileHighlighted(const QString&)));
00126 QObject::connect(d->filewidget, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
00127 QObject::connect(d->filewidget, SIGNAL(filterChanged(const QString&)), this, SIGNAL(filterChanged(const QString&)));
00128
00129
00130
00131
00132
00133
00134
00135 if( parent && parent->layout() )
00136 parent->layout()->addWidget(this);
00137 setMinimumSize( QSize(480,360) );
00138 }
00139
00140 FormFileWidget::~FormFileWidget()
00141 {
00142 delete d;
00143 }
00144
00145 void FormFileWidget::setMode(const QString& mode)
00146 {
00147 QMetaEnum e = metaObject()->enumerator( metaObject()->indexOfEnumerator("Mode") );
00148 KFileWidget::OperationMode m = (KFileWidget::OperationMode) e.keysToValue( mode.toLatin1() );
00149 d->filewidget->setOperationMode(m);
00150 }
00151
00152 QString FormFileWidget::currentFilter() const
00153 {
00154 return d->filewidget->currentFilter();
00155 }
00156
00157 void FormFileWidget::setFilter(const QString &filter)
00158 {
00159 QString f = filter;
00160 f.replace(QRegExp("([^\\\\]{1,1})/"), "\\1\\/");
00161 d->filewidget->setFilter(f);
00162 }
00163
00164 QString FormFileWidget::currentMimeFilter() const
00165 {
00166 return d->filewidget->currentMimeFilter();
00167 }
00168
00169 void FormFileWidget::setMimeFilter(const QStringList& filter)
00170 {
00171 d->filewidget->setMimeFilter(filter);
00172 }
00173
00174 void FormFileWidget::slotFileSelected( const QString & fn )
00175 {
00176
00177 d->filename = fn;
00178 }
00179
00180 QString FormFileWidget::selectedFile() const
00181 {
00182 if ( d->filewidget->operationMode() != KFileWidget::Saving ) {
00183 d->filewidget->accept();
00184 } else {
00185
00186 if ( d->filename.isEmpty() ) {
00187
00188 QObject::connect(d->filewidget, SIGNAL(accepted()), d->filewidget, SLOT(accept()));
00189 d->filewidget->slotOk();
00190 QObject::disconnect(d->filewidget, SIGNAL(accepted()), d->filewidget, SLOT(accept()));
00191 }
00192 }
00193
00194 KUrl url( d->filename );
00195 return url.path();
00196 }
00197
00198
00199
00200
00201
00202 namespace Kross {
00204 class FormProgressDialog::Private
00205 {
00206 public:
00207 QTextBrowser* browser;
00208 QProgressBar* bar;
00209 bool gotCanceled;
00210 QTime time;
00211 void update() {
00212 if( time.elapsed() >= 1000 ) {
00213 time.restart();
00214 qApp->processEvents();
00215 }
00216 }
00217 };
00218 }
00219
00220 FormProgressDialog::FormProgressDialog(const QString& caption, const QString& labelText) : KPageDialog(), d(new Private)
00221 {
00222 d->gotCanceled = false;
00223 d->time.start();
00224
00225 setCaption(caption);
00226 KDialog::setButtons(KDialog::Ok|KDialog::Cancel);
00227 setFaceType(KPageDialog::Plain);
00228 enableButton(KDialog::Ok, false);
00229
00230 setModal(false);
00231 setMinimumWidth(540);
00232 setMinimumHeight(400);
00233
00234 QWidget* widget = new QWidget( mainWidget() );
00235 KPageWidgetItem* item = KPageDialog::addPage(widget, QString());
00236 item->setHeader(labelText);
00237
00238 widget = item->widget();
00239 QVBoxLayout* layout = new QVBoxLayout(widget);
00240 layout->setMargin(0);
00241 widget->setLayout(layout);
00242
00243 d->browser = new QTextBrowser(this);
00244 d->browser->setHtml(labelText);
00245 layout->addWidget(d->browser);
00246
00247 d->bar = new QProgressBar(this);
00248
00249 d->bar->setVisible(false);
00250 layout->addWidget(d->bar);
00251
00252 setSizePolicy( QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding) );
00253 show();
00254 qApp->processEvents();
00255 }
00256
00257 FormProgressDialog::~FormProgressDialog()
00258 {
00259 delete d;
00260 }
00261
00262 void FormProgressDialog::setValue(int progress)
00263 {
00264 if( progress < 0 ) {
00265 if( d->bar->isVisible() ) {
00266 d->bar->setVisible(false);
00267 d->bar->setValue(0);
00268 qApp->processEvents();
00269 }
00270 return;
00271 }
00272 if( ! d->bar->isVisible() )
00273 d->bar->setVisible(true);
00274 d->bar->setValue(progress);
00275 d->update();
00276 }
00277
00278 void FormProgressDialog::setRange(int minimum, int maximum)
00279 {
00280 d->bar->setRange(minimum, maximum);
00281 }
00282
00283 void FormProgressDialog::setText(const QString& text)
00284 {
00285 d->browser->setHtml(text);
00286 d->update();
00287 }
00288
00289 void FormProgressDialog::addText(const QString& text)
00290 {
00291 QTextCursor cursor( d->browser->document()->end() );
00292 cursor.movePosition(QTextCursor::End);
00293 cursor.insertBlock();
00294 cursor.insertHtml(text);
00295 d->browser->moveCursor(QTextCursor::End);
00296 d->browser->ensureCursorVisible();
00297 d->update();
00298 }
00299
00300 void FormProgressDialog::done(int r)
00301 {
00302 if( r == Rejected && ! d->gotCanceled ) {
00303 if( KMessageBox::messageBox(this, KMessageBox::WarningContinueCancel, i18n("Abort?")) == KMessageBox::Continue ) {
00304 d->gotCanceled = true;
00305 enableButton(KDialog::Cancel, false);
00306 emit canceled();
00307 }
00308 return;
00309 }
00310 KPageDialog::done(r);
00311 }
00312
00313 int FormProgressDialog::exec()
00314 {
00315 enableButton(KDialog::Ok, true);
00316 enableButton(KDialog::Cancel, false);
00317 if( d->bar->isVisible() )
00318 d->bar->setValue( d->bar->maximum() );
00319 return KDialog::exec();
00320 }
00321
00322 bool FormProgressDialog::isCanceled()
00323 {
00324 return d->gotCanceled;
00325 }
00326
00327
00328
00329
00330
00331 namespace Kross {
00332
00334 class FormDialog::Private
00335 {
00336 public:
00337 KDialog::ButtonCode buttoncode;
00338 QHash<QString, KPageWidgetItem*> items;
00339 };
00340
00341 }
00342
00343 FormDialog::FormDialog(const QString& caption)
00344 : KPageDialog( )
00345 , d( new Private() )
00346 {
00347 setCaption(caption);
00348 KDialog::setButtons(KDialog::Ok);
00349 setSizePolicy( QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding) );
00350
00351 connect(this, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)),
00352 this, SLOT(slotCurrentPageChanged(KPageWidgetItem*)));
00353 }
00354
00355 FormDialog::~FormDialog()
00356 {
00357 kWarning()<<"dtor";
00358 delete d;
00359 }
00360
00361 bool FormDialog::setButtons(const QString& buttons)
00362 {
00363 int i = metaObject()->indexOfEnumerator("ButtonCode");
00364 Q_ASSERT( i >= 0 );
00365 QMetaEnum e = metaObject()->enumerator(i);
00366 int v = e.keysToValue( buttons.toUtf8() );
00367 if( v < 0 )
00368 return false;
00369 KDialog::setButtons( (KDialog::ButtonCode) v );
00370 return true;
00371 }
00372
00373 bool FormDialog::setButtonText(const QString& button, const QString& text)
00374 {
00375 int i = metaObject()->indexOfEnumerator("ButtonCode");
00376 Q_ASSERT( i >= 0 );
00377 QMetaEnum e = metaObject()->enumerator(i);
00378 int v = e.keysToValue( button.toUtf8() );
00379 if( v < 0 )
00380 return false;
00381 KDialog::setButtonText( (KDialog::ButtonCode) v, text);
00382 return true;
00383 }
00384
00385 bool FormDialog::setFaceType(const QString& facetype)
00386 {
00387 int i = KPageView::staticMetaObject.indexOfEnumerator("FaceType");
00388 Q_ASSERT( i >= 0 );
00389 QMetaEnum e = KPageView::staticMetaObject.enumerator(i);
00390 int v = e.keysToValue( facetype.toUtf8() );
00391 if( v < 0 )
00392 return false;
00393 KPageDialog::setFaceType( (KPageDialog::FaceType) v );
00394 return true;
00395 }
00396
00397 QString FormDialog::currentPage() const
00398 {
00399 KPageWidgetItem* item = KPageDialog::currentPage();
00400 return item ? item->name() : QString();
00401 }
00402
00403 bool FormDialog::setCurrentPage(const QString& name)
00404 {
00405 if( ! d->items.contains(name) )
00406 return false;
00407 KPageDialog::setCurrentPage( d->items[name] );
00408 return true;
00409 }
00410
00411 QWidget* FormDialog::page(const QString& name) const
00412 {
00413 return d->items.contains(name) ? d->items[name]->widget() : 0;
00414 }
00415
00416
00417 static KPageWidgetItem* formAddPage(KPageDialog* dialog, const QString& name, const QString& header, const QString& iconname)
00418 {
00419 QWidget* widget = new QWidget( dialog->mainWidget() );
00420 QVBoxLayout* boxlayout = new QVBoxLayout(widget);
00421 boxlayout->setSpacing(0);
00422 boxlayout->setMargin(0);
00423 widget->setLayout(boxlayout);
00424
00425 KPageWidgetItem* item = dialog->addPage(widget, name);
00426 item->setHeader(header.isNull() ? name : header);
00427 if( ! iconname.isEmpty() )
00428 item->setIcon( KIcon(iconname) );
00429
00430
00431 return item;
00432 }
00433
00434 QWidget* FormDialog::addPage(const QString& name, const QString& header, const QString& iconname)
00435 {
00436 return d->items.insert(name, formAddPage((KPageDialog*)this,name,header,iconname)).value()->widget();
00437 }
00438
00439 void FormDialog::setMainWidget(QWidget *newMainWidget)
00440 {
00441 KDialog::setMainWidget(newMainWidget);
00442 }
00443
00444 QString FormDialog::result()
00445 {
00446 int i = metaObject()->indexOfEnumerator("ButtonCode");
00447 if( i < 0 ) {
00448 kWarning() << "Kross::FormDialog::setButtons No such enumerator \"ButtonCode\"";
00449 return QString();
00450 }
00451 QMetaEnum e = metaObject()->enumerator(i);
00452 return e.valueToKey(d->buttoncode);
00453 }
00454
00455 void FormDialog::slotButtonClicked(int button)
00456 {
00457 d->buttoncode = (KDialog::ButtonCode) button;
00458 KDialog::slotButtonClicked(button);
00459 }
00460
00461 void FormDialog::slotCurrentPageChanged(KPageWidgetItem* current)
00462 {
00463 Q_UNUSED(current);
00464
00465
00466 }
00467
00468
00469 namespace Kross {
00471 class FormAssistant::Private
00472 {
00473 public:
00474 KDialog::ButtonCode buttoncode;
00475 QHash<QString, KPageWidgetItem*> items;
00476 };
00477 }
00478 FormAssistant::FormAssistant(const QString& caption)
00479 : KAssistantDialog( )
00480 , d( new Private() )
00481 {
00482 setCaption(caption);
00483 setSizePolicy( QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding) );
00484
00485 connect(this, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)),
00486 this, SLOT(slotCurrentPageChanged(KPageWidgetItem*)));
00487
00488
00489
00490
00491 }
00492
00493 FormAssistant::~FormAssistant()
00494 {
00495 delete d;
00496 }
00497
00498 void FormAssistant::showHelpButton(bool show)
00499 {
00500 showButton(KDialog::Help, show);
00501 }
00502
00503 void FormAssistant::back()
00504 {
00505 emit backClicked();
00506 KAssistantDialog::back();
00507 }
00508 void FormAssistant::next()
00509 {
00510 emit nextClicked();
00511 KAssistantDialog::next();
00512 }
00513
00514 QString FormAssistant::currentPage() const
00515 {
00516 KPageWidgetItem* item = KPageDialog::currentPage();
00517 return item ? item->name() : QString();
00518 }
00519
00520 bool FormAssistant::setCurrentPage(const QString& name)
00521 {
00522 if( ! d->items.contains(name) )
00523 return false;
00524 KPageDialog::setCurrentPage( d->items[name] );
00525 return true;
00526 }
00527
00528 QWidget* FormAssistant::page(const QString& name) const
00529 {
00530 return d->items.contains(name) ? d->items[name]->widget() : 0;
00531 }
00532
00533 QWidget* FormAssistant::addPage(const QString& name, const QString& header, const QString& iconname)
00534 {
00535 return d->items.insert(name, formAddPage((KPageDialog*)this,name,header,iconname)).value()->widget();
00536 }
00537
00538 bool FormAssistant::isAppropriate (const QString& name) const
00539 {
00540 return d->items.contains(name) && KAssistantDialog::isAppropriate(d->items[name]);
00541 }
00542 void FormAssistant::setAppropriate (const QString& name, bool appropriate)
00543 {
00544 if (!d->items.contains(name))
00545 return;
00546
00547 KAssistantDialog::setAppropriate(d->items[name],appropriate);
00548 }
00549 bool FormAssistant::isValid (const QString& name) const
00550 {
00551 return d->items.contains(name) && KAssistantDialog::isValid(d->items[name]);
00552 }
00553 void FormAssistant::setValid (const QString& name, bool enable)
00554 {
00555 if (!d->items.contains(name))
00556 return;
00557
00558 KAssistantDialog::setValid(d->items[name],enable);
00559 }
00560
00561 QString FormAssistant::result()
00562 {
00563 int i = metaObject()->indexOfEnumerator("AssistantButtonCode");
00564 if( i < 0 ) {
00565 kWarning() << "Kross::FormAssistant::setButtons No such enumerator \"AssistantButtonCode\"";
00566 return QString();
00567 }
00568 QMetaEnum e = metaObject()->enumerator(i);
00569 return e.valueToKey(FormAssistant::AssistantButtonCode(int(d->buttoncode)));
00570 }
00571
00572 void FormAssistant::slotButtonClicked(int button)
00573 {
00574 d->buttoncode = (KDialog::ButtonCode) button;
00575 KDialog::slotButtonClicked(button);
00576 }
00577
00578 void FormAssistant::slotCurrentPageChanged(KPageWidgetItem* current)
00579 {
00580 Q_UNUSED(current);
00581
00582
00583 }
00584
00585
00586
00587
00588
00589 namespace Kross {
00590
00592 class UiLoader : public QUiLoader
00593 {
00594 public:
00595 UiLoader() : QUiLoader() {}
00596 virtual ~UiLoader() {}
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615 };
00616
00618 class FormModule::Private
00619 {
00620 public:
00621 };
00622
00623 }
00624
00625 FormModule::FormModule()
00626 : QObject()
00627 , d( new Private() )
00628 {
00629 }
00630
00631 FormModule::~FormModule()
00632 {
00633 delete d;
00634 }
00635
00636 QWidget* FormModule::activeModalWidget()
00637 {
00638 return QApplication::activeModalWidget();
00639 }
00640
00641 QWidget* FormModule::activeWindow()
00642 {
00643 return QApplication::activeWindow();
00644 }
00645
00646 QString FormModule::showMessageBox(const QString& dialogtype, const QString& caption, const QString& message, const QString& details)
00647 {
00648 KMessageBox::DialogType type;
00649 if(dialogtype == "Error") {
00650 if( ! details.isNull() ) {
00651 KMessageBox::detailedError(0, message, details, caption);
00652 return QString();
00653 }
00654 type = KMessageBox::Error;
00655 }
00656 else if(dialogtype == "Sorry") {
00657 if( ! details.isNull() ) {
00658 KMessageBox::detailedSorry(0, message, details, caption);
00659 return QString();
00660 }
00661 type = KMessageBox::Sorry;
00662 }
00663 else if(dialogtype == "QuestionYesNo") type = KMessageBox::QuestionYesNo;
00664 else if(dialogtype == "WarningYesNo") type = KMessageBox::WarningYesNo;
00665 else if(dialogtype == "WarningContinueCancel") type = KMessageBox::WarningContinueCancel;
00666 else if(dialogtype == "WarningYesNoCancel") type = KMessageBox::WarningYesNoCancel;
00667 else if(dialogtype == "QuestionYesNoCancel") type = KMessageBox::QuestionYesNoCancel;
00668 else type = KMessageBox::Information;
00669 switch( KMessageBox::messageBox(0, type, message, caption) ) {
00670 case KMessageBox::Ok: return "Ok";
00671 case KMessageBox::Cancel: return "Cancel";
00672 case KMessageBox::Yes: return "Yes";
00673 case KMessageBox::No: return "No";
00674 case KMessageBox::Continue: return "Continue";
00675 default: break;
00676 }
00677 return QString();
00678 }
00679
00680 QWidget* FormModule::showProgressDialog(const QString& caption, const QString& labelText)
00681 {
00682 return new FormProgressDialog(caption, labelText);
00683 }
00684
00685 QWidget* FormModule::createDialog(const QString& caption)
00686 {
00687 return new FormDialog(caption);
00688 }
00689
00690 QWidget* FormModule::createAssistant(const QString& caption)
00691 {
00692 return new FormAssistant(caption);
00693 }
00694
00695 QObject* FormModule::createLayout(QWidget* parent, const QString& layout)
00696 {
00697 QLayout* l = 0;
00698 if( layout == "QVBoxLayout" )
00699 l = new QVBoxLayout();
00700 else if( layout == "QHBoxLayout" )
00701 l = new QHBoxLayout();
00702 else if( layout == "QStackedLayout" )
00703 l = new QStackedLayout();
00704 if( parent && l )
00705 parent->setLayout(l);
00706 return l;
00707 }
00708
00709 QWidget* FormModule::createWidget(const QString& className)
00710 {
00711 UiLoader loader;
00712 QWidget* widget = loader.createWidget(className);
00713 return widget;
00714 }
00715
00716 QWidget* FormModule::createWidget(QWidget* parent, const QString& className, const QString& name)
00717 {
00718 UiLoader loader;
00719 QWidget* widget = loader.createWidget(className, parent, name);
00720 if( parent && parent->layout() )
00721 parent->layout()->addWidget(widget);
00722 return widget;
00723 }
00724
00725
00726 QString FormModule::tr(const QString& str)
00727 {
00728 return QObject::tr(str.toUtf8());
00729 }
00730 QString FormModule::tr(const QString& str, const QString& comment)
00731 {
00732 return QObject::tr(str.toUtf8(),comment.toUtf8());
00733 }
00734
00735 QWidget* FormModule::createWidgetFromUI(QWidget* parent, const QString& xml)
00736 {
00737 QFormBuilder builder;
00738
00739 QDomDocument doc("mydocument");
00740 doc.setContent(xml.toUtf8());
00741
00742 QDomNodeList strings=doc.elementsByTagName("string");
00743 int i=strings.size();
00744 while(--i>=0)
00745 {
00746 QDomElement e=strings.at(i).toElement();
00747 QString i18nd=e.attribute("comment").isEmpty()?QObject::tr(e.text().toUtf8()):QObject::tr(e.text().toUtf8(),e.attribute("comment").toUtf8());
00748 if (i18nd==e.text())
00749 continue;
00750 QDomNode n = e.firstChild();
00751 while (!n.isNull())
00752 {
00753 QDomNode nn=n.nextSibling();
00754 if (n.isCharacterData())
00755 e.removeChild(n);
00756 n = nn;
00757 }
00758 e.appendChild(e.ownerDocument().createTextNode(i18nd));
00759 }
00760
00761 QByteArray ba = doc.toByteArray();
00762 QBuffer buffer(&ba);
00763 buffer.open(QIODevice::ReadOnly);
00764
00765 QWidget* widget = builder.load(&buffer, parent);
00766 if( widget && parent && parent->layout() )
00767 parent->layout()->addWidget(widget);
00768 return widget;
00769 }
00770
00771 QWidget* FormModule::createWidgetFromUIFile(QWidget* parent, const QString& filename)
00772 {
00773 QFile file(filename);
00774 if( ! file.exists() ) {
00775 kDebug() << QString("Kross::FormModule::createWidgetFromUIFile: There exists no such file \"%1\"").arg(filename);
00776 return false;
00777 }
00778 if( ! file.open(QFile::ReadOnly) ) {
00779 kDebug() << QString("Kross::FormModule::createWidgetFromUIFile: Failed to open the file \"%1\"").arg(filename);
00780 return false;
00781 }
00782 const QString xml = file.readAll();
00783 file.close();
00784 return createWidgetFromUI(parent, xml);
00785 }
00786
00787 QWidget* FormModule::createFileWidget(QWidget* parent, const QString& startDirOrVariable)
00788 {
00789 FormFileWidget* widget = new FormFileWidget(parent, startDirOrVariable);
00790 if( parent && parent->layout() )
00791 parent->layout()->addWidget(widget);
00792 return widget;
00793 }
00794
00795 QWidget* FormModule::createListView(QWidget* parent)
00796 {
00797 FormListView* widget = new FormListView(parent);
00798 if( parent && parent->layout() )
00799 parent->layout()->addWidget(widget);
00800 return widget;
00801 }
00802
00803 QAction* FormModule::createAction(QObject* parent)
00804 {
00805 return new QAction(parent);
00806 }
00807
00808 QObject* FormModule::loadPart(QWidget* parent, const QString& name, const QUrl& url)
00809 {
00810
00811 KPluginFactory* factory = KPluginLoader( name.toLatin1() ).factory();
00812 if( ! factory ) {
00813 kWarning() << QString("Kross::FormModule::loadPart: No such library \"%1\"").arg(name);
00814 return 0;
00815 }
00816 KParts::ReadOnlyPart* part = factory->create< KParts::ReadOnlyPart >( parent );
00817 if( ! part ) {
00818 kWarning() << QString("Kross::FormModule::loadPart: Library \"%1\" is not a KPart").arg(name);
00819 return 0;
00820 }
00821 if( url.isValid() )
00822 part->openUrl(url);
00823 if( parent && parent->layout() && part->widget() )
00824 parent->layout()->addWidget( part->widget() );
00825 return part;
00826 }
00827
00828 #include "form.moc"