2016-04-09 02:33:09 +02:00
|
|
|
#ifndef WIDGETS_BUTTONOVERLAY_H
|
|
|
|
#define WIDGETS_BUTTONOVERLAY_H
|
2015-04-22 18:57:44 +02:00
|
|
|
|
2016-08-29 15:41:11 +02:00
|
|
|
#include "../global.h"
|
2015-04-22 18:57:44 +02:00
|
|
|
|
|
|
|
#include <QtGlobal>
|
|
|
|
|
2020-06-09 23:24:24 +02:00
|
|
|
QT_FORWARD_DECLARE_CLASS(QAction)
|
2016-04-09 02:33:09 +02:00
|
|
|
QT_FORWARD_DECLARE_CLASS(QWidget)
|
|
|
|
QT_FORWARD_DECLARE_CLASS(QHBoxLayout)
|
|
|
|
QT_FORWARD_DECLARE_CLASS(QString)
|
|
|
|
QT_FORWARD_DECLARE_CLASS(QPixmap)
|
2020-06-04 19:13:14 +02:00
|
|
|
QT_FORWARD_DECLARE_CLASS(QMargins)
|
|
|
|
QT_FORWARD_DECLARE_CLASS(QRect)
|
2020-06-09 22:03:26 +02:00
|
|
|
QT_FORWARD_DECLARE_CLASS(QLineEdit)
|
2015-04-22 18:57:44 +02:00
|
|
|
|
2019-06-10 21:57:46 +02:00
|
|
|
namespace QtUtilities {
|
2015-04-22 18:57:44 +02:00
|
|
|
|
|
|
|
class IconButton;
|
2020-06-04 19:13:14 +02:00
|
|
|
class ClearComboBox;
|
|
|
|
class ClearSpinBox;
|
|
|
|
class ClearPlainTextEdit;
|
|
|
|
class ClearLineEdit;
|
2015-04-22 18:57:44 +02:00
|
|
|
|
2017-05-01 03:16:25 +02:00
|
|
|
class QT_UTILITIES_EXPORT ButtonOverlay {
|
2020-06-04 19:13:14 +02:00
|
|
|
// allow these derived classes to use private helpers provided by ButtonOverlay
|
|
|
|
friend class ClearComboBox;
|
|
|
|
friend class ClearSpinBox;
|
|
|
|
friend class ClearPlainTextEdit;
|
|
|
|
friend class ClearLineEdit;
|
|
|
|
|
2015-04-22 18:57:44 +02:00
|
|
|
public:
|
|
|
|
explicit ButtonOverlay(QWidget *widget);
|
2020-06-09 22:03:26 +02:00
|
|
|
explicit ButtonOverlay(QWidget *widget, QLineEdit *lineEdit);
|
2015-04-22 18:57:44 +02:00
|
|
|
virtual ~ButtonOverlay();
|
|
|
|
|
2020-06-09 22:03:26 +02:00
|
|
|
bool isUsingCustomLayout() const;
|
2015-04-22 18:57:44 +02:00
|
|
|
QHBoxLayout *buttonLayout();
|
|
|
|
bool isClearButtonEnabled() const;
|
|
|
|
void setClearButtonEnabled(bool enabled);
|
|
|
|
bool isInfoButtonEnabled() const;
|
|
|
|
void enableInfoButton(const QPixmap &pixmap, const QString &infoText);
|
|
|
|
void disableInfoButton();
|
|
|
|
void addCustomButton(QWidget *button);
|
|
|
|
void insertCustomButton(int index, QWidget *button);
|
|
|
|
void removeCustomButton(QWidget *button);
|
2020-06-09 23:24:24 +02:00
|
|
|
void addCustomAction(QAction *action);
|
|
|
|
void insertCustomAction(int index, QAction *action);
|
|
|
|
void removeCustomAction(QAction *action);
|
2015-04-22 18:57:44 +02:00
|
|
|
virtual bool isCleared() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void updateClearButtonVisibility(bool visible);
|
|
|
|
virtual void handleClearButtonClicked();
|
2020-06-09 22:03:26 +02:00
|
|
|
virtual void handleCustomLayoutCreated();
|
2015-04-22 18:57:44 +02:00
|
|
|
|
2017-05-01 03:16:25 +02:00
|
|
|
private:
|
2020-06-09 22:03:26 +02:00
|
|
|
void fallbackToUsingCustomLayout();
|
|
|
|
QLineEdit *lineEditForWidget() const;
|
2015-04-22 18:57:44 +02:00
|
|
|
void showInfo();
|
2020-06-04 19:13:14 +02:00
|
|
|
void setContentsMarginsFromEditFieldRectAndFrameWidth(const QRect &editFieldRect, int frameWidth, int padding = 0);
|
2015-04-22 18:57:44 +02:00
|
|
|
|
|
|
|
QWidget *m_widget;
|
|
|
|
QWidget *m_buttonWidget;
|
|
|
|
QHBoxLayout *m_buttonLayout;
|
|
|
|
IconButton *m_clearButton;
|
2020-06-09 22:03:26 +02:00
|
|
|
void *m_infoButtonOrAction;
|
2015-04-22 18:57:44 +02:00
|
|
|
};
|
|
|
|
|
2019-06-10 21:57:46 +02:00
|
|
|
} // namespace QtUtilities
|
2015-04-22 18:57:44 +02:00
|
|
|
|
2016-04-09 02:33:09 +02:00
|
|
|
#endif // WIDGETS_BUTTONOVERLAY_H
|