| 1 |
#ifndef WIDGETS_BUTTONOVERLAY_H |
| 2 |
#define WIDGETS_BUTTONOVERLAY_H |
| 3 |
|
| 4 |
#include "../global.h" |
| 5 |
|
| 6 |
#include <QtGlobal> |
| 7 |
|
| 8 |
QT_FORWARD_DECLARE_CLASS(QAction) |
| 9 |
QT_FORWARD_DECLARE_CLASS(QWidget) |
| 10 |
QT_FORWARD_DECLARE_CLASS(QHBoxLayout) |
| 11 |
QT_FORWARD_DECLARE_CLASS(QString) |
| 12 |
QT_FORWARD_DECLARE_CLASS(QPixmap) |
| 13 |
QT_FORWARD_DECLARE_CLASS(QMargins) |
| 14 |
QT_FORWARD_DECLARE_CLASS(QRect) |
| 15 |
QT_FORWARD_DECLARE_CLASS(QLineEdit) |
| 16 |
|
| 17 |
namespace QtUtilities { |
| 18 |
|
| 19 |
class IconButton; |
| 20 |
class ClearComboBox; |
| 21 |
class ClearSpinBox; |
| 22 |
class ClearPlainTextEdit; |
| 23 |
class ClearLineEdit; |
| 24 |
|
| 25 |
class QT_UTILITIES_EXPORT ButtonOverlay { |
| 26 |
|
| 27 |
friend class ClearComboBox; |
| 28 |
friend class ClearSpinBox; |
| 29 |
friend class ClearPlainTextEdit; |
| 30 |
friend class ClearLineEdit; |
| 31 |
|
| 32 |
public: |
| 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 |
|
| 52 |
protected: |
| 53 |
void updateClearButtonVisibility(bool visible); |
| 54 |
virtual void handleClearButtonClicked(); |
| 55 |
virtual void handleCustomLayoutCreated(); |
| 56 |
|
| 57 |
private: |
| 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 |
} |
| 71 |
|
| 72 |
#endif |