mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-05 02: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
|
||||
QString ttip = schema::channel[fl->code()].fullname() + "\n" +
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -509,13 +509,13 @@ void gGraph::ResetBounds()
|
||||
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) {
|
||||
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
|
||||
|
@ -239,7 +239,7 @@ class gGraph : public QObject
|
||||
virtual void paint(QPainter &painter, const QRegion ®ion);
|
||||
|
||||
//! \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
|
||||
void redraw();
|
||||
|
@ -47,6 +47,7 @@ gToolTip::gToolTip(gGraphView *graphview)
|
||||
m_pos.setX(0);
|
||||
m_pos.setY(0);
|
||||
m_visible = false;
|
||||
m_alignment = TT_AlignCenter;
|
||||
m_spacer = 8; // pixels around text area
|
||||
timer = new QTimer(graphview);
|
||||
connect(timer, SIGNAL(timeout()), SLOT(timerDone()));
|
||||
@ -64,11 +65,12 @@ w+=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) {
|
||||
timeout = p_profile->general->tooltipTimeout();
|
||||
}
|
||||
m_alignment = align;
|
||||
|
||||
m_text = text;
|
||||
m_visible = true;
|
||||
@ -104,6 +106,7 @@ void gToolTip::paint(QPainter &painter) //actually paints it.
|
||||
int y = m_pos.y();
|
||||
|
||||
QRect rect(x, y, 0, 0);
|
||||
|
||||
painter.setFont(*defaultfont);
|
||||
|
||||
rect = painter.boundingRect(rect, Qt::AlignCenter, m_text);
|
||||
@ -131,6 +134,16 @@ void gToolTip::paint(QPainter &painter) //actually paints it.
|
||||
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));
|
||||
brush.setStyle(Qt::SolidPattern);
|
||||
painter.setBrush(brush);
|
||||
|
@ -124,7 +124,7 @@ class gToolTip : public QObject
|
||||
/*! \fn virtual void display(QString text, int x, int y, int timeout=2000);
|
||||
\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
|
||||
virtual void paint(QPainter &paint); //actually paints it.
|
||||
@ -145,6 +145,7 @@ class gToolTip : public QObject
|
||||
int m_spacer;
|
||||
QImage m_image;
|
||||
bool m_invalidate;
|
||||
ToolTipAlignment m_alignment;
|
||||
|
||||
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)) {
|
||||
QRect rect(x1-d1-2, top, d1+2, height);
|
||||
QRect rect(x1-d1, top, d1+4, height);
|
||||
QColor col = m_flag_color;
|
||||
|
||||
|
||||
painter.setPen(QPen(col,4));
|
||||
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);
|
||||
QRect rect(x1-d1, start_py+2, d1, height-2);
|
||||
QRect rect((x1-d1), start_py+2, d1, height-2);
|
||||
if (rect.x() < left) {
|
||||
rect.setX(left);
|
||||
}
|
||||
@ -232,6 +235,18 @@ void gLineOverlayBar::paint(QPainter &painter, gGraph &w, const QRegion ®ion)
|
||||
painter.fillRect(rect, QBrush(col2));
|
||||
painter.setPen(col);
|
||||
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(), bottom, rect.x()+d1, 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.drawLine(x1, top, x1, bottom);
|
||||
}
|
||||
QColor txcol = hover ? Qt::red: Qt::black;
|
||||
|
||||
if (xx < 300000) {
|
||||
QString lab = QString("%1 (%2)").arg(schema::channel[m_code].fullname()).arg(raw);
|
||||
if (xx < (3600000)) {
|
||||
QString lab = QString("%1").arg(m_label).arg(raw);
|
||||
GetTextExtent(lab, x, y);
|
||||
w.renderText(lab, x1 - (x / 2)+2, top - y + (3 * w.printScaleY()),0,txcol);
|
||||
} 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);
|
||||
}
|
||||
w.renderText(lab, x1 - (x / 2), top - y + (3 * w.printScaleY()),0);
|
||||
}
|
||||
|
||||
|
||||
@ -272,11 +276,14 @@ void gLineOverlayBar::paint(QPainter &painter, gGraph &w, const QRegion ®ion)
|
||||
|
||||
// Draw text label
|
||||
QString lab = QString("%1 (%2)").arg(schema::channel[m_code].label()).arg(raw);
|
||||
GetTextExtent(lab, x, y);
|
||||
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);
|
||||
GetTextExtent(lab, x, y, defaultfont);
|
||||
|
||||
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);
|
||||
|
||||
//x1-=1;
|
||||
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;
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -401,7 +401,7 @@ bool gYAxis::mouseMoveEvent(QMouseEvent *event, gGraph *graph)
|
||||
int y = event->y();
|
||||
|
||||
if (!graph->units().isEmpty()) {
|
||||
graph->ToolTip(graph->units(), x, y - 20, 0);
|
||||
graph->ToolTip(graph->units(), x+10, y+10, TT_AlignLeft);
|
||||
// graph->redraw();
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,8 @@ class LayerGroup;
|
||||
|
||||
enum LayerPosition { LayerLeft, LayerRight, LayerTop, LayerBottom, LayerCenter, LayerOverlay };
|
||||
|
||||
enum ToolTipAlignment { TT_AlignCenter, TT_AlignLeft, TT_AlignRight };
|
||||
|
||||
/*! \class Layer
|
||||
\brief The base component for all individual Graph layers
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user