version 2.24.0
Graphic setCustomSaveImageTitleFunc() - add custom title when save to image
This commit is contained in:
@@ -1133,8 +1133,24 @@ void Graphic::autofit() {
|
||||
|
||||
void Graphic::saveImage(QString filename) {
|
||||
ppath = filename;
|
||||
QPixmap im(canvas->size());
|
||||
canvas->render(&im);
|
||||
QPixmap im;
|
||||
QString custom_title;
|
||||
if (func_image_title) custom_title = func_image_title();
|
||||
if (custom_title.isEmpty()) {
|
||||
im = QPixmap(canvas->size());
|
||||
canvas->render(&im);
|
||||
} else {
|
||||
QSize sz = canvas->size();
|
||||
QRectF tbr = fontMetrics().boundingRect(QRect(0, 0, sz.width(), 1), Qt::TextWordWrap, custom_title);
|
||||
sz.setHeight(sz.height() + tbr.height());
|
||||
im = QPixmap(canvas->size());
|
||||
im.fill(back_color);
|
||||
QPainter p(&im);
|
||||
p.setPen(text_color);
|
||||
p.drawText(tbr, Qt::TextWordWrap, custom_title);
|
||||
p.end();
|
||||
canvas->render(&im, QPoint(0, tbr.height()));
|
||||
}
|
||||
im.save(ppath);
|
||||
}
|
||||
|
||||
@@ -1300,6 +1316,11 @@ void Graphic::setCustomGridMarkFuncs(std::function<QString(double)> fx, std::fun
|
||||
}
|
||||
|
||||
|
||||
void Graphic::setCustomSaveImageTitleFunc(std::function<QString()> func) {
|
||||
func_image_title = func;
|
||||
}
|
||||
|
||||
|
||||
void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, double end_y) {
|
||||
double cx, cy, maxX, minX, maxY, minY, vx;
|
||||
bool isRangeX = (start_x != end_x), isRangeY = (start_y != end_y);
|
||||
|
||||
Reference in New Issue
Block a user