PushButton.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //============================================================================
  2. /// \file PushButton.cpp
  3. /// \author Uwe Kindler
  4. /// \date 18.10.2022
  5. /// \brief Implementation of CPushButton
  6. //============================================================================
  7. //============================================================================
  8. // INCLUDES
  9. //============================================================================
  10. #include "PushButton.h"
  11. #include <QPainter>
  12. #include <QStyleOptionButton>
  13. #include <QDebug>
  14. #include <QStylePainter>
  15. namespace ads
  16. {
  17. QSize CPushButton::sizeHint() const
  18. {
  19. QSize sh = QPushButton::sizeHint();
  20. if (m_Orientation != CPushButton::Horizontal)
  21. {
  22. sh.transpose();
  23. }
  24. return sh;
  25. }
  26. void CPushButton::paintEvent(QPaintEvent *event)
  27. {
  28. Q_UNUSED(event);
  29. QStylePainter painter(this);
  30. QStyleOptionButton option;
  31. initStyleOption(&option);
  32. if (m_Orientation == CPushButton::VerticalTopToBottom)
  33. {
  34. painter.rotate(90);
  35. painter.translate(0, -1 * width());
  36. option.rect = option.rect.transposed();
  37. }
  38. else if (m_Orientation == CPushButton::VerticalBottomToTop)
  39. {
  40. painter.rotate(-90);
  41. painter.translate(-1 * height(), 0);
  42. option.rect = option.rect.transposed();
  43. }
  44. painter.drawControl(QStyle::CE_PushButton, option);
  45. }
  46. CPushButton::Orientation CPushButton::buttonOrientation() const
  47. {
  48. return m_Orientation;
  49. }
  50. void CPushButton::setButtonOrientation(Orientation orientation)
  51. {
  52. m_Orientation = orientation;
  53. updateGeometry();
  54. }
  55. } // namespace ads
  56. //---------------------------------------------------------------------------
  57. // EOF PushButton.cpp