- Timestamp:
- Jun 15, 2007, 4:14:29 PM (17 years ago)
- Location:
- trunk/geant4/interfaces/basic
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/geant4/interfaces/basic/include/G4UIQt.hh
r513 r514 99 99 void SecondaryLoop(G4String); // a VIRER 100 100 void TerminalHelp(G4String); 101 void CreateChildTree(QTreeWidgetItem*,G4UIcommandTree* ,G4UIcommand*);101 void CreateChildTree(QTreeWidgetItem*,G4UIcommandTree*); 102 102 QString GetCommandList(G4UIcommand*); 103 void expandHelpItem (QTreeWidgetItem *,G4UIcommand*); 104 103 105 104 106 private: … … 126 128 void buttonCallback(const QString&); 127 129 void helpTreeCallback(); 128 void showHelp ();130 void showHelpCallback(); 129 131 }; 130 132 -
trunk/geant4/interfaces/basic/src/G4UIQt.cc
r513 r514 153 153 // Add a Help menu 154 154 QMenu *helpMenu = fMainWindow->menuBar()->addMenu("Help"); 155 helpMenu->addAction("Show Help", this, SLOT(showHelp ()));155 helpMenu->addAction("Show Help", this, SLOT(showHelpCallback())); 156 156 157 157 // Set the splitter size. The fTextArea sould be 2/3 on the fMainWindow … … 341 341 342 342 343 /**344 Callback call when "enter" clicked on the command zone.345 Send the command to geant4346 */347 void G4UIQt::buttonCallback (348 const QString& a_command349 )350 /***************************************************************************/351 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/352 {353 G4String ss = G4String(a_command.toStdString().c_str());354 printf ("debug : execute:\n-%s- %d %d \n",ss.data(),exitSession,exitPause);355 ApplyShellCommand(ss,exitSession,exitPause);356 if(exitSession==true)357 SessionTerminate();358 }359 360 /**361 Callback call when "click on a menu entry.362 Send the associated command to geant4363 */364 void G4UIQt::commandEnteredCallback (365 )366 /***************************************************************************/367 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/368 {369 printf ("debug : callback\n");370 G4String command (fCommandArea->text().toStdString().c_str());371 if (fCommandArea->text().toStdString().c_str() != "") {372 fCommandHistoryArea->append(fCommandArea->text());373 374 if (command(0,4) != "help") {375 ApplyShellCommand (command,exitSession,exitPause);376 } else {377 printf ("terminal help\n");378 TerminalHelp(command);379 }380 if(exitSession==true)381 SessionTerminate();382 }383 fCommandArea->setText("");384 }385 386 387 /***************************************************************************/388 void G4UIQt::clearButtonCallback (389 )390 /***************************************************************************/391 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/392 {393 fTextArea->clear();394 }395 343 396 344 … … 404 352 void G4UIQt::TerminalHelp(G4String newCommand) 405 353 { 406 if (fHelpDialog) { 407 fHelpDialog->show(); 408 fHelpDialog->raise(); 409 fHelpDialog->activateWindow(); 410 return; 411 } 412 fHelpDialog = new QDialog; 413 414 QSplitter *splitter = new QSplitter(Qt::Horizontal); 415 fHelpArea = new QTextEdit(); 416 QPushButton *exitButton = new QPushButton("Exit"); 417 connect(exitButton, SIGNAL(clicked()), fHelpDialog,SLOT(close())); 418 fHelpArea->setReadOnly(true); 419 420 // the help tree 421 G4UImanager* UI = G4UImanager::GetUIpointer(); 422 if(UI==NULL) return; 423 G4UIcommandTree * treeTop = UI->GetTree(); 354 if (!fHelpDialog) { 355 fHelpDialog = new QDialog; 356 357 QSplitter *splitter = new QSplitter(Qt::Horizontal); 358 fHelpArea = new QTextEdit(); 359 QPushButton *exitButton = new QPushButton("Exit"); 360 connect(exitButton, SIGNAL(clicked()), fHelpDialog,SLOT(close())); 361 fHelpArea->setReadOnly(true); 362 363 // the help tree 364 G4UImanager* UI = G4UImanager::GetUIpointer(); 365 if(UI==NULL) return; 366 G4UIcommandTree * treeTop = UI->GetTree(); 367 368 369 // build widget 370 fHelpTreeWidget = new QTreeWidget(); 371 fHelpTreeWidget->setColumnCount(2); 372 fHelpTreeWidget->setColumnHidden(1,true); 373 QStringList labels; 374 labels << QString("Command") << QString("Description"); 375 fHelpTreeWidget->setHeaderLabels(labels); 376 377 QList<QTreeWidgetItem *> items; 378 G4int treeSize = treeTop->GetTreeEntry(); 379 QTreeWidgetItem * newItem; 380 for (int a=0;a<treeSize;a++) { 381 // Creating new item 382 QStringList stringList; 383 stringList << QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed() ; 384 stringList << QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed() ; 385 386 newItem = new QTreeWidgetItem(stringList); 387 388 // look for childs 389 CreateChildTree(newItem,treeTop->GetTree(a+1)); 390 items.append(newItem); 391 } 392 fHelpTreeWidget->insertTopLevelItems(0, items); 393 394 //connecting callback 395 // QSignalMapper signalMapper = new QSignalMapper(this); 396 397 connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(helpTreeCallback())); 398 399 // Set layouts 400 QHBoxLayout *splitterLayout = new QHBoxLayout; 401 402 QVBoxLayout *vLayout = new QVBoxLayout; 403 404 splitterLayout->addWidget(fHelpTreeWidget); 405 splitterLayout->addWidget(fHelpArea); 406 splitter->setLayout(splitterLayout); 407 408 vLayout->addWidget(splitter); 409 vLayout->addWidget(exitButton); 410 fHelpDialog->setLayout(vLayout); 411 412 } 424 413 425 414 // Look for the choosen command "newCommand" 426 415 size_t i = newCommand.index(" "); 427 G4 UIcommand* expandCommand = NULL;416 G4String targetCom=""; 428 417 if( i != std::string::npos ) 429 418 { 430 419 G4String newValue = newCommand(i+1,newCommand.length()-(i+1)); 431 420 newValue.strip(G4String::both); 432 G4String targetCom = ModifyToFullPathCommand( newValue ); 433 expandCommand = treeTop->FindPath( targetCom ); 434 } 435 436 // build widget 437 fHelpTreeWidget = new QTreeWidget(); 438 fHelpTreeWidget->setColumnCount(2); 439 fHelpTreeWidget->setColumnHidden(1,true); 440 QStringList labels; 441 labels << QString("Summary") << QString("Description"); 442 fHelpTreeWidget->setHeaderLabels(labels); 443 444 QList<QTreeWidgetItem *> items; 445 G4int treeSize = treeTop->GetTreeEntry(); 446 QTreeWidgetItem * newItem; 447 for (int a=0;a<treeSize;a++) { 448 // Creating new item 449 QStringList stringList; 450 stringList << QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed() ; 451 stringList << QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed() ; 452 453 newItem = new QTreeWidgetItem(stringList); 454 455 // look for childs 456 CreateChildTree(newItem,treeTop->GetTree(a+1),expandCommand); 457 items.append(newItem); 458 } 459 fHelpTreeWidget->insertTopLevelItems(0, items); 460 461 //connecting callback 462 // QSignalMapper signalMapper = new QSignalMapper(this); 463 464 connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(helpTreeCallback())); 465 466 // Set layouts 467 QHBoxLayout *splitterLayout = new QHBoxLayout; 468 469 QVBoxLayout *vLayout = new QVBoxLayout; 470 471 splitterLayout->addWidget(fHelpTreeWidget); 472 splitterLayout->addWidget(fHelpArea); 473 splitter->setLayout(splitterLayout); 474 475 vLayout->addWidget(splitter); 476 vLayout->addWidget(exitButton); 477 fHelpDialog->setLayout(vLayout); 478 421 targetCom = ModifyToFullPathCommand( newValue ); 422 printf("test : av:%s-- ap:%s--\n",((char*)newValue.data()),((char*)targetCom.data())); 423 } 424 if (targetCom != "") { 425 QList<QTreeWidgetItem *> list = fHelpTreeWidget->findItems(QString(((char*)targetCom.data())),Qt::MatchFixedString,0); 426 for (int a=0;a<13;a++) { 427 printf("verif.... =%s= +%s+\n",fHelpTreeWidget->topLevelItem(a)->text(0).toStdString().c_str(),((char*)targetCom.data())); 428 } 429 430 if (!list.isEmpty()) { 431 printf("found...........\n"); 432 if (list.first()->childCount() >0) 433 list.first()->setExpanded(true); 434 435 QList<QTreeWidgetItem *> selected = fHelpTreeWidget->selectedItems(); 436 if (!selected.isEmpty()) { 437 for (int a=0;a<selected.count();a++) { 438 printf("unselect %d\n",selected.count()); 439 // selected.at(a)->setSelected(false); 440 selected.first()->setSelected(false); 441 } 442 printf("AAA\n"); 443 } 444 printf("BB\n"); 445 list.first()->setSelected(true); 446 printf("CC\n"); 447 448 // Call the update of the right textArea 449 helpTreeCallback(); 450 printf("DD\n"); 451 } 452 } 479 453 fHelpDialog->resize(800,600); 480 454 fHelpDialog->move(QPoint(400,150)); … … 482 456 fHelpDialog->raise(); 483 457 fHelpDialog->activateWindow(); 484 485 486 } 487 void G4UIQt::CreateChildTree(QTreeWidgetItem *a_parent,G4UIcommandTree *a_commandTree,G4UIcommand* a_expandCommand) { 458 } 459 460 461 462 void G4UIQt::CreateChildTree(QTreeWidgetItem *a_parent,G4UIcommandTree *a_commandTree) { 488 463 489 464 // Creating new item … … 499 474 newItem = new QTreeWidgetItem(stringList); 500 475 501 CreateChildTree(newItem,a_commandTree->GetTree(a+1) ,a_expandCommand);476 CreateChildTree(newItem,a_commandTree->GetTree(a+1)); 502 477 a_parent->addChild(newItem); 503 478 } … … 510 485 511 486 QStringList stringList; 512 stringList << QString((char*)(a_commandTree->GetCommand(a+1)->Get Title()).data()).trimmed() ;487 stringList << QString((char*)(a_commandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed() ; 513 488 stringList << QString((char*)(a_commandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed() ; 514 489 newItem = new QTreeWidgetItem(stringList); 515 490 516 491 a_parent->addChild(newItem); 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 } 529 } 530 } 531 532 /** 533 This callback is activated when user selected a item in the help tree 534 */ 535 void G4UIQt::helpTreeCallback ( 536 ) 537 /***************************************************************************/ 538 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 539 { 540 G4bool GetHelpChoice(G4int&); 541 QTreeWidgetItem* item = NULL; 542 if (!fHelpTreeWidget) 543 return ; 544 545 if (!fHelpArea) 546 return; 547 548 item = fHelpTreeWidget->selectedItems().first(); 549 if (!item) 550 return; 551 552 G4UImanager* UI = G4UImanager::GetUIpointer(); 553 if(UI==NULL) return; 554 G4UIcommandTree * treeTop = UI->GetTree(); 555 G4UIcommand* command = treeTop->FindPath(item->text (1).toStdString().c_str()); 556 if (command) { 557 fHelpArea->setText(GetCommandList(command)); 558 } else { 559 // this is not a command, this is a sub directory 560 // We display the Title 561 fHelpArea->setText(item->text (1).toStdString().c_str()); 562 } 563 } 492 newItem->setExpanded(false); 493 } 494 } 495 564 496 565 497 /** … … 620 552 } 621 553 622 /***************************************************************************/ 623 void G4UIQt::showHelp ( 554 555 556 /***************************************************************************/ 557 void G4UIQt::expandHelpItem ( 558 QTreeWidgetItem *a_parent 559 ,G4UIcommand* a_expandCommand 560 ) 561 /***************************************************************************/ 562 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 563 { 564 } 565 566 567 568 /***************************************************************************/ 569 // 570 // SLOTS DEFINITIONS 571 // 572 /***************************************************************************/ 573 574 /***************************************************************************/ 575 void G4UIQt::showHelpCallback ( 624 576 ) 625 577 /***************************************************************************/ … … 629 581 } 630 582 583 /***************************************************************************/ 584 void G4UIQt::clearButtonCallback ( 585 ) 586 /***************************************************************************/ 587 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 588 { 589 fTextArea->clear(); 590 } 591 592 593 /** 594 Callback call when "click on a menu entry. 595 Send the associated command to geant4 596 */ 597 void G4UIQt::commandEnteredCallback ( 598 ) 599 /***************************************************************************/ 600 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 601 { 602 printf ("debug : callback\n"); 603 G4String command (fCommandArea->text().toStdString().c_str()); 604 if (fCommandArea->text().toStdString().c_str() != "") { 605 fCommandHistoryArea->append(fCommandArea->text()); 606 607 if (command(0,4) != "help") { 608 ApplyShellCommand (command,exitSession,exitPause); 609 } else { 610 printf ("terminal help\n"); 611 TerminalHelp(command); 612 } 613 if(exitSession==true) 614 SessionTerminate(); 615 } 616 fCommandArea->setText(""); 617 } 618 619 /** 620 Callback call when "enter" clicked on the command zone. 621 Send the command to geant4 622 */ 623 void G4UIQt::buttonCallback ( 624 const QString& a_command 625 ) 626 /***************************************************************************/ 627 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 628 { 629 G4String ss = G4String(a_command.toStdString().c_str()); 630 printf ("debug : execute:\n-%s- %d %d \n",ss.data(),exitSession,exitPause); 631 ApplyShellCommand(ss,exitSession,exitPause); 632 if(exitSession==true) 633 SessionTerminate(); 634 } 635 /** 636 This callback is activated when user selected a item in the help tree 637 */ 638 void G4UIQt::helpTreeCallback ( 639 ) 640 /***************************************************************************/ 641 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ 642 { 643 // G4bool GetHelpChoice(G4int&); 644 QTreeWidgetItem* item = NULL; 645 if (!fHelpTreeWidget) 646 return ; 647 648 if (!fHelpArea) 649 return; 650 651 item = fHelpTreeWidget->selectedItems().first(); 652 if (!item) 653 return; 654 655 G4UImanager* UI = G4UImanager::GetUIpointer(); 656 if(UI==NULL) return; 657 G4UIcommandTree * treeTop = UI->GetTree(); 658 G4UIcommand* command = treeTop->FindPath(item->text (1).toStdString().c_str()); 659 if (command) { 660 fHelpArea->setText(GetCommandList(command)); 661 } else { 662 // this is not a command, this is a sub directory 663 // We display the Title 664 fHelpArea->setText(item->text (1).toStdString().c_str()); 665 } 666 } 667 668 631 669 #endif
Note: See TracChangeset
for help on using the changeset viewer.