Skip to content

Commit ee9b7f1

Browse files
committed
Update the overlay info area on a paint event
1 parent f0d967f commit ee9b7f1

2 files changed

Lines changed: 55 additions & 41 deletions

File tree

src/WidgetImageView.cpp

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,12 @@ void WidgetImageView::paintEvent(QPaintEvent *)
401401
painter.drawRect(m_areaRect);
402402
painter.restore();
403403
}
404+
//------------------------------------------------------------------------
405+
// Update the overlay info lines
406+
//------------------------------------------------------------------------
407+
QPoint mousePos = mapFromGlobal(QCursor::pos());
408+
QPoint imageCoords = m_invtx.map(mousePos);
409+
updateInfoArea(imageCoords);
404410

405411
// Measure the drawing performance
406412
qreal ms = timer.elapsed();
@@ -413,6 +419,53 @@ void WidgetImageView::paintEvent(QPaintEvent *)
413419
}
414420
}
415421

422+
/*
423+
* Update overlay info lines with the information about the given coordinate point on the image map
424+
*/
425+
void WidgetImageView::updateInfoArea(QPoint pt)
426+
{
427+
if (m_image.valid(pt.x(), pt.y()))
428+
{
429+
m_ov->setCoords(QString("%1,%2").arg(pt.x()).arg(pt.y()));
430+
431+
// Get a list of nets, net names and a possible transistor at the mouse location
432+
const QVector<net_t> nets = ::controller.getChip().getNetsAt<true>(pt.x(), pt.y());
433+
QStringList netNames = ::controller.getNetlist().get(nets); // Translate net numbers to names
434+
const tran_t trans = ::controller.getChip().getTransistorAt(pt.x(), pt.y());
435+
436+
// Make all active net names bold
437+
for (uint i = 0; i < netNames.count(); i++)
438+
{
439+
if (::controller.getSimZ80().getNetState(nets[i]) == 1)
440+
netNames[i] = QString("<b>%1</b>").arg(netNames[i]);
441+
}
442+
QString transInfo;
443+
// Insert the transistor name at the front and make the name bold if the transistor is ON
444+
if (trans)
445+
{
446+
transInfo = ::controller.getNetlist().transInfo(trans);
447+
if (::controller.getNetlist().isTransOn(trans))
448+
netNames.insert(0, QString("<b>t%1</b>").arg(trans));
449+
else
450+
netNames.insert(0, QString("t%1").arg(trans));
451+
}
452+
netNames.removeAll(QString()); // Remove any blanks
453+
netNames.removeDuplicates();
454+
m_ov->setInfoLine(1, netNames.join(", "));
455+
456+
QString tip = nets.count() ? ::controller.getTip().get(nets[0]) : QString();
457+
m_ov->setInfoLine(2, trans ? transInfo : tip);
458+
459+
m_ov->setInfoLine(3, ::controller.getChip().getFeaturesAt(pt.x(), pt.y()));
460+
}
461+
else
462+
{
463+
// Oops - the pointer is in this widget, but it's not currently over the image
464+
m_ov->clearInfoLine(0);
465+
m_ov->setCoords(QString());
466+
}
467+
}
468+
416469
void WidgetImageView::calcTransform()
417470
{
418471
int sx = m_image.width();
@@ -526,47 +579,7 @@ void WidgetImageView::mouseMoveEvent(QMouseEvent *event)
526579
{
527580
// With no buttons pushed, update information on which nets or objects the mouse is pointing to
528581
QPoint imageCoords = m_invtx.map(event->pos());
529-
if (m_image.valid(imageCoords.x(), imageCoords.y()))
530-
{
531-
m_ov->setCoords(QString("%1,%2").arg(imageCoords.x()).arg(imageCoords.y()));
532-
533-
// Get a list of nets, net names and a possible transistor at the mouse location
534-
const QVector<net_t> nets = ::controller.getChip().getNetsAt<true>(imageCoords.x(), imageCoords.y());
535-
QStringList netNames = ::controller.getNetlist().get(nets); // Translate net numbers to names
536-
const tran_t trans = ::controller.getChip().getTransistorAt(imageCoords.x(), imageCoords.y());
537-
538-
// Make all active net names bold
539-
for (uint i = 0; i < netNames.count(); i++)
540-
{
541-
if (::controller.getSimZ80().getNetState(nets[i]) == 1)
542-
netNames[i] = QString("<b>%1</b>").arg(netNames[i]);
543-
}
544-
QString transInfo;
545-
// Insert the transistor name at the front and make the name bold if the transistor is ON
546-
if (trans)
547-
{
548-
transInfo = ::controller.getNetlist().transInfo(trans);
549-
if (::controller.getNetlist().isTransOn(trans))
550-
netNames.insert(0, QString("<b>t%1</b>").arg(trans));
551-
else
552-
netNames.insert(0, QString("t%1").arg(trans));
553-
}
554-
netNames.removeAll(QString()); // Remove any blanks
555-
netNames.removeDuplicates();
556-
m_ov->setInfoLine(1, netNames.join(", "));
557-
558-
QString tip = nets.count() ? ::controller.getTip().get(nets[0]) : QString();
559-
m_ov->setInfoLine(2, trans ? transInfo : tip);
560-
561-
m_ov->setInfoLine(3, ::controller.getChip().getFeaturesAt(imageCoords.x(), imageCoords.y()));
562-
}
563-
else
564-
{
565-
// Oops - the pointer is in this widget, but it's not currently over
566-
// the image, so we have no data to report.
567-
m_ov->clearInfoLine(0);
568-
m_ov->setCoords(QString());
569-
}
582+
updateInfoArea(imageCoords);
570583
}
571584
}
572585

src/WidgetImageView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ private slots:
116116
void moveBy(QPointF); // Moves the image in the pane by specified normalized delta
117117
void setZoomMode(ZoomType); // Sets the view mode
118118

119+
void updateInfoArea(QPoint pt);
119120
void calcTransform();
120121
void clampImageCoords(QPointF &tex, qreal xmax = 1.0, qreal ymax = 1.0);
121122
void createLayout();

0 commit comments

Comments
 (0)