void FrameWidget::setRect(QWidget *widget, double x, double y, double w, double h, Unit unit) { if (!widget) return; int dpiX = widget->logicalDpiX(); int dpiY = widget->logicalDpiY(); FrameWidget *fw = qobject_cast<FrameWidget *>(widget); if (fw){ switch(unit){ case Pixel: fw->setRect(qRound(x), qRound(y), qRound(w), qRound(h)); break; case Inch: fw->setRect(qRound(x*dpiX), qRound(y*dpiY), qRound(w*dpiX), qRound(h*dpiY)); break; case Millimeter: fw->setRect(qRound(x*dpiX/25.4), qRound(y*dpiY/25.4), qRound(w*dpiX/25.4), qRound(h*dpiY/25.4)); break; case Centimeter: fw->setRect(qRound(x*dpiX/2.54), qRound(y*dpiY/2.54), qRound(w*dpiX/2.54), qRound(h*dpiY/2.54)); break; case Point: fw->setRect(qRound(x*dpiX/72.0), qRound(y*dpiY/72.0), qRound(w*dpiX/72.0), qRound(h*dpiY/72.0)); break; case Scale: fw->setCoordinates(x, y, x + w, y + h); break; } return; } switch(unit){ case Pixel: widget->setGeometry(qRound(x), qRound(y), qRound(w), qRound(h)); break; case Inch: widget->setGeometry(qRound(x*dpiX), qRound(y*dpiY), qRound(w*dpiX), qRound(h*dpiY)); break; case Millimeter: widget->setGeometry(qRound(x*dpiX/25.4), qRound(y*dpiY/25.4), qRound(w*dpiX/25.4), qRound(h*dpiY/25.4)); break; case Centimeter: widget->setGeometry(qRound(x*dpiX/2.54), qRound(y*dpiY/2.54), qRound(w*dpiX/2.54), qRound(h*dpiY/2.54)); break; case Point: widget->setGeometry(qRound(x*dpiX/72.0), qRound(y*dpiY/72.0), qRound(w*dpiX/72.0), qRound(h*dpiY/72.0)); break; default: break; } }
void EnrichmentDialog::setCoordinates(int unit) { if (!d_widget) return; if (unit == FrameWidget::Scale){//ScaleCoordinates double left = xBox->value(); double top = yBox->value(); FrameWidget *fw = qobject_cast<FrameWidget *>(d_widget); if (fw) fw->setCoordinates(left, top, left + widthBox->value(), top - heightBox->value()); } else FrameWidget::setRect(d_widget, xBox->value(), yBox->value(), widthBox->value(), heightBox->value(), (FrameWidget::Unit)unit); if (d_plot) d_plot->multiLayer()->notifyChanges(); if (d_app) d_app->d_frame_geometry_unit = unit; }