| 1 |
#ifndef xmpsolve_ROOTSRENDERER_H |
| 2 |
#define xmpsolve_ROOTSRENDERER_H |
| 3 |
|
| 4 |
#include "root.h" |
| 5 |
#include "rootsmodel.h" |
| 6 |
#include <QPainter> |
| 7 |
#include <QPaintEvent> |
| 8 |
|
| 9 |
namespace xmpsolve { |
| 10 |
|
| 11 |
class RootsRenderer |
| 12 |
{ |
| 13 |
|
| 14 |
public: |
| 15 |
explicit RootsRenderer(); |
| 16 |
|
| 17 |
void handlePaintEvent(QPainter& painter, int w, int h, QPaintEvent *); |
| 18 |
|
| 19 |
/** |
| 20 |
* @brief zoomIn changes the zoom to magnify more. |
| 21 |
*/ |
| 22 |
void zoomIn(); |
| 23 |
|
| 24 |
/** |
| 25 |
* @brief zoomOut changes the zoom to see a wider range. |
| 26 |
*/ |
| 27 |
void zoomOut(); |
| 28 |
|
| 29 |
/** |
| 30 |
* @brief setCenter selects the current centered point. |
| 31 |
* @param x Horizontal coordinate of the center (aka real part) |
| 32 |
* @param y Vertical coordinate of the center (aka imaginary part). |
| 33 |
*/ |
| 34 |
void setCenter(double x, double y); |
| 35 |
|
| 36 |
/** |
| 37 |
* @brief center returns the current center point of the plot. |
| 38 |
* @return A QPointF object representing the real and imaginary part of the |
| 39 |
* current center. |
| 40 |
*/ |
| 41 |
QPointF center() { return mCenter; } |
| 42 |
|
| 43 |
protected: |
| 44 |
|
| 45 |
/** |
| 46 |
* @brief reloadRoots reloads the roots from the model. |
| 47 |
*/ |
| 48 |
void reloadRoots(); |
| 49 |
|
| 50 |
/** |
| 51 |
* @brief scalePoint is used internally to scale, flip and translate a point |
| 52 |
* in a such a way that is plotted properly on the coordinate system on the screen. |
| 53 |
* |
| 54 |
* @param point Is the original point that shall be plotted. |
| 55 |
* @param width Is the current width of the widget. |
| 56 |
* @param height Is the current height of the widget. |
| 57 |
* @return The QPointF that can be plotted. |
| 58 |
*/ |
| 59 |
QPointF scalePoint(QPointF point, int width, int height); |
| 60 |
|
| 61 |
QPointF scaleVector(QPointF point, int width, int height); |
| 62 |
QPointF scaleVectorInverse(QPointF point, int width, int height); |
| 63 |
|
| 64 |
/** |
| 65 |
* @brief drawTicks is used internally to draw ticks on the axis. |
| 66 |
*/ |
| 67 |
void drawTicks(QPainter& painter, double w, double h); |
| 68 |
|
| 69 |
/** |
| 70 |
* @brief Points that should be displayed. |
| 71 |
*/ |
| 72 |
QList<QPointF> m_roots; |
| 73 |
|
| 74 |
/** |
| 75 |
* @brief m_maxRealModule is the maximum module of the real parts of the roots. |
| 76 |
*/ |
| 77 |
double m_maxRealModule; |
| 78 |
|
| 79 |
/** |
| 80 |
* @brief m_maxImagModule is the maximum module of the imaginary parts of the roots. |
| 81 |
*/ |
| 82 |
double m_maxImagModule; |
| 83 |
|
| 84 |
/** |
| 85 |
* @brief m_model is the model containing the roots that should be displayed. |
| 86 |
*/ |
| 87 |
RootsModel* m_model; |
| 88 |
|
| 89 |
private: |
| 90 |
QPointF mCenter; |
| 91 |
|
| 92 |
}; |
| 93 |
|
| 94 |
} // namespace xmpsolve |
| 95 |
|
| 96 |
#endif // xmpsolve_ROOTSRENDERER_H |