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 <QStyle>
#include <QApplication> #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) { void MessageBox::iconify(QDialogButtonBox *button_box) {
@ -63,21 +76,19 @@ QMessageBox::StandardButton MessageBox::show(QWidget *parent,
QMessageBox::StandardButtons buttons, QMessageBox::StandardButtons buttons,
QMessageBox::StandardButton defaultButton) { QMessageBox::StandardButton defaultButton) {
// Create and find needed components. // Create and find needed components.
QMessageBox msg_box(parent); MessageBox msg_box(parent);
QDialogButtonBox *button_box = msg_box.findChild<QDialogButtonBox*>(); QDialogButtonBox *button_box = msg_box.findChild<QDialogButtonBox*>();
// Initialize message box properties. // Initialize message box properties.
msg_box.setWindowTitle(title); msg_box.setWindowTitle(title);
msg_box.setText(text); msg_box.setText(text);
msg_box.setIcon(icon);
msg_box.setStandardButtons(buttons); msg_box.setStandardButtons(buttons);
msg_box.setDefaultButton(defaultButton); msg_box.setDefaultButton(defaultButton);
iconify(button_box); 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. // Display it.
if (msg_box.exec() == -1) { if (msg_box.exec() == -1) {

View File

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