StanfordCPPLib
Public Types | Public Member Functions | Protected Member Functions | List of all members
GTextField Class Reference

This interactor subclass represents a text field for entering short text strings. More...

#include "gtextfield.h"

Inheritance diagram for GTextField:
GInteractor GObservable

Public Types

enum  InputType { INPUT_TYPE_TEXT, INPUT_TYPE_INTEGER, INPUT_TYPE_REAL }
 Constants for the valid types of text field input. More...
 
enum  TextPosition { TEXT_BESIDE_ICON, TEXT_UNDER_ICON, TEXT_ONLY }
 The places where an interactor can place its text relative to its icon. More...
 

Public Member Functions

 GTextField(string text="", int charsWide=0, QWidget* parent=nullptr)
 Creates a text field with the given initial text. More...
 
 GTextField(int charsWide, QWidget* parent=nullptr)
 Creates a text field wide enough to display the given number of characters. More...
 
 GTextField(int value, int min, int max, int step=1, QWidget* parent=nullptr)
 Creates a text field for entering integer values, with the given initial value. More...
 
 GTextField(double value, double min, double max, double step, QWidget* parent=nullptr)
 Creates a text field for entering real number values, with the given initial value. More...
 
~GTextField()
 Frees memory allocated internally by the text field. More...
 
void addActionListener() (deprecated)
 Adds an event listener to be notified when this interactor is clicked or generally interacted with. More...
 
bool eventsEnabled() const
 Returns true if this interactor is currently accepting events. More...
 
string getAccelerator() const
 Returns a string representing a hotkey for this interactor, or an empty string if no accelerator has been set. More...
 
string getActionCommand() const
 Returns an action command for this interactor, which is a semi-unique string you can use to identify it when events occur. More...
 
string getBackground() const
 Returns the background color of the interactor as a string. More...
 
int getBackgroundInt() const
 Returns the background color of the interactor as an RGB integer. More...
 
GRectangle getBounds() const
 Returns a rectangle representing the x/y position and size of this interactor. More...
 
int getCharsWide() const
 Returns the number of characters that can fit in the visible area of this text field. More...
 
string getColor() const
 Returns the foreground/text color of the interactor as a string. More...
 
int getColorInt() const
 Returns the foreground/text color of the interactor as an RGB integer. More...
 
GContainergetContainer() const
 Returns a pointer to the onscreen container holding this interactor. More...
 
string getFont() const
 Returns the font of this interactor's text as a font string such as "Helvetica-12-Bold". More...
 
string getForeground() const
 Returns the foreground/text color of the interactor as a string. More...
 
int getForegroundInt() const
 Returns the foreground/text color of the interactor as an RGB integer. More...
 
double getHeight() const
 Returns the current onscreen height of this interactor in pixels. More...
 
string getIcon() const
 Returns the file name of the icon associated with this interactor, or an empty string if no icon has been set. More...
 
int getID() const
 Returns a globally unique identifier for this interactor, which is set when the interactor is constructed. More...
 
InputType getInputType() const
 Returns the type of input accepted by this text field. More...
 
_Internal_QWidget*  getInternalWidget() const
 Returns a direct pointer to the internal Qt widget being wrapped by this interactor. More...
 
GPoint getLocation() const
 Returns an (x, y) point representing the onscreen location of the top-left corner of this interactor within its containing window. More...
 
int getMaxLength() const
 Returns the maximum length of string allowed in the text field. More...
 
double getMinimumHeight() const
 Returns the minimum height in pixels that this interactor will permit itself to be resized to. More...
 
GDimension getMinimumSize() const
 Returns a GDimension structure representing the minimum size in pixels that this interactor will permit itself to be resized to. More...
 
double getMinimumWidth() const
 Returns the minimum width in pixels that this interactor will permit itself to be resized to. More...
 
string getName() const
 Returns a string representing a unique name for this interactor. More...
 
string getPlaceholder() const
 Returns the text field's placeholder text, which is usually displayed as a light gray text in the field when the field is empty. More...
 
double getPreferredHeight() const
 Returns the height in pixels that this interactor would prefer to be, which would exactly fit its contents with no stretching or scrollbars. More...
 
GDimension getPreferredSize() const
 Returns a GDimension structure storing the width and height in pixels that this interactor would prefer to be, which would exactly fit its contents with no stretching or scrollbars. More...
 
double getPreferredWidth() const
 Returns the height in pixels that this interactor would prefer to be, which would exactly fit its contents with no stretching or scrollbars. More...
 
GDimension getSize() const
 Returns a GDimension structure storing the current onscreen width and height of this interactor in pixels. More...
 
string getText() const
 Returns the text field's current text. More...
 
string getType() const
 Returns a string representing the class name of this interactor, such as "GButton" or "GCheckBox". More...
 
string getValue() const
 Returns the text field's current text. More...
 
bool getValueAsBool() const
 Returns the currently typed value in the text field, interpreted as a bool value of true or false. More...
 
char getValueAsChar() const
 Returns the currently typed value in the text field as a char value. More...
 
double getValueAsDouble() const
 Returns the currently typed value in the text field, interpreted as a real number value. More...
 
int getValueAsInt() const
 Returns the currently typed value in the text field, interpreted as an integer value. More...
 
int getValueAsInteger() const
 Returns the currently typed value in the text field, interpreted as an integer value. More...
 
QWidget*  getWidget() const
 Returns a direct pointer to the internal Qt widget being wrapped by this interactor. More...
 
double getWidth() const
 Returns the current onscreen width of this interactor in pixels. More...
 
double getX() const
 Returns the x-coordinate of the top-left pixel of this interactor within its onscreen window. More...
 
double getY() const
 Returns the y-coordinate of the top-left pixel of this interactor within its onscreen window. More...
 
bool inBounds(double x, double y) const
 Returns true if the given x/y pixel is within the bounds of this interactor. More...
 
bool inBounds(int x, int y) const
 Returns true if the given x/y pixel is within the bounds of this interactor. More...
 
bool isAutocompleteEnabled() const
 Returns true if this text field has an autocompletion list of options that will pop up as the user begins typing. More...
 
bool isEditable() const
 Returns true if the text field's value can be edited. More...
 
bool isEnabled() const
 Returns true if this interactor is currently enabled. More...
 
bool isVisible() const
 Returns true if the interactor is visible on the screen. More...
 
void removeActionListener()
 Removes the action listener from this text field so that it will no longer call it when the user presses Enter. More...
 
void removeTextChangeListener()
 Removes the text change listener from this text field so that it will no longer call it when the user types characters. More...
 
void requestFocus()
 Transfers keyboard focus to this interactor. More...
 
void setAccelerator(string accelerator)
 Sets an accelerator hotkey for this interactor, such as "Ctrl-S". More...
 
void setActionCommand(string actionCommand)
 Sets the action command for this interactor. More...
 
void setActionListener(GEventListener func)
 Sets an action listener on this text field so that it will be called when the user presses the Enter key. More...
 
void setActionListener(GEventListenerVoid func)
 Sets an action listener on this text field so that it will be called when the user presses the Enter key. More...
 
void setAutocompleteEnabled(bool enabled)
 Sets whether the autocompletion feature is enabled for this text field. More...
 
void setAutocompleteList(std::initializer_list< string > strings)
 Sets the given list of strings to be used as an autocompletion list for this text field. More...
 
void setAutocompleteList(const Vector< string > &strings)
 Sets the given list of strings to be used as an autocompletion list for this text field. More...
 
void setBackground(int rgb)
 Sets the background color of the interactor to the color represented by the given RGB integer. More...
 
void setBackground(string color)
 Sets the background color of the interactor to the color represented by the given string. More...
 
void setBounds(double x, double y, double width, double height)
 Sets the size and location of the widget. More...
 
void setBounds(const GRectangle &size)
 Sets the size and location of the widget. More...
 
void setCharsWide(int charsWide)
 Sets the width of this text field to be exactly wide enough to display the given number of characters. More...
 
void setColor(int rgb)
 Sets the foreground/text color of the interactor to the color represented by the given RGB integer. More...
 
void setColor(string color)
 Sets the foreground/text color of the interactor to the color represented by the given string. More...
 
void setEditable(bool value)
 Sets whether the value in the text box can be edited. More...
 
void setEnabled(bool value)
 Sets whether this interactor is currently enabled. More...
 
void setEventsEnabled(bool eventsEnabled)
 Sets whether the object is currently allowing itself to fire events. More...
 
void setFont(const QFont &font)
 Sets the font used by this widget to the given Qt font. More...
 
void setFont(string font)
 Sets the font used by this widget to the font represented by the given font string, such as "Helvetica-16-Bold". More...
 
void setForeground(int rgb)
 Sets the foreground/text color of the interactor to the color represented by the given RGB integer. More...
 
void setForeground(string color)
 Sets the foreground/text color of the interactor to the color represented by the given string. More...
 
void setHeight(double height)
 Sets the onscreen height of the interactor in pixels. More...
 
void setIcon(string filename, bool retainIconSize=true)
 Sets the file name of the icon associated with this interactor, or an empty string if no icon has been set. More...
 
void setLocation(double x, double y)
 Sets the onscreen x/y-coordinate of the top-left corner of the interactor relative to its window. More...
 
void setMaxLength(int maxLength)
 Sets the maximum number of characters that can be typed into the field. More...
 
void setMinimumSize(double width, double height)
 Sets the minimum size in pixels that this interactor will permit itself to be resized to. More...
 
void setMinimumSize(const GDimension &size)
 Sets the minimum size in pixels that this interactor will permit itself to be resized to. More...
 
void setName(string name)
 Sets a string representing a unique name for this interactor. More...
 
void setPlaceholder(string text)
 Sets a gray message that is displayed in the background of the text field before the user has typed any value. More...
 
void setPreferredHeight(double height)
 Sets the height in pixels that this interactor would prefer to be. More...
 
void setPreferredSize(double width, double height)
 Sets the width and height in pixels that this interactor would prefer to be. More...
 
void setPreferredSize(const GDimension &size)
 Sets the size in pixels that this interactor would prefer to be. More...
 
void setPreferredWidth(double width)
 Sets the width in pixels that this interactor would prefer to be. More...
 
void setSize(double width, double height)
 Sets the onscreen width and height of the interactor in pixels. More...
 
void setSize(const GDimension &size)
 Sets the onscreen width and height of the interactor in pixels. More...
 
void setText(string text)
 Sets the current text value in the text field. More...
 
void setTextChangeListener(GEventListener func)
 Sets a text-change listener on this text field so that it will be called when the value in the field changes, which will occur on every key press. More...
 
void setTextChangeListener(GEventListenerVoid func)
 Sets a text-change listener on this text field so that it will be called when the value in the field changes, which will occur on every key press. More...
 
void setTooltip(string tooltipText)
 Sets a "tooltip" that will appear if the user hovers their mouse over the interactor. More...
 
void setValue(bool value)
 Sets the current text value in the text field to the string representation of the given value. More...
 
void setValue(char value)
 Sets the current text value in the text field to the string representation of the given value. More...
 
void setValue(double value)
 Sets the current text value in the text field to the string representation of the given value. More...
 
void setValue(int value)
 Sets the current text value in the text field to the string representation of the given value. More...
 
void setValue(string value)
 Sets the current text value in the text field to the string representation of the given value. More...
 
void setVisible(bool visible)
 Returns true if the interactor is visible on the screen. More...
 
void setWidth(double width)
 Sets the onscreen width of the interactor in pixels. More...
 
void setX(double x)
 Sets the onscreen x-coordinate of the top-left corner of the interactor relative to its window. More...
 
void setY(double y)
 Sets the onscreen y-coordinate of the top-left corner of the interactor relative to its window. More...
 
string toString() const
 Returns a string representation of this observable object's state. More...
 
bool valueIsBool() const
 Returns true if the currently typed value in the text field can be interpreted as a bool value of true or false. More...
 
bool valueIsChar() const
 Returns true if the currently typed value in the text field can be interpreted as a char value. More...
 
bool valueIsDouble() const
 Returns true if the currently typed value in the text field can be interpreted as a real number. More...
 
bool valueIsInt() const
 Returns true if the currently typed value in the text field can be interpreted as an integer. More...
 
bool valueIsInteger() const
 Returns true if the currently typed value in the text field can be interpreted as an integer. More...
 
bool valueIsReal() const
 Returns true if the currently typed value in the text field can be interpreted as a real number. More...
 

Protected Member Functions

void clearEventListeners()
 Removes all event listeners from this object. More...
 
void ensureThreadSafety(string memberName="")
 Ensures that we are currently in the Qt GUI thread. More...
 
void fireEvent(GEvent &event)
 Sends out the given event to any attached listeners. More...
 
void fireGEvent(QEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QCloseEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QKeyEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QMouseEvent *event, EventType eventType, string eventName, string actionCommand="")
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QResizeEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QTimerEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QWheelEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
void fireGEvent(QWindowStateChangeEvent *event, EventType eventType, string eventName)
 Creates an event of the given type, then sends it out to any attached listeners. More...
 
bool hasEventListener(string eventName) const
 Returns true if the observable object has a listener for the given type of event. More...
 
bool isAcceptingEvent(int eventMask) const
 Returns true if the observable object has a listener for the given type of event. More...
 
bool isAcceptingEvent(const GEvent &event) const
 Returns true if the observable object has a listener for the given type of event. More...
 
bool isAcceptingEvent(string eventType) const
 Returns true if the observable object has a listener for the given type of event. More...
 
void removeEventListener(string eventName)
 Removes any event listener from this observable object that would respond to the given type of event, such as "click" or "keydown". More...
 
void removeEventListeners(std::initializer_list< string > eventNames)
 Removes any event listener from this observable object that would respond to the given types of events, such as "click" or "keydown". More...
 
void setEventListener(string eventName, GEventListener func)
 Adds an event listener from this observable object to respond to the given type of event, such as "click" or "keydown". More...
 
void setEventListener(string eventName, GEventListenerVoid func)
 Adds an event listener from this observable object to respond to the given type of event, such as "click" or "keydown". More...
 
void setEventListeners(std::initializer_list< string > eventNames, GEventListener func)
 Adds an event listener from this observable object to respond to the given types of events, such as "click" or "keydown". More...
 
void setEventListeners(std::initializer_list< string > eventNames, GEventListenerVoid func)
 Adds an event listener from this observable object to respond to the given types of events, such as "click" or "keydown". More...
 

Detailed Description

This interactor subclass represents a text field for entering short text strings.

Pressing Enter in a text field generates an action event.

Member Enumeration Documentation

◆ InputType

enum InputType

Constants for the valid types of text field input.

Enumerator
INPUT_TYPE_TEXT 
INPUT_TYPE_INTEGER 
INPUT_TYPE_REAL 

◆ TextPosition

enum TextPosition
inherited

The places where an interactor can place its text relative to its icon.

Enumerator
TEXT_BESIDE_ICON 
TEXT_UNDER_ICON 
TEXT_ONLY 

Constructor & Destructor Documentation

◆ GTextField() [1/4]

GTextField ( string   text = "",
int  charsWide = 0,
QWidget*   parent = nullptr 
)

Creates a text field with the given initial text.

If the optional charsWide parameter is passed, sizes the text field wide enough to display the given number of characters.

◆ GTextField() [2/4]

GTextField ( int  charsWide,
QWidget*   parent = nullptr 
)

Creates a text field wide enough to display the given number of characters.

◆ GTextField() [3/4]

GTextField ( int  value,
int  min,
int  max,
int  step = 1,
QWidget*   parent = nullptr 
)

Creates a text field for entering integer values, with the given initial value.

The value is constrained to the given minimum and maximum, incrementing by the given step amount.

Exceptions
ErrorExceptionif min > max or value is not between min and max

◆ GTextField() [4/4]

GTextField ( double  value,
double  min,
double  max,
double  step,
QWidget*   parent = nullptr 
)

Creates a text field for entering real number values, with the given initial value.

The value is constrained to the given minimum and maximum, incrementing by the given step amount.

Exceptions
ErrorExceptionif min > max or value is not between min and max

◆ ~GTextField()

~GTextField ( )
virtual

Frees memory allocated internally by the text field.

Member Function Documentation

◆ addActionListener()

void addActionListener ( )
virtualinherited

Adds an event listener to be notified when this interactor is clicked or generally interacted with.

Deprecated:
does nothing; use setActionListener instead

◆ clearEventListeners()

void clearEventListeners ( )
protectedvirtualinherited

Removes all event listeners from this object.

◆ ensureThreadSafety()

void ensureThreadSafety ( string   memberName = "")
protectedvirtualinherited

Ensures that we are currently in the Qt GUI thread.

◆ eventsEnabled()

bool eventsEnabled ( ) const
virtualinherited

Returns true if this interactor is currently accepting events.

Initially true. An interactor must be visible and added to an onscreen window to receive events.

Reimplemented from GObservable.

◆ fireEvent()

void fireEvent ( GEvent event)
protectedvirtualinherited

Sends out the given event to any attached listeners.

◆ fireGEvent() [1/8]

void fireGEvent ( QEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtualinherited

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [2/8]

void fireGEvent ( QCloseEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtualinherited

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [3/8]

void fireGEvent ( QKeyEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtualinherited

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [4/8]

void fireGEvent ( QMouseEvent *  event,
EventType  eventType,
string   eventName,
string   actionCommand = "" 
)
protectedvirtualinherited

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [5/8]

void fireGEvent ( QResizeEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtualinherited

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [6/8]

void fireGEvent ( QTimerEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtualinherited

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [7/8]

void fireGEvent ( QWheelEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtualinherited

Creates an event of the given type, then sends it out to any attached listeners.

◆ fireGEvent() [8/8]

void fireGEvent ( QWindowStateChangeEvent *  event,
EventType  eventType,
string   eventName 
)
protectedvirtualinherited

Creates an event of the given type, then sends it out to any attached listeners.

◆ getAccelerator()

string getAccelerator ( ) const
virtualinherited

Returns a string representing a hotkey for this interactor, or an empty string if no accelerator has been set.

Returns
an accelerator such as "Ctrl-S"

Reimplemented in GButton.

◆ getActionCommand()

string getActionCommand ( ) const
virtualinherited

Returns an action command for this interactor, which is a semi-unique string you can use to identify it when events occur.

For example, for buttons, the default action command is the button's text.

Reimplemented in GChooser, GRadioButton, GCheckBox, and GButton.

◆ getBackground()

string getBackground ( ) const
virtualinherited

Returns the background color of the interactor as a string.

Returns
a string such as "blue" or "#7700ff"

Reimplemented in GCanvas.

◆ getBackgroundInt()

int getBackgroundInt ( ) const
virtualinherited

Returns the background color of the interactor as an RGB integer.

Returns
an integer such as 0x7700ff

Reimplemented in GCanvas.

◆ getBounds()

GRectangle getBounds ( ) const
virtualinherited

Returns a rectangle representing the x/y position and size of this interactor.

◆ getCharsWide()

int getCharsWide ( ) const
virtual

Returns the number of characters that can fit in the visible area of this text field.

◆ getColor()

string getColor ( ) const
virtualinherited

Returns the foreground/text color of the interactor as a string.

Equivalent to getForeground.

Returns
a string such as "blue" or "#7700ff"

◆ getColorInt()

int getColorInt ( ) const
virtualinherited

Returns the foreground/text color of the interactor as an RGB integer.

Equivalent to getForegroundInt.

Returns
an integer such as 0x7700ff

◆ getContainer()

GContainer * getContainer ( ) const
virtualinherited

Returns a pointer to the onscreen container holding this interactor.

When an interactor is created, its container is initially null. This will become non-null automatically if you add the interactor to a window or other layout container. Interactors must be added to a container or window to receive events or to become visible on the screen.

Returns
the container, or nullptr if interactor has not yet been added to any container

◆ getFont()

string getFont ( ) const
virtualinherited

Returns the font of this interactor's text as a font string such as "Helvetica-12-Bold".

Returns
a font string such as "Helvetica-12-Bold"

Reimplemented in GCanvas.

◆ getForeground()

string getForeground ( ) const
virtualinherited

Returns the foreground/text color of the interactor as a string.

Equivalent to getColor.

Returns
a string such as "blue" or "#7700ff"

◆ getForegroundInt()

int getForegroundInt ( ) const
virtualinherited

Returns the foreground/text color of the interactor as an RGB integer.

Equivalent to getColorInt.

Returns
an integer such as 0x7700ff

◆ getHeight()

double getHeight ( ) const
virtualinherited

Returns the current onscreen height of this interactor in pixels.

◆ getIcon()

string getIcon ( ) const
virtualinherited

Returns the file name of the icon associated with this interactor, or an empty string if no icon has been set.

Not all types of interactors support icons.

◆ getID()

int getID ( ) const
virtualinherited

Returns a globally unique identifier for this interactor, which is set when the interactor is constructed.

These IDs can be useful for debugging to help identify interactors uniquely.

◆ getInputType()

GTextField::InputType getInputType ( ) const
virtual

Returns the type of input accepted by this text field.

The default is text input (GTextField::INPUT_TYPE_TEXT), but you can create a field that accepts integers (INPUT_TYPE_INTEGER) or real numbers (INPUT_TYPE_REAL).

◆ getInternalWidget()

_Internal_QWidget* getInternalWidget ( ) const
virtual

Returns a direct pointer to the internal Qt widget being wrapped by this interactor.

This must be overridden by all interactor subclasses. Students/clients generally should not need to call this.

Implements GInteractor.

◆ getLocation()

GPoint getLocation ( ) const
virtualinherited

Returns an (x, y) point representing the onscreen location of the top-left corner of this interactor within its containing window.

◆ getMaxLength()

int getMaxLength ( ) const
virtual

Returns the maximum length of string allowed in the text field.

By default no max is set, in which case this method returns 0.

◆ getMinimumHeight()

double getMinimumHeight ( ) const
virtualinherited

Returns the minimum height in pixels that this interactor will permit itself to be resized to.

◆ getMinimumSize()

GDimension getMinimumSize ( ) const
virtualinherited

Returns a GDimension structure representing the minimum size in pixels that this interactor will permit itself to be resized to.

◆ getMinimumWidth()

double getMinimumWidth ( ) const
virtualinherited

Returns the minimum width in pixels that this interactor will permit itself to be resized to.

◆ getName()

string getName ( ) const
virtualinherited

Returns a string representing a unique name for this interactor.

The default name string uses the interactor's type and its ID to make a string like "GButton_14", but you can override this by calling setName.

Returns
a string such as "GButton_14"

◆ getPlaceholder()

string getPlaceholder ( ) const
virtual

Returns the text field's placeholder text, which is usually displayed as a light gray text in the field when the field is empty.

This usually indicates a hint to the user about what value to type.

◆ getPreferredHeight()

double getPreferredHeight ( ) const
virtualinherited

Returns the height in pixels that this interactor would prefer to be, which would exactly fit its contents with no stretching or scrollbars.

◆ getPreferredSize()

GDimension getPreferredSize ( ) const
virtualinherited

Returns a GDimension structure storing the width and height in pixels that this interactor would prefer to be, which would exactly fit its contents with no stretching or scrollbars.

Reimplemented in GContainer.

◆ getPreferredWidth()

double getPreferredWidth ( ) const
virtualinherited

Returns the height in pixels that this interactor would prefer to be, which would exactly fit its contents with no stretching or scrollbars.

◆ getSize()

GDimension getSize ( ) const
virtualinherited

Returns a GDimension structure storing the current onscreen width and height of this interactor in pixels.

◆ getText()

string getText ( ) const
virtual

Returns the text field's current text.

Equivalent to getValue.

◆ getType()

string getType ( ) const
virtual

Returns a string representing the class name of this interactor, such as "GButton" or "GCheckBox".

All subclasses of GInteractor must implement this method.

Returns
a string such as "GCheckBox"

Implements GInteractor.

◆ getValue()

string getValue ( ) const
virtual

Returns the text field's current text.

Equivalent to getText.

◆ getValueAsBool()

bool getValueAsBool ( ) const
virtual

Returns the currently typed value in the text field, interpreted as a bool value of true or false.

See the stringToBool function in strlib.h for more information about how the string is converted to a bool value.

Exceptions
ErrorExceptionif the string cannot be converted to bool type

◆ getValueAsChar()

char getValueAsChar ( ) const
virtual

Returns the currently typed value in the text field as a char value.

This returns the first character of the string, or '\0' if the text field is empty.

◆ getValueAsDouble()

double getValueAsDouble ( ) const
virtual

Returns the currently typed value in the text field, interpreted as a real number value.

See the stringToDouble function in strlib.h for more information about how the string is converted to a numeric value.

Exceptions
ErrorExceptionif the string cannot be converted to double type

◆ getValueAsInt()

int getValueAsInt ( ) const
virtual

Returns the currently typed value in the text field, interpreted as an integer value.

See the stringToInteger function in strlib.h for more information about how the string is converted to a numeric value. Equivalent to getValueAsInteger.

Exceptions
ErrorExceptionif the string cannot be converted to integer type

◆ getValueAsInteger()

int getValueAsInteger ( ) const
virtual

Returns the currently typed value in the text field, interpreted as an integer value.

See the stringToInteger function in strlib.h for more information about how the string is converted to a numeric value. Equivalent to getValueAsInteger.

Exceptions
ErrorExceptionif the string cannot be converted to integer type

◆ getWidget()

QWidget* getWidget ( ) const
virtual

Returns a direct pointer to the internal Qt widget being wrapped by this interactor.

This must be overridden by all interactor subclasses. Students/clients generally should not need to call this.

Implements GInteractor.

◆ getWidth()

double getWidth ( ) const
virtualinherited

Returns the current onscreen width of this interactor in pixels.

◆ getX()

double getX ( ) const
virtualinherited

Returns the x-coordinate of the top-left pixel of this interactor within its onscreen window.

◆ getY()

double getY ( ) const
virtualinherited

Returns the y-coordinate of the top-left pixel of this interactor within its onscreen window.

◆ hasEventListener()

bool hasEventListener ( string   eventName) const
protectedvirtualinherited

Returns true if the observable object has a listener for the given type of event.

◆ inBounds() [1/2]

bool inBounds ( double  x,
double  y 
) const
virtualinherited

Returns true if the given x/y pixel is within the bounds of this interactor.

◆ inBounds() [2/2]

bool inBounds ( int  x,
int  y 
) const
virtualinherited

Returns true if the given x/y pixel is within the bounds of this interactor.

Reimplemented in GTable.

◆ isAcceptingEvent() [1/3]

bool isAcceptingEvent ( int  eventMask) const
protectedvirtualinherited

Returns true if the observable object has a listener for the given type of event.

See gevent.h for event types and masks.

◆ isAcceptingEvent() [2/3]

bool isAcceptingEvent ( const GEvent event) const
protectedvirtualinherited

Returns true if the observable object has a listener for the given type of event.

◆ isAcceptingEvent() [3/3]

bool isAcceptingEvent ( string   eventType) const
protectedvirtualinherited

Returns true if the observable object has a listener for the given type of event.

◆ isAutocompleteEnabled()

bool isAutocompleteEnabled ( ) const
virtual

Returns true if this text field has an autocompletion list of options that will pop up as the user begins typing.

Text fields do not initially have such a list, but you can supply one by calling setAutocompleteList.

◆ isEditable()

bool isEditable ( ) const
virtual

Returns true if the text field's value can be edited.

Initially this is true but can be changed by calling setEditable(false).

◆ isEnabled()

bool isEnabled ( ) const
virtualinherited

Returns true if this interactor is currently enabled.

Most interactors begin as enabled but can be disabled to stop them from being able to be clicked on or otherwise emit events.

◆ isVisible()

bool isVisible ( ) const
virtualinherited

Returns true if the interactor is visible on the screen.

Interactors will not be visible until they are added to an onscreen window or container.

◆ removeActionListener()

void removeActionListener ( )
virtual

Removes the action listener from this text field so that it will no longer call it when the user presses Enter.

◆ removeEventListener()

void removeEventListener ( string   eventName)
protectedvirtualinherited

Removes any event listener from this observable object that would respond to the given type of event, such as "click" or "keydown".

◆ removeEventListeners()

void removeEventListeners ( std::initializer_list< string >  eventNames)
protectedvirtualinherited

Removes any event listener from this observable object that would respond to the given types of events, such as "click" or "keydown".

◆ removeTextChangeListener()

void removeTextChangeListener ( )
virtual

Removes the text change listener from this text field so that it will no longer call it when the user types characters.

◆ requestFocus()

void requestFocus ( )
virtualinherited

Transfers keyboard focus to this interactor.

Reimplemented in GTable.

◆ setAccelerator()

void setAccelerator ( string   accelerator)
virtualinherited

Sets an accelerator hotkey for this interactor, such as "Ctrl-S".

Not all interactor types support accelerators.

Parameters
acceleratora hotkey such as "Ctrl-S"

Reimplemented in GButton.

◆ setActionCommand()

void setActionCommand ( string   actionCommand)
virtualinherited

Sets the action command for this interactor.

The action command is meant to be a semi-unique string you can use to identify the interactor when events occur. For example, for buttons, the default action command is the button's text, but you can change it to a different string if you prefer. The main usage of this feature is if you want to use the same function as an event listener for many interactors, you can use the action command to help distinguish which interactor generates each event.

◆ setActionListener() [1/2]

void setActionListener ( GEventListener  func)
virtual

Sets an action listener on this text field so that it will be called when the user presses the Enter key.

Any existing action listener will be replaced.

◆ setActionListener() [2/2]

void setActionListener ( GEventListenerVoid  func)
virtual

Sets an action listener on this text field so that it will be called when the user presses the Enter key.

Any existing action listener will be replaced.

◆ setAutocompleteEnabled()

void setAutocompleteEnabled ( bool  enabled)
virtual

Sets whether the autocompletion feature is enabled for this text field.

If you call setAutocompleteList, the autocompletion feature is automatically enabled; so the main purpose of this method is to turn it back off later.

◆ setAutocompleteList() [1/2]

void setAutocompleteList ( std::initializer_list< string >  strings)
virtual

Sets the given list of strings to be used as an autocompletion list for this text field.

After calling this, if the user types characters in the text field that form a prefix of any string in the list, those strings will be shown as a drop-down autocompletion list that the user can choose completed values from. To turn this feature back off, call setAutocompleteEnabled(false).

◆ setAutocompleteList() [2/2]

void setAutocompleteList ( const Vector< string > &  strings)
virtual

Sets the given list of strings to be used as an autocompletion list for this text field.

After calling this, if the user types characters in the text field that form a prefix of any string in the list, those strings will be shown as a drop-down autocompletion list that the user can choose completed values from. To turn this feature back off, call setAutocompleteEnabled(false).

◆ setBackground() [1/2]

void setBackground ( int  rgb)
virtualinherited

Sets the background color of the interactor to the color represented by the given RGB integer.

Parameters
rgban RGB integer such as 0x7700ff

Reimplemented in GCanvas, and GTable.

◆ setBackground() [2/2]

void setBackground ( string   color)
virtualinherited

Sets the background color of the interactor to the color represented by the given string.

Parameters
colora string such as "blue" or "#7700ff"

Reimplemented in GCanvas, and GTable.

◆ setBounds() [1/2]

void setBounds ( double  x,
double  y,
double  width,
double  height 
)
virtualinherited

Sets the size and location of the widget.

In general you should avoid explicitly sizing and positioning widgets in this way; instead, use containers and regions to help you lay out widgets at the proper sizes.

Reimplemented in GLabel.

◆ setBounds() [2/2]

void setBounds ( const GRectangle size)
virtualinherited

Sets the size and location of the widget.

In general you should avoid explicitly sizing and positioning widgets in this way; instead, use containers and regions to help you lay out widgets at the proper sizes.

Reimplemented in GLabel.

◆ setCharsWide()

void setCharsWide ( int  charsWide)
virtual

Sets the width of this text field to be exactly wide enough to display the given number of characters.

◆ setColor() [1/2]

void setColor ( int  rgb)
virtualinherited

Sets the foreground/text color of the interactor to the color represented by the given RGB integer.

Equivalent to setForeground.

Parameters
rgban RGB integer such as 0x7700ff

Reimplemented in GCanvas, GTable, and GLabel.

◆ setColor() [2/2]

void setColor ( string   color)
virtualinherited

Sets the foreground/text color of the interactor to the color represented by the given string.

Equivalent to setForeground.

Parameters
colora string such as "blue" or "#7700ff"

Reimplemented in GCanvas, GTable, and GLabel.

◆ setEditable()

void setEditable ( bool  value)
virtual

Sets whether the value in the text box can be edited.

Initially true.

◆ setEnabled()

void setEnabled ( bool  value)
virtualinherited

Sets whether this interactor is currently enabled.

Most interactors begin as enabled but can be disabled to stop them from being able to be clicked on or otherwise emit events.

◆ setEventListener() [1/2]

void setEventListener ( string   eventName,
GEventListener  func 
)
protectedvirtualinherited

Adds an event listener from this observable object to respond to the given type of event, such as "click" or "keydown".

Any prior listener for that type of event is replaced.

◆ setEventListener() [2/2]

void setEventListener ( string   eventName,
GEventListenerVoid  func 
)
protectedvirtualinherited

Adds an event listener from this observable object to respond to the given type of event, such as "click" or "keydown".

Any prior listener for that type of event is replaced.

◆ setEventListeners() [1/2]

void setEventListeners ( std::initializer_list< string >  eventNames,
GEventListener  func 
)
protectedvirtualinherited

Adds an event listener from this observable object to respond to the given types of events, such as "click" or "keydown".

Any prior listener for those types of event are replaced.

◆ setEventListeners() [2/2]

void setEventListeners ( std::initializer_list< string >  eventNames,
GEventListenerVoid  func 
)
protectedvirtualinherited

Adds an event listener from this observable object to respond to the given types of events, such as "click" or "keydown".

Any prior listener for those types of event are replaced.

◆ setEventsEnabled()

void setEventsEnabled ( bool  eventsEnabled)
virtualinherited

Sets whether the object is currently allowing itself to fire events.

Initially this is true.

◆ setFont() [1/2]

void setFont ( const QFont &  font)
virtualinherited

Sets the font used by this widget to the given Qt font.

Clients should generally use the string version of this method.

Reimplemented in GCanvas, GTable, and GLabel.

◆ setFont() [2/2]

void setFont ( string   font)
virtualinherited

Sets the font used by this widget to the font represented by the given font string, such as "Helvetica-16-Bold".

Parameters
fonta font string such as "Helvetica-16-Bold"

Reimplemented in GCanvas, GTable, and GLabel.

◆ setForeground() [1/2]

void setForeground ( int  rgb)
virtualinherited

Sets the foreground/text color of the interactor to the color represented by the given RGB integer.

Equivalent to setColor.

Parameters
rgban RGB integer such as 0x7700ff

Reimplemented in GCanvas, GTable, and GLabel.

◆ setForeground() [2/2]

void setForeground ( string   color)
virtualinherited

Sets the foreground/text color of the interactor to the color represented by the given string.

Equivalent to setColor.

Parameters
colora string such as "blue" or "#7700ff"

Reimplemented in GCanvas, GTable, and GLabel.

◆ setHeight()

void setHeight ( double  height)
virtualinherited

Sets the onscreen height of the interactor in pixels.

Exceptions
ErrorExceptionif height is negative

Reimplemented in GLabel.

◆ setIcon()

void setIcon ( string   filename,
bool  retainIconSize = true 
)
virtualinherited

Sets the file name of the icon associated with this interactor, or an empty string if no icon has been set.

Not all types of interactors support icons.

Parameters
filenameicon file path to use
retainIconSizetrue if icon should stay at its existing pixel size (default), or false if it should be resized to fit the interactor

Reimplemented in GLabel, and GButton.

◆ setLocation()

void setLocation ( double  x,
double  y 
)
virtualinherited

Sets the onscreen x/y-coordinate of the top-left corner of the interactor relative to its window.

Generally clients should not call this and should instead use containers and layout regions to position interactors.

Reimplemented in GLabel.

◆ setMaxLength()

void setMaxLength ( int  maxLength)
virtual

Sets the maximum number of characters that can be typed into the field.

◆ setMinimumSize() [1/2]

void setMinimumSize ( double  width,
double  height 
)
virtualinherited

Sets the minimum size in pixels that this interactor will permit itself to be resized to.

Exceptions
ErrorExceptionif width or height is negative

◆ setMinimumSize() [2/2]

void setMinimumSize ( const GDimension size)
virtualinherited

Sets the minimum size in pixels that this interactor will permit itself to be resized to.

Exceptions
ErrorExceptionif width or height is negative

◆ setName()

void setName ( string   name)
virtualinherited

Sets a string representing a unique name for this interactor.

The default name string uses the interactor's type and its ID to make a string like "GButton_14", but you can override this by calling setName.

Parameters
namea string such as "GButton_14"

◆ setPlaceholder()

void setPlaceholder ( string   text)
virtual

Sets a gray message that is displayed in the background of the text field before the user has typed any value.

This is often used as a hint to the user about what kind of value to type.

◆ setPreferredHeight()

void setPreferredHeight ( double  height)
virtualinherited

Sets the height in pixels that this interactor would prefer to be.

Normally clients do not need to call this method; the interactor can figure out its own preferred size. But calling it can help you to hint to the container/layout system if you want a given interactor to "prefer" to make itself larger or smaller for the purposes of your particular program.

◆ setPreferredSize() [1/2]

void setPreferredSize ( double  width,
double  height 
)
virtualinherited

Sets the width and height in pixels that this interactor would prefer to be.

Normally clients do not need to call this method; the interactor can figure out its own preferred size. But calling it can help you to hint to the container/layout system if you want a given interactor to "prefer" to make itself larger or smaller for the purposes of your particular program.

◆ setPreferredSize() [2/2]

void setPreferredSize ( const GDimension size)
virtualinherited

Sets the size in pixels that this interactor would prefer to be.

Normally clients do not need to call this method; the interactor can figure out its own preferred size.

◆ setPreferredWidth()

void setPreferredWidth ( double  width)
virtualinherited

Sets the width in pixels that this interactor would prefer to be.

Normally clients do not need to call this method; the interactor can figure out its own preferred size.

◆ setSize() [1/2]

void setSize ( double  width,
double  height 
)
virtualinherited

Sets the onscreen width and height of the interactor in pixels.

Exceptions
ErrorExceptionif width or height is negative

Reimplemented in GLabel.

◆ setSize() [2/2]

void setSize ( const GDimension size)
virtualinherited

Sets the onscreen width and height of the interactor in pixels.

Exceptions
ErrorExceptionif width or height is negative

Reimplemented in GLabel.

◆ setText()

void setText ( string   text)
virtual

Sets the current text value in the text field.

◆ setTextChangeListener() [1/2]

void setTextChangeListener ( GEventListener  func)
virtual

Sets a text-change listener on this text field so that it will be called when the value in the field changes, which will occur on every key press.

Any existing text-change listener will be replaced.

◆ setTextChangeListener() [2/2]

void setTextChangeListener ( GEventListenerVoid  func)
virtual

Sets a text-change listener on this text field so that it will be called when the value in the field changes, which will occur on every key press.

Any existing text-change listener will be replaced.

◆ setTooltip()

void setTooltip ( string   tooltipText)
virtualinherited

Sets a "tooltip" that will appear if the user hovers their mouse over the interactor.

Set an empty string to clear the tooltip.

◆ setValue() [1/5]

void setValue ( bool  value)
virtual

Sets the current text value in the text field to the string representation of the given value.

◆ setValue() [2/5]

void setValue ( char  value)
virtual

Sets the current text value in the text field to the string representation of the given value.

◆ setValue() [3/5]

void setValue ( double  value)
virtual

Sets the current text value in the text field to the string representation of the given value.

◆ setValue() [4/5]

void setValue ( int  value)
virtual

Sets the current text value in the text field to the string representation of the given value.

◆ setValue() [5/5]

void setValue ( string   value)
virtual

Sets the current text value in the text field to the string representation of the given value.

Equivalent to setText.

◆ setVisible()

void setVisible ( bool  visible)
virtualinherited

Returns true if the interactor is visible on the screen.

Interactors will not be visible until they are added to an onscreen window or container. If you call setVisible on an interactor that is not in any onscreen container, it will have no effect.

Reimplemented in GLabel.

◆ setWidth()

void setWidth ( double  width)
virtualinherited

Sets the onscreen width of the interactor in pixels.

Exceptions
ErrorExceptionif width is negative

Reimplemented in GLabel.

◆ setX()

void setX ( double  x)
virtualinherited

Sets the onscreen x-coordinate of the top-left corner of the interactor relative to its window.

Generally clients should not call this and should instead use containers and layout regions to position interactors.

Reimplemented in GLabel.

◆ setY()

void setY ( double  y)
virtualinherited

Sets the onscreen y-coordinate of the top-left corner of the interactor relative to its window.

Generally clients should not call this and should instead use containers and layout regions to position interactors.

Reimplemented in GLabel.

◆ toString()

string toString ( ) const
virtualinherited

Returns a string representation of this observable object's state.

Primarily used for debugging purposes.

◆ valueIsBool()

bool valueIsBool ( ) const
virtual

Returns true if the currently typed value in the text field can be interpreted as a bool value of true or false.

If this is true, a call to getValueAsBool will succeed.

◆ valueIsChar()

bool valueIsChar ( ) const
virtual

Returns true if the currently typed value in the text field can be interpreted as a char value.

This will be true if its length is exactly 1. If this is true, a call to getValueAsChar will succeed.

◆ valueIsDouble()

bool valueIsDouble ( ) const
virtual

Returns true if the currently typed value in the text field can be interpreted as a real number.

If this is true, a call to getValueAsDouble will succeed. Equivalent to valueIsReal.

◆ valueIsInt()

bool valueIsInt ( ) const
virtual

Returns true if the currently typed value in the text field can be interpreted as an integer.

If this is true, a call to getValueAsInt / getValueAsInteger will succeed. Equivalent to valueIsInteger.

◆ valueIsInteger()

bool valueIsInteger ( ) const
virtual

Returns true if the currently typed value in the text field can be interpreted as an integer.

If this is true, a call to getValueAsInt / getValueAsInteger will succeed. Equivalent to valueIsInt.

◆ valueIsReal()

bool valueIsReal ( ) const
virtual

Returns true if the currently typed value in the text field can be interpreted as a real number.

If this is true, a call to getValueAsDouble will succeed. Equivalent to valueIsDouble.