Changeset 513 for trunk/geant4/interfaces/basic/src
- Timestamp:
- Jun 15, 2007, 2:33:46 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/geant4/interfaces/basic/src/G4UIQt.cc
r512 r513 61 61 #include <stdlib.h> 62 62 63 static G4bool ConvertStringToInt(const char*,int&); 64 63 // Pourquoi Static et non variables de classe ? 65 64 static G4bool exitSession = true; 66 65 static G4bool exitPause = true; 67 static G4bool exitHelp = true;68 66 /***************************************************************************/ 69 67 /** … … 91 89 char** argv 92 90 ) 91 :fHelpDialog(NULL) 92 93 93 /***************************************************************************/ 94 94 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ … … 147 147 fMainWindow->setCentralWidget(splitter); 148 148 149 // Add a quit subMenu 149 150 QMenu *fileMenu = fMainWindow->menuBar()->addMenu("File"); 150 151 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())); 151 156 152 157 // Set the splitter size. The fTextArea sould be 2/3 on the fMainWindow … … 298 303 return 0; 299 304 } 300 /***************************************************************************/301 G4bool G4UIQt::GetHelpChoice(302 G4int& aInt303 )304 /***************************************************************************/305 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/306 {307 printf("G4UIQt::GetHelpChoice\n");308 309 fHelp = true; // TO KEEP310 // // SecondaryLoop : // TO KEEP311 G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ?312 Prompt("Help"); // TO KEEP313 exitHelp = false; // TO KEEP314 void* event; // TO KEEP315 while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP316 interactorManager->DispatchEvent(event); // TO KEEP317 if(exitHelp==true) break; // TO KEEP318 } // TO KEEP319 Prompt("session"); // TO KEEP320 // // TO KEEP321 if(fHelp==false) return false; // TO KEEP322 aInt = fHelpChoice; // TO KEEP323 fHelp = false; // TO KEEP324 return true; // TO KEEP325 }326 /***************************************************************************/327 void G4UIQt::ExitHelp(328 )329 /***************************************************************************/330 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/331 {332 printf("G4UIQt::ExitHelp\n");333 }334 305 335 306 /***************************************************************************/ … … 343 314 printf("G4UIQt::AddMenu %s %s\n",a_name,a_label); 344 315 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); 346 319 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);368 320 } 369 321 /***************************************************************************/ … … 386 338 signalMapper->setMapping(action, QString(a_command)); 387 339 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 411 342 412 343 /** … … 420 351 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 421 352 { 422 if(fHelp==true) return; // Disabled when in help.423 353 G4String ss = G4String(a_command.toStdString().c_str()); 424 354 printf ("debug : execute:\n-%s- %d %d \n",ss.data(),exitSession,exitPause); … … 441 371 if (fCommandArea->text().toStdString().c_str() != "") { 442 372 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); 447 376 } 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); 456 379 } 380 if(exitSession==true) 381 SessionTerminate(); 457 382 } 458 383 fCommandArea->setText(""); … … 469 394 } 470 395 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 */ 490 404 void G4UIQt::TerminalHelp(G4String newCommand) 491 405 { 492 QDialog *helpDialog = new QDialog; 406 if (fHelpDialog) { 407 fHelpDialog->show(); 408 fHelpDialog->raise(); 409 fHelpDialog->activateWindow(); 410 return; 411 } 412 fHelpDialog = new QDialog; 493 413 494 414 QSplitter *splitter = new QSplitter(Qt::Horizontal); 495 415 fHelpArea = new QTextEdit(); 496 416 QPushButton *exitButton = new QPushButton("Exit"); 497 connect(exitButton, SIGNAL(clicked()), helpDialog,SLOT(close()));417 connect(exitButton, SIGNAL(clicked()), fHelpDialog,SLOT(close())); 498 418 fHelpArea->setReadOnly(true); 499 419 … … 503 423 G4UIcommandTree * treeTop = UI->GetTree(); 504 424 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 505 437 fHelpTreeWidget = new QTreeWidget(); 506 438 fHelpTreeWidget->setColumnCount(2); … … 522 454 523 455 // look for childs 524 CreateChildTree(newItem,treeTop->GetTree(a+1) );456 CreateChildTree(newItem,treeTop->GetTree(a+1),expandCommand); 525 457 items.append(newItem); 526 458 } … … 530 462 // QSignalMapper signalMapper = new QSignalMapper(this); 531 463 532 connect(fHelpTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem*, int)),this, SLOT(helpTreeCallback(QTreeWidgetItem*, int)));533 464 connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(helpTreeCallback())); 534 465 … … 544 475 vLayout->addWidget(splitter); 545 476 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 } 487 void G4UIQt::CreateChildTree(QTreeWidgetItem *a_parent,G4UIcommandTree *a_commandTree,G4UIcommand* a_expandCommand) { 628 488 629 489 // Creating new item … … 639 499 newItem = new QTreeWidgetItem(stringList); 640 500 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); 650 502 a_parent->addChild(newItem); 651 503 } … … 664 516 a_parent->addChild(newItem); 665 517 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 } 666 529 } 667 530 } … … 675 538 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 676 539 { 677 printf ("G4UIQt::TerminalHelp ===========================\n");540 G4bool GetHelpChoice(G4int&); 678 541 QTreeWidgetItem* item = NULL; 679 542 if (!fHelpTreeWidget) … … 756 619 return txt; 757 620 } 621 622 /***************************************************************************/ 623 void G4UIQt::showHelp ( 624 ) 625 /***************************************************************************/ 626 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 627 { 628 TerminalHelp(""); 629 } 630 631 #endif
Note: See TracChangeset
for help on using the changeset viewer.