00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <qworkspace.h>
00021 #include <qdockarea.h>
00022 #include <qdockwindow.h>
00023 #include <qhbox.h>
00024 #include <qpainter.h>
00025 #include <qevent.h>
00026 #include <qobjectlist.h>
00027
00028 #include <kdeversion.h>
00029 #include <kaction.h>
00030 #include <kinstance.h>
00031 #include <klocale.h>
00032 #include <kaboutdata.h>
00033 #include <kdebug.h>
00034 #include <kstdaction.h>
00035 #include <kapplication.h>
00036 #include <kiconloader.h>
00037 #include <kfiledialog.h>
00038 #include <klibloader.h>
00039 #include <kmessagebox.h>
00040
00041 #include "form.h"
00042 #include "formIO.h"
00043 #include "objecttree.h"
00044 #include "container.h"
00045 #include "formmanager.h"
00046 #include "objecttreeview.h"
00047
00048 #include "kfd_kdev_part.h"
00049
00050 #define ENABLE_ACTION(name, enable) \
00051 if(actionCollection()->action( name )) \
00052 actionCollection()->action( name )->setEnabled( enable )
00053
00054 KInstance *KFDFactory::m_instance = 0L;
00055
00056 KFDFactory::KFDFactory()
00057 : KParts::Factory(0, "libkformdesigner_kdev_part")
00058 {}
00059
00060 KFDFactory::~KFDFactory()
00061 {
00062 if (m_instance)
00063 {
00064 delete m_instance->aboutData();
00065 delete m_instance;
00066 }
00067
00068 m_instance = 0;
00069 }
00070
00071 KParts::Part*
00072 KFDFactory::createPartObject( QWidget *parentWidget, const char *, QObject *, const char *name,
00073 const char *classname, const QStringList &args)
00074 {
00075 bool readOnly = (classname == "KParts::ReadOnlyPart");
00076 KFormDesignerKDevPart *part = new KFormDesignerKDevPart(parentWidget, name, readOnly, args);
00077 return part;
00078 }
00079
00080 KInstance*
00081 KFDFactory::instance()
00082 {
00083 if (!m_instance)
00084 m_instance = new KInstance(aboutData());
00085 return m_instance;
00086 }
00087
00088 KAboutData*
00089 KFDFactory::aboutData()
00090 {
00091 KAboutData *about = new KAboutData("kformdesigner_kdev_part", I18N_NOOP("Form Designer Part"), "0.3");
00092 return about;
00093 }
00094
00095
00096 class KFDPart_FormManager : public KFormDesigner::FormManager
00097 {
00098 public:
00103 KFDPart_FormManager(KFormDesignerPart *part, int options = 0, const char *name = 0)
00104 : KFormDesigner::FormManager(part, options, name)
00105 , m_part(part)
00106 {
00107 }
00108
00109 virtual KAction* action( const char* name)
00110 {
00111 return m_part->actionCollection()->action( name );
00112 }
00113
00114 virtual void enableAction( const char* name, bool enable ) {
00115 if(m_part->actionCollection()->action( name ))
00116 m_part->actionCollection()->action( name )->setEnabled( enable );
00117 }
00118
00119 KFormDesignerPart *m_part;
00120 };
00121
00123
00124 KFormDesigner::WidgetLibrary* KFormDesignerKDevPart::static_formsLibrary = 0L;
00125
00126 KFormDesignerKDevPart::KFormDesignerKDevPart(QWidget *parent, const char *name, bool readOnly, const QStringList &args)
00127 : Designer(parent, name), m_count(0)
00128 {
00129 setInstance(KFDFactory::instance());
00130 instance()->iconLoader()->addAppDir("kexi");
00131 instance()->iconLoader()->addAppDir("kformdesigner");
00132
00133 setReadWrite(!readOnly);
00134 m_uniqueFormMode = true;
00135 m_openingFile = false;
00136
00137 if(!args.grep("multipleMode").isEmpty())
00138 setUniqueFormMode(false);
00139 m_inShell = (!args.grep("shell").isEmpty());
00140
00141 QHBox *container = new QHBox(parent, "kfd_container_widget");
00142 container->setFocusPolicy(QWidget::ClickFocus);
00143
00144 m_workspace = new QWorkspace(container, "kfd_workspace");
00145 m_workspace->show();
00146 QStringList supportedFactoryGroups;
00147
00148 static_formsLibrary = KFormDesigner::FormManager::createWidgetLibrary(
00149 new KFDPart_FormManager(this, 0, "kfd_manager"), supportedFactoryGroups );
00150
00151 if(!readOnly)
00152 {
00153 QDockArea *dockArea = new QDockArea(Vertical, QDockArea::Reverse, container, "kfd_part_dockarea");
00154
00155 QDockWindow *dockTree = new QDockWindow(dockArea);
00156 KFormDesigner::ObjectTreeView *view = new KFormDesigner::ObjectTreeView(dockTree);
00157 dockTree->setWidget(view);
00158 dockTree->setCaption(i18n("Objects"));
00159 dockTree->setResizeEnabled(true);
00160 dockTree->setFixedExtentWidth(256);
00161
00162 QDockWindow *dockEditor = new QDockWindow(dockArea);
00163 KoProperty::Editor *editor = new KoProperty::Editor(dockEditor);
00164 dockEditor->setWidget(editor);
00165 dockEditor->setCaption(i18n("Properties"));
00166 dockEditor->setResizeEnabled(true);
00167
00168 KFormDesigner::FormManager::self()->setEditor(editor);
00169 KFormDesigner::FormManager::self()->setObjectTreeView(view);
00170
00171 setupActions();
00172 setModified(false);
00173
00174
00175 connect(KFormDesigner::FormManager::self(), SIGNAL(widgetSelected(KFormDesigner::Form*, bool)), SLOT(slotWidgetSelected(KFormDesigner::Form*, bool)));
00176 connect(KFormDesigner::FormManager::self(), SIGNAL(formWidgetSelected(KFormDesigner::Form*)), SLOT(slotFormWidgetSelected(KFormDesigner::Form*)));
00177 connect(KFormDesigner::FormManager::self(), SIGNAL(noFormSelected()), SLOT(slotNoFormSelected()));
00178 connect(KFormDesigner::FormManager::self(), SIGNAL(undoEnabled(bool, const QString&)), SLOT(setUndoEnabled(bool, const QString&)));
00179 connect(KFormDesigner::FormManager::self(), SIGNAL(redoEnabled(bool, const QString&)), SLOT(setRedoEnabled(bool, const QString&)));
00180
00181 connect(KFormDesigner::FormManager::self(), SIGNAL(dirty(KFormDesigner::Form*, bool)), this, SLOT(slotFormModified(KFormDesigner::Form*, bool)));
00182
00183 connect(KFormDesigner::FormManager::self(), SIGNAL(createFormSlot(KFormDesigner::Form*, const QString&, const QString&)),
00184 this, SLOT(slotCreateFormSlot(KFormDesigner::Form*, const QString&, const QString &)));
00185 }
00186
00187 container->show();
00188 setWidget(container);
00189 connect(m_workspace, SIGNAL(windowActivated(QWidget*)), KFormDesigner::FormManager::self(), SLOT(windowChanged(QWidget*)));
00190 slotNoFormSelected();
00191 }
00192
00193 KFormDesigner::WidgetLibrary* KFormDesignerKDevPart::formsLibrary()
00194 {
00195 return static_formsLibrary;
00196 }
00197
00198 void
00199 KFormDesignerKDevPart::setupActions()
00200 {
00201 KStdAction::open(this, SLOT(open()), actionCollection());
00202 KStdAction::openNew(this, SLOT(createBlankForm()), actionCollection());
00203 KStdAction::save(this, SLOT(save()), actionCollection());
00204 KStdAction::saveAs(this, SLOT(saveAs()), actionCollection());
00205 KStdAction::cut(KFormDesigner::FormManager::self(), SLOT(cutWidget()), actionCollection());
00206 KStdAction::copy(KFormDesigner::FormManager::self(), SLOT(copyWidget()), actionCollection());
00207 KStdAction::paste(KFormDesigner::FormManager::self(), SLOT(pasteWidget()), actionCollection());
00208 KStdAction::undo(KFormDesigner::FormManager::self(), SLOT(undo()), actionCollection());
00209 KStdAction::redo(KFormDesigner::FormManager::self(), SLOT(redo()), actionCollection());
00210 KStdAction::selectAll(KFormDesigner::FormManager::self(), SLOT(selectAll()), actionCollection());
00211 new KAction(i18n("Clear Widget Contents"), "editclear", KShortcut(0), KFormDesigner::FormManager::self(), SLOT(clearWidgetContent()), actionCollection(), "clear_contents");
00212 new KAction(i18n("Delete Widget"), "editdelete", KShortcut(0), KFormDesigner::FormManager::self(), SLOT(deleteWidget()), actionCollection(), "edit_delete");
00213 new KAction(i18n("Preview Form"), "filequickprint", "Ctrl+T", this, SLOT(slotPreviewForm()), actionCollection(), "preview_form");
00214 new KAction(i18n("Edit Tab Order"), "tab_order", KShortcut(0), KFormDesigner::FormManager::self(), SLOT(editTabOrder()), actionCollection(), "taborder");
00215 new KAction(i18n("Edit Pixmap Collection"), "icons", KShortcut(0), KFormDesigner::FormManager::self(), SLOT(editFormPixmapCollection()), actionCollection(), "pixmap_collection");
00216 new KAction(i18n("Edit Form Connections"), "connections", KShortcut(0), KFormDesigner::FormManager::self(), SLOT(editConnections()), actionCollection(), "form_connections");
00217
00218 new KAction(i18n("Lay Out Widgets &Horizontally"), QString::null, KShortcut(0), KFormDesigner::FormManager::self(), SLOT(layoutHBox()), actionCollection(), "layout_hbox");
00219 new KAction(i18n("Lay Out Widgets &Vertically"), QString::null, KShortcut(0), KFormDesigner::FormManager::self(), SLOT(layoutVBox()), actionCollection(), "layout_vbox");
00220 new KAction(i18n("Lay Out Widgets in &Grid"), QString::null, KShortcut(0), KFormDesigner::FormManager::self(), SLOT(layoutGrid()), actionCollection(), "layout_grid");
00221 new KAction(i18n("&Break Layout"), QString::null, KShortcut(0), KFormDesigner::FormManager::self(), SLOT(breakLayout()), actionCollection(), "break_layout");
00222
00223 new KAction(i18n("Bring Widget to Front"), "raise", KShortcut(0), KFormDesigner::FormManager::self(), SLOT(bringWidgetToFront()), actionCollection(), "format_raise");
00224 new KAction(i18n("Send Widget to Back"), "lower", KShortcut(0), KFormDesigner::FormManager::self(), SLOT(sendWidgetToBack()), actionCollection(), "format_lower");
00225
00226 KActionMenu *alignMenu = new KActionMenu(i18n("Align Widgets' Positions"), "aopos2grid", actionCollection(), "align_menu");
00227 alignMenu->insert( new KAction(i18n("To Left"), "aoleft", KShortcut(0), KFormDesigner::FormManager::self(), SLOT(alignWidgetsToLeft()), actionCollection(), "align_to_left") );
00228 alignMenu->insert( new KAction(i18n("To Right"), "aoright", KShortcut(0), KFormDesigner::FormManager::self(), SLOT(alignWidgetsToRight()), actionCollection(), "align_to_right") );
00229 alignMenu->insert( new KAction(i18n("To Top"), "aotop", KShortcut(0), KFormDesigner::FormManager::self(), SLOT(alignWidgetsToTop()), actionCollection(), "align_to_top") );
00230 alignMenu->insert( new KAction(i18n("To Bottom"), "aobottom", KShortcut(0), KFormDesigner::FormManager::self(), SLOT(alignWidgetsToBottom()), actionCollection(), "align_to_bottom") );
00231 alignMenu->insert( new KAction(i18n("To Grid"), "aopos2grid", KShortcut(0), KFormDesigner::FormManager::self(), SLOT(alignWidgetsToGrid()), actionCollection(), "align_to_grid") );
00232
00233 KActionMenu *sizeMenu = new KActionMenu(i18n("Adjust Widgets' Sizes"), "aogrid", actionCollection(), "adjust_size_menu");
00234 sizeMenu->insert( new KAction(i18n("To Fit"), "aofit", KShortcut(0), KFormDesigner::FormManager::self(), SLOT(adjustWidgetSize()), actionCollection(), "adjust_to_fit") );
00235 sizeMenu->insert( new KAction(i18n("To Grid"), "aogrid", KShortcut(0), KFormDesigner::FormManager::self(), SLOT(adjustSizeToGrid()), actionCollection(), "adjust_size_grid") );
00236 sizeMenu->insert( new KAction(i18n("To Shortest"), "aoshortest", KShortcut(0), KFormDesigner::FormManager::self(), SLOT(adjustHeightToSmall()), actionCollection(), "adjust_height_small") );
00237 sizeMenu->insert( new KAction(i18n("To Tallest"), "aotallest", KShortcut(0), KFormDesigner::FormManager::self(), SLOT(adjustHeightToBig()), actionCollection(), "adjust_height_big") );
00238 sizeMenu->insert( new KAction(i18n("To Narrowest"), "aonarrowest", KShortcut(0), KFormDesigner::FormManager::self(), SLOT(adjustWidthToSmall()), actionCollection(), "adjust_width_small") );
00239 sizeMenu->insert( new KAction(i18n("To Widest"), "aowidest", KShortcut(0), KFormDesigner::FormManager::self(), SLOT(adjustWidthToBig()), actionCollection(), "adjust_width_big") );
00240
00241 if(m_inShell)
00242 setXMLFile("kformdesigner_part_shell.rc");
00243 else
00244 setXMLFile("kformdesigner_part.rc");
00245 KFormDesigner::FormManager::self()->createActions(formsLibrary(), actionCollection(), this);
00246 }
00247
00248 void
00249 KFormDesignerKDevPart::createBlankForm()
00250 {
00251 if(KFormDesigner::FormManager::self()->activeForm() && m_uniqueFormMode)
00252 {
00253 m_openingFile = true;
00254 closeURL();
00255 m_openingFile = false;
00256 }
00257
00258 if(m_uniqueFormMode && KFormDesigner::FormManager::self()->activeForm() && !KFormDesigner::FormManager::self()->activeForm()->isModified() && KFormDesigner::FormManager::self()->activeForm()->filename().isNull())
00259 return;
00260
00261 QString n = i18n("Form") + QString::number(++m_count);
00262 Form *form = new Form(formsLibrary(), n.latin1());
00263 FormWidgetBase *w = new FormWidgetBase(this, m_workspace, n.latin1());
00264
00265 w->setCaption(n);
00266 w->setIcon(SmallIcon("form"));
00267 w->resize(350, 300);
00268 w->show();
00269 w->setFocus();
00270
00271 form->createToplevel(w, w);
00272 KFormDesigner::FormManager::self()->importForm(form);
00273 }
00274
00275 void
00276 KFormDesignerKDevPart::open()
00277 {
00278 m_openingFile = true;
00279 KURL url = KFileDialog::getOpenURL("::kformdesigner", i18n("*.ui|Qt Designer UI Files"), m_workspace->topLevelWidget());
00280 if(!url.isEmpty())
00281 ReadWritePart::openURL(url);
00282 m_openingFile = false;
00283 }
00284
00285 bool
00286 KFormDesignerKDevPart::openFile()
00287 {
00288 Form *form = new Form(formsLibrary());
00289 FormWidgetBase *w = new FormWidgetBase(this, m_workspace);
00290 form->createToplevel(w, w);
00291
00292 if(!KFormDesigner::FormIO::loadForm(form, w, m_file))
00293 {
00294 delete form;
00295 delete w;
00296 return false;
00297 }
00298
00299 w->show();
00300 KFormDesigner::FormManager::self()->importForm(form, !isReadWrite());
00301 return true;
00302 }
00303
00304 bool
00305 KFormDesignerKDevPart::saveFile()
00306 {
00307 KFormDesigner::FormIO::saveForm(KFormDesigner::FormManager::self()->activeForm(), m_file);
00308 return true;
00309 }
00310
00311 void
00312 KFormDesignerKDevPart::saveAs()
00313 {
00314 KURL url = KFileDialog::getSaveURL("::kformdesigner", i18n("*.ui|Qt Designer UI Files"), m_workspace);
00315 if(url.isEmpty())
00316 return;
00317 else
00318 ReadWritePart::saveAs(url);
00319 }
00320
00321 bool
00322 KFormDesignerKDevPart::closeForm(Form *form)
00323 {
00324 int res = KMessageBox::warningYesNoCancel( m_workspace->topLevelWidget(),
00325 i18n( "The form \"%1\" has been modified.\n"
00326 "Do you want to save your changes or discard them?" ).arg( form->objectTree()->name() ),
00327 i18n( "Close Form" ), KStdGuiItem::save(), KStdGuiItem::discard() );
00328
00329 if(res == KMessageBox::Yes)
00330 save();
00331
00332 return (res != KMessageBox::Cancel);
00333 }
00334
00335 bool
00336 KFormDesignerKDevPart::closeForms()
00337 {
00338 QWidgetList list = m_workspace->windowList(QWorkspace::CreationOrder);
00339 for(QWidget *w = list.first(); w; w = list.next())
00340 if(w->close() == false)
00341 return false;
00342
00343 return true;
00344 }
00345
00346 bool
00347 KFormDesignerKDevPart::closeURL()
00348 {
00349 if(!KFormDesigner::FormManager::self()->activeForm())
00350 return true;
00351
00352 if(m_uniqueFormMode || !m_openingFile)
00353 return closeForms();
00354
00355 return true;
00356 }
00357
00358 void
00359 KFormDesignerKDevPart::slotFormModified(Form *, bool isDirty)
00360 {
00361 setModified(isDirty);
00362 }
00363
00364 void
00365 KFormDesignerKDevPart::slotPreviewForm()
00366 {
00367 if(!KFormDesigner::FormManager::self()->activeForm())
00368 return;
00369
00370 FormWidgetBase *w = new FormWidgetBase(this, m_workspace);
00371 KFormDesigner::FormManager::self()->previewForm(KFormDesigner::FormManager::self()->activeForm(), w);
00372 }
00373
00374 void
00375 KFormDesignerKDevPart::slotWidgetSelected(Form *form, bool multiple)
00376 {
00377 enableFormActions();
00378
00379 ENABLE_ACTION("edit_copy", true);
00380 ENABLE_ACTION("edit_cut", true);
00381 ENABLE_ACTION("edit_delete", true);
00382 ENABLE_ACTION("clear_contents", true);
00383
00384
00385 ENABLE_ACTION("align_menu", multiple);
00386 ENABLE_ACTION("align_to_left", multiple);
00387 ENABLE_ACTION("align_to_right", multiple);
00388 ENABLE_ACTION("align_to_top", multiple);
00389 ENABLE_ACTION("align_to_bottom", multiple);
00390
00391 ENABLE_ACTION("adjust_size_menu", true);
00392 ENABLE_ACTION("adjust_width_small", multiple);
00393 ENABLE_ACTION("adjust_width_big", multiple);
00394 ENABLE_ACTION("adjust_height_small", multiple);
00395 ENABLE_ACTION("adjust_height_big", multiple);
00396
00397 ENABLE_ACTION("format_raise", true);
00398 ENABLE_ACTION("format_lower", true);
00399
00400
00401 if(!multiple)
00402 {
00403 KFormDesigner::ObjectTreeItem *item = form->objectTree()->lookup( form->selectedWidgets()->first()->name() );
00404 if(item && item->container())
00405 multiple = true;
00406 }
00407
00408 ENABLE_ACTION("layout_hbox", multiple);
00409 ENABLE_ACTION("layout_vbox", multiple);
00410 ENABLE_ACTION("layout_grid", multiple);
00411
00412 KFormDesigner::Container *container = KFormDesigner::FormManager::self()->activeForm()->activeContainer();
00413 ENABLE_ACTION("break_layout", (container->layoutType() != KFormDesigner::Container::NoLayout));
00414 }
00415
00416 void
00417 KFormDesignerKDevPart::slotFormWidgetSelected(Form *form)
00418 {
00419 disableWidgetActions();
00420 enableFormActions();
00421
00422
00423 ENABLE_ACTION("layout_hbox", true);
00424 ENABLE_ACTION("layout_vbox", true);
00425 ENABLE_ACTION("layout_grid", true);
00426 ENABLE_ACTION("break_layout", (form->toplevelContainer()->layoutType() != KFormDesigner::Container::NoLayout));
00427 }
00428
00429 void
00430 KFormDesignerKDevPart::slotNoFormSelected()
00431 {
00432 disableWidgetActions();
00433
00434
00435 ENABLE_ACTION("edit_paste", false);
00436
00437 ENABLE_ACTION("edit_undo", false);
00438 ENABLE_ACTION("edit_redo", false);
00439
00440
00441 ENABLE_ACTION("pixmap_collection", false);
00442 ENABLE_ACTION("form_connections", false);
00443 ENABLE_ACTION("taborder", false);
00444 ENABLE_ACTION("change_style", false);
00445
00446
00447 ENABLE_ACTION("file_save", false);
00448 ENABLE_ACTION("file_save_as", false);
00449 ENABLE_ACTION("preview_form", false);
00450 }
00451
00452 void
00453 KFormDesignerKDevPart::enableFormActions()
00454 {
00455
00456 ENABLE_ACTION("pixmap_collection", true);
00457 ENABLE_ACTION("form_connections", true);
00458 ENABLE_ACTION("taborder", true);
00459 ENABLE_ACTION("change_style", true);
00460
00461
00462 ENABLE_ACTION("file_save", true);
00463 ENABLE_ACTION("file_save_as", true);
00464 ENABLE_ACTION("preview_form", true);
00465
00466 ENABLE_ACTION("edit_paste", KFormDesigner::FormManager::self()->isPasteEnabled());
00467 ENABLE_ACTION("edit_select_all", true);
00468 }
00469
00470 void
00471 KFormDesignerKDevPart::disableWidgetActions()
00472 {
00473
00474 ENABLE_ACTION("edit_copy", false);
00475 ENABLE_ACTION("edit_cut", false);
00476 ENABLE_ACTION("edit_delete", false);
00477 ENABLE_ACTION("clear_contents", false);
00478
00479
00480 ENABLE_ACTION("align_menu", false);
00481 ENABLE_ACTION("align_to_left", false);
00482 ENABLE_ACTION("align_to_right", false);
00483 ENABLE_ACTION("align_to_top", false);
00484 ENABLE_ACTION("align_to_bottom", false);
00485 ENABLE_ACTION("adjust_size_menu", false);
00486 ENABLE_ACTION("format_raise", false);
00487 ENABLE_ACTION("format_lower", false);
00488
00489 ENABLE_ACTION("layout_hbox", false);
00490 ENABLE_ACTION("layout_vbox", false);
00491 ENABLE_ACTION("layout_grid", false);
00492 ENABLE_ACTION("break_layout", false);
00493 }
00494
00495 void
00496 KFormDesignerKDevPart::setUndoEnabled(bool enabled, const QString &text)
00497 {
00498 KAction *undoAction = actionCollection()->action("edit_undo");
00499 if(undoAction)
00500 {
00501 undoAction->setEnabled(enabled);
00502 if(!text.isNull())
00503 undoAction->setText(text);
00504 }
00505 }
00506
00507 void
00508 KFormDesignerKDevPart::setRedoEnabled(bool enabled, const QString &text)
00509 {
00510 KAction *redoAction = actionCollection()->action("edit_redo");
00511 if(redoAction)
00512 {
00513 redoAction->setEnabled(enabled);
00514 if(!text.isNull())
00515 redoAction->setText(text);
00516 }
00517 }
00518
00519 void
00520 KFormDesignerKDevPart::slotCreateFormSlot(Form *form, const QString &widget, const QString &signal)
00521 {
00522 Function f;
00523 f.returnType = "void";
00524 f.function = widget + "_" + signal;
00525 f.specifier = "non virtual";
00526 f.access = "public";
00527 f.type = ftQtSlot;
00528 emit addedFunction(designerType(), form->objectTree()->name(), f);
00529 }
00530
00531 KFormDesignerKDevPart::~KFormDesignerKDevPart()
00532 {
00533 }
00534
00535
00537
00538
00539 static void repaintAll(QWidget *w)
00540 {
00541 QObjectList *list = w->queryList("QWidget");
00542 QObjectListIt it(*list);
00543 for (QObject *obj; (obj=it.current()); ++it ) {
00544 static_cast<QWidget*>(obj)->repaint();
00545 }
00546 delete list;
00547 }
00548
00549 void
00550 FormWidgetBase::drawRects(const QValueList<QRect> &list, int type)
00551 {
00552 QPainter p;
00553 p.begin(this, true);
00554 bool unclipped = testWFlags( WPaintUnclipped );
00555 setWFlags( WPaintUnclipped );
00556
00557 if (prev_rect.isValid()) {
00558
00559 p.drawPixmap( QPoint(prev_rect.x()-2, prev_rect.y()-2), buffer, QRect(prev_rect.x()-2, prev_rect.y()-2, prev_rect.width()+4, prev_rect.height()+4));
00560 }
00561 p.setBrush(QBrush::NoBrush);
00562 if(type == 1)
00563 p.setPen(QPen(white, 1, Qt::DotLine));
00564 else if(type == 2)
00565 p.setPen(QPen(white, 2));
00566 p.setRasterOp(XorROP);
00567
00568 prev_rect = QRect();
00569 QValueList<QRect>::ConstIterator endIt = list.constEnd();
00570 for(QValueList<QRect>::ConstIterator it = list.constBegin(); it != endIt; ++it) {
00571 p.drawRect(*it);
00572 prev_rect = prev_rect.unite(*it);
00573 }
00574
00575 if (!unclipped)
00576 clearWFlags( WPaintUnclipped );
00577 p.end();
00578 }
00579
00580 void
00581 FormWidgetBase::drawRect(const QRect& r, int type)
00582 {
00583 QValueList<QRect> l;
00584 l.append(r);
00585 drawRects(l, type);
00586 }
00587
00588 void
00589 FormWidgetBase::initRect()
00590 {
00591 repaintAll(this);
00592 buffer.resize( width(), height() );
00593 buffer = QPixmap::grabWindow( winId() );
00594 prev_rect = QRect();
00595 }
00596
00597 void
00598 FormWidgetBase::clearRect()
00599 {
00600 QPainter p;
00601 p.begin(this, true);
00602 bool unclipped = testWFlags( WPaintUnclipped );
00603 setWFlags( WPaintUnclipped );
00604
00605
00606 p.drawPixmap( QPoint(0,0), buffer, QRect(0,0,buffer.width(), buffer.height()) );
00607
00608 if (!unclipped)
00609 clearWFlags( WPaintUnclipped );
00610 p.end();
00611
00612 repaintAll(this);
00613 }
00614
00615 void
00616 FormWidgetBase::highlightWidgets(QWidget *from, QWidget *to)
00617 {
00618 QPoint fromPoint, toPoint;
00619 if(from && from->parentWidget() && (from != this))
00620 fromPoint = from->parentWidget()->mapTo(this, from->pos());
00621 if(to && to->parentWidget() && (to != this))
00622 toPoint = to->parentWidget()->mapTo(this, to->pos());
00623
00624 QPainter p;
00625 p.begin(this, true);
00626 bool unclipped = testWFlags( WPaintUnclipped );
00627 setWFlags( WPaintUnclipped );
00628
00629 if (prev_rect.isValid()) {
00630
00631 p.drawPixmap( QPoint(prev_rect.x(), prev_rect.y()), buffer, QRect(prev_rect.x(), prev_rect.y(), prev_rect.width(), prev_rect.height()));
00632 }
00633
00634 p.setPen( QPen(Qt::red, 2) );
00635
00636 if(to)
00637 {
00638 QPixmap pix1 = QPixmap::grabWidget(from);
00639 QPixmap pix2 = QPixmap::grabWidget(to);
00640
00641 if((from != this) && (to != this))
00642 p.drawLine( from->parentWidget()->mapTo(this, from->geometry().center()), to->parentWidget()->mapTo(this, to->geometry().center()) );
00643
00644 p.drawPixmap(fromPoint.x(), fromPoint.y(), pix1);
00645 p.drawPixmap(toPoint.x(), toPoint.y(), pix2);
00646
00647 if(to == this)
00648 p.drawRoundRect(2, 2, width()-4, height()-4, 4, 4);
00649 else
00650 p.drawRoundRect(toPoint.x(), toPoint.y(), to->width(), to->height(), 5, 5);
00651 }
00652
00653 if(from == this)
00654 p.drawRoundRect(2, 2, width()-4, height()-4, 4, 4);
00655 else
00656 p.drawRoundRect(fromPoint.x(), fromPoint.y(), from->width(), from->height(), 5, 5);
00657
00658 if((to == this) || (from == this))
00659 prev_rect = QRect(0, 0, buffer.width(), buffer.height());
00660 else if(to)
00661 {
00662 prev_rect.setX( (fromPoint.x() < toPoint.x()) ? (fromPoint.x() - 5) : (toPoint.x() - 5) );
00663 prev_rect.setY( (fromPoint.y() < toPoint.y()) ? (fromPoint.y() - 5) : (toPoint.y() - 5) );
00664 prev_rect.setRight( (fromPoint.x() < toPoint.x()) ? (toPoint.x() + to->width() + 10) : (fromPoint.x() + from->width() + 10) );
00665 prev_rect.setBottom( (fromPoint.y() < toPoint.y()) ? (toPoint.y() + to->height() + 10) : (fromPoint.y() + from->height() + 10) ) ;
00666 }
00667 else
00668 prev_rect = QRect(fromPoint.x()- 5, fromPoint.y() -5, from->width() + 10, from->height() + 10);
00669
00670 if (!unclipped)
00671 clearWFlags( WPaintUnclipped );
00672 p.end();
00673 }
00674
00675 void
00676 FormWidgetBase::closeEvent(QCloseEvent *ev)
00677 {
00678 Form *form = KFormDesigner::FormManager::self()->formForWidget(this);
00679 if(!form || !form->isModified() || !form->objectTree())
00680 ev->accept();
00681 else
00682 {
00683 bool close = m_part->closeForm(form);
00684 if(close)
00685 ev->accept();
00686 else
00687 ev->ignore();
00688 }
00689 }
00690
00691 K_EXPORT_COMPONENT_FACTORY(libkformdesigner_kdev_part, KFDFactory)
00692
00693 #include "kfd_kdev_part.moc"
00694