30 squares_interval_(45.0),
31 current_orientation_(0.0),
33 must_highlight_angle_(false),
42 QSizePolicy size_policy(QSizePolicy::Minimum, QSizePolicy::Minimum);
44 size_policy.setHeightForWidth(
true);
45 setSizePolicy(size_policy);
49 setMouseTracking(
true);
119 if (texts_list.isEmpty())
return;
124 if (!texts_list.contains(text)) {
130 foreach(QString text, texts_list) {
162 return(QSize(50, 50));
182 QRect drawing_rectangle(QPoint(0, 0), size());
183 drawing_rectangle.adjust(5, 5, -5, -5);
185 QPointF drawing_rectangle_center(drawing_rectangle.center());
186 qreal drawing_rectangle_radius = drawing_rectangle.width() / 2.0;
191 p.setRenderHint(QPainter::Antialiasing,
true);
192 p.setRenderHint(QPainter::TextAntialiasing,
true);
195 p.setPen(QPen(QBrush(QColor(
"#9FA8A8")), 2.0));
196 p.setBrush(QBrush(QColor(
"#ffffaa")));
197 p.drawEllipse(drawing_rectangle);
200 p.setPen(QPen(QBrush(Qt::red), 1.0));
201 p.translate(drawing_rectangle_center);
203 p.drawLine(QLineF(QPointF(), QPointF(drawing_rectangle_radius, 0.0)));
209 if (!chosen_text.isEmpty()) {
213 p.translate(drawing_rectangle_center);
215 p.drawText(QPoint(), chosen_text);
220 qreal squares_size = size().width() / 15.0;
221 qreal square_offset = - squares_size / 2.0;
222 QRectF square_qrect = QRect(square_offset, square_offset, squares_size, squares_size);
224 p.setBrush(QBrush(QColor(
"#248A34")));
225 for (
double drawing_angle = 0.0 ; drawing_angle < 360.0 ; drawing_angle +=
squares_interval_) {
227 p.setBrush(QBrush(QColor(
"#43FF5F")));
230 p.translate(drawing_rectangle_center);
231 p.rotate(drawing_angle);
232 p.translate(drawing_rectangle_radius - 1.0, 0.0);
234 p.drawRect(square_qrect);
236 p.setBrush(QBrush(QColor(
"#248A34")));
265 double clicked_angle;
266 bool drawn_angle_clicked =
positionIsASquare(event -> localPos(), &clicked_angle);
268 if (drawn_angle_clicked) {
287 std::sort(available_lengths.begin(), available_lengths.end());
289 QList<qreal>::const_iterator i = qUpperBound(available_lengths, radius);
292 if (i == available_lengths.begin()) {
297 qreal final_length = *i;
299 return(final_string);
325 QRect drawing_rectangle(QPoint(0, 0), size());
326 drawing_rectangle.adjust(5, 5, -5, -5);
328 QPointF drawing_rectangle_center(drawing_rectangle.center());
329 qreal drawing_rectangle_radius = drawing_rectangle.width() / 2.0;
331 qreal squares_size = size().width() / 15.0;
332 qreal square_offset = - squares_size / 2.0;
333 QRectF square_qrect = QRect(square_offset, square_offset, squares_size, squares_size);
335 for (
double drawing_angle = 0.0 ; drawing_angle < 360.0 ; drawing_angle +=
squares_interval_) {
336 QTransform transform = QTransform()
337 .translate(drawing_rectangle_center.x(), drawing_rectangle_center.y())
338 .rotate(drawing_angle)
339 .translate(drawing_rectangle_radius - 1.0, 0.0)
342 QRectF mapped_rectangle = transform.mapRect(square_qrect);
343 if (mapped_rectangle.contains(pos)) {
344 if (angle_value_ptr) *angle_value_ptr = drawing_angle;
bool textDisplayed() const
double squares_interval_
Interval between commonly used angles (represented by squares), in degrees.
double highlight_angle_
Specific angle to be highlighted.
QString getMostUsableStringForRadius(const qreal &)
void paintEvent(QPaintEvent *) override
QStringList usableTexts() const
double current_orientation_
current angle
void setOrientation(const double &)
bool display_text_
Whether to display an example text.
void setUsableTexts(const QStringList &)
void mouseReleaseEvent(QMouseEvent *) override
QHash< QString, qreal > text_size_hash_
Associate available example texts with their length (in pixels)
~QTextOrientationWidget() override
bool read_only_
Whether this widget is read only.
void generateTextSizeHash()
double orientation() const
void setDisplayText(bool)
void setFont(const QFont &)
void mouseMoveEvent(QMouseEvent *) override
int heightForWidth(int) const override
bool positionIsASquare(const QPointF &, double *=nullptr)
QSize sizeHint() const override
bool must_highlight_angle_
Whether to highlight a specific angle.
QTextOrientationWidget(QWidget *=nullptr)
void orientationChanged(double)
QFont text_font_
Font used to render the example text.