LineEdit.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifndef LINEEDIT_H
  2. #define LINEEDIT_H
  3. #include <QHBoxLayout>
  4. #include <QLineEdit>
  5. #include <QPlainTextEdit>
  6. #include <QTextEdit>
  7. #include <QToolButton>
  8. #include "Common/Icon.h"
  9. class SmoothScroll;
  10. class LineEditButton : public QToolButton
  11. {
  12. Q_OBJECT
  13. public:
  14. LineEditButton(FluentIconBase *ficon, QWidget *parent = nullptr);
  15. void setIcon(FluentIconBase *ficon);
  16. FluentIconBase *ficon() const;
  17. QIcon icon() const;
  18. // QWidget interface
  19. protected:
  20. void paintEvent(QPaintEvent *event) override;
  21. private:
  22. QScopedPointer<FluentIconBase> m_ficon;
  23. };
  24. class LineEdit : public QLineEdit
  25. {
  26. Q_OBJECT
  27. public:
  28. explicit LineEdit(QWidget *parent = nullptr);
  29. bool isClearButtonEnabled() const;
  30. void setIsClearButtonEnabled(bool enable);
  31. QHBoxLayout *hBoxLayout() const;
  32. LineEditButton *clearButton() const;
  33. signals:
  34. private slots:
  35. void onTextChanged(const QString &text);
  36. // QWidget interface
  37. protected:
  38. void focusInEvent(QFocusEvent *event) override;
  39. void focusOutEvent(QFocusEvent *event) override;
  40. void paintEvent(QPaintEvent *event) override;
  41. void contextMenuEvent(QContextMenuEvent *event) override;
  42. private:
  43. QHBoxLayout *m_hBoxLayout;
  44. bool m_isClearButtonEnabled;
  45. LineEditButton *m_clearButton;
  46. };
  47. class SearchLineEdit : public LineEdit
  48. {
  49. Q_OBJECT
  50. public:
  51. SearchLineEdit(QWidget *parent = nullptr);
  52. signals:
  53. void searchSignal(const QString &);
  54. void clearSignal();
  55. protected slots:
  56. void search();
  57. private:
  58. LineEditButton *m_searchButton;
  59. };
  60. class PasswordLineEdit : public LineEdit
  61. {
  62. Q_OBJECT
  63. public:
  64. PasswordLineEdit(QWidget *parent = nullptr);
  65. signals:
  66. void echoModeChanged();
  67. void clearSignal();
  68. protected:
  69. void switchEchoMode();
  70. private:
  71. LineEditButton *m_echoButton;
  72. };
  73. class TextEdit : public QTextEdit
  74. {
  75. Q_OBJECT
  76. public:
  77. TextEdit(QWidget *parent = nullptr);
  78. // QWidget interface
  79. protected:
  80. void wheelEvent(QWheelEvent *event) override;
  81. void contextMenuEvent(QContextMenuEvent *event) override;
  82. private:
  83. SmoothScroll *m_verticalSmoothScroll;
  84. SmoothScroll *m_horizonSmoothScroll;
  85. };
  86. class PlainTextEdit : public QPlainTextEdit
  87. {
  88. Q_OBJECT
  89. public:
  90. PlainTextEdit(QWidget *parent = nullptr);
  91. protected:
  92. void wheelEvent(QWheelEvent *event) override;
  93. void contextMenuEvent(QContextMenuEvent *event) override;
  94. private:
  95. SmoothScroll *m_verticalSmoothScroll;
  96. SmoothScroll *m_horizonSmoothScroll;
  97. };
  98. #endif // LINEEDIT_H