More work on message boxes.

This commit is contained in:
Martin Rotter 2014-01-22 17:12:57 +01:00
parent 56dd8c66d5
commit c763a62e06
2 changed files with 25 additions and 10 deletions

View File

@ -9,7 +9,20 @@
#include <QStyle>
#include <QApplication>
MessageBox::MessageBox() {
MessageBox::MessageBox(QWidget *parent) : QMessageBox(parent) {
}
MessageBox::~MessageBox() {
}
void MessageBox::setIcon(QMessageBox::Icon icon) {
// Determine correct status icon size.
int icon_size = qApp->style()->pixelMetric(QStyle::PM_MessageBoxIconSize,
0,
this);
// Setup status icon.
setIconPixmap(iconForStatus(icon).pixmap(icon_size,
icon_size));
}
void MessageBox::iconify(QDialogButtonBox *button_box) {
@ -63,21 +76,19 @@ QMessageBox::StandardButton MessageBox::show(QWidget *parent,
QMessageBox::StandardButtons buttons,
QMessageBox::StandardButton defaultButton) {
// Create and find needed components.
QMessageBox msg_box(parent);
MessageBox msg_box(parent);
QDialogButtonBox *button_box = msg_box.findChild<QDialogButtonBox*>();
// Initialize message box properties.
msg_box.setWindowTitle(title);
msg_box.setText(text);
msg_box.setIcon(icon);
msg_box.setStandardButtons(buttons);
msg_box.setDefaultButton(defaultButton);
iconify(button_box);
// Setup status icon.
int icon_size = qApp->style()->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, &msg_box);
msg_box.setIconPixmap(iconForStatus(icon).pixmap(icon_size,
icon_size));
// Display it.
if (msg_box.exec() == -1) {

View File

@ -5,12 +5,16 @@
#include <QDialogButtonBox>
class MessageBox {
private:
// Constructors and destructors.
explicit MessageBox();
class MessageBox : public QMessageBox {
Q_OBJECT
public:
// Constructors and destructors.
explicit MessageBox(QWidget *parent = 0);
virtual ~MessageBox();
void setIcon(Icon icon);
// TODO: tudle metodu udelat private a udelat public
// metody information, warning atd a ty budou tudle volat
// se spravnejma parametrama