StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DialogsQ.C
1 //*-- Author : Valery Fine(fine@bnl.gov) 04/01/2006
2 //
3 // $Id: DialogsQ.C,v 1.3 2007/01/19 19:36:20 fine Exp $
4 //
5 // This file contains the set of functions to use class QInputDialog
6 // http://doc.trolltech.com/3.3/qinputdialog.html
7 // static methods to either get a string, integer or floating point number.
8 //
9 // (see $ROOTSYS/macros/Dialogs.C for the ROOT GUI-based counterpart )
10 //
11 //
12 // The functions prompt for an input string using a simple dialog box.
13 // There are also two functions showing how to use the file open and save dialogs.
14 // see: http://doc.trolltech.com/3.3/qfiledialog.html#getOpenFileName
15 //
16 // The utility functions are:
17 // --------------------------
18 // const char *OpenFileDialog()
19 // const char *SaveFileDialog()
20 // const char *GetStringDialog(const char *prompt, const char *defval)
21 // Int_t GetIntegerDialog(const char *prompt, Int_t defval)
22 // Float_t GetFloatDialog(const char *prompt, Float_t defval)
23 //
24 // To use the QInputDialog Qt class and the utility functions you just
25 // have to load the DialogsQ.C file as follows:
26 //
27 // .x DialogsQ.C
28 //
29 // Now you can use them like:
30 // {
31 // const char *file = OpenFileDialog();
32 // Int_t run = GetIntegerDialog("Give run number:", 0);
33 // Int_t event = GetIntegerDialog("Give event number:", 0);
34 // printf("analyse run %d, event %d from file %s\n", run ,event, file);
35 // }
36 //
37 #ifndef __CINT__
38 # include <qapplication.h>
39 # include <qstyle.h>
40 # include <qfiledialog.h>
41 # include <qstringlist.h>
42 # include <qstring.h>
43 # include "TObjString.h"
44 # include "TList.h"
45 # include "TSystem.h"
46 # include <qinputdialog.h>
47 #endif
48 
49 //--- Utility Functions --------------------------------------------------------
50 //______________________________________________________________________
51 void DialogsQ() {
52  // Load the Qt ROOT dictionary
53 #ifdef __CINT__
54  gSystem->Load("qtcint");
55 #endif
56 }
57 //______________________________________________________________________
58 const char *OpenFileDialog()
59 {
60  // Prompt for file to be opened.
61  // http://doc.trolltech.com/3.3/qfiledialog.html#getOpenFileName
62 
63  QString filter =
64  "Macro files (*.C);"
65  ";ROOT files (*.root);"
66  ";PostScript (*.ps);"
67  ";Encapsulated PostScript (*.eps);"
68  ";Gif files (*.gif);"
69  ";All files (*)";
70 
71  static QString fFilename;
72  fFilename = QFileDialog::getOpenFileName(gSystem->WorkingDirectory()
73  , filter);
74 
75  return (const char*)fFilename;
76 }
77 
78 //______________________________________________________________________
79 const char *SaveFileDialog()
80 {
81  // Prompt for file to be saved.
82  // http://doc.trolltech.com/3.3/qfiledialog.html#getSaveFileNamehttp://doc.trolltech.com/3.3/qfiledialog.html#getSaveFileName
83 
84  QString filter =
85  ";Macro files (*.C);"
86  ";ROOT files (*.root);"
87  ";PostScript (*.ps);"
88  ";Encapsulated PostScript (*.eps);"
89  ";Gif files (*.gif);"
90  ";All files (*);";
91 
92  static QString fFilename;
93  fFilename = QFileDialog::getSaveFileName(gSystem->WorkingDirectory()
94  , filter);
95 
96  return (const char*)fFilename;
97 }
98 
99 //______________________________________________________________________
100 const char *GetStringDialog(const char *prompt, const char *defval)
101 {
102  // Prompt for string. The typed in string is returned.
103  // http://doc.trolltech.com/3.3/qinputdialog.html#getText
104 
105  static QString answer;
106 
107  answer = QInputDialog::getText(
108  "Enter text", prompt, QLineEdit::Normal,defval);
109 
110  return (const char *)answer;
111 }
112 
113 //______________________________________________________________________
114 Int_t GetIntegerDialog(const char *prompt, Int_t defval
115  ,int minValue = -2147483647, int maxValue = 2147483647
116  , int step = 1)
117 {
118  // Prompt for integer. The typed in integer is returned.
119  // http://doc.trolltech.com/3.3/qinputdialog.html#getInteger
120 
121  return QInputDialog::getInteger("Enter integer", prompt, defval
122  ,minValue, maxValue, step);
123 }
124 
125 //______________________________________________________________________
126 Double_t GetFloatDialog(const char *prompt, Double_t defval
127  , double minValue = -2147483647, double maxValue = 2147483647
128  , int decimals = 1)
129 {
130  // Prompt for float. The typed in float is returned.
131  // http://doc.trolltech.com/3.3/qinputdialog.html#getDouble
132  //
133  return QInputDialog::getDouble("Enter double", prompt, defval
134  ,minValue, maxValue, decimals);
135 }