⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qmessagebox.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/******************************************************************************** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://www.trolltech.com/products/qt/opensource.html**** If you are unsure which license is appropriate for your use, please** review the following information:** http://www.trolltech.com/products/qt/licensing.html or contact the** sales department at sales@trolltech.com.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qglobal.h"#ifndef QT_NO_MESSAGEBOX#include "qmessagebox.h"#include "qbuffer.h"#include "qimagereader.h"#include "qevent.h"#include "qdesktopwidget.h"#include "qlabel.h"#include "qpushbutton.h"#include "qimage.h"#include "qapplication.h"#include "qcursor.h"#include "qicon.h"#include "qstyle.h"#include "qtextdocument.h"#ifndef QT_NO_ACCESSIBILITY#include "qaccessible.h"#endif#if defined QT_NON_COMMERCIAL#include "qnc_win.h"#endif#include "qdialog_p.h"class QMessageBoxPrivate : public QDialogPrivate{    Q_DECLARE_PUBLIC(QMessageBox)public:    QMessageBoxPrivate() {}    void _q_buttonClicked();    void init(int, int, int);    int indexOf(int) const;    QLabel *label;    int                 numButtons;             // number of buttons    QMessageBox::Icon   icon;                   // message box icon    QLabel              *iconLabel;              // label holding any icon    int                 button[3];              // button types    int                 defButton;              // default button (index)    int                 escButton;              // escape button (index)    QPushButton        *pb[3];                  // buttons};#ifndef QT_NO_IMAGEFORMAT_XPM/* XPM */static const char * const qtlogo_xpm[] = {/* width height ncolors chars_per_pixel */"50 50 17 1",/* colors */"  c #000000",". c #495808","X c #2A3304","o c #242B04","O c #030401","+ c #9EC011","@ c #93B310","# c #748E0C","$ c #A2C511","% c #8BA90E","& c #99BA10","* c #060701","= c #181D02","- c #212804","; c #61770A",": c #0B0D01","/ c None",/* pixels */"/$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$/","$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$","$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$","$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$","$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$","$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$","$$$$$$$$$$$$$$$$$$$$$$$+++$$$$$$$$$$$$$$$$$$$$$$$$","$$$$$$$$$$$$$$$$$$$@;.o=::=o.;@$$$$$$$$$$$$$$$$$$$","$$$$$$$$$$$$$$$$+#X*         **X#+$$$$$$$$$$$$$$$$","$$$$$$$$$$$$$$$#oO*         O  **o#+$$$$$$$$$$$$$$","$$$$$$$$$$$$$&.* OO              O*.&$$$$$$$$$$$$$","$$$$$$$$$$$$@XOO            * OO    X&$$$$$$$$$$$$","$$$$$$$$$$$@XO OO  O  **:::OOO OOO   X@$$$$$$$$$$$","$$$$$$$$$$&XO      O-;#@++@%.oOO      X&$$$$$$$$$$","$$$$$$$$$$.O  :  *-#+$$$$$$$$+#- : O O*.$$$$$$$$$$","$$$$$$$$$#*OO  O*.&$$$$$$$$$$$$+.OOOO **#$$$$$$$$$","$$$$$$$$+-OO O *;$$$$$$$$$$$&$$$$;*     o+$$$$$$$$","$$$$$$$$#O*  O .+$$$$$$$$$$@X;$$$+.O    *#$$$$$$$$","$$$$$$$$X*    -&$$$$$$$$$$@- :;$$$&-    OX$$$$$$$$","$$$$$$$@*O  *O#$$$$$$$$$$@oOO**;$$$#    O*%$$$$$$$","$$$$$$$;     -+$$$$$$$$$@o O OO ;+$$-O   *;$$$$$$$","$$$$$$$.     ;$$$$$$$$$@-OO OO  X&$$;O    .$$$$$$$","$$$$$$$o    *#$$$$$$$$@o  O O O-@$$$#O   *o$$$$$$$","$$$$$$+=    *@$$$$$$$@o* OO   -@$$$$&:    =$$$$$$$","$$$$$$+:    :+$$$$$$@-      *-@$$$$$$:    :+$$$$$$","$$$$$$+:    :+$$$$$@o* O    *-@$$$$$$:    :+$$$$$$","$$$$$$$=    :@$$$$@o*OOO      -@$$$$@:    =+$$$$$$","$$$$$$$-    O%$$$@o* O O    O O-@$$$#*   OX$$$$$$$","$$$$$$$. O *O;$$&o O*O* *O      -@$$;    O.$$$$$$$","$$$$$$$;*   Oo+$$;O*O:OO--      Oo@+=    *;$$$$$$$","$$$$$$$@*  O O#$$$;*OOOo@@-O     Oo;O*  **@$$$$$$$","$$$$$$$$X* OOO-+$$$;O o@$$@-    O O     OX$$$$$$$$","$$$$$$$$#*  * O.$$$$;X@$$$$@-O O        O#$$$$$$$$","$$$$$$$$+oO O OO.+$$+&$$$$$$@-O         o+$$$$$$$$","$$$$$$$$$#*    **.&$$$$$$$$$$@o      OO:#$$$$$$$$$","$$$$$$$$$+.   O* O-#+$$$$$$$$+;O    OOO:@$$$$$$$$$","$$$$$$$$$$&X  *O    -;#@++@#;=O    O    -@$$$$$$$$","$$$$$$$$$$$&X O     O*O::::O      OO    Oo@$$$$$$$","$$$$$$$$$$$$@XOO                  OO    O*X+$$$$$$","$$$$$$$$$$$$$&.*       **  O      ::    *:#$$$$$$$","$$$$$$$$$$$$$$$#o*OO       O    Oo#@-OOO=#$$$$$$$$","$$$$$$$$$$$$$$$$+#X:* *     O**X#+$$@-*:#$$$$$$$$$","$$$$$$$$$$$$$$$$$$$%;.o=::=o.#@$$$$$$@X#$$$$$$$$$$","$$$$$$$$$$$$$$$$$$$$$$$$+++$$$$$$$$$$$+$$$$$$$$$$$","$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$","$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$","$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$","$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$","$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$","/$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$/",};#endif // QT_NO_IMAGEFORMAT_XPM/*!    \class QMessageBox    \brief The QMessageBox class provides a modal dialog with a short message, an icon, and some buttons.    \ingroup dialogs    \mainclass    Message boxes are used to provide informative messages and to ask    simple questions.    QMessageBox provides a range of different messages, arranged    roughly along two axes: severity and complexity.    Severity is    \table    \row    \i \img qmessagebox-quest.png    \i Question    \i For message boxes that ask a question as part of normal    operation. Some style guides recommend using Information for this    purpose.    \row    \i \img qmessagebox-info.png    \i Information    \i For message boxes that are part of normal operation.    \row    \i \img qmessagebox-warn.png    \i Warning    \i For message boxes that tell the user about unusual errors.    \row    \i \img qmessagebox-crit.png    \i Critical    \i For message boxes that tell the user about critical errors.    \endtable    The message box has a different icon for each of the severity levels.    Complexity is one button (OK) for simple messages, or two or even    three buttons for questions.    There are static functions for the most common cases.    Examples:    If a program is unable to find a supporting file, but can do perfectly    well without it:    \code    QMessageBox::information(this, "Application name",    "Unable to find the user preferences file.\n"    "The factory default will be used instead.");    \endcode    question() is useful for simple yes/no questions:    \quotefromfile snippets/dialogs/dialogs.cpp    \skipto if (QFile::exists(filename) &&    \printuntil return false;    warning() can be used to tell the user about unusual errors, or    errors which can't be easily fixed:    \skipto switch(QMessageBox::warning(this, "Application name",    \printuntil }    The text part of all message box messages can be either rich text    or plain text. If you specify a rich text formatted string, it    will be rendered using the default stylesheet. See    QStyleSheet::defaultSheet() for details. With certain strings that    contain XML meta characters, the auto-rich text detection may    fail, interpreting plain text incorrectly as rich text. In these    rare cases, use QStyleSheet::convertFromPlainText() to convert    your plain text string to a visually equivalent rich text string    or set the text format explicitly with setTextFormat().    Note that the Microsoft Windows User Interface Guidelines    recommend using the application name as the window's caption.    Below are more examples of how to use the static member functions.    After these examples you will find an overview of the non-static    member functions.    Exiting a program is part of its normal operation. If there is    unsaved data the user probably should be asked if they want to    save the data. For example:    \skipto switch(QMessageBox::information(this, "Application name here",    \printuntil }    The Escape button cancels the entire exit operation, and pressing    Enter causes the changes to be saved before the exit occurs.    Disk full errors are unusual and they certainly can be hard to    correct. This example uses predefined buttons instead of    hard-coded button texts:    \skipto switch(QMessageBox::warning(this, "Application name here",    \printuntil }    The critical() function should be reserved for critical errors. In    this example errorDetails is a QString or const char*, and QString    is used to concatenate several strings:    \skipto QMessageBox::critical(0, "Application name here",    \printuntil "\n\nApplication will now exit.");    In this example an OK button is displayed.    QMessageBox provides a very simple About box which displays an    appropriate icon and the string you provide:    \skipto QMessageBox::about(this, "About <Application>",    \printuntil "http://www.such-and-such.com/Application/\n");    See about() for more information.    If you want your users to know that the application is built using    Qt (so they know that you use high quality tools) you might like    to add an "About Qt" menu option under the Help menu to invoke    aboutQt().    If none of the standard message boxes is suitable, you can create a    QMessageBox from scratch and use custom button texts:    \skipto QMessageBox mb("Application name here",    \printuntil }    QMessageBox defines two enum types: Icon and an unnamed button type.    Icon defines the \l Question, \l Information, \l Warning, and \l    Critical icons for each GUI style. It is used by the constructor    and by the static member functions question(), information(),    warning() and critical(). A function called standardIcon() gives    you access to the various icons.    The button types are:    \list    \i Ok - the default for single-button message boxes    \i Cancel - note that this is \e not automatically Escape    \i Yes    \i No    \i Abort    \i Retry    \i Ignore    \i YesAll    \i NoAll    \endlist    Button types can be combined with two modifiers by using OR, '|':    \list    \i Default - makes pressing Enter equivalent to    clicking this button. Normally used with Ok, Yes or similar.    \i Escape - makes pressing Escape equivalent to clicking this button.    Normally used with Abort, Cancel or similar.    \endlist    The text(), icon() and iconPixmap() functions provide access to the    current text and pixmap of the message box. The setText(), setIcon()    and setIconPixmap() let you change it. The difference between    setIcon() and setIconPixmap() is that the former accepts a    QMessageBox::Icon and can be used to set standard icons, whereas the    latter accepts a QPixmap and can be used to set custom icons.    setButtonText() and buttonText() provide access to the buttons.    QMessageBox has no signals or slots.    The \l{dialogs/standarddialogs}{Standard Dialogs} example shows    how to use QMessageBox as well as other built-in Qt dialogs.    \image plastique-messagebox.png A message box shown in the Plastique widget style.    \sa QDialog, {fowler}{GUI Design Handbook: Message Box}*//*!    \enum QMessageBox::Button    This enum describes the predefined buttons and button flags you can assign    to a QMessageBox.    \value Ok An "Ok" button.    \value Cancel A "Cancel" button.    \value Yes A "Yes" button.    \value No A "No" button.    \value Abort An "Abort" button.    \value Retry A "Retry" button.    \value Ignore An "Ignore" button.    \value YesAll A "Yes to all" button.    \value NoAll A "No to all" button.    The following values are flags that can be OR'ed with the button values.    \value Default The button is default (i.e., QPushButton::default).    \value Escape The button is activated by pressing the Escape key.    The following values are masks that can be used to separate buttons from    flags.    \value ButtonMask A bitmask that covers all button types.    \value FlagMask A bitmask that covers all button flags.    Finally, the last value is often used as a default value.    \value NoButton*//*!    \enum QMessageBox::Icon    This enum has the following values:    \value NoIcon the message box does not have any icon.    \value Question an icon indicating that    the message is asking a question.    \value Information an icon indicating that    the message is nothing out of the ordinary.    \value Warning an icon indicating that the    message is a warning, but can be dealt with.    \value Critical an icon indicating that    the message represents a critical problem.*/static const int LastButton = QMessageBox::NoAll;/*  NOTE: The table of button texts correspond to the button enum.*/#ifndef Q_OS_TEMPstatic const char * const mb_texts[] = {#elseconst char * mb_texts[] = {#endif    0,    QT_TRANSLATE_NOOP("QMessageBox","OK"),    QT_TRANSLATE_NOOP("QMessageBox","Cancel"),    QT_TRANSLATE_NOOP("QMessageBox","&Yes"),    QT_TRANSLATE_NOOP("QMessageBox","&No"),    QT_TRANSLATE_NOOP("QMessageBox","&Abort"),    QT_TRANSLATE_NOOP("QMessageBox","&Retry"),    QT_TRANSLATE_NOOP("QMessageBox","&Ignore"),    QT_TRANSLATE_NOOP("QMessageBox","Yes to &All"),    QT_TRANSLATE_NOOP("QMessageBox","N&o to All"),    0};/*!    Constructs a message box with no text and a button with the label    "OK".    If \a parent is 0, the message box becomes an application-global    modal dialog box. If \a parent is a widget, the message box    becomes modal relative to \a parent.    The \a parent argument is passed to the QDialog    constructor.*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -