Diana Software
QGCanvasWindowButtonsFrame.cc
Go to the documentation of this file.
2 #include <iostream>
3 #include <string>
4 #include <vector>
5 #include "QGCanvasWindow.hh"
6 #include "QGCutsEditorWindow.hh"
7 #include "QGDefaultsHandler.hh"
8 #include "QGFileHandler.hh"
9 #include "QGPlot.hh"
11 #include "QGPlotEditWindow.hh"
12 #include "QGPlotFrame.hh"
13 #include <TApplication.h>
14 #include <TCanvas.h>
15 #include <TGButton.h>
16 #include <TGClient.h>
17 #include <TGFileDialog.h>
18 #include <TGPicture.h>
19 #include <TGTextEntry.h>
20 #include <TRootEmbeddedCanvas.h>
21 
22 // Images
23 #include "ImageExportCuts.xpm"
24 #include "ImageGoToPlots.xpm"
25 #include "ImageNameLarge.xpm"
26 #include "ImageNewWindow.xpm"
27 #include "ImagePlotsList.xpm"
28 #include "ImageQuit.xpm"
29 #include "ImageSaveCanvas.xpm"
30 #include "ImageSetupWindow.xpm"
31 
33 
34 using std::cout;
35 using std::endl;
36 using std::string;
37 using std::vector;
38 
40 TGHorizontalFrame(p, w, h),
41 fCanvasWindow(p)
42 {
43  SetCleanup(kDeepCleanup);
44 
45  fNameButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("NameLarge", (char**)ImageNameLarge));
46  AddFrame(fNameButton, new TGLayoutHints(kLHintsCenterY, 0, 0, 0, 0));
47  fNameButton->SetToolTipText("Set the window name");
48  fNameButton->Connect("Clicked()", "QGCanvasWindowButtonsFrame", this, "HandleNameButton()");
49 
50  fNameEntryBox = new TGTextEntry(this);
51  AddFrame(fNameEntryBox, new TGLayoutHints(kLHintsCenterY, 0, 15, 0, 0));
52  fNameEntryBox->Resize(fNameEntryBox->GetDefaultWidth(), 25);
53  fNameEntryBox->SetToolTipText("Enter a new name for the window and press Return. Leave blank to cancel.");
54  fNameEntryBox->Connect("ReturnPressed()", "QGCanvasWindowButtonsFrame", this, "HandleNameEntryBox()");
55 
56  fSetupWindowButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("SetupWindow", (char**)ImageSetupWindow));
57  AddFrame(fSetupWindowButton, new TGLayoutHints(kLHintsCenterY, 0, 0, 0, 0));
58  fSetupWindowButton->SetToolTipText("Go to the setup window to open and close files or save the session");
59  fSetupWindowButton->Connect("Clicked()", "QGCanvasWindowButtonsFrame", this, "HandleSetupWindowButton()");
60 
61  fSaveCanvasButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("SaveCanvas", (char**)ImageSaveCanvas));
62  AddFrame(fSaveCanvasButton, new TGLayoutHints(kLHintsCenterY, 0, 0, 0, 0));
63  fSaveCanvasButton->SetToolTipText("Save the canvas as an image");
64  fSaveCanvasButton->Connect("Clicked()", "QGCanvasWindowButtonsFrame", this, "HandleSaveCanvasButton()");
65 
66  fPlotsListButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("PlotsList", (char**)ImagePlotsList));
67  AddFrame(fPlotsListButton, new TGLayoutHints(kLHintsCenterY, 0, 0, 0, 0));
68  fPlotsListButton->SetToolTipText("Show list of plots and graphical cuts");
69  fPlotsListButton->Connect("Clicked()", "QGCanvasWindowButtonsFrame", this, "HandlePlotsListButton()");
70 
71  fNewWindowButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("NewWindow", (char**)ImageNewWindow));
72  AddFrame(fNewWindowButton, new TGLayoutHints(kLHintsCenterY, 0, 0, 0, 0));
73  fNewWindowButton->SetToolTipText("Open a new window");
74  fNewWindowButton->Connect("Clicked()", "QGCanvasWindowButtonsFrame", this, "HandleNewWindowButton()");
75 
76  fExportCutsButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("ExportCuts", (char**)ImageExportCuts));
77  AddFrame(fExportCutsButton, new TGLayoutHints(kLHintsCenterY, 0, 0, 0, 0));
78  fExportCutsButton->SetToolTipText("Open editor for exporting cuts to Diana");
79  fExportCutsButton->Connect("Clicked()", "QGCanvasWindowButtonsFrame", this, "HandleExportCutsButton()");
80 
81  fGoToPlotsButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("GoToPlots", (char**)ImageGoToPlots));
82  AddFrame(fGoToPlotsButton, new TGLayoutHints(kLHintsCenterY, 0, 0, 0, 0));
83  fGoToPlotsButton->SetToolTipText("Go to plots window");
84  fGoToPlotsButton->Connect("Clicked()", "QGCanvasWindowButtonsFrame", this, "HandleGoToPlotsButton()");
85 
86  fQuitButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("Quit", (char**)ImageQuit));
87  AddFrame(fQuitButton, new TGLayoutHints(kLHintsCenterY, 0, 0, 0, 0));
88  fQuitButton->SetToolTipText("Quit the GUI");
89  fQuitButton->Connect("Clicked()", "QGCanvasWindowButtonsFrame", this, "HandleQuitButton()");
90 }
91 
93 {
94  Cleanup();
95 }
96 
98 {
99  new QGCutsEditorWindow();
100 }
101 
103 {
106 }
107 
109 {
110  if (IsVisible(fNameEntryBox)) {
112  } else {
113  fNameEntryBox->SetText(fCanvasWindow->GetWindowName());
114  ShowFrame(fNameEntryBox);
115  Resize(GetDefaultSize());
116  fNameEntryBox->SetFocus();
117  fNameEntryBox->SelectAll();
118  }
119 }
120 
122 {
123  string newName = fNameEntryBox->GetText();
124  if (newName != "") {
125  fCanvasWindow->SetWindowName(newName.c_str());
127  }
128  HideFrame(fNameEntryBox);
129  Resize(GetDefaultSize());
130 }
131 
133 {
134  new QGCanvasWindow();
136 }
137 
139 {
141 }
142 
144 {
145  gApplication->Terminate(0);
146 }
147 
149 {
150  string canvasDirectory = QGDefaultsHandler::Instance()->GetSaveCanvasDirectory();
151  TString dir(canvasDirectory.c_str());
152  TGFileInfo fi;
153  fi.fIniDir = StrDup(dir);
154  const char *fileTypes[] = {"Encapsulated Postscript" , "*.eps",
155  "Portable Document Format" , "*.pdf",
156  "Portable Network Graphics" , "*.png",
157  "ROOT Macro" , "*.C",
158  "Scalable Vector Graphics" , "*.svg",
159  0 , 0};
160  fi.fFileTypes = fileTypes;
161  new TGFileDialog(gClient->GetRoot(), 0, kFDSave, &fi);
162  if (fi.fFilename) {
163  TString filename(fi.fFilename);
164  TString extension(fi.fFileTypes[fi.fFileTypeIdx+1]);
165  extension.Remove(TString::kLeading, '*');
166  if (!filename.EndsWith(extension)) {
167  filename.Append(extension);
168  }
169  fCanvasWindow->GetPlotFrame()->GetEmbeddedCanvas()->GetCanvas()->SaveAs(filename);
170  string currentDirectory = fi.fIniDir;
171  if (currentDirectory != canvasDirectory) {
173  }
174  }
175 }
176 
178 {
180 }
181 
183 {
184  ShowFrame(fNameButton);
185  HideFrame(fNameEntryBox);
186  ShowFrame(fSetupWindowButton);
187  ShowFrame(fSaveCanvasButton);
188  ShowFrame(fPlotsListButton);
189  ShowFrame(fNewWindowButton);
190  ShowFrame(fExportCutsButton);
191  HideFrame(fGoToPlotsButton);
192  HideFrame(fQuitButton);
193  Resize(GetDefaultSize());
194 }
195 
197 {
198  HideFrame(fNameButton);
199  if (IsVisible(fNameEntryBox)) HandleNameEntryBox();
200  HideFrame(fSetupWindowButton);
201  HideFrame(fSaveCanvasButton);
202  HideFrame(fPlotsListButton);
203  HideFrame(fNewWindowButton);
204  HideFrame(fExportCutsButton);
205  ShowFrame(fGoToPlotsButton);
206  ShowFrame(fQuitButton);
207  Resize(GetDefaultSize());
208 }
ClassImp(QObject)
Part of a canvas window containing control buttons.
virtual ~QGCanvasWindowButtonsFrame()
Destructor.
TGPictureButton * fNewWindowButton
New window button.
QGCanvasWindowButtonsFrame(QGCanvasWindow *p=0, UInt_t w=70, UInt_t h=70)
Constructor.
void HandleQuitButton()
Handle quit button.
TGPictureButton * fGoToPlotsButton
Back to plots button.
TGPictureButton * fPlotsListButton
Plots list button.
TGPictureButton * fSaveCanvasButton
Save canvas button.
void HandleSaveCanvasButton()
Handle save canvas button.
void ShowSetupWindowDisplay()
Show setup window display, hide everything except back-to-plots button.
void HandleNameButton()
Handle name button click.
TGPictureButton * fNameButton
Name button.
TGPictureButton * fExportCutsButton
Export cuts button.
TGTextEntry * fNameEntryBox
Name entry box.
void HandleExportCutsButton()
Handle export cuts button.
TGPictureButton * fQuitButton
Quit button.
TGPictureButton * fSetupWindowButton
Setup window button.
void HandleSetupWindowButton()
Handle setup window button.
void ShowDefaultDisplay()
Show default display, hide certain elements.
void HandleNameEntryBox()
Handle name entry box.
void HandleGoToPlotsButton()
Handle go-to-plots button.
QGCanvasWindow * fCanvasWindow
Parent canvas window.
void HandleNewWindowButton()
Handle new window button.
void HandlePlotsListButton()
Handle plots list button.
Window containing a ROOT canvas.
void DisplayPlotFrame()
Display the plot frame.
QGPlotFrame * GetPlotFrame()
Get pointer to the plot frame.
void DisplaySetupFrame()
Display the setup frame.
Window used to manage writing cuts to a file.
const std::string & GetSaveCanvasDirectory()
Get save canvas directory.
void SetSaveCanvasDirectory(const std::string &directory)
Set save canvas directory.
static QGDefaultsHandler * Instance()
Singleton.
TRootEmbeddedCanvas * GetEmbeddedCanvas()
Get pointer to canvas.
Definition: QGPlotFrame.hh:26
static void ShowPlotsList()
Show plots list.
Definition: QGPlot.cc:286
static void UpdateWindowDropDownBoxes()
Update window drop down boxes.
Definition: QGWindow.cc:95
virtual void SetWindowName(const char *name=0)
Set name of window.
Definition: QGWindow.cc:52
std::string Resize(const std::string &s, size_t len)
resize a string to len, adding spaces if necessary