Debian Codegraph @

tab.cpp

raw symbols SCIP
1 /****************************************************************************
2 ** SASM - simple IDE for assembler development
3 ** Copyright (C) 2013 Dmitriy Manushin
4 ** Contact: site: http://dman95.github.io/SASM/
5 ** e-mail: [email protected]
6 **
7 ** This file is part of SASM.
8 **
9 ** SASM is free software: you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation, either version 3 of the License, or
12 ** (at your option) any later version.
13 **
14 ** SASM is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with SASM. If not, see <http://www.gnu.org/licenses/>.
21 **
22 ** Этот файл — часть SASM.
23 **
24 ** SASM - свободная программа: вы можете перераспространять ее и/или
25 ** изменять ее на условиях Стандартной общественной лицензии GNU в том виде,
26 ** в каком она была опубликована Фондом свободного программного обеспечения;
27 ** либо версии 3 лицензии, либо (по вашему выбору) любой более поздней
28 ** версии.
29 **
30 ** SASM распространяется в надежде, что она будет полезной,
31 ** но БЕЗО ВСЯКИХ ГАРАНТИЙ; даже без неявной гарантии ТОВАРНОГО ВИДА
32 ** или ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННЫХ ЦЕЛЕЙ. Подробнее см. в Стандартной
33 ** общественной лицензии GNU.
34 **
35 ** Вы должны были получить копию Стандартной общественной лицензии GNU
36 ** вместе с этой программой. Если это не так, см.
37 ** <http://www.gnu.org/licenses/>.)
38 **
39 ****************************************************************************/
40
41 #include "tab.h"
42
43 /**
44 * @file tab.cpp
45 * Implementation of the Tab class.
46 */
47
48 Tab::Tab(QWidget *parent) :
49 QMainWindow(parent),
50 currentFilePath("")
51 {
52 //! Setting code field
53 code = new CodeEditor;
54 setCentralWidget(code);
55
56 //! Setting input and output fields
57 input = new RuQTextEdit;
58 output = new RuQTextEdit;
59 output->setReadOnly(true);
60 inputLayout = new QVBoxLayout;
61 outputLayout = new QVBoxLayout;
62 inputLayout->addWidget(input);
63 outputLayout->addWidget(output);
64
65 setDockOptions(QMainWindow::AllowNestedDocks | QMainWindow::AnimatedDocks);
66
67 QDockWidget *inputDock = new QDockWidget(tr("Input"), this);
68 inputDock->setAllowedAreas(Qt::AllDockWidgetAreas);
69 inputWidget = new QWidget(inputDock);
70 inputWidget->setLayout(inputLayout);
71 inputDock->setWidget(inputWidget);
72 inputDock->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable);
73 addDockWidget(Qt::RightDockWidgetArea, inputDock);
74 inputDock->setObjectName("inputDock");
75
76 QDockWidget *outputDock = new QDockWidget(tr("Output"), this);
77 outputDock->setAllowedAreas(Qt::AllDockWidgetAreas);
78 outputWidget = new QWidget(outputDock);
79 outputWidget->setLayout(outputLayout);
80 outputDock->setWidget(outputWidget);
81 outputDock->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable);
82 addDockWidget(Qt::RightDockWidgetArea, outputDock);
83 outputDock->setObjectName("outputDock");
84
85 //! Setting io and code fonts
86 setFonts();
87
88 //! Restore state
89 QSettings settings("SASM Project", "SASM");
90 restoreGeometry(settings.value("tabgeometry").toByteArray());
91 restoreState(settings.value("tabwindowstate").toByteArray());
92 }
93
94 /*! \brief
95 *
96 *
97 */
98 void Tab::setFonts()
99 {
100 QSettings settings("SASM Project", "SASM");
101
102 QFont codeFont;
103 codeFont.setPointSize(settings.value("fontsize", 12).toInt());
104 codeFont.setFamily(settings.value("fontfamily", QString("Courier")).value<QString>());
105 codeFont.setStyleHint(QFont::Monospace);
106 code->setFont(codeFont);
107 code->repaintLineNumberArea();
108
109 QFont logFont;
110 logFont.setPointSize(settings.value("fontsize", 12).toInt());
111 input->setFont(logFont);
112 output->setFont(logFont);
113 }
114
115
116
117
118 /*! \brief
119 *
120 *
121 */
122 QTextDocument * Tab::getCodeDocument()
123 {
124 return code->document();
125 }
126
127 /*! \brief
128 *
129 *
130 */
131 QString Tab::getCurrentFilePath()
132 {
133 return currentFilePath;
134 }
135
136 /*! \brief
137 *
138 *
139 */
140 void Tab::saveCodeToFile(const QString &filePath, Assembler *assembler, bool changeCodeModifiedFlag, bool debugMode)
141 {
142 QFile outfile;
143 outfile.setFileName(filePath);
144 outfile.open(QIODevice::WriteOnly | QIODevice::Text);
145 QTextStream out(&outfile);
146 out.setCodec("UTF-8");
147 if (debugMode) {
148 assembler->putDebugString(code);
149 }
150 out << code->toPlainText();
151 if (changeCodeModifiedFlag) {
152 currentFilePath = filePath;
153 code->document()->setModified(false);
154 }
155 outfile.close();
156 }
157
158 /*! \brief
159 *
160 *
161 */
162 void Tab::loadCodeFromFile(const QString &filePath)
163 {
164 QFile file;
165 file.setFileName(filePath);
166 file.open(QIODevice::ReadOnly);
167 QTextStream text(&file);
168 text.setCodec("UTF-8");
169 QString source = text.readAll();
170 code->setPlainText(source);
171 currentFilePath = filePath;
172 code->document()->setModified(false);
173 file.close();
174 }
175
176 /*! \brief
177 *
178 *
179 */
180 void Tab::saveInputToFile(const QString &filePath)
181 {
182 QFile outfile;
183 outfile.setFileName(filePath);
184 outfile.open(QIODevice::WriteOnly | QIODevice::Text);
185 QTextStream out(&outfile);
186 out << input->toPlainText();
187 outfile.close();
188 }
189
190 /*! \brief
191 *
192 *
193 */
194 void Tab::loadOutputFromFile(const QString &filePath)
195 {
196 QFile outputFile;
197 outputFile.setFileName(filePath);
198 outputFile.open(QIODevice::ReadOnly);
199 QTextStream programOut(&outputFile);
200 QString out = programOut.readAll();
201 output->setPlainText(out);
202 outputFile.close();
203 }
204
205 /*! \brief
206 *
207 *
208 */
209 void Tab::appendOutput(QString msg)
210 {
211 msg = output->toPlainText().right(2000) + msg.right(2000);
212 msg = msg.right(2000);
213 output->setText(msg);
214 //! Scroll
215 QTextCursor cursor = output->textCursor();
216 cursor.movePosition(QTextCursor::End);
217 output->setTextCursor(cursor);
218 }
219
220 /*! \brief
221 *
222 *
223 */
224 void Tab::clearOutput()
225 {
226 output->clear();
227 }
228 /*! \brief Destructor for the Tab objects.
229 *
230 *
231 */
232 Tab::~Tab()
233 {
234 delete input;
235 delete output;
236
237 delete inputLayout;
238 delete outputLayout;
239
240 delete code;
241
242 delete inputWidget;
243 delete outputWidget;
244 }