File indexing completed on 2024-05-19 09:39:50

0001 /***************************************************************************
0002  *   Copyright (C) 2005 by David Saxton                                    *
0003  *   david@bluehaze.org                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #include "config.h"
0012 #ifndef NO_GPSIM
0013 
0014 #include "gpsimprocessor.h"
0015 #include "symbolviewer.h"
0016 #include "textview.h"
0017 #include "variablelabel.h"
0018 
0019 // BEGIN class VariableLabel
0020 VariableLabel::VariableLabel(TextView *parent)
0021     : QLabel(parent, Qt::WindowStaysOnTopHint /* | Qt::WStyle_Customize */ | Qt::FramelessWindowHint | Qt::Tool | Qt::X11BypassWindowManagerHint)
0022 {
0023     setObjectName("toolTipTip");
0024 
0025     m_value = -1;
0026 
0027     setMargin(1);
0028     // setAutoMask( false ); // TODO is this needed?
0029     setFrameStyle(QFrame::Plain | QFrame::Box);
0030     setLineWidth(1);
0031     setAlignment(Qt::AlignLeft | Qt::AlignTop);
0032     setIndent(0);
0033     ensurePolished();
0034     adjustSize();
0035 }
0036 
0037 void VariableLabel::setRegister(RegisterInfo *info, const QString &name)
0038 {
0039     disconnectRegisterInfo();
0040 
0041     if (!info)
0042         return;
0043 
0044     m_value = -1;
0045     m_pRegisterInfo = info;
0046     m_registerName = name;
0047 
0048     connect(m_pRegisterInfo, &RegisterInfo::destroyed, this, &VariableLabel::hide);
0049     connect(m_pRegisterInfo, &RegisterInfo::valueChanged, this, &VariableLabel::updateText);
0050 
0051     updateText();
0052 }
0053 
0054 void VariableLabel::disconnectRegisterInfo()
0055 {
0056     if (!m_pRegisterInfo)
0057         return;
0058 
0059     disconnect(m_pRegisterInfo, &RegisterInfo::destroyed, this, &VariableLabel::hide);
0060     disconnect(m_pRegisterInfo, &RegisterInfo::valueChanged, this, &VariableLabel::updateText);
0061 
0062     m_pRegisterInfo = nullptr;
0063     m_registerName = QString();
0064 }
0065 
0066 void VariableLabel::setValue(unsigned value)
0067 {
0068     disconnectRegisterInfo();
0069     m_value = value;
0070 
0071     updateText();
0072 }
0073 
0074 void VariableLabel::updateText()
0075 {
0076     if (m_pRegisterInfo)
0077         setText(QString("%1 = %2").arg(m_registerName).arg(SymbolViewer::self()->toDisplayString(m_pRegisterInfo->value())));
0078 
0079     else if (m_value != -1)
0080         setText(QString::number(m_value));
0081 
0082     adjustSize();
0083 }
0084 // END class VariableLabel
0085 
0086 #include "moc_variablelabel.cpp"
0087 
0088 #endif // !NO_GPSIM