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:
@@ -1 +1 @@
|
||||
qad_library(graphic "Gui;Widgets;OpenGL" "qad_widgets;${OPENGL_LIBRARIES}")
|
||||
qad_library(graphic "Gui;Widgets;OpenGL;OpenGLWidgets" "qad_widgets;${OPENGL_LIBRARIES}")
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -124,19 +124,20 @@ public:
|
||||
|
||||
typedef QVector<QVector<QPointF> > GraphicsData;
|
||||
enum GraphicAction {gaNone, gaZoomInRect, gaZoomRangeX, gaZoomRangeY, gaMove};
|
||||
enum Button {NoButtons = 0x0,
|
||||
AllButtons = 0xFFFFFFFF,
|
||||
Autofit = 0x01,
|
||||
Grid = 0x02,
|
||||
CursorAxis = 0x04,
|
||||
Fullscreen = 0x20,
|
||||
enum Button {NoButtons = 0x0,
|
||||
AllButtons = 0xFFFFFFFF,
|
||||
Autofit = 0x01,
|
||||
Grid = 0x02,
|
||||
CursorAxis = 0x04,
|
||||
Fullscreen = 0x20,
|
||||
BorderInputs = 0x40,
|
||||
Legend = 0x80,
|
||||
Configure = 0x100,
|
||||
Save = 0x200,
|
||||
Clear = 0x800,
|
||||
Close = 0x1000,
|
||||
Pause = 0x2000,
|
||||
Legend = 0x80,
|
||||
Configure = 0x100,
|
||||
Save = 0x200,
|
||||
Export = 0x400,
|
||||
Clear = 0x800,
|
||||
Close = 0x1000,
|
||||
Pause = 0x2000,
|
||||
StandartButtons = 0x2FFF
|
||||
};
|
||||
enum Alignment {Left, Right};
|
||||
@@ -314,9 +315,11 @@ public slots:
|
||||
void setVisualRect(const QRectF & rect);
|
||||
void setDefaultRect(const QRectF & rect);
|
||||
void autofit() {on_graphic_buttonAutofit_clicked();}
|
||||
void saveImage();
|
||||
void saveImage(QString filename);
|
||||
void exportGraphics(QString filename);
|
||||
void clear();
|
||||
void update(bool force = false);
|
||||
void update(bool force);
|
||||
void update() {update(false);}
|
||||
void updateGraphics() {findGraphicsRect(); update();}
|
||||
void setCurrentGraphic(int arg) {if (arg < 0 || arg >= graphics.size()) return; curGraphic = arg;}
|
||||
void setTraceGraphic(int arg) {if (arg < 0 || arg >= graphics.size()) return; curTrace = arg;}
|
||||
@@ -421,7 +424,8 @@ protected slots:
|
||||
void on_graphic_buttonAutofit_clicked();
|
||||
void on_graphic_buttonConfigure_clicked();
|
||||
void on_graphic_buttonFullscreen_clicked() {fullscreen();}
|
||||
void on_graphic_buttonSave_clicked() {saveImage();}
|
||||
void on_graphic_buttonSave_clicked();
|
||||
void on_graphic_buttonExport_clicked();
|
||||
void on_graphic_checkGrid_toggled(bool checked) {grid = checked; update();}
|
||||
void on_graphic_checkGuides_toggled(bool checked);
|
||||
void on_graphic_actionExpandX_triggered(bool checked);
|
||||
@@ -462,7 +466,9 @@ public:
|
||||
__GraphicRegistrator__() {
|
||||
qRegisterMetaType<QVector<QPointF> >("QVector<QPointF>");
|
||||
qRegisterMetaType<Graphic::GraphicsData>("Graphic::GraphicsData");
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
qRegisterMetaTypeStreamOperators<Graphic::GraphicsData>("Graphic::GraphicsData");
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>564</width>
|
||||
<height>484</height>
|
||||
<width>575</width>
|
||||
<height>440</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
@@ -180,6 +180,17 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="graphic_buttonExport">
|
||||
<property name="toolTip">
|
||||
<string>Export graphics ...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../blockview/qad_blockview.qrc">
|
||||
<normaloff>:/icons/document-edit.png</normaloff>:/icons/document-edit.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
|
||||
@@ -20,7 +20,11 @@ private:
|
||||
if (e->type() != QEvent::Paint) return QWidget::event(e);
|
||||
e->accept();
|
||||
QStyleOption opt;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
opt.init(this);
|
||||
#else
|
||||
opt.initFrom(this);
|
||||
#endif
|
||||
QPainter p(this);
|
||||
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
||||
emit paintEvent((QPaintEvent * )e);
|
||||
|
||||
Reference in New Issue
Block a user