kexi

containerfactory.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003 Lucijan Busch <lucijan@kde.org>
3 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
4 Copyright (C) 2006-2007 Jaroslaw Staniek <js@iidea.pl>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20*/
21
22#include <tqwidgetstack.h>
23#include <tqframe.h>
24#include <tqbuttongroup.h>
25#include <tqwidget.h>
26#include <tqhbox.h>
27#include <tqvbox.h>
28#include <tqstring.h>
29#include <tqpopupmenu.h>
30#include <tqdom.h>
31#include <tqevent.h>
32#include <tqobjectlist.h>
33#include <tqpainter.h>
34#include <tqvaluevector.h>
35#include <tqfileinfo.h>
36#include <tqscrollview.h>
37#include <tqtabbar.h>
38#include <tqsplitter.h>
39#include <tqlayout.h>
40
41#include <kiconloader.h>
42#include <kgenericfactory.h>
43#include <ktextedit.h>
44#include <klineedit.h>
45#include <tdelocale.h>
46#include <kdebug.h>
47
48#include "containerfactory.h"
49#include "container.h"
50#include "form.h"
51#include "formIO.h"
52#include "objecttree.h"
53#include "commands.h"
54#include "formmanager.h"
55#include "widgetlibrary.h"
56#include <formeditor/utils.h>
57#include <kinputdialog.h>
58
59ContainerWidget::ContainerWidget(TQWidget *parent, const char *name)
60 : TQWidget(parent, name)
61{
62}
63
64ContainerWidget::~ContainerWidget()
65{
66}
67
68TQSize ContainerWidget::sizeHint() const
69{
70 return TQSize(30,30); //default
71}
72
73void ContainerWidget::dragMoveEvent( TQDragMoveEvent *e )
74{
75 TQWidget::dragMoveEvent(e);
76 emit handleDragMoveEvent(e);
77}
78
79void ContainerWidget::dropEvent( TQDropEvent *e )
80{
81 TQWidget::dropEvent(e);
82 emit handleDropEvent(e);
83}
84
86
87GroupBox::GroupBox(const TQString & title, TQWidget *parent, const char *name)
88 : TQGroupBox(title, parent, name)
89{
90}
91
92GroupBox::~GroupBox()
93{
94}
95
96void GroupBox::dragMoveEvent( TQDragMoveEvent *e )
97{
98 TQGroupBox::dragMoveEvent(e);
99 emit handleDragMoveEvent(e);
100}
101
102void GroupBox::dropEvent( TQDropEvent *e )
103{
104 TQGroupBox::dropEvent(e);
105 emit handleDropEvent(e);
106}
107
109
110KFDTabWidget::KFDTabWidget(TQWidget *parent, const char *name)
111 : KFormDesigner::TabWidget(parent, name)
112{
113}
114
115KFDTabWidget::~KFDTabWidget()
116{
117}
118
119TQSize
120KFDTabWidget::sizeHint() const
121{
122 TQSize s(30,30); // default min size
123 for(int i=0; i < count(); i++)
124 s = s.expandedTo( KFormDesigner::getSizeFromChildren(page(i)) );
125
126 return s + TQSize(10/*margin*/, tabBar()->height() + 20/*margin*/);
127}
128
129void KFDTabWidget::dragMoveEvent( TQDragMoveEvent *e )
130{
131 TabWidgetBase::dragMoveEvent( e );
132 if (dynamic_cast<ContainerWidget*>(currentPage()))
133 emit dynamic_cast<ContainerWidget*>(currentPage())->handleDragMoveEvent(e);
134 emit handleDragMoveEvent(e);
135}
136
137void KFDTabWidget::dropEvent( TQDropEvent *e )
138{
139 TabWidgetBase::dropEvent( e );
140 if (dynamic_cast<ContainerWidget*>(currentPage()))
141 emit dynamic_cast<ContainerWidget*>(currentPage())->handleDropEvent(e);
142 emit handleDropEvent(e);
143}
144
146
147HBox::HBox(TQWidget *parent, const char *name)
148 : TQFrame(parent, name), m_preview(false)
149{}
150
151void
152HBox::paintEvent(TQPaintEvent *)
153{
154 if(m_preview) return;
155 TQPainter p(this);
156 p.setPen(TQPen(red, 2, TQt::DashLine));
157 p.drawRect(1, 1, width()-1, height() - 1);
158}
159
160VBox::VBox(TQWidget *parent, const char *name)
161 : TQFrame(parent, name), m_preview(false)
162{}
163
164void
165VBox::paintEvent(TQPaintEvent *)
166{
167 if(m_preview) return;
168 TQPainter p(this);
169 p.setPen(TQPen(blue, 2, TQt::DashLine));
170 p.drawRect(1, 1, width()-1, height() - 1);
171}
172
173Grid::Grid(TQWidget *parent, const char *name)
174 : TQFrame(parent, name), m_preview(false)
175{}
176
177void
178Grid::paintEvent(TQPaintEvent *)
179{
180 if(m_preview) return;
181 TQPainter p(this);
182 p.setPen(TQPen(darkGreen, 2, TQt::DashLine));
183 p.drawRect(1, 1, width()-1, height() - 1);
184}
185
186HFlow::HFlow(TQWidget *parent, const char *name)
187 : TQFrame(parent, name), m_preview(false)
188{}
189
190void
191HFlow::paintEvent(TQPaintEvent *)
192{
193 if(m_preview) return;
194 TQPainter p(this);
195 p.setPen(TQPen(magenta, 2, TQt::DashLine));
196 p.drawRect(1, 1, width()-1, height() - 1);
197}
198
199VFlow::VFlow(TQWidget *parent, const char *name)
200 : TQFrame(parent, name), m_preview(false)
201{}
202
203void
204VFlow::paintEvent(TQPaintEvent *)
205{
206 if(m_preview) return;
207 TQPainter p(this);
208 p.setPen(TQPen(cyan, 2, TQt::DashLine));
209 p.drawRect(1, 1, width()-1, height() - 1);
210}
211
212TQSize
213VFlow::sizeHint() const
214{
215 if(layout())
216 return layout()->sizeHint();
217 else
218 return TQSize(700, 50); // default
219}
220
222
223InsertPageCommand::InsertPageCommand(KFormDesigner::Container *container, TQWidget *parent)
224 : KCommand()
225{
226 m_containername = container->widget()->name();
227 m_form = container->form();
228 m_parentname = parent->name();
229 m_pageid = -1;
230}
231
232void
233InsertPageCommand::execute()
234{
235 KFormDesigner::Container *container = m_form->objectTree()->lookup(m_containername)->container();
236 TQWidget *parent = m_form->objectTree()->lookup(m_parentname)->widget();
237 if(m_name.isEmpty()) {
238 m_name = container->form()->objectTree()->generateUniqueName(
239 container->form()->library()->displayName("TQWidget").latin1(),false);
241 }
242
243 TQWidget *page = container->form()->library()->createWidget("TQWidget", parent, m_name.latin1(), container);
244// TQWidget *page = new ContainerWidget(parent, m_name.latin1());
245// new KFormDesigner::Container(container, page, parent);
246
247 TQCString classname = parent->className();
248 if(classname == "KFDTabWidget")
249 {
250 TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(parent);
251 TQString n = i18n("Page %1").arg(tab->count() + 1);
252 tab->addTab(page, n);
253 tab->showPage(page);
254
255 KFormDesigner::ObjectTreeItem *item = container->form()->objectTree()->lookup(m_name);
256 item->addModifiedProperty("title", n);
257 }
258 else if(classname == "TQWidgetStack")
259 {
260 TQWidgetStack *stack = (TQWidgetStack*)parent;
261 stack->addWidget(page, m_pageid);
262 stack->raiseWidget(page);
263 m_pageid = stack->id(page);
264
265 KFormDesigner::ObjectTreeItem *item = container->form()->objectTree()->lookup(m_name);
266 item->addModifiedProperty("id", stack->id(page));
267 }
268}
269
270void
271InsertPageCommand::unexecute()
272{
273 TQWidget *page = m_form->objectTree()->lookup(m_name)->widget();
274 TQWidget *parent = m_form->objectTree()->lookup(m_parentname)->widget();
275
277 list.append(page);
278 KCommand *com = new KFormDesigner::DeleteWidgetCommand(list, m_form);
279
280 TQCString classname = parent->className();
281 if(classname == "KFDTabWidget")
282 {
283 TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(parent);
284 tab->removePage(page);
285 }
286 else if(classname == "TQWidgetStack")
287 {
288 TQWidgetStack *stack = (TQWidgetStack*)parent;
289 int id = stack->id(page) - 1;
290 while(!stack->widget(id))
291 id--;
292
293 stack->raiseWidget(id);
294 stack->removeWidget(page);
295 }
296
297 com->execute();
298 delete com;
299}
300
301TQString
302InsertPageCommand::name() const
303{
304 return i18n("Add Page");
305}
306
308
309SubForm::SubForm(TQWidget *parent, const char *name)
310: TQScrollView(parent, name), m_form(0), m_widget(0)
311{
312 setFrameStyle(TQFrame::WinPanel | TQFrame::Sunken);
313 viewport()->setPaletteBackgroundColor(colorGroup().mid());
314}
315
316void
317SubForm::setFormName(const TQString &name)
318{
319 if(name.isEmpty())
320 return;
321
322 TQFileInfo info(name);
323 if(!info.exists()
325 && (info.fileName() == KFormDesigner::FormManager::self()->activeForm()->filename()) ) )
326 return; // we check if this is valid form
327
328 // we create the container widget
329 delete m_widget;
330 m_widget = new TQWidget(viewport(), "subform_widget");
331// m_widget->show();
332 addChild(m_widget);
333 m_form = new KFormDesigner::Form(
334 KFormDesigner::FormManager::self()->activeForm()->library(), this->name());
335 m_form->createToplevel(m_widget);
336
337 // and load the sub form
338 KFormDesigner::FormIO::loadFormFromFile(m_form, m_widget, name);
339 m_form->setDesignMode(false);
340
341 m_formName = name;
342
343}
344
346
347ContainerFactory::ContainerFactory(TQObject *parent, const char *, const TQStringList &)
348 : KFormDesigner::WidgetFactory(parent, "containers")
349{
351 wBtnGroup->setPixmap("frame");
352 wBtnGroup->setClassName("TQButtonGroup");
353 wBtnGroup->setName(i18n("Button Group"));
354 wBtnGroup->setNamePrefix(
355 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"));
356 wBtnGroup->setDescription(i18n("A simple container to group buttons"));
357 addClass(wBtnGroup);
358
360 wTabWidget->setPixmap("tabwidget");
361 wTabWidget->setClassName("KFDTabWidget");
362 wTabWidget->addAlternateClassName("KTabWidget");
363 wTabWidget->addAlternateClassName("TQTabWidget");
364//tmp: wTabWidget->setSavingName("TQTabWidget");
365 wTabWidget->setSavingName("KTabWidget");
366 wTabWidget->setIncludeFileName("ktabwidget.h");
367 wTabWidget->setName(i18n("Tab Widget"));
368 wTabWidget->setNamePrefix(
369 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"));
370 wTabWidget->setDescription(i18n("A widget to display multiple pages using tabs"));
371 addClass(wTabWidget);
372
374 wWidget->setPixmap("frame");
375 wWidget->setClassName("TQWidget");
376 wWidget->addAlternateClassName("ContainerWidget");
377 wWidget->setName(i18n("Basic container"));
378 wWidget->setNamePrefix(
379 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"));
380 wWidget->setDescription(i18n("An empty container with no frame"));
381 addClass(wWidget);
382
384 wGroupBox->setPixmap("groupbox");
385 wGroupBox->setClassName("TQGroupBox");
386 wGroupBox->addAlternateClassName("GroupBox");
387 wGroupBox->setName(i18n("Group Box"));
388 wGroupBox->setNamePrefix(
389 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"));
390 wGroupBox->setDescription(i18n("A container to group some widgets"));
391 addClass(wGroupBox);
392
394 wFrame->setPixmap("frame");
395 wFrame->setClassName("TQFrame");
396 wFrame->setName(i18n("Frame"));
397 wFrame->setNamePrefix(
398 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"));
399 wFrame->setDescription(i18n("A simple frame container"));
400 addClass(wFrame);
401
403 wWidgetStack->setPixmap("widgetstack");
404 wWidgetStack->setClassName("TQWidgetStack");
405 wWidgetStack->setName(i18n("Widget Stack"));
406 wWidgetStack->setNamePrefix(
407 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"));
408 wWidgetStack->setDescription(i18n("A container with multiple pages"));
409 addClass(wWidgetStack);
410
412 wHBox->setPixmap("frame");
413 wHBox->setClassName("HBox");
414 wHBox->setName(i18n("Horizontal Box"));
415 wHBox->setNamePrefix(
416 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"));
417 wHBox->setDescription(i18n("A simple container to group widgets horizontally"));
418 addClass(wHBox);
419
421 wVBox->setPixmap("frame");
422 wVBox->setClassName("VBox");
423 wVBox->setName(i18n("Vertical Box"));
424 wVBox->setNamePrefix(
425 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"));
426 wVBox->setDescription(i18n("A simple container to group widgets vertically"));
427 addClass(wVBox);
428
430 wGrid->setPixmap("frame");
431 wGrid->setClassName("Grid");
432 wGrid->setName(i18n("Grid Box"));
433 wGrid->setNamePrefix(
434 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"));
435 wGrid->setDescription(i18n("A simple container to group widgets in a grid"));
436 addClass(wGrid);
437
440 wSplitter->setPixmap("frame");
441 wSplitter->setClassName("Splitter");
442 wSplitter->addAlternateClassName("TQSplitter");
443 wSplitter->setName(i18n("Splitter"));
444 wSplitter->setNamePrefix(
445 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"));
446 wSplitter->setDescription(i18n("A container that enables user to resize its children"));
447 addClass(wSplitter);
448
451 wHFlow->setPixmap("frame");
452 wHFlow->setClassName("HFlow");
453 wHFlow->setName(i18n("Row Layout"));
454 wHFlow->setNamePrefix(
455 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"));
456 wHFlow->setDescription(i18n("A simple container to group widgets by rows"));
457 addClass(wHFlow);
458
461 wVFlow->setPixmap("frame");
462 wVFlow->setClassName("VFlow");
463 wVFlow->setName(i18n("Column Layout"));
464 wVFlow->setNamePrefix(
465 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"));
466 wVFlow->setDescription(i18n("A simple container to group widgets by columns"));
467 addClass(wVFlow);
468
470 wSubForm->setPixmap("form");
471 wSubForm->setClassName("SubForm");
472 wSubForm->setName(i18n("Sub Form"));
473 wSubForm->setNamePrefix(
474 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"));
475 wSubForm->setDescription(i18n("A form widget included in another Form"));
476 wSubForm->setAutoSyncForProperty( "formName", false );
477 addClass(wSubForm);
478
479 //groupbox
480 m_propDesc["title"] = i18n("Title");
481 m_propDesc["flat"] = i18n("Flat");
482
483 //tab widget
484 m_propDesc["tabPosition"] = i18n("Tab Position");
485 m_propDesc["currentPage"] = i18n("Current Page");
486 m_propDesc["tabShape"] = i18n("Tab Shape");
487
488 m_propDesc["tabPosition"] = i18n("Tab Position");
489 m_propDesc["tabPosition"] = i18n("Tab Position");
490
491 m_propValDesc["Rounded"] = i18n("for Tab Shape", "Rounded");
492 m_propValDesc["Triangular"] = i18n("for Tab Shape", "Triangular");
493}
494
495TQWidget*
496ContainerFactory::createWidget(const TQCString &c, TQWidget *p, const char *n,
497 KFormDesigner::Container *container, int options)
498{
499 if(c == "TQButtonGroup")
500 {
501 TQString text = container->form()->library()->textForWidgetName(n, c);
502 TQButtonGroup *w = new TQButtonGroup(/*i18n("Button Group")*/text, p, n);
503 new KFormDesigner::Container(container, w, container);
504 return w;
505 }
506 else if(c == "KFDTabWidget")
507 {
508 KFDTabWidget *tab = new KFDTabWidget(p, n);
509#if defined(USE_KTabWidget)
510 tab->setTabReorderingEnabled(true);
511 connect(tab, TQ_SIGNAL(movedTab(int,int)), this, TQ_SLOT(reorderTabs(int,int)));
512#endif
513 container->form()->objectTree()->addItem(container->objectTree(),
515 container->form()->library()->displayName(c), n, tab, container));
516// m_manager = container->form()->manager();
517
518 // if we are loading, don't add this tab
519 if(container->form()->interactiveMode())
520 {
521 //m_widget=tab;
522 setWidget(tab, container);
523// m_container=container;
524 addTabPage();
525 }
526
527 return tab;
528 }
529 else if(c == "TQWidget" || c=="ContainerWidget")
530 {
531 TQWidget *w = new ContainerWidget(p, n);
532 new KFormDesigner::Container(container, w, p);
533 return w;
534 }
535 else if(c == "TQGroupBox" || c == "GroupBox")
536 {
537 TQString text = container->form()->library()->textForWidgetName(n, c);
538 TQGroupBox *w = new GroupBox(text, p, n);
539 new KFormDesigner::Container(container, w, container);
540 return w;
541 }
542 else if(c == "TQFrame")
543 {
544 TQFrame *w = new TQFrame(p, n);
545 w->setLineWidth(2);
546 w->setFrameStyle(TQFrame::StyledPanel|TQFrame::Raised);
547 new KFormDesigner::Container(container, w, container);
548 return w;
549 }
550 else if(c == "TQWidgetStack")
551 {
552 TQWidgetStack *stack = new TQWidgetStack(p, n);
553 stack->setLineWidth(2);
554 stack->setFrameStyle(TQFrame::StyledPanel|TQFrame::Raised);
555 container->form()->objectTree()->addItem( container->objectTree(),
557 container->form()->library()->displayName(c), n, stack, container));
558
559 if(container->form()->interactiveMode())
560 {
561 //m_widget = stack;
562 setWidget(stack, container);
563// m_container = container;
564 addStackPage();
565 }
566 return stack;
567 }
568 else if(c == "HBox") {
569 HBox *w = new HBox(p, n);
570 new KFormDesigner::Container(container, w, container);
571 return w;
572 }
573 else if(c == "VBox") {
574 VBox *w = new VBox(p, n);
575 new KFormDesigner::Container(container, w, container);
576 return w;
577 }
578 else if(c == "Grid") {
579 Grid *w = new Grid(p, n);
580 new KFormDesigner::Container(container, w, container);
581 return w;
582 }
583 else if(c == "HFlow") {
584 HFlow *w = new HFlow(p, n);
585 new KFormDesigner::Container(container, w, container);
586 return w;
587 }
588 else if(c == "VFlow") {
589 VFlow *w = new VFlow(p, n);
590 new KFormDesigner::Container(container, w, container);
591 return w;
592 }
593 else if(c == "SubForm") {
594 SubForm *subform = new SubForm(p, n);
595 return subform;
596 }
597 else if(c == "TQSplitter") {
598 TQSplitter *split = new TQSplitter(p, n);
599 if (0 == (options & WidgetFactory::AnyOrientation))
600 split->setOrientation(
601 (options & WidgetFactory::VerticalOrientation) ? TQt::Vertical : TQt::Horizontal);
602 new KFormDesigner::Container(container, split, container);
603 return split;
604 }
605
606 return 0;
607}
608
609bool
610ContainerFactory::previewWidget(const TQCString &classname, TQWidget *widget, KFormDesigner::Container *container)
611{
612 if(classname == "WidgetStack")
613 {
614 TQWidgetStack *stack = ((TQWidgetStack*)widget);
615 KFormDesigner::ObjectTreeItem *tree = container->form()->objectTree()->lookup(widget->name());
616 if(!tree->modifiedProperties()->contains("frameShape"))
617 stack->setFrameStyle(TQFrame::NoFrame);
618 }
619 else if(classname == "HBox")
620 ((HBox*)widget)->setPreviewMode();
621 else if(classname == "VBox")
622 ((VBox*)widget)->setPreviewMode();
623 else if(classname == "Grid")
624 ((Grid*)widget)->setPreviewMode();
625 else if(classname == "HFlow")
626 ((HFlow*)widget)->setPreviewMode();
627 else if(classname == "VFlow")
628 ((VFlow*)widget)->setPreviewMode();
629 else
630 return false;
631 return true;
632}
633
634bool
635ContainerFactory::createMenuActions(const TQCString &classname, TQWidget *w, TQPopupMenu *menu,
636 KFormDesigner::Container *container)
637{
638 setWidget(w, container);
639 //m_widget = w;
640// m_container = container;
641
642 if((classname == "KFDTabWidget") || (w->parentWidget()->parentWidget()->inherits("TQTabWidget")))
643 {
644 if(w->parentWidget()->parentWidget()->inherits("TQTabWidget"))
645 {
646 //m_widget = w->parentWidget()->parentWidget();
647 setWidget(w->parentWidget()->parentWidget(), m_container->toplevel());
648// m_container = m_container->toplevel();
649 }
650
651 int id = menu->insertItem(SmallIconSet("tab_new"), i18n("Add Page"), this, TQ_SLOT(addTabPage()) );
652 id = menu->insertItem(SmallIconSet("edit"), i18n("Rename Page..."), this, TQ_SLOT(renameTabPage()));
653 id = menu->insertItem(SmallIconSet("tab_remove"), i18n("Remove Page"), this, TQ_SLOT(removeTabPage()));
654// if( dynamic_cast<TabWidgetBase*>(m_widget)->count() == 1)
655 if( dynamic_cast<TabWidgetBase*>(widget())->count() == 1)
656 menu->setItemEnabled(id, false);
657 return true;
658 }
659 else if(w->parentWidget()->isA("TQWidgetStack") && !w->parentWidget()->parentWidget()->inherits("TQTabWidget"))
660 {
661 //m_widget = w->parentWidget();
662 TQWidgetStack *stack = (TQWidgetStack*)w->parentWidget(); //m_widget;
663 setWidget(
664 w->parentWidget(),
665 container->form()->objectTree()->lookup(stack->name())->parent()->container()
666 );
667// m_container = container->form()->objectTree()->lookup(m_widget->name())->parent()->container();
668// m_container = container->form()->objectTree()->lookup(stack->name())->parent()->container();
669
670 int id = menu->insertItem(SmallIconSet("tab_new"), i18n("Add Page"), this, TQ_SLOT(addStackPage()) );
671
672 id = menu->insertItem(SmallIconSet("tab_remove"), i18n("Remove Page"), this, TQ_SLOT(removeStackPage()) );
673// if( ((TQWidgetStack*)m_widget)->children()->count() == 4) // == the stack has only one page
674 if(stack->childrenListObject().count() == 4) // == the stack has only one page
675 menu->setItemEnabled(id, false);
676
677 id = menu->insertItem(SmallIconSet("go-next"), i18n("Jump to Next Page"), this, TQ_SLOT(nextStackPage()));
678 if(!stack->widget(stack->id(stack->visibleWidget())+1))
679 menu->setItemEnabled(id, false);
680
681 id = menu->insertItem(SmallIconSet("go-previous"), i18n("Jump to Previous Page"), this, TQ_SLOT(prevStackPage()));
682 if(!stack->widget(stack->id(stack->visibleWidget()) -1) )
683 menu->setItemEnabled(id, false);
684 return true;
685 }
686 return false;
687}
688
689bool
690ContainerFactory::startEditing(const TQCString &classname, TQWidget *w, KFormDesigner::Container *container)
691{
692 m_container = container;
693 if(classname == "TQButtonGroup")
694 {
695 TQButtonGroup *group = static_cast<TQButtonGroup*>(w);
696 TQRect r = TQRect(group->x()+2, group->y()-5, group->width()-10, w->fontMetrics().height() + 10);
697 createEditor(classname, group->title(), group, container, r, TQt::AlignAuto);
698 return true;
699 }
700 if(classname == "TQGroupBox" || classname == "GroupBox")
701 {
702 TQGroupBox *group = static_cast<TQGroupBox*>(w);
703 TQRect r = TQRect(group->x()+2, group->y()-5, group->width()-10, w->fontMetrics().height() + 10);
704 createEditor(classname, group->title(), group, container, r, TQt::AlignAuto);
705 return true;
706 }
707 return false;
708}
709
710bool
711ContainerFactory::saveSpecialProperty(const TQCString &, const TQString &name, const TQVariant &, TQWidget *w, TQDomElement &parentNode, TQDomDocument &parent)
712{
713 if((name == "title") && (w->parentWidget()->parentWidget()->inherits("TQTabWidget")))
714 {
715 TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(w->parentWidget()->parentWidget());
716 KFormDesigner::FormIO::savePropertyElement(parentNode, parent, "attribute", "title", tab->tabLabel(w));
717 }
718 else if((name == "id") && (w->parentWidget()->isA("TQWidgetStack")))
719 {
720 TQWidgetStack *stack = (TQWidgetStack*)w->parentWidget();
721 KFormDesigner::FormIO::savePropertyElement(parentNode, parent, "attribute", "id", stack->id(w));
722 }
723 else
724 return false;
725 return true;
726}
727
728bool
729ContainerFactory::readSpecialProperty(const TQCString &, TQDomElement &node, TQWidget *w, KFormDesigner::ObjectTreeItem *item)
730{
731 TQString name = node.attribute("name");
732 if((name == "title") && (item->parent()->widget()->inherits("TQTabWidget")))
733 {
734 TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(w->parentWidget());
735 tab->addTab(w, node.firstChild().toElement().text());
736 item->addModifiedProperty("title", node.firstChild().toElement().text());
737 return true;
738 }
739
740 if((name == "id") && (w->parentWidget()->isA("TQWidgetStack")))
741 {
742 TQWidgetStack *stack = (TQWidgetStack*)w->parentWidget();
743 int id = KFormDesigner::FormIO::readPropertyValue(node.firstChild(), w, name).toInt();
744 stack->addWidget(w, id);
745 stack->raiseWidget(w);
746 item->addModifiedProperty("id", id);
747 return true;
748 }
749
750 return false;
751}
752
753TQValueList<TQCString>
755{
756 TQValueList<TQCString> lst;
757// if(c == "SubForm")
758// lst << "formName";
759 if(c == "TQSplitter")
760 lst << "orientation";
761 return lst;
762}
763
764bool
766 TQWidget *w, const TQCString &property, bool isTopLevel)
767{
768 bool ok = true;
769
770 if((classname == "HBox") || (classname == "VBox") || (classname == "Grid") ||
771 (classname == "HFlow") || (classname == "VFlow"))
772 {
773 return property == "name" || property == "geometry";
774 }
775 else if (classname == "TQGroupBox" || classname=="GroupBox") {
776 ok =
777#ifdef KEXI_NO_UNFINISHED
781 (m_showAdvancedProperties || (property != "checkable" && property != "checked")) &&
782#endif
783 true
784 ;
785 }
786 else if (classname == "KFDTabWidget") {
787 ok = (m_showAdvancedProperties || (property != "tabReorderingEnabled" && property != "hoverCloseButton" && property != "hoverCloseButtonDelayed"));
788 }
789
790 return ok && WidgetFactory::isPropertyVisibleInternal(classname, w, property, isTopLevel);
791}
792
793bool
794ContainerFactory::changeText(const TQString &text)
795{
796 changeProperty("title", text, m_container->form());
797 return true;
798}
799
800void
801ContainerFactory::resizeEditor(TQWidget *editor, TQWidget *widget, const TQCString &)
802{
803 TQSize s = widget->size();
804 editor->move(widget->x() + 2, widget->y() - 5);
805 editor->resize(s.width() - 20, widget->fontMetrics().height() +10);
806}
807
808// Widget Specific slots used in menu items
809
810void ContainerFactory::addTabPage()
811{
812// if (!m_widget->inherits("TQTabWidget"))
813 if (!widget()->inherits("TQTabWidget"))
814 return;
815 KCommand *com = new InsertPageCommand(m_container, widget());
816 if(dynamic_cast<TabWidgetBase*>(widget())->count() == 0)
817 {
818 com->execute();
819 delete com;
820 }
821 else
822 m_container->form()->addCommand(com, true);
823}
824
825void ContainerFactory::removeTabPage()
826{
827 if (!widget()->inherits("TQTabWidget"))
828 return;
829 TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(widget());
830 TQWidget *w = tab->currentPage();
831
833 list.append(w);
834 KCommand *com = new KFormDesigner::DeleteWidgetCommand(list, m_container->form());
835 tab->removePage(w);
836 m_container->form()->addCommand(com, true);
837}
838
839void ContainerFactory::renameTabPage()
840{
841 if (!widget()->inherits("TQTabWidget"))
842 return;
843 TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(widget());
844 TQWidget *w = tab->currentPage();
845 bool ok;
846
847 TQString name = KInputDialog::getText(i18n("New Page Title"), i18n("Enter a new title for the current page:"),
848 tab->tabLabel(w), &ok, w->topLevelWidget());
849 if(ok)
850 tab->changeTab(w, name);
851}
852
853void ContainerFactory::reorderTabs(int oldpos, int newpos)
854{
855 KFormDesigner::ObjectTreeItem *tab
857 if(!tab)
858 return;
859
860 KFormDesigner::ObjectTreeItem *item = tab->children()->take(oldpos);
861 tab->children()->insert(newpos, item);
862}
863
864void ContainerFactory::addStackPage()
865{
866 if (!widget()->isA("TQWidgetStack"))
867 return;
868 KCommand *com = new InsertPageCommand(m_container, widget());
869 if(!((TQWidgetStack*)widget())->visibleWidget())
870 {
871 com->execute();
872 delete com;
873 }
874 else
875 m_container->form()->addCommand(com, true);
876}
877
878void ContainerFactory::removeStackPage()
879{
880 if (!widget()->isA("TQWidgetStack"))
881 return;
882 TQWidgetStack *stack = (TQWidgetStack*)widget();
883 TQWidget *page = stack->visibleWidget();
884
886 list.append(page);
887 KCommand *com = new KFormDesigner::DeleteWidgetCommand(list, m_container->form());
888
889 // raise prev widget
890 int id = stack->id(page) - 1;
891 while(!stack->widget(id))
892 id--;
893 stack->raiseWidget(id);
894
895 stack->removeWidget(page);
896 m_container->form()->addCommand(com, true);
897}
898
899void ContainerFactory::prevStackPage()
900{
901 TQWidgetStack *stack = (TQWidgetStack*)widget();
902 int id = stack->id(stack->visibleWidget()) - 1;
903 if(stack->widget(id))
904 stack->raiseWidget(id);
905}
906
907void ContainerFactory::nextStackPage()
908{
909 TQWidgetStack *stack = (TQWidgetStack*)widget();
910 int id = stack->id(stack->visibleWidget()) + 1;
911 if(stack->widget(id))
912 stack->raiseWidget(id);
913}
914
915ContainerFactory::~ContainerFactory()
916{
917}
918
919KFORMDESIGNER_WIDGET_FACTORY(ContainerFactory, containers)
920
921#include "containerfactory.moc"
Standard Factory for all container widgets.
virtual TQValueList< TQCString > autoSaveProperties(const TQCString &classname)
virtual bool previewWidget(const TQCString &classname, TQWidget *widget, KFormDesigner::Container *container)
virtual bool changeText(const TQString &newText)
virtual void resizeEditor(TQWidget *editor, TQWidget *widget, const TQCString &classname)
ContainerFactory(TQObject *parent, const char *name, const TQStringList &args)
virtual bool saveSpecialProperty(const TQCString &classname, const TQString &name, const TQVariant &value, TQWidget *w, TQDomElement &parentNode, TQDomDocument &parent)
virtual bool createMenuActions(const TQCString &classname, TQWidget *w, TQPopupMenu *menu, KFormDesigner::Container *container)
virtual bool readSpecialProperty(const TQCString &classname, TQDomElement &node, TQWidget *w, KFormDesigner::ObjectTreeItem *item)
virtual bool startEditing(const TQCString &classname, TQWidget *w, KFormDesigner::Container *container)
virtual bool isPropertyVisibleInternal(const TQCString &classname, TQWidget *w, const TQCString &property, bool isTopLevel)
virtual TQWidget * createWidget(const TQCString &classname, TQWidget *parent, const char *name, KFormDesigner::Container *container, int options=DefaultOptions)
Creates a widget (and if needed a KFormDesigner::Container).
A simple container widget.
void handleDropEvent(TQDropEvent *e)
Needed to control dropping on the container's surface.
virtual void dragMoveEvent(TQDragMoveEvent *e)
Used to emit handleDragMoveEvent() signal needed to control dragging over the container's surface.
void handleDragMoveEvent(TQDragMoveEvent *e)
Needed to control dragging over the container's surface.
virtual void dropEvent(TQDropEvent *e)
Used to emit handleDropEvent() signal needed to control dropping on the container's surface.
Helper widget (used when using 'Lay out in a grid').
A group box widget.
virtual void dragMoveEvent(TQDragMoveEvent *e)
Used to emit handleDragMoveEvent() signal needed to control dragging over the container's surface.
void handleDragMoveEvent(TQDragMoveEvent *e)
Needed to control dragging over the container's surface.
void handleDropEvent(TQDropEvent *e)
Needed to control dropping on the container's surface.
virtual void dropEvent(TQDropEvent *e)
Used to emit handleDropEvent() signal needed to control dropping on the container's surface.
Helper widget (used when using 'Lay out horizontally').
HBox(TQWidget *parent, const char *name)
Various layout widgets /////////////////:
Helper widget (used when using 'Lay out with horizontal flow').
A tab widget.
void handleDropEvent(TQDropEvent *e)
Needed to control dropping on the container's surface.
virtual void dragMoveEvent(TQDragMoveEvent *e)
Used to emit handleDragMoveEvent() signal needed to control dragging over the container's surface.
virtual void dropEvent(TQDropEvent *e)
Used to emit handleDropEvent() signal needed to control dropping on the container's surface.
void handleDragMoveEvent(TQDragMoveEvent *e)
Needed to control dragging over the container's surface.
This class makes a container out of any TQWidget.
Definition container.h:74
TQWidget * widget() const
Definition container.h:94
ObjectTreeItem * objectTree() const
Definition container.h:97
Form * form() const
Definition container.h:91
static void savePropertyElement(TQDomElement &parentNode, TQDomDocument &domDoc, const TQString &tagName, const TQString &property, const TQVariant &value)
Definition formIO.cpp:728
static bool loadFormFromFile(Form *form, TQWidget *container, const TQString &filename=TQString())
Definition formIO.cpp:272
static TQVariant readPropertyValue(TQDomNode node, TQObject *obj, const TQString &name)
Definition formIO.cpp:737
static FormManager * self()
Access to FormManager singleton.
bool interactiveMode() const
Definition form.h:218
WidgetLibrary * library() const
Definition form.h:147
ObjectTree * objectTree() const
Definition form.h:167
TQString filename() const
Definition form.h:248
An item representing a widget Holds the properties of a widget (classname, name, parent,...
Definition objecttree.h:59
Container * container() const
Definition objecttree.h:76
const TQStringVariantMap * modifiedProperties() const
Definition objecttree.h:73
void addModifiedProperty(const TQCString &property, const TQVariant &oldValue)
TQCString generateUniqueName(const TQCString &prefix, bool numberSuffixRequired=true)
ObjectTreeItem * lookup(const TQString &name)
TQMap< TQCString, TQString > m_propDesc
i18n stuff
void createEditor(const TQCString &classname, const TQString &text, TQWidget *w, Container *container, TQRect geometry, int align, bool useFrame=false, bool multiLine=false, BackgroundMode background=TQt::NoBackground)
void changeProperty(const char *name, const TQVariant &value, Form *form)
This class holds properties of widget classes provided by a factory.
void setSavingName(const TQString &saveName)
void addAlternateClassName(const TQCString &alternateName, bool override=false)
void setAutoSyncForProperty(const char *propertyName, tristate flag)
void setIncludeFileName(const TQString &name)
TQWidget * createWidget(const TQCString &classname, TQWidget *parent, const char *name, Container *c, int options=WidgetFactory::DefaultOptions)
searches the right factory and creates a widget.
A form embedded as a widget inside other form.
Helper widget (used when using 'Lay out vertically').
Helper widget (used when using 'Lay out with horizontal flow').
TQPtrList< TQWidget > WidgetList
A list of widget pointers.
KFORMEDITOR_EXPORT TQSize getSizeFromChildren(TQWidget *widget, const char *inheritClass="TQWidget")