git-svn-id: svn://db.shs.com.ru/libs@710 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2020-01-19 20:29:11 +00:00
parent 88a45580a1
commit a17a46db40
7 changed files with 2274 additions and 225 deletions

View File

@@ -3,6 +3,8 @@
#include "uglwidget.h"
#include "ui_graphic.h"
#include "ui_graphic_conf.h"
#include <QMetaObject>
#include <QMessageBox>
#if QT_VERSION < 0x050000
# include <QTapAndHoldGesture>
# include <QPanGesture>
@@ -22,6 +24,7 @@ __GraphicRegistrator__ __graphic_registrator__;
Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this), line_x_max(this), line_y_min(this), line_y_max(this) {
canvas_gl = 0;
QTranslator * trans = new QTranslator();
trans->load(":/lang/qad_graphic_" + QLocale::system().name().left(2));
if (trans->isEmpty())
@@ -32,6 +35,7 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this),
#else
qApp->installTranslator(trans);
#endif
fullscr_dialog = 0;
gesture_angle = 45.;
leg_update = true;
visible_update = fullscr = need_mouse_pan = false;
@@ -166,10 +170,13 @@ bool Graphic::eventFilter(QObject * o, QEvent * e) {
foreach (QGesture * g, ((QGestureEvent*)e)->gestures())
procGesture(g);
break;
case QEvent::KeyPress:
if (((QKeyEvent*)e)->key() == Qt::Key_Back)
case QEvent::KeyPress: {
int k = ((QKeyEvent*)e)->key();
if ((k == Qt::Key_Back || k == Qt::Key_Escape) && fullscr) {
leaveFullscreen();
break;
return true;
}
} break;
case QEvent::TouchBegin:
if (!navigation || !gestures) break;
need_mouse_pan = true;
@@ -185,7 +192,25 @@ bool Graphic::eventFilter(QObject * o, QEvent * e) {
} break;
default: break;
}
}
} /*else {
if (fullscr) {
switch (e->type()) {
case QEvent::KeyPress:
if ((((QKeyEvent*)e)->key() != Qt::Key_Back) || !fullscr)
break;
case QEvent::Close:
leaveFullscreen();
return true;
case QEvent::OrientationChange:
case QEvent::Resize: {
QWidget * rw = canvas->parentWidget();
if (rw)
canvas->setGeometry(0, 0, rw->width(), rw->height());
} break;
default: break;
}
}
}*/
return QFrame::eventFilter(o, e);
}
@@ -233,7 +258,7 @@ void Graphic::procGesture(QGesture * g) {
case Qt::TapAndHoldGesture: {
QTapAndHoldGesture * pg = (QTapAndHoldGesture*)g;
if (pg->state() == Qt::GestureStarted)
fullscreen();
QMetaObject::invokeMethod(this, "enterFullscreen", Qt::QueuedConnection);
} break;
default:
qDebug() << g;
@@ -273,6 +298,7 @@ void Graphic::canvasPaintEvent() {
//QMutexLocker ml(&mutex_);
//static int pwid = 0, phei = 0;
int wid = canvas->width(), hei = canvas->height();
if (canvas->isHidden() || wid <= 1 || hei <= 1) return;
lastw = wid;
lasth = hei;
font_sz = fontMetrics().size(0, "0");
@@ -1274,7 +1300,7 @@ void Graphic::drawGuides() {
void Graphic::drawPause() {
painter->setClipping(false);
painter->save();
painter->resetMatrix();
painter->resetTransform();
painter->translate(canvas->width() - icon_pause_b.width() - 6, 6);
double o = (0.5 - pause_phase) * 2;
painter->setOpacity(o*o);
@@ -1677,7 +1703,7 @@ void Graphic::graphicVisibleChange(bool checked) {
if (isFit) on_buttonAutofit_clicked();
else update();
emit graphicSettingsChanged();
// update();
//update();
}
@@ -1696,21 +1722,48 @@ void Graphic::graphicAllVisibleChange(bool checked) {
void Graphic::enterFullscreen() {
if (fullscr) return;
//QMessageBox::information(0, "", "enter");
fullscr = true;
canvas->hide();
#ifdef Q_OS_ANDROID
tm_fscr.restart();
QDialog dlg;
dlg.setLayout(new QBoxLayout(QBoxLayout::TopToBottom));
dlg.layout()->setContentsMargins(0, 0, 0, 0);
dlg.layout()->addWidget(canvas);
QPushButton * btn = new QPushButton("Leave fullscreen");
dlg.layout()->addWidget(btn);
connect(btn, SIGNAL(clicked(bool)), this, SLOT(leaveFullscreen()));
//connect(fullscr_dialog, SIGNAL(finished(int)), this, SLOT(leaveFullscreen()));
canvas->show();
dlg.showFullScreen();
dlg.exec();
dlg.layout()->removeWidget(canvas);
leaveFullscreen();
#else
ui->layoutCanvas->removeWidget(canvas);
canvas->setParent(0);
canvas->showFullScreen();
canvas->setFocus();
canvas->raise();
fullscr = true;
#endif
}
void Graphic::leaveFullscreen() {
#ifdef Q_OS_ANDROID
if (tm_fscr.elapsed() < 100) return;
#endif
if (!fullscr) return;
canvas->setWindowFlags(canvas->windowFlags() & ~Qt::WindowFullScreen);
//QMessageBox::information(0, "", "leave");
fullscr = false;
//canvas->hide();
#ifndef Q_OS_ANDROID
canvas->showNormal();
canvas->hide();
#endif
ui->layoutCanvas->addWidget(canvas);
canvas->show();
fullscr = false;
}