From ff88c3872210f5a246348245c67e53342756ea26 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Sat, 3 May 2025 07:59:02 +0800 Subject: [PATCH] Fixes for build with Qt4 --- customtabwidget.h | 19 +++++++++++++++++++ highlighter.cpp | 1 + highlighter.h | 5 +++++ mainwindow.cpp | 18 +++++++++--------- mainwindow.h | 3 ++- 5 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 customtabwidget.h diff --git a/customtabwidget.h b/customtabwidget.h new file mode 100644 index 0000000..df820b2 --- /dev/null +++ b/customtabwidget.h @@ -0,0 +1,19 @@ +#ifndef CUSTOMTABWIDGET_H +#define CUSTOMTABWIDGET_H + +#include +#include + +class CustomTabWidget : public QTabWidget { +public: + // Constructor to accept a parent + explicit CustomTabWidget(QWidget* parent = nullptr) + : QTabWidget(parent) {} + + // Public method to expose the protected tabBar() + QTabBar* publicTabBar() { + return tabBar(); // Expose the protected tabBar() method + } +}; + +#endif // CUSTOMTABWIDGET_H diff --git a/highlighter.cpp b/highlighter.cpp index 1db02f4..a998ca5 100644 --- a/highlighter.cpp +++ b/highlighter.cpp @@ -1,6 +1,7 @@ #include "highlighter.h" #include +#include Highlighter::Highlighter(const QString _filename, QObject *parent) : QSyntaxHighlighter(parent) { xml_filename=_filename; diff --git a/highlighter.h b/highlighter.h index 26739f2..787d808 100644 --- a/highlighter.h +++ b/highlighter.h @@ -11,6 +11,11 @@ #include +// Custom hash function for QRegExp +inline uint qHash(const QRegExp &key) { + return qHash(key.pattern()); // Use the pattern of QRegExp as the hash key +} + class Highlighter : public QSyntaxHighlighter { public: explicit Highlighter(QString _filename, QObject *parent = 0); diff --git a/mainwindow.cpp b/mainwindow.cpp index 62be4e9..3ca01c5 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -32,12 +32,12 @@ void MainWindow::dragEnterEvent(QDragEnterEvent* drag_event) { void MainWindow::dropEvent(QDropEvent* drop_event) { QList url_list = drop_event->mimeData()->urls(); foreach (QUrl url, url_list) { - OpenFile(url.url(QUrl::RemoveScheme)); + OpenFile(url.toString(QUrl::RemoveScheme)); } } void MainWindow::SetupTabWidget() { - tabs = new QTabWidget(this); + tabs = new CustomTabWidget(this); tabs->setMovable(true); tabs->setTabsClosable(true); tabs->setUsesScrollButtons(true); @@ -113,11 +113,11 @@ void MainWindow::SetupOpenedDocsDock() { // update on opening/creating new file // delete on deleting tab provided by DeleteTabFromList(int) function // update position in list - connect(tabs->tabBar(), SIGNAL(tabMoved(int, int)), this, SLOT(ChangeTabIndexInList(int, int))); + connect(tabs->publicTabBar(), SIGNAL(tabMoved(int, int)), this, SLOT(ChangeTabIndexInList(int, int))); connect(opened_docs_widget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(UpdateCurrentIndex(QListWidgetItem*))); connect(opened_docs_widget, SIGNAL(currentRowChanged(int)), tabs, SLOT(setCurrentIndex(int))); - connect(tabs->tabBar(), SIGNAL(currentChanged(int)), this, SLOT(UpdateCurrentIndex(int))); - connect(tabs->tabBar(), SIGNAL(tabCloseRequested(int)), this, SLOT(UpdateCurrentIndexOnDelete(int))); + connect(tabs->publicTabBar(), SIGNAL(currentChanged(int)), this, SLOT(UpdateCurrentIndex(int))); + connect(tabs->publicTabBar(), SIGNAL(tabCloseRequested(int)), this, SLOT(UpdateCurrentIndexOnDelete(int))); opened_docs_dock = new QDockWidget("Opened files", this); @@ -242,8 +242,8 @@ void MainWindow::SaveFileAs() { } } filename = filepath.section("/",-1,-1); - tabs->tabBar()->setTabText(tabs->currentIndex(), filename); - tabs->tabBar()->setTabToolTip(tabs->currentIndex(), filepath); + tabs->publicTabBar()->setTabText(tabs->currentIndex(), filename); + tabs->publicTabBar()->setTabToolTip(tabs->currentIndex(), filepath); QString file_extension = QFileInfo(filename).suffix(); // setting up highlight if (highlighter->setExtension(file_extension)) { @@ -321,7 +321,7 @@ void MainWindow::closeEvent(QCloseEvent*) { void::MainWindow::UpdateParameter() { // highlight bad support (always changed) - QString file = tabs->tabBar()->tabText(tabs->currentIndex()); + QString file = tabs->publicTabBar()->tabText(tabs->currentIndex()); QString file_extension = QFileInfo(file).suffix(); if (!file_extension.isEmpty()) { if (highlighter->setExtension(file_extension)) { @@ -358,7 +358,7 @@ void MainWindow::UpdateCurrentIndex(int new_selection_index) { opened_docs_widget->setCurrentRow(new_selection_index); // + highlight update - QString file = tabs->tabBar()->tabText(new_selection_index); + QString file = tabs->publicTabBar()->tabText(new_selection_index); QString file_extension = QFileInfo(file).suffix(); if (!file_extension.isEmpty()) { if (highlighter->setExtension(file_extension)) { diff --git a/mainwindow.h b/mainwindow.h index 08d74b3..9b8c2be 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -34,6 +34,7 @@ #include "linenumberarea.h" #include "codeeditor.h" #include "highlighter.h" +#include "customtabwidget.h" namespace Ui { @@ -49,7 +50,7 @@ public: private: Ui::MainWindow *ui; - QTabWidget* tabs; + CustomTabWidget* tabs; // Use the custom class Highlighter* highlighter; QDirModel* file_system_model; -- 2.48.0