MenuCheckBox.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /******************************************************************************
  2. Copyright (C) 2025 by Taylor Giampaolo <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. #include <QCheckBox>
  16. #include <QPointer>
  17. class QStyleOptionButton;
  18. class QStylePainter;
  19. class QMouseEvent;
  20. class MenuCheckBox : public QCheckBox {
  21. Q_OBJECT
  22. public:
  23. explicit MenuCheckBox(const QString &text, QWidget *parent = nullptr);
  24. void setAction(QAction *action);
  25. protected:
  26. void focusInEvent(QFocusEvent *event) override;
  27. void mousePressEvent(QMouseEvent *event) override;
  28. void mouseMoveEvent(QMouseEvent *event) override;
  29. void mouseReleaseEvent(QMouseEvent *event) override;
  30. void enterEvent(QEnterEvent *event) override;
  31. void leaveEvent(QEvent *event) override;
  32. void paintEvent(QPaintEvent *event) override;
  33. private:
  34. QPointer<QAction> menuAction = nullptr;
  35. bool mousePressInside = false;
  36. bool isHovered = false;
  37. void setHovered(bool hovered);
  38. };