mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
b3fce3497c
commit
1b392b35bc
5 changed files with 57 additions and 76 deletions
|
@ -90,22 +90,6 @@ typedef gint (*sort_func_t)(GtkTreeModel *model,
|
|||
GtkTreeIter *b,
|
||||
gpointer user_data);
|
||||
|
||||
#define ALIGN_LEFT 1
|
||||
#define ALIGN_RIGHT 2
|
||||
#define INVISIBLE 4
|
||||
#define UNSORTABLE 8
|
||||
#define EDITABLE 16
|
||||
|
||||
#ifndef TEXT_SCALE
|
||||
#define TEXT_SCALE 1.0
|
||||
#endif
|
||||
|
||||
#define DEPTH_TEXT_SIZE (10 * TEXT_SCALE)
|
||||
#define PRESSURE_TEXT_SIZE (10 * TEXT_SCALE)
|
||||
#define DC_TEXT_SIZE (10.5 * TEXT_SCALE)
|
||||
#define PP_TEXT_SIZE (11 * TEXT_SCALE)
|
||||
#define TEMP_TEXT_SIZE (12 * TEXT_SCALE)
|
||||
|
||||
extern GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title,
|
||||
data_func_t data_func, unsigned int flags);
|
||||
extern GtkTreeViewColumn *tree_view_column_add_pixbuf(GtkWidget *tree_view, data_func_t data_func, GtkTreeViewColumn *col);
|
||||
|
|
51
profile.c
51
profile.c
|
@ -157,57 +157,6 @@ int get_maxdepth(struct plot_info *pi)
|
|||
return md;
|
||||
}
|
||||
|
||||
#if 0
|
||||
typedef struct {
|
||||
double size;
|
||||
color_indice_t color;
|
||||
double hpos, vpos;
|
||||
} text_render_options_t;
|
||||
#endif
|
||||
|
||||
#define RIGHT (-1.0)
|
||||
#define CENTER (-0.5)
|
||||
#define LEFT (0.0)
|
||||
|
||||
#define TOP (1)
|
||||
#define MIDDLE (0)
|
||||
#define BOTTOM (-1)
|
||||
|
||||
#if USE_GTK_UI
|
||||
static void plot_text(struct graphics_context *gc, const text_render_options_t *tro,
|
||||
double x, double y, const char *fmt, ...)
|
||||
{
|
||||
cairo_t *cr = gc->cr;
|
||||
cairo_font_extents_t fe;
|
||||
cairo_text_extents_t extents;
|
||||
double dx, dy;
|
||||
char buffer[256];
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
vsnprintf(buffer, sizeof(buffer), fmt, args);
|
||||
va_end(args);
|
||||
|
||||
cairo_set_font_size(cr, tro->size * plot_scale);
|
||||
cairo_font_extents(cr, &fe);
|
||||
cairo_text_extents(cr, buffer, &extents);
|
||||
dx = tro->hpos * (extents.width + extents.x_bearing);
|
||||
dy = tro->vpos * (extents.height + fe.descent);
|
||||
move_to(gc, x, y);
|
||||
cairo_rel_move_to(cr, dx, dy);
|
||||
|
||||
cairo_text_path(cr, buffer);
|
||||
set_source_rgba(gc, TEXT_BACKGROUND);
|
||||
cairo_stroke(cr);
|
||||
|
||||
move_to(gc, x, y);
|
||||
cairo_rel_move_to(cr, dx, dy);
|
||||
|
||||
set_source_rgba(gc, tro->color);
|
||||
cairo_show_text(cr, buffer);
|
||||
}
|
||||
#endif /* USE_GTK_UI */
|
||||
|
||||
/* collect all event names and whether we display them */
|
||||
struct ev_select {
|
||||
char *ev_name;
|
||||
|
|
24
profile.h
24
profile.h
|
@ -54,6 +54,30 @@ int get_maxtime(struct plot_info *pi);
|
|||
* partial pressure graphs */
|
||||
int get_maxdepth(struct plot_info *pi);
|
||||
|
||||
#define ALIGN_LEFT 1
|
||||
#define ALIGN_RIGHT 2
|
||||
#define INVISIBLE 4
|
||||
#define UNSORTABLE 8
|
||||
#define EDITABLE 16
|
||||
|
||||
#ifndef TEXT_SCALE
|
||||
#define TEXT_SCALE 1.0
|
||||
#endif
|
||||
|
||||
#define DEPTH_TEXT_SIZE (10 * TEXT_SCALE)
|
||||
#define PRESSURE_TEXT_SIZE (10 * TEXT_SCALE)
|
||||
#define DC_TEXT_SIZE (10.5 * TEXT_SCALE)
|
||||
#define PP_TEXT_SIZE (11 * TEXT_SCALE)
|
||||
#define TEMP_TEXT_SIZE (12 * TEXT_SCALE)
|
||||
|
||||
#define RIGHT (-1.0)
|
||||
#define CENTER (-0.5)
|
||||
#define LEFT (0.0)
|
||||
|
||||
#define TOP (1)
|
||||
#define MIDDLE (0)
|
||||
#define BOTTOM (-1)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue