/
mainwindow.hpp
208 lines (174 loc) · 5.78 KB
/
mainwindow.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
* Copyright (C) 2019-2020 Ashar Khan <ashar786khan@gmail.com>
*
* This file is part of CPEditor.
*
* CPEditor is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* I will not be responsible if CPEditor behaves in unexpected way and
* causes your ratings to go down and or loose any important contest.
*
* Believe Software is "Software" and it isn't immune to bugs.
*
*/
#ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP
#include <CompanionServer.hpp>
#include <Compiler.hpp>
#include <Formatter.hpp>
#include <IO.hpp>
#include <QCodeEditor>
#include <QFile>
#include <QFileSystemWatcher>
#include <QLabel>
#include <QMainWindow>
#include <QPushButton>
#include <QShortcut>
#include <QSplitter>
#include <QTemporaryDir>
#include <Runner.hpp>
#include <SettingsManager.hpp>
#include <UpdateNotifier.hpp>
#include <cftools.hpp>
#include <generated/version.hpp>
QT_BEGIN_NAMESPACE
namespace Ui
{
class MainWindow;
}
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
struct EditorStatus
{
bool isLanguageSet;
QString filePath, savedText, problemURL, editorText, language;
int editorCursor, editorAnchor, horizontalScrollBarValue, verticalScrollbarValue, untitledIndex;
QStringList input, expected;
EditorStatus(){};
EditorStatus(const QMap<QString, QVariant> &status);
QMap<QString, QVariant> toMap() const;
};
MainWindow(QString fileOpen, const Settings::SettingsData &data, int index = 0, QWidget *parent = nullptr);
~MainWindow() override;
int getUntitledIndex() const;
QString getFileName() const;
QString getFilePath() const;
QString getProblemURL() const;
QString getTabTitle(bool complete, bool star);
bool isUntitled() const;
EditorStatus toStatus() const;
void loadStatus(const EditorStatus &status);
void save(bool force, const QString &head);
void saveAs();
bool isTextChanged();
bool closeConfirm();
void killProcesses();
void detachedExecution();
void compileOnly();
void runOnly();
void compileAndRun();
void formatSource();
void applyCompanion(Network::CompanionData data);
void setLanguage(QString lang);
QString getLanguage();
void setSettingsData(const Settings::SettingsData &data, bool);
MessageLogger *getLogger();
QSplitter *getSplitter();
void insertText(QString text);
void focusOnEditor();
private slots:
void on_compile_clicked();
void on_runOnly_clicked();
void on_run_clicked();
void onCompilationStarted();
void onCompilationFinished(const QString &warning);
void onCompilationErrorOccured(const QString &error);
void onRunStarted(int index);
void onRunFinished(int index, const QString &out, const QString &err, int exitCode, int timeUsed);
void onRunErrorOccured(int index, const QString &error);
void onRunTimeout(int index);
void onRunKilled(int index);
void on_in1_customContextMenuRequested(const QPoint &pos);
void on_in2_customContextMenuRequested(const QPoint &pos);
void on_in3_customContextMenuRequested(const QPoint &pos);
void on_compiler_edit_customContextMenuRequested(const QPoint &pos);
void on_out3_customContextMenuRequested(const QPoint &pos);
void on_out2_customContextMenuRequested(const QPoint &pos);
void on_out1_customContextMenuRequested(const QPoint &pos);
void on_out1_diff_clicked();
void on_out2_diff_clicked();
void on_out3_diff_clicked();
void on_changeLanguageButton_clicked();
void onFileWatcherChanged(const QString &);
signals:
void editorChanged();
void confirmTriggered(MainWindow *widget);
private:
enum SaveMode
{
IgnoreUntitled, // save only when filePath is not empty
SaveUntitled, // save to filePath if it's not empty, otherwise ask for new path
SaveAs, // ask for new path no matter filePath is empty or not
};
enum AfterCompile
{
Nothing,
Run,
RunDetached
};
enum Verdict
{
ACCEPTED,
WRONG_ANSWER,
UNKNOWN
};
Ui::MainWindow *ui;
QCodeEditor *editor;
QString language;
Settings::SettingsData data;
bool isLanguageSet = false;
Core::Formatter *formatter = nullptr;
Core::Compiler *compiler = nullptr;
QVector<Core::Runner *> runner = QVector<Core::Runner *>(3, nullptr);
Core::Runner *detachedRunner = nullptr;
QTemporaryDir *tmpDir = nullptr;
AfterCompile afterCompile = Nothing;
MessageLogger log;
int untitledIndex;
QString problemURL;
QString filePath;
QString savedText;
QString cftoolPath;
QFileSystemWatcher *fileWatcher;
QVector<QPlainTextEdit *> input = QVector<QPlainTextEdit *>(3, nullptr);
QVector<QPlainTextEdit *> output = QVector<QPlainTextEdit *>(3, nullptr);
QVector<QLabel *> verdict = QVector<QLabel *>(3, nullptr);
QVector<QString *> expected = QVector<QString *>(3, nullptr);
QPushButton *submitToCodeforces = nullptr;
Network::CFTools *cftools = nullptr;
void setEditor();
void setupCore();
void compile();
void run();
void clearTests(bool outputOnly = false);
void loadTests();
void saveTests();
void setCFToolsUI();
void updateVerdict(Verdict, int);
bool isVerdictPass(QString, QString);
void setText(const QString &text, bool saveCursor = false);
void updateWatcher();
void loadFile(QString path);
bool saveFile(SaveMode, const QString &head);
bool saveTemp(const QString &head);
QString tmpPath();
void performCoreDiagonistics();
QString getRunnerHead(int index);
};
#endif // MAINWINDOW_HPP