36 #include <QCloseEvent> 39 #include <QMainWindow> 43 #include "gcontainer.h" 44 #include "gdrawingsurface.h" 45 #include "geventqueue.h" 46 #include "ginteractor.h" 51 class _Internal_QMainWindow;
163 GWindow(
double width,
double height,
bool visible =
true);
168 GWindow(
double x,
double y,
double width,
double height,
bool visible =
true);
216 virtual void add(
GObject* obj,
double x,
double y);
229 virtual void add(
GObject& obj,
double x,
double y);
235 virtual QMenu*
addMenu(
const string& text);
245 virtual QAction*
addMenuItem(
const string& menu,
const string& item,
246 const string& icon =
"");
256 virtual QAction*
addMenuItem(
const string& menu,
const string& item,
267 virtual QAction*
addMenuItem(
const string& menu,
const string& item,
278 virtual QAction*
addMenuItem(
const string& menu,
const string& item,
290 bool checked =
false,
291 const string& icon =
"");
318 virtual QMenu*
addSubMenu(
const string& menu,
const string& submenu);
345 virtual void addToolbar(
const string& title =
"");
354 const string& icon =
"");
395 void clear()
override;
450 const string& darkColor);
464 virtual void close();
475 virtual void compareToImage(
const string& filename,
bool ignoreWindowSize =
true)
const;
482 bool eventsEnabled()
const override;
568 static QMainWindow* getLastWindow();
659 string
getType()
const override;
666 virtual QWidget* getWidget()
const;
678 virtual double getX()
const;
684 virtual double getY()
const;
705 virtual bool inBounds(
double x,
double y)
const;
749 virtual bool isOpen()
const;
796 virtual void pause(
double ms);
804 virtual void rememberPosition();
826 virtual void remove(
GObject* obj);
832 virtual void remove(
GObject& obj);
1015 virtual void setMenuItemEnabled(
const string& menu,
const string& item,
bool enabled);
1073 virtual void setRegionAlignment(
const string& region,
const string& halign,
const string& valign);
1112 virtual void setSize(
double width,
double height);
1143 virtual void setTitle(
const string& title);
1155 virtual void setWidth(
double width);
1185 virtual void setX(
double x);
1190 virtual void setY(
double y);
1196 virtual void show();
1203 virtual void sleep(
double ms);
1221 virtual void processKeyPressEventInternal(QKeyEvent* event);
1226 static _Internal_QMainWindow* _lastWindow;
1228 void ensureForwardTarget()
override;
1229 void _init(
double width,
double height,
bool visible);
1230 static Region stringToRegion(
const string& regionStr);
1232 _Internal_QMainWindow* _iqmainwindow;
1237 std::map<string, QMenu*> _menuMap;
1238 std::map<string, QAction*> _menuActionMap;
1242 friend class _Internal_QMainWindow;
1289 void pause(
double milliseconds);
1302 class _Internal_QMainWindow :
public QMainWindow {
1306 _Internal_QMainWindow(
GWindow* gwindow, QWidget* parent =
nullptr);
1308 void changeEvent(QEvent* event)
override;
1309 void closeEvent(QCloseEvent* event)
override;
1310 void keyPressEvent(QKeyEvent* event)
override;
1311 void resizeEvent(QResizeEvent* event)
override;
1312 void timerEvent(QTimerEvent* event)
override;
1313 virtual bool timerExists(
int id = -1);
1314 virtual int timerStart(
double ms);
1315 virtual void timerStop(
int id = -1);
1318 void handleMenuAction(
const string& menu,
const string& item);
1322 std::set<int> _timerIDs;
1324 void processTimerEvent();
1331 #endif // _gwindow_h A GContainer is a logical grouping for interactors.
Definition: gcontainer.h:73
virtual void setLocation(double x, double y)
Sets the window's top-left x/y location on the screen to the given coordinates.
Definition: gwindow.cpp:1084
Definition: gwindow.h:122
virtual bool isMinimized() const
Returns true if the window is in a minimized (iconified) state, which often displays as the window be...
Definition: gwindow.cpp:861
This class represents a graphics window that supports simple graphics.
Definition: gwindow.h:102
virtual void maximize()
Puts the window in a maximized state, occupying the entire screen.
Definition: gwindow.cpp:886
string getType() const override
Returns the concrete type of the object as a string, such as "GButton" or "GWindow".
Definition: gwindow.cpp:793
virtual double getRegionHeight(Region region) const
Returns the height of the given region of the window in pixels.
Definition: gwindow.cpp:736
virtual void setCloseOperation(CloseOperation op)
Sets what should happen when the window is closed.
Definition: gwindow.cpp:1065
virtual void show()
Sets the window to be visible on the screen.
Definition: gwindow.cpp:1290
GWindow(bool visible=true)
Creates a new window of a default width and height.
Definition: gwindow.cpp:78
virtual bool isOpen() const
Returns true if the window is currently open and visible on the screen.
Definition: gwindow.cpp:865
Region
The five regions of window border layouts.
Definition: gwindow.h:107
virtual void setWindowListener(GEventListener func)
Sets a window listener on this window so that it will be called when window events occur...
Definition: gwindow.cpp:1258
Definition: gwindow.h:120
void exitGraphics()
Closes all graphics windows and exits from the application without waiting for any additional user in...
Definition: gwindow.cpp:1338
virtual CloseOperation getCloseOperation() const
Returns a constant representing the action that will be taken when the user closes the window...
Definition: gwindow.cpp:662
static double getScreenHeight()
Returns the height of the entire screen in pixels.
Definition: gwindow.cpp:769
HorizontalAlignment
The supported kinds of horizontal alignment of a widget or onscreen object.
Definition: gtypes.h:136
virtual void setResizable(bool resizable)
Sets whether the window allows itself to be resized.
Definition: gwindow.cpp:1178
Definition: gwindow.h:112
Definition: gcontainer.h:103
virtual QAction * addToolbarItem(string item, string icon="")
Adds a new item to the window's toolbar.
Definition: gwindow.cpp:415
virtual int getGObjectCount() const
Returns the total number of graphical objects in the window's canvas.
Definition: gwindow.cpp:712
Definition: gcontainer.h:104
virtual QAction * addMenuSeparator(string menu)
Adds a horizontal line separator to the end of the given menu.
Definition: gwindow.cpp:343
Definition: gwindow.h:110
virtual void saveCanvasPixels(string filename)
Writes the contents of the window's graphical canvas to the given output filename.
Definition: gwindow.cpp:1023
virtual bool isVisible() const
Returns true if the window is visible on the screen.
Definition: gwindow.cpp:877
double getScreenHeight()
Returns the height of the entire display screen.
Definition: gwindow.cpp:1342
virtual void clearCanvasObjects()
Removes all graphical objects from the graphical canvas in this window.
Definition: gwindow.cpp:554
virtual GDimension getRegionSize(Region region) const
Returns the width and height of the given region of the window in pixels.
Definition: gwindow.cpp:744
static bool isHighDpiScalingEnabled()
Returns whether we should scale some windows when run on high-density screens.
Definition: gwindow.cpp:848
virtual void close()
Closes the window.
Definition: gwindow.cpp:599
Definition: gwindow.h:109
virtual void setWidth(double width)
Sets the window's total width in pixels.
Definition: gwindow.cpp:1245
virtual string getTitle() const
Returns the title bar text for the window.
Definition: gwindow.cpp:789
virtual void setMouseListener(GEventListener func)
Sets a mouse listener on the window's canvas so that it will be called when the user moves or clicks ...
Definition: gwindow.cpp:1134
virtual void addToRegion(GInteractor *interactor, Region region)
Adds the given interactor to the given region in this window.
Definition: gwindow.cpp:376
static bool isHighDensityScreen()
Returns whether the dots-per-inch of the screen are high enough to consider it a "high-density" scree...
Definition: gwindow.cpp:844
virtual void setCanvasHeight(double height)
Resizes the window so that its central canvas region will occupy exactly the given height in pixels...
Definition: gwindow.cpp:1043
virtual void setSize(double width, double height)
Sets the window's total width and height in pixels.
Definition: gwindow.cpp:1200
virtual void removeMenuListener()
Removes the menu listener from this window so that it will no longer call it when events occur...
Definition: gwindow.cpp:976
virtual void loadCanvasPixels(string filename)
Reads pixel data from the file with the given name and loads it into the window's canvas area...
Definition: gwindow.cpp:881
virtual double getHeight() const
Returns the total height of the window in pixels, excluding its title bar and borders.
Definition: gwindow.cpp:724
virtual GDimension getSize() const
Returns the total width and height of the window in pixels, excluding its title bar and borders...
Definition: gwindow.cpp:785
virtual void setClickListener(GEventListener func)
Sets a mouse listener on this window so that it will be called when the mouse is clicked on the windo...
Definition: gwindow.cpp:1110
Definition: gcontainer.h:101
~GWindow() override
Frees memory allocated internally by the window.
Definition: gwindow.cpp:133
virtual void removeFromRegion(GInteractor *interactor, Region region)
Removes the given interactor from the given region within this window.
Definition: gwindow.cpp:943
virtual void clearRegion(Region region)
Removes all interactors from the given region of this window.
Definition: gwindow.cpp:566
virtual GObject * getGObjectAt(double x, double y) const
Returns the top-most graphical object in the z-ordering in the window's graphical canvas that touches...
Definition: gwindow.cpp:704
void pause(double milliseconds)
Pauses for the indicated number of milliseconds.
Definition: gwindow.cpp:1355
void repaint()
Issues a request to update the most recently created graphics window.
Definition: gwindow.cpp:1360
This class is the common superclass of all graphical objects that can be displayed on a graphical win...
Definition: gobjects.h:66
std::function< void(GEvent)> GEventListener
Types for the event listener functions to be passed to various interactors.
Definition: gevent.h:38
virtual void setWindowIcon(string iconFile)
Sets the window to use the.
Definition: gwindow.cpp:1249
virtual bool isResizable() const
Returns true if the window allows itself to be resized.
Definition: gwindow.cpp:873
This abstract class is the superclass for all graphical interactors.
Definition: ginteractor.h:52
virtual void addToolbar(string title="")
Adds a toolbar to this window where action buttons can be placed.
Definition: gwindow.cpp:403
Definition: gcontainer.h:105
virtual double getY() const
Returns the y location of the top edge of the interior of the window on screen, excluding any onscree...
Definition: gwindow.cpp:809
virtual void setCanvasSize(double width, double height)
Resizes the window so that its central canvas region will occupy exactly the given width and height i...
Definition: gwindow.cpp:1048
static string getDefaultInteractorBackgroundColor()
Returns the default color for backgrounds of interactors as a string.
Definition: gwindow.cpp:666
virtual void add(GInteractor *interactor)
Adds the given interactor to the center region of the window.
Definition: gwindow.cpp:144
static const int HIGH_DPI_SCREEN_THRESHOLD
The minimum number of dots per inch before a screen is considered to be high-density or high-DPI...
Definition: gwindow.h:141
A GCanvas is a graphical drawing surface on which you can draw shapes, lines, and colors...
Definition: gcanvas.h:75
virtual void setHeight(double width)
Sets the window's total height in pixels.
Definition: gwindow.cpp:1080
virtual QAction * addMenuItem(string menu, string item, string icon="")
Adds a new menu item to the given menu.
Definition: gwindow.cpp:202
virtual void requestFocus()
Asks the system to assign the keyboard focus to the window, which brings it to the top and ensures th...
Definition: gwindow.cpp:1010
virtual QMenu * addMenu(string text)
Adds a menu with the given text to the window's top menu bar.
Definition: gwindow.cpp:186
Definition: gwindow.h:119
virtual GCanvas * getCanvas() const
Returns a direct pointer to the window's internal graphical canvas on which shapes and objects are dr...
Definition: gwindow.cpp:642
static int getScreenDpi()
Returns the dots-per-inch of the screen.
Definition: gwindow.cpp:760
static int chooseLightDarkModeColorInt(int lightColor, int darkColor)
Returns which color to use depending on whether the user's computer is in light or dark mode...
Definition: gwindow.cpp:595
virtual void clearCanvasPixels()
Resets the background layer of pixels in the window's canvas to the window's background color...
Definition: gwindow.cpp:560
virtual void removeKeyListener()
Removes the key listener from this window so that it will no longer call it when events occur...
Definition: gwindow.cpp:970
virtual void setMenuListener(GEventListener func)
Sets a menu listener on this window so that it will be called when menu items are clicked...
Definition: gwindow.cpp:1126
static int getDefaultInteractorTextColorInt()
Returns the default color for text on interactors as an RGB integer.
Definition: gwindow.cpp:685
static bool isDarkMode()
Returns true if the user's computer is in "dark mode." This is a popular dark color scheme mostly use...
Definition: gwindow.cpp:829
bool isRepaintImmediately() const override
Returns true if the interactor should repaint itself automatically whenever any change is made to its...
Definition: gwindow.cpp:869
static string chooseLightDarkModeColor(string lightColor, string darkColor)
Returns which color to use depending on whether the user's computer is in light or dark mode...
Definition: gwindow.cpp:590
Definition: gwindow.h:108
virtual void setVisible(bool visible)
Sets whether the window can be seen on the screen.
Definition: gwindow.cpp:1239
virtual void setRegionHorizontalAlignment(Region region, HorizontalAlignment halign)
Sets the horizontal alignment of interactors in the given region of the window.
Definition: gwindow.cpp:1162
std::function< void()> GEventListenerVoid
Types for the event listener functions to be passed to various interactors.
Definition: gevent.h:44
virtual void removeToolbar()
Removes the toolbar from this window, if one was present.
Definition: gwindow.cpp:990
virtual void removeTimerListener()
Removes the timer listener from this window so that it will no longer call it when events occur...
Definition: gwindow.cpp:986
virtual void setMenuItemEnabled(string menu, string item, bool enabled)
Sets whether the given item in the given menu is enabled or disabled.
Definition: gwindow.cpp:1094
int convertColorToRGB(string colorName)
Converts a color name into an integer that encodes the red, green, and blue components of the color...
Definition: gwindow.cpp:1330
static double getScreenWidth()
Returns the width of the entire screen in pixels.
Definition: gwindow.cpp:781
virtual void minimize()
Puts the window in a minimized (iconified) state, which often displays as the window being hidden exc...
Definition: gwindow.cpp:892
static const string DEFAULT_ICON_FILENAME
The default file name used to load a GWindow's initial title bar icon.
Definition: gwindow.h:153
static int getDefaultInteractorBackgroundColorInt()
Returns the default color for text on interactors as an RGB integer.
Definition: gwindow.cpp:670
virtual void setRegionVerticalAlignment(string region, string valign)
Sets the vertical alignment of interactors in the given region of the window.
Definition: gwindow.cpp:1174
A GObservable object is one that is able to send out events.
Definition: gobservable.h:40
static const int DEFAULT_HEIGHT
The default height of a newly created window in pixels if its height is not explicitly specified...
Definition: gwindow.h:135
static double getScreenDpiScaleRatio()
Returns the ratio of this screen's DPI compared to a normal low-DPI screen.
Definition: gwindow.cpp:764
static const int STANDARD_SCREEN_DPI
The minimum number of dots per inch on a "normal" low-DPI screen.
Definition: gwindow.h:147
virtual GDimension getPreferredSize() const
Returns the size that the window would prefer to be.
Definition: gwindow.cpp:732
virtual GPoint getLocation() const
Returns the x/y location of the top-left corner of the interior of the window on screen, excluding any onscreen window title bar and frame.
Definition: gwindow.cpp:728
virtual void hide()
Makes the window be not visible on the screen.
Definition: gwindow.cpp:817
GDimension getScreenSize()
Returns the width/height of the entire display screen.
Definition: gwindow.cpp:1346
static string getDefaultInteractorTextColor()
Returns the default color for text on interactors as a string.
Definition: gwindow.cpp:681
This struct contains real-valued width and height fields.
Definition: gtypes.h:43
virtual GDimension getCanvasSize() const
Returns the width and height of the window's central canvas area in pixels.
Definition: gwindow.cpp:652
virtual void setWindowTitle(string title)
Sets the window's title bar text to the given string.
Definition: gwindow.cpp:1278
virtual double getX() const
Returns the x location of the left edge of the interior of the window on screen, excluding any onscre...
Definition: gwindow.cpp:805
virtual QAction * addToolbarSeparator()
Adds a separator to the window's toolbar.
Definition: gwindow.cpp:518
static GDimension getScreenSize()
Returns the width and height of the entire screen in pixels.
Definition: gwindow.cpp:773
Definition: gwindow.h:121
virtual void clearToolbarItems()
Removes all items from the window's toolbar, if present.
Definition: gwindow.cpp:574
void setBackground(int color) override
Sets the current background color of the interactor as an RGB integer.
Definition: gwindow.cpp:1028
virtual void setTimerListener(double ms, GEventListener func)
Sets a menu listener on this window so that it will be called when timer delays elapse, sending a timer event.
Definition: gwindow.cpp:1217
virtual void clearCanvas()
Removes all graphical objects from the graphical canvas in this window and resets the background laye...
Definition: gwindow.cpp:548
virtual void restore()
Puts the window in a normal state, neither minimized or maximized.
Definition: gwindow.cpp:1017
virtual double getRegionWidth(Region region) const
Returns the width of the given region of the window in pixels.
Definition: gwindow.cpp:752
virtual void removeWindowListener()
Removes the window listener from this window so that it will no longer call it when events occur...
Definition: gwindow.cpp:1000
Definition: gwindow.h:111
virtual void setY(double y)
Sets the window's top y location on the screen to the given coordinate.
Definition: gwindow.cpp:1286
virtual QAction * addMenuItemCheckBox(string menu, string item, bool checked=false, string icon="")
Adds a new checkbox menu item to the given menu.
Definition: gwindow.cpp:299
virtual void setExitOnClose(bool exitOnClose)
Sets whether the library's GUI system should shut down when the window is closed. ...
Definition: gwindow.cpp:1072
virtual bool hasToolbar() const
Returns true if this window has a toolbar.
Definition: gwindow.cpp:813
virtual void setCanvasWidth(double width)
Resizes the window so that its central canvas region will occupy exactly the given width in pixels...
Definition: gwindow.cpp:1060
virtual void setX(double x)
Sets the window's left x location on the screen to the given coordinate.
Definition: gwindow.cpp:1282
virtual void sleep(double ms)
Causes the current thread to pause itself for the given number of milliseconds.
Definition: gwindow.cpp:1294
virtual double getCanvasHeight() const
Returns the height of the window's central canvas area in pixels.
Definition: gwindow.cpp:647
Definition: gcontainer.h:102
This struct contains real-valued x and y fields.
Definition: gtypes.h:202
virtual bool inBounds(double x, double y) const
Returns true if the given x/y location is within the bounds of the entire window. ...
Definition: gwindow.cpp:821
virtual void toBack()
Moves the window to the back of the z-ordering in the operating system, underneath any other windows ...
Definition: gwindow.cpp:1314
virtual bool isMaximized() const
Returns true if the window is in a maximized state, occupying the entire screen.
Definition: gwindow.cpp:856
virtual bool inCanvasBounds(double x, double y) const
Returns true if the given x/y location is within the bounds of the central canvas area of the window...
Definition: gwindow.cpp:825
virtual void pack()
Resizes the window to its preferred size.
Definition: gwindow.cpp:898
virtual void setKeyListener(GEventListener func)
Sets a key listener on this window so that it will be called when the user presses any key...
Definition: gwindow.cpp:1118
virtual double getCanvasWidth() const
Returns the width of the window's central canvas area in pixels.
Definition: gwindow.cpp:657
virtual GObject * getGObject(int index) const
Returns the graphical object at the given 0-based index in the window's graphical canvas...
Definition: gwindow.cpp:696
virtual void removeClickListener()
Removes the click listener from this window so that it will no longer call it when events occur...
Definition: gwindow.cpp:937
CloseOperation
The various actions that can occur when a window closes.
Definition: gwindow.h:118
virtual void setRegionAlignment(Region region, HorizontalAlignment halign)
Sets the horizontal alignment of interactors in the given region of the window.
Definition: gwindow.cpp:1142
virtual void center()
Relocates the window to the exact center of the current screen.
Definition: gwindow.cpp:583
virtual void setTitle(string title)
Sets the window's title bar text to the given string.
Definition: gwindow.cpp:1233
void clear() override
Removes all interactors from all regionss of the window.
Definition: gwindow.cpp:530
virtual double getWidth() const
Returns the total width of the window in pixels, excluding its title bar and borders.
Definition: gwindow.cpp:801
double getScreenWidth()
Returns the width of the entire display screen.
Definition: gwindow.cpp:1350
virtual void toFront()
Moves the window to the front of the z-ordering in the operating system, in front of any other window...
Definition: gwindow.cpp:1320
string convertRGBToColor(int rgb)
Converts an rgb value into a color name in the form "#rrggbb".
Definition: gwindow.cpp:1334
virtual void removeMouseListener()
Removes the mouse listener from this window so that it will no longer call it when events occur...
Definition: gwindow.cpp:980
virtual void pause(double ms)
Causes the current thread to pause itself for the given number of milliseconds.
Definition: gwindow.cpp:902
VerticalAlignment
The supported kinds of vertical alignment of a widget or onscreen object.
Definition: gtypes.h:147
virtual QMenu * addSubMenu(string menu, string submenu)
Adds a sub-menu within an existing menu.
Definition: gwindow.cpp:358
static const int DEFAULT_WIDTH
The default width of a newly created window in pixels if its width is not explicitly specified...
Definition: gwindow.h:129