File indexing completed on 2023-09-24 07:52:19
0001 /* 0002 SPDX-FileCopyrightText: 2007 Niels Slot <nielsslot AT gmail DOT com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef _DIRECTIONDIALOG_H_ 0008 #define _DIRECTIONDIALOG_H_ 0009 0010 #include "interpreter/translator.h" 0011 0012 #include <QDialog> 0013 #include <QSvgRenderer> 0014 #include <QWidget> 0015 0016 class QComboBox; 0017 class QLineEdit; 0018 class QPushButton; 0019 class QSpinBox; 0020 0021 0022 class DirectionCanvas : public QWidget 0023 { 0024 Q_OBJECT 0025 0026 public: 0027 explicit DirectionCanvas(QWidget* parent = nullptr); 0028 void enableGreyTurtle(bool); 0029 0030 public Q_SLOTS: 0031 void updateDirections(double previousDeg, double deg); 0032 0033 Q_SIGNALS: 0034 void degreeChanged(double deg); 0035 void previousDegreeChanged(double deg); 0036 0037 protected: 0038 void paintEvent(QPaintEvent *event) override; 0039 void mouseMoveEvent(QMouseEvent *event) override; 0040 void mousePressEvent(QMouseEvent *event) override; 0041 0042 private: 0043 double translateMouseCoords(double x, double y); 0044 0045 double deg; 0046 double previousDeg; 0047 QSvgRenderer turtle; 0048 QSvgRenderer greyTurtle; 0049 bool greyTurtleEnabled; 0050 }; 0051 0052 0053 class DirectionDialog : public QDialog 0054 { 0055 Q_OBJECT 0056 0057 public: 0058 DirectionDialog(double deg, QWidget* parent); 0059 0060 enum Command { 0061 Turnleft = 0, 0062 Turnright = 1, 0063 Direction = 2 0064 }; 0065 0066 Q_SIGNALS: 0067 void pasteText(const QString&); 0068 0069 private: 0070 DirectionCanvas* canvas; 0071 0072 QComboBox* commandPicker; 0073 QSpinBox* previousDirectionSpin; 0074 QSpinBox* directionSpin; 0075 0076 QPushButton *copyButton; 0077 QPushButton *pasteButton; 0078 0079 QLineEdit* commandBox; 0080 0081 int currentCommand; // enum DirectionChooser::Command 0082 0083 Translator* translator; 0084 0085 bool skipValueChangedEvent; 0086 0087 void updateCanvas(); 0088 void updateCommandBox(); 0089 0090 private Q_SLOTS: 0091 void directionChanged(int value); 0092 void changeCommand(int command); 0093 void updateDegrees(double deg); 0094 void updatePreviousDegrees(double deg); 0095 void copyProxy(); 0096 void pasteProxy(); 0097 }; 0098 0099 #endif // _DIRECTIONDIALOG_H_