mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-20 13:32:04 +08:00
cabana: fix tooltip will not show if chart is partial visible. (#27897)
* use horizontalSpacing * fix chart toopl tip
This commit is contained in:
@@ -512,6 +512,13 @@ void ChartView::mouseMoveEvent(QMouseEvent *ev) {
|
||||
}
|
||||
|
||||
void ChartView::showTip(double sec) {
|
||||
QRect tip_area(0, chart()->plotArea().top(), rect().width(), chart()->plotArea().height());
|
||||
QRect visible_rect = charts_widget->chartVisibleRect(this).intersected(tip_area);
|
||||
if (visible_rect.isEmpty()) {
|
||||
tip_label.hide();
|
||||
return;
|
||||
}
|
||||
|
||||
tooltip_x = chart()->mapToPosition({sec, 0}).x();
|
||||
qreal x = tooltip_x;
|
||||
QStringList text_list(QString::number(chart()->mapToValue({x, 0}).x(), 'f', 3));
|
||||
@@ -532,9 +539,9 @@ void ChartView::showTip(double sec) {
|
||||
.arg(s.series->color().name(), name, value, min, max);
|
||||
}
|
||||
}
|
||||
QPointF tooltip_pt(x, chart()->plotArea().top());
|
||||
int plot_right = mapToGlobal(chart()->plotArea().topRight().toPoint()).x();
|
||||
tip_label.showText(mapToGlobal(tooltip_pt.toPoint()), "<p style='white-space:pre'>" + text_list.join("<br />") + "</p>", plot_right);
|
||||
QPoint pt(x, chart()->plotArea().top());
|
||||
QString text = "<p style='white-space:pre'>" % text_list.join("<br />") % "</p>";
|
||||
tip_label.showText(pt, text, this, visible_rect);
|
||||
viewport()->update();
|
||||
}
|
||||
|
||||
|
||||
@@ -161,14 +161,14 @@ void ChartsWidget::zoomReset() {
|
||||
zoom_undo_stack->clear();
|
||||
}
|
||||
|
||||
void ChartsWidget::showValueTip(double sec) {
|
||||
QRect ChartsWidget::chartVisibleRect(ChartView *chart) {
|
||||
const QRect visible_rect(-charts_container->pos(), charts_scroll->viewport()->size());
|
||||
return chart->rect().intersected(QRect(chart->mapFrom(charts_container, visible_rect.topLeft()), visible_rect.size()));
|
||||
}
|
||||
|
||||
void ChartsWidget::showValueTip(double sec) {
|
||||
for (auto c : currentCharts()) {
|
||||
if (sec >= 0 && visible_rect.contains(QRect(c->mapTo(charts_container, QPoint(0, 0)), c->size()))) {
|
||||
c->showTip(sec);
|
||||
} else {
|
||||
c->hideTip();
|
||||
}
|
||||
sec >= 0 ? c->showTip(sec) : c->hideTip();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ void ChartsWidget::updateLayout(bool force) {
|
||||
auto charts_layout = charts_container->charts_layout;
|
||||
int n = MAX_COLUMN_COUNT;
|
||||
for (; n > 1; --n) {
|
||||
if ((n * CHART_MIN_WIDTH + (n - 1) * charts_layout->spacing()) < charts_layout->geometry().width()) break;
|
||||
if ((n * CHART_MIN_WIDTH + (n - 1) * charts_layout->horizontalSpacing()) < charts_layout->geometry().width()) break;
|
||||
}
|
||||
|
||||
bool show_column_cb = n > 1;
|
||||
|
||||
@@ -59,6 +59,7 @@ private:
|
||||
ChartView *createChart();
|
||||
void removeChart(ChartView *chart);
|
||||
void splitChart(ChartView *chart);
|
||||
QRect chartVisibleRect(ChartView *chart);
|
||||
void eventsMerged();
|
||||
void updateState();
|
||||
void zoomReset();
|
||||
|
||||
@@ -22,18 +22,22 @@ TipLabel::TipLabel(QWidget *parent) : QLabel(parent, Qt::ToolTip | Qt::Frameless
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
void TipLabel::showText(const QPoint &pt, const QString &text, int right_edge) {
|
||||
void TipLabel::showText(const QPoint &pt, const QString &text, QWidget *w, const QRect &rect) {
|
||||
setText(text);
|
||||
if (!text.isEmpty()) {
|
||||
QSize extra(1, 1);
|
||||
resize(sizeHint() + extra);
|
||||
QPoint tip_pos(pt.x() + 12, pt.y());
|
||||
if (tip_pos.x() + size().width() >= right_edge) {
|
||||
QPoint tip_pos(pt.x() + 12, rect.top() + 2);
|
||||
if (tip_pos.x() + size().width() >= rect.right()) {
|
||||
tip_pos.rx() = pt.x() - size().width() - 12;
|
||||
}
|
||||
move(tip_pos);
|
||||
if (rect.contains({tip_pos, size()})) {
|
||||
move(w->mapToGlobal(tip_pos));
|
||||
setVisible(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
setVisible(!text.isEmpty());
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
void TipLabel::paintEvent(QPaintEvent *ev) {
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
class TipLabel : public QLabel {
|
||||
public:
|
||||
TipLabel(QWidget *parent = nullptr);
|
||||
void showText(const QPoint &pt, const QString &sec, int right_edge);
|
||||
void showText(const QPoint &pt, const QString &sec, QWidget *w, const QRect &rect);
|
||||
void paintEvent(QPaintEvent *ev) override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user