00001 //*-- Author : Valery Fine(fine@bnl.gov) 04/01/2006 00002 // 00003 // $Id: DialogsQ.C,v 1.3 2007/01/19 19:36:20 fine Exp $ 00004 // 00005 // This file contains the set of functions to use class QInputDialog 00006 // http://doc.trolltech.com/3.3/qinputdialog.html 00007 // static methods to either get a string, integer or floating point number. 00008 // 00009 // (see $ROOTSYS/macros/Dialogs.C for the ROOT GUI-based counterpart ) 00010 // 00011 // 00012 // The functions prompt for an input string using a simple dialog box. 00013 // There are also two functions showing how to use the file open and save dialogs. 00014 // see: http://doc.trolltech.com/3.3/qfiledialog.html#getOpenFileName 00015 // 00016 // The utility functions are: 00017 // -------------------------- 00018 // const char *OpenFileDialog() 00019 // const char *SaveFileDialog() 00020 // const char *GetStringDialog(const char *prompt, const char *defval) 00021 // Int_t GetIntegerDialog(const char *prompt, Int_t defval) 00022 // Float_t GetFloatDialog(const char *prompt, Float_t defval) 00023 // 00024 // To use the QInputDialog Qt class and the utility functions you just 00025 // have to load the DialogsQ.C file as follows: 00026 // 00027 // .x DialogsQ.C 00028 // 00029 // Now you can use them like: 00030 // { 00031 // const char *file = OpenFileDialog(); 00032 // Int_t run = GetIntegerDialog("Give run number:", 0); 00033 // Int_t event = GetIntegerDialog("Give event number:", 0); 00034 // printf("analyse run %d, event %d from file %s\n", run ,event, file); 00035 // } 00036 // 00037 #ifndef __CINT__ 00038 # include <qapplication.h> 00039 # include <qstyle.h> 00040 # include <qfiledialog.h> 00041 # include <qstringlist.h> 00042 # include <qstring.h> 00043 # include "TObjString.h" 00044 # include "TList.h" 00045 # include "TSystem.h" 00046 # include <qinputdialog.h> 00047 #endif 00048 00049 //--- Utility Functions -------------------------------------------------------- 00050 //______________________________________________________________________ 00051 void DialogsQ() { 00052 // Load the Qt ROOT dictionary 00053 #ifdef __CINT__ 00054 gSystem->Load("qtcint"); 00055 #endif 00056 } 00057 //______________________________________________________________________ 00058 const char *OpenFileDialog() 00059 { 00060 // Prompt for file to be opened. 00061 // http://doc.trolltech.com/3.3/qfiledialog.html#getOpenFileName 00062 00063 QString filter = 00064 "Macro files (*.C);" 00065 ";ROOT files (*.root);" 00066 ";PostScript (*.ps);" 00067 ";Encapsulated PostScript (*.eps);" 00068 ";Gif files (*.gif);" 00069 ";All files (*)"; 00070 00071 static QString fFilename; 00072 fFilename = QFileDialog::getOpenFileName(gSystem->WorkingDirectory() 00073 , filter); 00074 00075 return (const char*)fFilename; 00076 } 00077 00078 //______________________________________________________________________ 00079 const char *SaveFileDialog() 00080 { 00081 // Prompt for file to be saved. 00082 // http://doc.trolltech.com/3.3/qfiledialog.html#getSaveFileNamehttp://doc.trolltech.com/3.3/qfiledialog.html#getSaveFileName 00083 00084 QString filter = 00085 ";Macro files (*.C);" 00086 ";ROOT files (*.root);" 00087 ";PostScript (*.ps);" 00088 ";Encapsulated PostScript (*.eps);" 00089 ";Gif files (*.gif);" 00090 ";All files (*);"; 00091 00092 static QString fFilename; 00093 fFilename = QFileDialog::getSaveFileName(gSystem->WorkingDirectory() 00094 , filter); 00095 00096 return (const char*)fFilename; 00097 } 00098 00099 //______________________________________________________________________ 00100 const char *GetStringDialog(const char *prompt, const char *defval) 00101 { 00102 // Prompt for string. The typed in string is returned. 00103 // http://doc.trolltech.com/3.3/qinputdialog.html#getText 00104 00105 static QString answer; 00106 00107 answer = QInputDialog::getText( 00108 "Enter text", prompt, QLineEdit::Normal,defval); 00109 00110 return (const char *)answer; 00111 } 00112 00113 //______________________________________________________________________ 00114 Int_t GetIntegerDialog(const char *prompt, Int_t defval 00115 ,int minValue = -2147483647, int maxValue = 2147483647 00116 , int step = 1) 00117 { 00118 // Prompt for integer. The typed in integer is returned. 00119 // http://doc.trolltech.com/3.3/qinputdialog.html#getInteger 00120 00121 return QInputDialog::getInteger("Enter integer", prompt, defval 00122 ,minValue, maxValue, step); 00123 } 00124 00125 //______________________________________________________________________ 00126 Double_t GetFloatDialog(const char *prompt, Double_t defval 00127 , double minValue = -2147483647, double maxValue = 2147483647 00128 , int decimals = 1) 00129 { 00130 // Prompt for float. The typed in float is returned. 00131 // http://doc.trolltech.com/3.3/qinputdialog.html#getDouble 00132 // 00133 return QInputDialog::getDouble("Enter double", prompt, defval 00134 ,minValue, maxValue, decimals); 00135 }
1.5.9