Update the breakpoint feature
[clinton/Virtual-Jaguar-Rx.git] / src / debugger / SourceCWin.cpp
1 //
2 // SourceCWin.cpp - Source C tracing window
3 //
4 // by Jean-Paul Mari
5 //
6 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>
7 //
8 // Who When What
9 // --- ---------- -------------------------------------------------------------
10 // JPM 08/23/2019 Created this file
11
12 // STILL TO DO:
13 //
14
15 #include <stdlib.h>
16 #include "DBGManager.h"
17 #include "debugger/SourceCWin.h"
18 #include "debugger/SourcesWin.h"
19 //#include "m68000/m68kinterface.h"
20
21
22 //
23 SourceCWindow::SourceCWindow(QWidget * parent/*= 0*/) : QWidget(parent, Qt::Dialog),
24 layout(new QVBoxLayout),
25 FileIndex(0),
26 CurrentNumLineSrc(0),
27 #ifdef SC_LAYOUTTEXTS
28 text(new QTextBrowser)
29 #else
30 TableView(new QTableView),
31 model(new QStandardItemModel)
32 #endif
33 {
34 // Set font
35 QFont fixedFont("Lucida Console", 8, QFont::Normal);
36 fixedFont.setStyleHint(QFont::Monospace); //TypeWriter
37 fixedFont.setLetterSpacing(QFont::PercentageSpacing, 100);
38
39 // Set text in layout
40 #ifdef SC_LAYOUTTEXTS
41 text->setFont(fixedFont);
42 layout->addWidget(text);
43 #else
44 // Set the new layout with proper identation and readibility
45 model->setColumnCount(3);
46 model->setHeaderData(0, Qt::Horizontal, QObject::tr("LineStatus"));
47 model->setHeaderData(1, Qt::Horizontal, QObject::tr("LineNumber"));
48 model->setHeaderData(2, Qt::Horizontal, QObject::tr("LineSrc"));
49 // Information table
50 TableView->setModel(model);
51 TableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
52 TableView->setSelectionMode(QAbstractItemView::NoSelection);
53 TableView->setShowGrid(false);
54 TableView->horizontalHeader()->hide();
55 TableView->verticalHeader()->hide();
56 TableView->setFont(fixedFont);
57 layout->addWidget(TableView);
58 #endif
59
60 // Set layout
61 setLayout(layout);
62 }
63
64
65 //
66 void SourceCWindow::SetCursorTrace(int NumLineSrc, bool Remove)
67 {
68 // Check valid line number
69 if (NumLineSrc && (NbLinesText[0] >= NumLineSrc))
70 {
71 // Set the trace cursor
72 if (!Remove)
73 {
74 CurrentNumLineSrc = NumLineSrc;
75 #ifndef SC_LAYOUTTEXTS
76 model->item((NumLineSrc - 1), 0)->setText(">");
77 model->item((NumLineSrc - 1), 0)->setBackground(QColor(0xff, 0xfa, 0xcd));
78 model->item((NumLineSrc - 1), 1)->setBackground(QColor(0xff, 0xfa, 0xcd));
79 model->item((NumLineSrc - 1), 2)->setBackground(QColor(0xff, 0xfa, 0xcd));
80 #endif
81 }
82 else
83 {
84 // Remove the trace cursor
85 #ifndef SC_LAYOUTTEXTS
86 model->item((NumLineSrc - 1), 0)->setText(" ");
87 model->item((NumLineSrc - 1), 0)->setBackground(QColor(173, 216, 230));
88 model->item((NumLineSrc - 1), 1)->setBackground(QColor(255, 255, 255));
89 model->item((NumLineSrc - 1), 2)->setBackground(QColor(255, 255, 255));
90 #endif
91 }
92 }
93 }
94
95
96 //
97 void SourceCWindow::RefreshContents(void)
98 {
99 if (isVisible())
100 {
101 // Get the scroll bar information
102 int MaxSlider = TableView->verticalScrollBar()->maximum(); // Get the slider maximum position
103 int DeltaSlider = (int)NbLinesText[0] - MaxSlider; // Number of items displayed in the scroll bar slider
104 //int PosSlider = TableView->verticalScrollBar()->sliderPosition(); // Slider position
105
106 // Check visibility in the scroll bar
107 //if ((CurrentNumLineSrc > PosSlider) && ((CurrentNumLineSrc + (DeltaSlider / 2)) < MaxSlider))
108 {
109 // Set the scroll bar position
110 TableView->verticalScrollBar()->setSliderPosition(CurrentNumLineSrc - (DeltaSlider / 2) - 1);
111 }
112 }
113 }
114
115
116 // Fill the tab with the source text
117 void SourceCWindow::FillTab(size_t index, char **TextLines, size_t NbLines[], size_t *NumLinesUsed)
118 {
119 int i, j, k;
120 #ifdef SC_LAYOUTTEXTS
121 QString s;
122 char string[1024];
123 #endif
124
125 // Save information
126 FileIndex = index;
127 for (i = 0; i < 2; i++)
128 {
129 NbLinesText[i] = NbLines[i];
130 }
131 PtrTextLines = TextLines;
132 PtrNumLinesUsed = NumLinesUsed;
133
134 // Set columns
135 #ifndef SC_LAYOUTTEXTS
136 model->insertRow((int)NbLinesText[0]);
137 #endif
138
139 // Set text lines
140 for (i = j = 0; i < NbLinesText[0]; i++, j = 0)
141 {
142 // prepare space for the line status
143 #ifndef SC_LAYOUTTEXTS
144 model->setItem(i, 0, new QStandardItem(QString("%1").arg(" ")));
145 model->item(i, 0)->setTextAlignment(Qt::AlignCenter);
146 model->item(i, 0)->setBackground(QColor(173, 216, 230));
147 #endif
148 // display line number
149 #ifdef SC_LAYOUTTEXTS
150 sprintf(string, "| <font color='#006400'>%5u</font> | ", (i + 1));
151 s += QString(string);
152 #else
153 model->setItem(i, 1, new QStandardItem(QString(" %1 ").arg((i + 1))));
154 model->item(i, 1)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
155 model->item(i, 1)->setForeground(QColor(0, 0x64, 0));
156 #endif
157 // display source code line
158 #ifndef SC_LAYOUTTEXTS
159 model->setItem(i, 2, new QStandardItem(QString("%1").arg(PtrTextLines[i])));
160 model->item(i, 2)->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
161 #endif
162 // Check line used by code
163 while ((j < NbLinesText[1]) && !(k = ((PtrNumLinesUsed[j++] != i) - 1)));
164 if (k)
165 {
166 // Line is used by code
167 #ifdef SC_LAYOUTTEXTS
168 sprintf(string, "<font color='#000000'><b>%s</b></font>", PtrTextLines[i]);
169 #else
170 model->item(i, 2)->setForeground(QColor(0, 0, 0));
171 #endif
172 }
173 else
174 {
175 // Line is not used by code (such as comments)
176 #ifdef SC_LAYOUTTEXTS
177 sprintf(string, "<font color='#C8C8C8'>%s</font>", PtrTextLines[i]);
178 #else
179 model->item(i, 2)->setForeground(QColor(0xc8, 0xc8, 0xc8));
180 #endif
181 }
182 #ifdef SC_LAYOUTTEXTS
183 s += QString(string);
184 s += QString("<br>");
185 #endif
186 }
187
188 // Display text
189 #ifdef SC_LAYOUTTEXTS
190 text->setText(s);
191 #else
192 TableView->resizeColumnsToContents();
193 TableView->resizeRowsToContents();
194 #endif
195 }