| 1 | /* |
| 2 | * File: MainPanelModern.cpp |
| 3 | * |
| 4 | * Author: Jacob Dekel |
| 5 | * Created on: Oct 28, 2010 |
| 6 | * |
| 7 | * Copyright (c) 2009-2013 Jacob Dekel |
| 8 | * $Id: MainPanel.cpp 67 2010-09-13 14:06:31Z dekeljacob $ |
| 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 "HerculesStudio.h" |
| 26 | #include "MainPanelModern.h" |
| 27 | #include "Environment.h" |
| 28 | #include "PanelButton.h" |
| 29 | #include "Preferences.h" |
| 30 | #include "MipsLed.h" |
| 31 | #include "MipsGauge.h" |
| 32 | #include "ConfigurationEditor.h" |
| 33 | #include "Preferences.h" |
| 34 | |
| 35 | #include <sstream> |
| 36 | |
| 37 | |
| 38 | MainPanelModern::MainPanelModern(QWidget *parent) |
| 39 | : MainPanel(parent) |
| 40 | { |
| 41 | setupUi(parent); |
| 42 | mLcd0 = new QLCDNumber(1,this); mLcd0->setVisible(false); |
| 43 | mLcd1 = new QLCDNumber(1,this); mLcd1->setVisible(false); |
| 44 | mLcd2 = new QLCDNumber(1,this); mLcd2->setVisible(false); |
| 45 | mLcd3 = new QLCDNumber(1,this); mLcd3->setVisible(false); |
| 46 | mStopped=true; |
| 47 | doConnect(); |
| 48 | } |
| 49 | |
| 50 | MainPanelModern::~MainPanelModern() |
| 51 | { |
| 52 | delete mMips; |
| 53 | delete mYellowLow; |
| 54 | delete mYellowHigh; |
| 55 | } |
| 56 | |
| 57 | void MainPanelModern::setupUi(QWidget *) |
| 58 | { |
| 59 | const QColor black(70,70,70); |
| 60 | const QColor white(255,255,20); |
| 61 | QBrush blackBrush(black); |
| 62 | QPalette blackPalette(white, black); |
| 63 | this->setPalette(blackPalette); |
| 64 | this->setAutoFillBackground(true); |
| 65 | |
| 66 | QString iconsPath = Environment::getIconsPath().c_str() ; |
| 67 | hOutDebug(3,"icons path:'" << iconsPath.toStdString() << "'"); |
| 68 | |
| 69 | setButton(mPowerOnButton, QString("Power\nOn"), QIcon(iconsPath + "/modern/Play-icon.png")); |
| 70 | setButton(mPowerOffButton, QString("Power\nOff"), QIcon(iconsPath + "/modern/Stop-icon.png")); |
| 71 | setButton(mStopButton, QString("Stop"), QIcon(iconsPath + "/modern/Pause.png")); |
| 72 | setButton(mInterruptButton, QString("Interrupt"), QIcon(iconsPath + "/modern/interrupt.png")); |
| 73 | setButton(mLoadButton, QString("IPL\n(Boot)"), QIcon(iconsPath + "/modern/load.png")); |
| 74 | |
| 75 | mRestartButton = NULL; |
| 76 | mStoreButton = NULL; |
| 77 | mStartButton = NULL; |
| 78 | |
| 79 | mPowerOnButton->setToolTip("Power On"); |
| 80 | mPowerOffButton->setToolTip("Power Off"); |
| 81 | mInterruptButton->setToolTip("Interrupt"); |
| 82 | mLoadButton->setToolTip("Load (IPL)"); |
| 83 | mStopButton->setToolTip("Stop all CPUs"); |
| 84 | |
| 85 | QFont font; |
| 86 | font.setPointSize(6); |
| 87 | |
| 88 | mPSW = new QLabel(this); |
| 89 | QFont pswFont("Mono", 10); |
| 90 | mPSW->setFont(pswFont); |
| 91 | |
| 92 | if (Preferences::getInstance().mipsAsGauge()) |
| 93 | mMips = new MipsGauge(this); |
| 94 | else |
| 95 | mMips = new MipsLed(this); |
| 96 | mMips->setActive(false); |
| 97 | } |
| 98 | |
| 99 | void MainPanelModern::setButton(QToolButton*& button, QString text, QIcon icon) |
| 100 | { |
| 101 | button = new QToolButton(this); |
| 102 | button->resize(60,70); |
| 103 | button->setText(text); |
| 104 | button->setIcon(icon); |
| 105 | button->setStyleSheet("QToolButton {background: rgb(50,50,50); color: white; }"); |
| 106 | button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); |
| 107 | } |
| 108 | |
| 109 | void MainPanelModern::resizeEvent(QResizeEvent * ) |
| 110 | { |
| 111 | int width = this->size().rwidth(); |
| 112 | mPowerOnButton->move(10,20); |
| 113 | mPowerOffButton->move(70,20); |
| 114 | mStopButton->move(130,20); |
| 115 | mInterruptButton->move(190,20); |
| 116 | mLoadButton->move(250,20); |
| 117 | mMips->move(320,20); |
| 118 | |
| 119 | mPSW->setGeometry(width-550,110,48*12,12); |
| 120 | } |
| 121 | |
| 122 | void MainPanelModern::setDormant() |
| 123 | { |
| 124 | if (!mStopButton->text().contains("Stop", Qt::CaseSensitive)) |
| 125 | { |
| 126 | stopClickedSlot(); |
| 127 | } |
| 128 | |
| 129 | mMips->setActive(false); |
| 130 | } |
| 131 | |
| 132 | void MainPanelModern::standby() |
| 133 | { |
| 134 | mMips->setActive(true); |
| 135 | |
| 136 | const QColor black(50,50,50); |
| 137 | const QColor white(255,255,255); |
| 138 | QBrush blackBrush(black); |
| 139 | QBrush whiteBrush(black); |
| 140 | QPalette blackPalette(white, black); |
| 141 | QPalette whitePalette(white, white); |
| 142 | this->setPalette(whitePalette); |
| 143 | this->setAutoFillBackground(true); |
| 144 | this->repaint(); |
| 145 | this->setPalette(blackPalette); |
| 146 | } |
| 147 | |
| 148 | bool MainPanelModern::notify(const QByteArray& statusLine) |
| 149 | { |
| 150 | bool ret = true; |
| 151 | if (statusLine.startsWith("MIPS=")) |
| 152 | { |
| 153 | double d = atof(statusLine.data()+5); |
| 154 | if (d > mMipsHWM) |
| 155 | { |
| 156 | mMipsHWM = d; |
| 157 | std::stringstream ss; |
| 158 | ss << "High Water Mark:" << d; |
| 159 | mMips->setToolTip(ss.str().c_str()); |
| 160 | } |
| 161 | mMips->display(d); |
| 162 | } |
| 163 | //3.07 :STATUS=CPU0000 PSW=00000000 00000000 0000000000000000 M....... instcount=0 |
| 164 | else ret = false; |
| 165 | |
| 166 | return ret; |
| 167 | } |
| 168 | |
| 169 | void MainPanelModern::switchMips() |
| 170 | { |
| 171 | bool updated = false; |
| 172 | bool visible = mMips->isVisible(); |
| 173 | if (Preferences::getInstance().mipsAsGauge()) |
| 174 | { |
| 175 | MipsLed * oldMips = dynamic_cast<MipsLed *>(mMips); |
| 176 | if (oldMips != NULL) |
| 177 | { |
| 178 | Mips * gauge = new MipsGauge(this); |
| 179 | mMips = gauge; |
| 180 | mMips->setToolTip(oldMips->toolTip()); |
| 181 | oldMips->deleteLater(); |
| 182 | updated = true; |
| 183 | } |
| 184 | } |
| 185 | else |
| 186 | { |
| 187 | MipsGauge * oldMips = dynamic_cast<MipsGauge *>(mMips); |
| 188 | if (oldMips != NULL) |
| 189 | { |
| 190 | Mips * lcd = new MipsLed(this); |
| 191 | mMips = lcd; |
| 192 | mMips->setToolTip(oldMips->toolTip()); |
| 193 | oldMips->deleteLater(); |
| 194 | updated = true; |
| 195 | } |
| 196 | } |
| 197 | if (updated) |
| 198 | { |
| 199 | mMips->setActive(visible); |
| 200 | int width = this->size().rwidth(); |
| 201 | mMips->move(width-680,20); |
| 202 | } |
| 203 | |
| 204 | } |
| 205 | |
| 206 | QSize MainPanelModern::sizeHint() const |
| 207 | { |
| 208 | return QSize(100, 100); |
| 209 | } |
| 210 | |
| 211 | void MainPanelModern::stopClickedSlot() |
| 212 | { |
| 213 | if (!mMips->isVisible()) // actually: is hercules running |
| 214 | return; |
| 215 | if (mStopButton->text().contains("Stop", Qt::CaseSensitive)) |
| 216 | { |
| 217 | delete mStopButton; |
| 218 | setButton(mStopButton, QString("Resume"), QIcon(QString(Environment::getIconsPath().c_str()) + "/modern/Resume.png")); |
| 219 | mStopped=true; |
| 220 | } |
| 221 | else |
| 222 | { |
| 223 | delete mStopButton; |
| 224 | setButton(mStopButton, QString("Stop"), QIcon(QString(Environment::getIconsPath().c_str()) + "/modern/Pause.png")); |
| 225 | mStopped=false; |
| 226 | } |
| 227 | resizeEvent(NULL); |
| 228 | connect(stopButton(), SIGNAL(clicked()), this , SLOT(stopClickedSlot())); |
| 229 | mStopButton->setVisible(true); |
| 230 | emit stopClicked(); |
| 231 | } |
| 232 | |
| 233 | template<class T> void MainPanelModern::animateOne(int x, int y, T* button, int step) |
| 234 | { |
| 235 | for (int i = this->width(); i>=x; i-=step) |
| 236 | { |
| 237 | button->move(i,y); |
| 238 | this->repaint(); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | void MainPanelModern::animate() |
| 243 | { |
| 244 | int width = this->width(); |
| 245 | mPowerOnButton->move(width,20); |
| 246 | mPowerOffButton->move(width,20); |
| 247 | mStopButton->move(width,20); |
| 248 | mInterruptButton->move(width,20); |
| 249 | mLoadButton->move(width,20); |
| 250 | mMips->move(width,20); |
| 251 | |
| 252 | animateOne(10,20,mPowerOnButton, 5); |
| 253 | animateOne(70,20,mPowerOffButton, 5); |
| 254 | animateOne(130,20,mStopButton, 10); |
| 255 | animateOne(190,20,mInterruptButton, 10); |
| 256 | animateOne(250,20,mLoadButton, 15); |
| 257 | animateOne(320,20,mMips,5); |
| 258 | } |