00001
00002
00003
00004
00005
00006
00007 #include "CallbackBoundingRects.h"
00008 #include "EngaugeAssert.h"
00009 #include "Logger.h"
00010 #include "Point.h"
00011 #include <qmath.h>
00012 #include "QtToString.h"
00013 #include "Transformation.h"
00014
00015 CallbackBoundingRects::CallbackBoundingRects(const Transformation &transformation) :
00016 m_isEmpty (true),
00017 m_transformation (transformation)
00018 {
00019 }
00020
00021 QRectF CallbackBoundingRects::boundingRectGraph (bool &isEmpty) const
00022 {
00023 isEmpty = m_isEmpty;
00024
00025 return m_boundingRectGraph;
00026 }
00027
00028 QRectF CallbackBoundingRects::boundingRectScreen (bool &isEmpty) const
00029 {
00030 isEmpty = m_isEmpty;
00031
00032 return m_boundingRectScreen;
00033 }
00034
00035 CallbackSearchReturn CallbackBoundingRects::callback (const QString &curveName,
00036 const Point &point)
00037 {
00038 QPointF posGraph;
00039 if (curveName == AXIS_CURVE_NAME) {
00040 posGraph = point.posGraph();
00041 } else {
00042 m_transformation.transformScreenToRawGraph (point.posScreen(),
00043 posGraph);
00044 }
00045 mergeCoordinates (posGraph,
00046 m_boundingRectGraph);
00047 mergeCoordinates (point.posScreen(),
00048 m_boundingRectScreen);
00049
00050 m_isEmpty = false;
00051
00052 return CALLBACK_SEARCH_RETURN_CONTINUE;
00053 }
00054
00055 void CallbackBoundingRects::mergeCoordinates (const QPointF &pos,
00056 QRectF &boundingRect)
00057 {
00058 bool newGraphLeft = m_isEmpty;
00059 bool newGraphTop = m_isEmpty;
00060 bool newGraphRight = m_isEmpty;
00061 bool newGraphBottom = m_isEmpty;
00062
00063 if (!newGraphLeft) {
00064 newGraphLeft = (pos.x() < boundingRect.left());
00065 }
00066 if (!newGraphTop) {
00067 newGraphTop = (pos.y() < boundingRect.top());
00068 }
00069 if (!newGraphRight) {
00070 newGraphRight = (boundingRect.right() < pos.x());
00071 }
00072 if (!newGraphBottom) {
00073 newGraphBottom = (boundingRect.bottom() < pos.y());
00074 }
00075
00076 if (newGraphLeft) {
00077 boundingRect.setLeft (pos.x());
00078 }
00079 if (newGraphTop) {
00080 boundingRect.setTop (pos.y());
00081 }
00082 if (newGraphRight) {
00083 boundingRect.setRight (pos.x());
00084 }
00085 if (newGraphBottom) {
00086 boundingRect.setBottom (pos.y());
00087 }
00088 }