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

This commit is contained in:
2017-06-15 14:31:12 +00:00
parent 10f8898d2e
commit 4e90eef9bc

View File

@@ -166,11 +166,11 @@ bool Graphic::eventFilter(QObject * o, QEvent * e) {
//qDebug() << "event" << o << e; //qDebug() << "event" << o << e;
if (o == canvas) { if (o == canvas) {
switch (e->type()) { switch (e->type()) {
case QEvent::Gesture: case QEvent::Gesture:
foreach (QGesture * g, ((QGestureEvent*)e)->gestures()) foreach (QGesture * g, ((QGestureEvent*)e)->gestures())
procGesture(g); procGesture(g);
break; break;
default: break; default: break;
} }
} }
return QFrame::eventFilter(o, e); return QFrame::eventFilter(o, e);
@@ -265,34 +265,34 @@ void Graphic::canvasMouseMoveEvent(QMouseEvent * e) {
if (!navigation) return; if (!navigation) return;
if (curaction != gaMove && (e->buttons() & Qt::RightButton) == Qt::RightButton) return; if (curaction != gaMove && (e->buttons() & Qt::RightButton) == Qt::RightButton) return;
switch (curaction) { switch (curaction) {
case gaZoomInRect: case gaZoomInRect:
ui->status->setText(tr("Selection") + ": " + pointCoords(srp) + " -> " + ui->status->setText(tr("Selection") + ": " + pointCoords(srp) + " -> " +
pointCoords(crp) + ", " + tr("Size") + ": " + pointCoords(absPoint(crp - srp))); pointCoords(crp) + ", " + tr("Size") + ": " + pointCoords(absPoint(crp - srp)));
repaintCanvas(true); repaintCanvas(true);
break; break;
case gaZoomRangeX: case gaZoomRangeX:
ui->status->setText(tr("Range") + ": " + QString::number(srp.x(), 'f', 3) + ui->status->setText(tr("Range") + ": " + QString::number(srp.x(), 'f', 3) +
" -> " + QString::number(crp.x(), 'f', 3) + ", " + tr("Length") + ": " + " -> " + QString::number(crp.x(), 'f', 3) + ", " + tr("Length") + ": " +
QString::number(qAbs(crp.x() - srp.x()), 'f', 3)); QString::number(qAbs(crp.x() - srp.x()), 'f', 3));
repaintCanvas(true); repaintCanvas(true);
break; break;
case gaZoomRangeY: case gaZoomRangeY:
ui->status->setText(tr("Range") + ": " + QString::number(srp.y(), 'f', 3) + ui->status->setText(tr("Range") + ": " + QString::number(srp.y(), 'f', 3) +
" -> " + QString::number(crp.y(), 'f', 3) + ", " + tr("Length") + ": " + " -> " + QString::number(crp.y(), 'f', 3) + ", " + tr("Length") + ": " +
QString::number(qAbs(crp.y() - srp.y()), 'f', 3)); QString::number(qAbs(crp.y() - srp.y()), 'f', 3));
repaintCanvas(true); repaintCanvas(true);
break; break;
case gaMove: case gaMove:
dp = e->pos() - prevpos; dp = e->pos() - prevpos;
dp.rx() *= selrect.width() / double(gridborder.x() + 5 - lastw); dp.rx() *= selrect.width() / double(gridborder.x() + 5 - lastw);
dp.ry() *= selrect.height() / double(lasth - legy - gridborder.y() - 5); dp.ry() *= selrect.height() / double(lasth - legy - gridborder.y() - 5);
selrect.translate(dp); selrect.translate(dp);
isFit = false; isFit = false;
emit visualRectChanged(); emit visualRectChanged();
update(true); update(true);
setRectToLines(); setRectToLines();
break; break;
default: break; default: break;
} }
prevpos = e->pos(); prevpos = e->pos();
} }
@@ -325,12 +325,12 @@ void Graphic::canvasMousePressEvent(QMouseEvent * e) {
else if (e->modifiers() == Qt::ShiftModifier) curaction = gaZoomRangeY; else if (e->modifiers() == Qt::ShiftModifier) curaction = gaZoomRangeY;
else curaction = gaZoomInRect; else curaction = gaZoomInRect;
switch (curaction) { switch (curaction) {
case gaZoomInRect: case gaZoomInRect:
case gaZoomRangeX: case gaZoomRangeX:
case gaZoomRangeY: case gaZoomRangeY:
swapToBuffer(); swapToBuffer();
break; break;
default: break; default: break;
} }
} }
setCurrentAction(curaction); setCurrentAction(curaction);
@@ -359,20 +359,20 @@ void Graphic::canvasMouseReleaseEvent(QMouseEvent * e) {
brp = canvas2real(sr.bottomRight()); brp = canvas2real(sr.bottomRight());
isFit = false; isFit = false;
switch (curaction) { switch (curaction) {
case gaZoomInRect: case gaZoomInRect:
if (sr.width() <= 1 || sr.height() <= 1) break; if (sr.width() <= 1 || sr.height() <= 1) break;
selrect.setCoords(tlp.x(), brp.y(), brp.x(), tlp.y()); selrect.setCoords(tlp.x(), brp.y(), brp.x(), tlp.y());
setRectToLines(); setRectToLines();
break; break;
case gaZoomRangeX: case gaZoomRangeX:
if (sr.width() <= 1) break; if (sr.width() <= 1) break;
findGraphicsRect(tlp.x(), brp.x()); findGraphicsRect(tlp.x(), brp.x());
break; break;
case gaZoomRangeY: case gaZoomRangeY:
if (sr.height() <= 1) break; if (sr.height() <= 1) break;
findGraphicsRect(0., 0., brp.y(), tlp.y()); findGraphicsRect(0., 0., brp.y(), tlp.y());
break; break;
default: return; default: return;
} }
} }
swapToNormal(); swapToNormal();
@@ -442,8 +442,8 @@ void Graphic::canvasLeaveEvent(QEvent * ) {
void Graphic::canvasKeyPressEvent(QKeyEvent * e) { void Graphic::canvasKeyPressEvent(QKeyEvent * e) {
switch (e->key()) { switch (e->key()) {
case Qt::Key_Escape: leaveFullscreen(); case Qt::Key_Escape: leaveFullscreen();
default: break; default: break;
}; };
} }
@@ -568,13 +568,13 @@ void Graphic::setButtonsPosition(Graphic::Alignment a) {
ui->widgetLeft->hide(); ui->widgetLeft->hide();
ui->widgetRight->hide(); ui->widgetRight->hide();
switch (a) { switch (a) {
case Graphic::Left: case Graphic::Left:
ui->widgetLeft->setLayout(ui->layoutButtons); ui->widgetLeft->setLayout(ui->layoutButtons);
ui->widgetLeft->show(); ui->widgetLeft->show();
break; break;
case Graphic::Right: case Graphic::Right:
ui->widgetRight->setLayout(ui->layoutButtons); ui->widgetRight->setLayout(ui->layoutButtons);
ui->widgetRight->show(); ui->widgetRight->show();
break; break;
} }
} }
@@ -692,8 +692,8 @@ void Graphic::setGraphicsCount(int arg, bool update) {
void Graphic::setHistogramData(const QVector<float> & g, int graphic) { void Graphic::setHistogramData(const QVector<float> & g, int graphic) {
graphics[graphic].polyline.clear(); graphics[graphic].polyline.clear();
if (g.isEmpty()) { if (g.isEmpty()) {
return; return;
} }
QVector<float> data = g; QVector<float> data = g;
@@ -820,20 +820,20 @@ void Graphic::drawAction() {
painter->setPen(selpen); painter->setPen(selpen);
painter->setBrush(selbrush); painter->setBrush(selbrush);
switch (curaction) { switch (curaction) {
case gaZoomInRect: case gaZoomInRect:
painter->drawRect(QRect(startpos, curpos)); painter->drawRect(QRect(startpos, curpos));
break; break;
case gaZoomRangeX: case gaZoomRangeX:
painter->drawLine(sx, hei, sx, 0); painter->drawLine(sx, hei, sx, 0);
painter->drawLine(cx, hei, cx, 0); painter->drawLine(cx, hei, cx, 0);
painter->fillRect(sx, 0, cx - sx, hei, selbrush); painter->fillRect(sx, 0, cx - sx, hei, selbrush);
break; break;
case gaZoomRangeY: case gaZoomRangeY:
painter->drawLine(gridborder.x(), sy, wid, sy); painter->drawLine(gridborder.x(), sy, wid, sy);
painter->drawLine(gridborder.x(), cy, wid, cy); painter->drawLine(gridborder.x(), cy, wid, cy);
painter->fillRect(gridborder.x(), sy, wid - gridborder.x(), cy - sy, selbrush); painter->fillRect(gridborder.x(), sy, wid - gridborder.x(), cy - sy, selbrush);
break; break;
default: break; default: break;
} }
} }
@@ -853,7 +853,7 @@ void Graphic::drawGrid() {
cy = 0; cy = 0;
cx = gbx - 5; cx = gbx - 5;
grid_pen.setWidth(qMax<int>(qRound(thick / 1.4), 1)); grid_pen.setWidth(qMax<int>(qRound(thick / 1.4), 1));
QFont sf = font(); QFont sf = font();
QFont nf = sf; QFont nf = sf;
sf.setPointSizeF(qMax<qreal>(sf.pointSizeF() / 1.6, 7.)); sf.setPointSizeF(qMax<qreal>(sf.pointSizeF() / 1.6, 7.));
QFontMetrics fm(nf), sfm(sf); QFontMetrics fm(nf), sfm(sf);
@@ -1185,21 +1185,21 @@ double Graphic::real2canvasY(double py) const {
void Graphic::setCurrentAction(GraphicAction action) { void Graphic::setCurrentAction(GraphicAction action) {
curaction = action; curaction = action;
switch (action) { switch (action) {
case gaNone: case gaNone:
if (guides) setCanvasCursor(Qt::BlankCursor); if (guides) setCanvasCursor(Qt::BlankCursor);
else setCanvasCursor(Qt::ArrowCursor); else setCanvasCursor(Qt::ArrowCursor);
break; break;
case gaZoomInRect: case gaZoomInRect:
setCanvasCursor(Qt::CrossCursor); setCanvasCursor(Qt::CrossCursor);
break; break;
case gaZoomRangeX: case gaZoomRangeX:
setCanvasCursor(Qt::SplitHCursor); setCanvasCursor(Qt::SplitHCursor);
break; break;
case gaZoomRangeY: case gaZoomRangeY:
setCanvasCursor(Qt::SplitVCursor); setCanvasCursor(Qt::SplitVCursor);
break; break;
case gaMove: case gaMove:
setCanvasCursor(Qt::SizeAllCursor); setCanvasCursor(Qt::SizeAllCursor);
break; break;
} }
} }
@@ -1350,16 +1350,18 @@ void Graphic::on_checkGuides_toggled(bool checked) {
void Graphic::updateLegend(bool es) { void Graphic::updateLegend(bool es) {
if (!ui->widgetLegend->isVisible()) { if (!ui->widgetLegend->isVisibleTo(this)) {
emit graphicSettingsChanged(); if (es) emit graphicSettingsChanged();
// qDebug() << "skip updateLegend";
return; return;
} }
// qDebug() << "updateLegend" << graphics.size();
leg_update = false; leg_update = false;
int ps = 100; int ps = 100;
for (int i = 0; i < graphics.size(); i++) { for (int i = 0; i < graphics.size(); i++) {
while (!graphics[i].pb->actions().isEmpty()) graphics[i].pb->removeAction(graphics[i].pb->actions()[0]); while (!graphics[i].pb->actions().isEmpty()) graphics[i].pb->removeAction(graphics[i].pb->actions()[0]);
delete graphics[i].pb; delete graphics[i].pb;
//qDebug() << "new legend item" << graphics[i].name; // qDebug() << "new legend item" << graphics[i].name;
QPixmap pix(60, 22); QPixmap pix(60, 22);
pix.fill(back_color); pix.fill(back_color);
QPainter p(&pix); QPainter p(&pix);
@@ -1386,16 +1388,17 @@ void Graphic::updateLegend(bool es) {
} }
int maxcol = qMax<int>(ui->widgetLegend->width() / ps - 1, 1); int maxcol = qMax<int>(ui->widgetLegend->width() / ps - 1, 1);
int row = 0, col = 0; int row = 0, col = 0;
bool lv = ui->widgetLegend->isVisible(); bool lv = ui->widgetLegend->isVisibleTo(this);
ui->widgetLegend->hide(); ui->widgetLegend->hide();
for (int i = 0; i < graphics.size(); i++) { for (int i = 0; i < graphics.size(); i++) {
ui->layoutLegend->addWidget(graphics[i].pb,row,col); ui->layoutLegend->addWidget(graphics[i].pb,row,col);
graphics[i].pb->show();
col++; col++;
if (col > maxcol) {col = 0; row++;} if (col > maxcol) {col = 0; row++;}
} }
ui->widgetLegend->setVisible(lv); ui->widgetLegend->setVisible(lv);
leg_update = true; leg_update = true;
emit graphicSettingsChanged(); if (es) emit graphicSettingsChanged();
} }
@@ -1418,7 +1421,7 @@ void Graphic::graphicVisibleChange(bool checked) {
if (isFit) on_buttonAutofit_clicked(); if (isFit) on_buttonAutofit_clicked();
else update(); else update();
emit graphicSettingsChanged(); emit graphicSettingsChanged();
// update(); // update();
} }
@@ -1471,29 +1474,30 @@ bool Graphic::statusVisible() const {
bool Graphic::legendVisible() const { bool Graphic::legendVisible() const {
return ui->widgetLegend->isVisible(); return ui->widgetLegend->isVisible();
} }
QByteArray Graphic::save() { QByteArray Graphic::save() {
QByteArray ba; QByteArray ba;
QDataStream s(&ba, QIODevice::ReadWrite); QDataStream s(&ba, QIODevice::ReadWrite);
s << openGL() << antialiasing() << borderInputsVisible() << statusVisible() << legendVisible(); s << openGL() << antialiasing() << borderInputsVisible() << statusVisible() << legendVisible();
s << graphics; s << graphics;
return ba; return ba;
} }
void Graphic::load(QByteArray ba) { void Graphic::load(QByteArray ba) {
if (ba.isEmpty()) return; if (ba.isEmpty()) return;
QDataStream s(ba); QDataStream s(ba);
bool a; bool a;
s >> a; setOpenGL(a); s >> a; setOpenGL(a);
s >> a; setAntialiasing(a); s >> a; setAntialiasing(a);
s >> a; setBorderInputsVisible(a); s >> a; setBorderInputsVisible(a);
s >> a; setStatusVisible(a); s >> a; setStatusVisible(a);
s >> a; setLegendVisible(a); s >> a;
s >> graphics; s >> graphics;
setLegendVisible(a);
} }