| 1 | // File: helpdialog.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 | #include <QClipboard> |
| 22 | #include "helpdialog.h" |
| 23 | #include "ui_helpdialog.h" |
| 24 | #include "pep.h" |
| 25 | |
| 26 | HelpDialog::HelpDialog(QWidget *parent) : |
| 27 | QDialog(parent), |
| 28 | ui(new Ui::HelpDialog) |
| 29 | { |
| 30 | ui->setupUi(this); |
| 31 | |
| 32 | connect(ui->treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, |
| 33 | SLOT(onCurrentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*))); |
| 34 | // Forward the copyToSourceButton_clicked() signal from this to the main window |
| 35 | connect(ui->copyToSourceButton, SIGNAL(clicked()), this, SIGNAL(clicked())); |
| 36 | |
| 37 | ui->helpSplitter->widget(1)->hide(); |
| 38 | ui->treeWidget->expandAll(); |
| 39 | |
| 40 | selectItem("Writing Programs"); |
| 41 | |
| 42 | leftHighlighter = new PepHighlighter(ui->leftTextEdit->document()); |
| 43 | rightCppHighlighter = new CppHighlighter(ui->rightCppTextEdit->document()); |
| 44 | rightPepHighlighter = new PepHighlighter(ui->rightPepTextEdit->document()); |
| 45 | |
| 46 | ui->copyToSourceButton->setFont(QFont(Pep::labelFont)); |
| 47 | if (Pep::getSystem() == "Linux") { |
| 48 | ui->treeWidget->setFont(QFont(Pep::labelFont, 8)); |
| 49 | } |
| 50 | else if (Pep::getSystem() == "Windows") { |
| 51 | ui->treeWidget->setFont(QFont(Pep::labelFont, 8)); // I don't know if this is the proper font size. |
| 52 | } |
| 53 | |
| 54 | ui->rightCppTextEdit->setFont(QFont(Pep::codeFont, Pep::codeFontSize)); |
| 55 | ui->rightPepTextEdit->setFont(QFont(Pep::codeFont, Pep::codeFontSize)); |
| 56 | ui->leftTextEdit->setFont(QFont(Pep::codeFont, Pep::codeFontSize)); |
| 57 | } |
| 58 | |
| 59 | HelpDialog::~HelpDialog() |
| 60 | { |
| 61 | delete ui; |
| 62 | } |
| 63 | |
| 64 | void HelpDialog::selectItem(QString string) { |
| 65 | QTreeWidgetItemIterator it(ui->treeWidget); |
| 66 | while (*it) { |
| 67 | if ((*it)->text(0) == string) { |
| 68 | (*it)->setSelected(true); |
| 69 | ui->treeWidget->setCurrentItem((*it)); |
| 70 | } else { |
| 71 | (*it)->setSelected(false); |
| 72 | } |
| 73 | ++it; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | void HelpDialog::onCurrentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*) { |
| 78 | // Is this a subcategory? |
| 79 | bool isHelpSubCat = ui->treeWidget->currentIndex().parent().isValid(); |
| 80 | // Parent row (if it has a parent, -1 else) |
| 81 | int parentRow = ui->treeWidget->currentIndex().parent().row(); |
| 82 | // Row (if it has a parent, this is the child row) |
| 83 | int row = ui->treeWidget->currentIndex().row(); |
| 84 | |
| 85 | // qDebug() << "Selected: " << ui->treeWidget->currentIndex(); |
| 86 | |
| 87 | if ((!isHelpSubCat && row == eWRITING) || parentRow == eWRITING) { |
| 88 | ui->helpSplitter->widget(1)->hide(); |
| 89 | ui->webEngineView->show(); |
| 90 | if (!isHelpSubCat) { // Writing Programs |
| 91 | ui->webEngineView->load(QUrl("qrc:/help/writingprograms.html")); |
| 92 | } |
| 93 | else if (row == eMACHINE) { // Writing Programs > Machine Language |
| 94 | ui->webEngineView->load(QUrl("qrc:/help/machinelanguage.html")); |
| 95 | } |
| 96 | else if (row == eASSEMBLY) { // Writing Programs > Assembly Language |
| 97 | ui->webEngineView->load(QUrl("qrc:/help/assemblylanguage.html")); |
| 98 | } |
| 99 | } |
| 100 | else if (!isHelpSubCat && row == eDEBUGGING) { |
| 101 | ui->helpSplitter->widget(1)->hide(); |
| 102 | ui->webEngineView->show(); |
| 103 | ui->webEngineView->load(QUrl("qrc:/help/debuggingprograms.html")); |
| 104 | } |
| 105 | else if (!isHelpSubCat && row == eTRAP) { // Writing Trap Handlers |
| 106 | ui->helpSplitter->widget(1)->hide(); |
| 107 | ui->webEngineView->show(); |
| 108 | ui->webEngineView->load(QUrl("qrc:/help/writingtraphandlers.html")); |
| 109 | } |
| 110 | else if ((!isHelpSubCat && row == eREFERENCE)) { |
| 111 | ui->helpSplitter->widget(1)->hide(); |
| 112 | ui->webEngineView->show(); |
| 113 | ui->webEngineView->load(QUrl("qrc:/help/pep8reference.html")); |
| 114 | } |
| 115 | else if ((!isHelpSubCat && row == eEXAMPLES) || parentRow == eEXAMPLES) { |
| 116 | if (!isHelpSubCat) { |
| 117 | ui->helpSplitter->widget(1)->hide(); |
| 118 | ui->webEngineView->show(); |
| 119 | ui->webEngineView->load(QUrl("qrc:/help/examples.html")); |
| 120 | } |
| 121 | else { |
| 122 | ui->helpSplitter->widget(0)->hide(); |
| 123 | ui->helpSplitter->widget(1)->show(); |
| 124 | ui->copyToSourceButton->setText("Copy to Source"); |
| 125 | if (row == eFIG432) { |
| 126 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0432.peph")); |
| 127 | ui->rightPepTextEdit->setText(Pep::resToString(":/help/figures/fig0432.pepb")); |
| 128 | ui->figureLabel->setText("<b>Figure 4.32</b><code> </code> A machine language program to output the characters <code>Hi</code>."); |
| 129 | ui->rightPepTextEdit->show(); |
| 130 | ui->rightCppTextEdit->hide(); |
| 131 | ui->copyToSourceButton->setText("Copy to Object"); |
| 132 | |
| 133 | } |
| 134 | else if (row == eFIG434) { |
| 135 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0434.peph")); |
| 136 | ui->rightPepTextEdit->setText(Pep::resToString(":/help/figures/fig0434.pepb")); |
| 137 | ui->figureLabel->setText("<b>Figure 4.34</b><code> </code> A machine language program to input two characters and output them in reverse order."); |
| 138 | ui->rightPepTextEdit->show(); |
| 139 | ui->rightCppTextEdit->hide(); |
| 140 | ui->copyToSourceButton->setText("Copy to Object"); |
| 141 | } |
| 142 | else if (row == eFIG435) { |
| 143 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0435.peph")); |
| 144 | ui->rightPepTextEdit->setText(Pep::resToString(":/help/figures/fig0435.pepb")); |
| 145 | ui->figureLabel->setText("<b>Figure 4.35</b><code> </code> A machine language program to add 5 and 3 and output the single-character result."); |
| 146 | ui->rightPepTextEdit->show(); |
| 147 | ui->rightCppTextEdit->hide(); |
| 148 | ui->copyToSourceButton->setText("Copy to Object"); |
| 149 | } |
| 150 | else if (row == eFIG436) { |
| 151 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0436.peph")); |
| 152 | ui->rightPepTextEdit->setText(Pep::resToString(":/help/figures/fig0436.pepb")); |
| 153 | ui->figureLabel->setText("<b>Figure 4.36</b><code> </code> A machine language program that modifies itself. The add accumulator instruction changes to a subtract instruction."); |
| 154 | ui->rightPepTextEdit->show(); |
| 155 | ui->rightCppTextEdit->hide(); |
| 156 | ui->copyToSourceButton->setText("Copy to Object"); |
| 157 | } |
| 158 | else if (row == eFIG503) { |
| 159 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0503.pep")); |
| 160 | ui->rightPepTextEdit->setText(Pep::resToString(":/help/figures/fig0432.peph")); |
| 161 | ui->figureLabel->setText("<b>Figure 5.3</b><code> </code> An assembly-language program to output <code>Hi</code>. It is the assembly-language version of Figure 4.32."); |
| 162 | ui->rightCppTextEdit->hide(); |
| 163 | ui->rightPepTextEdit->show(); |
| 164 | } |
| 165 | else if (row == eFIG506) { |
| 166 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0506.pep")); |
| 167 | ui->rightPepTextEdit->setText(Pep::resToString(":/help/figures/fig0434.peph")); |
| 168 | ui->figureLabel->setText("<b>Figure 5.6</b><code> </code> An assembly language program to input two characters and output them in reverse order. It is the assembly language version of Figure 4.34."); |
| 169 | ui->rightCppTextEdit->hide(); |
| 170 | ui->rightPepTextEdit->show(); |
| 171 | } |
| 172 | else if (row == eFIG507) { |
| 173 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0507.pep")); |
| 174 | ui->rightPepTextEdit->setText(Pep::resToString(":/help/figures/fig0435.peph")); |
| 175 | ui->figureLabel->setText("<b>Figure 5.7</b><code> </code> An assembly language program to add 3 and 5 and output the single-character result. It is the assembly language version of Figure 4.35."); |
| 176 | ui->rightCppTextEdit->hide(); |
| 177 | ui->rightPepTextEdit->show(); |
| 178 | } |
| 179 | else if (row == eFIG510) { |
| 180 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0510.pep")); |
| 181 | ui->figureLabel->setText("<b>Figure 5.10</b><code> </code> A program to output <code>Hi</code> using immediate addressing."); |
| 182 | ui->rightCppTextEdit->hide(); |
| 183 | ui->rightPepTextEdit->hide(); |
| 184 | } |
| 185 | else if (row == eFIG511) { |
| 186 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0511.pep")); |
| 187 | ui->figureLabel->setText("<b>Figure 5.11</b><code> </code> A program to input a decimal value, add 1 to it, and output the sum."); |
| 188 | ui->rightCppTextEdit->hide(); |
| 189 | ui->rightPepTextEdit->hide(); |
| 190 | } |
| 191 | else if (row == eFIG512) { |
| 192 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0512.pep")); |
| 193 | ui->figureLabel->setText("<b>Figure 5.12</b><code> </code> A program identical to that of Figure 5.11 but with the <code>STRO</code> instruction."); |
| 194 | ui->rightCppTextEdit->hide(); |
| 195 | ui->rightPepTextEdit->hide(); |
| 196 | } |
| 197 | else if (row == eFIG513) { |
| 198 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0513.pep")); |
| 199 | ui->figureLabel->setText("<b>Figure 5.13</b><code> </code> A nonsense program to illustrate the interpretation of bit patterns."); |
| 200 | ui->rightCppTextEdit->hide(); |
| 201 | ui->rightPepTextEdit->hide(); |
| 202 | } |
| 203 | else if (row == eFIG514a) { |
| 204 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0514a.pep")); |
| 205 | ui->figureLabel->setText("<b>Figure 5.14a</b><code> </code> Two different source programs that produce the same object program and, therefore, the same output."); |
| 206 | ui->rightCppTextEdit->hide(); |
| 207 | ui->rightPepTextEdit->hide(); |
| 208 | } |
| 209 | else if (row == eFIG514b) { |
| 210 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0514b.pep")); |
| 211 | ui->figureLabel->setText("<b>Figure 5.14b</b><code> </code> Two different source programs that produce the same object program and, therefore, the same output."); |
| 212 | ui->rightCppTextEdit->hide(); |
| 213 | ui->rightPepTextEdit->hide(); |
| 214 | } |
| 215 | else if (row == eFIG515) { |
| 216 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0515.pep")); |
| 217 | ui->rightPepTextEdit->setText(Pep::resToString(":/help/figures/fig0512.pep")); |
| 218 | ui->figureLabel->setText("<b>Figure 5.15</b><code> </code> A program that adds 1 to a decimal value. It is identical to Figure 5.12 except that it uses symbols."); |
| 219 | ui->rightCppTextEdit->hide(); |
| 220 | ui->rightPepTextEdit->show(); |
| 221 | } |
| 222 | else if (row == eFIG516) { |
| 223 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0516.pep")); |
| 224 | ui->figureLabel->setText("<b>Figure 5.16</b><code> </code> A nonsense program that illustrates the underlying von Neumann nature of the machine."); |
| 225 | ui->rightCppTextEdit->hide(); |
| 226 | ui->rightPepTextEdit->hide(); |
| 227 | } |
| 228 | else if (row == eFIG518) { |
| 229 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0518.pep")); |
| 230 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0518.cpp")); |
| 231 | ui->figureLabel->setText("<b>Figure 5.18</b><code> </code> The <code>cout</code> statement."); |
| 232 | ui->rightCppTextEdit->show(); |
| 233 | ui->rightPepTextEdit->hide(); |
| 234 | } |
| 235 | else if (row == eFIG521) { |
| 236 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0521.pep")); |
| 237 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0521.cpp")); |
| 238 | ui->figureLabel->setText("<b>Figure 5.21</b><code> </code> The assignment statement with global variables."); |
| 239 | ui->rightCppTextEdit->show(); |
| 240 | ui->rightPepTextEdit->hide(); |
| 241 | } |
| 242 | else if (row == eFIG526) { |
| 243 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0526.pep")); |
| 244 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0526.cpp")); |
| 245 | ui->figureLabel->setText("<b>Figure 5.26</b><code> </code> C++ constants."); |
| 246 | ui->rightCppTextEdit->show(); |
| 247 | ui->rightPepTextEdit->hide(); |
| 248 | } |
| 249 | else if (row == eFIG601) { |
| 250 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0601.pep")); |
| 251 | ui->figureLabel->setText("<b>Figure 6.1</b><code> </code> Stack-relative addressing."); |
| 252 | ui->rightCppTextEdit->hide(); |
| 253 | ui->rightPepTextEdit->hide(); |
| 254 | } |
| 255 | else if (row == eFIG604) { |
| 256 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0604.pep")); |
| 257 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0604.cpp")); |
| 258 | ui->figureLabel->setText("<b>Figure 6.4</b><code> </code> Local variables."); |
| 259 | ui->rightCppTextEdit->show(); |
| 260 | ui->rightPepTextEdit->hide(); |
| 261 | } |
| 262 | else if (row == eFIG606) { |
| 263 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0606.pep")); |
| 264 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0606.cpp")); |
| 265 | ui->figureLabel->setText("<b>Figure 6.6</b><code> </code> The <code>if</code> statement."); |
| 266 | ui->rightCppTextEdit->show(); |
| 267 | ui->rightPepTextEdit->hide(); |
| 268 | } |
| 269 | else if (row == eFIG608) { |
| 270 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0608.pep")); |
| 271 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0608.cpp")); |
| 272 | ui->figureLabel->setText("<b>Figure 6.8</b><code> </code> The <code>if</code>/<code>else</code> statement."); |
| 273 | ui->rightCppTextEdit->show(); |
| 274 | ui->rightPepTextEdit->hide(); |
| 275 | } |
| 276 | else if (row == eFIG610) { |
| 277 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0610.pep")); |
| 278 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0610.cpp")); |
| 279 | ui->figureLabel->setText("<b>Figure 6.10</b><code> </code> The <code>while</code> statement."); |
| 280 | ui->rightCppTextEdit->show(); |
| 281 | ui->rightPepTextEdit->hide(); |
| 282 | } |
| 283 | else if (row == eFIG612) { |
| 284 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0612.pep")); |
| 285 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0612.cpp")); |
| 286 | ui->figureLabel->setText("<b>Figure 6.12</b><code> </code> The <code>do</code> statement."); |
| 287 | ui->rightCppTextEdit->show(); |
| 288 | ui->rightPepTextEdit->hide(); |
| 289 | } |
| 290 | else if (row == eFIG614) { |
| 291 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0614.pep")); |
| 292 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0614.cpp")); |
| 293 | ui->figureLabel->setText("<b>Figure 6.14</b><code> </code> The <code>for</code> statement."); |
| 294 | ui->rightCppTextEdit->show(); |
| 295 | ui->rightPepTextEdit->hide(); |
| 296 | } |
| 297 | else if (row == eFIG616) { |
| 298 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0616.pep")); |
| 299 | ui->figureLabel->setText("<b>Figure 6.16</b><code> </code> A mystery program."); |
| 300 | ui->rightCppTextEdit->hide(); |
| 301 | ui->rightPepTextEdit->hide(); |
| 302 | } |
| 303 | else if (row == eFIG618) { |
| 304 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0618.pep")); |
| 305 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0618.cpp")); |
| 306 | ui->figureLabel->setText("<b>Figure 6.18</b><code> </code> A procedure call with no parameters."); |
| 307 | ui->rightCppTextEdit->show(); |
| 308 | ui->rightPepTextEdit->hide(); |
| 309 | } |
| 310 | else if (row == eFIG621) { |
| 311 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0621.pep")); |
| 312 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0621.cpp")); |
| 313 | ui->figureLabel->setText("<b>Figure 6.21</b><code> </code> Call-by-value parameters with global variables."); |
| 314 | ui->rightCppTextEdit->show(); |
| 315 | ui->rightPepTextEdit->hide(); |
| 316 | } |
| 317 | else if (row == eFIG623) { |
| 318 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0623.pep")); |
| 319 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0623.cpp")); |
| 320 | ui->figureLabel->setText("<b>Figure 6.23</b><code> </code> Call-by-value parameters with local variables."); |
| 321 | ui->rightCppTextEdit->show(); |
| 322 | ui->rightPepTextEdit->hide(); |
| 323 | } |
| 324 | else if (row == eFIG625) { |
| 325 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0625.pep")); |
| 326 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0625.cpp")); |
| 327 | ui->figureLabel->setText("<b>Figure 6.25</b><code> </code> A recursive nonvoid function."); |
| 328 | ui->rightCppTextEdit->show(); |
| 329 | ui->rightPepTextEdit->hide(); |
| 330 | } |
| 331 | else if (row == eFIG627) { |
| 332 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0627.pep")); |
| 333 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0627.cpp")); |
| 334 | ui->figureLabel->setText("<b>Figure 6.27</b><code> </code> Call-by-reference parameters with global variables."); |
| 335 | ui->rightCppTextEdit->show(); |
| 336 | ui->rightPepTextEdit->hide(); |
| 337 | } |
| 338 | else if (row == eFIG629) { |
| 339 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0629.pep")); |
| 340 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0629.cpp")); |
| 341 | ui->figureLabel->setText("<b>Figure 6.29</b><code> </code> Call-by-reference parameters with local variables."); |
| 342 | ui->rightCppTextEdit->show(); |
| 343 | ui->rightPepTextEdit->hide(); |
| 344 | } |
| 345 | else if (row == eFIG632) { |
| 346 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0632.pep")); |
| 347 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0632.cpp")); |
| 348 | ui->figureLabel->setText("<b>Figure 6.32</b><code> </code> Translation of a boolean type."); |
| 349 | ui->rightCppTextEdit->show(); |
| 350 | ui->rightPepTextEdit->hide(); |
| 351 | } |
| 352 | else if (row == eFIG634) { |
| 353 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0634.pep")); |
| 354 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0634.cpp")); |
| 355 | ui->figureLabel->setText("<b>Figure 6.32</b><code> </code> A global array."); |
| 356 | ui->rightCppTextEdit->show(); |
| 357 | ui->rightPepTextEdit->hide(); |
| 358 | } |
| 359 | else if (row == eFIG636) { |
| 360 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0636.pep")); |
| 361 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0636.cpp")); |
| 362 | ui->figureLabel->setText("<b>Figure 6.36</b><code> </code> A local array."); |
| 363 | ui->rightCppTextEdit->show(); |
| 364 | ui->rightPepTextEdit->hide(); |
| 365 | } |
| 366 | else if (row == eFIG638) { |
| 367 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0638.pep")); |
| 368 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0638.cpp")); |
| 369 | ui->figureLabel->setText("<b>Figure 6.38</b><code> </code> Passing a local array as a parameter."); |
| 370 | ui->rightCppTextEdit->show(); |
| 371 | ui->rightPepTextEdit->hide(); |
| 372 | } |
| 373 | else if (row == eFIG640) { |
| 374 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0640.pep")); |
| 375 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0640.cpp")); |
| 376 | ui->figureLabel->setText("<b>Figure 6.40</b><code> </code> Translation of a <code>switch</code> statement."); |
| 377 | ui->rightCppTextEdit->show(); |
| 378 | ui->rightPepTextEdit->hide(); |
| 379 | } |
| 380 | else if (row == eFIG641) { |
| 381 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0641.pep")); |
| 382 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0641.cpp")); |
| 383 | ui->figureLabel->setText("<b>Figure 6.41</b><code> </code> Translation of global pointers."); |
| 384 | ui->rightCppTextEdit->show(); |
| 385 | ui->rightPepTextEdit->hide(); |
| 386 | } |
| 387 | else if (row == eFIG643) { |
| 388 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0643.pep")); |
| 389 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0643.cpp")); |
| 390 | ui->figureLabel->setText("<b>Figure 6.43</b><code> </code> Translation of local pointers."); |
| 391 | ui->rightCppTextEdit->show(); |
| 392 | ui->rightPepTextEdit->hide(); |
| 393 | } |
| 394 | else if (row == eFIG645) { |
| 395 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0645.pep")); |
| 396 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0645.cpp")); |
| 397 | ui->figureLabel->setText("<b>Figure 6.45</b><code> </code> Translation of a structure."); |
| 398 | ui->rightCppTextEdit->show(); |
| 399 | ui->rightPepTextEdit->hide(); |
| 400 | } |
| 401 | else if (row == eFIG647) { |
| 402 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/fig0647.pep")); |
| 403 | ui->rightCppTextEdit->setText(Pep::resToString(":/help/figures/fig0647.cpp")); |
| 404 | ui->figureLabel->setText("<b>Figure 6.47</b><code> </code> Translation of a linked list."); |
| 405 | ui->rightCppTextEdit->show(); |
| 406 | ui->rightPepTextEdit->hide(); |
| 407 | } |
| 408 | else if (row == eEXER804) { |
| 409 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/exer0804.pep")); |
| 410 | ui->figureLabel->setText("<b>Exercise 8.4</b><code> </code> An excercise for the <code>DECI</code> trap."); |
| 411 | ui->rightCppTextEdit->hide(); |
| 412 | ui->rightPepTextEdit->hide(); |
| 413 | } |
| 414 | else if (row == ePROB829) { |
| 415 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/prob0829.pep")); |
| 416 | ui->figureLabel->setText("<b>Problem 8.29</b><code> </code> A test driver for the <code>STADI</code> instruction."); |
| 417 | ui->rightCppTextEdit->hide(); |
| 418 | ui->rightPepTextEdit->hide(); |
| 419 | } |
| 420 | else if (row == ePROB832) { |
| 421 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/prob0832.pep")); |
| 422 | ui->figureLabel->setText("<b>Problem 8.32</b><code> </code> A test driver for the <code>STACKADD</code> instruction."); |
| 423 | ui->rightCppTextEdit->hide(); |
| 424 | ui->rightPepTextEdit->hide(); |
| 425 | } |
| 426 | |
| 427 | } |
| 428 | } |
| 429 | else if (!isHelpSubCat && row == eOS) { // Pep/8 Operating System |
| 430 | ui->copyToSourceButton->setText("Copy to Source"); |
| 431 | ui->helpSplitter->widget(0)->hide(); |
| 432 | ui->helpSplitter->widget(1)->show(); |
| 433 | ui->leftTextEdit->setText(Pep::resToString(":/help/figures/pep8os.pep")); |
| 434 | ui->rightCppTextEdit->hide(); |
| 435 | ui->rightPepTextEdit->hide(); |
| 436 | ui->figureLabel->setText("<b>Figures 8.2, 8.3, 8.6, 8.8, 8.10, 8.11</b><code> </code> The Pep/8 operating system."); |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | // Public functions called by main window help menu items: |
| 441 | void HelpDialog::onFontChanged(QFont font) |
| 442 | { |
| 443 | ui->leftTextEdit->setFont(font); |
| 444 | ui->rightCppTextEdit->setFont(font); |
| 445 | ui->rightPepTextEdit->setFont(font); |
| 446 | } |
| 447 | |
| 448 | void HelpDialog::machineLanguageClicked() |
| 449 | { |
| 450 | selectItem("Machine Language"); |
| 451 | } |
| 452 | |
| 453 | void HelpDialog::assemblyLanguageClicked() |
| 454 | { |
| 455 | selectItem("Assembly Language"); |
| 456 | } |
| 457 | |
| 458 | void HelpDialog::debuggingProgramsClicked() |
| 459 | { |
| 460 | selectItem("Debugging Programs"); |
| 461 | } |
| 462 | |
| 463 | void HelpDialog::writingTrapHandlersClicked() |
| 464 | { |
| 465 | selectItem("Writing Trap Handlers"); |
| 466 | } |
| 467 | |
| 468 | void HelpDialog::pep8ReferenceClicked() |
| 469 | { |
| 470 | selectItem("Pep/8 Reference"); |
| 471 | } |
| 472 | |
| 473 | void HelpDialog::examplesClicked() |
| 474 | { |
| 475 | selectItem("Examples"); |
| 476 | } |
| 477 | |
| 478 | void HelpDialog::operatingSystemClicked() |
| 479 | { |
| 480 | selectItem("Pep/8 Operating System"); |
| 481 | } |
| 482 | |
| 483 | // Helper Functions |
| 484 | QString HelpDialog::getCode(Enu::EPane &destPane, Enu::EPane &inputDest, QString &input) |
| 485 | { |
| 486 | bool isHelpSubCat = ui->treeWidget->currentIndex().parent().isValid(); |
| 487 | int row = ui->treeWidget->currentIndex().row(); |
| 488 | if (!isHelpSubCat && row == eOS) { // Pep/8 Operating System |
| 489 | destPane = Enu::ESource; |
| 490 | return ui->leftTextEdit->toPlainText(); |
| 491 | } |
| 492 | if (row == eFIG432) { |
| 493 | destPane = Enu::EObject; |
| 494 | return Pep::resToString(":/help/figures/fig0432.pepo"); |
| 495 | } |
| 496 | else if (row == eFIG434) { |
| 497 | destPane = Enu::EObject; |
| 498 | input = "up"; |
| 499 | return Pep::resToString(":/help/figures/fig0434.pepo"); |
| 500 | } |
| 501 | else if (row == eFIG435) { |
| 502 | destPane = Enu::EObject; |
| 503 | return Pep::resToString(":/help/figures/fig0435.pepo"); |
| 504 | } |
| 505 | else if (row == eFIG436) { |
| 506 | destPane = Enu::EObject; |
| 507 | return Pep::resToString(":/help/figures/fig0436.pepo"); |
| 508 | } |
| 509 | else if (row == eFIG506) { |
| 510 | input = "up"; |
| 511 | } |
| 512 | else if (row == eFIG511) { |
| 513 | input = "-479"; |
| 514 | } |
| 515 | else if (row == eFIG512) { |
| 516 | input = "-479"; |
| 517 | } |
| 518 | else if (row == eFIG515) { |
| 519 | input = "-479"; |
| 520 | } |
| 521 | else if (row == eFIG521) { |
| 522 | input = "M 419"; |
| 523 | } |
| 524 | else if (row == eFIG526 || row == eFIG604) { |
| 525 | input = "68 84"; |
| 526 | } |
| 527 | else if (row == eFIG606) { |
| 528 | input = "-25"; |
| 529 | } |
| 530 | else if (row == eFIG608) { |
| 531 | input = "75"; |
| 532 | } |
| 533 | else if (row == eFIG610) { |
| 534 | input = "happy*"; |
| 535 | } |
| 536 | else if (row == eFIG616) { |
| 537 | input = "3 -15 25"; |
| 538 | } |
| 539 | else if (row == eFIG621 || row == eFIG623) { |
| 540 | input = "12 3 13 17 34 27 23 25 29 16 10 0 2"; |
| 541 | } |
| 542 | else if (row == eFIG632) { |
| 543 | input = "25"; |
| 544 | } |
| 545 | else if (row == eFIG634) { |
| 546 | input = "60 70 80 90"; |
| 547 | } |
| 548 | else if (row == eFIG636) { |
| 549 | input = "2 26 -3 9"; |
| 550 | } |
| 551 | else if (row == eFIG638) { |
| 552 | input = "5 40 50 60 70 80"; |
| 553 | } |
| 554 | else if (row == eFIG645) { |
| 555 | input = "bj 32 m"; |
| 556 | } |
| 557 | else if (row == eFIG647) { |
| 558 | input = "10 20 30 40 -9999"; |
| 559 | } |
| 560 | else if (row == eFIG627 || row == eFIG629 || row == eFIG640) { |
| 561 | inputDest = Enu::ETerminal; |
| 562 | } |
| 563 | else if (row == eEXER804) { |
| 564 | input = "37"; |
| 565 | } |
| 566 | destPane = Enu::ESource; |
| 567 | return ui->leftTextEdit->toPlainText(); |
| 568 | } |
| 569 | |
| 570 | bool HelpDialog::hasFocus() |
| 571 | { |
| 572 | return ui->leftTextEdit->hasFocus() || ui->rightCppTextEdit->hasFocus() || ui->webEngineView->hasFocus(); |
| 573 | } |
| 574 | |
| 575 | void HelpDialog::copy() |
| 576 | { |
| 577 | if (ui->leftTextEdit->hasFocus()) { |
| 578 | ui->leftTextEdit->copy(); |
| 579 | } else if (ui->rightCppTextEdit->hasFocus()) { |
| 580 | ui->rightCppTextEdit->copy(); |
| 581 | } else if (ui->webEngineView->hasFocus()) { |
| 582 | QApplication::clipboard()->setText(ui->webEngineView->selectedText()); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | void HelpDialog::setCopyButtonDisabled(bool b) |
| 587 | { |
| 588 | ui->copyToSourceButton->setDisabled(b); |
| 589 | } |