12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #ifndef TIMEWIDGET_H
- #define TIMEWIDGET_H
- /**
- * 使用说明
- * 1、这个时间选择器支持两种方式
- * * 提升QTimeEdit,作为编辑栏修改时间
- * * 以弹窗的方式出现
- * 2、时间选择区域m_wdgTimeArea和时间编辑栏(在UI中)不是统一的,时间选择区域可以点击时间编辑栏
- * 创建出来,也可以在弹窗中直接显示出来,所以moveEvent事件就是用来移动m_wdgTimeArea的。
- * 3、在原来的基础上新添加了两个信号,在关闭的时候发送
- * 4、使用Dialog模式的时候,点击空白处隐藏就会close掉,然后发送新的时间信号
- * 5、使用Dialog模式,记得要调用showTimeEditArea()函数才会显示
- */
- #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);
- ~TimeWidget();
- void CreateTimeVector(const QVector<int>& types);
- void ClearVector(QVector<TimePartWidget*>& vec);
- // 在父窗口无法容纳控件时,这是必要的
- void SetMainWindow(QWidget* pWidget);
- QString getTime();
- 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();
- signals:
- void signal_nowTime(const QTime& time);
- void signal_formerTimer(const QTime& time);
- 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();
- 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
|