PresetButton.h 931 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #if !defined(Q_MOC_RUN)
  10. #include <QPushButton>
  11. #endif
  12. class PresetButton
  13. : public QPushButton
  14. {
  15. Q_OBJECT
  16. public:
  17. using OnClicked = std::function<void(bool checked)>;
  18. PresetButton(const QString& defaultIconPath,
  19. const QString& hoverIconPath,
  20. const QString& selectedIconPath,
  21. const QSize& fixedButtonAndIconSize,
  22. const QString& text,
  23. OnClicked clicked,
  24. QWidget* parent = nullptr);
  25. protected:
  26. void enterEvent(QEvent* ev) override;
  27. void leaveEvent(QEvent* ev) override;
  28. private:
  29. void UpdateIcon(bool isChecked);
  30. bool m_isHovering;
  31. QIcon m_defaultIcon;
  32. QIcon m_hoverIcon;
  33. QIcon m_selectedIconPath;
  34. };