Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "QUserPanel.h"
00016
00017 #include <stdlib.h>
00018 #include <stdio.h>
00019
00020 #include <QMimeData>
00021
00022 #include "Riostream.h"
00023 #include "Rstrstream.h"
00024 #include "TClass.h"
00025 #include "TCanvas.h"
00026 #include "TGo4Proxy.h"
00027 #include "QRootCanvas.h"
00028
00029
00030
00031 #include <sstream>
00032
00033
00034 extern "C" Q_DECL_EXPORT void* StartUserPanel(void* parent)
00035 {
00036
00037 return new QUserPanel((QWidget*) parent);
00038
00039
00040
00041
00042
00043
00044
00045 }
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 QUserPanel::QUserPanel( QWidget* parent, const char* name )
00059 : QGo4Widget( parent, name )
00060 {
00061 setupUi(this);
00062
00063 DragLbl->setText("");
00064 DragItemLbl->setText("");
00065 DragClassLbl->setText("");
00066 DragKindLbl->setText("");
00067
00068 PrintLbl->setText("");
00069
00070 QObject::connect(InfoBtn, SIGNAL(clicked()), this, SLOT(InfoBtn_clicked()));
00071 QObject::connect(EditBtn, SIGNAL(clicked()), this, SLOT(EditBtn_clicked()));
00072 QObject::connect(DrawBtn, SIGNAL(clicked()), this, SLOT(DrawBtn_clicked()));
00073 QObject::connect(fxDrawCanvas, SIGNAL(CanvasDropEvent(QDropEvent*,TPad*)), this, SLOT(CanvasDropEventSlot(QDropEvent*,TPad*)));
00074 }
00075
00076 QUserPanel::~QUserPanel()
00077 {
00078 fxDrawCanvas->getCanvas()->Clear();
00079 }
00080
00081 QString QUserPanel::kindString(int kind)
00082 {
00083 QString kndlabel;
00084
00085 switch(kind) {
00086 case TGo4Access::kndNone: kndlabel = "unknown"; break;
00087 case TGo4Access::kndObject: kndlabel = "object"; break;
00088 case TGo4Access::kndFolder: kndlabel = "folder"; break;
00089 case TGo4Access::kndTreeBranch: kndlabel = "tree brunch"; break;
00090 case TGo4Access::kndTreeLeaf: kndlabel = "tree leaf"; break;
00091 case TGo4Access::kndGo4Param: kndlabel = "go4 parameter"; break;
00092 case TGo4Access::kndDataMember: kndlabel = "event data member"; break;
00093 case TGo4Access::kndEventElement: kndlabel = "event element"; break;
00094 default: kndlabel = "undefined"; break;
00095 }
00096
00097 kndlabel = QString("Kind of draged item: ") + kndlabel +
00098 " (" + QString::number(kind) + ")";
00099
00100 return kndlabel;
00101 }
00102
00103 bool QUserPanel::IsAcceptDrag(const char* itemname, TClass* cl, int kind)
00104 {
00105 bool res = false;
00106
00107 switch (TabWidget->currentIndex()) {
00108 case 0:
00109 DragLbl->setText("Go4 GUI asks if widget accept dragged item");
00110 DragItemLbl->setText(itemname);
00111 DragClassLbl->setText(QString("Class: ") + (cl==0 ? "not exists (known)" : cl->GetName()));
00112 DragKindLbl->setText(kindString(kind));
00113 res = cl!=0;
00114 break;
00115
00116 case 1:
00117 PrintLbl->setText(QString("Class: ") + (cl==0 ? "not exists (known)" : cl->GetName()));
00118 res = cl!=0;
00119 break;
00120 }
00121
00122 return res;
00123 }
00124
00125 void QUserPanel::DropItem(const char* itemname, TClass* cl, int kind)
00126 {
00127 switch (TabWidget->currentIndex()) {
00128 case 0:
00129 DragLbl->setText("User dropped item");
00130 DragItemLbl->setText(itemname);
00131 DragClassLbl->setText(cl==0 ? "No class specified" : cl->GetName());
00132 DragKindLbl->setText(kindString(kind));
00133 break;
00134 case 1:
00135 if (cl==0) {
00136 PrintLbl->setText("Can not drop item of uncknown class");
00137 } else {
00138 PrintLbl->setText(QString("Print item: ") + itemname);
00139 RemoveLink("PrintItem");
00140 AddLink(itemname, "PrintItem");
00141 PrintObject(GetLinked("PrintItem", 2));
00142 }
00143
00144 break;
00145 case 2:
00146 DrawObjectOnCanvas(itemname);
00147 break;
00148 }
00149 }
00150
00151 void QUserPanel::linkedObjectUpdated(const char* linkname, TObject* obj)
00152 {
00153 if (strcmp(linkname, "PrintItem")==0)
00154 PrintObject(obj);
00155 else
00156 if (strcmp(linkname, "DrawItem")==0) {
00157 fxDrawCanvas->getCanvas()->Clear();
00158 fxDrawCanvas->getCanvas()->cd();
00159 obj->Draw("");
00160 fxDrawCanvas->getCanvas()->Update();
00161 }
00162 }
00163
00164 void QUserPanel::linkedObjectRemoved(const char* linkname)
00165 {
00166 if (strcmp(linkname, "PrintItem")==0)
00167 PrintObject(0);
00168 else
00169 if (strcmp(linkname, "DrawItem")==0) {
00170 RemoveLink("DrawItem");
00171 fxDrawCanvas->getCanvas()->Clear();
00172 fxDrawCanvas->getCanvas()->Update();
00173 }
00174 }
00175
00176 void QUserPanel::InfoBtn_clicked()
00177 {
00178 ShowItemInfo(DragItemLbl->text());
00179 }
00180
00181 void QUserPanel::EditBtn_clicked()
00182 {
00183 EditItem(DragItemLbl->text());
00184 }
00185
00186 void QUserPanel::DrawBtn_clicked()
00187 {
00188 DrawItem(DragItemLbl->text());
00189 }
00190
00191 void QUserPanel::PrintObject(TObject* obj)
00192 {
00193 PrintEdit->clear();
00194 if (obj==0) return;
00195
00196 if (stdoutButton->isChecked()) {
00197 std::cout.flush();
00198 char sbuf[30000];
00199 memset(sbuf, 0, 30000);
00200 std::setvbuf(stdout, sbuf, _IOFBF, 30000);
00201 obj->Print("");
00202 fflush(stdout);
00203 std::setvbuf(stdout, 0, _IONBF, 0);
00204 PrintEdit->setText(sbuf);
00205 } else {
00206 std::cout.flush();
00207 std::ostringstream strout;
00208 std::streambuf* ccc_buffer = std::cout.rdbuf();
00209 std::cout.rdbuf(strout.rdbuf());
00210 obj->Print("");
00211 std::cout << std::endl;
00212 std::cout.flush();
00213 std::cout.rdbuf(ccc_buffer);
00214 PrintEdit->setText(strout.str().c_str());
00215 }
00216 }
00217
00218 void QUserPanel::CanvasDropEventSlot(QDropEvent* event, TPad* pad)
00219 {
00220
00221 if (!event->mimeData()->hasText()) return;
00222 QString eventstr = event->mimeData()->text();
00223 event->acceptProposedAction();
00224 DrawObjectOnCanvas(eventstr.toLatin1().constData());
00225 }
00226
00227 void QUserPanel::DrawObjectOnCanvas(const char* itemname)
00228 {
00229 RemoveLink("DrawItem");
00230 AddLink(itemname, "DrawItem");
00231 TObject* obj = GetLinked("DrawItem", 2);
00232 if (obj!=0) {
00233 fxDrawCanvas->getCanvas()->Clear();
00234 fxDrawCanvas->getCanvas()->cd();
00235 obj->Draw("");
00236 fxDrawCanvas->getCanvas()->Update();
00237 }
00238 }
00239