From f713858ba452f6aa0faf0eaf5876606cf59eed59 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 9 Aug 2021 16:48:08 +0200 Subject: [PATCH] profile: rename printFontScale to dpr (device pixel ratio) The printFontScale is used to scale up fonts (and icons) when rendering to high-DPI devices. With absolute scaling, this will also be used to scale the size of different chart regions, line thickness, etc. Therefore, give it an more appropriate name. "Device pixel ratio", which is a well established term, seems to appropriately describe the concept. Signed-off-by: Berthold Stoeger --- desktop-widgets/printer.cpp | 6 ++-- profile-widget/divecartesianaxis.cpp | 12 +++---- profile-widget/divecartesianaxis.h | 8 ++--- profile-widget/diveeventitem.cpp | 10 +++--- profile-widget/diveeventitem.h | 4 +-- profile-widget/diveprofileitem.cpp | 52 ++++++++++++++-------------- profile-widget/diveprofileitem.h | 24 ++++++------- profile-widget/divetextitem.cpp | 8 ++--- profile-widget/divetextitem.h | 4 +-- profile-widget/profilescene.cpp | 47 ++++++++++++------------- profile-widget/profilescene.h | 4 +-- profile-widget/profilewidget2.cpp | 4 +-- profile-widget/profilewidget2.h | 2 +- profile-widget/tankitem.cpp | 6 ++-- profile-widget/tankitem.h | 4 +-- 15 files changed, 97 insertions(+), 98 deletions(-) diff --git a/desktop-widgets/printer.cpp b/desktop-widgets/printer.cpp index 2d0d24983..d476f4c55 100644 --- a/desktop-widgets/printer.cpp +++ b/desktop-widgets/printer.cpp @@ -107,10 +107,10 @@ void Printer::render(int pages) QWebElementCollection collection = webView->page()->mainFrame()->findAllElements(".diveprofile"); // A "standard" profile has about 600 pixels in height. - // Scale the fonts in the printed profile accordingly. + // Scale the items in the printed profile accordingly. // This is arbitrary, but it seems to work reasonably well. - double printFontScale = collection.count() > 0 ? collection[0].geometry().size().height() / 600.0 : 1.0; - auto profile = std::make_unique(printFontScale, true, !printOptions.color_selected); + double dpr = collection.count() > 0 ? collection[0].geometry().size().height() / 600.0 : 1.0; + auto profile = std::make_unique(dpr, true, !printOptions.color_selected); // render the Qwebview QPainter painter; diff --git a/profile-widget/divecartesianaxis.cpp b/profile-widget/divecartesianaxis.cpp index 231e8f56d..b84278770 100644 --- a/profile-widget/divecartesianaxis.cpp +++ b/profile-widget/divecartesianaxis.cpp @@ -47,7 +47,7 @@ void DiveCartesianAxis::setTextColor(const QColor &color) textColor = color; } -DiveCartesianAxis::DiveCartesianAxis(double fontPrintScale, bool printMode, ProfileScene &scene) : +DiveCartesianAxis::DiveCartesianAxis(double dpr, bool printMode, ProfileScene &scene) : printMode(printMode), scene(scene), orientation(LeftToRight), @@ -60,7 +60,7 @@ DiveCartesianAxis::DiveCartesianAxis(double fontPrintScale, bool printMode, Prof labelScale(1.0), line_size(1), changed(true), - fontPrintScale(fontPrintScale) + dpr(dpr) { setPen(gridPen()); } @@ -184,7 +184,7 @@ void DiveCartesianAxis::updateTicks(int animSpeed, color_index_t color) } else { childPos = begin - i * stepSize; } - DiveTextItem *label = new DiveTextItem(fontPrintScale, this); + DiveTextItem *label = new DiveTextItem(dpr, this); label->setText(textForValue(currValueText)); label->setBrush(colorForValue(currValueText)); label->setScale(labelScale); @@ -339,7 +339,7 @@ QColor DepthAxis::colorForValue(double) const return QColor(Qt::red); } -DepthAxis::DepthAxis(double fontPrintScale, bool printMode, ProfileScene &scene) : DiveCartesianAxis(fontPrintScale, printMode, scene) +DepthAxis::DepthAxis(double dpr, bool printMode, ProfileScene &scene) : DiveCartesianAxis(dpr, printMode, scene) { changed = true; } @@ -372,8 +372,8 @@ QString TemperatureAxis::textForValue(double value) const return QString::number(mkelvin_to_C((int)value)); } -PartialGasPressureAxis::PartialGasPressureAxis(const DivePlotDataModel &model, double fontPrintScale, bool printMode, ProfileScene &scene) : - DiveCartesianAxis(fontPrintScale, printMode, scene), +PartialGasPressureAxis::PartialGasPressureAxis(const DivePlotDataModel &model, double dpr, bool printMode, ProfileScene &scene) : + DiveCartesianAxis(dpr, printMode, scene), model(model) { } diff --git a/profile-widget/divecartesianaxis.h b/profile-widget/divecartesianaxis.h index 5834964f4..c9cb22291 100644 --- a/profile-widget/divecartesianaxis.h +++ b/profile-widget/divecartesianaxis.h @@ -29,7 +29,7 @@ public: LeftToRight, RightToLeft }; - DiveCartesianAxis(double fontPrintScale, bool printMode, ProfileScene &scene); + DiveCartesianAxis(double dpr, bool printMode, ProfileScene &scene); ~DiveCartesianAxis(); void setMinimum(double minimum); void setMaximum(double maximum); @@ -70,13 +70,13 @@ protected: double labelScale; qreal line_size; bool changed; - double fontPrintScale; + double dpr; }; class DepthAxis : public DiveCartesianAxis { Q_OBJECT public: - DepthAxis(double fontPrintScale, bool printMode, ProfileScene &scene); + DepthAxis(double dpr, bool printMode, ProfileScene &scene); private: QString textForValue(double value) const override; QColor colorForValue(double value) const override; @@ -103,7 +103,7 @@ private: class PartialGasPressureAxis : public DiveCartesianAxis { Q_OBJECT public: - PartialGasPressureAxis(const DivePlotDataModel &model, double fontPrintScale, bool printMode, ProfileScene &scene); + PartialGasPressureAxis(const DivePlotDataModel &model, double dpr, bool printMode, ProfileScene &scene); void update(int animSpeed); private: const DivePlotDataModel &model; diff --git a/profile-widget/diveeventitem.cpp b/profile-widget/diveeventitem.cpp index 911aba8a7..cf7d0766b 100644 --- a/profile-widget/diveeventitem.cpp +++ b/profile-widget/diveeventitem.cpp @@ -17,7 +17,7 @@ DiveEventItem::DiveEventItem(const struct dive *d, struct event *ev, struct gasmix lastgasmix, DivePlotDataModel *model, DiveCartesianAxis *hAxis, DiveCartesianAxis *vAxis, - int speed, double fontPrintScale, QGraphicsItem *parent) : DivePixmapItem(parent), + int speed, double dpr, QGraphicsItem *parent) : DivePixmapItem(parent), vAxis(vAxis), hAxis(hAxis), dataModel(model), @@ -26,7 +26,7 @@ DiveEventItem::DiveEventItem(const struct dive *d, struct event *ev, struct gasm { setFlag(ItemIgnoresTransformations); - setupPixmap(lastgasmix, fontPrintScale); + setupPixmap(lastgasmix, dpr); setupToolTipString(lastgasmix); recalculatePos(0); @@ -49,7 +49,7 @@ struct event *DiveEventItem::getEventMutable() return ev; } -void DiveEventItem::setupPixmap(struct gasmix lastgasmix, double fontPrintScale) +void DiveEventItem::setupPixmap(struct gasmix lastgasmix, double dpr) { extern int verbose; const IconMetrics& metrics = defaultIconMetrics(); @@ -65,10 +65,10 @@ void DiveEventItem::setupPixmap(struct gasmix lastgasmix, double fontPrintScale) int sz_bigger = metrics.sz_big + metrics.sz_med; #endif #endif - sz_bigger = lrint(sz_bigger * fontPrintScale); + sz_bigger = lrint(sz_bigger * dpr); int sz_pix = sz_bigger/2; // ex 20px if (verbose) - qDebug() << __FUNCTION__ << "fontPrintScale" << fontPrintScale << "metrics" << metrics.sz_med << metrics.sz_small << "sz_bigger" << sz_bigger; + qDebug() << __FUNCTION__ << "DPR" << dpr << "metrics" << metrics.sz_med << metrics.sz_small << "sz_bigger" << sz_bigger; #define EVENT_PIXMAP(PIX) QPixmap(QString(PIX)).scaled(sz_pix, sz_pix, Qt::KeepAspectRatio, Qt::SmoothTransformation) #define EVENT_PIXMAP_BIGGER(PIX) QPixmap(QString(PIX)).scaled(sz_bigger, sz_bigger, Qt::KeepAspectRatio, Qt::SmoothTransformation) diff --git a/profile-widget/diveeventitem.h b/profile-widget/diveeventitem.h index 2fb584aae..fefae9efc 100644 --- a/profile-widget/diveeventitem.h +++ b/profile-widget/diveeventitem.h @@ -13,7 +13,7 @@ class DiveEventItem : public DivePixmapItem { public: DiveEventItem(const struct dive *d, struct event *ev, struct gasmix lastgasmix, DivePlotDataModel *model, DiveCartesianAxis *hAxis, DiveCartesianAxis *vAxis, - int speed, double fontPrintScale, QGraphicsItem *parent = nullptr); + int speed, double dpr, QGraphicsItem *parent = nullptr); ~DiveEventItem(); const struct event *getEvent() const; struct event *getEventMutable(); @@ -28,7 +28,7 @@ slots: private: void setupToolTipString(struct gasmix lastgasmix); - void setupPixmap(struct gasmix lastgasmix, double fontPrintScale); + void setupPixmap(struct gasmix lastgasmix, double dpr); int depthAtTime(int time); DiveCartesianAxis *vAxis; DiveCartesianAxis *hAxis; diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp index 1b701de6f..0d4867657 100644 --- a/profile-widget/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -13,8 +13,8 @@ #include "profile-widget/profilewidget2.h" AbstractProfilePolygonItem::AbstractProfilePolygonItem(const DivePlotDataModel &model, const DiveCartesianAxis &horizontal, int hColumn, - const DiveCartesianAxis &vertical, int vColumn, double fontPrintScale) : - hAxis(horizontal), vAxis(vertical), dataModel(model), hDataColumn(hColumn), vDataColumn(vColumn), fontPrintScale(fontPrintScale) + const DiveCartesianAxis &vertical, int vColumn, double dpr) : + hAxis(horizontal), vAxis(vertical), dataModel(model), hDataColumn(hColumn), vDataColumn(vColumn), dpr(dpr) { setCacheMode(DeviceCoordinateCache); } @@ -47,8 +47,8 @@ void AbstractProfilePolygonItem::replot(const dive *, bool) } DiveProfileItem::DiveProfileItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, - const DiveCartesianAxis &vAxis, int vColumn, double fontPrintScale) : - AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn, fontPrintScale), + const DiveCartesianAxis &vAxis, int vColumn, double dpr) : + AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn, dpr), show_reported_ceiling(0), reported_ceiling_in_red(0) { } @@ -142,7 +142,7 @@ void DiveProfileItem::replot(const dive *d, bool in_planner) void DiveProfileItem::plot_depth_sample(struct plot_data *entry, QFlags flags, const QColor &color) { - DiveTextItem *item = new DiveTextItem(fontPrintScale, this); + DiveTextItem *item = new DiveTextItem(dpr, this); item->setPos(hAxis.posAtValue(entry->sec), vAxis.posAtValue(entry->depth)); item->setText(get_depth_string(entry->depth, true)); item->setAlignment(flags); @@ -151,8 +151,8 @@ void DiveProfileItem::plot_depth_sample(struct plot_data *entry, QFlagssetAlignment(Qt::AlignRight | Qt::AlignBottom); text->setBrush(getColor(HR_TEXT)); text->setPos(QPointF(hAxis.posAtValue(sec), vAxis.posAtValue(hr))); @@ -234,8 +234,8 @@ void DiveHeartrateItem::paint(QPainter *painter, const QStyleOptionGraphicsItem* } DivePercentageItem::DivePercentageItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, - const DiveCartesianAxis &vAxis, int vColumn, int i, double fontPrintScale) : - AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn, fontPrintScale), + const DiveCartesianAxis &vAxis, int vColumn, int i, double dpr) : + AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn, dpr), tissueIndex(i) { } @@ -305,8 +305,8 @@ void DivePercentageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem } DiveTemperatureItem::DiveTemperatureItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, - const DiveCartesianAxis &vAxis, int vColumn, double fontPrintScale) : - AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn, fontPrintScale) + const DiveCartesianAxis &vAxis, int vColumn, double dpr) : + AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn, dpr) { QPen pen; pen.setBrush(QBrush(getColor(::TEMP_PLOT))); @@ -363,7 +363,7 @@ void DiveTemperatureItem::createTextItem(int sec, int mkelvin) temperature_t temp; temp.mkelvin = mkelvin; - DiveTextItem *text = new DiveTextItem(fontPrintScale, this); + DiveTextItem *text = new DiveTextItem(dpr, this); text->setAlignment(Qt::AlignRight | Qt::AlignBottom); text->setBrush(getColor(TEMP_TEXT)); text->setPos(QPointF(hAxis.posAtValue(sec), vAxis.posAtValue(mkelvin))); @@ -383,8 +383,8 @@ void DiveTemperatureItem::paint(QPainter *painter, const QStyleOptionGraphicsIte } DiveMeanDepthItem::DiveMeanDepthItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, - const DiveCartesianAxis &vAxis, int vColumn, double fontPrintScale) : - AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn, fontPrintScale) + const DiveCartesianAxis &vAxis, int vColumn, double dpr) : + AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn, dpr) { QPen pen; pen.setBrush(QBrush(getColor(::HR_AXIS))); @@ -431,7 +431,7 @@ void DiveMeanDepthItem::createTextItem() int sec = entry[dataModel.rowCount()-1].sec; qDeleteAll(texts); texts.clear(); - DiveTextItem *text = new DiveTextItem(fontPrintScale, this); + DiveTextItem *text = new DiveTextItem(dpr, this); text->setAlignment(Qt::AlignRight | Qt::AlignTop); text->setBrush(getColor(TEMP_TEXT)); text->setPos(QPointF(hAxis.posAtValue(sec) + 1, vAxis.posAtValue(lastRunningSum))); @@ -569,7 +569,7 @@ void DiveGasPressureItem::plotPressureValue(int mbar, int sec, QFlagssetPos(hAxis.posAtValue(sec), vAxis.posAtValue(mbar) + pressure_offset ); text->setText(QString("%1%2").arg(pressure).arg(unit)); text->setAlignment(align); @@ -580,7 +580,7 @@ void DiveGasPressureItem::plotPressureValue(int mbar, int sec, QFlags align, double gasname_offset) { QString gas = get_gas_string(gasmix); - DiveTextItem *text = new DiveTextItem(fontPrintScale, this); + DiveTextItem *text = new DiveTextItem(dpr, this); text->setPos(hAxis.posAtValue(sec), vAxis.posAtValue(mbar) + gasname_offset ); text->setText(gas); text->setAlignment(align); @@ -607,8 +607,8 @@ void DiveGasPressureItem::paint(QPainter *painter, const QStyleOptionGraphicsIte } DiveCalculatedCeiling::DiveCalculatedCeiling(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, - const DiveCartesianAxis &vAxis, int vColumn, double fontPrintScale) : - AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn, fontPrintScale) + const DiveCartesianAxis &vAxis, int vColumn, double dpr) : + AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn, dpr) { } @@ -641,14 +641,14 @@ void DiveCalculatedCeiling::paint(QPainter *painter, const QStyleOptionGraphicsI } DiveCalculatedTissue::DiveCalculatedTissue(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, - const DiveCartesianAxis &vAxis, int vColumn, double fontPrintScale) : - DiveCalculatedCeiling(model, hAxis, hColumn, vAxis, vColumn, fontPrintScale) + const DiveCartesianAxis &vAxis, int vColumn, double dpr) : + DiveCalculatedCeiling(model, hAxis, hColumn, vAxis, vColumn, dpr) { } DiveReportedCeiling::DiveReportedCeiling(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, - const DiveCartesianAxis &vAxis, int vColumn, double fontPrintScale) : - AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn, fontPrintScale) + const DiveCartesianAxis &vAxis, int vColumn, double dpr) : + AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn, dpr) { } @@ -752,8 +752,8 @@ void PartialPressureGasItem::setThresholdSettingsKey(const double *prefPointerMi } PartialPressureGasItem::PartialPressureGasItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, - const DiveCartesianAxis &vAxis, int vColumn, double fontPrintScale) : - AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn, fontPrintScale), + const DiveCartesianAxis &vAxis, int vColumn, double dpr) : + AbstractProfilePolygonItem(model, hAxis, hColumn, vAxis, vColumn, dpr), thresholdPtrMin(NULL), thresholdPtrMax(NULL) { diff --git a/profile-widget/diveprofileitem.h b/profile-widget/diveprofileitem.h index bf9c0ae10..1c34abfcf 100644 --- a/profile-widget/diveprofileitem.h +++ b/profile-widget/diveprofileitem.h @@ -11,7 +11,7 @@ /* This is the Profile Item, it should be used for quite a lot of things on the profile view. The usage should be pretty simple: - DiveProfileItem *profile = new DiveProfileItem(DiveDataModel, timeAxis, DiveDataModel::TIME, DiveDataModel, DiveDataModel::DEPTH, fontPrintScale); + DiveProfileItem *profile = new DiveProfileItem(DiveDataModel, timeAxis, DiveDataModel::TIME, DiveDataModel, DiveDataModel::DEPTH, dpr); scene()->addItem(profile); This is a generically item and should be used as a base for others, I think... @@ -30,7 +30,7 @@ class AbstractProfilePolygonItem : public QObject, public QGraphicsPolygonItem { Q_PROPERTY(qreal x WRITE setX READ x) Q_PROPERTY(qreal y WRITE setY READ y) public: - AbstractProfilePolygonItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, double fontPrintScale); + AbstractProfilePolygonItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, double dpr); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) = 0; void clear(); virtual void replot(const dive *d, bool in_planner); @@ -41,7 +41,7 @@ protected: const DivePlotDataModel &dataModel; int hDataColumn; int vDataColumn; - double fontPrintScale; + double dpr; QList texts; }; @@ -49,7 +49,7 @@ class DiveProfileItem : public AbstractProfilePolygonItem { Q_OBJECT public: - DiveProfileItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, double fontPrintScale); + DiveProfileItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, double dpr); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; void replot(const dive *d, bool in_planner) override; void plot_depth_sample(struct plot_data *entry, QFlags flags, const QColor &color); @@ -64,7 +64,7 @@ private: class DiveMeanDepthItem : public AbstractProfilePolygonItem { Q_OBJECT public: - DiveMeanDepthItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, double fontPrintScale); + DiveMeanDepthItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, double dpr); void replot(const dive *d, bool in_planner) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; @@ -77,7 +77,7 @@ private: class DiveTemperatureItem : public AbstractProfilePolygonItem { Q_OBJECT public: - DiveTemperatureItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, double fontPrintScale); + DiveTemperatureItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, double dpr); void replot(const dive *d, bool in_planner) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; @@ -88,7 +88,7 @@ private: class DiveHeartrateItem : public AbstractProfilePolygonItem { Q_OBJECT public: - DiveHeartrateItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, double fontPrintScale); + DiveHeartrateItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, double dpr); void replot(const dive *d, bool in_planner) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; @@ -100,7 +100,7 @@ private: class DivePercentageItem : public AbstractProfilePolygonItem { Q_OBJECT public: - DivePercentageItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, int i, double fontPrintScale); + DivePercentageItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, int i, double dpr); void replot(const dive *d, bool in_planner) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; @@ -135,7 +135,7 @@ class DiveCalculatedCeiling : public AbstractProfilePolygonItem { public: DiveCalculatedCeiling(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, - const DiveCartesianAxis &vAxis, int vColumn, double fontPrintScale); + const DiveCartesianAxis &vAxis, int vColumn, double dpr); void replot(const dive *d, bool in_planner) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; }; @@ -144,7 +144,7 @@ class DiveReportedCeiling : public AbstractProfilePolygonItem { Q_OBJECT public: - DiveReportedCeiling(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, double fontPrintScale); + DiveReportedCeiling(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, double dpr); void replot(const dive *d, bool in_planner) override; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; }; @@ -153,13 +153,13 @@ class DiveCalculatedTissue : public DiveCalculatedCeiling { Q_OBJECT public: DiveCalculatedTissue(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, - const DiveCartesianAxis &vAxis, int vColumn, double fontPrintScale); + const DiveCartesianAxis &vAxis, int vColumn, double dpr); }; class PartialPressureGasItem : public AbstractProfilePolygonItem { Q_OBJECT public: - PartialPressureGasItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, double fontPrintScale); + PartialPressureGasItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, double dpr); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override; void replot(const dive *d, bool in_planner) override; void setThresholdSettingsKey(const double *prefPointerMin, const double *prefPointerMax); diff --git a/profile-widget/divetextitem.cpp b/profile-widget/divetextitem.cpp index c307a399b..e36728590 100644 --- a/profile-widget/divetextitem.cpp +++ b/profile-widget/divetextitem.cpp @@ -8,11 +8,11 @@ #include #include -DiveTextItem::DiveTextItem(double printScale, QGraphicsItem *parent) : QGraphicsItemGroup(parent), +DiveTextItem::DiveTextItem(double dpr, QGraphicsItem *parent) : QGraphicsItemGroup(parent), internalAlignFlags(Qt::AlignHCenter | Qt::AlignVCenter), textBackgroundItem(new QGraphicsPathItem(this)), textItem(new QGraphicsPathItem(this)), - printScale(printScale), + dpr(dpr), scale(1.0) { setFlag(ItemIgnoresTransformations); @@ -69,11 +69,11 @@ void DiveTextItem::updateText() QFont fnt(qApp->font()); if ((size = fnt.pixelSize()) > 0) { // set in pixels - so the scale factor may not make a difference if it's too close to 1 - size *= scale * printScale; + size *= scale * dpr; fnt.setPixelSize(lrint(size)); } else { size = fnt.pointSizeF(); - size *= scale * printScale; + size *= scale * dpr; fnt.setPointSizeF(size); } QFontMetrics fm(fnt); diff --git a/profile-widget/divetextitem.h b/profile-widget/divetextitem.h index 1aa1864a2..c84750642 100644 --- a/profile-widget/divetextitem.h +++ b/profile-widget/divetextitem.h @@ -13,7 +13,7 @@ class DiveTextItem : public QObject, public QGraphicsItemGroup { Q_PROPERTY(QPointF pos READ pos WRITE setPos) Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity) public: - DiveTextItem(double printScale, QGraphicsItem *parent = 0); + DiveTextItem(double dpr, QGraphicsItem *parent = 0); void setText(const QString &text); void setAlignment(int alignFlags); void setScale(double newscale); @@ -27,7 +27,7 @@ private: QGraphicsPathItem *textBackgroundItem; QGraphicsPathItem *textItem; QString internalText; - double printScale; + double dpr; double scale; }; diff --git a/profile-widget/profilescene.cpp b/profile-widget/profilescene.cpp index 8164644c3..d870c4a84 100644 --- a/profile-widget/profilescene.cpp +++ b/profile-widget/profilescene.cpp @@ -55,34 +55,34 @@ T *ProfileScene::createItem(const DiveCartesianAxis &vAxis, int vColumn, int z, PartialPressureGasItem *ProfileScene::createPPGas(int column, color_index_t color, color_index_t colorAlert, const double *thresholdSettingsMin, const double *thresholdSettingsMax) { - PartialPressureGasItem *item = createItem(*gasYAxis, column, 99, fontPrintScale); + PartialPressureGasItem *item = createItem(*gasYAxis, column, 99, dpr); item->setThresholdSettingsKey(thresholdSettingsMin, thresholdSettingsMax); item->setColors(getColor(color, isGrayscale), getColor(colorAlert, isGrayscale)); return item; } -ProfileScene::ProfileScene(double fontPrintScale, bool printMode, bool isGrayscale) : +ProfileScene::ProfileScene(double dpr, bool printMode, bool isGrayscale) : d(nullptr), dc(-1), - fontPrintScale(fontPrintScale), + dpr(dpr), printMode(printMode), isGrayscale(isGrayscale), maxtime(-1), maxdepth(-1), dataModel(new DivePlotDataModel(this)), - profileYAxis(new DepthAxis(fontPrintScale, printMode, *this)), - gasYAxis(new PartialGasPressureAxis(*dataModel, fontPrintScale, printMode, *this)), - temperatureAxis(new TemperatureAxis(fontPrintScale, printMode, *this)), - timeAxis(new TimeAxis(fontPrintScale, printMode, *this)), - cylinderPressureAxis(new DiveCartesianAxis(fontPrintScale, printMode, *this)), - heartBeatAxis(new DiveCartesianAxis(fontPrintScale, printMode, *this)), - percentageAxis(new DiveCartesianAxis(fontPrintScale, printMode, *this)), - diveProfileItem(createItem(*profileYAxis, DivePlotDataModel::DEPTH, 0, fontPrintScale)), - temperatureItem(createItem(*temperatureAxis, DivePlotDataModel::TEMPERATURE, 1, fontPrintScale)), - meanDepthItem(createItem(*profileYAxis, DivePlotDataModel::INSTANT_MEANDEPTH, 1, fontPrintScale)), - gasPressureItem(createItem(*cylinderPressureAxis, DivePlotDataModel::TEMPERATURE, 1, fontPrintScale)), - diveComputerText(new DiveTextItem(fontPrintScale)), - reportedCeiling(createItem(*profileYAxis, DivePlotDataModel::CEILING, 1, fontPrintScale)), + profileYAxis(new DepthAxis(dpr, printMode, *this)), + gasYAxis(new PartialGasPressureAxis(*dataModel, dpr, printMode, *this)), + temperatureAxis(new TemperatureAxis(dpr, printMode, *this)), + timeAxis(new TimeAxis(dpr, printMode, *this)), + cylinderPressureAxis(new DiveCartesianAxis(dpr, printMode, *this)), + heartBeatAxis(new DiveCartesianAxis(dpr, printMode, *this)), + percentageAxis(new DiveCartesianAxis(dpr, printMode, *this)), + diveProfileItem(createItem(*profileYAxis, DivePlotDataModel::DEPTH, 0, dpr)), + temperatureItem(createItem(*temperatureAxis, DivePlotDataModel::TEMPERATURE, 1, dpr)), + meanDepthItem(createItem(*profileYAxis, DivePlotDataModel::INSTANT_MEANDEPTH, 1, dpr)), + gasPressureItem(createItem(*cylinderPressureAxis, DivePlotDataModel::TEMPERATURE, 1, dpr)), + diveComputerText(new DiveTextItem(dpr)), + reportedCeiling(createItem(*profileYAxis, DivePlotDataModel::CEILING, 1, dpr)), pn2GasItem(createPPGas(DivePlotDataModel::PN2, PN2, PN2_ALERT, NULL, &prefs.pp_graphs.pn2_threshold)), pheGasItem(createPPGas(DivePlotDataModel::PHE, PHE, PHE_ALERT, NULL, &prefs.pp_graphs.phe_threshold)), po2GasItem(createPPGas(DivePlotDataModel::PO2, PO2, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max)), @@ -91,10 +91,10 @@ ProfileScene::ProfileScene(double fontPrintScale, bool printMode, bool isGraysca ccrsensor2GasItem(createPPGas(DivePlotDataModel::CCRSENSOR2, CCRSENSOR2, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max)), ccrsensor3GasItem(createPPGas(DivePlotDataModel::CCRSENSOR3, CCRSENSOR3, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max)), ocpo2GasItem(createPPGas(DivePlotDataModel::SCR_OC_PO2, SCR_OCPO2, PO2_ALERT, &prefs.pp_graphs.po2_threshold_min, &prefs.pp_graphs.po2_threshold_max)), - diveCeiling(createItem(*profileYAxis, DivePlotDataModel::CEILING, 1, fontPrintScale)), - decoModelParameters(new DiveTextItem(fontPrintScale)), - heartBeatItem(createItem(*heartBeatAxis, DivePlotDataModel::HEARTBEAT, 1, fontPrintScale)), - tankItem(new TankItem(*timeAxis, fontPrintScale)) + diveCeiling(createItem(*profileYAxis, DivePlotDataModel::CEILING, 1, dpr)), + decoModelParameters(new DiveTextItem(dpr)), + heartBeatItem(createItem(*heartBeatAxis, DivePlotDataModel::HEARTBEAT, 1, dpr)), + tankItem(new TankItem(*timeAxis, dpr)) { init_plot_info(&plotInfo); @@ -167,9 +167,9 @@ ProfileScene::ProfileScene(double fontPrintScale, bool printMode, bool isGraysca tankItem->setPos(itemPos.tankBar.on); for (int i = 0; i < 16; i++) { - DiveCalculatedTissue *tissueItem = createItem(*profileYAxis, DivePlotDataModel::TISSUE_1 + i, i + 1, fontPrintScale); + DiveCalculatedTissue *tissueItem = createItem(*profileYAxis, DivePlotDataModel::TISSUE_1 + i, i + 1, dpr); allTissues.append(tissueItem); - DivePercentageItem *percentageItem = createItem(*percentageAxis, DivePlotDataModel::PERCENTAGE_1 + i, i + 1, i, fontPrintScale); + DivePercentageItem *percentageItem = createItem(*percentageAxis, DivePlotDataModel::PERCENTAGE_1 + i, i + 1, i, dpr); allPercentages.append(percentageItem); } @@ -637,8 +637,7 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM // BUT events are wanted. #endif DiveEventItem *item = new DiveEventItem(d, event, lastgasmix, dataModel, - timeAxis, profileYAxis, animSpeed, - fontPrintScale); + timeAxis, profileYAxis, animSpeed, dpr); item->setZValue(2); addItem(item); eventItems.push_back(item); diff --git a/profile-widget/profilescene.h b/profile-widget/profilescene.h index f99f13dff..1277fb466 100644 --- a/profile-widget/profilescene.h +++ b/profile-widget/profilescene.h @@ -36,7 +36,7 @@ class TimeAxis; class ProfileScene : public QGraphicsScene { public: - ProfileScene(double fontPrintScale, bool printMode, bool isGrayscale); + ProfileScene(double dpr, bool printMode, bool isGrayscale); ~ProfileScene(); void updateAxes(bool instant); // Update axes according to preferences @@ -59,7 +59,7 @@ private: void updateVisibility(); // Update visibility of non-interactive chart features according to preferences friend class ProfileWidget2; // For now, give the ProfileWidget full access to the objects on the scene - double fontPrintScale; + double dpr; // Device Pixel Ratio. A DPR of one corresponds to a "standard" PC screen. bool printMode; bool isGrayscale; int maxtime; diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index bc88b6658..1d2ae36c2 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -45,8 +45,8 @@ static const double thumbnailBaseZValue = 100.0; #endif -ProfileWidget2::ProfileWidget2(DivePlannerPointsModel *plannerModelIn, double fontPrintScale, QWidget *parent) : QGraphicsView(parent), - profileScene(new ProfileScene(fontPrintScale, false, false)), +ProfileWidget2::ProfileWidget2(DivePlannerPointsModel *plannerModelIn, double dpr, QWidget *parent) : QGraphicsView(parent), + profileScene(new ProfileScene(dpr, false, false)), currentState(INIT), plannerModel(plannerModelIn), zoomLevel(0), diff --git a/profile-widget/profilewidget2.h b/profile-widget/profilewidget2.h index 87df3463b..8908a599a 100644 --- a/profile-widget/profilewidget2.h +++ b/profile-widget/profilewidget2.h @@ -43,7 +43,7 @@ public: }; // Pass null as plannerModel if no support for planning required - ProfileWidget2(DivePlannerPointsModel *plannerModel, double fontPrintScale, QWidget *parent = 0); + ProfileWidget2(DivePlannerPointsModel *plannerModel, double dpr, QWidget *parent = 0); ~ProfileWidget2(); void resetZoom(); void scale(qreal sx, qreal sy); diff --git a/profile-widget/tankitem.cpp b/profile-widget/tankitem.cpp index 40a1ce7ca..53ea5abbc 100644 --- a/profile-widget/tankitem.cpp +++ b/profile-widget/tankitem.cpp @@ -9,10 +9,10 @@ static const qreal height = 3.0; -TankItem::TankItem(const DiveCartesianAxis &axis, double fontPrintScale) : +TankItem::TankItem(const DiveCartesianAxis &axis, double dpr) : hAxis(axis), plotEndTime(-1), - fontPrintScale(fontPrintScale) + dpr(dpr) { QColor red(PERSIANRED1); QColor blue(AIR_BLUE); @@ -51,7 +51,7 @@ void TankItem::createBar(int startTime, int stopTime, struct gasmix gas) rect->setBrush(nitrox); rect->setPen(QPen(QBrush(), 0.0)); // get rid of the thick line around the rectangle rects.push_back(rect); - DiveTextItem *label = new DiveTextItem(fontPrintScale, rect); + DiveTextItem *label = new DiveTextItem(dpr, rect); label->setText(gasname(gas)); label->setBrush(Qt::black); label->setPos(x + 1, 0); diff --git a/profile-widget/tankitem.h b/profile-widget/tankitem.h index 49c01b689..2c96f20dd 100644 --- a/profile-widget/tankitem.h +++ b/profile-widget/tankitem.h @@ -13,14 +13,14 @@ class DiveCartesianAxis; class TankItem : public QGraphicsRectItem { public: - explicit TankItem(const DiveCartesianAxis &axis, double fontPrintScale); + explicit TankItem(const DiveCartesianAxis &axis, double dpr); void setData(const struct plot_info *plotInfo, const struct dive *d); private: void createBar(int startTime, int stopTime, struct gasmix gas); const DiveCartesianAxis &hAxis; int plotEndTime; - double fontPrintScale; + double dpr; QBrush air, nitrox, oxygen, trimix; QList rects; };