1 /* 2 For general Scribus (>=1.3.2) copyright and licensing information please refer 3 to the COPYING file provided with the program. Following this notice may exist 4 a copyright and/or license notice that predates the release of Scribus 1.3.2 5 for which a new license (GPL+exception) is in place. 6 */ 7 /*************************************************************************** 8 begin : Oct 2005 9 copyright : (C) 2005 by Craig Bradney 10 email : cbradney@zip.com.au 11 ***************************************************************************/ 12 13 /*************************************************************************** 14 * * 15 * This program is free software; you can redistribute it and/or modify * 16 * it under the terms of the GNU General Public License as published by * 17 * the Free Software Foundation; either version 2 of the License, or * 18 * (at your option) any later version. * 19 * * 20 ***************************************************************************/ 21 #ifndef SCMESSAGEBOX_H 22 #define SCMESSAGEBOX_H 23 24 #include <QMessageBox> 25 26 #include "scribusapi.h" 27 28 /** 29 * \brief This class provides alternate versions of QMessageBox functions 30 * that write to log files when Scribus does not have a GUI. 31 * This class is identical to QMessageBox except that provides an optional default batch button. 32 * In batch mode, functions return the default batch button when it is not NoButton, 33 * otherwise they return the default button when it is not NoButton, 34 * otherwise they return one of the standard buttons. 35 * If a dialog asks "Are you sure that you want to do this?", 36 * the default button can be No to keep users from accidentally destroying data, 37 * while the batch button can be Yes to allow scripts to do what they need. 38 * This class does not include QMessageBox functions marked obsolete in Qt5. 39 * Use non-obsolete functions instead. 40 */ 41 class SCRIBUS_API ScMessageBox : public QMessageBox 42 { 43 Q_OBJECT 44 45 public: 46 // Property-based API 47 ScMessageBox(QWidget *parent = nullptr); 48 ScMessageBox(QMessageBox::Icon icon, const QString &title, const QString &text, 49 QMessageBox::StandardButtons buttons = QMessageBox::NoButton, QWidget *parent = nullptr, 50 Qt::WindowFlags flags = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); 51 int exec(); 52 QAbstractButton *clickedButton() const; 53 void setDefaultBatchButton(QPushButton *button); 54 void setDefaultBatchButton(StandardButton button); 55 56 // Static function API 57 static QMessageBox::StandardButton information(QWidget *parent, const QString &title, const QString &text, 58 StandardButtons buttons = Ok, StandardButton defaultButton = NoButton, StandardButton defaultBatchButton = NoButton); 59 60 static QMessageBox::StandardButton question(QWidget *parent, const QString &title, const QString &text, 61 StandardButtons buttons = StandardButtons(Yes | No), StandardButton defaultButton = NoButton, StandardButton defaultBatchButton = NoButton); 62 63 static QMessageBox::StandardButton warning(QWidget *parent, const QString &title, const QString &text, 64 StandardButtons buttons = Ok, StandardButton defaultButton = NoButton, StandardButton defaultBatchButton = NoButton); 65 66 static QMessageBox::StandardButton critical(QWidget *parent, const QString &title, const QString &text, 67 StandardButtons buttons = Ok, StandardButton defaultButton = NoButton, StandardButton defaultBatchButton = NoButton); 68 69 static void about(QWidget *parent, const QString &title, const QString &text); 70 static void aboutQt(QWidget *parent, const QString &title = QString()); 71 72 private: 73 // Saved fields for the property-based API 74 QString messageTitle; 75 QPushButton *defaultBatchPushButton; 76 StandardButton defaultBatchStandardButton; 77 78 // Initialize private variables 79 void initScMessageBox(); 80 81 // Find the appropriate default button 82 static QMessageBox::StandardButton findDefaultButton(QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton, StandardButton defaultBatchButton); 83 }; 84 85 #endif 86