00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "QGo4Widget.h"
00015 #include <QtCore/QTimer>
00016 #include <QAction>
00017 #include <QMenu>
00018 #include <QtCore/QSignalMapper>
00019
00020 #include <QDragMoveEvent>
00021 #include <QCloseEvent>
00022 #include <QDropEvent>
00023 #include <QDragEnterEvent>
00024
00025 QGo4Widget::QGo4Widget(QWidget * parent, const char * name, Qt::WindowFlags f) :
00026 QWidget(parent, f),
00027 fWaitsForObjectCreation(false),
00028 fCanDestroyWidget(true),
00029 fResetWidgetShooted(false),
00030 fBlockUpdate(false),
00031 fBrowserProxy(0)
00032 {
00033 setObjectName(name);
00034 setAcceptDrops(true);
00035 }
00036
00037 QGo4Widget::~QGo4Widget()
00038 {
00039 RemoveLinksMasked("complete");
00040 }
00041
00042 void QGo4Widget::ObjectCreatedByWidget(const char* itemname, TClass* cl)
00043
00044 {
00045 if (fWaitsForObjectCreation) {
00046 fWaitsForObjectCreation = false;
00047 requestedObjectCreated(itemname, cl);
00048 }
00049 }
00050
00051 void QGo4Widget::ResetWidget()
00052 {
00053
00054 fResetWidgetShooted = true;
00055 RemoveAllLinks();
00056 fWaitsForObjectCreation = false;
00057 fResetWidgetShooted = false;
00058 }
00059
00060 void QGo4Widget::ShootResetWidget()
00061 {
00062 if (fResetWidgetShooted) return;
00063
00064 fResetWidgetShooted = true;
00065
00066 QTimer::singleShot(0, this, SLOT(ResetWidgetSlot()));
00067 }
00068
00069 void QGo4Widget::ShootCloseWidget(bool closeparent)
00070 {
00071 if (fResetWidgetShooted) return;
00072
00073 fResetWidgetShooted = true;
00074
00075 QTimer::singleShot(0, closeparent ? parentWidget() : this, SLOT(close()));
00076 }
00077
00078
00079 void QGo4Widget::ResetWidgetSlot()
00080 {
00081 ResetWidget();
00082 }
00083
00084 bool QGo4Widget::IsAcceptDrag(const char*, TClass*, int)
00085 {
00086 return false;
00087 }
00088
00089 void QGo4Widget::DropItem(const char*, TClass*, int)
00090 {
00091 }
00092
00093 void QGo4Widget::closeEvent(QCloseEvent* e)
00094 {
00095 if (fCanDestroyWidget) {
00096 e->accept();
00097 } else {
00098 e->ignore();
00099 }
00100 }
00101
00102 void QGo4Widget::dragEnterEvent(QDragEnterEvent *e)
00103 {
00104 emit widgetService(this, service_DragEnter, 0, e);
00105 }
00106
00107 void QGo4Widget::dragMoveEvent(QDragMoveEvent*)
00108 {
00109
00110 }
00111
00112 void QGo4Widget::dropEvent(QDropEvent* e)
00113 {
00114 emit widgetService(this, service_DropEvent, 0, e);
00115 }
00116
00117 void QGo4Widget::AddLink(const char* itemname, const char* linkname)
00118 {
00119 emit widgetService(this, service_AddEditorLink, linkname, (void*) itemname);
00120 }
00121
00122 void QGo4Widget::AddLink(TGo4Slot* slot, const char* linkname)
00123 {
00124 emit widgetService(this, service_AddDirectLink, linkname, (void*) slot);
00125 }
00126
00127 TGo4Slot* QGo4Widget::AddLink(const char* itemname, TGo4Slot* parent)
00128 {
00129 TGo4Slot* res = parent;
00130 emit widgetService(this, service_AddLinkInSlot, itemname, (void*) &res);
00131 return res;
00132 }
00133
00134 TGo4Slot* QGo4Widget::GetTopSlot(bool force)
00135 {
00136 TGo4Slot* res = 0;
00137 emit widgetService(this, service_GetTopSlot, force ? "force" : "normal", (void*) &res);
00138 return res;
00139 }
00140
00141 TGo4Slot* QGo4Widget::AddSlot(const char* slotname)
00142 {
00143 TGo4Slot* res = 0;
00144 emit widgetService(this, service_AddEditorSlot, slotname, (void*) &res);
00145 return res;
00146 }
00147
00148 void QGo4Widget::SetLinkedName(TGo4Slot* slot, const char* itemname)
00149 {
00150 emit widgetService(this, service_SetLinkedName, itemname, (void*) slot);
00151 }
00152
00153 const char* QGo4Widget::GetLinkedName(const char* linkname)
00154 {
00155 const char* res = 0;
00156
00157 emit widgetService(this, service_GetLinkedName, linkname, (void*) &res);
00158
00159 return res;
00160 }
00161
00162 const char* QGo4Widget::GetLinkedName(TGo4Slot* slot)
00163 {
00164 void* res = slot;
00165
00166 emit widgetService(this, service_GetLinkedName2, "", (void*) &res);
00167
00168 return (const char*) res;
00169 }
00170
00171
00172 TObject* QGo4Widget::GetLinked(const char* linkname, int updatelevel)
00173 {
00174 TObject* res = 0;
00175 int func = 0;
00176 switch (updatelevel) {
00177 case 0: func = service_GetLinked0; break;
00178 case 1: func = service_GetLinked1; break;
00179 case 2: func = service_GetLinked2; break;
00180 default: func = service_GetLinked1; break;
00181 }
00182
00183 emit widgetService(this, func, linkname, (void*) &res);
00184
00185 return res;
00186 }
00187
00188 void QGo4Widget::RemoveLink(const char* linkname, bool blockreset)
00189 {
00190 bool oldvalue = fBlockUpdate;
00191 if (blockreset) fBlockUpdate = true;
00192 emit widgetService(this, service_RemoveLink, linkname, 0);
00193 fBlockUpdate = oldvalue;
00194 }
00195
00196 void QGo4Widget::RemoveAllLinks(bool blockreset)
00197 {
00198 bool oldvalue = fBlockUpdate;
00199 if (blockreset) fBlockUpdate = true;
00200 emit widgetService(this, service_RemoveAllLinks, 0, 0);
00201 fBlockUpdate = oldvalue;
00202 }
00203
00204 void QGo4Widget::RemoveLinksMasked(const char* startedwith, bool blockreset)
00205 {
00206 bool oldvalue = fBlockUpdate;
00207 if (blockreset) fBlockUpdate = true;
00208 emit widgetService(this, service_RemoveAllLinks, startedwith, 0);
00209 fBlockUpdate = oldvalue;
00210 }
00211
00212 bool QGo4Widget::BrowserItemRemote(const char* itemname)
00213 {
00214 bool isremote = false;
00215 emit widgetService(this, service_BrowserItemRemote, itemname, (void*) &isremote);
00216 return isremote;
00217 }
00218
00219 TGo4BrowserProxy* QGo4Widget::Browser()
00220 {
00221 if (fBrowserProxy!=0) return fBrowserProxy;
00222
00223 TGo4BrowserProxy* br = 0;
00224 emit widgetService(this, service_Browser, "", (void*) &br);
00225 fBrowserProxy = br;
00226 return br;
00227 }
00228
00229 void QGo4Widget::ConnectPad(TPad* pad)
00230 {
00231 emit widgetService(this, service_ConnectPad, "", (void*) pad);
00232 }
00233
00234 void QGo4Widget::CallPanelFunc(int func, TPad* pad)
00235 {
00236 emit widgetService(this, func, "", (void*) pad);
00237 }
00238
00239
00240 void QGo4Widget::StatusMessage(const QString& message)
00241 {
00242 emit widgetService(this, service_StatusMessage, message.toLatin1().constData(), 0);
00243 }
00244
00245
00246 void QGo4Widget::ProcessSignal(const char* linkname, bool assigned, TObject* obj, TGo4Slot* slot)
00247 {
00248 if (assigned) {
00249 linkedUpdated(slot, obj);
00250 linkedObjectUpdated(linkname, obj);
00251 } else
00252
00253 if (!IsUpdateBlocked()) {
00254 linkedRemoved(slot, obj);
00255 linkedObjectRemoved(linkname);
00256 }
00257 }
00258
00259 void QGo4Widget::linkedObjectUpdated(const char* , TObject* )
00260 {
00261 }
00262
00263 void QGo4Widget::linkedObjectRemoved(const char* )
00264 {
00265
00266 ShootResetWidget();
00267 }
00268
00269 void QGo4Widget::linkedUpdated(TGo4Slot* , TObject* )
00270 {
00271 }
00272
00273 void QGo4Widget::linkedRemoved(TGo4Slot* , TObject* )
00274 {
00275 }
00276
00277 void QGo4Widget::AskToCreateObject(TClass* cl, int isremote)
00278 {
00279 fWaitsForObjectCreation = (isremote>=0);
00280 QString str = QString::number(isremote);
00281 emit widgetService(this, service_CreateItem, str.toLatin1().constData(), (void*) cl);
00282 }
00283
00284 void QGo4Widget::InformThatObjectCreated(const char* itemname, TClass* cl)
00285 {
00286 emit widgetService(this, service_ObjectCreated, itemname, cl);
00287 }
00288
00289 void QGo4Widget::requestedObjectCreated(const char* , TClass* )
00290
00291 {
00292 }
00293
00294 void QGo4Widget::ShowItemInfo(const QString& itemname)
00295 {
00296 emit widgetService(this, service_ShowInfo, itemname.toLatin1().constData(), 0);
00297 }
00298
00299 TGo4ViewPanel* QGo4Widget::CreateViewPanel(int ndiv)
00300 {
00301 QString str = QString::number(ndiv);
00302 TGo4ViewPanel* res = 0;
00303 emit widgetService(this, service_CreateViewPanel, str.toLatin1().constData(), (void*)&res);
00304 return res;
00305 }
00306
00307 TGo4ViewPanel* QGo4Widget::DrawItem(const QString& itemname, TGo4ViewPanel* panel, TPad* pad, bool activate, int updatelevel)
00308 {
00309 void* res[4];
00310 res[0] = panel;
00311 res[1] = pad;
00312 res[2] = &activate;
00313 res[3] = &updatelevel;
00314 emit widgetService(this, service_DrawItem, itemname.toLatin1().constData(), res);
00315 return (TGo4ViewPanel*) res[0];
00316 }
00317
00318 TGo4ViewPanel* QGo4Widget::WhereItemDrawn(const char* itemname)
00319 {
00320 TGo4ViewPanel* res = false;
00321 emit widgetService(this, service_WhereItemDrawn, itemname, &res);
00322 return res;
00323 }
00324
00325 void QGo4Widget::UndrawItem(const char* itemname)
00326 {
00327 emit widgetService(this, service_UndrawItem, itemname, 0);
00328 }
00329
00330 void QGo4Widget::HelpWindow(const char* filename, const char* msg)
00331 {
00332 emit widgetService(this, service_HelpWindow, filename, (void*)msg);
00333 }
00334
00335 void QGo4Widget::StartHotstart(const char* filename)
00336 {
00337 emit widgetService(this, service_HotStart, filename, 0);
00338 }
00339
00340 TGo4ViewPanel* QGo4Widget::LastActivePanel()
00341 {
00342 TGo4ViewPanel* res = 0;
00343 emit widgetService(this, service_LastActivePanel, "", (void*)&res);
00344 return res;
00345 }
00346
00347 void QGo4Widget::EditItem(const QString& itemname)
00348 {
00349 emit widgetService(this, service_EditItem, itemname.toLatin1().constData(), 0);
00350 }
00351
00352 void QGo4Widget::EditObjectInSlot(TGo4Slot* slot)
00353 {
00354 emit widgetService(this, service_EditInSlot, "", (void*) slot);
00355 }
00356
00357 QString QGo4Widget::SaveObjectInMemory(const char* foldername, TObject* obj)
00358 {
00359 void* par = obj;
00360 emit widgetService(this, service_SaveToMemory, foldername, (void*) &par);
00361 QString itemname = "";
00362 if ((par!=obj) && (par!=0)) {
00363 QString* res = (QString*) par;
00364 itemname = *res;
00365 delete res;
00366 }
00367 return itemname;
00368 }
00369
00370 bool QGo4Widget::SaveItemToFile(const char* itemname, const char* subfolder)
00371 {
00372 char buf[1000];
00373 if (subfolder==0) strcpy(buf, ""); else
00374 strcpy(buf, subfolder);
00375 emit widgetService(this, service_SaveItem, itemname, (void*) buf);
00376 return (buf[0]!=0);
00377 }
00378
00379 bool QGo4Widget::UpdateItemInAnalysis(const char* itemname, TObject* obj)
00380 {
00381 TObject* res = obj;
00382 emit widgetService(this, service_UpdateAnalysisItem, itemname, (void*) &res);
00383 return (res!=0);
00384 }
00385
00386 TGo4AnalysisProxy* QGo4Widget::GetAnalysis(const char* itemname)
00387 {
00388 TGo4AnalysisProxy* res = 0;
00389 emit widgetService(this, service_GetAnalysis, itemname, (void*) &res);
00390 return res;
00391 }
00392
00393 void QGo4Widget::CallServiceFunc(int func, const char* str, void* par)
00394 {
00395 emit widgetService(this, func, str, par);
00396 }
00397
00398 void QGo4Widget::ServiceCall(const char* name, void* par)
00399 {
00400 CallServiceFunc(service_General, name, par);
00401 }
00402
00403 QAction* AddChkAction(QMenu* menu,
00404 const QString& text, bool checked,
00405 QObject* recv, const char* member)
00406 {
00407 QAction* act = new QAction(text, menu);
00408 act->setCheckable(true);
00409 act->setChecked(checked);
00410 recv->connect (act, SIGNAL(triggered()), recv, member);
00411 menu->addAction(act);
00412 return act;
00413 }
00414
00415 QAction* AddIdAction(QMenu* menu, QSignalMapper* map,
00416 const QString& text, int id, int enabled, int checked)
00417 {
00418 QAction* act = new QAction(text, menu);
00419 if (checked!=-1) {
00420 act->setCheckable(true);
00421 act->setChecked(checked > 0);
00422 }
00423 if (enabled!=-1)
00424 act->setEnabled(enabled > 0);
00425 map->connect (act, SIGNAL(triggered()), map, SLOT(map()));
00426 menu->addAction(act);
00427 map->setMapping(act, id);
00428 return act;
00429 }
00430
00431 QAction* SetIdAction(QSignalMapper* map, int id, int enabled, int checked)
00432 {
00433 QAction* act = (QAction*) map->mapping(id);
00434 if (act==0) return 0;
00435 if (checked!=-1) {
00436 act->setCheckable(true);
00437 act->setChecked(checked > 0);
00438 }
00439 if (enabled!=-1)
00440 act->setEnabled(enabled > 0);
00441 return act;
00442 }
00443
00444 QAction* AddIdAction(QMenu* menu, QSignalMapper* map,
00445 const QIcon& icon, const QString& text, int id, int enabled, int checked)
00446 {
00447 QAction* act = new QAction(icon, text, menu);
00448 if (checked!=-1) {
00449 act->setCheckable(true);
00450 act->setChecked(checked > 0);
00451 }
00452 if (enabled!=-1)
00453 act->setEnabled(enabled > 0);
00454 map->connect (act, SIGNAL(triggered()), map, SLOT(map()));
00455 menu->addAction(act);
00456 map->setMapping(act, id);
00457 return act;
00458 }