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