Sometimes need convert from different unit that in a pattern.

--HG--
branch : develop
This commit is contained in:
dismine 2014-07-23 13:04:23 +03:00
parent 3953d6fb22
commit 28fa14cff2
6 changed files with 36 additions and 20 deletions

View File

@ -199,7 +199,7 @@ void DialogEndLine::ShowDialog(bool click)
QLineF line = QLineF(point->toQPointF(), scene->getScenePos());
//Radius of point circle, but little bigger. Need handle with hover sizes.
qreal radius = ((DefPointRadius/*mm*/ / 25.4) * VApplication::PrintDPI)*1.5;
qreal radius = qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm)*1.5;
if (line.length() <= radius)
{
return;

View File

@ -51,7 +51,7 @@ TableWindow::TableWindow(QWidget *parent)
ui->statusBar->addWidget(colission);
outItems = collidingItems = false;
//sceneRect = QRectF(0, 0, qApp->toPixel(203), qApp->toPixel(287));
sceneRect = QRectF(0, 0, qApp->toPixel(823), qApp->toPixel(1171));
sceneRect = QRectF(0, 0, qApp->toPixel(823, Unit::Mm), qApp->toPixel(1171, Unit::Mm));
tableScene = new QGraphicsScene(sceneRect);
QBrush brush;
brush.setStyle( Qt::SolidPattern );
@ -206,7 +206,7 @@ void TableWindow::StopTable()
delete listOutItems;
listDetails.clear();
//sceneRect = QRectF(0, 0, 230*resol/25.9, 327*resol/25.9);
sceneRect = QRectF(0, 0, qApp->toPixel(823), qApp->toPixel(1171));
sceneRect = QRectF(0, 0, qApp->toPixel(823, Unit::Mm), qApp->toPixel(1171, Unit::Mm));
emit closed();
}
@ -442,13 +442,13 @@ void TableWindow::GetNextDetail()
void TableWindow::AddLength()
{
QRectF rect = tableScene->sceneRect();
rect.setHeight(rect.height()+qApp->toPixel(279));
rect.setHeight(rect.height()+qApp->toPixel(279, Unit::Mm));
tableScene->setSceneRect(rect);
rect = shadowPaper->rect();
rect.setHeight(rect.height()+qApp->toPixel(279));
rect.setHeight(rect.height()+qApp->toPixel(279, Unit::Mm));
shadowPaper->setRect(rect);
rect = paper->rect();
rect.setHeight(rect.height()+qApp->toPixel(279));
rect.setHeight(rect.height()+qApp->toPixel(279, Unit::Mm));
paper->setRect(rect);
ui->actionRemove->setEnabled(true);
emit LengthChanged();
@ -463,13 +463,13 @@ void TableWindow::RemoveLength()
if (sceneRect.height() <= tableScene->sceneRect().height() - 100)
{
QRectF rect = tableScene->sceneRect();
rect.setHeight(rect.height()-qApp->toPixel(279));
rect.setHeight(rect.height()-qApp->toPixel(279, Unit::Mm));
tableScene->setSceneRect(rect);
rect = shadowPaper->rect();
rect.setHeight(rect.height()-qApp->toPixel(279));
rect.setHeight(rect.height()-qApp->toPixel(279, Unit::Mm));
shadowPaper->setRect(rect);
rect = paper->rect();
rect.setHeight(rect.height()-qApp->toPixel(279));
rect.setHeight(rect.height()-qApp->toPixel(279, Unit::Mm));
paper->setRect(rect);
if (fabs(sceneRect.height() - tableScene->sceneRect().height()) < 0.01)
{
@ -561,7 +561,7 @@ void TableWindow::PdfFile(const QString &name) const
qreal x=0, y=0, w=0, h=0;
r.getRect(&x, &y, &w, &h);// Re-shrink the scene to it's bounding contents
printer.setResolution(static_cast<int>(qApp->PrintDPI));
printer.setPaperSize ( QSizeF(qApp->fromPixel(w), qApp->fromPixel(h)), QPrinter::Millimeter );
printer.setPaperSize ( QSizeF(qApp->fromPixel(w, Unit::Mm), qApp->fromPixel(h, Unit::Mm)), QPrinter::Millimeter );
QPainter painter;
if (painter.begin( &printer ) == false)
{ // failed to open file

View File

@ -44,7 +44,7 @@ const QString VToolPoint::TagName = QStringLiteral("point");
VToolPoint::VToolPoint(VPattern *doc, VContainer *data, quint32 id, QGraphicsItem *parent):VDrawTool(doc, data, id),
QGraphicsEllipseItem(parent), radius(DefPointRadius), namePoint(0), lineName(0)
{
radius = (DefPointRadius/*mm*/ / 25.4) * VApplication::PrintDPI;
radius = qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm);
namePoint = new VGraphicsSimpleTextItem(this);
connect(namePoint, &VGraphicsSimpleTextItem::ShowContextMenu, this, &VToolPoint::ShowContextMenu);
namePoint->setBrush(Qt::black);

View File

@ -49,7 +49,7 @@ VisToolEndLine::VisToolEndLine(const VContainer *data, QGraphicsItem *parent)
point->setBrush(QBrush(Qt::NoBrush));
point->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor));
const qreal radius = (DefPointRadius/*mm*/ / 25.4) * VApplication::PrintDPI;
const qreal radius = qApp->toPixel(DefPointRadius/*mm*/, Unit::Mm);
QRectF rec = QRectF(0, 0, radius*2/factor, radius*2/factor);
rec.translate(-rec.center().x(), -rec.center().y());
point->setRect(rec);

View File

@ -144,19 +144,19 @@ bool VApplication::notify(QObject *receiver, QEvent *event)
}
//---------------------------------------------------------------------------------------------------------------------
double VApplication::toPixel(double unit) const
double VApplication::toPixel(double val, const Unit &unit) const
{
double result = 0;
switch (_patternUnit)
switch (unit)
{
case Unit::Mm:
result = (unit / 25.4) * PrintDPI;
result = (val / 25.4) * PrintDPI;
break;
case Unit::Cm:
result = ((unit * 10.0) / 25.4) * PrintDPI;
result = ((val * 10.0) / 25.4) * PrintDPI;
break;
case Unit::Inch:
result = unit * PrintDPI;
result = val * PrintDPI;
break;
default:
break;
@ -165,10 +165,16 @@ double VApplication::toPixel(double unit) const
}
//---------------------------------------------------------------------------------------------------------------------
double VApplication::fromPixel(double pix) const
double VApplication::toPixel(double val) const
{
return toPixel(val, _patternUnit);
}
//---------------------------------------------------------------------------------------------------------------------
double VApplication::fromPixel(double pix, const Unit &unit) const
{
double result = 0;
switch (_patternUnit)
switch (unit)
{
case Unit::Mm:
result = (pix / PrintDPI) * 25.4;
@ -185,6 +191,12 @@ double VApplication::fromPixel(double pix) const
return result;
}
//---------------------------------------------------------------------------------------------------------------------
double VApplication::fromPixel(double pix) const
{
return fromPixel(pix, _patternUnit);
}
//---------------------------------------------------------------------------------------------------------------------
QString VApplication::pathToTables() const
{

View File

@ -60,8 +60,12 @@ public:
void setPatternUnit(const Unit &patternUnit);
MeasurementsType patternType() const;
void setPatternType(const MeasurementsType &patternType);
double toPixel(double unit) const;
double toPixel(double val, const Unit &unit) const;
double toPixel(double val) const;
double fromPixel(double pix, const Unit &unit) const;
double fromPixel(double pix) const;
static const qreal PrintDPI;
QString translationsPath() const;
QString pathToTables() const;