version 2.24.0
Graphic setCustomSaveImageTitleFunc() - add custom title when save to image
This commit is contained in:
@@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
|||||||
cmake_policy(SET CMP0072 NEW) # FindOpenGL prefers GLVND by default
|
cmake_policy(SET CMP0072 NEW) # FindOpenGL prefers GLVND by default
|
||||||
project(QAD)
|
project(QAD)
|
||||||
set(QAD_MAJOR 2)
|
set(QAD_MAJOR 2)
|
||||||
set(QAD_MINOR 23)
|
set(QAD_MINOR 24)
|
||||||
set(QAD_REVISION 0)
|
set(QAD_REVISION 0)
|
||||||
set(QAD_SUFFIX )
|
set(QAD_SUFFIX )
|
||||||
set(QAD_COMPANY SHS)
|
set(QAD_COMPANY SHS)
|
||||||
|
|||||||
@@ -1133,8 +1133,24 @@ void Graphic::autofit() {
|
|||||||
|
|
||||||
void Graphic::saveImage(QString filename) {
|
void Graphic::saveImage(QString filename) {
|
||||||
ppath = filename;
|
ppath = filename;
|
||||||
QPixmap im(canvas->size());
|
QPixmap im;
|
||||||
canvas->render(&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);
|
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) {
|
void Graphic::findGraphicsRect(double start_x, double end_x, double start_y, double end_y) {
|
||||||
double cx, cy, maxX, minX, maxY, minY, vx;
|
double cx, cy, maxX, minX, maxY, minY, vx;
|
||||||
bool isRangeX = (start_x != end_x), isRangeY = (start_y != end_y);
|
bool isRangeX = (start_x != end_x), isRangeY = (start_y != end_y);
|
||||||
|
|||||||
@@ -380,6 +380,7 @@ public slots:
|
|||||||
void setGraphicsCount(int arg, bool update = true);
|
void setGraphicsCount(int arg, bool update = true);
|
||||||
void removeGraphic(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 setCustomGridMarkFuncs(std::function<QString(double val)> fx, std::function<QString(double val)> fy);
|
||||||
|
void setCustomSaveImageTitleFunc(std::function<QString()> func);
|
||||||
|
|
||||||
void zoom(float factor);
|
void zoom(float factor);
|
||||||
void zoomIn() { zoom(1. / 1.2); }
|
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,
|
bool hasLblX, hasLblY, navigation, only_expand_y, only_expand_x, is_lines_update, leg_update, visible_update, fullscr, need_mouse_pan,
|
||||||
was_trace;
|
was_trace;
|
||||||
std::function<QString(double val)> func_gridMarkX, func_gridMarkY;
|
std::function<QString(double val)> func_gridMarkX, func_gridMarkY;
|
||||||
|
std::function<QString()> func_image_title;
|
||||||
QVector<DateFormats> date_formats;
|
QVector<DateFormats> date_formats;
|
||||||
QList<QImage> record_imgs;
|
QList<QImage> record_imgs;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user