git-svn-id: svn://db.shs.com.ru/libs@536 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -18,21 +18,22 @@
|
||||
|
||||
#include "qglview.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QKeyEvent>
|
||||
|
||||
QGLView::QGLView(QWidget * parent): QGraphicsView(parent), fbo_selection(3) {
|
||||
setFrameShape(QFrame::NoFrame);
|
||||
setViewportUpdateMode(FullViewportUpdate);
|
||||
setCacheMode(CacheNone);
|
||||
setMouseTracking(true);
|
||||
setFocusPolicy(Qt::WheelFocus);
|
||||
setScene(new QGraphicsScene());
|
||||
setInteractive(true);
|
||||
_w = 0;
|
||||
|
||||
QGLView::QGLView(): OpenGLWindow(), fbo_selection(3) {
|
||||
// setFrameShape(QFrame::NoFrame);
|
||||
// setViewportUpdateMode(FullViewportUpdate);
|
||||
// setCacheMode(CacheNone);
|
||||
// setMouseTracking(true);
|
||||
// setFocusPolicy(Qt::WheelFocus);
|
||||
// setScene(new QGraphicsScene());
|
||||
// setInteractive(true);
|
||||
timer = 0;
|
||||
need_init_ = is_first_draw = true;
|
||||
objects_.is_root = true;
|
||||
objects_.view_ = this;
|
||||
painter_ = 0;
|
||||
backColor_ = Qt::black;
|
||||
hoverHaloColor_ = QColor(195, 140, 255, 96);
|
||||
selectionHaloColor_ = QColor(175, 255, 140);
|
||||
@@ -45,17 +46,18 @@ QGLView::QGLView(QWidget * parent): QGraphicsView(parent), fbo_selection(3) {
|
||||
shaders_supported = selecting_ = customMouseMove_ = false;
|
||||
sel_button = Qt::LeftButton;
|
||||
sel_mod = Qt::NoModifier;
|
||||
renderer_ = 0;
|
||||
renderer_ = nullptr;
|
||||
fps_cnt = 0;
|
||||
fps_tm = fps_ = 0.;
|
||||
sel_obj = hov_obj = 0;
|
||||
sel_obj = hov_obj = nullptr;
|
||||
fogDensity_ = fogEnd_ = 1.;
|
||||
fogStart_ = 0.;
|
||||
fogMode_ = Exp;
|
||||
hoverHaloFill_ = 0.333;
|
||||
selectionHaloFill_ = 0.5;
|
||||
//lmode = Simple;
|
||||
shader_select = shader_halo = 0;
|
||||
shader_select = shader_halo = nullptr;
|
||||
m_texture_manager = new GLTextureManager();
|
||||
setFeature(qglMSAA, false);
|
||||
setFeature(qglFXAA, false);
|
||||
setFeature(qglLinearFiltering, true);
|
||||
@@ -84,11 +86,11 @@ QGLView::QGLView(QWidget * parent): QGraphicsView(parent), fbo_selection(3) {
|
||||
setFeature(qglDepthOfFieldFocus, 1.);
|
||||
setFeature(qglDepthOfFieldDiaphragm, 8.);
|
||||
mouse_first = mouseSelect_ = hoverHalo_ = selectionHalo_ = true;
|
||||
fogEnabled_ = is_init = grabMouse_ = mouseRotate_ = mouseThis_ = shaders_bind = changed_ = false;
|
||||
fogEnabled_ = is_init = grabMouse_ = mouseRotate_ = shaders_bind = changed_ = false;
|
||||
rmode = GLObjectBase::Fill;
|
||||
sel_mode = QGLView::SingleSelection;
|
||||
sel_pen = QPen(Qt::black, 1, Qt::DashLine);
|
||||
sel_brush = QBrush(QColor(170, 100, 255, 120));
|
||||
// sel_pen = QPen(Qt::black, 1, Qt::DashLine);
|
||||
// sel_brush = QBrush(QColor(170, 100, 255, 120));
|
||||
camera().setAim(QVector3D(0,0,5.5));
|
||||
camera().setPos(QVector3D(10, 5, 5.5));
|
||||
camera().setName("Camera");
|
||||
@@ -103,20 +105,27 @@ QGLView::~QGLView() {
|
||||
stop();
|
||||
if (shader_select) delete shader_select;
|
||||
if (shader_halo) delete shader_halo;
|
||||
currentQGLView = 0;
|
||||
currentGLTextureManager = 0;
|
||||
//if (shader_rope != 0) delete shader_rope;
|
||||
delete m_texture_manager;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::addObject(QWidget * o, Qt::WindowFlags f) {
|
||||
scene()->addWidget(o, f)->setCacheMode(QGraphicsItem::ItemCoordinateCache);
|
||||
/*QList<QGraphicsItem * > il = collectGraphicItems();
|
||||
foreach (QGraphicsItem * i, il) {
|
||||
QGraphicsProxyWidget * p = qgraphicsitem_cast<QGraphicsProxyWidget * >(i);
|
||||
if (p == 0) continue;
|
||||
p->setCacheMode(QGraphicsItem::ItemCoordinateCache);
|
||||
}*/
|
||||
void QGLView::stop() {
|
||||
if (timer) killTimer(timer);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::start(double freq) {
|
||||
timer = startTimer(freq <= 0. ? 0 : 1000. / freq);
|
||||
}
|
||||
|
||||
|
||||
GLRendererBase * QGLView::renderer() {
|
||||
return renderer_;
|
||||
}
|
||||
|
||||
void QGLView::setRenderer(GLRendererBase * r, GLRendererBase ** prev) {
|
||||
if (prev != nullptr) *prev = renderer_;
|
||||
renderer_ = r;
|
||||
}
|
||||
|
||||
|
||||
@@ -130,15 +139,13 @@ void QGLView::addObject(GLObjectBase * o) {
|
||||
emit objectAdded(i);
|
||||
}
|
||||
if (is_init) {
|
||||
globMutex.lock();
|
||||
o->init();
|
||||
globMutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QGLView::removeObject(GLObjectBase * o, bool inChildren) {
|
||||
o->setView(0);
|
||||
o->setView(nullptr);
|
||||
if (inChildren)
|
||||
removeObjectInternal(o, &objects_);
|
||||
else
|
||||
@@ -151,8 +158,8 @@ void QGLView::clearObjects(bool deleteAll) {
|
||||
removeObject(camera_);
|
||||
objects_.clearChildren(deleteAll);
|
||||
addObject(camera());
|
||||
selectObject(0);
|
||||
hov_obj = 0;
|
||||
selectObject(nullptr);
|
||||
hov_obj = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -164,95 +171,22 @@ void QGLView::selectObject(GLObjectBase * o) {
|
||||
}
|
||||
|
||||
|
||||
void QGLView::drawBackground(QPainter * painter, const QRectF & rect) {
|
||||
if (setupViewport()) {
|
||||
QGraphicsView::drawBackground(painter_, rect);
|
||||
return;
|
||||
}
|
||||
painter_ = painter;
|
||||
if (is_first_draw) {
|
||||
//connect(context(), SIGNAL(aboutToBeDestroyed()), this, SLOT(glCleanup()));
|
||||
//resizeGL(viewport()->width(), viewport()->height());
|
||||
initializeGL();
|
||||
}
|
||||
is_first_draw = false;
|
||||
painter_->beginNativePainting();
|
||||
paintGL();
|
||||
painter_->endNativePainting();
|
||||
glDisableDepth();
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glReleaseTextures();
|
||||
painter_ = 0;
|
||||
QGraphicsView::drawBackground(painter, rect);
|
||||
void QGLView::resizeEvent(QResizeEvent * e) {
|
||||
resizeGL(width(), height());
|
||||
/* QWindow::resizeEvent(e);*/
|
||||
}
|
||||
|
||||
void QGLView::timerEvent(QTimerEvent *) {
|
||||
renderNow();
|
||||
if (ktm_.elapsed() < QApplication::keyboardInputInterval()) return;
|
||||
Qt::KeyboardModifiers km = QApplication::keyboardModifiers();
|
||||
foreach (int i, keys_)
|
||||
emit keyEvent((Qt::Key)i, km);
|
||||
}
|
||||
|
||||
|
||||
void QGLView::initializeGL() {
|
||||
//qDebug() << "init glview";
|
||||
//makeCurrent();
|
||||
#if QT_VERSION >= 0x050600
|
||||
initializeOpenGLFunctions();
|
||||
#endif
|
||||
currentQGLView = (__GLWidget__ * )viewport();
|
||||
currentGLTextureManager = &textures_manager;
|
||||
currentCamera = &camera();
|
||||
glEnable(GL_TEXTURE_MAX_ANISOTROPY_EXT);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glEnableDepth();
|
||||
glEnable(GL_CULL_FACE);
|
||||
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
|
||||
glActiveTextureChannel(3);
|
||||
glEnable(GL_TEXTURE_GEN_S);
|
||||
glEnable(GL_TEXTURE_GEN_T);
|
||||
glEnable(GL_TEXTURE_GEN_R);
|
||||
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
|
||||
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
|
||||
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
glActiveTextureChannel(0);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glCullFace(GL_BACK);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glColorMaterial(GL_FRONT, GL_DIFFUSE);
|
||||
|
||||
textures_manager.loadTextures();
|
||||
objects_.initInternal();
|
||||
checkCaps();
|
||||
|
||||
shader_select = new __GLShaderProgram__(context());
|
||||
shader_halo = new __GLShaderProgram__(context());
|
||||
//shader_rope = new __GLShaderProgram__(context());
|
||||
reloadThisShaders();
|
||||
is_init = true;
|
||||
resizeGL(viewport()->width(), viewport()->height());
|
||||
|
||||
//dynamic_cubemap.loadPathesFromDirectory("e");
|
||||
//dynamic_cubemap.load();
|
||||
/*dynamic_cubemap.loadFront("e/front.jpg");
|
||||
dynamic_cubemap.loadBack("e/back.jpg");
|
||||
dynamic_cubemap.loadLeft("e/left.jpg");
|
||||
dynamic_cubemap.loadRight("e/right.jpg");
|
||||
dynamic_cubemap.loadTop("e/top.jpg");
|
||||
dynamic_cubemap.loadBottom("e/bottom.jpg");*/
|
||||
//glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
|
||||
//GLuint t = 0;
|
||||
//createGLTexture(t, QImage("e/bottom.jpg"));
|
||||
//qDebug() << bindTexture(QImage("e/bottom.jpg"));
|
||||
|
||||
need_init_ = false;
|
||||
emit glInitializeDone();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::paintGL() {
|
||||
#if QT_VERSION >= 0x050600
|
||||
//initializeOpenGLFunctions();
|
||||
if (need_init_)
|
||||
initializeGL();
|
||||
#endif
|
||||
void QGLView::render() {
|
||||
QRect g_rect(QPoint(), size());
|
||||
emit glBeforePaint();
|
||||
//qDebug() << "paintGL";
|
||||
//QMutexLocker ml_v(&v_mutex);
|
||||
@@ -290,16 +224,16 @@ void QGLView::paintGL() {
|
||||
if (shaders_supported && shader_select->isLinked()) shader_select->release();
|
||||
uchar cgid[4] = {0, 0, 0, 0};
|
||||
uint iid = 0;
|
||||
GLObjectBase * so = 0;
|
||||
if (!rect().contains(lastPos)) {
|
||||
if (hov_obj != 0) {
|
||||
hov_obj = 0;
|
||||
emit hoverChanged(0, hov_obj);
|
||||
GLObjectBase * so = nullptr;
|
||||
if (!g_rect.contains(lastPos)) {
|
||||
if (hov_obj != nullptr) {
|
||||
hov_obj = nullptr;
|
||||
emit hoverChanged(nullptr, hov_obj);
|
||||
}
|
||||
} else {
|
||||
glReadPixels(lastPos.x(), viewport()->height() - lastPos.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, cgid);
|
||||
glReadPixels(lastPos.x(), height() - lastPos.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, cgid);
|
||||
iid = (cgid[0] << 24) | (cgid[1] << 16) | (cgid[2] << 8) | cgid[3];
|
||||
so = ids[iid];
|
||||
so = ids.value(iid, nullptr);
|
||||
//qDebug() <<cgid[0]<<cgid[1]<<cgid[2]<<cgid[3]<< iid;
|
||||
if (so != hov_obj) {
|
||||
emit hoverChanged(so, hov_obj);
|
||||
@@ -309,7 +243,7 @@ void QGLView::paintGL() {
|
||||
}
|
||||
if (selectionHalo_ && sel_obj) {
|
||||
fbo_selection.setWriteBuffer(2);
|
||||
renderHalo(sel_obj, ids.key(sel_obj), selectionHaloColor_, selectionHaloFill_);
|
||||
renderHalo(sel_obj, qHash((quint64)sel_obj), selectionHaloColor_, selectionHaloFill_);
|
||||
}
|
||||
if (hoverHalo_ && hov_obj) {
|
||||
fbo_selection.setWriteBuffer(1);
|
||||
@@ -327,18 +261,18 @@ void QGLView::paintGL() {
|
||||
cur_mvpm = start_rp.proj_matrix * start_rp.view_matrix * start_rp.cam_offset_matrix;
|
||||
//objects_.preparePos(camera());
|
||||
|
||||
static GLRendererBase * prev_rend = 0;
|
||||
static GLRendererBase * prev_rend = nullptr;
|
||||
glShadeModel(GL_SMOOTH);
|
||||
if (prev_rend != renderer_) {
|
||||
prev_rend = renderer_;
|
||||
if (renderer_ != 0) {
|
||||
renderer_->init(viewport()->width(), viewport()->height());
|
||||
renderer_->resize(viewport()->width(), viewport()->height());
|
||||
if (renderer_ != nullptr) {
|
||||
renderer_->init(width(), height());
|
||||
renderer_->resize(width(), height());
|
||||
renderer_->reloadShaders();
|
||||
}
|
||||
}
|
||||
emit glBeginPaint();
|
||||
if (renderer_ != 0) {
|
||||
if (renderer_ != nullptr) {
|
||||
renderer_->rp.prepare();
|
||||
renderer_->prepareScene();
|
||||
renderer_->renderScene();
|
||||
@@ -367,13 +301,6 @@ void QGLView::paintGL() {
|
||||
}
|
||||
}
|
||||
|
||||
if (selecting_ && painter_) {
|
||||
painter_->setPen(sel_pen);
|
||||
painter_->setBrush(sel_brush);
|
||||
painter_->drawRect(QRect(downPos, lastPos).normalized());
|
||||
qDebug() << QRect(downPos, lastPos).normalized();
|
||||
}
|
||||
|
||||
glReleaseShaders();
|
||||
glResetAllTransforms();
|
||||
glReleaseFramebuffer();
|
||||
@@ -419,12 +346,47 @@ void QGLView::paintGL() {
|
||||
fps_ = fps_cnt / fps_tm * 1000.;
|
||||
fps_tm = 0.;
|
||||
fps_cnt = 0;
|
||||
|
||||
//glResetAllTransforms();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::renderHalo(const GLObjectBase * obj, const int iid, const QColor & color, const double & fill) {
|
||||
void QGLView::initialize() {
|
||||
initializeOpenGLFunctions();
|
||||
glEnable(GL_TEXTURE_MAX_ANISOTROPY_EXT);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glEnableDepth();
|
||||
glEnable(GL_CULL_FACE);
|
||||
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
|
||||
glActiveTextureChannel(3);
|
||||
glEnable(GL_TEXTURE_GEN_S);
|
||||
glEnable(GL_TEXTURE_GEN_T);
|
||||
glEnable(GL_TEXTURE_GEN_R);
|
||||
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
|
||||
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
|
||||
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||
glActiveTextureChannel(0);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glCullFace(GL_BACK);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glColorMaterial(GL_FRONT, GL_DIFFUSE);
|
||||
|
||||
textures_manager.loadTextures();
|
||||
objects_.initInternal();
|
||||
checkCaps();
|
||||
|
||||
shader_select = new QOpenGLShaderProgram(context());
|
||||
shader_halo = new QOpenGLShaderProgram(context());
|
||||
reloadThisShaders();
|
||||
is_init = true;
|
||||
resizeGL(width(), height());
|
||||
need_init_ = false;
|
||||
emit glInitializeDone();
|
||||
}
|
||||
|
||||
|
||||
void QGLView::renderHalo(const GLObjectBase * obj, const uint iid, const QColor & color, const double & fill) {
|
||||
if (!shaders_supported) return;
|
||||
if (!shader_halo) return;
|
||||
if (!shader_halo->isLinked()) return;
|
||||
@@ -434,7 +396,7 @@ void QGLView::renderHalo(const GLObjectBase * obj, const int iid, const QColor &
|
||||
glActiveTextureChannel(0);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_selection.colorTexture());
|
||||
shader_halo->setUniformValue("t0", 0);
|
||||
shader_halo->setUniformValue("dt", QVector2D(1. / viewport()->width(), 1. / viewport()->height()));
|
||||
shader_halo->setUniformValue("dt", QVector2D(1. / width(), 1. / height()));
|
||||
shader_halo->setUniformValue("selected", QVector4D(float((iid >> 24) & 0xFF) / 255.f,
|
||||
float((iid >> 16) & 0xFF) / 255.f,
|
||||
float((iid >> 8) & 0xFF) / 255.f,
|
||||
@@ -454,7 +416,7 @@ void QGLView::renderHalo(const GLObjectBase * obj, const int iid, const QColor &
|
||||
|
||||
|
||||
void QGLView::renderSelection() {
|
||||
cid = 1;
|
||||
// cid = 1;
|
||||
ids.clear();
|
||||
if (shaders_supported) {
|
||||
if (shader_select) {
|
||||
@@ -480,28 +442,29 @@ void QGLView::renderSingleSelection(GLObjectBase & o) {
|
||||
}
|
||||
if (!o.visible_ || !o.select_) return;
|
||||
QMatrix4x4 curview = start_rp.view_matrix * start_rp.cam_offset_matrix * o.itransform_;
|
||||
ids.insert(cid, &o);
|
||||
uint id = qHash((quint64)&o);
|
||||
ids.insert(id, &o);
|
||||
if (shaders_supported){
|
||||
if (shader_select) {
|
||||
if (shader_select->isLinked()) {
|
||||
setUniformMatrices(shader_select, start_rp.proj_matrix, curview);
|
||||
shader_select->setUniformValue(sh_id_loc, QVector4D(float((cid >> 24) & 0xFF) / 255.f,
|
||||
float((cid >> 16) & 0xFF) / 255.f,
|
||||
float((cid >> 8) & 0xFF) / 255.f,
|
||||
float(cid & 0xFF) / 255.f));
|
||||
shader_select->setUniformValue(sh_id_loc, QVector4D(float((id >> 24) & 0xFF) / 255.f,
|
||||
float((id >> 16) & 0xFF) / 255.f,
|
||||
float((id >> 8) & 0xFF) / 255.f,
|
||||
float(id & 0xFF) / 255.f));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
setGLMatrix(curview);
|
||||
glColor4f(float((cid >> 24) & 0xFF) / 255.f,
|
||||
float((cid >> 16) & 0xFF) / 255.f,
|
||||
float((cid >> 8) & 0xFF) / 255.f,
|
||||
float(cid & 0xFF) / 255.f);
|
||||
glColor4f(float((id >> 24) & 0xFF) / 255.f,
|
||||
float((id >> 16) & 0xFF) / 255.f,
|
||||
float((id >> 8) & 0xFF) / 255.f,
|
||||
float(id & 0xFF) / 255.f);
|
||||
}
|
||||
//qDebug() << o.name() << "assign to" << sh_id_loc << cid;
|
||||
//glColor4f(float((cid >> 24) & 0xFF) / 255.f, float((cid >> 16) & 0xFF) / 255.f, float((cid >> 8) & 0xFF) / 255.f, float(cid & 0xFF) / 255.f);
|
||||
++cid;
|
||||
o.draw(0, true);
|
||||
// ++cid;
|
||||
o.draw(nullptr, true);
|
||||
foreach (GLObjectBase * i, o.children_)
|
||||
renderSingleSelection(*i);
|
||||
}
|
||||
@@ -515,25 +478,8 @@ void QGLView::collectLights() {
|
||||
|
||||
void QGLView::objectDeleted(GLObjectBase * o) {
|
||||
//qDebug() << "del" << o;
|
||||
if (sel_obj == o) selectObject(0);
|
||||
if (hov_obj == o) hov_obj = 0;
|
||||
}
|
||||
|
||||
|
||||
QList<QGraphicsItem * > QGLView::collectGraphicItems() {
|
||||
QList<QGraphicsItem * > list = scene()->items();
|
||||
foreach (QGraphicsItem * i, list)
|
||||
collectGraphicItems(list, i);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
void QGLView::collectGraphicItems(QList<QGraphicsItem * > & list, QGraphicsItem * o) {
|
||||
QList<QGraphicsItem * > cl = o->childItems();
|
||||
foreach (QGraphicsItem * i, cl) {
|
||||
list << i;
|
||||
collectGraphicItems(list, i);
|
||||
}
|
||||
if (sel_obj == o) selectObject(nullptr);
|
||||
if (hov_obj == o) hov_obj = nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -563,7 +509,7 @@ void QGLView::checkCaps() {
|
||||
//glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_texture_chanels);
|
||||
//qDebug() << max_texture_chanels;
|
||||
//qDebug() << max_texture_chanels;
|
||||
shaders_supported = __GLShaderProgram__::hasOpenGLShaderPrograms();
|
||||
shaders_supported = QOpenGLShaderProgram::hasOpenGLShaderPrograms();
|
||||
}
|
||||
|
||||
|
||||
@@ -605,10 +551,10 @@ void QGLView::resizeGL(int width, int height) {
|
||||
|
||||
|
||||
void QGLView::mouseReleaseEvent(QMouseEvent * e) {
|
||||
QGraphicsView::mouseReleaseEvent(e);
|
||||
// QGraphicsView::mouseReleaseEvent(e);
|
||||
//setCursor(QCursor(Qt::ArrowCursor));
|
||||
selecting_ = false;
|
||||
if (mouseThis_ && mouseSelect_ && e->button() == Qt::LeftButton) {
|
||||
if (mouseSelect_ && e->button() == Qt::LeftButton) {
|
||||
if ((lastPos - downPos).manhattanLength() < 8) {
|
||||
if (sel_obj != hov_obj)
|
||||
selectObject(hov_obj);
|
||||
@@ -619,14 +565,10 @@ void QGLView::mouseReleaseEvent(QMouseEvent * e) {
|
||||
|
||||
|
||||
void QGLView::mousePressEvent(QMouseEvent * e) {
|
||||
QGraphicsView::mousePressEvent(e);
|
||||
mouseThis_ = (scene()->itemAt(mapToScene(e->pos())
|
||||
#if QT_VERSION >= 0x050000
|
||||
, QTransform()
|
||||
#endif
|
||||
) == 0);
|
||||
// QGraphicsView::mousePressEvent(e);
|
||||
// mouseThis_ = (scene()->itemAt(mapToScene(e->pos()) , QTransform() ) == 0);
|
||||
selecting_ = false;
|
||||
if (!mouseThis_) return;
|
||||
if (!QRect(QPoint(), size()).contains(e->pos())) return;
|
||||
/// TODO select by rect
|
||||
//if (e->button() == sel_button && e->modifiers() == sel_mod)
|
||||
// selecting_ = true;
|
||||
@@ -638,16 +580,16 @@ void QGLView::mousePressEvent(QMouseEvent * e) {
|
||||
|
||||
|
||||
void QGLView::mouseMoveEvent(QMouseEvent * e) {
|
||||
//qDebug() << e->pos();
|
||||
QGraphicsView::mouseMoveEvent(e);
|
||||
// qDebug() << e->pos();
|
||||
// QGraphicsView::mouseMoveEvent(e);
|
||||
//lastPos = e->pos();
|
||||
if (selecting_) {
|
||||
|
||||
return;
|
||||
}
|
||||
if (!mouseThis_) return;
|
||||
//if (scene()->itemAt(mapToScene(e->pos())) != 0) return;
|
||||
///qDebug() << e->x() << e->y();
|
||||
QRect g_rect(QPoint(), size());
|
||||
if (mouseRotate_) {
|
||||
double dx = e->x() - lastPos.x();
|
||||
double dy = e->y() - lastPos.y();
|
||||
@@ -676,7 +618,7 @@ void QGLView::mouseMoveEvent(QMouseEvent * e) {
|
||||
lastPos = e->pos();
|
||||
if (grabMouse_) {
|
||||
//if (!isrunning) return;
|
||||
QCursor::setPos(mapToGlobal(rect().center()));
|
||||
QCursor::setPos(mapToGlobal(QRect(QPoint(), size()).center()));
|
||||
static bool mouse_sec = false;
|
||||
if (mouse_sec) {
|
||||
mouse_sec = false;
|
||||
@@ -688,7 +630,7 @@ void QGLView::mouseMoveEvent(QMouseEvent * e) {
|
||||
//qDebug() << "first" << e->pos();
|
||||
return;
|
||||
}
|
||||
lastPos = rect().center();
|
||||
lastPos = g_rect.center();
|
||||
int dx = e->x() - lastPos.x();
|
||||
int dy = e->y() - lastPos.y();
|
||||
emit glMouseMoveEvent(new QMouseEvent(QEvent::MouseMove, QPoint(dx, dy), e->button(), e->buttons(), e->modifiers()));
|
||||
@@ -699,12 +641,6 @@ void QGLView::mouseMoveEvent(QMouseEvent * e) {
|
||||
|
||||
|
||||
void QGLView::wheelEvent(QWheelEvent * e) {
|
||||
QGraphicsView::wheelEvent(e);
|
||||
if (scene()->itemAt(mapToScene(e->pos())
|
||||
#if QT_VERSION >= 0x050000
|
||||
, QTransform()
|
||||
#endif
|
||||
) != 0) return;
|
||||
if (mouseRotate_) {
|
||||
if (e->delta() > 0) camera().flyCloser(0.1); //camera().pos.setZ(camera().pos.z() - 0.1 * camera().pos.z());
|
||||
if (e->delta() < 0) camera().flyFarer(0.1); //camera().pos.setZ(camera().pos.z() + 0.1 * camera().pos.z());
|
||||
@@ -720,37 +656,19 @@ void QGLView::leaveEvent(QEvent * ) {
|
||||
}
|
||||
|
||||
|
||||
void QGLView::processKeys() {
|
||||
if (ktm_.elapsed() < QApplication::keyboardInputInterval()) return;
|
||||
Qt::KeyboardModifiers km = QApplication::keyboardModifiers();
|
||||
foreach (int i, keys_)
|
||||
emit keyEvent((Qt::Key)i, km);
|
||||
void QGLView::keyPressEvent(QKeyEvent * e) {
|
||||
emit glKeyPressEvent(e);
|
||||
if (e->key() > 0) keys_.insert(e->key());
|
||||
}
|
||||
|
||||
|
||||
bool QGLView::setupViewport() {
|
||||
if (_w) return false;
|
||||
#if QT_VERSION >= 0x050600
|
||||
_w = new __GLWidget__();
|
||||
QSurfaceFormat f = _w->format();
|
||||
f.setSamples(8);
|
||||
_w->setFormat(f);
|
||||
#else
|
||||
QGLFormat f(QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba | QGL::AlphaChannel | QGL::DirectRendering | QGL::SampleBuffers);
|
||||
f.setSwapInterval(1);
|
||||
_w = new __GLWidget__(f);
|
||||
#endif
|
||||
setViewport(_w);
|
||||
_w->setMouseTracking(true);
|
||||
return true;
|
||||
void QGLView::keyReleaseEvent(QKeyEvent * e) {
|
||||
emit glKeyReleaseEvent(e);
|
||||
keys_.remove(e->key());
|
||||
}
|
||||
|
||||
|
||||
void QGLView::glCleanup() {
|
||||
//qDebug() << "cleanup";
|
||||
/*disconnect(context(), SIGNAL(aboutToBeDestroyed()), this, SLOT(glCleanup()));
|
||||
is_first_draw = true;
|
||||
textures_manager = GLTextureManager();
|
||||
currentQGLView = 0;
|
||||
currentGLTextureManager = 0;*/
|
||||
void QGLView::focusOutEvent(QFocusEvent *)
|
||||
{keys_.clear();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user