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