version 2.0.0_alpha

Important! All QtWraps macros renamed!
Qt 6 support
Graphic export feature
qad_types cross-Qt small changes
This commit is contained in:
2021-03-05 13:05:23 +03:00
parent add26cf9ad
commit 7b011ed242
46 changed files with 815 additions and 219 deletions

View File

@@ -212,10 +212,20 @@ bool Graphic::eventFilter(QObject * o, QEvent * e) {
break;
case QEvent::TouchUpdate: {
if (!navigation || !gestures) break;
QList<QTouchEvent::TouchPoint> tpl = ((QTouchEvent*)e)->touchPoints();
QList<QTouchEvent::TouchPoint> tpl =
#if QT_VERSION_MAJOR <= 5
((QTouchEvent*)e)->touchPoints();
#else
((QTouchEvent*)e)->points();
#endif
if (tpl.size() == 2) {
need_mouse_pan = false;
QPointF dp = tpl[0].scenePos() - tpl[1].scenePos();
QPointF dp =
#if QT_VERSION_MAJOR <= 5
tpl[0].scenePos() - tpl[1].scenePos();
#else
tpl[0].scenePosition() - tpl[1].scenePosition();
#endif
gesture_angle = rad2deg_qpie * qAtan2(qAbs(dp.y()), qAbs(dp.x()));
}
} break;
@@ -432,7 +442,7 @@ void Graphic::canvasMousePressEvent(QMouseEvent * e) {
startpos = prevpos;
startpos_r = canvas2real(startpos);
if (cancel || gestures) return;
if (e->button() == Qt::MidButton) curaction = gaMove;
if (e->button() == QT_MID_BUTTON) curaction = gaMove;
if (e->button() == Qt::RightButton) {
if (bufferActive) {
curpos = startpos;
@@ -700,6 +710,7 @@ void Graphic::setButtons(Graphic::Buttons b) {
ui->graphic_buttonClear->setVisible(b.testFlag(Clear));
ui->graphic_buttonConfigure->setVisible(b.testFlag(Configure));
ui->graphic_buttonSave->setVisible(b.testFlag(Save));
ui->graphic_buttonExport->setVisible(b.testFlag(Export));
ui->graphic_buttonClose->setVisible(b.testFlag(Close));
ui->graphic_checkPause->setVisible(b.testFlag(Pause));
if (ui->graphic_buttonAutofit ->isVisible() || ui->graphic_checkGrid ->isVisible() || ui->graphic_checkGuides->isVisible() ||
@@ -793,10 +804,8 @@ void Graphic::setDefaultRect(const QRectF & rect) {
}
void Graphic::saveImage() {
QString str = QFileDialog::getSaveFileName(this, tr("Save Image"), ppath, "PNG(*.png);;JPEG(*.jpg *.jpeg);;BMP(*.bmp);;TIFF(*.tiff *.tif);;PPM(*.ppm)");
if (str == "") return;
ppath = str;
void Graphic::saveImage(QString filename) {
ppath = filename;
QPixmap im(canvas->size());
canvas->render(&im);
im.save(ppath);
@@ -804,6 +813,50 @@ void Graphic::saveImage() {
}
void Graphic::exportGraphics(QString filename) {
ppath = filename;
QFile f(filename);
if (!f.open(QIODevice::ReadWrite)) {
QMessageBox::critical(this, tr("Export graphics"), tr("Can`t open file \"%1\"!").arg(filename));
return;
}
f.resize(0);
QTextStream ts(&f);
ts << "#";
for (int i = 0; i < graphics.size(); ++i) {
GraphicType & g(graphics[i]);
if (!g.visible) continue;
ts << ";" << (g.name + "_X") << ";" << (g.name + "_Y");
}
ts << "\n";
bool has_data = true;
int ind = 0;
QString line;
while (has_data) {
has_data = false;
line.clear();
line += QString::number(ind + 1);
for (int i = 0; i < graphics.size(); ++i) {
GraphicType & g(graphics[i]);
if (!g.visible) continue;
if (ind >= g.polyline.size()) {
line += ";;";
continue;
}
has_data = true;
line += ";";
line += QString::number(g.polyline[ind].x(), 'g', 9);
line += ";";
line += QString::number(g.polyline[ind].y(), 'g', 9);
}
++ind;
line += "\n";
if (has_data)
ts << line;
}
}
void Graphic::setOpenGL(bool on) {
#ifdef HAS_GL
isOGL = on;
@@ -1546,6 +1599,20 @@ void Graphic::on_graphic_buttonConfigure_clicked() {
}
void Graphic::on_graphic_buttonSave_clicked() {
QString f = QFileDialog::getSaveFileName(this, tr("Save Image"), ppath, "PNG(*.png);;JPEG(*.jpg *.jpeg);;BMP(*.bmp);;TIFF(*.tiff *.tif);;PPM(*.ppm)");
if (f.isEmpty()) return;
saveImage(f);
}
void Graphic::on_graphic_buttonExport_clicked() {
QString f = QFileDialog::getSaveFileName(this, tr("Export graphics"), ppath, "CSV(*.csv)");
if (f.isEmpty()) return;
exportGraphics(f);
}
void Graphic::on_graphic_checkGuides_toggled(bool checked) {
guides = checked;
setGuidesCursor();