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#include <tdeversion.h>
48
49#include "containerfactory.h"
50#include "container.h"
51#include "form.h"
52#include "formIO.h"
53#include "objecttree.h"
54#include "commands.h"
55#include "formmanager.h"
56#include "widgetlibrary.h"
57#include <formeditor/utils.h>
58
59#if TDE_VERSION < TDE_MAKE_VERSION(3,1,9)
60# define KInputDialog TQInputDialog
61# include <tqinputdialog.h>
62# include <tqlineedit.h>
63#else
64# include <kinputdialog.h>
65#endif
66
67ContainerWidget::ContainerWidget(TQWidget *parent, const char *name)
68 : TQWidget(parent, name)
69{
70}
71
72ContainerWidget::~ContainerWidget()
73{
74}
75
76TQSize ContainerWidget::sizeHint() const
77{
78 return TQSize(30,30); //default
79}
80
81void ContainerWidget::dragMoveEvent( TQDragMoveEvent *e )
82{
83 TQWidget::dragMoveEvent(e);
84 emit handleDragMoveEvent(e);
85}
86
87void ContainerWidget::dropEvent( TQDropEvent *e )
88{
89 TQWidget::dropEvent(e);
90 emit handleDropEvent(e);
91}
92
94
95GroupBox::GroupBox(const TQString & title, TQWidget *parent, const char *name)
96 : TQGroupBox(title, parent, name)
97{
98}
99
100GroupBox::~GroupBox()
101{
102}
103
104void GroupBox::dragMoveEvent( TQDragMoveEvent *e )
105{
106 TQGroupBox::dragMoveEvent(e);
107 emit handleDragMoveEvent(e);
108}
109
110void GroupBox::dropEvent( TQDropEvent *e )
111{
112 TQGroupBox::dropEvent(e);
113 emit handleDropEvent(e);
114}
115
117
118KFDTabWidget::KFDTabWidget(TQWidget *parent, const char *name)
119 : KFormDesigner::TabWidget(parent, name)
120{
121}
122
123KFDTabWidget::~KFDTabWidget()
124{
125}
126
127TQSize
128KFDTabWidget::sizeHint() const
129{
130 TQSize s(30,30); // default min size
131 for(int i=0; i < count(); i++)
132 s = s.expandedTo( KFormDesigner::getSizeFromChildren(page(i)) );
133
134 return s + TQSize(10/*margin*/, tabBar()->height() + 20/*margin*/);
135}
136
137void KFDTabWidget::dragMoveEvent( TQDragMoveEvent *e )
138{
139 TabWidgetBase::dragMoveEvent( e );
140 if (dynamic_cast<ContainerWidget*>(currentPage()))
141 emit dynamic_cast<ContainerWidget*>(currentPage())->handleDragMoveEvent(e);
142 emit handleDragMoveEvent(e);
143}
144
145void KFDTabWidget::dropEvent( TQDropEvent *e )
146{
147 TabWidgetBase::dropEvent( e );
148 if (dynamic_cast<ContainerWidget*>(currentPage()))
149 emit dynamic_cast<ContainerWidget*>(currentPage())->handleDropEvent(e);
150 emit handleDropEvent(e);
151}
152
154
155HBox::HBox(TQWidget *parent, const char *name)
156 : TQFrame(parent, name), m_preview(false)
157{}
158
159void
160HBox::paintEvent(TQPaintEvent *)
161{
162 if(m_preview) return;
163 TQPainter p(this);
164 p.setPen(TQPen(red, 2, TQt::DashLine));
165 p.drawRect(1, 1, width()-1, height() - 1);
166}
167
168VBox::VBox(TQWidget *parent, const char *name)
169 : TQFrame(parent, name), m_preview(false)
170{}
171
172void
173VBox::paintEvent(TQPaintEvent *)
174{
175 if(m_preview) return;
176 TQPainter p(this);
177 p.setPen(TQPen(blue, 2, TQt::DashLine));
178 p.drawRect(1, 1, width()-1, height() - 1);
179}
180
181Grid::Grid(TQWidget *parent, const char *name)
182 : TQFrame(parent, name), m_preview(false)
183{}
184
185void
186Grid::paintEvent(TQPaintEvent *)
187{
188 if(m_preview) return;
189 TQPainter p(this);
190 p.setPen(TQPen(darkGreen, 2, TQt::DashLine));
191 p.drawRect(1, 1, width()-1, height() - 1);
192}
193
194HFlow::HFlow(TQWidget *parent, const char *name)
195 : TQFrame(parent, name), m_preview(false)
196{}
197
198void
199HFlow::paintEvent(TQPaintEvent *)
200{
201 if(m_preview) return;
202 TQPainter p(this);
203 p.setPen(TQPen(magenta, 2, TQt::DashLine));
204 p.drawRect(1, 1, width()-1, height() - 1);
205}
206
207VFlow::VFlow(TQWidget *parent, const char *name)
208 : TQFrame(parent, name), m_preview(false)
209{}
210
211void
212VFlow::paintEvent(TQPaintEvent *)
213{
214 if(m_preview) return;
215 TQPainter p(this);
216 p.setPen(TQPen(cyan, 2, TQt::DashLine));
217 p.drawRect(1, 1, width()-1, height() - 1);
218}
219
220TQSize
221VFlow::sizeHint() const
222{
223 if(layout())
224 return layout()->sizeHint();
225 else
226 return TQSize(700, 50); // default
227}
228
230
231InsertPageCommand::InsertPageCommand(KFormDesigner::Container *container, TQWidget *parent)
232 : KCommand()
233{
234 m_containername = container->widget()->name();
235 m_form = container->form();
236 m_parentname = parent->name();
237 m_pageid = -1;
238}
239
240void
241InsertPageCommand::execute()
242{
243 KFormDesigner::Container *container = m_form->objectTree()->lookup(m_containername)->container();
244 TQWidget *parent = m_form->objectTree()->lookup(m_parentname)->widget();
245 if(m_name.isEmpty()) {
246 m_name = container->form()->objectTree()->generateUniqueName(
247 container->form()->library()->displayName("TQWidget").latin1(),
false);
249 }
250
251 TQWidget *page = container->form()->library()->createWidget("TQWidget", parent, m_name.latin1(), container);
252// TQWidget *page = new ContainerWidget(parent, m_name.latin1());
253// new KFormDesigner::Container(container, page, parent);
254
255 TQCString classname = parent->className();
256 if(classname == "KFDTabWidget")
257 {
258 TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(parent);
259 TQString n = i18n("Page %1").arg(tab->count() + 1);
260 tab->addTab(page, n);
261 tab->showPage(page);
262
263 KFormDesigner::ObjectTreeItem *item = container->form()->objectTree()->lookup(m_name);
264 item->addModifiedProperty("title", n);
265 }
266 else if(classname == "TQWidgetStack")
267 {
268 TQWidgetStack *stack = (TQWidgetStack*)parent;
269 stack->addWidget(page, m_pageid);
270 stack->raiseWidget(page);
271 m_pageid = stack->id(page);
272
273 KFormDesigner::ObjectTreeItem *item = container->form()->objectTree()->lookup(m_name);
274 item->addModifiedProperty("id", stack->id(page));
275 }
276}
277
278void
279InsertPageCommand::unexecute()
280{
281 TQWidget *page = m_form->objectTree()->lookup(m_name)->widget();
282 TQWidget *parent = m_form->objectTree()->lookup(m_parentname)->widget();
283
285 list.append(page);
286 KCommand *com = new KFormDesigner::DeleteWidgetCommand(list, m_form);
287
288 TQCString classname = parent->className();
289 if(classname == "KFDTabWidget")
290 {
291 TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(parent);
292 tab->removePage(page);
293 }
294 else if(classname == "TQWidgetStack")
295 {
296 TQWidgetStack *stack = (TQWidgetStack*)parent;
297 int id = stack->id(page) - 1;
298 while(!stack->widget(id))
299 id--;
300
301 stack->raiseWidget(id);
302 stack->removeWidget(page);
303 }
304
305 com->execute();
306 delete com;
307}
308
309TQString
310InsertPageCommand::name() const
311{
312 return i18n("Add Page");
313}
314
316
317SubForm::SubForm(TQWidget *parent, const char *name)
318: TQScrollView(parent, name), m_form(0), m_widget(0)
319{
320 setFrameStyle(TQFrame::WinPanel | TQFrame::Sunken);
321 viewport()->setPaletteBackgroundColor(colorGroup().mid());
322}
323
324void
325SubForm::setFormName(const TQString &name)
326{
327 if(name.isEmpty())
328 return;
329
330 TQFileInfo info(name);
331 if(!info.exists()
333 && (info.fileName() == KFormDesigner::FormManager::self()->activeForm()->filename()) ) )
334 return; // we check if this is valid form
335
336 // we create the container widget
337 delete m_widget;
338 m_widget = new TQWidget(viewport(), "subform_widget");
339// m_widget->show();
340 addChild(m_widget);
341 m_form = new KFormDesigner::Form(
342 KFormDesigner::FormManager::self()->activeForm()->library(), this->name());
343 m_form->createToplevel(m_widget);
344
345 // and load the sub form
346 KFormDesigner::FormIO::loadFormFromFile(m_form, m_widget, name);
347 m_form->setDesignMode(false);
348
349 m_formName = name;
350
351}
352
354
355ContainerFactory::ContainerFactory(TQObject *parent, const char *, const TQStringList &)
356 : KFormDesigner::WidgetFactory(parent, "containers")
357{
359 wBtnGroup->setPixmap("frame");
360 wBtnGroup->setClassName("TQButtonGroup");
361 wBtnGroup->setName(i18n("Button Group"));
362 wBtnGroup->setNamePrefix(
363 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"));
364 wBtnGroup->setDescription(i18n("A simple container to group buttons"));
365 addClass(wBtnGroup);
366
368 wTabWidget->setPixmap("tabwidget");
369 wTabWidget->setClassName("KFDTabWidget");
370#if TDE_VERSION >= TDE_MAKE_VERSION(3,1,9)
371 wTabWidget->addAlternateClassName("KTabWidget");
372 wTabWidget->addAlternateClassName("TQTabWidget");
373//tmp: wTabWidget->setSavingName("TQTabWidget");
374 wTabWidget->setSavingName("KTabWidget");
375#else
376 wTabWidget->setSavingName("TQTabWidget");
377#endif
378 wTabWidget->setIncludeFileName("ktabwidget.h");
379 wTabWidget->setName(i18n("Tab Widget"));
380 wTabWidget->setNamePrefix(
381 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"));
382 wTabWidget->setDescription(i18n("A widget to display multiple pages using tabs"));
383 addClass(wTabWidget);
384
386 wWidget->setPixmap("frame");
387 wWidget->setClassName("TQWidget");
388 wWidget->addAlternateClassName("ContainerWidget");
389 wWidget->setName(i18n("Basic container"));
390 wWidget->setNamePrefix(
391 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"));
392 wWidget->setDescription(i18n("An empty container with no frame"));
393 addClass(wWidget);
394
396 wGroupBox->setPixmap("groupbox");
397 wGroupBox->setClassName("TQGroupBox");
398 wGroupBox->addAlternateClassName("GroupBox");
399 wGroupBox->setName(i18n("Group Box"));
400 wGroupBox->setNamePrefix(
401 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"));
402 wGroupBox->setDescription(i18n("A container to group some widgets"));
403 addClass(wGroupBox);
404
406 wFrame->setPixmap("frame");
407 wFrame->setClassName("TQFrame");
408 wFrame->setName(i18n("Frame"));
409 wFrame->setNamePrefix(
410 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"));
411 wFrame->setDescription(i18n("A simple frame container"));
412 addClass(wFrame);
413
415 wWidgetStack->setPixmap("widgetstack");
416 wWidgetStack->setClassName("TQWidgetStack");
417 wWidgetStack->setName(i18n("Widget Stack"));
418 wWidgetStack->setNamePrefix(
419 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"));
420 wWidgetStack->setDescription(i18n("A container with multiple pages"));
421 addClass(wWidgetStack);
422
424 wHBox->setPixmap("frame");
425 wHBox->setClassName("HBox");
426 wHBox->setName(i18n("Horizontal Box"));
427 wHBox->setNamePrefix(
428 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"));
429 wHBox->setDescription(i18n("A simple container to group widgets horizontally"));
430 addClass(wHBox);
431
433 wVBox->setPixmap("frame");
434 wVBox->setClassName("VBox");
435 wVBox->setName(i18n("Vertical Box"));
436 wVBox->setNamePrefix(
437 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"));
438 wVBox->setDescription(i18n("A simple container to group widgets vertically"));
439 addClass(wVBox);
440
442 wGrid->setPixmap("frame");
443 wGrid->setClassName("Grid");
444 wGrid->setName(i18n("Grid Box"));
445 wGrid->setNamePrefix(
446 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"));
447 wGrid->setDescription(i18n("A simple container to group widgets in a grid"));
448 addClass(wGrid);
449
452 wSplitter->setPixmap("frame");
453 wSplitter->setClassName("Splitter");
454 wSplitter->addAlternateClassName("TQSplitter");
455 wSplitter->setName(i18n("Splitter"));
456 wSplitter->setNamePrefix(
457 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"));
458 wSplitter->setDescription(i18n("A container that enables user to resize its children"));
459 addClass(wSplitter);
460
463 wHFlow->setPixmap("frame");
464 wHFlow->setClassName("HFlow");
465 wHFlow->setName(i18n("Row Layout"));
466 wHFlow->setNamePrefix(
467 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"));
468 wHFlow->setDescription(i18n("A simple container to group widgets by rows"));
469 addClass(wHFlow);
470
473 wVFlow->setPixmap("frame");
474 wVFlow->setClassName("VFlow");
475 wVFlow->setName(i18n("Column Layout"));
476 wVFlow->setNamePrefix(
477 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"));
478 wVFlow->setDescription(i18n("A simple container to group widgets by columns"));
479 addClass(wVFlow);
480
482 wSubForm->setPixmap("form");
483 wSubForm->setClassName("SubForm");
484 wSubForm->setName(i18n("Sub Form"));
485 wSubForm->setNamePrefix(
486 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"));
487 wSubForm->setDescription(i18n("A form widget included in another Form"));
488 wSubForm->setAutoSyncForProperty( "formName", false );
489 addClass(wSubForm);
490
491 //groupbox
492 m_propDesc["title"] = i18n("Title");
493 m_propDesc["flat"] = i18n("Flat");
494
495 //tab widget
496 m_propDesc["tabPosition"] = i18n("Tab Position");
497 m_propDesc["currentPage"] = i18n("Current Page");
498 m_propDesc["tabShape"] = i18n("Tab Shape");
499
500 m_propDesc["tabPosition"] = i18n("Tab Position");
501 m_propDesc["tabPosition"] = i18n("Tab Position");
502
503 m_propValDesc["Rounded"] = i18n("for Tab Shape", "Rounded");
504 m_propValDesc["Triangular"] = i18n("for Tab Shape", "Triangular");
505}
506
507TQWidget*
508ContainerFactory::createWidget(const TQCString &c, TQWidget *p, const char *n,
509 KFormDesigner::Container *container, int options)
510{
511 if(c == "TQButtonGroup")
512 {
513 TQString text = container->form()->library()->textForWidgetName(n, c);
514 TQButtonGroup *w = new TQButtonGroup(/*i18n("Button Group")*/text, p, n);
515 new KFormDesigner::Container(container, w, container);
516 return w;
517 }
518 else if(c == "KFDTabWidget")
519 {
520 KFDTabWidget *tab = new KFDTabWidget(p, n);
521#if defined(USE_KTabWidget) && TDE_VERSION >= TDE_MAKE_VERSION(3,1,9)
522 tab->setTabReorderingEnabled(true);
523 connect(tab, TQ_SIGNAL(movedTab(int,int)), this, TQ_SLOT(reorderTabs(int,int)));
524#endif
525 container->form()->objectTree()->addItem(container->objectTree(),
527 container->form()->library()->displayName(c), n, tab, container));
528// m_manager = container->form()->manager();
529
530 // if we are loading, don't add this tab
531 if(container->form()->interactiveMode())
532 {
533 //m_widget=tab;
534 setWidget(tab, container);
535// m_container=container;
536 addTabPage();
537 }
538
539 return tab;
540 }
541 else if(c == "TQWidget" || c=="ContainerWidget")
542 {
543 TQWidget *w = new ContainerWidget(p, n);
544 new KFormDesigner::Container(container, w, p);
545 return w;
546 }
547 else if(c == "TQGroupBox" || c == "GroupBox")
548 {
549 TQString text = container->form()->library()->textForWidgetName(n, c);
550 TQGroupBox *w = new GroupBox(text, p, n);
551 new KFormDesigner::Container(container, w, container);
552 return w;
553 }
554 else if(c == "TQFrame")
555 {
556 TQFrame *w = new TQFrame(p, n);
557 w->setLineWidth(2);
558 w->setFrameStyle(TQFrame::StyledPanel|TQFrame::Raised);
559 new KFormDesigner::Container(container, w, container);
560 return w;
561 }
562 else if(c == "TQWidgetStack")
563 {
564 TQWidgetStack *stack = new TQWidgetStack(p, n);
565 stack->setLineWidth(2);
566 stack->setFrameStyle(TQFrame::StyledPanel|TQFrame::Raised);
567 container->form()->objectTree()->addItem( container->objectTree(),
569 container->form()->library()->displayName(c), n, stack, container));
570
571 if(container->form()->interactiveMode())
572 {
573 //m_widget = stack;
574 setWidget(stack, container);
575// m_container = container;
576 addStackPage();
577 }
578 return stack;
579 }
580 else if(c == "HBox") {
581 HBox *w = new HBox(p, n);
582 new KFormDesigner::Container(container, w, container);
583 return w;
584 }
585 else if(c == "VBox") {
586 VBox *w = new VBox(p, n);
587 new KFormDesigner::Container(container, w, container);
588 return w;
589 }
590 else if(c == "Grid") {
591 Grid *w = new Grid(p, n);
592 new KFormDesigner::Container(container, w, container);
593 return w;
594 }
595 else if(c == "HFlow") {
596 HFlow *w = new HFlow(p, n);
597 new KFormDesigner::Container(container, w, container);
598 return w;
599 }
600 else if(c == "VFlow") {
601 VFlow *w = new VFlow(p, n);
602 new KFormDesigner::Container(container, w, container);
603 return w;
604 }
605 else if(c == "SubForm") {
606 SubForm *subform = new SubForm(p, n);
607 return subform;
608 }
609 else if(c == "TQSplitter") {
610 TQSplitter *split = new TQSplitter(p, n);
611 if (0 == (options & WidgetFactory::AnyOrientation))
612 split->setOrientation(
613 (options & WidgetFactory::VerticalOrientation) ? TQt::Vertical : TQt::Horizontal);
614 new KFormDesigner::Container(container, split, container);
615 return split;
616 }
617
618 return 0;
619}
620
621bool
622ContainerFactory::previewWidget(const TQCString &classname, TQWidget *widget, KFormDesigner::Container *container)
623{
624 if(classname == "WidgetStack")
625 {
626 TQWidgetStack *stack = ((TQWidgetStack*)widget);
627 KFormDesigner::ObjectTreeItem *tree = container->form()->objectTree()->lookup(widget->name());
628 if(!tree->modifiedProperties()->contains("frameShape"))
629 stack->setFrameStyle(TQFrame::NoFrame);
630 }
631 else if(classname == "HBox")
632 ((HBox*)widget)->setPreviewMode();
633 else if(classname == "VBox")
634 ((VBox*)widget)->setPreviewMode();
635 else if(classname == "Grid")
636 ((Grid*)widget)->setPreviewMode();
637 else if(classname == "HFlow")
638 ((HFlow*)widget)->setPreviewMode();
639 else if(classname == "VFlow")
640 ((VFlow*)widget)->setPreviewMode();
641 else
642 return false;
643 return true;
644}
645
646bool
647ContainerFactory::createMenuActions(const TQCString &classname, TQWidget *w, TQPopupMenu *menu,
648 KFormDesigner::Container *container)
649{
650 setWidget(w, container);
651 //m_widget = w;
652// m_container = container;
653
654 if((classname == "KFDTabWidget") || (w->parentWidget()->parentWidget()->inherits("TQTabWidget")))
655 {
656 if(w->parentWidget()->parentWidget()->inherits("TQTabWidget"))
657 {
658 //m_widget = w->parentWidget()->parentWidget();
659 setWidget(w->parentWidget()->parentWidget(), m_container->toplevel());
660// m_container = m_container->toplevel();
661 }
662
663 int id = menu->insertItem(SmallIconSet("tab_new"), i18n("Add Page"), this, TQ_SLOT(addTabPage()) );
664 id = menu->insertItem(SmallIconSet("edit"), i18n("Rename Page..."), this, TQ_SLOT(renameTabPage()));
665 id = menu->insertItem(SmallIconSet("tab_remove"), i18n("Remove Page"), this, TQ_SLOT(removeTabPage()));
666// if( dynamic_cast<TabWidgetBase*>(m_widget)->count() == 1)
667 if( dynamic_cast<TabWidgetBase*>(widget())->count() == 1)
668 menu->setItemEnabled(id, false);
669 return true;
670 }
671 else if(w->parentWidget()->isA("TQWidgetStack") && !w->parentWidget()->parentWidget()->inherits("TQTabWidget"))
672 {
673 //m_widget = w->parentWidget();
674 TQWidgetStack *stack = (TQWidgetStack*)w->parentWidget(); //m_widget;
675 setWidget(
676 w->parentWidget(),
677 container->form()->objectTree()->lookup(stack->name())->parent()->container()
678 );
679// m_container = container->form()->objectTree()->lookup(m_widget->name())->parent()->container();
680// m_container = container->form()->objectTree()->lookup(stack->name())->parent()->container();
681
682 int id = menu->insertItem(SmallIconSet("tab_new"), i18n("Add Page"), this, TQ_SLOT(addStackPage()) );
683
684 id = menu->insertItem(SmallIconSet("tab_remove"), i18n("Remove Page"), this, TQ_SLOT(removeStackPage()) );
685// if( ((TQWidgetStack*)m_widget)->children()->count() == 4) // == the stack has only one page
686 if(stack->childrenListObject().count() == 4) // == the stack has only one page
687 menu->setItemEnabled(id, false);
688
689 id = menu->insertItem(SmallIconSet("go-next"), i18n("Jump to Next Page"), this, TQ_SLOT(nextStackPage()));
690 if(!stack->widget(stack->id(stack->visibleWidget())+1))
691 menu->setItemEnabled(id, false);
692
693 id = menu->insertItem(SmallIconSet("go-previous"), i18n("Jump to Previous Page"), this, TQ_SLOT(prevStackPage()));
694 if(!stack->widget(stack->id(stack->visibleWidget()) -1) )
695 menu->setItemEnabled(id, false);
696 return true;
697 }
698 return false;
699}
700
701bool
702ContainerFactory::startEditing(const TQCString &classname, TQWidget *w, KFormDesigner::Container *container)
703{
704 m_container = container;
705 if(classname == "TQButtonGroup")
706 {
707 TQButtonGroup *group = static_cast<TQButtonGroup*>(w);
708 TQRect r = TQRect(group->x()+2, group->y()-5, group->width()-10, w->fontMetrics().height() + 10);
709 createEditor(classname, group->title(), group, container, r, TQt::AlignAuto);
710 return true;
711 }
712 if(classname == "TQGroupBox" || classname == "GroupBox")
713 {
714 TQGroupBox *group = static_cast<TQGroupBox*>(w);
715 TQRect r = TQRect(group->x()+2, group->y()-5, group->width()-10, w->fontMetrics().height() + 10);
716 createEditor(classname, group->title(), group, container, r, TQt::AlignAuto);
717 return true;
718 }
719 return false;
720}
721
722bool
723ContainerFactory::saveSpecialProperty(const TQCString &, const TQString &name, const TQVariant &, TQWidget *w, TQDomElement &parentNode, TQDomDocument &parent)
724{
725 if((name == "title") && (w->parentWidget()->parentWidget()->inherits("TQTabWidget")))
726 {
727 TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(w->parentWidget()->parentWidget());
728 KFormDesigner::FormIO::savePropertyElement(parentNode, parent, "attribute", "title", tab->tabLabel(w));
729 }
730 else if((name == "id") && (w->parentWidget()->isA("TQWidgetStack")))
731 {
732 TQWidgetStack *stack = (TQWidgetStack*)w->parentWidget();
733 KFormDesigner::FormIO::savePropertyElement(parentNode, parent, "attribute", "id", stack->id(w));
734 }
735 else
736 return false;
737 return true;
738}
739
740bool
741ContainerFactory::readSpecialProperty(const TQCString &, TQDomElement &node, TQWidget *w, KFormDesigner::ObjectTreeItem *item)
742{
743 TQString name = node.attribute("name");
744 if((name == "title") && (item->parent()->widget()->inherits("TQTabWidget")))
745 {
746 TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(w->parentWidget());
747 tab->addTab(w, node.firstChild().toElement().text());
748 item->addModifiedProperty("title", node.firstChild().toElement().text());
749 return true;
750 }
751
752 if((name == "id") && (w->parentWidget()->isA("TQWidgetStack")))
753 {
754 TQWidgetStack *stack = (TQWidgetStack*)w->parentWidget();
755 int id = KFormDesigner::FormIO::readPropertyValue(node.firstChild(), w, name).toInt();
756 stack->addWidget(w, id);
757 stack->raiseWidget(w);
758 item->addModifiedProperty("id", id);
759 return true;
760 }
761
762 return false;
763}
764
765TQValueList<TQCString>
767{
768 TQValueList<TQCString> lst;
769// if(c == "SubForm")
770// lst << "formName";
771 if(c == "TQSplitter")
772 lst << "orientation";
773 return lst;
774}
775
776bool
778 TQWidget *w, const TQCString &property, bool isTopLevel)
779{
780 bool ok = true;
781
782 if((classname == "HBox") || (classname == "VBox") || (classname == "Grid") ||
783 (classname == "HFlow") || (classname == "VFlow"))
784 {
785 return property == "name" || property == "geometry";
786 }
787 else if (classname == "TQGroupBox" || classname=="GroupBox") {
788 ok =
789#ifdef KEXI_NO_UNFINISHED
793 (m_showAdvancedProperties || (property != "checkable" && property != "checked")) &&
794#endif
795 true
796 ;
797 }
798 else if (classname == "KFDTabWidget") {
799 ok = (m_showAdvancedProperties || (property != "tabReorderingEnabled" && property != "hoverCloseButton" && property != "hoverCloseButtonDelayed"));
800 }
801
802 return ok && WidgetFactory::isPropertyVisibleInternal(classname, w, property, isTopLevel);
803}
804
805bool
806ContainerFactory::changeText(const TQString &text)
807{
808 changeProperty("title", text, m_container->form());
809 return true;
810}
811
812void
813ContainerFactory::resizeEditor(TQWidget *editor, TQWidget *widget, const TQCString &)
814{
815 TQSize s = widget->size();
816 editor->move(widget->x() + 2, widget->y() - 5);
817 editor->resize(s.width() - 20, widget->fontMetrics().height() +10);
818}
819
820// Widget Specific slots used in menu items
821
822void ContainerFactory::addTabPage()
823{
824// if (!m_widget->inherits("TQTabWidget"))
825 if (!widget()->inherits("TQTabWidget"))
826 return;
827 KCommand *com = new InsertPageCommand(m_container, widget());
828 if(dynamic_cast<TabWidgetBase*>(widget())->count() == 0)
829 {
830 com->execute();
831 delete com;
832 }
833 else
834 m_container->form()->addCommand(com, true);
835}
836
837void ContainerFactory::removeTabPage()
838{
839 if (!widget()->inherits("TQTabWidget"))
840 return;
841 TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(widget());
842 TQWidget *w = tab->currentPage();
843
845 list.append(w);
846 KCommand *com = new KFormDesigner::DeleteWidgetCommand(list, m_container->form());
847 tab->removePage(w);
848 m_container->form()->addCommand(com, true);
849}
850
851void ContainerFactory::renameTabPage()
852{
853 if (!widget()->inherits("TQTabWidget"))
854 return;
855 TabWidgetBase *tab = dynamic_cast<TabWidgetBase*>(widget());
856 TQWidget *w = tab->currentPage();
857 bool ok;
858
859 TQString name = KInputDialog::getText(i18n("New Page Title"), i18n("Enter a new title for the current page:"),
860#if TDE_VERSION < TDE_MAKE_VERSION(3,1,9)
861 TQLineEdit::Normal,
862#endif
863 tab->tabLabel(w), &ok, w->topLevelWidget());
864 if(ok)
865 tab->changeTab(w, name);
866}
867
868void ContainerFactory::reorderTabs(int oldpos, int newpos)
869{
872 if(!tab)
873 return;
874
875 KFormDesigner::ObjectTreeItem *item = tab->children()->take(oldpos);
876 tab->children()->insert(newpos, item);
877}
878
879void ContainerFactory::addStackPage()
880{
881 if (!widget()->isA("TQWidgetStack"))
882 return;
883 KCommand *com = new InsertPageCommand(m_container, widget());
884 if(!((TQWidgetStack*)widget())->visibleWidget())
885 {
886 com->execute();
887 delete com;
888 }
889 else
890 m_container->form()->addCommand(com, true);
891}
892
893void ContainerFactory::removeStackPage()
894{
895 if (!widget()->isA("TQWidgetStack"))
896 return;
897 TQWidgetStack *stack = (TQWidgetStack*)widget();
898 TQWidget *page = stack->visibleWidget();
899
901 list.append(page);
902 KCommand *com = new KFormDesigner::DeleteWidgetCommand(list, m_container->form());
903
904 // raise prev widget
905 int id = stack->id(page) - 1;
906 while(!stack->widget(id))
907 id--;
908 stack->raiseWidget(id);
909
910 stack->removeWidget(page);
911 m_container->form()->addCommand(com, true);
912}
913
914void ContainerFactory::prevStackPage()
915{
916 TQWidgetStack *stack = (TQWidgetStack*)widget();
917 int id = stack->id(stack->visibleWidget()) - 1;
918 if(stack->widget(id))
919 stack->raiseWidget(id);
920}
921
922void ContainerFactory::nextStackPage()
923{
924 TQWidgetStack *stack = (TQWidgetStack*)widget();
925 int id = stack->id(stack->visibleWidget()) + 1;
926 if(stack->widget(id))
927 stack->raiseWidget(id);
928}
929
930ContainerFactory::~ContainerFactory()
931{
932}
933
934KFORMDESIGNER_WIDGET_FACTORY(ContainerFactory, containers)
935
936#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 FormManager * self()
Access to FormManager singleton.
A simple class representing a form.
Definition form.h:136
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
void setDesignMode(bool design)
Definition form.cpp:214
void createToplevel(TQWidget *container, FormWidget *formWidget=0, const TQCString &classname="TQWidget")
Definition form.cpp:127
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")