2 // SourceCWin.cpp - Source C tracing window
6 // JPM = Jean-Paul Mari <djipi.mari@gmail.com>
9 // --- ---------- -------------------------------------------------------------
10 // JPM 08/23/2019 Created this file
16 #include "DBGManager.h"
17 #include "debugger/SourceCWin.h"
18 #include "debugger/SourcesWin.h"
19 //#include "m68000/m68kinterface.h"
23 SourceCWindow::SourceCWindow(QWidget
* parent
/*= 0*/) : QWidget(parent
, Qt::Dialog
),
24 layout(new QVBoxLayout
),
28 text(new QTextBrowser
)
30 TableView(new QTableView
),
31 model(new QStandardItemModel
)
35 QFont
fixedFont("Lucida Console", 8, QFont::Normal
);
36 fixedFont
.setStyleHint(QFont::Monospace
); //TypeWriter
37 fixedFont
.setLetterSpacing(QFont::PercentageSpacing
, 100);
41 text
->setFont(fixedFont
);
42 layout
->addWidget(text
);
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"));
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
);
66 void SourceCWindow::SetCursorTrace(int NumLineSrc
, bool Remove
)
68 // Check valid line number
69 if (NumLineSrc
&& (NbLinesText
[0] >= NumLineSrc
))
71 // Set the trace cursor
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));
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));
97 void SourceCWindow::RefreshContents(void)
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
106 // Check visibility in the scroll bar
107 //if ((CurrentNumLineSrc > PosSlider) && ((CurrentNumLineSrc + (DeltaSlider / 2)) < MaxSlider))
109 // Set the scroll bar position
110 TableView
->verticalScrollBar()->setSliderPosition(CurrentNumLineSrc
- (DeltaSlider
/ 2) - 1);
116 // Fill the tab with the source text
117 void SourceCWindow::FillTab(size_t index
, char **TextLines
, size_t NbLines
[], size_t *NumLinesUsed
)
120 #ifdef SC_LAYOUTTEXTS
127 for (i
= 0; i
< 2; i
++)
129 NbLinesText
[i
] = NbLines
[i
];
131 PtrTextLines
= TextLines
;
132 PtrNumLinesUsed
= NumLinesUsed
;
135 #ifndef SC_LAYOUTTEXTS
136 model
->insertRow((int)NbLinesText
[0]);
140 for (i
= j
= 0; i
< NbLinesText
[0]; i
++, j
= 0)
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));
148 // display line number
149 #ifdef SC_LAYOUTTEXTS
150 sprintf(string
, "| <font color='#006400'>%5u</font> | ", (i
+ 1));
151 s
+= QString(string
);
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));
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
);
162 // Check line used by code
163 while ((j
< NbLinesText
[1]) && !(k
= ((PtrNumLinesUsed
[j
++] != i
) - 1)));
166 // Line is used by code
167 #ifdef SC_LAYOUTTEXTS
168 sprintf(string
, "<font color='#000000'><b>%s</b></font>", PtrTextLines
[i
]);
170 model
->item(i
, 2)->setForeground(QColor(0, 0, 0));
175 // Line is not used by code (such as comments)
176 #ifdef SC_LAYOUTTEXTS
177 sprintf(string
, "<font color='#C8C8C8'>%s</font>", PtrTextLines
[i
]);
179 model
->item(i
, 2)->setForeground(QColor(0xc8, 0xc8, 0xc8));
182 #ifdef SC_LAYOUTTEXTS
183 s
+= QString(string
);
184 s
+= QString("<br>");
189 #ifdef SC_LAYOUTTEXTS
192 TableView
->resizeColumnsToContents();
193 TableView
->resizeRowsToContents();