mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-07 03:30:44 +00:00
Use tooltips for overlay information instead. Add alignment ability to tooltips
This commit is contained in:
parent
45d1430de9
commit
3d22d869d6
@ -148,7 +148,7 @@ bool gFlagsGroup::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
|
|||||||
// Display tooltip
|
// Display tooltip
|
||||||
QString ttip = schema::channel[fl->code()].fullname() + "\n" +
|
QString ttip = schema::channel[fl->code()].fullname() + "\n" +
|
||||||
schema::channel[fl->code()].description();
|
schema::channel[fl->code()].description();
|
||||||
graph->ToolTip(ttip, event->x(), event->y() - 15);
|
graph->ToolTip(ttip, event->x()+15, event->y(), TT_AlignLeft);
|
||||||
graph->timedRedraw(30);
|
graph->timedRedraw(30);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -509,13 +509,13 @@ void gGraph::ResetBounds()
|
|||||||
max_y = MaxY();
|
max_y = MaxY();
|
||||||
}
|
}
|
||||||
|
|
||||||
void gGraph::ToolTip(QString text, int x, int y, int timeout)
|
void gGraph::ToolTip(QString text, int x, int y, ToolTipAlignment align, int timeout)
|
||||||
{
|
{
|
||||||
if (timeout <= 0) {
|
if (timeout <= 0) {
|
||||||
timeout = p_profile->general->tooltipTimeout();
|
timeout = p_profile->general->tooltipTimeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_graphview->m_tooltip->display(text, x, y, timeout);
|
m_graphview->m_tooltip->display(text, x, y, align, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// YAxis Autoscaling code
|
// YAxis Autoscaling code
|
||||||
|
@ -239,7 +239,7 @@ class gGraph : public QObject
|
|||||||
virtual void paint(QPainter &painter, const QRegion ®ion);
|
virtual void paint(QPainter &painter, const QRegion ®ion);
|
||||||
|
|
||||||
//! \brief Gives the supplied data to the main ToolTip object for display
|
//! \brief Gives the supplied data to the main ToolTip object for display
|
||||||
void ToolTip(QString text, int x, int y, int timeout = 0);
|
void ToolTip(QString text, int x, int y, ToolTipAlignment align = TT_AlignCenter, int timeout = 0);
|
||||||
|
|
||||||
//! \brief Public version of updateGL(), to redraw all graphs.. Not for normal use
|
//! \brief Public version of updateGL(), to redraw all graphs.. Not for normal use
|
||||||
void redraw();
|
void redraw();
|
||||||
|
@ -47,6 +47,7 @@ gToolTip::gToolTip(gGraphView *graphview)
|
|||||||
m_pos.setX(0);
|
m_pos.setX(0);
|
||||||
m_pos.setY(0);
|
m_pos.setY(0);
|
||||||
m_visible = false;
|
m_visible = false;
|
||||||
|
m_alignment = TT_AlignCenter;
|
||||||
m_spacer = 8; // pixels around text area
|
m_spacer = 8; // pixels around text area
|
||||||
timer = new QTimer(graphview);
|
timer = new QTimer(graphview);
|
||||||
connect(timer, SIGNAL(timeout()), SLOT(timerDone()));
|
connect(timer, SIGNAL(timeout()), SLOT(timerDone()));
|
||||||
@ -64,11 +65,12 @@ w+=m_spacer*2;
|
|||||||
h+=m_spacer*2; */
|
h+=m_spacer*2; */
|
||||||
//}
|
//}
|
||||||
|
|
||||||
void gToolTip::display(QString text, int x, int y, int timeout)
|
void gToolTip::display(QString text, int x, int y, ToolTipAlignment align, int timeout)
|
||||||
{
|
{
|
||||||
if (timeout <= 0) {
|
if (timeout <= 0) {
|
||||||
timeout = p_profile->general->tooltipTimeout();
|
timeout = p_profile->general->tooltipTimeout();
|
||||||
}
|
}
|
||||||
|
m_alignment = align;
|
||||||
|
|
||||||
m_text = text;
|
m_text = text;
|
||||||
m_visible = true;
|
m_visible = true;
|
||||||
@ -104,6 +106,7 @@ void gToolTip::paint(QPainter &painter) //actually paints it.
|
|||||||
int y = m_pos.y();
|
int y = m_pos.y();
|
||||||
|
|
||||||
QRect rect(x, y, 0, 0);
|
QRect rect(x, y, 0, 0);
|
||||||
|
|
||||||
painter.setFont(*defaultfont);
|
painter.setFont(*defaultfont);
|
||||||
|
|
||||||
rect = painter.boundingRect(rect, Qt::AlignCenter, m_text);
|
rect = painter.boundingRect(rect, Qt::AlignCenter, m_text);
|
||||||
@ -131,6 +134,16 @@ void gToolTip::paint(QPainter &painter) //actually paints it.
|
|||||||
rect.setHeight(h);
|
rect.setHeight(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_alignment == TT_AlignRight) {
|
||||||
|
rect.moveTopRight(m_pos);
|
||||||
|
if ((x-w) < 0) {
|
||||||
|
rect.moveLeft(0);
|
||||||
|
}
|
||||||
|
} else if (m_alignment == TT_AlignLeft) {
|
||||||
|
rect.moveTopLeft(m_pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QBrush brush(QColor(255, 255, 128, 230));
|
QBrush brush(QColor(255, 255, 128, 230));
|
||||||
brush.setStyle(Qt::SolidPattern);
|
brush.setStyle(Qt::SolidPattern);
|
||||||
painter.setBrush(brush);
|
painter.setBrush(brush);
|
||||||
|
@ -124,7 +124,7 @@ class gToolTip : public QObject
|
|||||||
/*! \fn virtual void display(QString text, int x, int y, int timeout=2000);
|
/*! \fn virtual void display(QString text, int x, int y, int timeout=2000);
|
||||||
\brief Set the tooltips display message, position, and timeout value
|
\brief Set the tooltips display message, position, and timeout value
|
||||||
*/
|
*/
|
||||||
virtual void display(QString text, int x, int y, int timeout = 0);
|
virtual void display(QString text, int x, int y, ToolTipAlignment align = TT_AlignCenter, int timeout = 0);
|
||||||
|
|
||||||
//! \brief Draw the tooltip
|
//! \brief Draw the tooltip
|
||||||
virtual void paint(QPainter &paint); //actually paints it.
|
virtual void paint(QPainter &paint); //actually paints it.
|
||||||
@ -145,6 +145,7 @@ class gToolTip : public QObject
|
|||||||
int m_spacer;
|
int m_spacer;
|
||||||
QImage m_image;
|
QImage m_image;
|
||||||
bool m_invalidate;
|
bool m_invalidate;
|
||||||
|
ToolTipAlignment m_alignment;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
|
|
||||||
|
@ -215,16 +215,19 @@ void gLineOverlayBar::paint(QPainter &painter, gGraph &w, const QRegion ®ion)
|
|||||||
|
|
||||||
|
|
||||||
if ((m_flt == FT_Bar) && (odt == ODT_Bars)) { // || (xx < 3600000)) {
|
if ((m_flt == FT_Bar) && (odt == ODT_Bars)) { // || (xx < 3600000)) {
|
||||||
QRect rect(x1-d1-2, top, d1+2, height);
|
QRect rect(x1-d1, top, d1+4, height);
|
||||||
QColor col = m_flag_color;
|
QColor col = m_flag_color;
|
||||||
|
|
||||||
|
|
||||||
painter.setPen(QPen(col,4));
|
painter.setPen(QPen(col,4));
|
||||||
painter.drawPoint(x1, top);
|
painter.drawPoint(x1, top);
|
||||||
|
|
||||||
if (rect.contains(mouse)) {
|
if (!m_blockhover && rect.contains(mouse) && !m_hover) {
|
||||||
|
m_hover = true;
|
||||||
|
|
||||||
|
|
||||||
QColor col2(230,230,230,128);
|
QColor col2(230,230,230,128);
|
||||||
QRect rect(x1-d1, start_py+2, d1, height-2);
|
QRect rect((x1-d1), start_py+2, d1, height-2);
|
||||||
if (rect.x() < left) {
|
if (rect.x() < left) {
|
||||||
rect.setX(left);
|
rect.setX(left);
|
||||||
}
|
}
|
||||||
@ -232,6 +235,18 @@ void gLineOverlayBar::paint(QPainter &painter, gGraph &w, const QRegion ®ion)
|
|||||||
painter.fillRect(rect, QBrush(col2));
|
painter.fillRect(rect, QBrush(col2));
|
||||||
painter.setPen(col);
|
painter.setPen(col);
|
||||||
painter.drawRect(rect);
|
painter.drawRect(rect);
|
||||||
|
|
||||||
|
// Draw text label
|
||||||
|
QString lab = QString("%1 (%2)").arg(schema::channel[m_code].label()).arg(raw);
|
||||||
|
GetTextExtent(lab, x, y);
|
||||||
|
|
||||||
|
w.ToolTip(lab, x1 - 10, start_py + 24 + (3 * w.printScaleY()), TT_AlignRight, p_profile->general->tooltipTimeout());
|
||||||
|
|
||||||
|
//painter.fillRect(x1 - (x / 2) - x, start_py + 14 + (3 * w.printScaleY()), x+4,y+4, QBrush(QColor(255,255,255,245)));
|
||||||
|
// painter.setPen(QPen(Qt::gray,1));
|
||||||
|
// painter.drawRect(x1 - (x / 2) - x, start_py + 14 + (3 * w.printScaleY()), x+4,y+4);
|
||||||
|
// w.renderText(lab, x1 - (x / 2)+2 - x, start_py + 14 + y + (3 * w.printScaleY()),0);
|
||||||
|
|
||||||
// painter.drawLine(rect.x(), top, rect.x()+d1, top);
|
// painter.drawLine(rect.x(), top, rect.x()+d1, top);
|
||||||
// painter.drawLine(rect.x(), bottom, rect.x()+d1, bottom);
|
// painter.drawLine(rect.x(), bottom, rect.x()+d1, bottom);
|
||||||
// painter.drawLine(rect.x(), top, rect.x(), bottom);
|
// painter.drawLine(rect.x(), top, rect.x(), bottom);
|
||||||
@ -242,21 +257,10 @@ void gLineOverlayBar::paint(QPainter &painter, gGraph &w, const QRegion ®ion)
|
|||||||
painter.setPen(QPen(col,1));
|
painter.setPen(QPen(col,1));
|
||||||
painter.drawLine(x1, top, x1, bottom);
|
painter.drawLine(x1, top, x1, bottom);
|
||||||
}
|
}
|
||||||
QColor txcol = hover ? Qt::red: Qt::black;
|
if (xx < (3600000)) {
|
||||||
|
QString lab = QString("%1").arg(m_label).arg(raw);
|
||||||
if (xx < 300000) {
|
|
||||||
QString lab = QString("%1 (%2)").arg(schema::channel[m_code].fullname()).arg(raw);
|
|
||||||
GetTextExtent(lab, x, y);
|
GetTextExtent(lab, x, y);
|
||||||
w.renderText(lab, x1 - (x / 2)+2, top - y + (3 * w.printScaleY()),0,txcol);
|
w.renderText(lab, x1 - (x / 2), top - y + (3 * w.printScaleY()),0);
|
||||||
} else if (xx < (3600000)) {
|
|
||||||
if (!hover) {
|
|
||||||
GetTextExtent(m_label, x, y);
|
|
||||||
w.renderText(m_label, x1 - (x / 2)+2, top - y + (3 * w.printScaleY()),0,txcol);
|
|
||||||
} else {
|
|
||||||
QString lab = QString("%1 (%2)").arg(m_label).arg(raw);
|
|
||||||
GetTextExtent(lab, x, y);
|
|
||||||
w.renderText(lab, x1 - (x / 2)+2, top - y + (3 * w.printScaleY()),0,txcol);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -272,11 +276,14 @@ void gLineOverlayBar::paint(QPainter &painter, gGraph &w, const QRegion ®ion)
|
|||||||
|
|
||||||
// Draw text label
|
// Draw text label
|
||||||
QString lab = QString("%1 (%2)").arg(schema::channel[m_code].label()).arg(raw);
|
QString lab = QString("%1 (%2)").arg(schema::channel[m_code].label()).arg(raw);
|
||||||
GetTextExtent(lab, x, y);
|
GetTextExtent(lab, x, y, defaultfont);
|
||||||
painter.fillRect(x1 - (x / 2) - x, start_py + 14 + (3 * w.printScaleY()), x+4,y+4, QBrush(QColor(255,255,255,245)));
|
|
||||||
painter.setPen(QPen(Qt::gray,1));
|
w.ToolTip(lab, x1 - 10, start_py + 24 + (3 * w.printScaleY()), TT_AlignRight, p_profile->general->tooltipTimeout());
|
||||||
painter.drawRect(x1 - (x / 2) - x, start_py + 14 + (3 * w.printScaleY()), x+4,y+4);
|
|
||||||
w.renderText(lab, x1 - (x / 2)+2 - x, start_py + 14 + y + (3 * w.printScaleY()),0);
|
// painter.fillRect(x1 - (x / 2) - x, start_py + 14 + (3 * w.printScaleY()), x+4,y+4, QBrush(QColor(255,255,255,245)));
|
||||||
|
// painter.setPen(QPen(Qt::gray,1));
|
||||||
|
// painter.drawRect(x1 - (x / 2) - x, start_py + 14 + (3 * w.printScaleY()), x+4,y+4);
|
||||||
|
// w.renderText(lab, x1 - (x / 2)+2 - x, start_py + 14 + y + (3 * w.printScaleY()),0);
|
||||||
|
|
||||||
//x1-=1;
|
//x1-=1;
|
||||||
QColor col = m_flag_color;
|
QColor col = m_flag_color;
|
||||||
|
@ -1252,11 +1252,11 @@ bool SummaryChart::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
graph->ToolTip(z, x, y - 15, p_profile->general->tooltipTimeout());
|
graph->ToolTip(z, x, y - 15);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
QString z = dt.toString(Qt::SystemLocaleShortDate) + "\r\nNo Data";
|
QString z = dt.toString(Qt::SystemLocaleShortDate) + "\r\nNo Data";
|
||||||
graph->ToolTip(z, x, y - 15, p_profile->general->tooltipTimeout());
|
graph->ToolTip(z, x, y - 15);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -401,7 +401,7 @@ bool gYAxis::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
|
|||||||
int y = event->y();
|
int y = event->y();
|
||||||
|
|
||||||
if (!graph->units().isEmpty()) {
|
if (!graph->units().isEmpty()) {
|
||||||
graph->ToolTip(graph->units(), x, y - 20, 0);
|
graph->ToolTip(graph->units(), x+10, y+10, TT_AlignLeft);
|
||||||
// graph->redraw();
|
// graph->redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,8 @@ class LayerGroup;
|
|||||||
|
|
||||||
enum LayerPosition { LayerLeft, LayerRight, LayerTop, LayerBottom, LayerCenter, LayerOverlay };
|
enum LayerPosition { LayerLeft, LayerRight, LayerTop, LayerBottom, LayerCenter, LayerOverlay };
|
||||||
|
|
||||||
|
enum ToolTipAlignment { TT_AlignCenter, TT_AlignLeft, TT_AlignRight };
|
||||||
|
|
||||||
/*! \class Layer
|
/*! \class Layer
|
||||||
\brief The base component for all individual Graph layers
|
\brief The base component for all individual Graph layers
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user