Debian Codegraph @

HercStudio/Psw.cpp

raw symbols SCIP
1 /*
2 * File: Psw.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
26 #include "Psw.h"
27 #include "HerculesStudio.h"
28 #include "Preferences.h"
29
30 #include <QStatusBar>
31 #include <iostream>
32
33 Psw::Psw( QStatusBar * statusBar)
34 : mHasStatusBar(false), mVisible(false), mCpu(NULL)
35 {
36 mStatusBar = statusBar;
37 mMode = Preferences::getInstance().pswMode();
38 mFontCourier = new QFont("Mono",10);
39
40 setFont();
41 setStatusBar();
42 mActive = false;
43 setStatusVisible(false,false);
44 mLine.reserve(100);
45 mLine = QString(100,' ');
46 setGeometry(0,0,1200,12);
47 }
48
49 Psw::~Psw()
50 {
51 delete mFontCourier;
52 }
53
54 bool Psw::notify(const QByteArray& statusLine)
55 {
56 if (!mActive || !mVisible)
57 return false;
58 if (statusLine.startsWith("SYS="))
59 {
60 if (statusLine[4] == '1')
61 mSys->setText("SYS");
62 else
63 mSys->setText(" ");
64 return true;
65 }
66 //STATUS=CPU0000 PSW=00000000 00000000 0000000000000000 M.W..... instcount=0
67 if (!statusLine.startsWith("STATUS=") || statusLine.length() < 63)
68 return false;
69 if (mMode == Psw::Docked)
70 {
71 mLine.replace(0,46, statusLine.mid(7,46));
72 mLine.replace(48,statusLine.length()-56, statusLine.mid(63,statusLine.length()-56));
73 setText(mLine);
74 }
75 else
76 {
77 mCpu->setText(statusLine.mid(7,46));
78 mInstCount->setText(statusLine.mid(62));
79 if (statusLine[54] == 'M')
80 mMan->setText("MAN");
81 else
82 mMan->setText(" ");
83 if (statusLine[56] == 'W')
84 mWait->setText("WAIT");
85 else
86 mWait->setText(" ");
87 }
88 return true;
89 }
90
91 void Psw::setFont()
92 {
93 Preferences& pref = Preferences::getInstance();
94 QFont font(pref.fontName(Preferences::PswFontObject).c_str(),
95 pref.fontSize(Preferences::PswFontObject),
96 (pref.fontIsBold(Preferences::PswFontObject) ? QFont::Bold : QFont::Normal),
97 pref.fontIsItalic(Preferences::PswFontObject));
98
99 font.setStyleHint(QFont::Courier);
100 QLabel::setFont(font);
101 }
102
103 void Psw::setMode(Psw::PswMode mode)
104 {
105 mMode = mode;
106 setStatusBar();
107 setStatusVisible(mVisible, Preferences::getInstance().theme() == Preferences::Modern);
108 }
109
110 void Psw::setStatusBar()
111 {
112 if (!mHasStatusBar)
113 {
114 mHasStatusBar = true;
115
116 mCpu = new QLabel(" ", mStatusBar);
117 mCpu->setMinimumWidth(400);
118 mCpu->setFont(*mFontCourier);
119 mCpu->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
120 mStatusBar->addWidget(mCpu);
121
122 mSys = new QLabel(" ", mStatusBar);
123 mSys->setFont(*mFontCourier);
124 mSys->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
125 mStatusBar->addWidget(mSys);
126
127 mWait = new QLabel(" ", mStatusBar);
128 mWait->setFont(*mFontCourier);
129 mWait->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
130 mStatusBar->addWidget(mWait);
131
132 mMan = new QLabel(" ", mStatusBar);
133 mMan->setFont(*mFontCourier);
134 mMan->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
135 mStatusBar->addWidget(mMan);
136
137 mInstCount = new QLabel(" ", mStatusBar);
138 mInstCount->setFont(*mFontCourier);
139 mInstCount->setFrameStyle(QFrame::StyledPanel | QFrame::NoFrame);
140 mStatusBar->addWidget(mInstCount);
141 }
142 }
143
144 void Psw::setStatusVisible(bool visible, bool modern)
145 {
146 mCpu->setVisible((mMode != Docked) && visible);
147 mSys->setVisible(visible && modern);
148 mWait->setVisible(visible && modern);
149 mMan->setVisible(visible && modern);
150 mInstCount->setVisible((mMode != Docked) && visible);
151 mVisible = visible;
152 }
153
154 void Psw::setVisible(bool visible, bool modern)
155 {
156 QLabel::setVisible(visible);
157 setStatusVisible(visible, modern);
158 }
159
160 bool Psw::visible()
161 {
162 return mVisible;
163 }
164
165 void Psw::setDormant()
166 {
167 mActive = false;
168 }
169
170 void Psw::standby()
171 {
172 mActive = true;
173 }