| 1 | /* |
| 2 | * File: Regs32.cpp |
| 3 | * |
| 4 | * Author: Jacob Dekel |
| 5 | * Created on: Aug 7, 2009 |
| 6 | * |
| 7 | * Copyright (c) 2009-2013 Jacob Dekel |
| 8 | * $Id$ |
| 9 | * |
| 10 | * This program is free software: you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation, either version 3 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include "Regs32.h" |
| 26 | #include "Preferences.h" |
| 27 | #include "MainWindow.h" |
| 28 | |
| 29 | #include <iostream> |
| 30 | |
| 31 | std::string Regs32::gCommand = "]GREGS="; |
| 32 | std::string Regs32::cCommand = "]CREGS="; |
| 33 | std::string Regs32::fCommand = "]FREGS="; |
| 34 | std::string Regs32::aCommand = "]AREGS="; |
| 35 | |
| 36 | Regs32::Regs32(QWidget * parent, std::string command) : |
| 37 | QWidget(parent), |
| 38 | mParent(parent), |
| 39 | mLine1(this), |
| 40 | mLine2(this), |
| 41 | mLine3(this), |
| 42 | mLine4(this) |
| 43 | { |
| 44 | //QFont font("monospace", 9); |
| 45 | setFont(); |
| 46 | |
| 47 | mCommand = command; |
| 48 | } |
| 49 | |
| 50 | Regs32::~Regs32() |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | void Regs32::setActive(bool active) |
| 55 | { |
| 56 | mLine1.setVisible(active); |
| 57 | mLine2.setVisible(active); |
| 58 | mLine3.setVisible(active); |
| 59 | mLine4.setVisible(active); |
| 60 | std::string command = mCommand + (active ? '1' : '0'); |
| 61 | MainWindow * mainWindow = dynamic_cast<MainWindow *>(mParent); |
| 62 | mainWindow->issueCommand(command); |
| 63 | } |
| 64 | |
| 65 | void Regs32::setFont() |
| 66 | { |
| 67 | Preferences& pref = Preferences::getInstance(); |
| 68 | int fontSize = pref.fontSize(Preferences::RegsFontObject); |
| 69 | QFont font(pref.fontName(Preferences::RegsFontObject).c_str(), |
| 70 | fontSize, |
| 71 | (pref.fontIsBold(Preferences::RegsFontObject) ? QFont::Bold : QFont::Normal), |
| 72 | pref.fontIsItalic(Preferences::RegsFontObject)); |
| 73 | |
| 74 | font.setStyleHint(QFont::Courier); |
| 75 | mLine1.setFont(font); |
| 76 | mLine2.setFont(font); |
| 77 | mLine3.setFont(font); |
| 78 | mLine4.setFont(font); |
| 79 | mLine1.setGeometry(2,fontSize+2,fontSize*35,fontSize+2); |
| 80 | mLine2.setGeometry(2,2*(fontSize+2),fontSize*35,fontSize+2); |
| 81 | mLine3.setGeometry(2,3*(fontSize+2),fontSize*35,fontSize+2); |
| 82 | mLine4.setGeometry(2,4*(fontSize+2),fontSize*35,fontSize+2); |
| 83 | |
| 84 | } |
| 85 | |
| 86 | bool Regs32::notify(const QByteArray& statusLine) |
| 87 | { |
| 88 | if (statusLine.length() < 2) |
| 89 | { |
| 90 | setFont(); |
| 91 | return false; |
| 92 | } |
| 93 | if (statusLine[2] == '0') |
| 94 | Regs32::mLine1.setText(statusLine); |
| 95 | else if (statusLine[2] == '4') |
| 96 | Regs32::mLine2.setText(statusLine); |
| 97 | else if (statusLine[2] == '8') |
| 98 | Regs32::mLine3.setText(statusLine); |
| 99 | else if (statusLine[2] == 'C') |
| 100 | Regs32::mLine4.setText(statusLine); |
| 101 | else return false; |
| 102 | |
| 103 | return true; |
| 104 | } |