kexi

kfd_kdev_part.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include <tqworkspace.h>
21#include <tqdockarea.h>
22#include <tqdockwindow.h>
23#include <tqhbox.h>
24#include <tqpainter.h>
25#include <tqevent.h>
26#include <tqobjectlist.h>
27
28#include <tdeaction.h>
29#include <tdeinstance.h>
30#include <tdelocale.h>
31#include <tdeaboutdata.h>
32#include <kdebug.h>
33#include <kstdaction.h>
34#include <tdeapplication.h>
35#include <kiconloader.h>
36#include <tdefiledialog.h>
37#include <klibloader.h>
38#include <tdemessagebox.h>
39
40#include "form.h"
41#include "formIO.h"
42#include "objecttree.h"
43#include "container.h"
44#include "formmanager.h"
45#include "objecttreeview.h"
46
47#include "kfd_kdev_part.h"
48
49#define ENABLE_ACTION(name, enable) \
50 if(actionCollection()->action( name )) \
51 actionCollection()->action( name )->setEnabled( enable )
52
53TDEInstance *KFDFactory::m_instance = 0L;
54
55KFDFactory::KFDFactory()
56: KParts::Factory(0, "libkformdesigner_kdev_part")
57{}
58
59KFDFactory::~KFDFactory()
60{
61 if (m_instance)
62 {
63 delete m_instance->aboutData();
64 delete m_instance;
65 }
66
67 m_instance = 0;
68}
69
70KParts::Part*
71KFDFactory::createPartObject( TQWidget *parentWidget, const char *, TQObject *, const char *name,
72 const char *classname, const TQStringList &args)
73{
74 bool readOnly = (classname == "KParts::ReadOnlyPart");
75 KFormDesignerKDevPart *part = new KFormDesignerKDevPart(parentWidget, name, readOnly, args);
76 return part;
77}
78
79TDEInstance*
80KFDFactory::instance()
81{
82 if (!m_instance)
83 m_instance = new TDEInstance(aboutData());
84 return m_instance;
85}
86
87TDEAboutData*
88KFDFactory::aboutData()
89{
90 TDEAboutData *about = new TDEAboutData("kformdesigner_kdev_part", I18N_NOOP("Form Designer Part"), "0.3");
91 return about;
92}
93
94// copied from kfd_part.cpp
95class KFDPart_FormManager : public KFormDesigner::FormManager
96{
97 public:
102 KFDPart_FormManager(KFormDesignerPart *part, int options = 0, const char *name = 0)
103 : KFormDesigner::FormManager(part, options, name)
104 , m_part(part)
105 {
106 }
107
108 virtual TDEAction* action( const char* name)
109 {
110 return m_part->actionCollection()->action( name );
111 }
112
113 virtual void enableAction( const char* name, bool enable ) {
114 if(m_part->actionCollection()->action( name ))
115 m_part->actionCollection()->action( name )->setEnabled( enable );
116 }
117
118 KFormDesignerPart *m_part;
119};
120
122
123KFormDesigner::WidgetLibrary* KFormDesignerKDevPart::static_formsLibrary = 0L;
124
125KFormDesignerKDevPart::KFormDesignerKDevPart(TQWidget *parent, const char *name, bool readOnly, const TQStringList &args)
126: Designer(parent, name), m_count(0)
127{
128 setInstance(KFDFactory::instance());
129 instance()->iconLoader()->addAppDir("kexi");
130 instance()->iconLoader()->addAppDir("kformdesigner");
131
132 setReadWrite(!readOnly);
133 m_uniqueFormMode = true;
134 m_openingFile = false;
135
136 if(!args.grep("multipleMode").isEmpty())
137 setUniqueFormMode(false);
138 m_inShell = (!args.grep("shell").isEmpty());
139
140 TQHBox *container = new TQHBox(parent, "kfd_container_widget");
141 container->setFocusPolicy(TQWidget::ClickFocus);
142
143 m_workspace = new TQWorkspace(container, "kfd_workspace");
144 m_workspace->show();
145 TQStringList supportedFactoryGroups;
146/* @todo add configuration for supported factory groups */
148 new KFDPart_FormManager(this, 0, "kfd_manager"), supportedFactoryGroups );
149
150 if(!readOnly)
151 {
152 TQDockArea *dockArea = new TQDockAreaQt::Vertical, TQDockArea::Reverse, container, "kfd_part_dockarea");
153
154 TQDockWindow *dockTree = new TQDockWindow(dockArea);
156 dockTree->setWidget(view);
157 dockTree->setCaption(i18n("Objects"));
158 dockTree->setResizeEnabled(true);
159 dockTree->setFixedExtentWidth(256);
160
161 TQDockWindow *dockEditor = new TQDockWindow(dockArea);
162 KoProperty::Editor *editor = new KoProperty::Editor(dockEditor);
163 dockEditor->setWidget(editor);
164 dockEditor->setCaption(i18n("Properties"));
165 dockEditor->setResizeEnabled(true);
166
169
170 setupActions();
171 setModified(false);
172
173 // action stuff
174 connect(KFormDesigner::FormManager::self(), TQ_SIGNAL(widgetSelected(KFormDesigner::Form*, bool)), TQ_SLOT(slotWidgetSelected(KFormDesigner::Form*, bool)));
175 connect(KFormDesigner::FormManager::self(), TQ_SIGNAL(formWidgetSelected(KFormDesigner::Form*)), TQ_SLOT(slotFormWidgetSelected(KFormDesigner::Form*)));
176 connect(KFormDesigner::FormManager::self(), TQ_SIGNAL(noFormSelected()), TQ_SLOT(slotNoFormSelected()));
177 connect(KFormDesigner::FormManager::self(), TQ_SIGNAL(undoEnabled(bool, const TQString&)), TQ_SLOT(setUndoEnabled(bool, const TQString&)));
178 connect(KFormDesigner::FormManager::self(), TQ_SIGNAL(redoEnabled(bool, const TQString&)), TQ_SLOT(setRedoEnabled(bool, const TQString&)));
179
180 connect(KFormDesigner::FormManager::self(), TQ_SIGNAL(dirty(KFormDesigner::Form*, bool)), this, TQ_SLOT(slotFormModified(KFormDesigner::Form*, bool)));
181
182 connect(KFormDesigner::FormManager::self(), TQ_SIGNAL(createFormSlot(KFormDesigner::Form*, const TQString&, const TQString&)),
183 this, TQ_SLOT(slotCreateFormSlot(KFormDesigner::Form*, const TQString&, const TQString &)));
184 }
185
186 container->show();
187 setWidget(container);
188 connect(m_workspace, TQ_SIGNAL(windowActivated(TQWidget*)), KFormDesigner::FormManager::self(), TQ_SLOT(windowChanged(TQWidget*)));
189 slotNoFormSelected();
190}
191
192KFormDesigner::WidgetLibrary* KFormDesignerKDevPart::formsLibrary()
193{
194 return static_formsLibrary;
195}
196
197void
198KFormDesignerKDevPart::setupActions()
199{
200 KStdAction::open(this, TQ_SLOT(open()), actionCollection());
201 KStdAction::openNew(this, TQ_SLOT(createBlankForm()), actionCollection());
202 KStdAction::save(this, TQ_SLOT(save()), actionCollection());
203 KStdAction::saveAs(this, TQ_SLOT(saveAs()), actionCollection());
204 KStdAction::cut(KFormDesigner::FormManager::self(), TQ_SLOT(cutWidget()), actionCollection());
205 KStdAction::copy(KFormDesigner::FormManager::self(), TQ_SLOT(copyWidget()), actionCollection());
206 KStdAction::paste(KFormDesigner::FormManager::self(), TQ_SLOT(pasteWidget()), actionCollection());
207 KStdAction::undo(KFormDesigner::FormManager::self(), TQ_SLOT(undo()), actionCollection());
208 KStdAction::redo(KFormDesigner::FormManager::self(), TQ_SLOT(redo()), actionCollection());
209 KStdAction::selectAll(KFormDesigner::FormManager::self(), TQ_SLOT(selectAll()), actionCollection());
210 new TDEAction(i18n("Clear Widget Contents"), "edit-clear", TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(clearWidgetContent()), actionCollection(), "clear_contents");
211 new TDEAction(i18n("Delete Widget"), "edit-delete", TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(deleteWidget()), actionCollection(), "edit_delete");
212 new TDEAction(i18n("Preview Form"), "document-print-preview", "Ctrl+T", this, TQ_SLOT(slotPreviewForm()), actionCollection(), "preview_form");
213 new TDEAction(i18n("Edit Tab Order"), "tab_order", TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(editTabOrder()), actionCollection(), "taborder");
214 new TDEAction(i18n("Edit Pixmap Collection"), "icons", TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(editFormPixmapCollection()), actionCollection(), "pixmap_collection");
215 new TDEAction(i18n("Edit Form Connections"), "connections", TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(editConnections()), actionCollection(), "form_connections");
216
217 new TDEAction(i18n("Lay Out Widgets &Horizontally"), TQString(), TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(layoutHBox()), actionCollection(), "layout_hbox");
218 new TDEAction(i18n("Lay Out Widgets &Vertically"), TQString(), TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(layoutVBox()), actionCollection(), "layout_vbox");
219 new TDEAction(i18n("Lay Out Widgets in &Grid"), TQString(), TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(layoutGrid()), actionCollection(), "layout_grid");
220 new TDEAction(i18n("&Break Layout"), TQString(), TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(breakLayout()), actionCollection(), "break_layout");
221
222 new TDEAction(i18n("Bring Widget to Front"), "raise", TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(bringWidgetToFront()), actionCollection(), "format_raise");
223 new TDEAction(i18n("Send Widget to Back"), "lower", TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(sendWidgetToBack()), actionCollection(), "format_lower");
224
225 TDEActionMenu *alignMenu = new TDEActionMenu(i18n("Align Widgets' Positions"), "aopos2grid", actionCollection(), "align_menu");
226 alignMenu->insert( new TDEAction(i18n("To Left"), "aoleft", TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(alignWidgetsToLeft()), actionCollection(), "align_to_left") );
227 alignMenu->insert( new TDEAction(i18n("To Right"), "aoright", TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(alignWidgetsToRight()), actionCollection(), "align_to_right") );
228 alignMenu->insert( new TDEAction(i18n("To Top"), "aotop", TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(alignWidgetsToTop()), actionCollection(), "align_to_top") );
229 alignMenu->insert( new TDEAction(i18n("To Bottom"), "aobottom", TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(alignWidgetsToBottom()), actionCollection(), "align_to_bottom") );
230 alignMenu->insert( new TDEAction(i18n("To Grid"), "aopos2grid", TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(alignWidgetsToGrid()), actionCollection(), "align_to_grid") );
231
232 TDEActionMenu *sizeMenu = new TDEActionMenu(i18n("Adjust Widgets' Sizes"), "aogrid", actionCollection(), "adjust_size_menu");
233 sizeMenu->insert( new TDEAction(i18n("To Fit"), "aofit", TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(adjustWidgetSize()), actionCollection(), "adjust_to_fit") );
234 sizeMenu->insert( new TDEAction(i18n("To Grid"), "aogrid", TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(adjustSizeToGrid()), actionCollection(), "adjust_size_grid") );
235 sizeMenu->insert( new TDEAction(i18n("To Shortest"), "aoshortest", TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(adjustHeightToSmall()), actionCollection(), "adjust_height_small") );
236 sizeMenu->insert( new TDEAction(i18n("To Tallest"), "aotallest", TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(adjustHeightToBig()), actionCollection(), "adjust_height_big") );
237 sizeMenu->insert( new TDEAction(i18n("To Narrowest"), "aonarrowest", TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(adjustWidthToSmall()), actionCollection(), "adjust_width_small") );
238 sizeMenu->insert( new TDEAction(i18n("To Widest"), "aowidest", TDEShortcut(0), KFormDesigner::FormManager::self(), TQ_SLOT(adjustWidthToBig()), actionCollection(), "adjust_width_big") );
239
240 if(m_inShell)
241 setXMLFile("kformdesigner_part_shell.rc");
242 else
243 setXMLFile("kformdesigner_part.rc");
244 KFormDesigner::FormManager::self()->createActions(formsLibrary(), actionCollection(), this);
245}
246
247void
248KFormDesignerKDevPart::createBlankForm()
249{
250 if(KFormDesigner::FormManager::self()->activeForm() && m_uniqueFormMode)
251 {
252 m_openingFile = true;
253 closeURL();
254 m_openingFile = false;
255 }
256
257 if(m_uniqueFormMode && KFormDesigner::FormManager::self()->activeForm() && !KFormDesigner::FormManager::self()->activeForm()->isModified() && KFormDesigner::FormManager::self()->activeForm()->filename().isNull())
258 return; // active form is already a blank one
259
260 TQString n = i18n("Form") + TQString::number(++m_count);
261 Form *form = new Form(formsLibrary(), n.latin1());
262 FormWidgetBase *w = new FormWidgetBase(this, m_workspace, n.latin1());
263
264 w->setCaption(n);
265 w->setIcon(SmallIcon("form"));
266 w->resize(350, 300);
267 w->show();
268 w->setFocus();
269
270 form->createToplevel(w, w);
272}
273
274void
275KFormDesignerKDevPart::open()
276{
277 m_openingFile = true;
278 KURL url = KFileDialog::getOpenURL("::kformdesigner", i18n("*.ui|TQt Designer UI Files"), m_workspace->topLevelWidget());
279 if(!url.isEmpty())
280 ReadWritePart::openURL(url);
281 m_openingFile = false;
282}
283
284bool
285KFormDesignerKDevPart::openFile()
286{
287 Form *form = new Form(formsLibrary());
288 FormWidgetBase *w = new FormWidgetBase(this, m_workspace);
289 form->createToplevel(w, w);
290
291 if(!KFormDesigner::FormIO::loadForm(form, w, m_file))
292 {
293 delete form;
294 delete w;
295 return false;
296 }
297
298 w->show();
299 KFormDesigner::FormManager::self()->importForm(form, !isReadWrite());
300 return true;
301}
302
303bool
304KFormDesignerKDevPart::saveFile()
305{
306 KFormDesigner::FormIO::saveForm(KFormDesigner::FormManager::self()->activeForm(), m_file);
307 return true;
308}
309
310void
311KFormDesignerKDevPart::saveAs()
312{
313 KURL url = KFileDialog::getSaveURL("::kformdesigner", i18n("*.ui|TQt Designer UI Files"), m_workspace);
314 if(url.isEmpty())
315 return;
316 else
317 ReadWritePart::saveAs(url);
318}
319
320bool
321KFormDesignerKDevPart::closeForm(Form *form)
322{
323 int res = KMessageBox::warningYesNoCancel( m_workspace->topLevelWidget(),
324 i18n( "The form \"%1\" has been modified.\n"
325 "Do you want to save your changes or discard them?" ).arg( form->objectTree()->name() ),
326 i18n( "Close Form" ), KStdGuiItem::save(), KStdGuiItem::discard() );
327
328 if(res == KMessageBox::Yes)
329 save();
330
331 return (res != KMessageBox::Cancel);
332}
333
334bool
335KFormDesignerKDevPart::closeForms()
336{
337 TQWidgetList list = m_workspace->windowList(TQWorkspace::CreationOrder);
338 for(TQWidget *w = list.first(); w; w = list.next())
339 if(w->close() == false)
340 return false;
341
342 return true;
343}
344
345bool
346KFormDesignerKDevPart::closeURL()
347{
348 if(!KFormDesigner::FormManager::self()->activeForm())
349 return true;
350
351 if(m_uniqueFormMode || !m_openingFile)
352 return closeForms();
353
354 return true;
355}
356
357void
358KFormDesignerKDevPart::slotFormModified(Form *, bool isDirty)
359{
360 setModified(isDirty);
361}
362
363void
364KFormDesignerKDevPart::slotPreviewForm()
365{
366 if(!KFormDesigner::FormManager::self()->activeForm())
367 return;
368
369 FormWidgetBase *w = new FormWidgetBase(this, m_workspace);
371}
372
373void
374KFormDesignerKDevPart::slotWidgetSelected(Form *form, bool multiple)
375{
376 enableFormActions();
377 // Enable edit actions
378 ENABLE_ACTION("edit_copy", true);
379 ENABLE_ACTION("edit_cut", true);
380 ENABLE_ACTION("edit_delete", true);
381 ENABLE_ACTION("clear_contents", true);
382
383 // 'Align Widgets' menu
384 ENABLE_ACTION("align_menu", multiple);
385 ENABLE_ACTION("align_to_left", multiple);
386 ENABLE_ACTION("align_to_right", multiple);
387 ENABLE_ACTION("align_to_top", multiple);
388 ENABLE_ACTION("align_to_bottom", multiple);
389
390 ENABLE_ACTION("adjust_size_menu", true);
391 ENABLE_ACTION("adjust_width_small", multiple);
392 ENABLE_ACTION("adjust_width_big", multiple);
393 ENABLE_ACTION("adjust_height_small", multiple);
394 ENABLE_ACTION("adjust_height_big", multiple);
395
396 ENABLE_ACTION("format_raise", true);
397 ENABLE_ACTION("format_lower", true);
398
399 // If the widgets selected is a container, we enable layout actions
400 if(!multiple)
401 {
402 KFormDesigner::ObjectTreeItem *item = form->objectTree()->lookup( form->selectedWidgets()->first()->name() );
403 if(item && item->container())
404 multiple = true;
405 }
406 // Layout actions
407 ENABLE_ACTION("layout_hbox", multiple);
408 ENABLE_ACTION("layout_vbox", multiple);
409 ENABLE_ACTION("layout_grid", multiple);
410
411 KFormDesigner::Container *container = KFormDesigner::FormManager::self()->activeForm()->activeContainer();
412 ENABLE_ACTION("break_layout", (container->layoutType() != KFormDesigner::Container::NoLayout));
413}
414
415void
416KFormDesignerKDevPart::slotFormWidgetSelected(Form *form)
417{
418 disableWidgetActions();
419 enableFormActions();
420
421 // Layout actions
422 ENABLE_ACTION("layout_hbox", true);
423 ENABLE_ACTION("layout_vbox", true);
424 ENABLE_ACTION("layout_grid", true);
425 ENABLE_ACTION("break_layout", (form->toplevelContainer()->layoutType() != KFormDesigner::Container::NoLayout));
426}
427
428void
429KFormDesignerKDevPart::slotNoFormSelected()
430{
431 disableWidgetActions();
432
433 // Disable paste action
434 ENABLE_ACTION("edit_paste", false);
435
436 ENABLE_ACTION("edit_undo", false);
437 ENABLE_ACTION("edit_redo", false);
438
439 // Disable 'Tools' actions
440 ENABLE_ACTION("pixmap_collection", false);
441 ENABLE_ACTION("form_connections", false);
442 ENABLE_ACTION("taborder", false);
443 ENABLE_ACTION("change_style", false);
444
445 // Disable items in 'File'
446 ENABLE_ACTION("file_save", false);
447 ENABLE_ACTION("file_save_as", false);
448 ENABLE_ACTION("preview_form", false);
449}
450
451void
452KFormDesignerKDevPart::enableFormActions()
453{
454 // Enable 'Tools' actions
455 ENABLE_ACTION("pixmap_collection", true);
456 ENABLE_ACTION("form_connections", true);
457 ENABLE_ACTION("taborder", true);
458 ENABLE_ACTION("change_style", true);
459
460 // Enable items in 'File'
461 ENABLE_ACTION("file_save", true);
462 ENABLE_ACTION("file_save_as", true);
463 ENABLE_ACTION("preview_form", true);
464
465 ENABLE_ACTION("edit_paste", KFormDesigner::FormManager::self()->isPasteEnabled());
466 ENABLE_ACTION("edit_select_all", true);
467}
468
469void
470KFormDesignerKDevPart::disableWidgetActions()
471{
472 // Disable edit actions
473 ENABLE_ACTION("edit_copy", false);
474 ENABLE_ACTION("edit_cut", false);
475 ENABLE_ACTION("edit_delete", false);
476 ENABLE_ACTION("clear_contents", false);
477
478 // Disable format functions
479 ENABLE_ACTION("align_menu", false);
480 ENABLE_ACTION("align_to_left", false);
481 ENABLE_ACTION("align_to_right", false);
482 ENABLE_ACTION("align_to_top", false);
483 ENABLE_ACTION("align_to_bottom", false);
484 ENABLE_ACTION("adjust_size_menu", false);
485 ENABLE_ACTION("format_raise", false);
486 ENABLE_ACTION("format_lower", false);
487
488 ENABLE_ACTION("layout_hbox", false);
489 ENABLE_ACTION("layout_vbox", false);
490 ENABLE_ACTION("layout_grid", false);
491 ENABLE_ACTION("break_layout", false);
492}
493
494void
495KFormDesignerKDevPart::setUndoEnabled(bool enabled, const TQString &text)
496{
497 TDEAction *undoAction = actionCollection()->action("edit_undo");
498 if(undoAction)
499 {
500 undoAction->setEnabled(enabled);
501 if(!text.isNull())
502 undoAction->setText(text);
503 }
504}
505
506void
507KFormDesignerKDevPart::setRedoEnabled(bool enabled, const TQString &text)
508{
509 TDEAction *redoAction = actionCollection()->action("edit_redo");
510 if(redoAction)
511 {
512 redoAction->setEnabled(enabled);
513 if(!text.isNull())
514 redoAction->setText(text);
515 }
516}
517
518void
519KFormDesignerKDevPart::slotCreateFormSlot(Form *form, const TQString &widget, const TQString &signal)
520{
521 Function f;
522 f.returnType = "void";
523 f.function = widget + "_" + signal;
524 f.specifier = "non virtual";
525 f.access = "public";
526 f.type = ftTQtSlot;
527 emit addedFunction(designerType(), form->objectTree()->name(), f);
528}
529
530KFormDesignerKDevPart::~KFormDesignerKDevPart()
531{
532}
533
534
536
537//repaint all children widgets
538static void repaintAll(TQWidget *w)
539{
540 TQObjectList *list = w->queryList("TQWidget");
541 TQObjectListIt it(*list);
542 for (TQObject *obj; (obj=it.current()); ++it ) {
543 static_cast<TQWidget*>(obj)->repaint();
544 }
545 delete list;
546}
547
548void
549FormWidgetBase::drawRects(const TQValueList<TQRect> &list, int type)
550{
551 TQPainter p;
552 p.begin(this, true);
553 bool unclipped = testWFlags( WPaintUnclipped );
554 setWFlags( WPaintUnclipped );
555
556 if (prev_rect.isValid()) {
557 //redraw prev. selection's rectangle
558 p.drawPixmap( TQPoint(prev_rect.x()-2, prev_rect.y()-2), buffer, TQRect(prev_rect.x()-2, prev_rect.y()-2, prev_rect.width()+4, prev_rect.height()+4));
559 }
560 p.setBrush(TQBrush::NoBrush);
561 if(type == 1) // selection rect
562 p.setPen(TQPen(white, 1, TQt::DotLine));
563 else if(type == 2) // insert rect
564 p.setPen(TQPen(white, 2));
565 p.setRasterOp(XorROP);
566
567 prev_rect = TQRect();
568 TQValueList<TQRect>::ConstIterator endIt = list.constEnd();
569 for(TQValueList<TQRect>::ConstIterator it = list.constBegin(); it != endIt; ++it) {
570 p.drawRect(*it);
571 prev_rect = prev_rect.unite(*it);
572 }
573
574 if (!unclipped)
575 clearWFlags( WPaintUnclipped );
576 p.end();
577}
578
579void
580FormWidgetBase::drawRect(const TQRect& r, int type)
581{
582 TQValueList<TQRect> l;
583 l.append(r);
584 drawRects(l, type);
585}
586
587void
588FormWidgetBase::initRect()
589{
590 repaintAll(this);
591 buffer.resize( width(), height() );
592 buffer = TQPixmap::grabWindow( winId() );
593 prev_rect = TQRect();
594}
595
596void
597FormWidgetBase::clearRect()
598{
599 TQPainter p;
600 p.begin(this, true);
601 bool unclipped = testWFlags( WPaintUnclipped );
602 setWFlags( WPaintUnclipped );
603
604 //redraw entire form surface
605 p.drawPixmap( TQPoint(0,0), buffer, TQRect(0,0,buffer.width(), buffer.height()) );
606
607 if (!unclipped)
608 clearWFlags( WPaintUnclipped );
609 p.end();
610
611 repaintAll(this);
612}
613
614void
615FormWidgetBase::highlightWidgets(TQWidget *from, TQWidget *to)//, const TQPoint &point)
616{
617 TQPoint fromPoint, toPoint;
618 if(from && from->parentWidget() && (from != this))
619 fromPoint = from->parentWidget()->mapTo(this, from->pos());
620 if(to && to->parentWidget() && (to != this))
621 toPoint = to->parentWidget()->mapTo(this, to->pos());
622
623 TQPainter p;
624 p.begin(this, true);
625 bool unclipped = testWFlags( WPaintUnclipped );
626 setWFlags( WPaintUnclipped );
627
628 if (prev_rect.isValid()) {
629 //redraw prev. selection's rectangle
630 p.drawPixmap( TQPoint(prev_rect.x(), prev_rect.y()), buffer, TQRect(prev_rect.x(), prev_rect.y(), prev_rect.width(), prev_rect.height()));
631 }
632
633 p.setPen( TQPen(TQt::red, 2) );
634
635 if(to)
636 {
637 TQPixmap pix1 = TQPixmap::grabWidget(from);
638 TQPixmap pix2 = TQPixmap::grabWidget(to);
639
640 if((from != this) && (to != this))
641 p.drawLine( from->parentWidget()->mapTo(this, from->geometry().center()), to->parentWidget()->mapTo(this, to->geometry().center()) );
642
643 p.drawPixmap(fromPoint.x(), fromPoint.y(), pix1);
644 p.drawPixmap(toPoint.x(), toPoint.y(), pix2);
645
646 if(to == this)
647 p.drawRoundRect(2, 2, width()-4, height()-4, 4, 4);
648 else
649 p.drawRoundRect(toPoint.x(), toPoint.y(), to->width(), to->height(), 5, 5);
650 }
651
652 if(from == this)
653 p.drawRoundRect(2, 2, width()-4, height()-4, 4, 4);
654 else
655 p.drawRoundRect(fromPoint.x(), fromPoint.y(), from->width(), from->height(), 5, 5);
656
657 if((to == this) || (from == this))
658 prev_rect = TQRect(0, 0, buffer.width(), buffer.height());
659 else if(to)
660 {
661 prev_rect.setX( (fromPoint.x() < toPoint.x()) ? (fromPoint.x() - 5) : (toPoint.x() - 5) );
662 prev_rect.setY( (fromPoint.y() < toPoint.y()) ? (fromPoint.y() - 5) : (toPoint.y() - 5) );
663 prev_rect.setRight( (fromPoint.x() < toPoint.x()) ? (toPoint.x() + to->width() + 10) : (fromPoint.x() + from->width() + 10) );
664 prev_rect.setBottom( (fromPoint.y() < toPoint.y()) ? (toPoint.y() + to->height() + 10) : (fromPoint.y() + from->height() + 10) ) ;
665 }
666 else
667 prev_rect = TQRect(fromPoint.x()- 5, fromPoint.y() -5, from->width() + 10, from->height() + 10);
668
669 if (!unclipped)
670 clearWFlags( WPaintUnclipped );
671 p.end();
672}
673
674void
675FormWidgetBase::closeEvent(TQCloseEvent *ev)
676{
678 if(!form || !form->isModified() || !form->objectTree()) // == preview form
679 ev->accept();
680 else
681 {
682 bool close = m_part->closeForm(form);
683 if(close)
684 ev->accept();
685 else
686 ev->ignore();
687 }
688}
689
690K_EXPORT_COMPONENT_FACTORY(libkformdesigner_kdev_part, KFDFactory)
691
692#include "kfd_kdev_part.moc"
693
void highlightWidgets(TQWidget *from, TQWidget *to)
void drawRects(const TQValueList< TQRect > &list, int type)
LayoutType layoutType() const
Definition container.h:110
A class to manage (create/load/save) Forms.
Definition formmanager.h:73
void importForm(Form *form=0, bool preview=false)
static FormManager * self()
Access to FormManager singleton.
Form * formForWidget(TQWidget *w)
void setEditor(KoProperty::Editor *editor)
FormManager(TQObject *parent=0, int options=0, const char *name=0)
void setObjectTreeView(ObjectTreeView *treeview)
void previewForm(Form *form, TQWidget *w, Form *toForm=0)
static WidgetLibrary * createWidgetLibrary(FormManager *m, const TQStringList &supportedFactoryGroups)
ActionList createActions(WidgetLibrary *lib, TDEActionCollection *collection, KXMLGUIClient *client)
A simple class representing a form.
Definition form.h:136
Container * toplevelContainer() const
Definition form.h:161
WidgetList * selectedWidgets() const
Definition form.h:192
Container * activeContainer()
Definition form.cpp:151
ObjectTree * objectTree() const
Definition form.h:167
void createToplevel(TQWidget *container, FormWidget *formWidget=0, const TQCString &classname="TQWidget")
Definition form.cpp:127
Container * container() const
Definition objecttree.h:76
A graphical view of Form's ObjectTree. This is a TDEListView which represents an item for each widget...
ObjectTreeItem * lookup(const TQString &name)
This class searches for factories and provides TDEActions for widget creation.