00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <qwidgetstack.h>
00023 #include <qframe.h>
00024 #include <qbuttongroup.h>
00025 #include <qwidget.h>
00026 #include <qhbox.h>
00027 #include <qvbox.h>
00028 #include <qstring.h>
00029 #include <qpopupmenu.h>
00030 #include <qdom.h>
00031 #include <qevent.h>
00032 #include <qobjectlist.h>
00033 #include <qpainter.h>
00034 #include <qvaluevector.h>
00035 #include <qfileinfo.h>
00036 #include <qscrollview.h>
00037 #include <qtabbar.h>
00038 #include <qsplitter.h>
00039 #include <qlayout.h>
00040
00041 #include <kiconloader.h>
00042 #include <kgenericfactory.h>
00043 #include <ktextedit.h>
00044 #include <klineedit.h>
00045 #include <klocale.h>
00046 #include <kdebug.h>
00047 #include <kdeversion.h>
00048
00049 #include "containerfactory.h"
00050 #include "container.h"
00051 #include "form.h"
00052 #include "formIO.h"
00053 #include "objecttree.h"
00054 #include "commands.h"
00055 #include "formmanager.h"
00056 #include "widgetlibrary.h"
00057 #include <formeditor/utils.h>
00058
00059 #if KDE_VERSION < KDE_MAKE_VERSION(3,1,9)
00060 # define KInputDialog QInputDialog
00061 # include <qinputdialog.h>
00062 # include <qlineedit.h>
00063 #else
00064 # include <kinputdialog.h>
00065 #endif
00066
00067 ContainerWidget::ContainerWidget(QWidget *parent, const char *name)
00068 : QWidget(parent, name)
00069 {
00070 }
00071
00072 ContainerWidget::~ContainerWidget()
00073 {
00074 }
00075
00076 QSize ContainerWidget::sizeHint() const
00077 {
00078 return QSize(30,30);
00079 }
00080
00081 void ContainerWidget::dragMoveEvent( QDragMoveEvent *e )
00082 {
00083 QWidget::dragMoveEvent(e);
00084 emit handleDragMoveEvent(e);
00085 }
00086
00087 void ContainerWidget::dropEvent( QDropEvent *e )
00088 {
00089 QWidget::dropEvent(e);
00090 emit handleDropEvent(e);
00091 }
00092
00094
00095 GroupBox::GroupBox(const QString & title, QWidget *parent, const char *name)
00096 : QGroupBox(title, parent, name)
00097 {
00098 }
00099
00100 GroupBox::~GroupBox()
00101 {
00102 }
00103
00104 void GroupBox::dragMoveEvent( QDragMoveEvent *e )
00105 {
00106 QGroupBox::dragMoveEvent(e);
00107 emit handleDragMoveEvent(e);
00108 }
00109
00110 void GroupBox::dropEvent( QDropEvent *e )
00111 {
00112 QGroupBox::dropEvent(e);
00113 emit handleDropEvent(e);
00114 }
00115
00117
00118 KFDTabWidget::KFDTabWidget(QWidget *parent, const char *name)
00119 : KFormDesigner::TabWidget(parent, name)
00120 {
00121 }
00122
00123 KFDTabWidget::~KFDTabWidget()
00124 {
00125 }
00126
00127 QSize
00128 KFDTabWidget::sizeHint() const
00129 {
00130 QSize s(30,30);
00131 for(int i=0; i < count(); i++)
00132 s = s.expandedTo( KFormDesigner::getSizeFromChildren(page(i)) );
00133
00134 return s + QSize(10, tabBar()->height() + 20);
00135 }
00136
00137 void KFDTabWidget::dragMoveEvent( QDragMoveEvent *e )
00138 {
00139 TabWidgetBase::dragMoveEvent( e );
00140 if (dynamic_cast<ContainerWidget*>(currentPage()))
00141 emit dynamic_cast<ContainerWidget*>(currentPage())->handleDragMoveEvent(e);
00142 emit handleDragMoveEvent(e);
00143 }
00144
00145 void KFDTabWidget::dropEvent( QDropEvent *e )
00146 {
00147 TabWidgetBase::dropEvent( e );
00148 if (dynamic_cast<ContainerWidget*>(currentPage()))
00149 emit dynamic_cast<ContainerWidget*>(currentPage())->handleDropEvent(e);
00150 emit handleDropEvent(e);
00151 }
00152
00154
00155 HBox::HBox(QWidget *parent, const char *name)
00156 : QFrame(parent, name), m_preview(false)
00157 {}
00158
00159 void
00160 HBox::paintEvent(QPaintEvent *)
00161 {
00162 if(m_preview) return;
00163 QPainter p(this);
00164 p.setPen(QPen(red, 2, Qt::DashLine));
00165 p.drawRect(1, 1, width()-1, height() - 1);
00166 }
00167
00168 VBox::VBox(QWidget *parent, const char *name)
00169 : QFrame(parent, name), m_preview(false)
00170 {}
00171
00172 void
00173 VBox::paintEvent(QPaintEvent *)
00174 {
00175 if(m_preview) return;
00176 QPainter p(this);
00177 p.setPen(QPen(blue, 2, Qt::DashLine));
00178 p.drawRect(1, 1, width()-1, height() - 1);
00179 }
00180
00181 Grid::Grid(QWidget *parent, const char *name)
00182 : QFrame(parent, name), m_preview(false)
00183 {}
00184
00185 void
00186 Grid::paintEvent(QPaintEvent *)
00187 {
00188 if(m_preview) return;
00189 QPainter p(this);
00190 p.setPen(QPen(darkGreen, 2, Qt::DashLine));
00191 p.drawRect(1, 1, width()-1, height() - 1);
00192 }
00193
00194 HFlow::HFlow(QWidget *parent, const char *name)
00195 : QFrame(parent, name), m_preview(false)
00196 {}
00197
00198 void
00199 HFlow::paintEvent(QPaintEvent *)
00200 {
00201 if(m_preview) return;
00202 QPainter p(this);
00203 p.setPen(QPen(magenta, 2, Qt::DashLine));
00204 p.drawRect(1, 1, width()-1, height() - 1);
00205 }
00206
00207 VFlow::VFlow(QWidget *parent, const char *name)
00208 : QFrame(parent, name), m_preview(false)
00209 {}
00210
00211 void
00212 VFlow::paintEvent(QPaintEvent *)
00213 {
00214 if(m_preview) return;
00215 QPainter p(this);
00216 p.setPen(QPen(cyan, 2, Qt::DashLine));
00217 p.drawRect(1, 1, width()-1, height() - 1);
00218 }
00219
00220 QSize
00221 VFlow::sizeHint() const
00222 {
00223 if(layout())
00224 return layout()->sizeHint();
00225 else
00226 return QSize(700, 50);
00227 }
00228
00230
00231 InsertPageCommand::InsertPageCommand(KFormDesigner::Container *container, QWidget *parent)
00232 : KCommand()
00233 {
00234 m_containername = container->widget()->name();
00235 m_form = container->form();
00236 m_parentname = parent->name();
00237 m_pageid = -1;
00238 }
00239
00240 void
00241 InsertPageCommand::execute()
00242 {
00243 KFormDesigner::Container *container = m_form->objectTree()->lookup(m_containername)->container();
00244 QWidget *parent = m_form->objectTree()->lookup(m_parentname)->widget();
00245 if(m_name.isEmpty()) {
00246 m_name = container->form()->objectTree()->generateUniqueName(
00247 container->form()->library()->displayName("QWidget").latin1(),false);
00249 }
00250
00251 QWidget *page = container->form()->library()->createWidget("QWidget", parent, m_name.latin1(), container);
00252
00253
00254
00255 QCString classname = parent->className();
00256 if(classname == "KFDTabWidget")
00257 {
00258 TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(parent);
00259 QString n = i18n("Page %1").arg(tab->count() + 1);
00260 tab->addTab(page, n);
00261 tab->showPage(page);
00262
00263 KFormDesigner::ObjectTreeItem *item = container->form()->objectTree()->lookup(m_name);
00264 item->addModifiedProperty("title", n);
00265 }
00266 else if(classname == "QWidgetStack")
00267 {
00268 QWidgetStack *stack = (QWidgetStack*)parent;
00269 stack->addWidget(page, m_pageid);
00270 stack->raiseWidget(page);
00271 m_pageid = stack->id(page);
00272
00273 KFormDesigner::ObjectTreeItem *item = container->form()->objectTree()->lookup(m_name);
00274 item->addModifiedProperty("id", stack->id(page));
00275 }
00276 }
00277
00278 void
00279 InsertPageCommand::unexecute()
00280 {
00281 QWidget *page = m_form->objectTree()->lookup(m_name)->widget();
00282 QWidget *parent = m_form->objectTree()->lookup(m_parentname)->widget();
00283
00284 KFormDesigner::WidgetList list;
00285 list.append(page);
00286 KCommand *com = new KFormDesigner::DeleteWidgetCommand(list, m_form);
00287
00288 QCString classname = parent->className();
00289 if(classname == "KFDTabWidget")
00290 {
00291 TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(parent);
00292 tab->removePage(page);
00293 }
00294 else if(classname == "QWidgetStack")
00295 {
00296 QWidgetStack *stack = (QWidgetStack*)parent;
00297 int id = stack->id(page) - 1;
00298 while(!stack->widget(id))
00299 id--;
00300
00301 stack->raiseWidget(id);
00302 stack->removeWidget(page);
00303 }
00304
00305 com->execute();
00306 delete com;
00307 }
00308
00309 QString
00310 InsertPageCommand::name() const
00311 {
00312 return i18n("Add Page");
00313 }
00314
00316
00317 SubForm::SubForm(QWidget *parent, const char *name)
00318 : QScrollView(parent, name), m_form(0), m_widget(0)
00319 {
00320 setFrameStyle(QFrame::WinPanel | QFrame::Sunken);
00321 viewport()->setPaletteBackgroundColor(colorGroup().mid());
00322 }
00323
00324 void
00325 SubForm::setFormName(const QString &name)
00326 {
00327 if(name.isEmpty())
00328 return;
00329
00330 QFileInfo info(name);
00331 if(!info.exists()
00332 || (KFormDesigner::FormManager::self()->activeForm()
00333 && (info.fileName() == KFormDesigner::FormManager::self()->activeForm()->filename()) ) )
00334 return;
00335
00336
00337 delete m_widget;
00338 m_widget = new QWidget(viewport(), "subform_widget");
00339
00340 addChild(m_widget);
00341 m_form = new KFormDesigner::Form(
00342 KFormDesigner::FormManager::self()->activeForm()->library(), this->name());
00343 m_form->createToplevel(m_widget);
00344
00345
00346 KFormDesigner::FormIO::loadFormFromFile(m_form, m_widget, name);
00347 m_form->setDesignMode(false);
00348
00349 m_formName = name;
00350
00351 }
00352
00354
00355 ContainerFactory::ContainerFactory(QObject *parent, const char *, const QStringList &)
00356 : KFormDesigner::WidgetFactory(parent, "containers")
00357 {
00358 KFormDesigner::WidgetInfo *wBtnGroup = new KFormDesigner::WidgetInfo(this);
00359 wBtnGroup->setPixmap("frame");
00360 wBtnGroup->setClassName("QButtonGroup");
00361 wBtnGroup->setName(i18n("Button Group"));
00362 wBtnGroup->setNamePrefix(
00363 i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "buttonGroup"));
00364 wBtnGroup->setDescription(i18n("A simple container to group buttons"));
00365 addClass(wBtnGroup);
00366
00367 KFormDesigner::WidgetInfo *wTabWidget = new KFormDesigner::WidgetInfo(this);
00368 wTabWidget->setPixmap("tabwidget");
00369 wTabWidget->setClassName("KFDTabWidget");
00370 #if KDE_VERSION >= KDE_MAKE_VERSION(3,1,9)
00371 wTabWidget->addAlternateClassName("KTabWidget");
00372 wTabWidget->addAlternateClassName("QTabWidget");
00373
00374 wTabWidget->setSavingName("KTabWidget");
00375 #else
00376 wTabWidget->setSavingName("QTabWidget");
00377 #endif
00378 wTabWidget->setIncludeFileName("ktabwidget.h");
00379 wTabWidget->setName(i18n("Tab Widget"));
00380 wTabWidget->setNamePrefix(
00381 i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "tabWidget"));
00382 wTabWidget->setDescription(i18n("A widget to display multiple pages using tabs"));
00383 addClass(wTabWidget);
00384
00385 KFormDesigner::WidgetInfo *wWidget = new KFormDesigner::WidgetInfo(this);
00386 wWidget->setPixmap("frame");
00387 wWidget->setClassName("QWidget");
00388 wWidget->addAlternateClassName("ContainerWidget");
00389 wWidget->setName(i18n("Basic container"));
00390 wWidget->setNamePrefix(
00391 i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "container"));
00392 wWidget->setDescription(i18n("An empty container with no frame"));
00393 addClass(wWidget);
00394
00395 KFormDesigner::WidgetInfo *wGroupBox = new KFormDesigner::WidgetInfo(this);
00396 wGroupBox->setPixmap("groupbox");
00397 wGroupBox->setClassName("QGroupBox");
00398 wGroupBox->addAlternateClassName("GroupBox");
00399 wGroupBox->setName(i18n("Group Box"));
00400 wGroupBox->setNamePrefix(
00401 i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "groupBox"));
00402 wGroupBox->setDescription(i18n("A container to group some widgets"));
00403 addClass(wGroupBox);
00404
00405 KFormDesigner::WidgetInfo *wFrame = new KFormDesigner::WidgetInfo(this);
00406 wFrame->setPixmap("frame");
00407 wFrame->setClassName("QFrame");
00408 wFrame->setName(i18n("Frame"));
00409 wFrame->setNamePrefix(
00410 i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "frame"));
00411 wFrame->setDescription(i18n("A simple frame container"));
00412 addClass(wFrame);
00413
00414 KFormDesigner::WidgetInfo *wWidgetStack = new KFormDesigner::WidgetInfo(this);
00415 wWidgetStack->setPixmap("widgetstack");
00416 wWidgetStack->setClassName("QWidgetStack");
00417 wWidgetStack->setName(i18n("Widget Stack"));
00418 wWidgetStack->setNamePrefix(
00419 i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "widgetStack"));
00420 wWidgetStack->setDescription(i18n("A container with multiple pages"));
00421 addClass(wWidgetStack);
00422
00423 KFormDesigner::WidgetInfo *wHBox = new KFormDesigner::WidgetInfo(this);
00424 wHBox->setPixmap("frame");
00425 wHBox->setClassName("HBox");
00426 wHBox->setName(i18n("Horizontal Box"));
00427 wHBox->setNamePrefix(
00428 i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "horizontalBox"));
00429 wHBox->setDescription(i18n("A simple container to group widgets horizontally"));
00430 addClass(wHBox);
00431
00432 KFormDesigner::WidgetInfo *wVBox = new KFormDesigner::WidgetInfo(this);
00433 wVBox->setPixmap("frame");
00434 wVBox->setClassName("VBox");
00435 wVBox->setName(i18n("Vertical Box"));
00436 wVBox->setNamePrefix(
00437 i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "verticalBox"));
00438 wVBox->setDescription(i18n("A simple container to group widgets vertically"));
00439 addClass(wVBox);
00440
00441 KFormDesigner::WidgetInfo *wGrid = new KFormDesigner::WidgetInfo(this);
00442 wGrid->setPixmap("frame");
00443 wGrid->setClassName("Grid");
00444 wGrid->setName(i18n("Grid Box"));
00445 wGrid->setNamePrefix(
00446 i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "gridBox"));
00447 wGrid->setDescription(i18n("A simple container to group widgets in a grid"));
00448 addClass(wGrid);
00449
00450 KFormDesigner::WidgetInfo *wSplitter = new KFormDesigner::WidgetInfo(this);
00452 wSplitter->setPixmap("frame");
00453 wSplitter->setClassName("Splitter");
00454 wSplitter->addAlternateClassName("QSplitter");
00455 wSplitter->setName(i18n("Splitter"));
00456 wSplitter->setNamePrefix(
00457 i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "splitter"));
00458 wSplitter->setDescription(i18n("A container that enables user to resize its children"));
00459 addClass(wSplitter);
00460
00461 KFormDesigner::WidgetInfo *wHFlow = new KFormDesigner::WidgetInfo(this);
00463 wHFlow->setPixmap("frame");
00464 wHFlow->setClassName("HFlow");
00465 wHFlow->setName(i18n("Row Layout"));
00466 wHFlow->setNamePrefix(
00467 i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "rowLayout"));
00468 wHFlow->setDescription(i18n("A simple container to group widgets by rows"));
00469 addClass(wHFlow);
00470
00471 KFormDesigner::WidgetInfo *wVFlow = new KFormDesigner::WidgetInfo(this);
00473 wVFlow->setPixmap("frame");
00474 wVFlow->setClassName("VFlow");
00475 wVFlow->setName(i18n("Column Layout"));
00476 wVFlow->setNamePrefix(
00477 i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "columnLayout"));
00478 wVFlow->setDescription(i18n("A simple container to group widgets by columns"));
00479 addClass(wVFlow);
00480
00481 KFormDesigner::WidgetInfo *wSubForm = new KFormDesigner::WidgetInfo(this);
00482 wSubForm->setPixmap("form");
00483 wSubForm->setClassName("SubForm");
00484 wSubForm->setName(i18n("Sub Form"));
00485 wSubForm->setNamePrefix(
00486 i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "subForm"));
00487 wSubForm->setDescription(i18n("A form widget included in another Form"));
00488 wSubForm->setAutoSyncForProperty( "formName", false );
00489 addClass(wSubForm);
00490
00491
00492 m_propDesc["title"] = i18n("Title");
00493 m_propDesc["flat"] = i18n("Flat");
00494
00495
00496 m_propDesc["tabPosition"] = i18n("Tab Position");
00497 m_propDesc["currentPage"] = i18n("Current Page");
00498 m_propDesc["tabShape"] = i18n("Tab Shape");
00499
00500 m_propDesc["tabPosition"] = i18n("Tab Position");
00501 m_propDesc["tabPosition"] = i18n("Tab Position");
00502
00503 m_propValDesc["Rounded"] = i18n("for Tab Shape", "Rounded");
00504 m_propValDesc["Triangular"] = i18n("for Tab Shape", "Triangular");
00505 }
00506
00507 QWidget*
00508 ContainerFactory::createWidget(const QCString &c, QWidget *p, const char *n,
00509 KFormDesigner::Container *container, int options)
00510 {
00511 if(c == "QButtonGroup")
00512 {
00513 QString text = container->form()->library()->textForWidgetName(n, c);
00514 QButtonGroup *w = new QButtonGroup(text, p, n);
00515 new KFormDesigner::Container(container, w, container);
00516 return w;
00517 }
00518 else if(c == "KFDTabWidget")
00519 {
00520 KFDTabWidget *tab = new KFDTabWidget(p, n);
00521 #if defined(USE_KTabWidget) && KDE_VERSION >= KDE_MAKE_VERSION(3,1,9)
00522 tab->setTabReorderingEnabled(true);
00523 connect(tab, SIGNAL(movedTab(int,int)), this, SLOT(reorderTabs(int,int)));
00524 #endif
00525 container->form()->objectTree()->addItem(container->objectTree(),
00526 new KFormDesigner::ObjectTreeItem(
00527 container->form()->library()->displayName(c), n, tab, container));
00528
00529
00530
00531 if(container->form()->interactiveMode())
00532 {
00533
00534 setWidget(tab, container);
00535
00536 addTabPage();
00537 }
00538
00539 return tab;
00540 }
00541 else if(c == "QWidget" || c=="ContainerWidget")
00542 {
00543 QWidget *w = new ContainerWidget(p, n);
00544 new KFormDesigner::Container(container, w, p);
00545 return w;
00546 }
00547 else if(c == "QGroupBox" || c == "GroupBox")
00548 {
00549 QString text = container->form()->library()->textForWidgetName(n, c);
00550 QGroupBox *w = new GroupBox(text, p, n);
00551 new KFormDesigner::Container(container, w, container);
00552 return w;
00553 }
00554 else if(c == "QFrame")
00555 {
00556 QFrame *w = new QFrame(p, n);
00557 w->setLineWidth(2);
00558 w->setFrameStyle(QFrame::StyledPanel|QFrame::Raised);
00559 new KFormDesigner::Container(container, w, container);
00560 return w;
00561 }
00562 else if(c == "QWidgetStack")
00563 {
00564 QWidgetStack *stack = new QWidgetStack(p, n);
00565 stack->setLineWidth(2);
00566 stack->setFrameStyle(QFrame::StyledPanel|QFrame::Raised);
00567 container->form()->objectTree()->addItem( container->objectTree(),
00568 new KFormDesigner::ObjectTreeItem(
00569 container->form()->library()->displayName(c), n, stack, container));
00570
00571 if(container->form()->interactiveMode())
00572 {
00573
00574 setWidget(stack, container);
00575
00576 addStackPage();
00577 }
00578 return stack;
00579 }
00580 else if(c == "HBox") {
00581 HBox *w = new HBox(p, n);
00582 new KFormDesigner::Container(container, w, container);
00583 return w;
00584 }
00585 else if(c == "VBox") {
00586 VBox *w = new VBox(p, n);
00587 new KFormDesigner::Container(container, w, container);
00588 return w;
00589 }
00590 else if(c == "Grid") {
00591 Grid *w = new Grid(p, n);
00592 new KFormDesigner::Container(container, w, container);
00593 return w;
00594 }
00595 else if(c == "HFlow") {
00596 HFlow *w = new HFlow(p, n);
00597 new KFormDesigner::Container(container, w, container);
00598 return w;
00599 }
00600 else if(c == "VFlow") {
00601 VFlow *w = new VFlow(p, n);
00602 new KFormDesigner::Container(container, w, container);
00603 return w;
00604 }
00605 else if(c == "SubForm") {
00606 SubForm *subform = new SubForm(p, n);
00607 return subform;
00608 }
00609 else if(c == "QSplitter") {
00610 QSplitter *split = new QSplitter(p, n);
00611 if (0 == (options & WidgetFactory::AnyOrientation))
00612 split->setOrientation(
00613 (options & WidgetFactory::VerticalOrientation) ? Qt::Vertical : Qt::Horizontal);
00614 new KFormDesigner::Container(container, split, container);
00615 return split;
00616 }
00617
00618 return 0;
00619 }
00620
00621 bool
00622 ContainerFactory::previewWidget(const QCString &classname, QWidget *widget, KFormDesigner::Container *container)
00623 {
00624 if(classname == "WidgetStack")
00625 {
00626 QWidgetStack *stack = ((QWidgetStack*)widget);
00627 KFormDesigner::ObjectTreeItem *tree = container->form()->objectTree()->lookup(widget->name());
00628 if(!tree->modifiedProperties()->contains("frameShape"))
00629 stack->setFrameStyle(QFrame::NoFrame);
00630 }
00631 else if(classname == "HBox")
00632 ((HBox*)widget)->setPreviewMode();
00633 else if(classname == "VBox")
00634 ((VBox*)widget)->setPreviewMode();
00635 else if(classname == "Grid")
00636 ((Grid*)widget)->setPreviewMode();
00637 else if(classname == "HFlow")
00638 ((HFlow*)widget)->setPreviewMode();
00639 else if(classname == "VFlow")
00640 ((VFlow*)widget)->setPreviewMode();
00641 else
00642 return false;
00643 return true;
00644 }
00645
00646 bool
00647 ContainerFactory::createMenuActions(const QCString &classname, QWidget *w, QPopupMenu *menu,
00648 KFormDesigner::Container *container)
00649 {
00650 setWidget(w, container);
00651
00652
00653
00654 if((classname == "KFDTabWidget") || (w->parentWidget()->parentWidget()->inherits("QTabWidget")))
00655 {
00656 if(w->parentWidget()->parentWidget()->inherits("QTabWidget"))
00657 {
00658
00659 setWidget(w->parentWidget()->parentWidget(), m_container->toplevel());
00660
00661 }
00662
00663 int id = menu->insertItem(SmallIconSet("tab_new"), i18n("Add Page"), this, SLOT(addTabPage()) );
00664 id = menu->insertItem(SmallIconSet("edit"), i18n("Rename Page..."), this, SLOT(renameTabPage()));
00665 id = menu->insertItem(SmallIconSet("tab_remove"), i18n("Remove Page"), this, SLOT(removeTabPage()));
00666
00667 if( dynamic_cast<TabWidgetBase*>(widget())->count() == 1)
00668 menu->setItemEnabled(id, false);
00669 return true;
00670 }
00671 else if(w->parentWidget()->isA("QWidgetStack") && !w->parentWidget()->parentWidget()->inherits("QTabWidget"))
00672 {
00673
00674 QWidgetStack *stack = (QWidgetStack*)w->parentWidget();
00675 setWidget(
00676 w->parentWidget(),
00677 container->form()->objectTree()->lookup(stack->name())->parent()->container()
00678 );
00679
00680
00681
00682 int id = menu->insertItem(SmallIconSet("tab_new"), i18n("Add Page"), this, SLOT(addStackPage()) );
00683
00684 id = menu->insertItem(SmallIconSet("tab_remove"), i18n("Remove Page"), this, SLOT(removeStackPage()) );
00685
00686 if(stack->children()->count() == 4)
00687 menu->setItemEnabled(id, false);
00688
00689 id = menu->insertItem(SmallIconSet("next"), i18n("Jump to Next Page"), this, SLOT(nextStackPage()));
00690 if(!stack->widget(stack->id(stack->visibleWidget())+1))
00691 menu->setItemEnabled(id, false);
00692
00693 id = menu->insertItem(SmallIconSet("previous"), i18n("Jump to Previous Page"), this, SLOT(prevStackPage()));
00694 if(!stack->widget(stack->id(stack->visibleWidget()) -1) )
00695 menu->setItemEnabled(id, false);
00696 return true;
00697 }
00698 return false;
00699 }
00700
00701 bool
00702 ContainerFactory::startEditing(const QCString &classname, QWidget *w, KFormDesigner::Container *container)
00703 {
00704 m_container = container;
00705 if(classname == "QButtonGroup")
00706 {
00707 QButtonGroup *group = static_cast<QButtonGroup*>(w);
00708 QRect r = QRect(group->x()+2, group->y()-5, group->width()-10, w->fontMetrics().height() + 10);
00709 createEditor(classname, group->title(), group, container, r, Qt::AlignAuto);
00710 return true;
00711 }
00712 if(classname == "QGroupBox" || classname == "GroupBox")
00713 {
00714 QGroupBox *group = static_cast<QGroupBox*>(w);
00715 QRect r = QRect(group->x()+2, group->y()-5, group->width()-10, w->fontMetrics().height() + 10);
00716 createEditor(classname, group->title(), group, container, r, Qt::AlignAuto);
00717 return true;
00718 }
00719 return false;
00720 }
00721
00722 bool
00723 ContainerFactory::saveSpecialProperty(const QCString &, const QString &name, const QVariant &, QWidget *w, QDomElement &parentNode, QDomDocument &parent)
00724 {
00725 if((name == "title") && (w->parentWidget()->parentWidget()->inherits("QTabWidget")))
00726 {
00727 TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(w->parentWidget()->parentWidget());
00728 KFormDesigner::FormIO::savePropertyElement(parentNode, parent, "attribute", "title", tab->tabLabel(w));
00729 }
00730 else if((name == "id") && (w->parentWidget()->isA("QWidgetStack")))
00731 {
00732 QWidgetStack *stack = (QWidgetStack*)w->parentWidget();
00733 KFormDesigner::FormIO::savePropertyElement(parentNode, parent, "attribute", "id", stack->id(w));
00734 }
00735 else
00736 return false;
00737 return true;
00738 }
00739
00740 bool
00741 ContainerFactory::readSpecialProperty(const QCString &, QDomElement &node, QWidget *w, KFormDesigner::ObjectTreeItem *item)
00742 {
00743 QString name = node.attribute("name");
00744 if((name == "title") && (item->parent()->widget()->inherits("QTabWidget")))
00745 {
00746 TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(w->parentWidget());
00747 tab->addTab(w, node.firstChild().toElement().text());
00748 item->addModifiedProperty("title", node.firstChild().toElement().text());
00749 return true;
00750 }
00751
00752 if((name == "id") && (w->parentWidget()->isA("QWidgetStack")))
00753 {
00754 QWidgetStack *stack = (QWidgetStack*)w->parentWidget();
00755 int id = KFormDesigner::FormIO::readPropertyValue(node.firstChild(), w, name).toInt();
00756 stack->addWidget(w, id);
00757 stack->raiseWidget(w);
00758 item->addModifiedProperty("id", id);
00759 return true;
00760 }
00761
00762 return false;
00763 }
00764
00765 QValueList<QCString>
00766 ContainerFactory::autoSaveProperties(const QCString &c)
00767 {
00768 QValueList<QCString> lst;
00769
00770
00771 if(c == "QSplitter")
00772 lst << "orientation";
00773 return lst;
00774 }
00775
00776 bool
00777 ContainerFactory::isPropertyVisibleInternal(const QCString &classname,
00778 QWidget *w, const QCString &property, bool isTopLevel)
00779 {
00780 bool ok = true;
00781
00782 if((classname == "HBox") || (classname == "VBox") || (classname == "Grid") ||
00783 (classname == "HFlow") || (classname == "VFlow"))
00784 {
00785 return property == "name" || property == "geometry";
00786 }
00787 else if (classname == "QGroupBox" || classname=="GroupBox") {
00788 ok =
00789 #ifdef KEXI_NO_UNFINISHED
00790
00793 (m_showAdvancedProperties || (property != "checkable" && property != "checked")) &&
00794 #endif
00795 true
00796 ;
00797 }
00798 else if (classname == "KFDTabWidget") {
00799 ok = (m_showAdvancedProperties || (property != "tabReorderingEnabled" && property != "hoverCloseButton" && property != "hoverCloseButtonDelayed"));
00800 }
00801
00802 return ok && WidgetFactory::isPropertyVisibleInternal(classname, w, property, isTopLevel);
00803 }
00804
00805 bool
00806 ContainerFactory::changeText(const QString &text)
00807 {
00808 changeProperty("title", text, m_container->form());
00809 return true;
00810 }
00811
00812 void
00813 ContainerFactory::resizeEditor(QWidget *editor, QWidget *widget, const QCString &)
00814 {
00815 QSize s = widget->size();
00816 editor->move(widget->x() + 2, widget->y() - 5);
00817 editor->resize(s.width() - 20, widget->fontMetrics().height() +10);
00818 }
00819
00820
00821
00822 void ContainerFactory::addTabPage()
00823 {
00824
00825 if (!widget()->inherits("QTabWidget"))
00826 return;
00827 KCommand *com = new InsertPageCommand(m_container, widget());
00828 if(dynamic_cast<TabWidgetBase*>(widget())->count() == 0)
00829 {
00830 com->execute();
00831 delete com;
00832 }
00833 else
00834 m_container->form()->addCommand(com, true);
00835 }
00836
00837 void ContainerFactory::removeTabPage()
00838 {
00839 if (!widget()->inherits("QTabWidget"))
00840 return;
00841 TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(widget());
00842 QWidget *w = tab->currentPage();
00843
00844 KFormDesigner::WidgetList list;
00845 list.append(w);
00846 KCommand *com = new KFormDesigner::DeleteWidgetCommand(list, m_container->form());
00847 tab->removePage(w);
00848 m_container->form()->addCommand(com, true);
00849 }
00850
00851 void ContainerFactory::renameTabPage()
00852 {
00853 if (!widget()->inherits("QTabWidget"))
00854 return;
00855 TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(widget());
00856 QWidget *w = tab->currentPage();
00857 bool ok;
00858
00859 QString name = KInputDialog::getText(i18n("New Page Title"), i18n("Enter a new title for the current page:"),
00860 #if KDE_VERSION < KDE_MAKE_VERSION(3,1,9)
00861 QLineEdit::Normal,
00862 #endif
00863 tab->tabLabel(w), &ok, w->topLevelWidget());
00864 if(ok)
00865 tab->changeTab(w, name);
00866 }
00867
00868 void ContainerFactory::reorderTabs(int oldpos, int newpos)
00869 {
00870 KFormDesigner::ObjectTreeItem *tab
00871 = KFormDesigner::FormManager::self()->activeForm()->objectTree()->lookup(sender()->name());
00872 if(!tab)
00873 return;
00874
00875 KFormDesigner::ObjectTreeItem *item = tab->children()->take(oldpos);
00876 tab->children()->insert(newpos, item);
00877 }
00878
00879 void ContainerFactory::addStackPage()
00880 {
00881 if (!widget()->isA("QWidgetStack"))
00882 return;
00883 KCommand *com = new InsertPageCommand(m_container, widget());
00884 if(!((QWidgetStack*)widget())->visibleWidget())
00885 {
00886 com->execute();
00887 delete com;
00888 }
00889 else
00890 m_container->form()->addCommand(com, true);
00891 }
00892
00893 void ContainerFactory::removeStackPage()
00894 {
00895 if (!widget()->isA("QWidgetStack"))
00896 return;
00897 QWidgetStack *stack = (QWidgetStack*)widget();
00898 QWidget *page = stack->visibleWidget();
00899
00900 KFormDesigner::WidgetList list;
00901 list.append(page);
00902 KCommand *com = new KFormDesigner::DeleteWidgetCommand(list, m_container->form());
00903
00904
00905 int id = stack->id(page) - 1;
00906 while(!stack->widget(id))
00907 id--;
00908 stack->raiseWidget(id);
00909
00910 stack->removeWidget(page);
00911 m_container->form()->addCommand(com, true);
00912 }
00913
00914 void ContainerFactory::prevStackPage()
00915 {
00916 QWidgetStack *stack = (QWidgetStack*)widget();
00917 int id = stack->id(stack->visibleWidget()) - 1;
00918 if(stack->widget(id))
00919 stack->raiseWidget(id);
00920 }
00921
00922 void ContainerFactory::nextStackPage()
00923 {
00924 QWidgetStack *stack = (QWidgetStack*)widget();
00925 int id = stack->id(stack->visibleWidget()) + 1;
00926 if(stack->widget(id))
00927 stack->raiseWidget(id);
00928 }
00929
00930 ContainerFactory::~ContainerFactory()
00931 {
00932 }
00933
00934 KFORMDESIGNER_WIDGET_FACTORY(ContainerFactory, containers)
00935
00936 #include "containerfactory.moc"