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