Some Mouse handling and By Pressure cleanups

This commit is contained in:
Mark Watkins 2014-08-12 20:44:05 +10:00
parent 67203a8c49
commit 8fae3b4a6e
13 changed files with 278 additions and 54 deletions

View File

@ -108,6 +108,7 @@ bool MinutesAtPressure::isEmpty()
return m_empty;
}
void MinutesAtPressure::paint(QPainter &painter, gGraph &graph, const QRegion &region)
{
QRect rect = region.boundingRect();
@ -116,8 +117,8 @@ void MinutesAtPressure::paint(QPainter &painter, gGraph &graph, const QRegion &r
float cells = m_maxpressure-m_minpressure+1;
float width = rect.width() - gYAxis::Margin;
float left = rect.left() + gYAxis::Margin;
float width = rect.width();
float left = rect.left();
float pix = width / cells;
m_minx = graph.min_x;
@ -140,21 +141,31 @@ void MinutesAtPressure::paint(QPainter &painter, gGraph &graph, const QRegion &r
QMap<EventStoreType, int>::iterator times_end = times.end();
QPoint mouse = graph.graphView()->currentMousePos();
float ypos = top;
QString text = schema::channel[m_presChannel].label();
QRectF rec(left,top, pix * 3,0);
QRectF rec(left - gYAxis::Margin, top, gYAxis::Margin,0);
rec = painter.boundingRect(rec, Qt::AlignTop | Qt::AlignRight, text);
rec.moveRight(left-4);
painter.drawText(rec, Qt::AlignRight | Qt::AlignVCenter, text);
graph.renderText(text, rec, Qt::AlignRight | Qt::AlignVCenter);
//painter.drawText(rec, Qt::AlignRight | Qt::AlignVCenter, text);
if (rec.contains(mouse)) {
QString text = schema::channel[m_presChannel].description();
graph.ToolTip(text, mouse.x() + 10, mouse.y(), TT_AlignLeft);
}
double tmph = rec.height();
text = STR_UNIT_Minutes;
QRectF rec2(left, top + rec.height(),pix * 3, 0);
QRectF rec2(left - gYAxis::Margin, top + rec.height(), gYAxis::Margin, 0);
rec2 = painter.boundingRect(rec2, Qt::AlignTop | Qt::AlignRight, text);
rec2.moveRight(left-4);
painter.drawText(rec2, Qt::AlignRight | Qt::AlignVCenter, text);
//painter.drawText(rec2, Qt::AlignRight | Qt::AlignVCenter, text);
graph.renderText(text, rec2, Qt::AlignRight | Qt::AlignVCenter);
tmph += rec2.height();
float xpos = left;
for (it = times.begin(); it != times_end; ++it) {
@ -166,16 +177,19 @@ void MinutesAtPressure::paint(QPainter &painter, gGraph &graph, const QRegion &r
rec.setWidth(pix - 1);
painter.fillRect(rec, QColor("orange"));
painter.drawText(rec, Qt::AlignCenter, text);
graph.renderText(text, rec, Qt::AlignCenter);
//painter.drawText(rec, Qt::AlignCenter, text);
rec.moveTop(top + rec.height());
painter.drawText(rec, Qt::AlignCenter, value);
graph.renderText(value, rec, Qt::AlignCenter);
//painter.drawText(rec, Qt::AlignCenter, value);
xpos += pix;
}
float hh = rec.height();
ypos = top + tmph;
left = rect.left();
float ypos = top + hh * 2;
float hh = rec.height();
QHash<ChannelID, QMap<EventStoreType, EventDataType> >::iterator eit;
QHash<ChannelID, QMap<EventStoreType, EventDataType> >::iterator ev_end = events.end();
@ -196,8 +210,8 @@ void MinutesAtPressure::paint(QPainter &painter, gGraph &graph, const QRegion &r
QMap<EventStoreType, EventDataType>::iterator eit_end = eit.value().end();
QString text = chan.label();
QRectF rec2(xpos, ypos, pix * 3, hh);
rec2 = painter.boundingRect(rec2, Qt::AlignTop | Qt::AlignRight, text);
QRectF rec2(xpos - gYAxis::Margin, ypos, gYAxis::Margin, hh);
rec2 = painter.boundingRect(rec2, Qt::AlignRight | Qt::AlignVCenter, text);
rec2.moveRight(left-4);
if (rec2.contains(mouse)) {
@ -207,7 +221,8 @@ void MinutesAtPressure::paint(QPainter &painter, gGraph &graph, const QRegion &r
}
graph.ToolTip(text, mouse.x() + 10, mouse.y(), TT_AlignLeft);
}
painter.drawText(rec2, Qt::AlignRight | Qt::AlignVCenter, text);
graph.renderText(text, rec2, Qt::AlignRight | Qt::AlignVCenter);
//painter.drawText(rec2, Qt::AlignRight | Qt::AlignVCenter, text);
for (it = times.begin(), vit = eit.value().begin(); vit != eit_end; ++vit, ++it) {
float minutes = float(it.value()) / 60.0;
@ -228,7 +243,8 @@ void MinutesAtPressure::paint(QPainter &painter, gGraph &graph, const QRegion &r
}
painter.drawText(rec, Qt::AlignCenter, QString(fmt).arg(value,5,'f',2));
graph.renderText(QString(fmt).arg(value,5,'f',2), rec, Qt::AlignCenter);
// painter.drawText(rec, Qt::AlignCenter, QString(fmt).arg(value,5,'f',2));
xpos += pix;
}
@ -456,21 +472,36 @@ void MinutesAtPressure::recalcFinished()
bool MinutesAtPressure::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
{
Q_UNUSED(event);
Q_UNUSED(graph);
return true;
// int y = event->y() - m_rect.top();
// int x = event->x() - graph->graphView()->titleWidth;
// double w = m_rect.width() - gYAxis::Margin;
// double xmult = (graph->blockZoom() ? double(graph->rmax_x - graph->rmin_x) : double(graph->max_x - graph->min_x)) / w;
// double a = x - gYAxis::Margin;
// if (a < 0) a = 0;
// if (a > w) a = w;
// double b = a * xmult;
// double c= b + (graph->blockZoom() ? graph->rmin_x : graph->min_x);
// graph->graphView()->setCurrentTime(c);
graph->timedRedraw(0);
return false;
}
bool MinutesAtPressure::mousePressEvent(QMouseEvent *event, gGraph *graph)
{
Q_UNUSED(event);
Q_UNUSED(graph);
return true;
return false;
}
bool MinutesAtPressure::mouseReleaseEvent(QMouseEvent *event, gGraph *graph)
{
Q_UNUSED(event);
Q_UNUSED(graph);
return true;
return false;
}

View File

@ -15,15 +15,15 @@
#include "gFlagsLine.h"
#include "gYAxis.h"
gFlagsLabelArea::gFlagsLabelArea(gFlagsGroup *group)
gLabelArea::gLabelArea(Layer * layer)
: gSpacer(20)
{
m_group = group;
m_mainlayer = layer;
}
bool gFlagsLabelArea::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
bool gLabelArea::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
{
if (m_group) {
return m_group->mouseMoveEvent(event, graph);
if (m_mainlayer) {
return m_mainlayer->mouseMoveEvent(event, graph);
}
return false;
@ -221,7 +221,7 @@ bool gFlagsGroup::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
}
}
return true;
return false;
}
@ -405,5 +405,5 @@ bool gFlagsLine::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
Q_UNUSED(graph)
// qDebug() << code() << event->x() << event->y() << graph->rect();
return true;
return false;
}

View File

@ -20,17 +20,17 @@ class gFlagsGroup;
/*! \class gYSpacer
\brief A dummy vertical spacer object
*/
class gFlagsLabelArea: public gSpacer
class gLabelArea: public gSpacer
{
public:
gFlagsLabelArea(gFlagsGroup *group);
gLabelArea(Layer * layer);
virtual void paint(QPainter &painter, gGraph &w, const QRegion &region) {
Q_UNUSED(w);
Q_UNUSED(painter);
Q_UNUSED(region);
}
protected:
gFlagsGroup *m_group;
Layer *m_mainlayer;
virtual bool mouseMoveEvent(QMouseEvent *event, gGraph *graph);
};

View File

@ -265,6 +265,12 @@ void gGraph::renderText(QString text, int x, int y, float angle, QColor color, Q
m_graphview->AddTextQue(text, x, y, angle, color, font, antialias);
}
void gGraph::renderText(QString text, QRectF rect, int flags, float angle, QColor color, QFont *font, bool antialias)
{
m_graphview->AddTextQue(text, rect, flags, angle, color, font, antialias);
}
void gGraph::paint(QPainter &painter, const QRegion &region)
{
m_rect = region.boundingRect();
@ -702,7 +708,8 @@ void gGraph::mouseMoveEvent(QMouseEvent *event)
for (int i = 0; i < m_layers.size(); i++) {
if (m_layers[i]->m_rect.contains(x, y))
if (m_layers[i]->mouseMoveEvent(event, this)) {
doredraw = true;
return;
// doredraw = true;
}
}

View File

@ -113,6 +113,7 @@ class gGraph : public QObject
bool selectingArea();
double currentTime() const;
void setCurrentTime(double value) { m_currentTime = value; }
@ -123,8 +124,10 @@ class gGraph : public QObject
bool movable = false, short x = 0, short y = 0);
//! \brief Queues text for gGraphView object to draw it.
void renderText(QString text, int x, int y, float angle = 0.0,
QColor color = Qt::black, QFont *font = defaultfont, bool antialias = true);
void renderText(QString text, int x, int y, float angle = 0.0, QColor color = Qt::black, QFont *font = defaultfont, bool antialias = true);
//! \brief Queues text for gGraphView object to draw it, using given rect.
void renderText(QString text, QRectF rect, int flags = Qt::AlignCenter, float angle = 0.0, QColor color = Qt::black, QFont *font = defaultfont, bool antialias = true);
//! \brief Rounds Y scale values to make them look nice..
// Applies the Graph Preference min/max settings.

View File

@ -440,8 +440,8 @@ void gGraphView::DrawTextQue(QPainter &painter)
// not sure if global antialiasing would be better..
//painter.setRenderHint(QPainter::TextAntialiasing, p_profile->appearance->antiAliasing());
int m_textque_items = m_textque.size();
for (int i = 0; i < m_textque_items; ++i) {
int items = m_textque.size();
for (int i = 0; i < items; ++i) {
TextQue &q = m_textque[i];
painter.setPen(q.color);
painter.setRenderHint(QPainter::TextAntialiasing, q.antialias);
@ -466,6 +466,37 @@ void gGraphView::DrawTextQue(QPainter &painter)
}
m_textque.clear();
items = m_textqueRect.size();
for (int i=0; i< items; ++i) {
TextQueRect &q = m_textqueRect[i];
painter.setPen(q.color);
painter.setRenderHint(QPainter::TextAntialiasing, q.antialias);
QFont font = *q.font;
painter.setFont(font);
if (q.angle == 0) { // normal text
painter.drawText(q.rect, q.flags, q.text);
} else { // rotated text
int x = q.rect.x();
int y = q.rect.y();
w = painter.fontMetrics().width(q.text);
h = painter.fontMetrics().xHeight() + 2;
painter.translate(x, y);
painter.rotate(-q.angle);
painter.drawText(floor(-w / 2.0), floor(-h / 2.0), q.text);
painter.rotate(+q.angle);
painter.translate(-x, -y);
}
strings_drawn_this_frame++;
q.text.clear();
}
m_textqueRect.clear();
}
#else
@ -477,7 +508,6 @@ void gGraphView::DrawTextQue(QPainter &painter)
int h,w;
for (int i = 0; i < m_textque_items; ++i) {
TextQue &q = m_textque[i];
@ -563,11 +593,114 @@ void gGraphView::DrawTextQue(QPainter &painter)
}
m_textque.clear();
////////////////////////////////////////////////////////////////////////
// Text Rectangle Queues..
////////////////////////////////////////////////////////////////////////
int items = m_textqueRect.size();
float ww, hh;
for (int i = 0; i < items; ++i) {
TextQueRect &q = m_textqueRect[i];
// can do antialiased text via texture cache fine on mac
if (usePixmapCache()) {
// Generate the pixmap cache "key"
QString hstr = QString("%1:%2:%3").
arg(q.text).
arg(q.color.name()).
arg(q.font->pointSize());
QPixmap pm;
const int buf = 8;
if (!QPixmapCache::find(hstr, &pm)) {
ww = q.rect.width();
hh = q.rect.height();
pm=QPixmap(ww, hh);
pm.fill(Qt::transparent);
QPainter imgpainter(&pm);
imgpainter.setPen(q.color);
imgpainter.setFont(*q.font);
imgpainter.setRenderHint(QPainter::Antialiasing, true);
imgpainter.setRenderHint(QPainter::TextAntialiasing, true);
QRectF rect(0,0, ww, hh);
imgpainter.drawText(rect, q.flags, q.text);
imgpainter.end();
QPixmapCache::insert(hstr, pm);
strings_drawn_this_frame++;
} else {
//cached
strings_cached_this_frame++;
}
hh = pm.height();
ww = pm.width();
if (q.angle != 0) {
float xxx = q.rect.x() - hh - (hh / 2);
float yyy = q.rect.y() + ww / 2; // + buf / 2;
xxx+=4;
yyy+=4;
painter.translate(xxx, yyy);
painter.rotate(-q.angle);
painter.drawPixmap(QRect(0, hh / 2, ww, hh), pm);
painter.rotate(+q.angle);
painter.translate(-xxx, -yyy);
} else {
painter.drawPixmap(QRect(q.rect.x(), q.rect.y(), ww, hh), pm);
}
} else {
// Just draw the fonts..
painter.setPen(QColor(q.color));
painter.setFont(*q.font);
if (q.angle == 0) {
painter.drawText(q.rect, q.flags, q.text);
} else {
painter.setFont(*q.font);
w = painter.fontMetrics().width(q.text);
h = painter.fontMetrics().xHeight() + 2;
painter.translate(q.rect.x(), q.rect.y());
painter.rotate(-q.angle);
painter.drawText(floor(-ww / 2.0), floor(-hh / 2.0), q.text);
painter.rotate(+q.angle);
painter.translate(-q.rect.x(), -q.rect.y());
}
strings_drawn_this_frame++;
}
//q.text.clear();
//q.text.squeeze();
}
m_textqueRect.clear();
}
#endif
void gGraphView::AddTextQue(const QString &text, short x, short y, float angle, QColor color,
QFont *font, bool antialias)
void gGraphView::AddTextQue(const QString &text, QRectF rect, int flags, float angle, QColor color, QFont *font, bool antialias)
{
#ifdef ENABLED_THREADED_DRAWING
text_mutex.lock();
#endif
m_textqueRect.append(TextQueRect(rect,flags,text,angle,color,font,antialias));
#ifdef ENABLED_THREADED_DRAWING
text_mutex.unlock();
#endif
}
void gGraphView::AddTextQue(const QString &text, short x, short y, float angle, QColor color, QFont *font, bool antialias)
{
#ifdef ENABLED_THREADED_DRAWING
text_mutex.lock();
@ -576,13 +709,6 @@ void gGraphView::AddTextQue(const QString &text, short x, short y, float angle,
#ifdef ENABLED_THREADED_DRAWING
text_mutex.unlock();
#endif
// q.text = text;
// q.x = x;
// q.y = y;
// q.angle = angle;
// q.color = color;
// q.font = font;
// q.antialias = antialias;
}
void gGraphView::addGraph(gGraph *g, short group)

View File

@ -72,6 +72,39 @@ struct TextQue {
bool antialias;
};
struct TextQueRect {
TextQueRect() {
}
TextQueRect(QRectF rect, int flags, QString text, float angle, QColor color, QFont * font, bool antialias):
rect(rect), flags(flags), text(text), angle(angle), color(color), font(font), antialias(antialias)
{
}
TextQueRect(const TextQueRect & copy) {
rect = copy.rect;
flags = copy.flags;
text = copy.text;
angle = copy.angle;
color = copy.color;
font = copy.font;
antialias = copy.antialias;
}
//! \variable contains the QRect containing the text object
QRectF rect;
//! \variable Qt alignment flags..
int flags;
//! \variable the actual text to draw
QString text;
//! \variable the angle in degrees for drawing rotated text
float angle;
//! \variable the color the text will be drawn in
QColor color;
//! \variable a pointer to the QFont to use to draw this text
QFont *font;
//! \variable whether to use antialiasing to draw this text
bool antialias;
};
/*! \class MyScrollBar
\brief An custom scrollbar to interface with gGraphWindow
*/
@ -295,6 +328,10 @@ class gGraphView
//! \brief Updates the current selection time in the statusbar area
void updateSelectionTime();
//! \brief Add the Text information to the Text Drawing Queue (called by gGraphs renderText method)
void AddTextQue(const QString &text, QRectF rect, int flags, float angle = 0.0,
QColor color = Qt::black, QFont *font = defaultfont, bool antialias = true);
//! \brief Add the Text information to the Text Drawing Queue (called by gGraphs renderText method)
void AddTextQue(const QString &text, short x, short y, float angle = 0.0,
QColor color = Qt::black, QFont *font = defaultfont, bool antialias = true);
@ -486,6 +523,9 @@ class gGraphView
//! \brief List of all queue text to draw.. not sure why I didn't use a vector here.. Might of been a leak issue
QVector<TextQue> m_textque;
//! \brief ANother text que with rect alignment capabilities...
QVector<TextQueRect> m_textqueRect;
int m_lastxpos, m_lastypos;
QString m_emptytext;

View File

@ -288,7 +288,9 @@ bool gLineChart::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
{
Q_UNUSED(event)
Q_UNUSED(graph)
return true;
graph->timedRedraw(0);
return false;
}
QString gLineChart::getMetaString(qint64 time)

View File

@ -319,7 +319,7 @@ bool gLineOverlayBar::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
{
Q_UNUSED(event)
Q_UNUSED(graph)
return true;
return false;
}

View File

@ -447,11 +447,23 @@ void SummaryChart::paint(QPainter &painter, gGraph &w, const QRegion &region)
int days = ceil(double(maxx-minx) / 86400000.0);
double lcursor = w.graphView()->currentTime();
if (days >= 1) {
double b = w.max_x - w.min_x;
double a = lcursor - w.min_x;
double c = a / b;
minx = floor(double(minx)/86400000.0);
minx *= 86400000L;
maxx = minx + 86400000L * qint64(days)-1;
b = maxx - minx;
double d = c * b;
lcursor = d + minx;
}
@ -511,8 +523,9 @@ void SummaryChart::paint(QPainter &painter, gGraph &w, const QRegion &region)
lastdaygood = true;
// Display Line Cursor
if (p_profile->appearance->lineCursorMode()) {
qint64 time = w.currentTime();
qint64 time = lcursor;
double xmult = double(width) / xx;
if ((time > minx) && (time < maxx)) {
@ -1063,6 +1076,7 @@ QString formatTime(EventDataType v, bool show_seconds = false, bool duration = f
bool SummaryChart::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
{
graph->timedRedraw(0);
int x = event->x();
int y = event->y();
@ -1253,11 +1267,11 @@ bool SummaryChart::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
}
graph->ToolTip(z, x, y - 15);
return true;
return false;
} else {
QString z = dt.toString(Qt::SystemLocaleShortDate) + "\r\nNo Data";
graph->ToolTip(z, x, y - 15);
return true;
return false;
}
}

View File

@ -405,7 +405,7 @@ bool gYAxis::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
// graph->redraw();
}
return true;
return false;
}
bool gYAxis::mouseDoubleClickEvent(QMouseEvent *event, gGraph *graph)

View File

@ -174,7 +174,7 @@ class Layer
QRect m_rect;
bool m_mouseover;
volatile bool m_recalculating;
public:
// //! \brief A vector containing all this layers custom drawing buffers
// QVector<GLBuffer *> mgl_buffers;

View File

@ -261,7 +261,7 @@ Daily::Daily(QWidget *parent,gGraphView * shared)
SF->setBlockZoom(true);
SF->AddLayer(new gShadowArea());
SF->AddLayer(new gFlagsLabelArea(fg),LayerLeft,gYAxis::Margin);
SF->AddLayer(new gLabelArea(fg),LayerLeft,gYAxis::Margin);
//SF->AddLayer(new gFooBar(),LayerBottom,0,1);
SF->AddLayer(new gXAxis(COLOR_Text,false),LayerBottom,0,20); //gXAxis::Margin);
@ -340,8 +340,9 @@ Daily::Daily(QWidget *parent,gGraphView * shared)
gGraph * TAP2;
graphlist[STR_GRAPH_TAP] = TAP2 = new gGraph(STR_GRAPH_TAP, GraphView, QObject::tr("By Pressure"), QObject::tr("Statistics at Pressure"), default_height);
// TAP2->AddLayer(new gFlagsLabelArea(nullptr),LayerLeft,gYAxis::Margin);
TAP2->AddLayer(AddCPAP(new MinutesAtPressure()));
MinutesAtPressure * map;
TAP2->AddLayer(AddCPAP(map = new MinutesAtPressure()));
TAP2->AddLayer(new gLabelArea(map),LayerLeft,gYAxis::Margin);
TAP2->setBlockSelect(true);
if (p_profile->general->calculateRDI()) {