StanfordCPPLib
goptionpane.h
1 /*
2  * File: goptionpane.h
3  * -------------------
4  *
5  * @author Marty Stepp
6  * @version 2018/09/23
7  * - renamed enum constants to avoid name collisions (may break some client code)
8  * @version 2018/09/08
9  * - added doc comments for new documentation generation
10  * @version 2018/08/23
11  * - renamed to goptionpane.h to replace Java version
12  * @version 2018/06/28
13  * - initial version
14  */
15 
16 #include "private/init.h" // ensure that Stanford C++ lib is initialized
17 
18 #ifndef INTERNAL_INCLUDE
19 // signal that GUI system is in use (so it will be initialized)
20 #define SPL_QT_GUI_IN_USE 1
21 #include "private/initstudent.h" // insert necessary included code by student
22 #endif // INTERNAL_INCLUDE
23 
24 #ifndef _goptionpane_h
25 #define _goptionpane_h
26 
27 #include <string>
28 
29 #define INTERNAL_INCLUDE 1
30 #include "ginteractor.h"
31 #define INTERNAL_INCLUDE 1
32 #include "vector.h"
33 #undef INTERNAL_INCLUDE
34 
35 // forward declaration
36 class GWindow;
37 class GOptionPane;
38 
43 class GOptionPane {
44 public:
49  enum ConfirmType {
53  };
54 
61  CONFIRM_CANCEL = -1, // for yes/no/cancel dialogs
62  CONFIRM_NO = 0, // 0 so that 'no' is 'falsey'
63  CONFIRM_YES = 1, // 1 so that 'yes' is 'truthy'
64  CONFIRM_OK = 2 // for ok/cancel dialogs
65  };
66 
72  enum MessageType {
79  };
80 
87  static ConfirmResult showConfirmDialog(const string& message,
88  const string& title = "",
90 
98  const string& message,
99  const string& title = "",
100  ConfirmType type = CONFIRM_YES_NO);
101 
108  static ConfirmResult showConfirmDialog(QWidget* parent,
109  const string& message,
110  const string& title = "",
111  ConfirmType type = CONFIRM_YES_NO);
112 
119  static string showInputDialog(const string& message,
120  const string& title = "",
121  const string& initialValue = "");
122 
129  static string showInputDialog(GWindow* parent,
130  const string& message,
131  const string& title = "",
132  const string& initialValue = "");
133 
140  static string showInputDialog(QWidget* parent,
141  const string& message,
142  const string& title = "",
143  const string& initialValue = "");
144 
153  static void showMessageDialog(const string& message,
154  const string& title = "",
155  MessageType type = MESSAGE_PLAIN);
156 
165  static void showMessageDialog(GWindow* parent,
166  const string& message,
167  const string& title = "",
168  MessageType type = MESSAGE_PLAIN);
169 
178  static void showMessageDialog(QWidget* parent,
179  const string& message,
180  const string& title = "",
181  MessageType type = MESSAGE_PLAIN);
182 
190  static string showOptionDialog(const string& message,
191  const Vector<string>& options,
192  const string& title = "",
193  const string& initiallySelected = "");
194 
202  static string showOptionDialog(GWindow* parent,
203  const string& message,
204  const Vector<string>& options,
205  const string& title = "",
206  const string& initiallySelected = "");
207 
215  static string showOptionDialog(QWidget* parent,
216  const string& message,
217  const Vector<string>& options,
218  const string& title = "",
219  const string& initiallySelected = "");
220 
225  static void showTextFileDialog(const string& fileText,
226  const string& title = "",
227  int rows = -1, int cols = -1);
228 
233  static void showTextFileDialog(GWindow* parent,
234  const string& fileText,
235  const string& title = "",
236  int rows = -1, int cols = -1);
237 
242  static void showTextFileDialog(QWidget* parent,
243  const string& fileText,
244  const string& title = "",
245  int rows = -1, int cols = -1);
246 
247 private:
253  GOptionPane();
254 
259  enum InternalResult {
260  INTERNAL_CANCEL_OPTION = 2,
261  INTERNAL_CLOSED_OPTION = -1,
262  INTERNAL_NO_OPTION = 1,
263  INTERNAL_OK_OPTION = 0,
264  INTERNAL_YES_OPTION = 0
265  };
266 };
267 
268 #endif // _goptionpane_h
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:64
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:61
Definition: goptionpane.h:50
Definition: goptionpane.h:74
Definition: goptionpane.h:77
static void showMessageDialog(string message, string title="", MessageType type=MESSAGE_PLAIN)
Displays an output message dialog to the user.
Definition: goptionpane.cpp:135
Definition: goptionpane.h:73
static string showOptionDialog(string message, const 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
ConfirmResult
The various results that can be returned from some option dialogs.
Definition: goptionpane.h:60
ConfirmType
Types used by showConfirmDialog, representing the three kinds of confirmation dialogs: Yes/No...
Definition: goptionpane.h:49
This class provides static methods that pop up graphical input/output dialog boxes on the screen...
Definition: goptionpane.h:43
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
Definition: goptionpane.h:78
This class represents a graphics window that supports simple graphics.
Definition: gwindow.h:114
Definition: goptionpane.h:75
MessageType
Types used by showMessageDialog, representing the various kinds of message dialogs.
Definition: goptionpane.h:72
Definition: goptionpane.h:52
Definition: goptionpane.h:76
Definition: goptionpane.h:51
Definition: goptionpane.h:63
Definition: goptionpane.h:62