version 2.24.0

Graphic setCustomSaveImageTitleFunc() - add custom title when save to image
This commit is contained in:
2024-02-27 14:43:36 +03:00
parent 12f0603413
commit 03f8452512
3 changed files with 26 additions and 3 deletions

View File

@@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake
cmake_policy(SET CMP0072 NEW) # FindOpenGL prefers GLVND by default
project(QAD)
set(QAD_MAJOR 2)
set(QAD_MINOR 23)
set(QAD_MINOR 24)
set(QAD_REVISION 0)
set(QAD_SUFFIX )
set(QAD_COMPANY SHS)

View File

@@ -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);

View File

@@ -380,6 +380,7 @@ public slots:
void setGraphicsCount(int arg, bool update = true);
void removeGraphic(int arg, bool update = true);
void setCustomGridMarkFuncs(std::function<QString(double val)> fx, std::function<QString(double val)> fy);
void setCustomSaveImageTitleFunc(std::function<QString()> func);
void zoom(float factor);
void zoomIn() { zoom(1. / 1.2); }
@@ -475,6 +476,7 @@ protected:
bool hasLblX, hasLblY, navigation, only_expand_y, only_expand_x, is_lines_update, leg_update, visible_update, fullscr, need_mouse_pan,
was_trace;
std::function<QString(double val)> func_gridMarkX, func_gridMarkY;
std::function<QString()> func_image_title;
QVector<DateFormats> date_formats;
QList<QImage> record_imgs;