2010-01-03 19:45:33 +00:00
|
|
|
/*
|
2014-01-29 18:37:45 +00:00
|
|
|
Copyright 2006-2014 The QElectroTech Team
|
2010-01-03 19:45:33 +00:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#ifndef Q_TEXT_ORIENTATION_WIDGET_H
|
|
|
|
#define Q_TEXT_ORIENTATION_WIDGET_H
|
|
|
|
#include <QtGui>
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
This class provides a visual representation of a text orientation.
|
2010-01-03 19:45:33 +00:00
|
|
|
*/
|
|
|
|
class QTextOrientationWidget : public QWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// constructors, destructor
|
2010-01-03 19:45:33 +00:00
|
|
|
public:
|
|
|
|
QTextOrientationWidget(QWidget * = 0);
|
|
|
|
virtual ~QTextOrientationWidget();
|
|
|
|
private:
|
|
|
|
QTextOrientationWidget(const QTextOrientationWidget &);
|
|
|
|
QTextOrientationWidget &operator=(const QTextOrientationWidget &);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// methods
|
2010-01-03 19:45:33 +00:00
|
|
|
public:
|
|
|
|
double orientation() const;
|
|
|
|
void setFont(const QFont &);
|
|
|
|
QFont font() const;
|
|
|
|
void setDisplayText(bool);
|
|
|
|
bool textDisplayed() const;
|
|
|
|
void setUsableTexts(const QStringList &);
|
|
|
|
QStringList usableTexts() const;
|
|
|
|
bool isReadOnly() const;
|
|
|
|
void setReadOnly(bool);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void setOrientation(const double &);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual QSize sizeHint () const;
|
|
|
|
int heightForWidth(int) const;
|
|
|
|
virtual void paintEvent(QPaintEvent *);
|
|
|
|
void mouseMoveEvent(QMouseEvent *);
|
|
|
|
void mouseReleaseEvent(QMouseEvent *);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
/**
|
2012-11-09 21:09:24 +00:00
|
|
|
Signal emitted when users specify an orientation by clicking the widget.
|
2010-01-03 19:45:33 +00:00
|
|
|
*/
|
|
|
|
void orientationChanged(double);
|
|
|
|
|
2012-11-09 21:09:24 +00:00
|
|
|
// attributes
|
2010-01-03 19:45:33 +00:00
|
|
|
private:
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Interval between commonly used angles (represented by squares), in degrees
|
2010-01-03 19:45:33 +00:00
|
|
|
double squares_interval_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// current angle
|
2010-01-03 19:45:33 +00:00
|
|
|
double current_orientation_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Whether to display an example text
|
2010-01-03 19:45:33 +00:00
|
|
|
bool display_text_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Font used to render the example text
|
2010-01-03 19:45:33 +00:00
|
|
|
QFont text_font_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Associate available example texts with their length (in pixels)
|
2010-01-03 19:45:33 +00:00
|
|
|
QHash<QString, qreal> text_size_hash_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Specific angle to be highlighted
|
2010-01-03 19:45:33 +00:00
|
|
|
double highlight_angle_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Whether to highlight a specific angle
|
2010-01-03 19:45:33 +00:00
|
|
|
bool must_highlight_angle_;
|
2012-11-09 21:09:24 +00:00
|
|
|
/// Whether this widget is read only
|
2010-01-03 19:45:33 +00:00
|
|
|
bool read_only_;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString getMostUsableStringForRadius(const qreal &);
|
|
|
|
void generateTextSizeHash();
|
|
|
|
bool positionIsASquare(const QPointF &, double * = 0);
|
|
|
|
};
|
|
|
|
#endif
|