git-svn-id: svn://db.shs.com.ru/libs@455 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
#include "graphic.h"
|
||||
#include "qad_types.h"
|
||||
#include "uglwidget.h"
|
||||
#include "ui_graphic.h"
|
||||
#include "ui_graphic_conf.h"
|
||||
#if QT_VERSION >= 0x050100
|
||||
//# include <QSensorGestureManager>
|
||||
#endif
|
||||
#ifndef GL_MULTISAMPLE
|
||||
# define GL_MULTISAMPLE 0x809D
|
||||
#ifndef Q_OS_ANDROID
|
||||
# define HAS_GL
|
||||
#endif
|
||||
#ifdef HAS_GL
|
||||
# ifndef GL_MULTISAMPLE
|
||||
# define GL_MULTISAMPLE 0x809D
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -54,20 +60,24 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), line_x_min(this), line_x_max
|
||||
connect(ui->canvas_raster, SIGNAL(wheelEvent(QWheelEvent * )), this, SLOT(canvasWheelEvent(QWheelEvent * )));
|
||||
connect(ui->canvas_raster, SIGNAL(leaveEvent(QEvent * )), this, SLOT(canvasLeaveEvent(QEvent * )));
|
||||
connect(ui->canvas_raster, SIGNAL(keyPressEvent(QKeyEvent * )), this, SLOT(canvasKeyPressEvent(QKeyEvent * )));
|
||||
connect(ui->canvas_gl, SIGNAL(paintSignal()), this, SLOT(canvasPaintEvent()));
|
||||
connect(ui->canvas_gl, SIGNAL(mouseMoveEvent(QMouseEvent * )), this, SLOT(canvasMouseMoveEvent(QMouseEvent * )));
|
||||
connect(ui->canvas_gl, SIGNAL(mousePressEvent(QMouseEvent * )), this, SLOT(canvasMousePressEvent(QMouseEvent * )));
|
||||
connect(ui->canvas_gl, SIGNAL(mouseReleaseEvent(QMouseEvent * )), this, SLOT(canvasMouseReleaseEvent(QMouseEvent * )));
|
||||
connect(ui->canvas_gl, SIGNAL(mouseDoubleClickEvent(QMouseEvent*)), this, SLOT(canvasMouseDoubleClickEvent(QMouseEvent * )));
|
||||
connect(ui->canvas_gl, SIGNAL(wheelEvent(QWheelEvent * )), this, SLOT(canvasWheelEvent(QWheelEvent * )));
|
||||
connect(ui->canvas_gl, SIGNAL(leaveEvent(QEvent * )), this, SLOT(canvasLeaveEvent(QEvent * )));
|
||||
connect(ui->canvas_gl, SIGNAL(keyPressEvent(QKeyEvent * )), this, SLOT(canvasKeyPressEvent(QKeyEvent * )));
|
||||
#ifdef HAS_GL
|
||||
canvas_gl = new UGLWidget();
|
||||
ui->layoutCanvas->addWidget(canvas_gl);
|
||||
connect(canvas_gl, SIGNAL(paintSignal()), this, SLOT(canvasPaintEvent()));
|
||||
connect(canvas_gl, SIGNAL(mouseMoveEvent(QMouseEvent * )), this, SLOT(canvasMouseMoveEvent(QMouseEvent * )));
|
||||
connect(canvas_gl, SIGNAL(mousePressEvent(QMouseEvent * )), this, SLOT(canvasMousePressEvent(QMouseEvent * )));
|
||||
connect(canvas_gl, SIGNAL(mouseReleaseEvent(QMouseEvent * )), this, SLOT(canvasMouseReleaseEvent(QMouseEvent * )));
|
||||
connect(canvas_gl, SIGNAL(mouseDoubleClickEvent(QMouseEvent*)), this, SLOT(canvasMouseDoubleClickEvent(QMouseEvent * )));
|
||||
connect(canvas_gl, SIGNAL(wheelEvent(QWheelEvent * )), this, SLOT(canvasWheelEvent(QWheelEvent * )));
|
||||
connect(canvas_gl, SIGNAL(leaveEvent(QEvent * )), this, SLOT(canvasLeaveEvent(QEvent * )));
|
||||
connect(canvas_gl, SIGNAL(keyPressEvent(QKeyEvent * )), this, SLOT(canvasKeyPressEvent(QKeyEvent * )));
|
||||
canvas_gl->grabGesture(Qt::PinchGesture);
|
||||
canvas_gl->grabGesture(Qt::PanGesture);
|
||||
canvas_gl->installEventFilter(this);
|
||||
#endif
|
||||
ui->canvas_raster->grabGesture(Qt::PinchGesture);
|
||||
ui->canvas_raster->grabGesture(Qt::PanGesture);
|
||||
ui->canvas_raster->installEventFilter(this);
|
||||
ui->canvas_gl->grabGesture(Qt::PinchGesture);
|
||||
ui->canvas_gl->grabGesture(Qt::PanGesture);
|
||||
ui->canvas_gl->installEventFilter(this);
|
||||
icon_exp_x = QIcon(":/icons/expand_x.png");
|
||||
icon_exp_y = QIcon(":/icons/expand_y.png");
|
||||
icon_exp_sx = QIcon(":/icons/expand_s_x.png");
|
||||
@@ -111,8 +121,8 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), line_x_min(this), line_x_max
|
||||
selpen.setStyle(Qt::DashLine);
|
||||
back_color = Qt::white;
|
||||
buttons_ = AllButtons;
|
||||
setButtonsPosition(Graphic::Left);
|
||||
setOpenGL(false);
|
||||
setButtonsPosition(Graphic::Left);
|
||||
setAntialiasing(false);
|
||||
setCaption("");
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
@@ -207,14 +217,14 @@ void Graphic::canvasPaintEvent() {
|
||||
//pwid = wid;
|
||||
//phei = hei;
|
||||
QPainter p;
|
||||
#ifdef HAS_GL
|
||||
if (isOGL) {
|
||||
#ifdef ANDROID
|
||||
p.fillRect(canvas->rect(), Qt::black);
|
||||
#else
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
#endif
|
||||
p.begin(canvas);
|
||||
} else p.begin(buffer);
|
||||
} else
|
||||
#endif
|
||||
p.begin(buffer);
|
||||
p.fillRect(canvas->rect(), back_color);
|
||||
painter = &p;
|
||||
p.setFont(font());
|
||||
@@ -231,12 +241,12 @@ void Graphic::canvasPaintEvent() {
|
||||
if (grid)
|
||||
drawGrid();
|
||||
p.setRenderHint(QPainter::Antialiasing, aalias);
|
||||
if (isOGL) {
|
||||
#ifndef ANDROID
|
||||
if (isOGL) {
|
||||
if (aalias) glEnable(GL_MULTISAMPLE);
|
||||
else glDisable(GL_MULTISAMPLE);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
//p.setRenderHint(QPainter::HighQualityAntialiasing, aalias);
|
||||
if (!aalias) p.translate(-0.5, -0.5);
|
||||
drawGraphics();
|
||||
@@ -305,7 +315,9 @@ void Graphic::canvasMouseMoveEvent(QMouseEvent * e) {
|
||||
void Graphic::canvasMousePressEvent(QMouseEvent * e) {
|
||||
emit graphicMousePressEvent(canvas2real(QPointF(e->pos())), e->buttons());
|
||||
if (!navigation) return;
|
||||
ui->canvas_gl->setCursor(guides ? Qt::BlankCursor : Qt::ArrowCursor);
|
||||
#ifdef HAS_GL
|
||||
canvas_gl->setCursor(guides ? Qt::BlankCursor : Qt::ArrowCursor);
|
||||
#endif
|
||||
ui->canvas_raster->setCursor(guides ? Qt::BlankCursor : Qt::ArrowCursor);
|
||||
prevpos = e->pos();
|
||||
startpos = prevpos;
|
||||
@@ -344,7 +356,9 @@ void Graphic::canvasMousePressEvent(QMouseEvent * e) {
|
||||
void Graphic::canvasMouseReleaseEvent(QMouseEvent * e) {
|
||||
emit graphicMouseReleaseEvent(canvas2real(QPointF(e->pos())), e->buttons());
|
||||
if (!navigation) return;
|
||||
ui->canvas_gl->setCursor(guides ? Qt::BlankCursor : Qt::ArrowCursor);
|
||||
#ifdef HAS_GL
|
||||
canvas_gl->setCursor(guides ? Qt::BlankCursor : Qt::ArrowCursor);
|
||||
#endif
|
||||
ui->canvas_raster->setCursor(guides ? Qt::BlankCursor : Qt::ArrowCursor);
|
||||
QPointF tlp, brp;
|
||||
QRect sr;
|
||||
@@ -467,9 +481,9 @@ void Graphic::clear() {
|
||||
void Graphic::setAntialiasing(bool enabled) {
|
||||
if (aalias == enabled) return;
|
||||
aalias = enabled;
|
||||
/*QGLFormat f = ui->canvas_gl->format();
|
||||
/*QGLFormat f = canvas_gl->format();
|
||||
f.setSampleBuffers(enabled);
|
||||
ui->canvas_gl->setFormat(f);*/
|
||||
canvas_gl->setFormat(f);*/
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -669,16 +683,22 @@ void Graphic::saveImage() {
|
||||
|
||||
|
||||
void Graphic::setOpenGL(bool on) {
|
||||
#ifdef HAS_GL
|
||||
isOGL = on;
|
||||
if (on) {
|
||||
ui->canvas_raster->hide();
|
||||
ui->canvas_gl->show();
|
||||
canvas = ui->canvas_gl;
|
||||
canvas_gl->show();
|
||||
canvas = canvas_gl;
|
||||
} else {
|
||||
ui->canvas_gl->hide();
|
||||
canvas_gl->hide();
|
||||
ui->canvas_raster->show();
|
||||
canvas = ui->canvas_raster;
|
||||
}
|
||||
#else
|
||||
isOGL = false;
|
||||
ui->canvas_raster->show();
|
||||
canvas = ui->canvas_raster;
|
||||
#endif
|
||||
/*line_x_min.setParent(canvas);
|
||||
line_x_max.setParent(canvas);
|
||||
line_y_min.setParent(canvas);
|
||||
@@ -1264,19 +1284,23 @@ void Graphic::setCurrentAction(GraphicAction action) {
|
||||
|
||||
void Graphic::setCanvasCursor(QCursor cursor) {
|
||||
ui->canvas_raster->setCursor(cursor);
|
||||
ui->canvas_gl->setCursor(cursor);
|
||||
#ifdef HAS_GL
|
||||
canvas_gl->setCursor(cursor);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void Graphic::swapToBuffer() {
|
||||
QImage timg;
|
||||
//qDebug() << "render start";
|
||||
#ifdef HAS_GL
|
||||
if (isOGL) {
|
||||
timg = ui->canvas_gl->grabFrameBuffer();
|
||||
timg = canvas_gl->grabFrameBuffer();
|
||||
QPainter p(buffer);
|
||||
p.drawImage(0, 0, timg);
|
||||
p.end();
|
||||
}
|
||||
#endif
|
||||
//qDebug() << "render finish";
|
||||
bufferActive = true;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace Ui {
|
||||
class Graphic;
|
||||
};
|
||||
|
||||
class UGLWidget;
|
||||
|
||||
class Graphic: public QFrame
|
||||
{
|
||||
@@ -343,6 +344,7 @@ protected:
|
||||
QPair<QString, QString> gridMark(double v) const;
|
||||
|
||||
Ui::Graphic * ui;
|
||||
UGLWidget * canvas_gl;
|
||||
///QMutex mutex, mutex_;
|
||||
QWidget * canvas;
|
||||
QImage * buffer;
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
<string>Grid</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../application/qad_application.qrc">
|
||||
<iconset resource="../widgets/qad_widgets.qrc">
|
||||
<normaloff>:/icons/view-grid.png</normaloff>:/icons/view-grid.png</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
@@ -81,7 +81,7 @@
|
||||
<string>Cursor axis</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../application/qad_application.qrc">
|
||||
<iconset resource="../widgets/qad_widgets.qrc">
|
||||
<normaloff>:/icons/edit-guides.png</normaloff>:/icons/edit-guides.png</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
@@ -95,7 +95,7 @@
|
||||
<string>Only expand Y</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../application/qad_application.qrc">
|
||||
<iconset resource="../widgets/qad_widgets.qrc">
|
||||
<normaloff>:/icons/expand_s_y.png</normaloff>:/icons/expand_s_y.png</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
@@ -109,7 +109,7 @@
|
||||
<string>Only expand X</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../application/qad_application.qrc">
|
||||
<iconset resource="../widgets/qad_widgets.qrc">
|
||||
<normaloff>:/icons/expand_s_x.png</normaloff>:/icons/expand_s_x.png</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
@@ -134,7 +134,7 @@
|
||||
<string>Border inputs</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../application/qad_application.qrc">
|
||||
<iconset resource="../widgets/qad_widgets.qrc">
|
||||
<normaloff>:/icons/border-line.png</normaloff>:/icons/border-line.png</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
@@ -151,7 +151,7 @@
|
||||
<string>Legend</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../application/qad_application.qrc">
|
||||
<iconset resource="../widgets/qad_widgets.qrc">
|
||||
<normaloff>:/icons/legend.png</normaloff>:/icons/legend.png</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
@@ -182,7 +182,7 @@
|
||||
<string>Configure ...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../application/qad_application.qrc">
|
||||
<iconset resource="../widgets/qad_widgets.qrc">
|
||||
<normaloff>:/icons/configure.png</normaloff>:/icons/configure.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -193,7 +193,7 @@
|
||||
<string>Save image ...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../application/qad_application.qrc">
|
||||
<iconset resource="../utils/qad_utils.qrc">
|
||||
<normaloff>:/icons/document-save.png</normaloff>:/icons/document-save.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -220,7 +220,7 @@
|
||||
<string>Clear</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../application/qad_application.qrc">
|
||||
<iconset resource="../utils/qad_utils.qrc">
|
||||
<normaloff>:/icons/edit-clear.png</normaloff>:/icons/edit-clear.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -231,7 +231,7 @@
|
||||
<string>Close</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../application/qad_application.qrc">
|
||||
<iconset resource="../widgets/qad_widgets.qrc">
|
||||
<normaloff>:/icons/dialog-close.png</normaloff>:/icons/dialog-close.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -338,13 +338,6 @@
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="UGLWidget" name="canvas_gl" native="true">
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="UWidget" name="canvas_raster" native="true">
|
||||
<property name="mouseTracking">
|
||||
@@ -439,14 +432,10 @@
|
||||
<extends>QWidget</extends>
|
||||
<header>uwidget.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>UGLWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>uglwidget.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../application/qad_application.qrc"/>
|
||||
<include location="../utils/qad_utils.qrc"/>
|
||||
<include location="../widgets/qad_widgets.qrc"/>
|
||||
<include location="../blockview/qad_blockview.qrc"/>
|
||||
<include location="qad_graphic.qrc"/>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user