#include <YButtonBox.h>
Public Member Functions | |
virtual | ~YButtonBox () |
virtual const char * | widgetClass () const |
virtual void | setMargins (const YButtonBoxMargins &margins) |
YButtonBoxMargins | margins () const |
virtual void | doLayout (int width, int height) |
YPushButton * | findButton (YButtonRole role) |
void | sanityCheck () |
void | setSanityCheckRelaxed (bool relax=true) |
bool | sanityCheckRelaxed () const |
virtual int | preferredWidth () |
virtual int | preferredHeight () |
virtual void | setSize (int newWidth, int newHeight) |
virtual bool | stretchable (YUIDimension dimension) const |
![]() | |
virtual | ~YWidget () |
virtual std::string | debugLabel () const |
std::string | helpText () const |
void | setHelpText (const std::string &helpText) |
virtual const YPropertySet & | propertySet () |
virtual bool | setProperty (const std::string &propertyName, const YPropertyValue &val) |
virtual YPropertyValue | getProperty (const std::string &propertyName) |
bool | hasChildren () const |
YWidget * | firstChild () const |
YWidget * | lastChild () const |
YWidgetListIterator | childrenBegin () const |
YWidgetListIterator | childrenEnd () const |
YWidgetListConstIterator | childrenConstBegin () const |
YWidgetListConstIterator | childrenConstEnd () const |
YWidgetListIterator | begin () |
YWidgetListIterator | end () |
int | childrenCount () const |
bool | contains (YWidget *child) const |
virtual void | addChild (YWidget *child) |
virtual void | removeChild (YWidget *child) |
void | deleteChildren () |
YWidget * | parent () const |
bool | hasParent () const |
void | setParent (YWidget *newParent) |
YDialog * | findDialog () |
YWidget * | findWidget (YWidgetID *id, bool doThrow=true) const |
virtual int | preferredSize (YUIDimension dim) |
bool | isValid () const |
bool | beingDestroyed () const |
void * | widgetRep () const |
void | setWidgetRep (void *toolkitWidgetRep) |
bool | hasId () const |
YWidgetID * | id () const |
void | setId (YWidgetID *newId_disown) |
virtual void | setEnabled (bool enabled=true) |
void | setDisabled () |
virtual bool | isEnabled () const |
void | setStretchable (YUIDimension dim, bool newStretch) |
void | setDefaultStretchable (YUIDimension dim, bool newStretch) |
virtual int | weight (YUIDimension dim) |
bool | hasWeight (YUIDimension dim) |
void | setWeight (YUIDimension dim, int weight) |
void | setNotify (bool notify=true) |
bool | notify () const |
void | setNotifyContextMenu (bool notifyContextMenu=true) |
bool | notifyContextMenu () const |
bool | sendKeyEvents () const |
void | setSendKeyEvents (bool doSend) |
bool | autoShortcut () const |
void | setAutoShortcut (bool _newAutoShortcut) |
int | functionKey () const |
bool | hasFunctionKey () const |
virtual void | setFunctionKey (int fkey_no) |
virtual bool | setKeyboardFocus () |
virtual std::string | shortcutString () const |
virtual void | setShortcutString (const std::string &str) |
virtual const char * | userInputProperty () |
void | dumpWidgetTree (int indentationLevel=0) |
void | dumpDialogWidgetTree () |
void | setChildrenEnabled (bool enabled) |
virtual void | saveUserInput (YMacroRecorder *macroRecorder) |
void * | operator new (size_t size) |
void | operator delete (void *ptr) noexcept |
virtual void | startMultipleChanges () |
virtual void | doneMultipleChanges () |
Static Public Member Functions | |
static void | setLayoutPolicy (const YButtonBoxLayoutPolicy &layoutPolicy) |
static YButtonBoxLayoutPolicy | layoutPolicy () |
static YButtonBoxLayoutPolicy | kdeLayoutPolicy () |
static YButtonBoxLayoutPolicy | gnomeLayoutPolicy () |
static void | setDefaultMargins (const YButtonBoxMargins &margins) |
static YButtonBoxMargins | defaultMargins () |
Protected Member Functions | |
YButtonBox (YWidget *parent) | |
virtual std::vector< YPushButton * > | buttonsByButtonOrder () |
int | maxChildSize (YUIDimension dim) const |
int | totalChildrenWidth () const |
virtual void | moveChild (YWidget *child, int newX, int newY)=0 |
int | preferredWidth (bool equalSizeButtons) |
![]() | |
YWidget (YWidget *parent) | |
YWidgetChildrenManager * | childrenManager () const |
void | setChildrenManager (YWidgetChildrenManager *manager) |
void | setBeingDestroyed () |
void | dumpWidget (YWidget *w, int indentationLevel) |
Friends | |
class | YButtonBoxPrivate |
Container widget for dialog buttons that abstracts the button order depending on the desktop environment.
KDE and Windows arrange dialog buttons like this:
[OK] [Apply] [Cancel] [Custom1] [Custom2] ... [Help] [Continue] [Cancel] [Yes] [No]
GNOME and MacOS arrange them like this:
[Help] [Custom1] [Custom2] ... [Apply] [Cancel] [OK] [Cancel] [Continue] [No] [Yes]
This class provides the abstraction to use whatever layout is more appropriate in the current environment. The application creates the buttons as child widgets of a YButtonBox (rather than a YHBox) and leaves the button order to the YButtonBox.
Each of the standard buttons ([OK], [Apply], [Cancel], [Help]) needs to have a button role properly assigned.
If set up properly (see YApplication::setDefaultFunctionKey()), known button labels will be assigned an appropriate role:
[OK] F10 [Continue] -> [OK] F10 [Yes] -> [OK] F10 [Accept] -> [OK] F10 [Next] -> [OK] F10 [Cancel] F9 [No] -> [Cancel] F9 [Help] F1
Buttons with nonstandard labels that act in such a role need to be explicitly assigned that role:
[Print ] [Cancel] [Help] [Delete] [Cancel] [Help]
Those [Print] or [Delete] buttons act as [OK] buttons (the "yes, do it" action of that dialog). Call YPushButton::setButtonRole( YOkButton ) explicitly for them.
YButtonBox widgets only accept YPushButton child widgets. Otherwise an exception is thrown.
If there is more than one button, one of the child buttons needs to have the [OK] role, and another needs to have the [Cancel] role. Otherwise an exception is thrown.
|
protected |
Constructor.
|
virtual |
Destructor.
|
protectedvirtual |
Return the button children sorted (left to right) by the current button order (from the layout policy).
This default implementation handles KDE and Gnome button orders. It is used in the default doLayout() method.
This may throw exceptions if there are non-button children or if there are multiple buttons with any of the standard button roles (except YCustomButton, of course).
|
static |
Return the default margins for all future YButtonBox widgets.
|
virtual |
Lay out the button box and its children (its buttons). This is where the button order is implemented.
This method is called by the default setSize() method. It uses YButtonBox::layoutPolicy() and the specified margins (defaultMargins unless changed with setMargins() ). It moves the buttons to their position with moveChild().
This all should work reasonably in all cases (Qt-UI with KDE button order, Gtk-UI with Gnome button order, NCurses-UI with KDE button order).
Still, derived classes can reimplement this. It does not make very much sense to call this default method in a new implementation.
YPushButton * YButtonBox::findButton | ( | YButtonRole | role | ) |
Search the child widgets for the first button with the specified role. Return the button or 0 if there is no button with that role.
|
static |
Predefined layout policy for GNOME-like behaviour.
|
static |
Predefined layout policy for KDE-like behaviour.
|
static |
Return the layout policy.
YButtonBoxMargins YButtonBox::margins | ( | ) | const |
Return the margins of this YButtonBox.
Notice that those are only the desired margins; if there is not enough space, margins and spacings will be reduced before buttons are cut off.
|
protected |
Return the (preferred) size of the biggest child widget in the specified dimension.
|
protectedpure virtual |
Move a child to a new position. This is used in doLayout().
Derived classes are required to implement this.
|
virtual |
Preferred height of the widget.
Reimplemented from YWidget. This default method returns the height of the highest child plus the top and bottom margins.
Derived classes can reimplement this method. It does not make very much sense to call this base class method in a new implementation.
Implements YWidget.
|
virtual |
Preferred width of the widget.
Reimplemented from YWidget. This default method returns the sum of the the widths of all child widgets plus the left and right margins plus the spacings.
Derived classes can reimplement this method. It does not make very much sense to call this base class method in a new implementation.
Implements YWidget.
|
protected |
Calculate the preferred with with or without trying to enforce buttons of equal size.
void YButtonBox::sanityCheck | ( | ) |
Sanity check: Check if all child widgets have the correct widget class and if the button roles are assigned correctly.
A YButtonBox with more than one button is required to have one YOKButton and ony YCancelButton. Neither button role may be assigned more than once.
This method may throw exceptions:
This cannot be done as child widgets are inserted since this is done from the child widgets' constructors, so virtual methods or dynamic_cast don't work at that point.
This is called in the default setSize() method (just before doLayout()), so any of the above errors are caught only at that time. Applications are free to call this before that time to make error handling more transparent.
bool YButtonBox::sanityCheckRelaxed | ( | ) | const |
Return 'true' if sanity checks are currently relaxed, 'false' if not.
|
static |
Set the default margins for all future YButtonBox widgets.
|
static |
Set the button policy for all future YButtonBox widgets: Button order, alignment if there is any excess space, whether or not to give all buttons the same size.
You might want to use one of the predefined static methods: YButtonBox::kdeLayoutPolicy(), YButtonBox::gnomeLayoutPolicy().
The default doLayout() method uses those values.
Notice that there is intentionally no way to set this differently for each individual YButtonBox: This would defeat the purpose of consistency (with the desktop environment this application is running in), which is the reason for having this widget class.
|
virtual |
Set the margins for this YButtonBox.
Derived classes are free to reimplement this, but they should call this base class method in the new method.
void YButtonBox::setSanityCheckRelaxed | ( | bool | relax = true | ) |
Relax the sanity check done in sanityCheck(): Do not enforce that there has to be a YOKButton and a YCancelButton if there is more than one button.
In very rare cases, it might be neccessary to have a less stringent sanity check: There are some very few legitimate cases for having a YButtonBox with multiple buttons, yet without a YCancelButton.
Examples:
...message... <Countdown> [OK] [Stop] ...message... [OK] [Details]
In those cases, it makes sense to relax the sanity check.
|
virtual |
Sets the size of the YButtonBox.
Derived classes can reimplement this, but this base class method should be called in the reimplemented function.
Reimplemented from YWidget.
Implements YWidget.
|
virtual |
Returns the stretchability of the YButtonBox. YButtonBox widgets are horizontally stretchable by default. How any excess space is used is specified in the layout policy.
Reimplemented from YWidget.
Reimplemented from YWidget.
|
protected |
Return the sum of the (preferred) widths of all child widgets.
|
inlinevirtual |
Return a descriptive name of this widget class for logging, debugging etc.
Reimplemented from YWidget.