Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/qtroot/interface/tqcanvasmenu.cpp

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 /****************************************************************************
00017 ** Copyright ( C ) 2000 denis Bertini.  All rights reserved.
00018 *****************************************************************************/
00019 
00020 #include "tqcanvasmenu.h"
00021 
00022 #include <iostream.h>
00023 
00024 #include "qevent.h"
00025 #include "qpainter.h"
00026 #include "qprinter.h"
00027 #include "qtoolbar.h"
00028 #include "qtoolbutton.h"
00029 #include "qspinbox.h"
00030 #include "qtooltip.h"
00031 #include "qrect.h"
00032 #include "qpoint.h"
00033 #include "qcolordialog.h"
00034 #include "qfiledialog.h"
00035 #include "qcursor.h"
00036 #include "qimage.h"
00037 #include "qstrlist.h"
00038 #include "qpopupmenu.h"
00039 #include "qintdict.h"
00040 #include "qpushbutton.h"
00041 #include "qaction.h"
00042 using namespace std;
00043 #include "qdial.h"
00044 #include "qapplication.h"
00045 #include "qimage.h"
00046 #include "qpixmap.h"
00047 #include "qtoolbar.h"
00048 #include "qtoolbutton.h"
00049 #include "qmenubar.h"
00050 #include "qkeycode.h"
00051 #include "qfile.h"
00052 #include "qfiledialog.h"
00053 #include "qstatusbar.h"
00054 #include "qmessagebox.h"
00055 #include "qwhatsthis.h"
00056 #include "qdialog.h"
00057 #include "qlabel.h"
00058 #include "TLatex.h"
00059 #include "qinputdialog.h"
00060 
00061 
00062 #include "TPad.h"
00063 #include "TList.h"
00064 #include "TObject.h"
00065 #include "TROOT.h"
00066 #include "TString.h"
00067 #include "TH1.h"
00068 #include "TList.h"
00069 #include "TIterator.h"
00070 #include "TMethod.h"
00071 #include "TCanvas.h"
00072 #include "TDataType.h"
00073 #include "TMethodCall.h"
00074 #include "TPad.h"
00075 #include "TObjArray.h"
00076 #include "TIterator.h"
00077 #include "TColor.h"
00078 
00079 #include "qcolordialog.h"
00080 #include "qcolor.h"
00081 
00082 #include "lockguard.h"
00083 
00084 char* TQCanvasMenu::createDialogTitle( TObject *object, TMethod *method ){
00085  // Create title for dialog box retrieving argument values.
00086 Qtrootlockguard threadlock;
00087   static char methodTitle[128];
00088 
00089   if (object && method)
00090     snprintf(methodTitle, 127, "%s::%s", object->ClassName(), method->GetName());
00091   else
00092     *methodTitle = 0;
00093 
00094   return methodTitle;
00095 
00096 }
00097 
00098 char* TQCanvasMenu::createArgumentTitle(TMethodArg *argument){
00099   // Create string describing argument (for use in dialog box).
00100 Qtrootlockguard threadlock;
00101   static Char_t argTitle[128];
00102   if (argument) {
00103     snprintf(argTitle, 127, "(%s)  %s", argument->GetTitle(), argument->GetName());
00104     if (argument->GetDefault() && *(argument->GetDefault())) {
00105       strcat(argTitle, "  [default: ");
00106       strcat(argTitle, argument->GetDefault());
00107       strcat(argTitle, "]");
00108     }
00109   } else
00110     *argTitle = 0;
00111 
00112   return argTitle;
00113 }
00114 
00115 
00116 void TQCanvasMenu::popup(TObject *obj, double x, double y, QMouseEvent *e){
00117    Qtrootlockguard threadlock;
00118    TClass *klass=obj->IsA();
00119    int curId=-1;
00120 
00121    fCurrObj=obj;
00122    fPopup->clear();
00123    fMethods.Clear();
00124 
00125    QString buffer=klass->GetName();
00126    buffer+="::";
00127    buffer+=obj->GetName();
00128    fPopup->insertItem(buffer, this, SLOT( execute(int) ), 0,curId); curId++;
00129    klass->GetMenuItems(&fMethods);
00130    fPopup->insertSeparator();
00131 
00132    if(!klass->InheritsFrom("TLatex")) {
00133        fPopup->insertItem("Insert Latex", this, SLOT(execute(int)), 0, 100 );
00134        fPopup->insertSeparator();
00135    }
00136 
00137    if(klass->InheritsFrom("TH1")) {
00138       fPopup->insertItem("Qt Hist Line Color ", this, SLOT(execute(int)), 0, 101 );
00139       fPopup->insertItem("Qt Hist Fill Color ", this, SLOT(execute(int)), 0, 102 );
00140       fPopup->insertSeparator();
00141    }
00142 
00143    TIter iter(&fMethods);
00144    TMethod *method=0;
00145    while ( (method = dynamic_cast<TMethod*>(iter())) != 0) {
00146       buffer=method->GetName();
00147       fPopup->insertItem(buffer, this, SLOT( execute(int) ), 0,curId);
00148        curId++;
00149    }
00150 
00151    MousePosX= x;  // hold the position where the mouse was clicked
00152    MousePosY= y;
00153 
00154    fPopup->popup(e->globalPos(), 0); /* let Qt decide how to draw the popup Menu otherwise we have a problem that
00155                     *   the visible rectangle can get outside the screen (M. Al-Turany 03.06.02)
00156                     */
00157 
00158 }
00159 
00160 void TQCanvasMenu::execute(int id) {
00161    Qtrootlockguard threadlock;
00162 //   TObjLink *pickobj=0;
00163    QString text="";
00164    bool ok = FALSE;
00165       if (   id >=100){
00166       TLatex *fxLatex = new TLatex() ;
00167      //cout <<"TQCanvasMenu::execute(int id)"<<  fCurrObj->GetName()<<endl;
00168      switch (id){
00169         case 100:
00170 
00171 
00172            text = QInputDialog::getText(
00173                  tr( "Qt Root" ),
00174                  tr( "Please enter your text" ),
00175                  QLineEdit::Normal, QString::null, &ok);
00176          if ( ok && !text.isEmpty() )
00177                ;// user entered something and pressed OK
00178            fxLatex->DrawLatex(MousePosX,MousePosY, text.data());
00179            break;
00180         case 101 :
00181            ChangeHisLineColor();
00182            break;
00183         case 102 :
00184            ChangeHisFillColor();
00185            break;
00186 
00187      }
00188      gROOT->GetSelectedPad()->Update();
00189     gROOT->GetSelectedPad()->Modified();
00190 
00191     c->Modified();
00192     c->ForceUpdate();
00193 
00194     gROOT->SetFromPopUp( kFALSE );
00195 
00196   }else if (! (id < 0) ){
00197 
00198     // save global to Pad before calling TObject::Execute()
00199 
00200     TVirtualPad  *psave = gROOT->GetSelectedPad();
00201     TMethod *method=(TMethod *)fMethods.At(id);
00202     
00204     c->HandleInput(kButton3Up,gPad->XtoAbsPixel(MousePosX), gPad->YtoAbsPixel(MousePosY) );
00205     /*
00206        This line do nothing but saving the coordinates of the gPad so that when TCutG::RemovePoint or InsertPoint are called
00207        gPad->GetEventX and gPadGetEventY will have these coordinats which are the real position where the right mouse click
00208        took place. (Mohammad Al-Turany 24.09.02)
00209     */
00210     // print defaults
00211     //  cout << fCurrObj->IsA()->GetName() << method->GetName() << endl;
00212 
00213 //    //qDebug("MENU:  gPad:%s gROOT:%s psave:%s \n" ,
00214 //          gPad->GetName(), gROOT->GetSelectedPad()->GetName(),psave->GetName());
00215 
00216     if (  method->GetListOfMethodArgs()->First() ){
00217           dialog(fCurrObj,method);
00218     }else{
00219 
00220     gROOT->SetFromPopUp(kTRUE);
00222     //c->HandleInput(kButton3Up,gPad->XtoAbsPixel(MousePosX), gPad->YtoAbsPixel(MousePosY) );
00223     /*
00224        This line do nothing but saving the coordinates of the gPad so that when TCutG::RemovePoint or InsertPoint are called
00225        gPad->GetEventX and gPadGetEventY will have these coordinats which are the real position where the right mouse click
00226        took place. (Mohammad Al-Turany 24.09.02)
00227     */
00229     //qDebug("MENU: fCurrOBJ: %s meth %s \n", fCurrObj->GetName(), method->GetName());
00230 
00231 
00232     fCurrObj->Execute((char *) method->GetName(), "");
00233     }
00234     c->GetPadSave()->Update();
00235     c->GetPadSave()->Modified();
00236 
00237     gROOT->SetSelectedPad(psave);
00239       //gPad->GetName(), gROOT->GetSelectedPad()->GetName(), c->GetName());
00240 
00241 
00242 
00243     gROOT->GetSelectedPad()->Update();
00244     gROOT->GetSelectedPad()->Modified();
00245 
00246 
00247     c->Modified();
00248     c->ForceUpdate();
00249 
00250     gROOT->SetFromPopUp( kFALSE );
00251   }
00252 }
00253 
00254 void TQCanvasMenu::dialog(TObject* object, TMethod* method){
00255 Qtrootlockguard threadlock;
00256   // Create dialog object with OK and Cancel buttons. This dialog
00257    // prompts for the arguments of "method".
00258 
00259   if (!(object && method)) return;
00260 
00261   fDialog = new TQRootDialog(fParent,createDialogTitle(object, method),0,object
00262              ,method);
00263   fDialog->setTCanvas(c);
00264   // iterate through all arguments and create apropriate input-data objects:
00265   // inputlines, option menus...
00266    TMethodArg *argument = 0;
00267    TIter next(method->GetListOfMethodArgs());
00268 
00269    while ((argument = (TMethodArg *) next())) {
00270      Text_t       *argname    = createArgumentTitle(argument);
00271      const Text_t *type       = argument->GetTypeName();
00272      TDataType    *datatype   = gROOT->GetType(type);
00273      const Text_t *charstar   = "char*";
00274      Text_t        basictype [32];
00275 
00276      if (datatype) {
00277        strncpy(basictype, datatype->GetTypeName(),31);
00278      } else {
00279        if (strncmp(type, "enum", 4) != 0)
00280     cout << "*** Warning in Dialog(): data type is not basic type, assuming (int)\n";
00281        strcpy(basictype, "int");
00282       }
00283 
00284      if (strchr(argname, '*')) {
00285        strcat(basictype, "*");
00286        type = charstar;
00287      }
00288 
00289       TDataMember *m = argument->GetDataMember();
00290       if (m && m->GetterMethod()) {
00291 
00292    Text_t gettername[256] = "";
00293    strncpy(gettername, m->GetterMethod()->GetMethodName(),255);
00294    m->GetterMethod()->Init(object->IsA(), gettername, "");
00295 
00296    // Get the current value and form it as a text:
00297 
00298    Text_t val[256];
00299 
00300    if (!strncmp(basictype, "char*", 5)) {
00301      Text_t *tdefval;
00302             m->GetterMethod()->Execute(object, "", &tdefval);
00303             strncpy(val, tdefval, 255);
00304    } else if (!strncmp(basictype, "float", 5) ||
00305          !strncmp(basictype, "double", 6)) {
00306      Double_t ddefval;
00307      m->GetterMethod()->Execute(object, "", ddefval);
00308      snprintf(val, 255, "%g", ddefval);
00309    } else if (!strncmp(basictype, "char", 4) ||
00310                     !strncmp(basictype, "int", 3)  ||
00311          !strncmp(basictype, "long", 4) ||
00312          !strncmp(basictype, "short", 5)) {
00313      Long_t ldefval;
00314      m->GetterMethod()->Execute(object, "", ldefval);
00315             snprintf(val, 255, "%li", ldefval);
00316    }
00317 
00318    // Find out whether we have options ...
00319 
00320    TList *opt;
00321    if ((opt = m->GetOptions())) {
00322      cout << "*** Warning in Dialog(): option menu not yet implemented " << opt << endl;
00323      // should stop dialog
00324      return;
00325 #if 0
00326      TMotifOptionMenu *o= new TMotifOptionMenu(argname);
00327      TIter nextopt(opt);
00328      TOptionListItem *it = 0;
00329      while ((it = (TOptionListItem*) nextopt())) {
00330        Text_t *name  = it->fOptName;
00331        Text_t *label = it->fOptLabel;
00332                Long_t value  = it->fValue;
00333                if (value != -9999) {
00334        Text_t val[256];
00335        snprintf(val, 255, "%li", value);
00336        o->AddItem(name, val);
00337                }else
00338        o->AddItem(name, label);
00339      }
00340      o->SetData(val);
00341      fDialog->Add(o);
00342 #endif
00343    } else {
00344      // we haven't got options - textfield ...
00345             fDialog->add(argname, val, type);
00346    }
00347 
00348       } else {    // if m not found ...
00349 
00350    char val[256] = "";
00351    const char *tval = argument->GetDefault();
00352          if (tval) strncpy(val, tval, 255);
00353          fDialog->add(argname, val, type);
00354 
00355       }
00356    }
00357 
00358    fDialog->popup();
00359 }
00360 
00361 
00362 void TQCanvasMenu::ChangeHisLineColor()
00363 {
00364    TH1 *fxTH1 = (TH1 *)fCurrObj;
00365    QColor c = QColorDialog::getColor();
00366     if ( c.isValid() ) {
00367       short int C_new =  TColor::GetColor(c.red(), c.green(), c.blue());
00368       if (fxTH1!=0) {
00369          fxTH1->SetLineColor(C_new);
00370       }
00371     }
00372 
00373 
00374 }
00375 
00376 void TQCanvasMenu::ChangeHisFillColor()
00377 {
00378 
00379    TH1 *fxTH1 = (TH1 *)fCurrObj;
00380    QColor c = QColorDialog::getColor();
00381     if ( c.isValid() ) {
00382       short int C_new =  TColor::GetColor(c.red(), c.green(), c.blue());
00383       if (fxTH1!=0) {
00384          fxTH1->SetFillColor(C_new);
00385       }
00386     }
00387 
00388 }
00389 
00390 
00391 
00392 
00393 
00394 
00395 
00396 
00397 
00398 
00399 
00400 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:56:09 2005 for Go4-v2.10-5 by doxygen1.2.15