Changeset 513


Ignore:
Timestamp:
Jun 15, 2007, 2:33:46 PM (17 years ago)
Author:
garnier
Message:

r630@mac-90108: laurentgarnier | 2007-06-15 14:37:13 +0200
un peu de menage et tentative de passage d arguments dans l aide

Location:
trunk/geant4/interfaces/basic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/geant4/interfaces/basic/include/G4UIQt.hh

    r512 r513  
    9898private:
    9999  void SecondaryLoop(G4String); // a VIRER
    100   G4bool GetHelpChoice(G4int&);
    101100  void TerminalHelp(G4String);
    102   void CreateChildTree(QTreeWidgetItem*,G4UIcommandTree*);
     101  void CreateChildTree(QTreeWidgetItem*,G4UIcommandTree*,G4UIcommand*);
    103102  QString GetCommandList(G4UIcommand*);
    104103
    105   void ExitHelp();
    106104private:
    107105
     
    110108  //  static void commandEnteredCallback(Widget,XtPointer,XtPointer);
    111109  //  static void keyHandler(Widget,XtPointer,XEvent*,Boolean*);
    112   G4bool fHelp;
    113   G4int fHelpChoice;
    114110  QMainWindow * fMainWindow;
    115111  QLabel *fCommandLabel;
     
    120116  QSignalMapper *signalMapper ;
    121117  QTreeWidget *fHelpTreeWidget;
     118  QDialog *fHelpDialog;
     119
    122120signals :
    123121  void myClicked(const QString &text);
     
    128126  void buttonCallback(const QString&);
    129127  void helpTreeCallback();
     128  void showHelp();
    130129};
    131130
  • trunk/geant4/interfaces/basic/src/G4UIQt.cc

    r512 r513  
    6161#include <stdlib.h>
    6262
    63 static G4bool ConvertStringToInt(const char*,int&);
    64 
     63// Pourquoi Static et non  variables de classe ?
    6564static G4bool exitSession = true;
    6665static G4bool exitPause = true;
    67 static G4bool exitHelp = true;
    6866/***************************************************************************/
    6967/**
     
    9189 char** argv
    9290)
     91  :fHelpDialog(NULL)
     92
    9393/***************************************************************************/
    9494/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
     
    147147  fMainWindow->setCentralWidget(splitter);
    148148
     149  // Add a quit subMenu
    149150  QMenu *fileMenu = fMainWindow->menuBar()->addMenu("File");
    150151  fileMenu->addAction("Quitter", fMainWindow, SLOT(close()));
     152
     153  // Add a Help menu
     154  QMenu *helpMenu = fMainWindow->menuBar()->addMenu("Help");
     155  helpMenu->addAction("Show Help", this, SLOT(showHelp()));
    151156
    152157  // Set the splitter size. The fTextArea sould be 2/3 on the fMainWindow
     
    298303  return 0;
    299304}
    300 /***************************************************************************/
    301 G4bool G4UIQt::GetHelpChoice(
    302  G4int& aInt
    303 )
    304 /***************************************************************************/
    305 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
    306 {
    307   printf("G4UIQt::GetHelpChoice\n");
    308  
    309   fHelp = true; // TO KEEP
    310 //   // SecondaryLoop : // TO KEEP
    311   G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ?
    312   Prompt("Help"); // TO KEEP
    313   exitHelp = false; // TO KEEP
    314   void* event; // TO KEEP
    315   while((event = interactorManager->GetEvent())!=NULL) {  // TO KEEP
    316     interactorManager->DispatchEvent(event); // TO KEEP
    317     if(exitHelp==true) break; // TO KEEP
    318   } // TO KEEP
    319   Prompt("session"); // TO KEEP
    320   // // TO KEEP
    321   if(fHelp==false) return false; // TO KEEP
    322   aInt = fHelpChoice; // TO KEEP
    323   fHelp = false; // TO KEEP
    324   return true; // TO KEEP
    325 }
    326 /***************************************************************************/
    327 void G4UIQt::ExitHelp(
    328 )
    329 /***************************************************************************/
    330 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
    331 {
    332   printf("G4UIQt::ExitHelp\n");
    333 }
    334305
    335306/***************************************************************************/
     
    343314  printf("G4UIQt::AddMenu %s %s\n",a_name,a_label);
    344315
    345   QMenu *fileMenu = fMainWindow->menuBar()->addMenu(a_label);
     316  //  QMenu *fileMenu = fMainWindow->menuBar()->addMenu(a_label);
     317  QMenu *fileMenu = new QMenu(a_label);
     318  fMainWindow->menuBar()->insertMenu(fMainWindow->menuBar()->actions().last(),fileMenu);
    346319  AddInteractor (a_name,(G4Interactor)fileMenu);
    347 
    348   //  QMenu *menu = new QMenu("test");//a_label);
    349   //  fMainWindow->menuBar()->addMenu(menu);
    350 
    351 //   if(menuBar==NULL) return;
    352 //   if(a_name==NULL) return;
    353 //   if(a_label==NULL) return;
    354 //   XtManageChild (menuBar);
    355 //   // Pulldown menu :
    356 //   Widget widget;
    357 //   widget = XmCreatePulldownMenu (menuBar,(char*)a_name,NULL,0);
    358 //   AddInteractor (a_name,(G4Interactor)widget);
    359 //   // Cascade button :
    360 //   Arg args[2];
    361 //   XmString cps = XmStringLtoRCreate((char*)a_label,XmSTRING_DEFAULT_CHARSET);
    362 //   XtSetArg (args[0],XmNlabelString,cps);
    363 //   XtSetArg (args[1],XmNsubMenuId,widget);
    364 //   widget = XmCreateCascadeButton (menuBar,(char*)a_name,args,2);
    365 //   XmStringFree (cps);
    366 //   XtManageChild (widget);
    367 //   ExecuteChangeSizeFunction(form);
    368320}
    369321/***************************************************************************/
     
    386338  signalMapper->setMapping(action, QString(a_command));
    387339  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(buttonCallback(const QString&)));
    388  
    389   //  std::string slot = SLOT(buttonCallback(std::string));   
    390   printf("G4UIQt::AddButton %s %s %s\n",a_menu,a_label,a_command);
    391 
    392 //   Widget widget = XmCreatePushButton(parent,(char*)a_label,NULL,0);
    393 //   XtManageChild (widget);
    394 //   XtAddCallback (widget,XmNactivateCallback,ButtonCallback,(XtPointer)this);
    395 //   commands[action] = a_command;
    396 }
    397 
    398 
    399 // /***************************************************************************/
    400 //G4String G4UIQt::GetCommand (
    401 //  QAction *a_widget
    402 //)
    403 // /***************************************************************************/
    404 // /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
    405 // {
    406 //   return commands[a_widget];
    407 // }
    408 /***************************************************************************/
    409 /***************************************************************************/
    410 /***************************************************************************/
     340}
     341
    411342
    412343/**
     
    420351/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
    421352{
    422   if(fHelp==true) return; // Disabled when in help.
    423353  G4String ss = G4String(a_command.toStdString().c_str());
    424354  printf ("debug : execute:\n-%s- %d %d \n",ss.data(),exitSession,exitPause);
     
    441371  if (fCommandArea->text().toStdString().c_str() != "") {
    442372    fCommandHistoryArea->append(fCommandArea->text());
    443     if(fHelp==true) {
    444   printf ("ne doit plus passer ici\n");
    445       exitHelp = true;
    446       fHelp = ConvertStringToInt(command.data(),fHelpChoice);
     373
     374    if (command(0,4) != "help") {
     375      ApplyShellCommand (command,exitSession,exitPause);
    447376    } else {
    448       if (command(0,4) != "help") {
    449         ApplyShellCommand (command,exitSession,exitPause);
    450       } else {
    451         printf ("terminal help\n");
    452         TerminalHelp(command);
    453       }
    454       if(exitSession==true)
    455         SessionTerminate();
     377      printf ("terminal help\n");
     378      TerminalHelp(command);
    456379    }
     380    if(exitSession==true)
     381      SessionTerminate();
    457382  }
    458383  fCommandArea->setText("");
     
    469394}
    470395
    471 //////////////////////////////////////////////////////////////////////////////
    472 G4bool ConvertStringToInt(
    473  const char* aString
    474 ,int& aInt
    475 )
    476 //////////////////////////////////////////////////////////////////////////////
    477 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
    478 {
    479   aInt = 0; // TO KEEP
    480   if(aString==NULL) return false; // TO KEEP
    481   char* s; // TO KEEP
    482   long value = strtol(aString,&s,10); // TO KEEP
    483   if(s==aString) return false; // TO KEEP
    484   aInt = value; // TO KEEP
    485   return true; // TO KEEP
    486 }
    487 
    488 #endif
    489 
     396
     397/**
     398  Open the help dialog in a separate window.
     399  This will be display as a tree widget
     400  Implementation of <b>void G4VBasicShell::TerminalHelp(G4String newCommand)</b>
     401
     402  @param newCommand : open the tree widget item on this command if is set
     403 */
    490404void G4UIQt::TerminalHelp(G4String newCommand)
    491405{
    492   QDialog *helpDialog = new QDialog;
     406  if (fHelpDialog) {
     407    fHelpDialog->show();
     408    fHelpDialog->raise();
     409    fHelpDialog->activateWindow();
     410    return;
     411  }
     412  fHelpDialog = new QDialog;
    493413
    494414  QSplitter *splitter = new QSplitter(Qt::Horizontal);
    495415  fHelpArea = new QTextEdit();
    496416  QPushButton *exitButton = new QPushButton("Exit");
    497   connect(exitButton, SIGNAL(clicked()), helpDialog,SLOT(close()));
     417  connect(exitButton, SIGNAL(clicked()), fHelpDialog,SLOT(close()));
    498418  fHelpArea->setReadOnly(true);
    499419
     
    503423  G4UIcommandTree * treeTop = UI->GetTree();
    504424
     425  // Look for the choosen command "newCommand"
     426  size_t i = newCommand.index(" ");
     427  G4UIcommand* expandCommand = NULL;
     428  if( i != std::string::npos )
     429  {
     430    G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
     431    newValue.strip(G4String::both);
     432    G4String targetCom = ModifyToFullPathCommand( newValue );
     433    expandCommand = treeTop->FindPath( targetCom );
     434  }
     435
     436  // build widget
    505437  fHelpTreeWidget = new QTreeWidget();
    506438  fHelpTreeWidget->setColumnCount(2);
     
    522454
    523455    // look for childs
    524     CreateChildTree(newItem,treeTop->GetTree(a+1));
     456    CreateChildTree(newItem,treeTop->GetTree(a+1),expandCommand);
    525457    items.append(newItem);
    526458  }
     
    530462  //  QSignalMapper signalMapper = new QSignalMapper(this);
    531463
    532   connect(fHelpTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem*, int)),this, SLOT(helpTreeCallback(QTreeWidgetItem*, int))); 
    533464  connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(helpTreeCallback())); 
    534465
     
    544475  vLayout->addWidget(splitter);
    545476  vLayout->addWidget(exitButton);
    546   helpDialog->setLayout(vLayout);
    547 
    548   helpDialog->resize(800,600);
    549   helpDialog->move(QPoint(400,150));
    550   helpDialog->show();
    551   helpDialog->raise();
    552   helpDialog->activateWindow();
    553   ////////////////
    554 
    555   printf ("G4UIQt::TerminalHelp \n");
    556 
    557 
    558 //   size_t i = newCommand.index(" ");
    559 //   if( i != std::string::npos )
    560 //   {
    561 //     G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
    562 //     newValue.strip(G4String::both);
    563 //     G4String targetCom = ModifyToFullPathCommand( newValue );
    564 //     G4UIcommand* theCommand = treeTop->FindPath( targetCom );
    565 //     if( theCommand != NULL )
    566 //     {
    567 //       theCommand->List();
    568 //       return;
    569 //     }
    570 //     else
    571 //     {
    572 //       G4cout << "Command <" << newValue << " is not found." << G4endl;
    573 //       return;
    574 //     }
    575 //   }
    576 
    577 //   G4UIcommandTree * floor[10];
    578 //   floor[0] = treeTop;
    579 //   G4int iFloor = 0;
    580 //   size_t prefixIndex = 1;
    581 //   G4String prefix = GetCurrentWorkingDirectory();
    582 //   while( prefixIndex < prefix.length()-1 )
    583 //   {
    584 //     size_t ii = prefix.index("/",prefixIndex);
    585 //     floor[iFloor+1] =
    586 //       floor[iFloor]->GetTree(G4String(prefix(0,ii+1)));
    587 //     prefixIndex = ii+1;
    588 //     iFloor++;
    589 //   }
    590 //   floor[iFloor]->ListCurrentWithNum();
    591 //   // 1998 Oct 2 non-number input
    592 //   while(1){
    593 //    //G4cout << G4endl << "Type the number ( 0:end, -n:n level back ) : "<<std::flush;
    594 //     G4cout << G4endl << "Type the number ( 0:end, -n:n level back ) : "<<G4endl;
    595 //     G4int i;
    596 //     if(!GetHelpChoice(i)){
    597 //       G4cout << G4endl << "Not a number, once more" << G4endl;
    598 //       continue;
    599 //     } else if( i < 0 ){
    600 //       iFloor += i;
    601 //       if( iFloor < 0 ) iFloor = 0;
    602 //       floor[iFloor]->ListCurrentWithNum();
    603 //       continue;
    604 //     } else if(i == 0) {
    605 //       break;
    606 //     } else if( i > 0 ) {
    607 //       G4int n_tree = floor[iFloor]->GetTreeEntry();
    608 //       if( i > n_tree )
    609 //       {
    610 //         if( i <= n_tree + floor[iFloor]->GetCommandEntry() )
    611 //         {
    612 //           floor[iFloor]->GetCommand(i-n_tree)->List();
    613 //         }
    614 //       }
    615 //       else
    616 //       {
    617 //         floor[iFloor+1] = floor[iFloor]->GetTree(i);
    618 //         iFloor++;
    619 //         floor[iFloor]->ListCurrentWithNum();
    620 //       }
    621 //     }
    622 //   }
    623   G4cout << "Exit from HELP." << G4endl << G4endl;
    624   //G4cout << G4endl;
    625   ExitHelp();
    626 }
    627 void G4UIQt::CreateChildTree(QTreeWidgetItem *a_parent,G4UIcommandTree *a_commandTree) {
     477  fHelpDialog->setLayout(vLayout);
     478
     479  fHelpDialog->resize(800,600);
     480  fHelpDialog->move(QPoint(400,150));
     481  fHelpDialog->show();
     482  fHelpDialog->raise();
     483  fHelpDialog->activateWindow();
     484
     485
     486}
     487void G4UIQt::CreateChildTree(QTreeWidgetItem *a_parent,G4UIcommandTree *a_commandTree,G4UIcommand* a_expandCommand) {
    628488
    629489  // Creating new item
     
    639499    newItem = new QTreeWidgetItem(stringList);
    640500
    641     //connecting callback
    642     //    signalMapper = new QSignalMapper(this);
    643     //    QAction *action = parent->addAction(a_label, signalMapper, SLOT(map()));
    644    
    645     //  signalMapper->setMapping(action, QString(a_command));
    646     //  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(helpTreeCallback(const QString&)));
    647     //QTreeWidget::itemActivated ( QTreeWidgetItem * item, int column )   [signal]
    648 
    649     CreateChildTree(newItem,a_commandTree->GetTree(a+1));
     501    CreateChildTree(newItem,a_commandTree->GetTree(a+1),a_expandCommand);
    650502    a_parent->addChild(newItem);
    651503  }
     
    664516    a_parent->addChild(newItem);
    665517
     518    // expand if possible
     519    if (a_expandCommand) {
     520      printf("compare : -%s- -%s- \n",((char*)(a_expandCommand->GetCommandPath()).data()),((char*)(a_commandTree->GetCommand(a+1)->GetCommandPath()).data()));
     521      if (a_expandCommand->GetCommandPath() == a_commandTree->GetCommand(a+1)->GetCommandPath()) {
     522        printf("mmmmmmmmmmmmmmmmmmm\n");
     523        newItem->setExpanded(true);
     524        fHelpArea->setText(GetCommandList(a_expandCommand));
     525      } else {
     526        newItem->setExpanded(false);
     527      }
     528    }
    666529  }
    667530}
     
    675538/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
    676539{
    677   printf ("G4UIQt::TerminalHelp ===========================\n");
     540  G4bool GetHelpChoice(G4int&);
    678541  QTreeWidgetItem* item =  NULL;
    679542  if (!fHelpTreeWidget)
     
    756619  return txt;
    757620}
     621
     622/***************************************************************************/
     623void G4UIQt::showHelp (
     624)
     625/***************************************************************************/
     626/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
     627{
     628  TerminalHelp("");
     629}
     630
     631#endif
Note: See TracChangeset for help on using the changeset viewer.