#include "signaldrawer.h"
#include <QFontMetrics>
-const int SignalDrawer::AXIS_LABEL_BORDER_OFFSET(2);
-const int SignalDrawer::AXIS_LABEL_SCALE_OFFSET(3);
+const int SignalDrawer::DEFAULT_AXIS_LABEL_BORDER_OFFSET(2);
+const int SignalDrawer::DEFAULT_AXIS_LABEL_SCALE_OFFSET(4);
const int SignalDrawer::DEFAULT_BIGTICK_LENGTH(8);
const double SignalDrawer::DEFAULT_DPI(96);
+const int SignalDrawer::DEFAULT_LINE_WIDTH(1);
const int SignalDrawer::DEFAULT_MAXIMAL_AXIS_BIGTICK_STEP(150);
const int SignalDrawer::DEFAULT_MINIMAL_AXIS_BIGTICK_STEP(25);
const int SignalDrawer::DEFAULT_SCALE_TEXT_VERTICAL_OFFSET(15);
m_axisLabelFont = new QFont("arial", scaleToDpiX(LABEL_FONT_SIZE));
m_axisLabelFM = new QFontMetrics(*m_axisLabelFont);
+
+ m_axisLabelBorderOffset = scaleToDpiX(DEFAULT_AXIS_LABEL_BORDER_OFFSET);
+ m_axisLabelScaleOffset = scaleToDpiX(DEFAULT_AXIS_LABEL_SCALE_OFFSET);
m_bigTickLength = scaleToDpiX(DEFAULT_BIGTICK_LENGTH);
m_subTickLength = scaleToDpiX(DEFAULT_SUBTICK_LENGTH);
+ m_lineWidth = scaleToDpiX(DEFAULT_LINE_WIDTH);
m_maximalBigtickStep = scaleToDpiX(DEFAULT_MAXIMAL_AXIS_BIGTICK_STEP);
m_minimalBigtickStep = scaleToDpiX(DEFAULT_MINIMAL_AXIS_BIGTICK_STEP);
m_scaleTextVerticalOffset = scaleToDpiY(DEFAULT_SCALE_TEXT_VERTICAL_OFFSET);
}
m_xAxisLabelRect = m_axisLabelFM->boundingRect(m_xAxisLabelText);
m_yAxisLabelRect = m_axisLabelFM->boundingRect(m_yAxisLabelText);
- m_xAxisLabelRect.moveTo(m_width - m_axisLabelFM->width(m_xAxisLabelText) - AXIS_LABEL_BORDER_OFFSET, m_gHeight - AXIS_LABEL_SCALE_OFFSET);
- m_yAxisLabelRect.moveTo(m_leftGraphOffset + AXIS_LABEL_SCALE_OFFSET, m_axisLabelFM->height() - m_axisLabelFM->underlinePos());
+ m_xAxisLabelRect.moveTo(m_width - m_axisLabelFM->width(m_xAxisLabelText) - m_axisLabelBorderOffset, m_gHeight - m_axisLabelScaleOffset);
+ m_yAxisLabelRect.moveTo(m_leftGraphOffset + m_axisLabelScaleOffset, m_axisLabelFM->height() - m_axisLabelFM->underlinePos());
} else {
m_gWidth = m_width;
m_leftGraphOffset = 0;
return false;
}
+ painter->setPen(QPen(Qt::black, m_lineWidth));
painter->setFont(*m_axisLabelFont);
/* VALUE scale must be drawn first - left offset of the graph depends on it */
drawValueScale(painter);
return false;
}
- painter->setPen(QColor(Qt::blue));
+ painter->setPen(QPen(Qt::blue, m_lineWidth));
fromXPix = relToXPix(m_gdData->ddata[0].first);
fromYPix = relToYPix(m_gdData->ddata[0].second);
QRegion SignalDrawer::renderPeak(const PeakDrawData& pd, QPainter* const painter)
{
- QFont font("arial", 10);
- QFontMetrics fm(font);
QString aucText, timeText;
QRegion peakReg;
int tTextHeight, tTextWidth, aTextWidth;
aucText = m_locale.toString(pd.auc, 'f', 4);
timeText = QString("A:") + m_locale.toString(pd.time, 'f', 4);
- painter->setPen(Qt::red);
+ painter->setPen(QPen(Qt::red, m_lineWidth));
painter->drawLine(fromXPix, fromYPix, toXPix, toYPix);
if (pd.itype == IntegrationType::BASELINE) {
painter->drawLine(fromXPix, fromYPix, fromXPix, relToYPix(pd.blFromY));
}
/* Draw AREA and TIME caption */
- painter->setFont(font);
+ painter->setFont(*m_axisLabelFont);
painter->setPen(Qt::black);
- tTextWidth = fm.width(timeText);
+ tTextWidth = m_axisLabelFM->width(timeText);
if (peakY - tTextWidth < 2)
peakY += tTextWidth - peakY + 2;
- tTextHeight = fm.height();
+ tTextHeight = m_axisLabelFM->height();
painter->save();
painter->translate(peakX, peakY);
painter->rotate(-90);
painter->drawText(0, 0, timeText);
painter->rotate(+90);
painter->restore();
- aTextWidth = fm.width(aucText);
+ aTextWidth = m_axisLabelFM->width(aucText);
painter->drawText(peakX + 5, peakY, aucText);
if (peakX - tTextHeight < fromXPix)
}
template<typename T>
-T SignalDrawer::scaleToDpiX(const T value)
+int SignalDrawer::scaleToDpiX(const T value)
{
- return static_cast<double>(value) * m_dpiX / DEFAULT_DPI;
+ return floor((static_cast<double>(value) * m_dpiX / DEFAULT_DPI) + 0.5);
}
template<typename T>
-T SignalDrawer::scaleToDpiY(const T value)
+int SignalDrawer::scaleToDpiY(const T value)
{
- return static_cast<double>(value) * m_dpiY / DEFAULT_DPI;
+ return floor((static_cast<double>(value) * m_dpiY / DEFAULT_DPI) + 0.5);
}
void SignalDrawer::setNewRelativeConstraints(const double fromX, const double fromY, const double toX, const double toY)
double xPixToRel(const int pix);
double yPixToRel(const int pix);
- static const int AXIS_LABEL_BORDER_OFFSET;
- static const int AXIS_LABEL_SCALE_OFFSET;
+ static const int DEFAULT_AXIS_LABEL_BORDER_OFFSET;
+ static const int DEFAULT_AXIS_LABEL_SCALE_OFFSET;
static const int DEFAULT_BIGTICK_LENGTH;
static const double DEFAULT_DPI;
+ static const int DEFAULT_LINE_WIDTH;
static const int DEFAULT_MAXIMAL_AXIS_BIGTICK_STEP;
static const int DEFAULT_MINIMAL_AXIS_BIGTICK_STEP;
static const int DEFAULT_SCALE_TEXT_VERTICAL_OFFSET;
int calculateMaximalTickStep(const int dimension);
double linesIntersection(const double k1, const double q1, const double k2, const double q2);
void restoreRelativeConstraints();
- template<typename T> T scaleToDpiX(const T value);
- template<typename T> T scaleToDpiY(const T value);
+ template<typename T> int scaleToDpiX(const T value);
+ template<typename T> int scaleToDpiY(const T value);
void setNewRelativeConstraints(const double fromX, const double fromY, const double toX, const double toY);
double subStep(const double step);
int m_leftGraphOffset;
bool m_validConstraints;
+ int m_axisLabelBorderOffset;
+ int m_axisLabelScaleOffset;
int m_bigTickLength;
int m_subTickLength;
+ int m_lineWidth;
int m_maximalBigtickStep;
int m_minimalBigtickStep;
int m_scaleTextVerticalOffset;