ff7tk  1.2.0.13
Work with Final Fantasy 7 game data
OrientationWidget.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2009 - 2022 Arzel Jérôme <myst6re@gmail.com>
2 // SPDX-FileCopyrightText: 2023 Chris Rizzitello <sithlord48@gmail.com>
3 // SPDX-License-Identifier: LGPL-3.0-or-later
4 
5 #pragma once
6 
7 #include <QWidget>
8 #include <QEvent>
9 #include <ff7tkqtwidgets_export.h>
10 
11 class FF7TKQTWIDGETS_EXPORT OrientationWidget : public QWidget
12 {
13  Q_OBJECT
14 public:
15  enum Style { Grid, Arrow};
16  enum Direction {North, East, South, West};
17  enum RotationDirection {ClockWise, CounterClockWise};
18  explicit OrientationWidget(QWidget *parent = nullptr);
19  explicit OrientationWidget(quint8 value, Direction zeroDirection = West, RotationDirection rotationDirection = CounterClockWise, Style style = Style::Grid, QWidget *parent = nullptr);
20  quint8 value() const;
21  bool isReadOnly() const;
22  void setReadOnly(bool ro);
23  virtual QSize minimumSizeHint() const override;
24  virtual QSize sizeHint() const override;
25 signals:
26  void valueChanged(int i);
27  void valueEdited(int i);
28 public slots:
29  void setValue(int value);
30  void setStyle(OrientationWidget::Style style);
31  void setRotationDirection(OrientationWidget::RotationDirection rotationDirection);
32  void setZeroDirection(OrientationWidget::Direction zeroDirection);
33 private:
34  void byte2degree(quint8 v);
35  quint8 degree2byte() const;
36  QPointF centerCircle() const;
37  double radiusCircle() const;
38  bool isInCircle(const QPointF &pos);
39  void moveCursor(const QPointF &pos);
40  void mouseEvent(QMouseEvent *e);
41  int _value;
42  bool _readOnly;
43  Direction _zeroDirection;
44  RotationDirection _rotationDirection;
45  Style _style;
46  QString _lblString;
47  void paintGrid(QPainter *p, double radius);
48  void paintArrow(QPainter *p, double radius);
49  void updateLabel();
50 protected:
51  virtual void changeEvent(QEvent *e) override;
52  virtual void paintEvent(QPaintEvent *e) override;
53  virtual inline void mousePressEvent(QMouseEvent *e) override {
54  mouseEvent(e);
55  }
56  virtual inline void mouseMoveEvent(QMouseEvent *e) override {
57  mouseEvent(e);
58  }
59 };
OrientationWidget::RotationDirection
RotationDirection
Definition: OrientationWidget.h:17
OrientationWidget
Definition: OrientationWidget.h:11
OrientationWidget::Direction
Direction
Definition: OrientationWidget.h:16
OrientationWidget::mousePressEvent
virtual void mousePressEvent(QMouseEvent *e) override
Definition: OrientationWidget.h:53
OrientationWidget::Style
Style
Definition: OrientationWidget.h:15
OrientationWidget::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *e) override
Definition: OrientationWidget.h:56