24#include <tqsplitter.h>
25#include <tqmetaobject.h>
29#include <tdepopupmenu.h>
30#include <tdemessagebox.h>
31#include <tdeaccelmanager.h>
35#include "objecttree.h"
36#include "formmanager.h"
38#include "widgetlibrary.h"
41#include "widgetpropertyset.h"
42#include "widgetwithsubpropertiesinterface.h"
43#include <koproperty/property.h>
62PropertyCommand::PropertyCommand(WidgetPropertySet *set,
const TQCString &wname,
63 const TQVariant &oldValue,
const TQVariant &value,
const TQCString &property)
64 :
Command(), m_propSet(set), m_value(value), m_property(property)
66 m_oldvalues.insert(wname, oldValue);
69PropertyCommand::PropertyCommand(WidgetPropertySet *set,
const TQMap<TQCString, TQVariant> &oldvalues,
70 const TQVariant &value,
const TQCString &property)
71 :
Command(), m_propSet(set), m_value(value), m_oldvalues(oldvalues), m_property(property)
87PropertyCommand::setValue(
const TQVariant &value)
94PropertyCommand::execute()
97 m_propSet->setUndoing(
true);
99 TQMap<TQCString, TQVariant>::ConstIterator endIt = m_oldvalues.constEnd();
100 for(TQMap<TQCString, TQVariant>::ConstIterator it = m_oldvalues.constBegin(); it != endIt; ++it)
108 (*m_propSet)[m_property] = m_value;
109 m_propSet->setUndoing(
false);
113PropertyCommand::unexecute()
116 m_propSet->setUndoing(
true);
118 TQMap<TQCString, TQVariant>::ConstIterator endIt = m_oldvalues.constEnd();
119 for(TQMap<TQCString, TQVariant>::ConstIterator it = m_oldvalues.constBegin(); it != endIt; ++it)
124 TQWidget *widg = item->widget();
128 WidgetWithSubpropertiesInterface* subpropIface =
dynamic_cast<WidgetWithSubpropertiesInterface*
>(widg);
129 TQWidget *subWidget = (subpropIface && subpropIface->
subwidget()) ? subpropIface->
subwidget() : widg;
130 if (-1!=subWidget->metaObject()->findProperty( m_property,
true ))
131 subWidget->setProperty(m_property, it.data());
134 (*m_propSet)[m_property] = m_oldvalues.begin().data();
135 m_propSet->setUndoing(
false);
139PropertyCommand::name()
const
141 if(m_oldvalues.count() >= 2)
142 return i18n(
"Change \"%1\" property for multiple widgets" ).arg(TQString(m_property));
144 return i18n(
"Change \"%1\" property for widget \"%2\"" ).arg(TQString(m_property)).arg(TQString(m_oldvalues.begin().key()));
148PropertyCommand::debug()
150 kdDebug() <<
"PropertyCommand: name=\"" << name() <<
"\" widgets=" << m_oldvalues.keys()
151 <<
" value=" << m_value <<
" oldValues=" << m_oldvalues.values() << endl;
156GeometryPropertyCommand::GeometryPropertyCommand(WidgetPropertySet *set,
157 const TQStringList &names,
const TQPoint& oldPos)
158 :
Command(), m_propSet(set), m_names(names), m_oldPos(oldPos)
163GeometryPropertyCommand::execute()
165 m_propSet->setUndoing(
true);
166 int dx = m_pos.x() - m_oldPos.x();
167 int dy = m_pos.y() - m_oldPos.y();
169 TQStringList::ConstIterator endIt = m_names.constEnd();
171 for(TQStringList::ConstIterator it = m_names.constBegin(); it != endIt; ++it)
176 TQWidget *w = item->widget();
177 w->move(w->x() + dx, w->y() + dy);
179 m_propSet->setUndoing(
false);
183GeometryPropertyCommand::unexecute()
185 m_propSet->setUndoing(
true);
186 int dx = m_pos.x() - m_oldPos.x();
187 int dy = m_pos.y() - m_oldPos.y();
189 TQStringList::ConstIterator endIt = m_names.constEnd();
191 for(TQStringList::ConstIterator it = m_names.constBegin(); it != endIt; ++it)
196 TQWidget *w = item->widget();
197 w->move(w->x() - dx, w->y() - dy);
199 m_propSet->setUndoing(
false);
203GeometryPropertyCommand::setPos(
const TQPoint& pos)
210GeometryPropertyCommand::name()
const
212 return i18n(
"Move multiple widgets");
216GeometryPropertyCommand::debug()
218 kdDebug() <<
"GeometryPropertyCommand: pos=" << m_pos <<
" oldPos=" << m_oldPos
219 <<
" widgets=" << m_names << endl;
224AlignWidgetsCommand::AlignWidgetsCommand(
int type,
WidgetList &list,
Form *form)
225:
Command(), m_form(form), m_type(type)
227 for(TQWidget *w = list.first(); w; w = list.next())
228 m_pos.insert(w->name(), w->pos());
232AlignWidgetsCommand::execute()
235 m_form->selectFormWidget();
237 int gridX = m_form->gridSize();
238 int gridY = m_form->gridSize();
239 TQWidget *parentWidget = m_form->selectedWidgets()->first()->parentWidget();
243 TQMap<TQCString, TQPoint>::ConstIterator endIt = m_pos.constEnd();
244 for(TQMap<TQCString, TQPoint>::ConstIterator it = m_pos.constBegin(); it != endIt; ++it)
246 ObjectTreeItem *item = m_form->objectTree()->lookup(it.key());
247 if(item && item->widget())
248 list.append(item->widget());
255 for(TQWidget *w = list.first(); w; w = list.next())
257 tmpx = int( (
float)w->x() / ((
float)gridX) + 0.5 ) * gridX;
258 tmpy = int( (
float)w->y() / ((
float)gridY) + 0.5 ) * gridY;
260 if((tmpx != w->x()) || (tmpy != w->y()))
268 tmpx = parentWidget->width();
269 for(TQWidget *w = list.first(); w; w = list.next())
275 for(TQWidget *w = list.first(); w; w = list.next())
276 w->move(tmpx, w->y());
283 for(TQWidget *w = list.first(); w; w = list.next())
285 if(w->x() + w->width() > tmpx)
286 tmpx = w->x() + w->width();
289 for(TQWidget *w = list.first(); w; w = list.next())
290 w->move(tmpx - w->width(), w->y());
296 tmpy = parentWidget->height();
297 for(TQWidget *w = list.first(); w; w = list.next())
303 for(TQWidget *w = list.first(); w; w = list.next())
304 w->move(w->x(), tmpy);
311 for(TQWidget *w = list.first(); w; w = list.next())
313 if(w->y() + w->height() > tmpy)
314 tmpy = w->y() + w->height();
317 for(TQWidget *w = list.first(); w; w = list.next())
318 w->move(w->x(), tmpy - w->height());
327 for(TQWidget *w = list.first(); w; w = list.next())
328 m_form->setSelectedWidget(w,
true);
332AlignWidgetsCommand::unexecute()
335 m_form->selectFormWidget();
337 TQMap<TQCString, TQPoint>::ConstIterator endIt = m_pos.constEnd();
338 for(TQMap<TQCString, TQPoint>::ConstIterator it = m_pos.constBegin(); it != endIt; ++it)
340 ObjectTreeItem *item = m_form->objectTree()->lookup(it.key());
341 if(item && item->widget())
342 item->widget()->move( m_pos[item->widget()->name()] );
343 m_form->setSelectedWidget(item->widget(),
true);
348AlignWidgetsCommand::name()
const
353 return i18n(
"Align Widgets to Grid");
355 return i18n(
"Align Widgets to Left");
357 return i18n(
"Align Widgets to Right");
359 return i18n(
"Align Widgets to Top");
361 return i18n(
"Align Widgets to Bottom");
368AlignWidgetsCommand::debug()
370 kdDebug() <<
"AlignWidgetsCommand: name=\"" << name() <<
"\" form=" << m_form->widget()->name()
371 <<
" widgets=" << m_pos.keys() << endl;
376AdjustSizeCommand::AdjustSizeCommand(
int type,
WidgetList &list,
Form *form)
377:
Command(), m_form(form), m_type(type)
379 for(TQWidget *w = list.first(); w; w = list.next())
381 if(w->parentWidget() && w->parentWidget()->isA(
"TQWidgetStack"))
383 w = w->parentWidget();
384 if(w->parentWidget() && w->parentWidget()->inherits(
"TQTabWidget"))
385 w = w->parentWidget();
388 m_sizes.insert(w->name(), w->size());
389 if(m_type == SizeToGrid)
390 m_pos.insert(w->name(), w->pos());
395AdjustSizeCommand::execute()
398 m_form->selectFormWidget();
400 int gridX = m_form->gridSize();
401 int gridY = m_form->gridSize();
405 TQMap<TQCString, TQSize>::ConstIterator endIt = m_sizes.constEnd();
406 for(TQMap<TQCString, TQSize>::ConstIterator it = m_sizes.constBegin(); it != endIt; ++it)
408 ObjectTreeItem *item = m_form->objectTree()->lookup(it.key());
409 if(item && item->widget())
410 list.append(item->widget());
419 for(TQWidget *w = list.first(); w; w = list.next())
421 tmpx = int( (
float)w->x() / ((
float)gridX) + 0.5 ) * gridX;
422 tmpy = int( (
float)w->y() / ((
float)gridY) + 0.5 ) * gridY;
423 tmpw = int( (
float)w->width() / ((
float)gridX) + 0.5 ) * gridX;
424 tmph = int( (
float)w->height() / ((
float)gridY) + 0.5 ) * gridY;
426 if((tmpx != w->x()) || (tmpy != w->y()))
428 if((tmpw != w->width()) || (tmph != w->height()))
429 w->resize(tmpw, tmph);
436 for(TQWidget *w = list.first(); w; w = list.next()) {
437 ObjectTreeItem *item = m_form->objectTree()->lookup(w->name());
438 if(item && !item->children()->isEmpty()) {
443 s = getSizeFromChildren(item);
451 if(type == Container::HFlow)
452 s.setWidth(s.width() + 5);
453 else if(type == Container::VFlow)
454 s.setHeight(s.height() + 5);
460 TQSize sizeHint(w->sizeHint());
461 if (sizeHint.isValid())
468 case SizeToSmallWidth:
470 for(TQWidget *w = list.first(); w; w = list.next())
472 if((tmpw == 0) || (w->width() < tmpw))
476 for(TQWidget *w = list.first(); w; w = list.next())
478 if(tmpw != w->width())
479 w->resize(tmpw, w->height());
486 for(TQWidget *w = list.first(); w; w = list.next())
488 if(w->width() > tmpw)
492 for(TQWidget *w = list.first(); w; w = list.next())
494 if(tmpw != w->width())
495 w->resize(tmpw, w->height());
500 case SizeToSmallHeight:
502 for(TQWidget *w = list.first(); w; w = list.next())
504 if((tmph == 0) || (w->height() < tmph))
508 for(TQWidget *w = list.first(); w; w = list.next())
510 if(tmph != w->height())
511 w->resize(w->width(), tmph);
516 case SizeToBigHeight:
518 for(TQWidget *w = list.first(); w; w = list.next())
520 if(w->height() > tmph)
524 for(TQWidget *w = list.first(); w; w = list.next())
526 if(tmph != w->height())
527 w->resize(w->width(), tmph);
537 for(TQWidget *w = list.first(); w; w = list.next())
538 m_form->setSelectedWidget(w,
true);
548 for(ObjectTreeItem *tree = item->children()->first(); tree; tree = item->children()->next())
549 s = s.expandedTo(getSizeFromChildren(tree));
553 int tmpw = 0, tmph = 0;
554 for(ObjectTreeItem *tree = item->children()->first(); tree; tree = item->children()->next()) {
557 tmpw = TQMAX(tmpw, tree->widget()->geometry().right());
558 tmph = TQMAX(tmph, tree->widget()->geometry().bottom());
561 return TQSize(tmpw, tmph) + TQSize(10, 10);
565AdjustSizeCommand::unexecute()
568 m_form->selectFormWidget();
570 TQMap<TQCString, TQSize>::ConstIterator endIt = m_sizes.constEnd();
571 for(TQMap<TQCString, TQSize>::ConstIterator it = m_sizes.constBegin(); it != endIt; ++it)
573 ObjectTreeItem *item = m_form->objectTree()->lookup(it.key());
574 if(item && item->widget())
576 item->widget()->resize( m_sizes[item->widget()->name()] );
577 if(m_type == SizeToGrid)
578 item->widget()->move( m_pos[item->widget()->name()] );
579 m_form->setSelectedWidget(item->widget(),
true);
585AdjustSizeCommand::name()
const
590 return i18n(
"Resize Widgets to Grid");
592 return i18n(
"Resize Widgets to Fit Contents");
593 case SizeToSmallWidth:
594 return i18n(
"Resize Widgets to Narrowest");
596 return i18n(
"Resize Widgets to Widest");
597 case SizeToSmallHeight:
598 return i18n(
"Resize Widgets to Shortest");
599 case SizeToBigHeight:
600 return i18n(
"Resize Widgets to Tallest");
607AdjustSizeCommand::debug()
609 kdDebug() <<
"AdjustSizeCommand: name=\"" << name() <<
"\" form=" << m_form->widget()->name()
610 <<
" widgets=" << m_sizes.keys() << endl;
615LayoutPropertyCommand::LayoutPropertyCommand(WidgetPropertySet *buf,
const TQCString &wname,
616 const TQVariant &oldValue,
const TQVariant &value)
626 m_geometries.insert(it->name().latin1(), it->widget()->geometry());
630LayoutPropertyCommand::execute()
632 PropertyCommand::execute();
636LayoutPropertyCommand::unexecute()
638 ObjectTreeItem* titem = m_form->objectTree()->lookup(m_oldvalues.begin().key());
641 Container *m_container = titem->
container();
642 m_container->
setLayout(Container::NoLayout);
644 TQMap<TQCString,TQRect>::ConstIterator endIt = m_geometries.constEnd();
645 for(TQMap<TQCString,TQRect>::ConstIterator it = m_geometries.constBegin(); it != endIt; ++it)
649 tree->widget()->setGeometry(it.data());
652 PropertyCommand::unexecute();
656LayoutPropertyCommand::name()
const
658 return i18n(
"Change layout of widget \"%1\"").arg(TQString(m_oldvalues.begin().key()));
662LayoutPropertyCommand::debug()
664 kdDebug() <<
"LayoutPropertyCommand: name=\"" << name() <<
"\" oldValue=" << m_oldvalues.keys()
665 <<
" value=" << m_value << endl;
673 m_containername = container->
widget()->name();
674 m_form = container->
form();
676 m_insertRect = container->m_insertRect;
677 m_point = container->m_insertBegin;
679 container->
form()->
library()->namePrefix(m_class).latin1(),
false);
684 const TQCString& className,
const TQPoint& pos,
const TQCString& namePrefix)
687 m_containername = container->
widget()->name();
688 m_form = container->
form();
692 if (namePrefix.isEmpty()) {
693 m_name = container->form()->objectTree()->generateUniqueName(
694 container->form()->library()->namePrefix(m_class).latin1() );
697 m_name = container->form()->objectTree()->generateUniqueName(
705 if (!m_form->objectTree())
707 ObjectTreeItem* titem = m_form->objectTree()->lookup(m_containername);
712 if (m_container->
form()->
library()->internalProperty(m_class,
"orientationSelectionPopup")==
"1") {
713 if(m_insertRect.isValid()) {
714 if (m_insertRect.width() < m_insertRect.height()) {
718 else if (m_insertRect.width() > m_insertRect.height()) {
726 m_class, m_container->m_container,
727 m_container->
form()->
widget()->mapToGlobal(m_point));
736 m_container, options);
742 i18n(
"Could not insert widget of type \"%1\". A problem with widget's creation encountered.")
743 .arg(winfo ? winfo->
name() : TQString()));
744 kdWarning() <<
"InsertWidgetCommand::execute() ERROR: widget creation failed" << endl;
748 if (m_form->designMode()) {
750 TDEAcceleratorManager::setNoAccel(w);
754 if(( (m_insertRect.width() < 21) && (m_insertRect.height() < 21)))
756 TQSize s = w->sizeHint();
761 if(m_insertRect.isValid())
763 x = m_insertRect.x();
764 y = m_insertRect.y();
771 m_insertRect = TQRect(x, y, s.width() + 16,
774 w->move(m_insertRect.x(), m_insertRect.y());
775 w->resize(m_insertRect.width()-1, m_insertRect.height()-1);
776 w->setStyle(&(m_container->
widget()->style()));
777 w->setBackgroundOrigin(TQWidget::ParentOrigin);
797 TQValueList<TQCString> list(m_container->
form()->
library()->autoSaveProperties(w->className()));
799 TQValueList<TQCString>::ConstIterator endIt = list.constEnd();
800 for(TQValueList<TQCString>::ConstIterator it = list.constBegin(); it != endIt; ++it)
806 if (m_container->
form()->
library()->internalProperty(w->className(),
807 "dontStartEditingOnInserting").isEmpty())
813 kdDebug() <<
"Container::eventFilter(): widget added " <<
this << endl;
817InsertWidgetCommand::unexecute()
822 TQWidget *m_widget = titem->widget();
828InsertWidgetCommand::name()
const
830 if(!m_name.isEmpty())
831 return i18n(
"Insert widget \"%1\"").arg(TQString(m_name));
833 return i18n(
"Insert widget");
837InsertWidgetCommand::debug()
839 kdDebug() <<
"InsertWidgetCommand: name=\"" << name() <<
"\" generatedName=" << m_name
840 <<
" container=" << m_containername
841 <<
" form=" << m_form->widget()->name() <<
" class=" << m_class
842 <<
" rect=" << m_insertRect <<
" pos=" << m_point << endl;
848 : m_form(form), m_type(layoutType)
853 case Container::HBox:
854 case Container::Grid:
855 case Container::HSplitter:
856 case Container::HFlow:
858 case Container::VBox:
859 case Container::VSplitter:
860 case Container::VFlow:
863 for(TQWidget *w = list.first(); w; w = list.next())
867 for(TQWidget *w = m_list->first(); w; w = m_list->next())
868 m_pos.insert(w->name(), w->geometry());
871 m_containername = item->parent()->name();
881 ObjectTreeItem* titem = m_form->objectTree()->lookup(m_containername);
884 container = m_form->toplevelContainer();
888 case Container::HSplitter:
case Container::VSplitter:
889 classname =
"TQSplitter";
break;
895 m_name = m_form->
objectTree()->generateUniqueName(classname);
897 TQWidget *w = lib->
createWidget(classname, container->
widget(), m_name.latin1(), container);
900 if (m_form->designMode()) {
902 TDEAcceleratorManager::setNoAccel(w);
905 ObjectTreeItem *tree = w ? m_form->objectTree()->lookup(w->name()) : 0;
910 w->move(m_pos.begin().data().topLeft());
912 if(m_type == Container::HFlow)
913 w->resize( TQSize(700, 20) );
914 else if(m_type == Container::VFlow)
915 w->resize( TQSize(20, 700));
919 TQMap<TQCString,TQRect>::ConstIterator endIt = m_pos.constEnd();
920 for(TQMap<TQCString,TQRect>::ConstIterator it = m_pos.constBegin(); it != endIt; ++it)
923 if(item && item->widget())
925 item->widget()->reparent(w, item->widget()->pos(),
true);
927 m_form->objectTree()->reparent(item->name(), m_name);
931 if(m_type == Container::HSplitter)
932 ((TQSplitter*)w)->setOrientation(TQt::Horizontal);
933 else if(m_type == Container::VSplitter)
934 ((TQSplitter*)w)->setOrientation(TQt::Vertical);
945CreateLayoutCommand::unexecute()
952 TQMap<TQCString,TQRect>::ConstIterator endIt = m_pos.constEnd();
953 for(TQMap<TQCString,TQRect>::ConstIterator it = m_pos.constBegin(); it != endIt; ++it)
956 if(item && item->widget())
958 item->widget()->reparent(parent->widget(), TQPoint(0,0),
true);
960 if(m_pos[it.key()].isValid())
961 item->widget()->setGeometry(m_pos[it.key()]);
968 ObjectTreeItem* titem = m_form->objectTree()->lookup(m_name);
971 TQWidget *w = titem->widget();
977CreateLayoutCommand::name()
const
981 case Container::HBox:
982 return i18n(
"Group Widgets Horizontally");
983 case Container::VBox:
984 return i18n(
"Group Widgets Vertically");
985 case Container::Grid:
986 return i18n(
"Group Widgets in a Grid");
987 case Container::HSplitter:
988 return i18n(
"Group Widgets Horizontally in a Splitter");
989 case Container::VSplitter:
990 return i18n(
"Group Widgets Vertically in a Splitter");
991 case Container::HFlow:
992 return i18n(
"Group Widgets By Rows");
993 case Container::VFlow:
994 return i18n(
"Group Widgets Vertically By Columns");
996 return i18n(
"Group widgets");
1001CreateLayoutCommand::debug()
1003 kdDebug() <<
"CreateLayoutCommand: name=\"" << name() <<
"\" generatedName=" << m_name
1004 <<
" widgets=" << m_pos.keys() <<
" container=" << m_containername
1005 <<
" form=" << m_form->widget()->name() << endl;
1013 m_containername = container->
toplevel()->widget()->name();
1014 m_name = container->
widget()->name();
1015 m_form = container->
form();
1020 TQRect r(container->widget()->mapTo(container->widget()->parentWidget(), tree->widget()->pos()), tree->widget()->size());
1021 m_pos.insert(tree->widget()->name(), r);
1028 CreateLayoutCommand::unexecute();
1032BreakLayoutCommand::unexecute()
1038BreakLayoutCommand::name()
const
1040 return i18n(
"Break Layout: \"%1\"").arg(m_name);
1044BreakLayoutCommand::debug()
1046 kdDebug() <<
"BreakLayoutCommand: name=\"" << name()
1047 <<
" widgets=" << m_pos.keys() <<
" container=" << m_containername
1048 <<
" form=" << m_form->widget()->name() << endl;
1053PasteWidgetCommand::PasteWidgetCommand(TQDomDocument &domDoc,
Container *container,
const TQPoint& p)
1056 m_data = domDoc.toCString();
1057 m_containername = container->
widget()->name();
1058 m_form = container->
form();
1060 if(domDoc.namedItem(
"UI").firstChild().nextSibling().toElement().tagName() !=
"widget")
1063 TQRect boundingRect;
1064 for(TQDomNode n = domDoc.namedItem(
"UI").firstChild(); !n.isNull(); n = n.nextSibling())
1066 if(n.toElement().tagName() !=
"widget")
1068 TQDomElement el = n.toElement();
1071 for(TQDomNode n = el.firstChild(); !n.isNull(); n = n.nextSibling())
1073 if((n.toElement().tagName() ==
"property") && (n.toElement().attribute(
"name") ==
"geometry"))
1074 rect = n.firstChild().toElement();
1077 TQDomElement x = rect.namedItem(
"x").toElement();
1078 TQDomElement y = rect.namedItem(
"y").toElement();
1079 TQDomElement wi = rect.namedItem(
"width").toElement();
1080 TQDomElement h = rect.namedItem(
"height").toElement();
1082 int rx = x.text().toInt();
1083 int ry = y.text().toInt();
1084 int rw = wi.text().toInt();
1085 int rh = h.text().toInt();
1086 TQRect r(rx, ry, rw, rh);
1087 boundingRect = boundingRect.unite(r);
1090 m_point = m_point - boundingRect.topLeft();
1094PasteWidgetCommand::execute()
1096 ObjectTreeItem* titem = m_form->objectTree()->lookup(m_containername);
1099 Container *container = titem->
container();
1103 TQDomDocument domDoc(
"UI");
1104 bool parsed = domDoc.setContent(m_data,
false, &errMsg, &errLine, &errCol);
1108 kdDebug() <<
"WidgetWatcher::load(): " << errMsg << endl;
1109 kdDebug() <<
"WidgetWatcher::load(): line: " << errLine <<
" col: " << errCol << endl;
1115 kdDebug() << domDoc.toString() << endl;
1116 if(!domDoc.namedItem(
"UI").hasChildNodes())
1118 if(domDoc.namedItem(
"UI").firstChild().nextSibling().toElement().tagName() !=
"widget")
1120 TQDomElement el = domDoc.namedItem(
"UI").firstChild().toElement();
1122 if(m_point.isNull())
1127 m_form->setInteractiveMode(
false);
1129 m_form->setInteractiveMode(
true);
1131 else for(TQDomNode n = domDoc.namedItem(
"UI").firstChild(); !n.isNull(); n = n.nextSibling())
1133 if(n.toElement().tagName() !=
"widget")
1135 TQDomElement el = n.toElement();
1137 if(!m_point.isNull())
1138 moveWidgetBy(el, container, m_point);
1141 kdDebug() <<
"jdkjfldfksmfkdfjmqdsklfjdkkfmsqfksdfsm" << endl;
1144 m_form->setInteractiveMode(
false);
1146 m_form->setInteractiveMode(
true);
1152 for(TQDomNode n = domDoc.namedItem(
"UI").firstChild(); !n.isNull(); n = n.nextSibling())
1154 if(n.toElement().tagName() !=
"widget")
1156 for(TQDomNode m = n.firstChild(); !m.isNull(); n = m.nextSibling())
1158 if((m.toElement().tagName() ==
"property") && (m.toElement().attribute(
"name") ==
"name"))
1160 m_names.append(m.toElement().text());
1167 TQStringList::ConstIterator endIt = m_names.constEnd();
1168 for(TQStringList::ConstIterator it = m_names.constBegin(); it != endIt; ++it)
1170 ObjectTreeItem *item = m_form->objectTree()->lookup(*it);
1177PasteWidgetCommand::unexecute()
1179 ObjectTreeItem* titem = m_form->objectTree()->lookup(m_containername);
1182 Container *container = titem->
container();
1184 TQStringList::ConstIterator endIt = m_names.constEnd();
1185 for(TQStringList::ConstIterator it = m_names.constBegin(); it != endIt; ++it)
1190 TQWidget *w = titem->widget();
1196PasteWidgetCommand::name()
const
1198 return i18n(
"Paste");
1208 for(TQDomNode n = el.firstChild(); !n.isNull(); n = n.nextSibling())
1210 if((n.toElement().tagName() ==
"property") && (n.toElement().attribute(
"name") ==
"geometry"))
1211 rect = n.firstChild().toElement();
1214 TQDomElement x = rect.namedItem(
"x").toElement();
1215 x.removeChild(x.firstChild());
1216 TQDomText valueX = el.ownerDocument().createTextNode(TQString::number(newpos.x()));
1217 x.appendChild(valueX);
1219 TQDomElement y = rect.namedItem(
"y").toElement();
1220 y.removeChild(y.firstChild());
1221 TQDomText valueY = el.ownerDocument().createTextNode(TQString::number(newpos.y()));
1222 y.appendChild(valueY);
1274 moveWidgetBy(el, container, TQPoint(0, 0));
1278PasteWidgetCommand::moveWidgetBy(TQDomElement &el,
Container *container,
const TQPoint &p)
1281 for(TQDomNode n = el.firstChild(); !n.isNull(); n = n.nextSibling())
1283 if((n.toElement().tagName() ==
"property") && (n.toElement().attribute(
"name") ==
"geometry"))
1284 rect = n.firstChild().toElement();
1287 TQDomElement x = rect.namedItem(
"x").toElement();
1288 TQDomElement y = rect.namedItem(
"y").toElement();
1289 TQDomElement wi = rect.namedItem(
"width").toElement();
1290 TQDomElement h = rect.namedItem(
"height").toElement();
1292 int rx = x.text().toInt();
1293 int ry = y.text().toInt();
1294 int rw = wi.text().toInt();
1295 int rh = h.text().toInt();
1296 TQRect r(rx + p.x(), ry + p.y(), rw, rh);
1297 kdDebug() <<
"Moving widget by " << p <<
" from " << rx <<
" " << ry <<
" to " << r.topLeft() << endl;
1299 TQWidget *w = m_form->
widget()->childAt(r.x() + 6, r.y() + 6,
false);
1301 while(w && (w->geometry() == r))
1303 w = m_form->
widget()->childAt(w->x() + 16, w->y() + 16,
false);
1310 else if(r.right() > container->
widget()->width())
1311 r.moveLeft(container->
widget()->width() - r.width());
1315 else if(r.bottom() > container->
widget()->height())
1316 r.moveTop(container->
widget()->height() - r.height());
1318 if(r != TQRect(rx, ry, rw, rh))
1328 for(TQDomNode n = el.firstChild(); !n.isNull(); n = n.nextSibling())
1330 if((n.toElement().tagName() ==
"property") && (n.toElement().attribute(
"name") ==
"name"))
1332 wname = n.toElement().text();
1333 while(m_form->objectTree()->lookup(wname))
1336 int num = wname.right(1).toInt(&ok, 10);
1338 wname = wname.left(wname.length()-1) + TQString::number(num+1);
1342 if(wname != n.toElement().text())
1344 n.removeChild(n.firstChild());
1345 TQDomElement type = el.ownerDocument().createElement(
"string");
1346 TQDomText valueE = el.ownerDocument().createTextNode(wname);
1347 type.appendChild(valueE);
1348 n.toElement().appendChild(type);
1352 if(n.toElement().tagName() ==
"widget")
1354 TQDomElement child = n.toElement();
1361PasteWidgetCommand::debug()
1363 kdDebug() <<
"PasteWidgetCommand: pos=" << m_point
1364 <<
" widgets=" << m_names <<
" container=" << m_containername
1365 <<
" form=" << m_form->
widget()->name()
1366 <<
" data=\"" << m_data.left(80) <<
"...\"" << endl;
1371DeleteWidgetCommand::DeleteWidgetCommand(
WidgetList &list,
Form *form)
1374 m_domDoc = TQDomDocument(
"UI");
1375 m_domDoc.appendChild(m_domDoc.createElement(
"UI"));
1377 TQDomElement parent = m_domDoc.namedItem(
"UI").toElement();
1399 m_containers.insert(item->name().latin1(), m_form->
parentContainer(item->widget())->
widget()->name());
1400 m_parents.insert(item->name().latin1(), item->parent()->name().latin1());
1402 form->connectionBuffer()->saveAllConnectionsForWidget(item->widget()->name(), m_domDoc);
1409DeleteWidgetCommand::execute()
1411 Container *containerToSelect = 0;
1413 TQMap<TQCString,TQCString>::ConstIterator endIt = m_containers.constEnd();
1414 for(TQMap<TQCString,TQCString>::ConstIterator it = m_containers.constBegin(); it != endIt; ++it)
1416 ObjectTreeItem *item = m_form->objectTree()->lookup(it.key());
1417 if (!item || !item->widget())
1420 Container *cont = m_form->parentContainer(item->widget());
1421 if (!containerToSelect)
1422 containerToSelect = cont;
1426 if (containerToSelect)
1427 m_form->setSelectedWidget( containerToSelect->
widget() );
1431DeleteWidgetCommand::unexecute()
1434 m_form->setInteractiveMode(
false);
1435 for(TQDomNode n = m_domDoc.namedItem(
"UI").firstChild(); !n.isNull(); n = n.nextSibling())
1437 if(n.toElement().tagName() ==
"connections")
1438 m_form->connectionBuffer()->load(n);
1439 if(n.toElement().tagName() !=
"widget")
1442 for(TQDomNode m = n.firstChild(); !m.isNull(); n = m.nextSibling())
1444 if((m.toElement().tagName() ==
"property") && (m.toElement().attribute(
"name") ==
"name"))
1446 wname = m.toElement().text().latin1();
1451 ObjectTreeItem* titem = m_form->objectTree()->lookup(m_containers[wname]);
1455 ObjectTreeItem *parent = m_form->
objectTree()->lookup(m_parents[wname]);
1456 TQDomElement widg = n.toElement();
1462 m_form->setInteractiveMode(
true);
1466DeleteWidgetCommand::name()
const
1468 return i18n(
"Delete widget");
1472DeleteWidgetCommand::debug()
1474 kdDebug() <<
"DeleteWidgetCommand: containers=" << m_containers.keys()
1475 <<
" parents=" << m_parents.keys() <<
" form=" << m_form->widget()->name() << endl;
1485CutWidgetCommand::execute()
1487 DeleteWidgetCommand::execute();
1493CutWidgetCommand::unexecute()
1495 DeleteWidgetCommand::unexecute();
1500CutWidgetCommand::name()
const
1506CutWidgetCommand::debug()
1508 kdDebug() <<
"CutWidgetCommand: containers=" << m_containers.keys()
1509 <<
" parents=" << m_parents.keys() <<
" form=" << m_form->widget()->name()
1510 <<
" data=\"" << m_data.left(80) <<
"...\"" << endl;
1516class CommandGroup::SubCommands :
public KMacroCommand
1519 SubCommands(
const TQString & name )
1520 : KMacroCommand(name)
1523 const TQPtrList<KCommand>&
commands()
const {
return m_commands; }
1527CommandGroup::CommandGroup(
const TQString & name, WidgetPropertySet *propSet )
1529 , m_subCommands(new SubCommands(name))
1530 , m_propSet(propSet)
1534CommandGroup::~CommandGroup()
1536 delete m_subCommands;
1541 return m_subCommands->commands();
1549 m_subCommands->addCommand(command);
1557 for (TQPtrListIterator<KCommand> it(m_subCommands->commands()); it.current(); ++it) {
1559 it.current()->execute();
1567 m_subCommands->unexecute();
1571TQString CommandGroup::name()
const
1573 return m_subCommands->name();
1582CommandGroup::debug()
1584 kdDebug() <<
"*CommandGroup: name=\"" << name() <<
"\" #=" << m_subCommands->commands().count() << endl;
1586 for (TQPtrListIterator<KCommand> it(m_subCommands->commands()); it.current(); ++it, i++) {
1587 kdDebug() <<
"#" << i <<
":"
1589 if (
dynamic_cast<Command*
>(it.current()))
1590 dynamic_cast<Command*
>(it.current())->debug();
1594 kdDebug() <<
"(other KCommand)" << endl;
1596 kdDebug() <<
"End of CommandGroup" << endl;