diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-05-06 15:35:17 -0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-05-06 13:55:06 -0700 |
commit | 1b392b35bca24ce25da9073dbe9a1bb0186c47af (patch) | |
tree | fba8fbcb37564086f62ae40d19e0edb84a0067f5 /qt-ui | |
parent | b3fce3497cc6cd801afae01f713b56b1d8e883b8 (diff) | |
download | subsurface-1b392b35bca24ce25da9073dbe9a1bb0186c47af.tar.gz |
Port the plot text method to Qt, also test it by actually plotting something
The plot_text function from the cairo-methods are now ported
on the qt version. this patch moves around some code since
quite defines are already used and I didn't want to reinvent
the whell.
Original code used varargs, but I prefered to change it
, so now it receives just a reference to a QString object
and the string must be constructed before sending,
using the .arg methods.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/profilegraphics.cpp | 36 | ||||
-rw-r--r-- | qt-ui/profilegraphics.h | 6 |
2 files changed, 33 insertions, 9 deletions
diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp index 89c3a74fc..b52368b11 100644 --- a/qt-ui/profilegraphics.cpp +++ b/qt-ui/profilegraphics.cpp @@ -100,6 +100,12 @@ void fill_profile_color() } #undef COLOR +struct text_render_options{ + double size; + color_indice_t color; + double hpos, vpos; +}; + ProfileGraphicsView::ProfileGraphicsView(QWidget* parent) : QGraphicsView(parent) { setScene(new QGraphicsScene()); @@ -293,19 +299,17 @@ void ProfileGraphicsView::plot_depth_profile(struct graphics_context *gc, struct scene()->addItem(line); } -#if 0 /* now the text on the time markers */ - text_render_options_t tro = {DEPTH_TEXT_SIZE, TIME_TEXT, CENTER, TOP}; + struct text_render_options tro = {DEPTH_TEXT_SIZE, TIME_TEXT, CENTER, TOP}; if (maxtime < 600) { /* Be a bit more verbose with shorter dives */ for (i = incr; i < maxtime; i += incr) - plot_text(gc, &tro, i, 1, "%02d:%02d", i/60, i%60); + plot_text(gc, &tro, i, 1, QString("%1:%2").arg(i/60).arg(i%60)); } else { /* Only render the time on every second marker for normal dives */ for (i = incr; i < maxtime; i += 2 * incr) - plot_text(gc, &tro, i, 1, "%d", i/60); + plot_text(gc, &tro, i, 1, QString::number(i/60)); } -#endif /* Depth markers: every 30 ft or 10 m*/ gc->leftx = 0; gc->rightx = 1.0; @@ -418,9 +422,6 @@ void ProfileGraphicsView::plot_depth_profile(struct graphics_context *gc, struct // TODO: Port the profile_calc_ceiling to QSettings // if (prefs.profile_calc_ceiling) { - qDebug() << "CALC_CEILING_SHALLOW" << profile_color[CALC_CEILING_SHALLOW].first(); - qDebug() << "CALC_CEILING_DEEP" << profile_color[CALC_CEILING_DEEP].first(); - pat.setColorAt(0, profile_color[CALC_CEILING_SHALLOW].first()); pat.setColorAt(1, profile_color[CALC_CEILING_DEEP].first()); @@ -479,6 +480,23 @@ void ProfileGraphicsView::plot_depth_profile(struct graphics_context *gc, struct } } +void ProfileGraphicsView::plot_text(struct graphics_context *gc, text_render_options_t *tro, double x, double y, const QString& text) +{ + QFontMetrics fm(font()); + + double dx = tro->hpos * (fm.width(text)); + double dy = tro->vpos * (fm.height()); + + QGraphicsSimpleTextItem *item = new QGraphicsSimpleTextItem(text); + QPointF point( SCALE(gc, x, y) ); // This is neded because of the SCALE macro. + + item->setPos(point.x() + dx, point.y() +dy ); + item->setBrush( QBrush(profile_color[tro->color].first())); + item->setPen( QPen(profile_color[BACKGROUND].first())); + scene()->addItem(item); + qDebug() << item->pos(); +} + void ProfileGraphicsView::resizeEvent(QResizeEvent *event) { @@ -486,5 +504,5 @@ void ProfileGraphicsView::resizeEvent(QResizeEvent *event) // I can pass some parameters to this - // like Qt::IgnoreAspectRatio or Qt::KeepAspectRatio QRectF r = scene()->sceneRect(); - fitInView ( r.x() - 2, r.y() -2, r.width() + 4, r.height() + 4); // do a little bit of spacing; + fitInView ( r.x() - 50, r.y() -50, r.width() + 100, r.height() + 100); // do a little bit of spacing; } diff --git a/qt-ui/profilegraphics.h b/qt-ui/profilegraphics.h index a62e55c4d..0b472f8b5 100644 --- a/qt-ui/profilegraphics.h +++ b/qt-ui/profilegraphics.h @@ -3,6 +3,11 @@ #include <QGraphicsView> +struct text_render_options; +struct graphics_context; +struct plot_info; +typedef struct text_render_options text_render_options_t; + class ProfileGraphicsView : public QGraphicsView { Q_OBJECT public: @@ -14,6 +19,7 @@ protected: private: void plot_depth_profile(struct graphics_context *gc, struct plot_info *pi); + void plot_text(struct graphics_context *gc, text_render_options_t *tro, double x, double y, const QString &text); QPen defaultPen; QBrush defaultBrush; |