123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- #ifndef TIMEWIDGET_H
- #define TIMEWIDGET_H
- /**
- * 使用说明
- * 1、这个时间选择器支持两种方式
- * * 提升QTimeEdit,作为编辑栏修改时间
- * * 以弹窗的方式出现
- * 2、时间选择区域m_wdgTimeArea和时间编辑栏(在UI中)不是统一的,时间选择区域可以点击时间编辑栏
- * 创建出来,也可以在弹窗中直接显示出来,所以moveEvent事件就是用来移动m_wdgTimeArea的。
- * 3、在原来的基础上新添加了两个信号,在关闭的时候发送
- * 4、使用Dialog模式的时候,点击空白处隐藏就会close掉,然后发送新的时间信号
- * 5、使用Dialog模式,执行execShow()函数,会阻塞运行,直到关闭
- */
- #include <QFrame>
- #include <QTime>
- class TimePartWidget;
- class QListWidgetItem;
- class ShadowWidget;
- namespace Ui {
- class TimeWidget;
- }
- /* 添加ShowType类型,判断这个控件是编辑栏还是弹窗 */
- class TimeWidget : public QFrame
- {
- Q_OBJECT
- public:
- enum ShowType{
- EditLine = 0, /* 时间编辑栏 */
- Dialog = 1, /* 以弹窗的形式出现 */
- };
- explicit TimeWidget(QWidget *parent = nullptr , ShowType type = EditLine);
- explicit TimeWidget(ShowType type = EditLine);
- ~TimeWidget();
- void CreateTimeVector(const QVector<int>& types);
- void ClearVector(QVector<TimePartWidget*>& vec);
- // 在父窗口无法容纳控件时,这是必要的
- void SetMainWindow(QWidget* pWidget);
- QTime getTime();
- QString getTimeStr();
- QTime getFormTime() const;
- void setTime(const QString& t);
- void setTime(const QTime& t);
- void clearTime();
- QString tipText() const;
- /* 新增一个设置时间条宽度的函数 */
- void setTimeAreaWidth(int w);
- /***** 2024-05-25 添加两个信号 ******/
- void showTimeEditArea();
- /* 以弹窗的模式模态显示 */
- void execShow();
- /* 设置时间图标 */
- void setIcon(const QString& icon);
- /* 设置图标显示 */
- void setIconShow(bool isShow);
- /* 设置图标大小 */
- void setIconSize(int w, int h);
- /* 设置默认的样式 */
- void setDefaultStyle();
- /* 设置编辑栏大小 */
- void setEditLine(int w, int h);
- /* 设置QSS */
- void setQSS();
- signals:
- void signal_nowTime(const QTime& time);
- void signal_formerTimer(const QTime& time);
- void signal_close();
- protected:
- bool eventFilter(QObject* obj, QEvent* e) override;
- void moveEvent(QMoveEvent *event) override;
- private slots:
- void onBtnTipClicked();
- void onListItemClicked(QListWidgetItem* item);
- void onDateTimeChanged(const QDateTime& dt);
- private:
- void UpdateProperty(QObject* obj, const char* name, bool flag);
- void UpdatePopupTime(const QDateTime& dt);
- void ShowTimeArea(bool bShow);
- void CreatePopupWidget();
- /* 初始化函数 */
- void Init();
- private:
- const int TIME_AREA_WIDTH = 56;
- const int TIME_AREA_HEIGHT = 32;
- const int SHADOW_MARGIN = 9; // 对应BlurRadius模糊半径16px
- Ui::TimeWidget *ui;
- QVector<TimePartWidget*> m_vecTimePart;
- QVector<int> m_vecTimeSections;
- bool m_bTimeFlag{false}; // 时间更新标志
- QScopedPointer<ShadowWidget> m_wdgTimeArea; // 时间选择窗口
- QWidget* m_pMainWindow; // 外层祖辈窗口,能容纳时间控件高度即可(默认父窗口)
- ShowType m_type; /* 显示类型 */
- int m_width = 0; /* TimeArea宽度 */
- };
- #endif // TIMEWIDGET_H
|