maxLibQt
ScrollableMessageBox.h
Go to the documentation of this file.
1 /*
2  ScrollableMessageBox
3  https://github.com/mpaperno/maxLibQt
4 
5  COPYRIGHT: (c)2017 Maxim Paperno; All Right Reserved.
6  Contact: http://www.WorldDesign.com/contact
7 
8  LICENSE:
9 
10  Commercial License Usage
11  Licensees holding valid commercial licenses may use this file in
12  accordance with the terms contained in a written agreement between
13  you and the copyright holder.
14 
15  GNU General Public License Usage
16  Alternatively, this file may be used under the terms of the GNU
17  General Public License as published by the Free Software Foundation,
18  either version 3 of the License, or (at your option) any later version.
19 
20  This program is distributed in the hope that it will be useful,
21  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  GNU General Public License for more details.
24 
25  A copy of the GNU General Public License is available at <http://www.gnu.org/licenses/>.
26 */
27 
28 #ifndef SCROLLABLEESSAGEBOX_H
29 #define SCROLLABLEESSAGEBOX_H
30 
31 #include <QDialog>
32 #include <QDialogButtonBox>
33 #include <QIcon>
34 #include <QLabel>
35 #include <QMessageBox>
36 #include <QPointer>
37 #include <QPushButton>
38 #include <QTextEdit>
39 
86 {
87  Q_OBJECT
88 
89  public:
90  enum CustomButton {
91  // First QDialogButtonBox::StandardButton enum value starts at 0x400
92  ShowDetails = 0x01
93  };
94 
96  explicit ScrollableMessageBox(const QString &title, const QString &text = QString(), const QString &details = QString(), QWidget *parent = nullptr, Qt::WindowFlags f = Qt::Dialog);
98  explicit ScrollableMessageBox(const QString &title, QMessageBox::Icon icon, const QString &text, const QString &details = QString(), QWidget *parent = nullptr, Qt::WindowFlags f = Qt::Dialog);
102  explicit ScrollableMessageBox(QWidget *parent, const QString &title, const QString &text, const QString &details,
103  int buttons, int defaultButtton = QDialogButtonBox::NoButton, Qt::WindowFlags f = Qt::Dialog);
107  explicit ScrollableMessageBox(QWidget *parent, const QString &title, QMessageBox::Icon icon, const QString &text, const QString &details,
108  int buttons, int defaultButtton = QDialogButtonBox::NoButton, Qt::WindowFlags f = Qt::Dialog);
109 
111  inline QTextEdit *textEdit() const { return m_textEdit.data(); }
113  inline QLabel *textLabel() const { return m_textLabel.data(); }
115  inline QLabel *iconLabel() const { return m_iconLabel.data(); }
117  inline QDialogButtonBox *buttonBox() const { return m_btnBox.data(); }
119  QLabel *promptLabel();
120 
122  bool detailsExpanded() const;
124  bool detailsButtonVisible() const;
125 
126  public slots:
128  void setText(const QString &text = QString());
130  void setDetailedText(const QString &details = QString(), Qt::TextFormat format = Qt::AutoText);
132  void setPromptText(const QString &text = QString());
133 
135  void setIcon(const QPixmap &pixmap = QPixmap());
138  void setIcon(QMessageBox::Icon icon, const QSize &size = QSize());
141  void setIcon(const QIcon &icon, const QSize &size = QSize());
144  void setIconAlignment(Qt::AlignmentFlag valign);
145 
147  void setFontFixedWidth(bool fixed = true);
149  void setWordWrap(bool wrap = true);
151  void setTextWordWrap(bool wrap = true);
152 
154  bool showDetailsExpanded(bool on = true);
156  bool toggleDetailsExpanded();
157 
162  void setDetailsButtonVisible(bool visible = true, bool toggleDetails = true, bool toggleDetailPosition = true);
163 
167  void setShowDetailsBelowButtons(bool on = true);
168 
171  void updateSize();
172 
173  protected:
174  void showEvent(QShowEvent *e) override;
175 
176  private:
177  void init(const QString &title = QString(), const QString &text = QString(), const QString &details = QString(),
179 
180  QPointer<QLabel> m_textLabel = nullptr;
181  QPointer<QLabel> m_iconLabel = nullptr;
182  QPointer<QLabel> m_promptLabel = nullptr;
183  QPointer<QTextEdit> m_textEdit = nullptr;
184  QPointer<QDialogButtonBox> m_btnBox = nullptr;
185  QPointer<QPushButton> m_detailsBtn = nullptr;
186  bool m_updatesSuspended = true;
187 
188 };
189 
190 #endif // SCROLLABLEESSAGEBOX_H
T * data() const const
void setDetailedText(const QString &details=QString(), Qt::TextFormat format=Qt::AutoText)
Set the longer details text shown in the scrollable message pane area.
TextFormat
A "Show Details" button which toggles the details text on and off (defined with QDialogButtonBox::Act...
QLabel * textLabel() const
The QLabel which holds the text. It is recommended to use setText() instead of setting the label text...
QDialogButtonBox * buttonBox() const
The dialog's button box. Buttons could be added/removed directly, and its signals can be connected to...
void setWordWrap(bool wrap=true)
Enable or disable word wrapping for the detailed text display.
void setIcon(const QPixmap &pixmap=QPixmap())
Set the image displayed next to the message box text label to pixmap. An invalid pixmap value will re...
AlignmentFlag
bool showDetailsExpanded(bool on=true)
Sets the details text visibility to on.
QLabel * iconLabel() const
The QLabel which holds the icon. It is recommended to use setIcon() instead of setting the pixmap dir...
A simple message box with a large scrollable area (a QTextEdit ) for detailed text (including HTML fo...
void setFontFixedWidth(bool fixed=true)
Changes the font used to display the detailed text to a fixed-width or a proportional font based on f...
QSize size() const const
QTextEdit * textEdit() const
The QTextEdit which holds the detailed text. It is recommended to use setDetailedText() instead of se...
ScrollableMessageBox(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::Dialog)
void setIconAlignment(Qt::AlignmentFlag valign)
Set the vertical alignment of the icon to valign.
void setPromptText(const QString &text=QString())
Set a message to be shown just above the dialog button(s), below the details text.
void setText(const QString &text=QString())
Set the text shown at the top of the dialog, before the details text.
void updateSize()
Recalculates the dialog minimum size after UI element changes like adding/removing buttons.
void setDetailsButtonVisible(bool visible=true, bool toggleDetails=true, bool toggleDetailPosition=true)
Enables or disables showing a "show details" button which toggles visibility of the details text.
void setShowDetailsBelowButtons(bool on=true)
Toggles where the details text is displayed.
void showEvent(QShowEvent *e) override
QObject * parent() const const
QLabel * promptLabel()
The QLabel which holds a prompt shown just above the buttons. This is created lazily if needed.
bool toggleDetailsExpanded()
Shows the details text if it is currently hidden, and hides it otherwise.
typedef WindowFlags
bool detailsButtonVisible() const
Returns true if the "show details" button is shown, false otherwise.
void setTextWordWrap(bool wrap=true)
Enable or disable word wrapping for the text message (shorthand for textLabel()->setWordWrap(wrap) ).
bool detailsExpanded() const
Returns true if the details text is currently visible, false otherwise.