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( 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, WFlags fl)
DialogFrame::DialogFrame(QWidget *parent, int numButtons, char *labels[],
char *tips[],
bool equalSized, char *caption, char *fallback,
const char *name, WFlags fl)
DialogFrame::DialogFrame(QWidget *parent, int numButtons, int numRows,
char *labels[], char *tips[], bool equalSized,
bool rounded, char *caption, char *fallback,
const char *name, WFlags fl)
void DialogFrame::fontChange(const QFont &oldFont)
FloatSpinBox::FloatSpinBox( int nDecimal, int minValue, int maxValue,
int step, QWidget * parent, const char * name)
MultiSlider::MultiSlider(QWidget *parent, int numSliders, 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)
QSlider *MultiSlider::getSlider(int slider)
ToolEdit::ToolEdit( QWidget * parent, int columns, const char * name)
Functions in dia_qtutils.cpp
QPushButton *diaPushButton(char *text, QWidget *parent, QBoxLayout *layout)
QCheckBox *diaCheckBox(char *text, QWidget *parent, QBoxLayout *layout)
QRadioButton *diaRadioButton(char *text, QWidget *parent)
QLabel *diaLabel(char *text, QWidget *parent, QBoxLayout *layout)
QSpinBox *diaLabeledSpin(int nDecimal, int minValue, int maxValue, int step,
char *text, QWidget *parent, QBoxLayout *layout)
void diaSetChecked(QCheckBox *button, bool state)
void diaSetSlider(QSlider *slider, int value)
void diaSetSpinBox(QSpinBox *box, int value)
void diaSetSpinMMVal(QSpinBox *box, int min, int max, int value)
void diaSetGroup(QButtonGroup *group, int value)
void diaSetEditText(QLineEdit *edit, const QString &text)
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(char *title)
int dia_puts(char *message)
int dia_err(char *message)
int dia_ask(char *question)
int dia_ask_forever(char *question)
int dia_choice(char *question, char *lab1, char *lab2, char *lab3)
int diaQInput(int *value, int low, int high, int decimal, char *prompt)
QString diaOpenFileName(QWidget *parent, char *caption, int numFilters,
char *filters[])
void dia_vasmsg(char *msg, ...)
void dia_smsg( char **msg)
ArrowButton class
ArrowButton::ArrowButton ( ArrowType type, QWidget * parent,
const char * name)
A toolbutton with an arrow icon. type should be one of Qt::UpArrow,
Qt::DownArrow, Qt::LeftArrow, Qt::RightArrow. name defaults to 0.
ColorSelector class
ColorSelector::ColorSelector(QWidget *parent, QString label, int red,
int green, int blue, int hotFlag, int hotKey,
bool rounded, const char *name, 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, char *labels[],
char *tips[],
bool equalSized, char *caption, char *fallback,
const char *name, 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::WDestructiveClose | Qt::WType_TopLevel.
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,
char *labels[], char *tips[], bool equalSized,
bool rounded, char *caption, char *fallback,
const char *name, 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::fontChange(const QFont &oldFont)
A virtual protected function that maintains the size of the buttons upon
font change. Note that the class has a non-virtual setFontDependentWidths
member function so a different name would be needed in the inheriting class.
FloatSpinBox class
FloatSpinBox::FloatSpinBox( int nDecimal, int minValue, int maxValue,
int step, QWidget * parent, const char * name)
A float spin box class: specify number of decimal places in nDecimal,
and minValue, maxValue, and step in the integer units of the
underlying spin box. step defaults to 10, parent and name to NULL.
MultiSlider class
MultiSlider::MultiSlider(QWidget *parent, int numSliders, 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). 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.
QSlider *MultiSlider::getSlider(int slider)
Returns a pointer to the given slider, or NULL if the value is out of range.
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. name and columns default to 0.
Functions in dia_qtutils.cpp
QPushButton *diaPushButton(char *text, QWidget *parent, QBoxLayout *layout)
Makes a new push button with the given text, adds it to layout, and
sets it for no focus
QCheckBox *diaCheckBox(char *text, QWidget *parent, QBoxLayout *layout)
Makes a new check box with the given text, adds it to layout, and sets
it for no focus
QRadioButton *diaRadioButton(char *text, QWidget *parent)
Makes a new radio button with the given text and sets it for no focus
QLabel *diaLabel(char *text, QWidget *parent, QBoxLayout *layout)
Makes a new label with the given text and adds it to layout
QSpinBox *diaLabeledSpin(int nDecimal, int minValue, int maxValue, int step,
char *text, QWidget *parent, QBoxLayout *layout)
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. 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 FloatSpinBox with that number of decimal
places.
void diaSetChecked(QCheckBox *button, bool state)
Sets a checkbox 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 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 value)
Sets a button group group to value with signals blocked
void diaSetEditText(QLineEdit *edit, const QString &text)
Sets a text edit edit to the given tex with signals blocked
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(char *title)
Sets the application title into the static variable Dia_title
int dia_puts(char *message)
Puts up an application-model message box with the information string in
message and an OK button
int dia_err(char *message)
Puts up an application-modal message box with an error string in message
message and an OK button
int dia_ask(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(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(char *question, char *lab1, char *lab2, 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, 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, char *caption, int numFilters,
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(char *msg, ...)
Makes a scrolled text window with the text taken a set of character strings
passed as variable arguments
void dia_smsg( char **msg)
Makes a scrolled text window with the text taken from the array of
character strings in msg