diff options
author | Tomaz Canabrava <tomaz.canabrava@intel.com> | 2015-01-14 17:11:41 -0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-01-15 14:46:57 +1300 |
commit | 6a1a6c82bfbbc455f2c0c9ec85216f248b3152b6 (patch) | |
tree | fdefe2cea5c786579c3e752dbb0b7b2726eb97c8 /qt-ui/profile | |
parent | 3169ec8dc9cf7f385a6662a3d75396c24ba0da5c (diff) | |
download | subsurface-6a1a6c82bfbbc455f2c0c9ec85216f248b3152b6.tar.gz |
Reuse the entry tooltip item and do fewer calls for each mouse move
While analizing the code for the mouse movement I've discovered that
we did a lot of uneeded things: Set the color, the pen, the size
of a fixed-colored line, twice.
We also deleted-newed the same Pixmap / Text for every mouse movement
so now we reuse the 'entryToolTip' that consists of a huge line and
a pixmap, and after that we add the other tooltips that are not static
Also, reduced a lot the number of calls to expand() (that did a lot of
math).
Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/profile')
-rw-r--r-- | qt-ui/profile/divetooltipitem.cpp | 70 | ||||
-rw-r--r-- | qt-ui/profile/divetooltipitem.h | 1 |
2 files changed, 41 insertions, 30 deletions
diff --git a/qt-ui/profile/divetooltipitem.cpp b/qt-ui/profile/divetooltipitem.cpp index db0963208..fc76e50dc 100644 --- a/qt-ui/profile/divetooltipitem.cpp +++ b/qt-ui/profile/divetooltipitem.cpp @@ -23,27 +23,27 @@ void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QP { const IconMetrics& iconMetrics = defaultIconMetrics(); - QGraphicsPixmapItem *iconItem = 0, *pixmapItem = 0; + QGraphicsPixmapItem *iconItem = 0; double yValue = title->boundingRect().height() + iconMetrics.spacing; Q_FOREACH (ToolTip t, toolTips) { yValue += t.second->boundingRect().height(); } + if (entryToolTip.second) { + yValue += entryToolTip.second->boundingRect().height(); + } + iconItem = new QGraphicsPixmapItem(this); if (!icon.isNull()) { - iconItem = new QGraphicsPixmapItem(icon.pixmap(iconMetrics.sz_small, iconMetrics.sz_small), this); - iconItem->setPos(iconMetrics.spacing, yValue); - } else { - if (!pixmap.isNull()) { - pixmapItem = new QGraphicsPixmapItem(pixmap, this); - pixmapItem->setPos(iconMetrics.spacing, yValue); - } + iconItem->setPixmap(icon.pixmap(iconMetrics.sz_small, iconMetrics.sz_small)); + } else if (!pixmap.isNull()) { + iconItem->setPixmap(pixmap); } + iconItem->setPos(iconMetrics.spacing, yValue); QGraphicsSimpleTextItem *textItem = new QGraphicsSimpleTextItem(toolTip, this); textItem->setPos(iconMetrics.spacing + iconMetrics.sz_small + iconMetrics.spacing, yValue); textItem->setBrush(QBrush(Qt::white)); textItem->setFlag(ItemIgnoresTransformations); toolTips.push_back(qMakePair(iconItem, textItem)); - expand(); } void ToolTipItem::clear() @@ -111,11 +111,18 @@ void ToolTipItem::expand() const IconMetrics& iconMetrics = defaultIconMetrics(); double width = 0, height = title->boundingRect().height() + iconMetrics.spacing; - Q_FOREACH (ToolTip t, toolTips) { + Q_FOREACH (const ToolTip& t, toolTips) { if (t.second->boundingRect().width() > width) width = t.second->boundingRect().width(); height += t.second->boundingRect().height(); } + + if (entryToolTip.first) { + if (entryToolTip.second->boundingRect().width() > width) + width = entryToolTip.second->boundingRect().width(); + height += entryToolTip.second->boundingRect().height(); + } + /* Left padding, Icon Size, space, right padding */ width += iconMetrics.spacing + iconMetrics.sz_small + iconMetrics.spacing + iconMetrics.spacing; @@ -148,10 +155,22 @@ ToolTipItem::ToolTipItem(QGraphicsItem *parent) : QGraphicsPathItem(parent), lastTime(-1) { memset(&pInfo, 0, sizeof(pInfo)); - + entryToolTip.first = NULL; + entryToolTip.second = NULL; setFlags(ItemIgnoresTransformations | ItemIsMovable | ItemClipsChildrenToShape); updateTitlePosition(); setZValue(99); + + addToolTip(QString(), QIcon(), QPixmap(16,60)); + entryToolTip = toolTips.first(); + toolTips.clear(); + + separator->setFlag(ItemIgnoresTransformations); + separator->setPen(QPen(Qt::white)); + + title->setFlag(ItemIgnoresTransformations); + title->setPen(QPen(Qt::white, 1)); + title->setBrush(Qt::white); } ToolTipItem::~ToolTipItem() @@ -170,23 +189,13 @@ void ToolTipItem::updateTitlePosition() } title->setPos(boundingRect().width() / 2 - title->boundingRect().width() / 2 - 1, 0); - title->setFlag(ItemIgnoresTransformations); - title->setPen(QPen(Qt::white, 1)); - title->setBrush(Qt::white); - if (toolTips.size() > 0) { - double x1 = 3; - double y1 = title->pos().y() + iconMetrics.spacing / 2 + title->boundingRect().height(); - double x2 = boundingRect().width() - 10; - double y2 = y1; - - separator->setLine(x1, y1, x2, y2); - separator->setFlag(ItemIgnoresTransformations); - separator->setPen(QPen(Qt::white)); - separator->show(); - } else { - separator->hide(); - } + double x1 = 3; + double y1 = title->pos().y() + iconMetrics.spacing / 2 + title->boundingRect().height(); + double x2 = boundingRect().width() - 10; + double y2 = y1; + + separator->setLine(x1, y1, x2, y2); } bool ToolTipItem::isExpanded() const @@ -234,7 +243,6 @@ void ToolTipItem::setTimeAxis(DiveCartesianAxis *axis) void ToolTipItem::refresh(const QPointF &pos) { - int i; struct plot_data *entry; static QPixmap tissues(16,60); static QPainter painter(&tissues); @@ -263,10 +271,11 @@ void ToolTipItem::refresh(const QPointF &pos) painter.drawLine(0, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure / 2, 16, 60 - AMB_PERCENTAGE * (entry->pressures.n2 + entry->pressures.he) / entry->ambpressure /2); painter.setPen(QColor(0, 0, 0, 127)); - for (i=0; i<16; i++) { + for (int i=0; i<16; i++) { painter.drawLine(i, 60, i, 60 - entry->percentages[i] / 2); } - addToolTip(QString::fromUtf8(mb.buffer, mb.len),QIcon(), tissues); + entryToolTip.first->setPixmap(tissues); + entryToolTip.second->setText(QString::fromUtf8(mb.buffer, mb.len)); } Q_FOREACH (QGraphicsItem *item, scene()->items(pos, Qt::IntersectsItemBoundingRect @@ -274,6 +283,7 @@ void ToolTipItem::refresh(const QPointF &pos) if (!item->toolTip().isEmpty()) addToolTip(item->toolTip()); } + expand(); } void ToolTipItem::mousePressEvent(QGraphicsSceneMouseEvent *event) diff --git a/qt-ui/profile/divetooltipitem.h b/qt-ui/profile/divetooltipitem.h index bb3ad84d3..ca5bc8905 100644 --- a/qt-ui/profile/divetooltipitem.h +++ b/qt-ui/profile/divetooltipitem.h @@ -50,6 +50,7 @@ slots: private: typedef QPair<QGraphicsPixmapItem *, QGraphicsSimpleTextItem *> ToolTip; QVector<ToolTip> toolTips; + ToolTip entryToolTip; QGraphicsPathItem *background; QGraphicsLineItem *separator; QGraphicsSimpleTextItem *title; |