Qt Utilities: widgets/buttonoverlay.h Source File

Qt Utilities 6.22.0 Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models

Loading...
Searching...
No Matches
buttonoverlay.h
Go to the documentation of this file.
1#ifndef WIDGETS_BUTTONOVERLAY_H
2#define WIDGETS_BUTTONOVERLAY_H
3
4#include "../global.h"
5
6#include <QtGlobal>
7
8QT_FORWARD_DECLARE_CLASS(QAction)
9QT_FORWARD_DECLARE_CLASS(QWidget)
10QT_FORWARD_DECLARE_CLASS(QHBoxLayout)
11QT_FORWARD_DECLARE_CLASS(QString)
12QT_FORWARD_DECLARE_CLASS(QPixmap)
13QT_FORWARD_DECLARE_CLASS(QMargins)
14QT_FORWARD_DECLARE_CLASS(QRect)
15QT_FORWARD_DECLARE_CLASS(QLineEdit)
16
17namespace QtUtilities {
18
19class IconButton;
20class ClearComboBox;
21class ClearSpinBox;
22class ClearPlainTextEdit;
23class ClearLineEdit;
24
25 class QT_UTILITIES_EXPORT ButtonOverlay {
26 // allow these derived classes to use private helpers provided by ButtonOverlay
27 friend class ClearComboBox;
28 friend class ClearSpinBox;
29 friend class ClearPlainTextEdit;
30 friend class ClearLineEdit;
31
32public:
33 explicit ButtonOverlay(QWidget *widget);
34 explicit ButtonOverlay(QWidget *widget, QLineEdit *lineEdit);
35 virtual ~ButtonOverlay();
36
37 bool isUsingCustomLayout() const;
38 QHBoxLayout *buttonLayout();
39 bool isClearButtonEnabled() const;
40 void setClearButtonEnabled(bool enabled);
41 bool isInfoButtonEnabled() const;
42 void enableInfoButton(const QPixmap &pixmap, const QString &infoText);
43 void disableInfoButton();
44 void addCustomButton(QWidget *button);
45 void insertCustomButton(int index, QWidget *button);
46 void removeCustomButton(QWidget *button);
47 void addCustomAction(QAction *action);
48 void insertCustomAction(int index, QAction *action);
49 void removeCustomAction(QAction *action);
50 virtual bool isCleared() const;
51
52protected:
53 void updateClearButtonVisibility(bool visible);
54 virtual void handleClearButtonClicked();
55 virtual void handleCustomLayoutCreated();
56
57private:
58 void fallbackToUsingCustomLayout();
59 QLineEdit *lineEditForWidget() const;
60 void showInfo();
61 void setContentsMarginsFromEditFieldRectAndFrameWidth(const QRect &editFieldRect, int frameWidth, int padding = 0);
62
63 QWidget *m_widget;
64 QWidget *m_buttonWidget;
65 QHBoxLayout *m_buttonLayout;
66 IconButton *m_clearButton;
67 void *m_infoButtonOrAction;
68};
69
70} // namespace QtUtilities
71
72#endif // WIDGETS_BUTTONOVERLAY_H
QtUtilities::ButtonOverlay::isCleared
virtual bool isCleared() const
Returns whether the related widget is cleared.
Definition buttonoverlay.cpp:377
QtUtilities::ButtonOverlay::updateClearButtonVisibility
void updateClearButtonVisibility(bool visible)
Updates the visibility of the clear button.
Definition buttonoverlay.cpp:283
QtUtilities::ButtonOverlay::buttonLayout
QHBoxLayout * buttonLayout()
Returns the layout manager holding the buttons.
Definition buttonoverlay.cpp:97
QtUtilities::ButtonOverlay::ClearComboBox
friend class ClearComboBox
Definition buttonoverlay.h:27
QtUtilities::ButtonOverlay::handleCustomLayoutCreated
virtual void handleCustomLayoutCreated()
Applies additional handling when the button layout has been created.
Definition buttonoverlay.cpp:305
QtUtilities::ButtonOverlay::ButtonOverlay
ButtonOverlay(QWidget *widget)
Constructs a button overlay for the specified widget.
Definition buttonoverlay.cpp:49
QtUtilities::ButtonOverlay::insertCustomAction
void insertCustomAction(int index, QAction *action)
Inserts a custom action at the specified index.
Definition buttonoverlay.cpp:256
QtUtilities::ButtonOverlay::isInfoButtonEnabled
bool isInfoButtonEnabled() const
Returns whether the info button is enabled.
Definition buttonoverlay.cpp:117
QtUtilities::ButtonOverlay::enableInfoButton
void enableInfoButton(const QPixmap &pixmap, const QString &infoText)
Shows an info button with the specified pixmap and infoText.
Definition buttonoverlay.cpp:157
QtUtilities::ButtonOverlay::removeCustomButton
void removeCustomButton(QWidget *button)
Removes the specified custom button; does nothing if button has not been added.
Definition buttonoverlay.cpp:234
QtUtilities::ButtonOverlay::isClearButtonEnabled
bool isClearButtonEnabled() const
Returns whether the clear button is enabled.
Definition buttonoverlay.cpp:106
QtUtilities::ButtonOverlay::ClearPlainTextEdit
friend class ClearPlainTextEdit
Definition buttonoverlay.h:29
QtUtilities::ButtonOverlay::handleClearButtonClicked
virtual void handleClearButtonClicked()
Clears the related widget.
Definition buttonoverlay.cpp:295
QtUtilities::ButtonOverlay::insertCustomButton
void insertCustomButton(int index, QWidget *button)
Inserts a custom button at the specified index.
Definition buttonoverlay.cpp:223
QtUtilities::ButtonOverlay::isUsingCustomLayout
bool isUsingCustomLayout() const
Returns whether the "custom approach" mentioned in the class documentation is used.
Definition buttonoverlay.cpp:87
QtUtilities::ButtonOverlay::addCustomButton
void addCustomButton(QWidget *button)
Adds a custom button.
Definition buttonoverlay.cpp:209
QtUtilities::ButtonOverlay::removeCustomAction
void removeCustomAction(QAction *action)
Removes the specified custom action; does nothing if action has not been added.
Definition buttonoverlay.cpp:269
QtUtilities::ButtonOverlay::disableInfoButton
void disableInfoButton()
Hides an info button if one is shown.
Definition buttonoverlay.cpp:185
QtUtilities::ButtonOverlay::addCustomAction
void addCustomAction(QAction *action)
Adds a custom action.
Definition buttonoverlay.cpp:244
QtUtilities::ButtonOverlay::ClearLineEdit
friend class ClearLineEdit
Definition buttonoverlay.h:30
QtUtilities::ButtonOverlay::setClearButtonEnabled
void setClearButtonEnabled(bool enabled)
Sets whether the clear button is enabled.
Definition buttonoverlay.cpp:125
QtUtilities::ButtonOverlay::ClearSpinBox
friend class ClearSpinBox
Definition buttonoverlay.h:28
QtUtilities::ClearComboBox
A QComboBox with an embedded button for clearing its contents.
Definition clearcombobox.h:10
QtUtilities::ClearLineEdit
A QLineEdit with an embedded button for clearing its contents.
Definition clearlineedit.h:14
QtUtilities::ClearPlainTextEdit
A QPlainTextEdit with an embedded button for clearing its contents.
Definition clearplaintextedit.h:10
QtUtilities::ClearSpinBox
A QSpinBox with an embedded button for clearing its contents and the ability to hide the minimum valu...
Definition clearspinbox.h:15
QtUtilities::IconButton
A simple QAbstractButton implementation displaying a QPixmap.
Definition iconbutton.h:15
global.h
QT_UTILITIES_EXPORT
#define QT_UTILITIES_EXPORT
Marks the symbol to be exported by the qtutilities library.
Definition global.h:14
QtUtilities
!
Definition trylocker.h:8