| 47 | } |
| 48 | |
| 49 | CodeEditor::CodeEditor(QTextDocument* doc, const QString& path, bool isNewFile, bool large, |
| 50 | QFont& font, int indentSize0, bool useTabs0, const Theme& theme0, bool darkMode0, |
| 51 | QTabWidget* t, QWidget *parent) : |
| 52 | QPlainTextEdit(parent), loadContentsButton(nullptr), tabs(t), |
| 53 | indentSize(indentSize0), useTabs(useTabs0), theme(theme0), darkMode(darkMode0) |
| 54 | { |
| 55 | if (doc) { |
| 56 | QPlainTextEdit::setDocument(doc); |
| 57 | } |
| 58 | initUI(font); |
| 59 | if (isNewFile) { |
| 60 | filepath = ""; |
| 61 | filename = path; |
| 62 | } else { |
| 63 | filepath = QFileInfo(path).absoluteFilePath(); |
| 64 | filename = QFileInfo(path).fileName(); |
| 65 | } |
| 66 | if (large) { |
| 67 | setReadOnly(true); |
| 68 | QPushButton* pb = new QPushButton("Big file. Load contents?", this); |
| 69 | connect(pb, &QPushButton::clicked, this, &CodeEditor::loadContents); |
| 70 | loadContentsButton = pb; |
| 71 | } |
| 72 | completer = new QCompleter(this); |
| 73 | QStringList completionList; |
| 74 | completionList << "annotation" << "array" << "bool" << "constraint" |
| 75 | << "diff" << "else" << "elseif" << "endif" << "enum" << "float" |
| 76 | << "function" << "include" << "intersect" << "maximize" << "minimize" |
| 77 | << "output" << "predicate" << "satisfy" << "solve" << "string" |
| 78 | << "subset" << "superset" << "symdiff" << "test" << "then" |
| 79 | << "union" << "where"; |
| 80 | completionList.sort(); |
| 81 | completionModel.setStringList(completionList); |
| 82 | completer->setModel(&completionModel); |
| 83 | completer->setCaseSensitivity(Qt::CaseSensitive); |
| 84 | completer->setModelSorting(QCompleter::CaseSensitivelySortedModel); |
| 85 | completer->setWrapAround(false); |
| 86 | completer->setWidget(this); |
| 87 | completer->setCompletionMode(QCompleter::PopupCompletion); |
| 88 | QObject::connect(completer, QOverload<const QString&>::of(&QCompleter::activated), this, &CodeEditor::insertCompletion); |
| 89 | |
| 90 | modificationTimer.setSingleShot(true); |
| 91 | QObject::connect(&modificationTimer, &QTimer::timeout, this, &CodeEditor::contentsChangedWithTimeout); |
| 92 | |
| 93 | auto* mw = qobject_cast<MainWindow*>(parent); |
| 94 | if (mw != nullptr) { |
| 95 | QObject::connect(this, &CodeEditor::escPressed, mw, &MainWindow::closeFindWidget); |
| 96 | } |
| 97 | |
| 98 | setAcceptDrops(false); |
| 99 | installEventFilter(this); |
| 100 | } |
| 101 | |
| 102 | void CodeEditor::loadContents() |
| 103 | { |
nothing calls this directly
no outgoing calls
no test coverage detected