timepartwidget.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef TIMEPARTWIDGET_H
  2. #define TIMEPARTWIDGET_H
  3. #include <QWidget>
  4. class MyTimeDelegate;
  5. class QListWidgetItem;
  6. class QScrollBar;
  7. namespace Ui {
  8. class TimePartWidget;
  9. }
  10. class TimePartWidget : public QWidget
  11. {
  12. Q_OBJECT
  13. public:
  14. enum emSection {
  15. HOUR = 0,
  16. MINUTE = 1,
  17. SECOND = 2,
  18. MAX_SECTION
  19. };
  20. public:
  21. explicit TimePartWidget(QWidget *parent = nullptr);
  22. TimePartWidget(emSection type, QWidget* parent = nullptr);
  23. ~TimePartWidget();
  24. emSection GetType() const {return m_type;}
  25. void SetTime(const QDateTime& dt);
  26. void SetMaxWidth(int w);
  27. void ScrollToSelect();
  28. protected:
  29. void enterEvent(QEvent* event) override;
  30. void leaveEvent(QEvent* event) override;
  31. signals:
  32. void sigItemClicked(QListWidgetItem* item);
  33. private:
  34. void InitListWidget(int total);
  35. void SelectListItem(int time);
  36. private:
  37. Ui::TimePartWidget *ui;
  38. emSection m_type;
  39. QScopedPointer<MyTimeDelegate> m_delegate;
  40. QScopedPointer<QScrollBar> m_pListBar;
  41. };
  42. #endif // TIMEPARTWIDGET_H