AlignmentSelector.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 <components/AccessibleAlignmentSelector.hpp>
  16. #include <QFocusEvent>
  17. #include <QKeyEvent>
  18. #include <QWidget>
  19. class AlignmentSelector : public QWidget {
  20. Q_OBJECT
  21. friend class AccessibleAlignmentSelector;
  22. friend class AccessibleAlignmentCell;
  23. public:
  24. explicit AlignmentSelector(QWidget *parent = nullptr);
  25. QSize sizeHint() const override;
  26. QSize minimumSizeHint() const override;
  27. Qt::Alignment value() const;
  28. int currentIndex() const;
  29. void setAlignment(Qt::Alignment alignment);
  30. void setCurrentIndex(int index);
  31. signals:
  32. void valueChanged(Qt::Alignment value);
  33. void currentIndexChanged(int value);
  34. protected:
  35. QRect cellRect(int index) const;
  36. void paintEvent(QPaintEvent *event) override;
  37. void leaveEvent(QEvent *event) override;
  38. void mouseMoveEvent(QMouseEvent *event) override;
  39. void mousePressEvent(QMouseEvent *event) override;
  40. void keyPressEvent(QKeyEvent *event) override;
  41. void focusInEvent(QFocusEvent *event) override;
  42. void focusOutEvent(QFocusEvent *event) override;
  43. private:
  44. Qt::Alignment alignment = Qt::AlignTop | Qt::AlignLeft;
  45. int hoveredCell = -1;
  46. int focusedCell = 4;
  47. int selectedCell = 4;
  48. QRect gridRect() const;
  49. void moveFocusedCell(int moveX, int moveY);
  50. void setFocusedCell(int cell);
  51. void selectCell(int cell);
  52. Qt::Alignment cellAlignment(int index) const;
  53. };