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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user