| 1 | From 4c07c7e63727750a85f796a5b356c480f462bec2 Mon Sep 17 00:00:00 2001
|
| 2 | From: benyamin <[email protected]>
|
| 3 | Date: Wed, 14 Sep 2022 19:43:38 +0430
|
| 4 | Subject: [PATCH] initialized with Qt6
|
| 5 |
|
| 6 | ---
|
| 7 | CMakeLists.txt | 12 ++++++------
|
| 8 | example/CMakeLists.txt | 14 +++++++-------
|
| 9 | example/src/MainWindow.cpp | 9 +++++----
|
| 10 | src/internal/QCodeEditor.cpp | 15 ++++++++-------
|
| 11 | src/internal/QLanguage.cpp | 7 ++-----
|
| 12 | src/internal/QSyntaxStyle.cpp | 19 +++++++------------
|
| 13 | 6 files changed, 35 insertions(+), 41 deletions(-)
|
| 14 |
|
| 15 | diff --git a/CMakeLists.txt b/CMakeLists.txt
|
| 16 | index 40d5617..7cc7496 100644
|
| 17 | |
| 18 | |
| 19 | @@ -75,9 +75,9 @@ set(CMAKE_AUTOMOC On)
|
| 20 | set(CMAKE_AUTORCC ON)
|
| 21 |
|
| 22 | # Find includes in corresponding build directories
|
| 23 | -find_package(Qt5Core CONFIG REQUIRED)
|
| 24 | -find_package(Qt5Widgets CONFIG REQUIRED)
|
| 25 | -find_package(Qt5Gui CONFIG REQUIRED)
|
| 26 | +find_package(Qt6Core CONFIG REQUIRED)
|
| 27 | +find_package(Qt6Widgets CONFIG REQUIRED)
|
| 28 | +find_package(Qt6Gui CONFIG REQUIRED)
|
| 29 |
|
| 30 | add_library(QCodeEditor STATIC
|
| 31 | ${RESOURCES_FILE}
|
| 32 | @@ -104,7 +104,7 @@ if(CMAKE_COMPILER_IS_GNUCXX)
|
| 33 | endif(CMAKE_COMPILER_IS_GNUCXX)
|
| 34 |
|
| 35 | target_link_libraries(QCodeEditor
|
| 36 | - Qt5::Core
|
| 37 | - Qt5::Widgets
|
| 38 | - Qt5::Gui
|
| 39 | + Qt::Core
|
| 40 | + Qt::Widgets
|
| 41 | + Qt::Gui
|
| 42 | )
|
| 43 | diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt
|
| 44 | index 0e0bf4a..d6204e4 100644
|
| 45 | |
| 46 | |
| 47 | @@ -6,9 +6,9 @@ set(CMAKE_CXX_STANDARD 17)
|
| 48 | set(CMAKE_AUTOMOC On)
|
| 49 | set(CMAKE_AUTORCC ON)
|
| 50 |
|
| 51 | -find_package(Qt5Core CONFIG REQUIRED)
|
| 52 | -find_package(Qt5Widgets CONFIG REQUIRED)
|
| 53 | -find_package(Qt5Gui CONFIG REQUIRED)
|
| 54 | +find_package(Qt6Core CONFIG REQUIRED)
|
| 55 | +find_package(Qt6Widgets CONFIG REQUIRED)
|
| 56 | +find_package(Qt6Gui CONFIG REQUIRED)
|
| 57 |
|
| 58 | add_executable(QCodeEditorExample
|
| 59 | resources/demo_resources.qrc
|
| 60 | @@ -22,8 +22,8 @@ target_include_directories(QCodeEditorExample PUBLIC
|
| 61 | )
|
| 62 |
|
| 63 | target_link_libraries(QCodeEditorExample
|
| 64 | - Qt5::Core
|
| 65 | - Qt5::Widgets
|
| 66 | - Qt5::Gui
|
| 67 | + Qt::Core
|
| 68 | + Qt::Widgets
|
| 69 | + Qt::Gui
|
| 70 | QCodeEditor
|
| 71 | -)
|
| 72 | \ No newline at end of file
|
| 73 | +)
|
| 74 | diff --git a/example/src/MainWindow.cpp b/example/src/MainWindow.cpp
|
| 75 | index 5552835..e71a1f2 100644
|
| 76 | |
| 77 | |
| 78 | @@ -15,13 +15,14 @@
|
| 79 | #include <QPythonHighlighter>
|
| 80 |
|
| 81 | // Qt
|
| 82 | -#include <QComboBox>
|
| 83 | -#include <QVBoxLayout>
|
| 84 | -#include <QHBoxLayout>
|
| 85 | #include <QCheckBox>
|
| 86 | -#include <QSpinBox>
|
| 87 | +#include <QComboBox>
|
| 88 | +#include <QFile>
|
| 89 | #include <QGroupBox>
|
| 90 | +#include <QHBoxLayout>
|
| 91 | #include <QLabel>
|
| 92 | +#include <QSpinBox>
|
| 93 | +#include <QVBoxLayout>
|
| 94 |
|
| 95 | MainWindow::MainWindow(QWidget* parent) :
|
| 96 | QMainWindow(parent),
|
| 97 | diff --git a/src/internal/QCodeEditor.cpp b/src/internal/QCodeEditor.cpp
|
| 98 | index 1aa93e7..1369ff4 100644
|
| 99 | |
| 100 | |
| 101 | @@ -537,16 +537,17 @@ void QCodeEditor::keyPressEvent(QKeyEvent* e) {
|
| 102 |
|
| 103 | // Shortcut for moving line to left
|
| 104 | if (m_replaceTab && e->key() == Qt::Key_Backtab) {
|
| 105 | - indentationLevel = std::min(indentationLevel, m_tabReplace.size());
|
| 106 | + indentationLevel = std::min(indentationLevel, (int) m_tabReplace.size());
|
| 107 |
|
| 108 | - auto cursor = textCursor();
|
| 109 | + auto cursor = textCursor();
|
| 110 |
|
| 111 | - cursor.movePosition(QTextCursor::MoveOperation::StartOfLine);
|
| 112 | - cursor.movePosition(QTextCursor::MoveOperation::Right,
|
| 113 | - QTextCursor::MoveMode::KeepAnchor, indentationLevel);
|
| 114 | + cursor.movePosition(QTextCursor::MoveOperation::StartOfLine);
|
| 115 | + cursor.movePosition(QTextCursor::MoveOperation::Right,
|
| 116 | + QTextCursor::MoveMode::KeepAnchor,
|
| 117 | + indentationLevel);
|
| 118 |
|
| 119 | - cursor.removeSelectedText();
|
| 120 | - return;
|
| 121 | + cursor.removeSelectedText();
|
| 122 | + return;
|
| 123 | }
|
| 124 |
|
| 125 | QTextEdit::keyPressEvent(e);
|
| 126 | diff --git a/src/internal/QLanguage.cpp b/src/internal/QLanguage.cpp
|
| 127 | index 3665df7..417c657 100644
|
| 128 | |
| 129 | |
| 130 | @@ -32,8 +32,7 @@ bool QLanguage::load(QIODevice* device)
|
| 131 |
|
| 132 | if (type == QXmlStreamReader::TokenType::StartElement)
|
| 133 | {
|
| 134 | - if (reader.name() == "section")
|
| 135 | - {
|
| 136 | + if (reader.name().toString() == "section") {
|
| 137 | if (!list.empty())
|
| 138 | {
|
| 139 | m_list[name] = list;
|
| 140 | @@ -41,9 +40,7 @@ bool QLanguage::load(QIODevice* device)
|
| 141 | }
|
| 142 |
|
| 143 | name = reader.attributes().value("name").toString();
|
| 144 | - }
|
| 145 | - else if (reader.name() == "name")
|
| 146 | - {
|
| 147 | + } else if (reader.name().toString() == "name") {
|
| 148 | readText = true;
|
| 149 | }
|
| 150 | }
|
| 151 | diff --git a/src/internal/QSyntaxStyle.cpp b/src/internal/QSyntaxStyle.cpp
|
| 152 | index 6a9eb55..a4730de 100644
|
| 153 | |
| 154 | |
| 155 | @@ -25,15 +25,12 @@ bool QSyntaxStyle::load(QString fl)
|
| 156 |
|
| 157 | if(token == QXmlStreamReader::StartElement)
|
| 158 | {
|
| 159 | - if (reader.name() == "style-scheme")
|
| 160 | - {
|
| 161 | + if (reader.name().toString() == "style-scheme") {
|
| 162 | if (reader.attributes().hasAttribute("name"))
|
| 163 | {
|
| 164 | m_name = reader.attributes().value("name").toString();
|
| 165 | }
|
| 166 | - }
|
| 167 | - else if (reader.name() == "style")
|
| 168 | - {
|
| 169 | + } else if (reader.name().toString() == "style") {
|
| 170 | auto attributes = reader.attributes();
|
| 171 |
|
| 172 | auto name = attributes.value("name");
|
| 173 | @@ -50,21 +47,19 @@ bool QSyntaxStyle::load(QString fl)
|
| 174 | format.setForeground(QColor(attributes.value("foreground").toString()));
|
| 175 | }
|
| 176 |
|
| 177 | - if (attributes.hasAttribute("bold") &&
|
| 178 | - attributes.value("bold") == "true")
|
| 179 | - {
|
| 180 | + if (attributes.hasAttribute("bold")
|
| 181 | + && attributes.value("bold").toString() == "true") {
|
| 182 | format.setFontWeight(QFont::Weight::Bold);
|
| 183 | }
|
| 184 |
|
| 185 | - if (attributes.hasAttribute("italic") &&
|
| 186 | - attributes.value("italic") == "true")
|
| 187 | - {
|
| 188 | + if (attributes.hasAttribute("italic")
|
| 189 | + && attributes.value("italic").toString() == "true") {
|
| 190 | format.setFontItalic(true);
|
| 191 | }
|
| 192 |
|
| 193 | if (attributes.hasAttribute("underlineStyle"))
|
| 194 | {
|
| 195 | - auto underline = attributes.value("underlineStyle");
|
| 196 | + auto underline = attributes.value("underlineStyle").toString();
|
| 197 |
|
| 198 | auto s = QTextCharFormat::UnderlineStyle::NoUnderline;
|
| 199 |
|