Higher resolution graph snapshots in antialias mode

This commit is contained in:
Mark Watkins 2014-08-28 03:30:53 +10:00
parent fb9e26aee3
commit 32bc6a97d0
5 changed files with 93 additions and 144 deletions

View File

@ -291,18 +291,17 @@ void gGraph::paint(QPainter &painter, const QRegion &region)
int fw, font_height;
GetTextExtent("Wg@", fw, font_height);
if (m_margintop > 0) { m_margintop = font_height + (8 * printScaleY()); }
if (m_margintop > 0) { m_margintop = font_height + (8); }
//m_marginbottom=5;
left = marginLeft(), right = marginRight(), top = marginTop(), bottom = marginBottom();
left = marginLeft()*printScaleX(), right = marginRight()*printScaleX(), top = marginTop(), bottom = marginBottom() * printScaleY();
int x = 0, y = 0;
if (m_showTitle) {
int title_x, yh;
painter.setFont(*mediumfont);
QFontMetrics fm(*mediumfont);
yh = fm.height();
@ -310,14 +309,14 @@ void gGraph::paint(QPainter &painter, const QRegion &region)
y = yh;
x = fm.width(title());
//GetTextExtent(title(),x,y,mediumfont);
title_x = float(yh) * 1.5;
title_x = float(yh) ;
QString & txt = title();
if (!m_issnapshot) {
graphView()->AddTextQue(txt, marginLeft() + title_x + 4, originY + height / 2 - y / 2, 90, Qt::black, mediumfont);
graphView()->AddTextQue(txt, marginLeft() + title_x + 8*printScaleX(), originY + height / 2 - y / 2, 90, Qt::black, mediumfont);
}
left += title_x;
left += graphView()->titleWidth*printScaleX();
} else { left = 0; }
@ -339,7 +338,6 @@ void gGraph::paint(QPainter &painter, const QRegion &region)
}
// #define DEBUG_LAYOUT
#ifdef DEBUG_LAYOUT
QColor col = Qt::red;
painter.setPen(col);
@ -355,11 +353,10 @@ void gGraph::paint(QPainter &painter, const QRegion &region)
if (!ll->visible()) { continue; }
tmp = ll->Height() * m_graphview->printScaleY();
tmp = ll->Height();// * m_graphview->printScaleY();
if (ll->position() == LayerTop) { top += tmp; }
if (ll->position() == LayerBottom) { bottom += tmp; }
if (ll->position() == LayerBottom) { bottom += tmp * printScaleY(); }
}
@ -397,7 +394,7 @@ void gGraph::paint(QPainter &painter, const QRegion &region)
}
}
bottom = marginBottom();
bottom = marginBottom() * printScaleY();
top = marginTop();
for (int i = 0; i < m_layers.size(); i++) {
@ -405,7 +402,7 @@ void gGraph::paint(QPainter &painter, const QRegion &region)
if (!ll->visible()) { continue; }
tmp = ll->Height() * m_graphview->printScaleY();
tmp = ll->Height();
if (ll->position() == LayerTop) {
QRect rect(originX + left, originY + top, width - left - right, tmp);
@ -415,7 +412,7 @@ void gGraph::paint(QPainter &painter, const QRegion &region)
}
if (ll->position() == LayerBottom) {
bottom += tmp;
bottom += tmp * printScaleY();
QRect rect(originX + left, originY + height - bottom, width - left - right, tmp);
ll->m_rect = rect;
ll->paint(painter, *this, QRegion(rect));

View File

@ -9,6 +9,8 @@
#ifndef graphs_ggraph_h
#define graphs_ggraph_h
//#define DEBUG_LAYOUT
#include <QFont>
#include <QObject>
#include <QPixmap>

View File

@ -2099,12 +2099,73 @@ void gGraphView::onSnapshotGraphToggle()
bool pinned = graph->isPinned();
graph->setPinned(false);
QPixmap pm = graph->renderPixmap(width(), graph->m_rect.height(), false);
bool highres = p_profile->appearance->antiAliasing();
QPixmap pm;
////////////////////////////////////////////////////////////////////////////
if (highres) {
QFont *_defaultfont = defaultfont;
QFont *_mediumfont = mediumfont;
QFont *_bigfont = bigfont;
QFont fa = *defaultfont;
QFont fb = *mediumfont;
QFont fc = *bigfont;
fa.setPointSize(fa.pointSize()*2.0);
fb.setPointSize(fb.pointSize()*2.0);
fc.setPointSize(fc.pointSize()*2.0);
defaultfont = &fa;
mediumfont = &fb;
bigfont = &fc;
graph->m_printing = true;
bool pmc = p_profile->appearance->usePixmapCaching();
p_profile->appearance->setUsePixmapCaching(false);
setUsePixmapCache(false);
int w = graph->m_rect.width() * 2.0;
int h = graph->m_rect.height() * 2.0;
setPrintScaleX(2);
setPrintScaleY(2);
pm = QPixmap(w,h);
QPainter painter(&pm);
QRect rec(0,0,w,h);
painter.fillRect(rec,QBrush(QColor(Qt::white)));
float f = scaleY();
QRegion region(rec);
graph->paint(painter, region);
DrawTextQue(painter);
painter.end();
setUsePixmapCache(pmc);
p_profile->appearance->setUsePixmapCaching(pmc);
setPrintScaleX(1);
setPrintScaleY(1);
graph->m_printing = false;
defaultfont = _defaultfont;
mediumfont = _mediumfont;
bigfont = _bigfont;
////////////////////////////////////////////////////////////////////////////
} else {
pm = graph->renderPixmap(width(), graph->m_rect.height(), false);
}
graph->setPinned(pinned);
gGraph * newgraph = new gGraph(newname, nullptr, graph->title(), graph->units(), graph->height(), graph->group());
newgraph->setSnapshot(pm);
newgraph->setBlockSelect(true);
newgraph->setHeight(pm.height());
newgraph->setHeight(pm.height()/(highres?2:1));
//newgraph->setMinHeight(pm.height());
m_graphs.insert(m_graphs.indexOf(graph)+1, newgraph);

View File

@ -52,7 +52,7 @@ void gXGrid::paint(QPainter &painter, gGraph &w, const QRegion &region)
static QString fd = "0";
GetTextExtent(fd, x, y);
double max_yticks = round(height / (y + 14.0)); // plus spacing between lines
double max_yticks = round(height / (y + 14.0*w.printScaleY())); // plus spacing between lines
//double yt=1/max_yticks;
double mxy = maxy; //MAX(fabs(maxy), fabs(miny));
@ -155,131 +155,11 @@ void gYAxis::paint(QPainter &painter, gGraph &w, const QRegion &region)
//Todo: clean this up as there is a lot of duplicate code between the sections
if (0) {//w.graphView()->usePixmapCache()) {
/* if (w.invalidate_yAxisImage) {
if (!m_image.isNull()) {
w.graphView()->deleteTexture(m_textureID);
m_image=QImage();
}
if (height<0) return;
if (height>2000) return;
int labelW=0;
EventDataType miny=w.min_y;
EventDataType maxy=w.max_y;
if (miny<0) { // even it up if it's starts negative
miny=-MAX(fabs(miny),fabs(maxy));
}
w.roundY(miny,maxy);
EventDataType dy=maxy-miny;
static QString fd="0";
GetTextExtent(fd,x,y);
yh=y;
m_image=QImage(width,height+y+4,QImage::Format_ARGB32_Premultiplied);
m_image.fill(Qt::transparent);
QPainter paint(&m_image);
double max_yticks=round(height / (y+14.0)); // plus spacing between lines
double mxy=MAX(fabs(maxy),fabs(miny));
double mny=miny;
if (miny<0) {
mny=-mxy;
}
double rxy=mxy-mny;
int myt;
bool fnd=false;
for (myt=max_yticks;myt>2;myt--) {
float v=rxy/float(myt);
if (v==int(v)) {
fnd=true;
break;
}
}
if (fnd) max_yticks=myt;
double yt=1/max_yticks;
double ymult=height/rxy;
double min_ytick=rxy*yt;
float ty,h;
if (min_ytick<=0) {
qDebug() << "min_ytick error in gYAxis::paint() in" << w.title();
return;
}
if (min_ytick>=1000000) {
min_ytick=100;
}
//lines=w.backlines();
for (double i=miny; i<=maxy+min_ytick-0.00001; i+=min_ytick) {
ty=(i - miny) * ymult;
if (dy<5) {
fd=Format(i*m_yaxis_scale,2);
} else {
fd=Format(i*m_yaxis_scale,1);
}
GetTextExtent(fd,x,y);
if (x>labelW) labelW=x;
h=(height-2)-ty;
h+=yh;
#ifndef Q_OS_MAC
// stupid pixel alignment rubbish, I really should be using floats..
h+=1;
#endif
if (h<0)
continue;
paint.setBrush(Qt::black);
paint.drawText(width-8-x,h+y/2,fd);
paint.setPen(m_line_color);
paint.drawLine(width-4,h,width,h);
double z=(min_ytick/4)*ymult;
double g=h;
for (int i=0;i<3;i++) {
g+=z;
if (g>height+yh) break;
paint.drawLine(width-3,g,width,g);
}
}
paint.end();
m_image=QGLWidget::convertToGLFormat(m_image);
m_textureID=w.graphView()->bindTexture(m_image,GL_TEXTURE_2D,GL_RGBA,QGLContext::NoBindOption);
w.invalidate_yAxisImage=false;
}
if (!m_image.isNull()) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
w.graphView()->drawTexture(QPoint(left,(top+height)-m_image.height()+5),m_textureID);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
}
*/
if (0) {
} else {
if (height < 0) { return; }
if (height > 2000) { return; }
if (height > 4000) { return; }
int labelW = 0;
@ -294,7 +174,12 @@ void gYAxis::paint(QPainter &painter, gGraph &w, const QRegion &region)
static QString fd = "0";
GetTextExtent(fd, x, y);
double max_yticks = round(height / (y + 14.0)); // plus spacing between lines
#ifdef DEBUG_LAYOUT
painter.setPen(Qt::green);
painter.drawLine(0,top,100,top);
#endif
double max_yticks = height / (y + 14.0); // plus spacing between lines
double mxy = maxy; // MAX(fabs(maxy), fabs(miny));
double mny = miny;
@ -311,7 +196,7 @@ void gYAxis::paint(QPainter &painter, gGraph &w, const QRegion &region)
for (myt = max_yticks; myt > 2; myt--) {
float v = rxy / float(myt);
if (v == int(v)) {
if (qAbs(v - int(v)) < 0.000001) {
fnd = true;
break;
}
@ -345,6 +230,7 @@ void gYAxis::paint(QPainter &painter, gGraph &w, const QRegion &region)
QVector<QLine> ticks;
float shorttick = 4.0 * w.printScaleX();
for (double i = miny; i <= maxy + min_ytick - 0.00001; i += min_ytick) {
ty = (i - miny) * ymult;
@ -362,9 +248,9 @@ void gYAxis::paint(QPainter &painter, gGraph &w, const QRegion &region)
if (h < top) { continue; }
w.renderText(fd, left + width - 8 - x, (h + (y / 2.0)), 0, m_text_color, defaultfont);
w.renderText(fd, left + width - shorttick*2 - x, (h + (y / 2.0)), 0, m_text_color, defaultfont);
ticks.append(QLine(left + width - 4, h, left + width, h));
ticks.append(QLine(left + width - shorttick, h, left + width, h));
double z = (min_ytick / 4) * ymult;
double g = h;
@ -374,7 +260,7 @@ void gYAxis::paint(QPainter &painter, gGraph &w, const QRegion &region)
if (g > top + height) { break; }
ticks.append(QLine(left + width - 3, g, left + width, g));
ticks.append(QLine(left + width - shorttick/2, g, left + width, g));
}
}
painter.setPen(m_line_color);

View File

@ -415,6 +415,7 @@ void Report::PrintReport(gGraphView *gv, QString name, QDate date)
if (!print_bookmarks) {
for (int i = 0; i < gv->size(); i++) {
g = (*gv)[i];
if (g->isSnapshot()) continue;
if (g->isEmpty()) { continue; }
@ -508,6 +509,7 @@ void Report::PrintReport(gGraphView *gv, QString name, QDate date)
for (int i = 0; i < gv->size(); i++) {
gGraph *g = (*gv)[i];
if (g->isSnapshot()) continue;
if (g->isEmpty()) { continue; }
@ -529,6 +531,7 @@ void Report::PrintReport(gGraphView *gv, QString name, QDate date)
if (g->isEmpty()) { continue; }
if (!g->visible()) { continue; }
if (g->isSnapshot()) continue;
start.push_back(st);
end.push_back(et);