Libdiaqt Library

This library contains several useful classes and a collection of utility functions for Qt programming. The include files for the classes are named by the class name all in lower case, with extension .h, except for dialog_frame.h for DialogFrame. The include file for the utility functions is dia_qtutils.h.

Derived Qt Classes


ArrowButton::ArrowButton( Qt::ArrowType type, QWidget * parent, const char * name)
ColorSelector::ColorSelector(QWidget *parent, QString label, int red, int green, int blue, int hotFlag, int hotKey, bool rounded, const char *name, Qt::WFlags fl)
DialogFrame::DialogFrame(QWidget *parent, int numButtons, const char *labels[], const char *tips[], bool equalSized, const char *caption, const char *fallback, const char *name, Qt::WFlags fl)
DialogFrame::DialogFrame(QWidget *parent, int numButtons, int numRows, const char *labels[], const char *tips[], bool equalSized, bool rounded, const char *caption, const char *fallback, const char *name, Qt::WFlags fl)
void DialogFrame::changeEvent(QEvent *e)
MultiSlider::MultiSlider(QWidget *parent, int numSliders, const char *titles[], int minVal, int maxVal, int decimals, bool horizontal)
void MultiSlider::setDecimals(int slider, int decimals)
void MultiSlider::setValue(int slider, int value)
void MultiSlider::setRange(int slider, int minVal, int maxVal)
void MultiSlider::setMinMaxVal(int slider, int minVal, int maxVal, int value)
QSlider *MultiSlider::getSlider(int slider)
void MultiSlider::setEnabled(int slider, bool enabled)
void MultiSlider::showWidgets(int slider, bool show)
ToolEdit::ToolEdit( QWidget * parent, int columns, const char * name)
void ToolEdit::setColumnWidth(int columns)

Functions in dia_qtutils.cpp


QPushButton *diaPushButton(const char *text, QWidget *parent, QBoxLayout *layout)
QCheckBox *diaCheckBox(const char *text, QWidget *parent, QBoxLayout *layout)
QRadioButton *diaRadioButton(const char *label, QWidget *parent, QButtonGroup *group, QBoxLayout *layout, int id, const char *tooltip)
QLabel *diaLabel(const char *text, QWidget *parent, QBoxLayout *layout)
QAbstractSpinBox *diaLabeledSpin(int nDecimal, float minValue, float maxValue, float step, const char *text, QWidget *parent, QBoxLayout *layout, QLabel **labelPtr)
QVBoxLayout *diaVBoxLayout(QBoxLayout *layout)
QHBoxLayout *diaHBoxLayout(QBoxLayout *layout)
QSlider *diaSlider(int min, int max, int step, int value, QWidget *parent, QBoxLayout *layout)
void diaSetChecked(QAbstractButton *button, bool state)
void diaSetSlider(QSlider *slider, int value)
void diaSetSpinBox(QSpinBox *box, int value)
void diaSetDoubleSpinBox(QDoubleSpinBox *box, double value)
void diaSetSpinMMVal(QSpinBox *box, int min, int max, int value)
void diaSetGroup(QButtonGroup *group, int id)
void diaSetEditText(QLineEdit *edit, const QString &text)
void diaShowWidget(QWidget *widget, bool state)
int diaGetButtonWidth(QWidget *widget, bool rounded, float factor, const QString &text)
int diaSetButtonWidth(QPushButton *button, bool rounded, float factor, const QString &text)
void diaMaximumWindowSize(int &width, int &height)
void diaLimitWindowSize(int &width, int &height)
void diaLimitWindowPos(int neww, int newh, int &newdx, int &newdy)
void diaSetTitle(const char *title)
int dia_puts(const char *message)
int dia_err(const char *message)
int dia_ask(const char *question)
int dia_ask_forever(const char *question)
int dia_choice(const char *question, const char *lab1, const char *lab2, const char *lab3)
int diaQInput(int *value, int low, int high, int decimal, const char *prompt)
QString diaOpenFileName(QWidget *parent, const char *caption, int numFilters, const char *filters[])
void dia_vasmsg(const char *msg, ...)
void dia_smsg(const char **msg)

ArrowButton class

ArrowButton::ArrowButton ( Qt::ArrowType type, QWidget * parent, const char * name)

A toolbutton with an arrow icon that is nicer than the Qt arrow button.  type should be one of Qt::UpArrow, Qt::DownArrow, Qt::LeftArrow, Qt::RightArrow.  name defaults to 0 and is now irrelevant.  To use this class, you must have the four arrow.png files in a directory named images under the top directory of your project, and they must be included in a resource file, as in 3dmod and midas.

ColorSelector class

ColorSelector::ColorSelector(QWidget *parent, QString label, int red, int green, int blue, int hotFlag, int hotKey, bool rounded, const char *name, Qt::WFlags fl)

This class provides a color selector with a sample color panel, and three sliders for adjusting red, green, and blue.  label is used to set a label at the top of the panel, and the color is initialized with red, green, and blue.  It manages the color of the panel continuously during changes, and emits a signal for a new color if the slider is clicked.  It will also emit signals during a drag if hotFlag is not 2; if the key given by hotKey is up when hotFlag is 0; or if that key is down when hotFlag is 1.  name defaults to NULL, and the window flags default to Qt::WDestructiveClose | Qt::WType_TopLevel.
     Signals emitted are:
void newColor(int r, int g, int b);  -  When the color changes
void done();   -  When the Done button is pressed
void closing();  -  When the window is closing
void keyPress(QKeyEvent *e);   -  When a key is pressed
void keyRelease(QKeyEvent *e);  -  When a key is released
     In addition, there is one method:
bool hotSliding();  -  Returns true is a slider is being dragged

DialogFrame class

DialogFrame::DialogFrame(QWidget *parent, int numButtons, const char *labels[], const char *tips[], bool equalSized, const char *caption, const char *fallback, const char *name, Qt::WFlags fl)

DialogFrame provides a widget whose default style is to be a dialog box that destroys itself on closing.  Its main area is a QVBoxLayout, protected member mLayout, that can be populated with widgets by the inheriting class.  The bottom row(s) will have numButton buttons, with text given in labels.  Tooltips for each button can be provided in tips if it is non-NULL.  The buttons will be equally sized if equalSized is true; otherwise they will all be just big enough for their respective text.  The window title will be set to caption, or to fallback if caption is NULL.  name defaults to 0, fl defaults to Qt::Window.
The class emits two signals: actionPressed(int which) and actionClicked(int which) with the argument providing the number of the button pressed or clicked.

DialogFrame::DialogFrame(QWidget *parent, int numButtons, int numRows, const char *labels[], const char *tips[], bool equalSized, bool rounded, const char *caption, const char *fallback, const char *name, Qt::WFlags fl)

This alternate constructor includes numRows to specify the number of rows, and rounded to indicate that the style has rounded buttons.  Other items are as above.

void DialogFrame::changeEvent(QEvent *e)

A virtual protected function that maintains the size of the buttons upon font change.  If the inheriting class reimplements this, it should first update the mRoundedStyle variable, then call DialogFrame::changeEvent(e), then set its font-dependent sizes

MultiSlider class

MultiSlider::MultiSlider(QWidget *parent, int numSliders, const char *titles[], int minVal, int maxVal, int decimals, bool horizontal)

This class provides an arbitrary number of horizontal sliders, each with a label and an integer numeric output that is managed as the slider is dragged.  The number of sliders is set in numSliders, their text labels in titles.  Overall minimal and maximum values and number of decimal places can be set with minVal (default 0), maxVal (default 255), and decimals (default 0).  The page step and single step size of each slider is set to 1.  Set horizontal flag to true to have the sliders arranged in a QHBoxLayout instead of a QVBoxLayout.  The layout can be obtained with:
   QBoxLayout *getLayout();
As a slider value changes, the class emits a signal:
   void sliderChanged(int slider, int value, bool dragging);
with slider equal to the slider number, value with the new integer value, and dragging true if the slider is being dragged.

void MultiSlider::setDecimals(int slider, int decimals)

Sets the number of decimals to display for the given slider number to decimals.

void MultiSlider::setValue(int slider, int value)

Sets the value of the given slider to value with signals blocked.

void MultiSlider::setRange(int slider, int minVal, int maxVal)

Sets the range of the given slider to minVal, maxVal with signals blocked.

void MultiSlider::setMinMaxVal(int slider, int minVal, int maxVal, int value)

Sets the range of the given slider to minVal, maxVal and the value to value with signals blocked, thus avoiding any signals from an existing value being outside of a new range.

QSlider *MultiSlider::getSlider(int slider)

Returns a pointer to the given slider, or NULL if the value is out of range.

void MultiSlider::setEnabled(int slider, bool enabled)

Sets the enable state of given slider and its associated text fields to enabled.

void MultiSlider::showWidgets(int slider, bool show)

Shows or hides a given slider and its associated text fields depending on the value of show.

ToolEdit class

ToolEdit::ToolEdit( QWidget * parent, int columns, const char * name)

A line edit widget that sends a signal, focusLost(), when it loses input focus, and that can be set to fixed column width by providing the number of characters in columns.  columns defaults to 0.  name is ignored. Use the signal editingFinished() instead of focusLost() and returnPressed().

void ToolEdit::setColumnWidth(int columns)

Set the edit box to fit the number of characters in columns, or resize it to fit a previously specified number if columns is zero

Functions in dia_qtutils.cpp

QPushButton *diaPushButton(const char *text, QWidget *parent, QBoxLayout *layout)

Makes a new push button with the given text, adds it to layout if it is non-NULL, and sets it for no focus.  layout can be a QHBoxLayout or a QVBoxLayout.

QCheckBox *diaCheckBox(const char *text, QWidget *parent, QBoxLayout *layout)

Makes a new check box with the given text, adds it to layout if it is non-NULL, and sets it for no focus.  layout can be a QHBoxLayout or a QVBoxLayout.

QRadioButton *diaRadioButton(const char *label, QWidget *parent, QButtonGroup *group, QBoxLayout *layout, int id, const char *tooltip)

Makes a new radio button with the give text and with the given parent (which can be NULL), adds it to the button group group with button ID id if group is non-NULL, adds it to layout if it is non-NULL, sets it for no focus, and sets tooltip as the tooltip if it is non-NULL.  layout can be a QHBoxLayout or a QVBoxLayout.

QLabel *diaLabel(const char *text, QWidget *parent, QBoxLayout *layout)

Makes a new label with the given text and adds it to layout if it is non-NULL. layout can be a QHBoxLayout or a QVBoxLayout.

QAbstractSpinBox *diaLabeledSpin(int nDecimal, float minValue, float maxValue, float step, const char *text, QWidget *parent, QBoxLayout *layout, QLabel **labelPtr)

Makes a labeled spin box, with the label given by text to the left of the box and right aligned to it, provided that layout is a horizontal layout box in which to place them.  (In a toolbar, layout can be NULL.) minValue, maxValue, and step are the  minimum, maximum, and step sizes for the spin box.  If nDecimal is non-zero, it creates and returns a QDoubleSpinBox with that number of decimal places.  It skips the label if text is NULL.  The focus policy is set to ClickFocus.  Keyboard tracking is turned off.  If a pointer is supplied in the optional argument labelPtr (which is NULL by default), it is returned with the label pointer.

QVBoxLayout *diaVBoxLayout(QBoxLayout *layout)

Creates a QVBoxLayout and adds it to layout, replacing the very useful Qt 3 constructor.

QHBoxLayout *diaHBoxLayout(QBoxLayout *layout)

Creates a QHBoxLayout and adds it to layout

QSlider *diaSlider(int min, int max, int step, int value, QWidget *parent, QBoxLayout *layout)

Creates and returns a new horizontal slider with range from min to max, value value and single step size step, adds it to layout if it is not NULL, and sets it for no focus.  The page step and single step are both set to 1.

void diaSetChecked(QAbstractButton *button, bool state)

Sets a checkbox or checkable toolbutton button to state with signals blocked

void diaSetSlider(QSlider *slider, int value)

Sets slider to value with signals blocked

void diaSetSpinBox(QSpinBox *box, int value)

Sets a spin box box to value with signals blocked

void diaSetDoubleSpinBox(QDoubleSpinBox *box, double value)

Sets a double spin box box to value with signals blocked

void diaSetSpinMMVal(QSpinBox *box, int min, int max, int value)

Sets a spin box box to value and sets its minimum and maximum to min and max, with signals blocked

void diaSetGroup(QButtonGroup *group, int id)

Turns on button with ID id in button group group, with signals blocked. The ID must be explicitly assigned such as when adding the button to the group.

void diaSetEditText(QLineEdit *edit, const QString &text)

Sets a text edit edit to the given tex with signals blocked

void diaShowWidget(QWidget *widget, bool state)

Shows or hides widget depending on value of state.

int diaGetButtonWidth(QWidget *widget, bool rounded, float factor, const QString &text)

Determines a button width appropriate for the given text, multiplying by factor and adding height if rounded is true.

int diaSetButtonWidth(QPushButton *button, bool rounded, float factor, const QString &text)

Sets button to a fixed width of appropriate for the given text, multiplying by factor and adding height if rounded is true.  The width is returned to use in setting other buttons to the same width.

void diaMaximumWindowSize(int &width, int &height)

Gets the maximum window size in width and height, i.e., the desktop size minus assumed borders

void diaLimitWindowSize(int &width, int &height)

Limits width and height to the maximum window size

void diaLimitWindowPos(int neww, int newh, int &newdx, int &newdy)

Limits the position of a window with width neww, height newh, and desired position newdx, newdy, adjusting newdx and newdy so that the window should be fullyon the screen.  This is done differently for X11, Mac, and Windows.

void diaSetTitle(const char *title)

Sets the application title into the static variable Dia_title

int dia_puts(const char *message)

Puts up an application-model message box with the information string in message and an OK button

int dia_err(const char *message)

Puts up an application-modal message box with an error string in message message and an OK button

int dia_ask(const char *question)

Puts up an application-modal message box with the text in question and Yes and No buttons.  Returns 0 for no, 1 for yes.

int dia_ask_forever(const char *question)

Puts up an application-modal message box with the text in question and Yes, Yes Always, and No buttons.  Returns 0 for No, 1 for Yes, 2 for Yes Always.

int dia_choice(const char *question, const char *lab1, const char *lab2, const char *lab3)

Puts up an application-modal message box with the text in question and with up to three buttons, whose labels are in lab1, lab2, and lab3. Supply a NULL to omit a button.  Returns the number of the button pressed, numbered from 1.

int diaQInput(int *value, int low, int high, int decimal, const char *prompt)

Uses QInputDialog to get an integer or float value from the user.  The text should be in prompt; value provides a default or initial value and the new value is returned into this variable unless the user cancels.  The If decimal is 0 it sets up a spin box with low and high as its limits; otherwise it gets a float with the given number of decimal places, with low and high specifying scaled lower an upper limits. Returns 0 if the user cancels.

QString diaOpenFileName(QWidget *parent, const char *caption, int numFilters, const char *filters[])

Gets the name of a single existing file with a file chooser that will show caption in its title bar.  A set of numFilters filters can be given in filters; the first will be the default filter.  Returns an empty string if the user cancels.

void dia_vasmsg(const char *msg, ...)

Makes a scrolled text window with the text taken a set of character strings passed as variable arguments

void dia_smsg(const char **msg)

Makes a scrolled text window with the text taken from the array of character strings in msg