Debian Codegraph @

memorycellgraphicsitem.cpp

raw symbols SCIP
1 // File: memorycellgraphicsitem.cpp
2 /*
3 Pep8-1 is a virtual machine for writing machine language and assembly
4 language programs.
5
6 Copyright (C) 2009 J. Stanley Warford, Pepperdine University
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "memorycellgraphicsitem.h"
23 #include "pep.h"
24 #include "sim.h"
25 #include <QPainter>
26
27 // #include <QDebug>
28
29 const int MemoryCellGraphicsItem::boxHeight = 22;
30 const int MemoryCellGraphicsItem::boxWidth = 50;
31 const int MemoryCellGraphicsItem::addressWidth = 48;
32 const int MemoryCellGraphicsItem::symbolWidth = 96;
33 const int MemoryCellGraphicsItem::bufferWidth = 14;
34
35 MemoryCellGraphicsItem::MemoryCellGraphicsItem(int addr, QString sym, Enu::ESymbolFormat eSymFrmt, int xLoc, int yLoc)
36 {
37 x = xLoc;
38 y = yLoc;
39 address = addr;
40 symbol = sym;
41 eSymbolFormat = eSymFrmt;
42 boxColor = Qt::black;
43 boxBgColor = Qt::white;
44 textColor = Qt::black;
45 boxTextColor = Qt::black;
46 }
47
48 QRectF MemoryCellGraphicsItem::boundingRect() const
49 {
50 const int Margin = 4;
51 return QRectF(QPointF(x - addressWidth - Margin, y - Margin),
52 QSizeF(addressWidth + bufferWidth * 2 + boxWidth + symbolWidth + Margin * 2, boxHeight + Margin * 2));
53 }
54
55 void MemoryCellGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
56 {
57 QPen pen(boxColor);
58 pen.setWidth(2);
59 painter->setPen(pen);
60 painter->setBrush(boxBgColor);
61 painter->setRenderHint(QPainter::Antialiasing);
62 painter->drawRoundedRect(QRectF(x, y, boxWidth, boxHeight), 2, 2, Qt::RelativeSize);
63
64 painter->setPen(textColor);
65 painter->setRenderHint(QPainter::TextAntialiasing);
66 painter->setFont(QFont(Pep::codeFont, Pep::codeFontSize));
67
68 painter->drawText(QRectF(x - addressWidth - bufferWidth, y, addressWidth, boxHeight), Qt::AlignVCenter | Qt::AlignRight, QString("%1").arg(address, 4, 16, QLatin1Char('0')).toUpper());
69 painter->drawText(QRectF(x + bufferWidth + boxWidth, y, symbolWidth, boxHeight), Qt::AlignVCenter | Qt::AlignLeft, QString("%1").arg(symbol));
70
71 painter->setPen(boxTextColor);
72 painter->drawText(QRectF(x, y, boxWidth, boxHeight), Qt::AlignCenter, value);
73 }
74
75 void MemoryCellGraphicsItem::updateValue()
76 {
77 switch (eSymbolFormat) {
78 case Enu::F_1C:
79 value = QString(QChar(Sim::Mem[address]));
80 break;
81 case Enu::F_1D:
82 value = QString("%1").arg(Sim::Mem[address]);
83 break;
84 case Enu::F_2D:
85 value = QString("%1").arg(Sim::toSignedDecimal(Sim::Mem[address] * 256 + Sim::Mem[address +1]));
86 break;
87 case Enu::F_1H:
88 value = QString("%1").arg(Sim::Mem[address], 2, 16, QLatin1Char('0')).toUpper();
89 break;
90 case Enu::F_2H:
91 value = QString("%1").arg(Sim::Mem[address] * 256 + Sim::Mem[address + 1], 4, 16, QLatin1Char('0')).toUpper();
92 break;
93 default:
94 value = ""; // Should not occur
95 break;
96 }
97 }
98
99 int MemoryCellGraphicsItem::getAddress()
100 {
101 return address;
102 }
103
104 int MemoryCellGraphicsItem::getNumBytes()
105 {
106 return Sim::cellSize(eSymbolFormat);
107 }