SGL
goptionpane.h
1 /*
2  * File: goptionpane.h
3  * -------------------
4  *
5  * @author Marty Stepp
6  * @version 2021/04/09
7  * - added sgl namespace
8  * @version 2021/04/03
9  * - removed dependency on custom collections
10  * @version 2018/09/23
11  * - renamed enum constants to avoid name collisions (may break some client code)
12  * @version 2018/09/08
13  * - added doc comments for new documentation generation
14  * @version 2018/08/23
15  * - renamed to goptionpane.h to replace Java version
16  * @version 2018/06/28
17  * - initial version
18  */
19 
20 
21 #ifndef _goptionpane_h
22 #define _goptionpane_h
23 
24 #include <string>
25 #include <vector>
26 
27 #include "ginteractor.h"
28 
29 namespace sgl {
30 
31 // forward declaration
32 class GWindow;
33 
38 class GOptionPane {
39 public:
44  enum ConfirmType {
48  };
49 
56  CONFIRM_CANCEL = -1, // for yes/no/cancel dialogs
57  CONFIRM_NO = 0, // 0 so that 'no' is 'falsey'
58  CONFIRM_YES = 1, // 1 so that 'yes' is 'truthy'
59  CONFIRM_OK = 2 // for ok/cancel dialogs
60  };
61 
67  enum MessageType {
74  };
75 
82  static ConfirmResult showConfirmDialog(const string& message,
83  const string& title = "",
85 
93  const string& message,
94  const string& title = "",
96 
103  static ConfirmResult showConfirmDialog(QWidget* parent,
104  const string& message,
105  const string& title = "",
106  ConfirmType type = CONFIRM_YES_NO);
107 
114  static string showInputDialog(const string& message,
115  const string& title = "",
116  const string& initialValue = "");
117 
124  static string showInputDialog(GWindow* parent,
125  const string& message,
126  const string& title = "",
127  const string& initialValue = "");
128 
135  static string showInputDialog(QWidget* parent,
136  const string& message,
137  const string& title = "",
138  const string& initialValue = "");
139 
148  static void showMessageDialog(const string& message,
149  const string& title = "",
150  MessageType type = MESSAGE_PLAIN);
151 
160  static void showMessageDialog(GWindow* parent,
161  const string& message,
162  const string& title = "",
163  MessageType type = MESSAGE_PLAIN);
164 
173  static void showMessageDialog(QWidget* parent,
174  const string& message,
175  const string& title = "",
176  MessageType type = MESSAGE_PLAIN);
177 
185  static string showOptionDialog(const string& message,
186  const std::vector<string>& options,
187  const string& title = "",
188  const string& initiallySelected = "");
189 
197  static string showOptionDialog(GWindow* parent,
198  const string& message,
199  const std::vector<string>& options,
200  const string& title = "",
201  const string& initiallySelected = "");
202 
210  static string showOptionDialog(QWidget* parent,
211  const string& message,
212  const std::vector<string>& options,
213  const string& title = "",
214  const string& initiallySelected = "");
215 
220  static void showTextFileDialog(const string& fileText,
221  const string& title = "",
222  int rows = -1, int cols = -1);
223 
228  static void showTextFileDialog(GWindow* parent,
229  const string& fileText,
230  const string& title = "",
231  int rows = -1, int cols = -1);
232 
237  static void showTextFileDialog(QWidget* parent,
238  const string& fileText,
239  const string& title = "",
240  int rows = -1, int cols = -1);
241 
242 private:
248  GOptionPane();
249 
254  enum InternalResult {
255  INTERNAL_CANCEL_OPTION = 2,
256  INTERNAL_CLOSED_OPTION = -1,
257  INTERNAL_NO_OPTION = 1,
258  INTERNAL_OK_OPTION = 0,
259  INTERNAL_YES_OPTION = 0
260  };
261 };
262 
263 } // namespace sgl
264 
265 #endif // _goptionpane_h
This class represents a graphics window that supports simple graphics.
Definition: gwindow.h:102
ConfirmType
Types used by showConfirmDialog, representing the three kinds of confirmation dialogs: Yes/No...
Definition: goptionpane.h:44
MessageType
Types used by showMessageDialog, representing the various kinds of message dialogs.
Definition: goptionpane.h:67
Definition: goptionpane.h:70
Definition: goptionpane.h:56
Definition: goptionpane.h:71
This class provides static methods that pop up graphical input/output dialog boxes on the screen...
Definition: goptionpane.h:38
Definition: goptionpane.h:58
static void showMessageDialog(string message, string title="", MessageType type=MESSAGE_PLAIN)
Displays an output message dialog to the user.
Definition: goptionpane.cpp:135
Definition: console.h:45
static ConfirmResult showConfirmDialog(string message, string title="", ConfirmType type=CONFIRM_YES_NO)
Pops up a yes/no confirmation box.
Definition: goptionpane.cpp:47
Definition: goptionpane.h:45
Definition: goptionpane.h:59
Definition: goptionpane.h:69
Definition: goptionpane.h:72
ConfirmResult
The various results that can be returned from some option dialogs.
Definition: goptionpane.h:55
Definition: goptionpane.h:46
static string showInputDialog(string message, string title="", string initialValue="")
Pops up an input box with a text field where the user can type a response, which is returned...
Definition: goptionpane.cpp:106
Definition: goptionpane.h:73
Definition: goptionpane.h:47
Definition: goptionpane.h:68
static string showOptionDialog(string message, const std::vector< string > &options, string title="", string initiallySelected="")
Shows a general input box with a set of buttons from which the user may choose one option...
Definition: goptionpane.cpp:177
Definition: goptionpane.h:57
static void showTextFileDialog(string fileText, string title="", int rows=-1, int cols=-1)
Displays the given text in a scrolling monospaced text area.
Definition: goptionpane.cpp:272