Add support qt6

This commit is contained in:
Oleg Korshul
2025-08-20 17:46:40 +03:00
parent 5958a31328
commit 980a95f4d1
23 changed files with 266 additions and 38 deletions

View File

@ -68,7 +68,8 @@ INCLUDEPATH += \
$$BASEEDITORS_PATH/lib/include \
$$BASEEDITORS_PATH/lib/qt_wrapper/include \
$$CORE_ROOT_DIR/DesktopEditor \
$$CORE_ROOT_DIR/Common
$$CORE_ROOT_DIR/Common \
$$PWD/src
HEADERS += \
$$PWD/src/windows/cmainwindow.h \

View File

@ -6,7 +6,7 @@
#include <QTimer>
#include <QDir>
#include <QDateTime>
#include <QDesktopWidget>
#include <qtcomp/qdesktopwidget.h>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>

View File

@ -5,11 +5,12 @@
#include <QApplication>
#include <QFile>
#include <QSettings>
#include <QRegularExpression>
#include <QTranslator>
#include <list>
#include <algorithm>
#include <qtcomp/qregexp.h>
#ifdef _WIN32
# ifndef __OS_WIN_XP
# include <commctrl.h>
@ -60,21 +61,21 @@ QString normalizeLocale(const QString &locale)
{
int len = locale.length();
if (len > 1) {
int prim = locale.indexOf(QRegExp("[-_]"));
int prim = locale.indexOf(QtComp::RegExp::QRegExp("[-_]"));
if (prim == -1) {
if (len <= 3)
return locale.toLower();
} else
if (prim == 2 || prim == 3) {
QString out = locale.mid(0, prim).toLower();
int scnd = locale.indexOf(QRegExp("[-_]"), prim + 1);
int scnd = locale.indexOf(QtComp::RegExp::QRegExp("[-_]"), prim + 1);
if ((scnd == -1 && len - prim == 3) || (scnd != -1 && scnd - prim == 3)) {
out += "-" + locale.mid(prim + 1, 2).toUpper();
} else
if ((scnd == -1 && len - prim == 5) || (scnd != -1 && scnd - prim == 5)) {
out += QString("-") + locale.at(prim + 1).toUpper() + locale.mid(prim + 2, 3).toLower();
if (scnd != -1) {
int thrd = locale.indexOf(QRegExp("[-_]"), scnd + 1);
int thrd = locale.indexOf(QtComp::RegExp::QRegExp("[-_]"), scnd + 1);
if ((thrd == -1 && len - scnd == 3) || (thrd != -1 && thrd - scnd == 3))
out += "-" + locale.mid(scnd + 1, 2).toUpper();
}
@ -110,7 +111,7 @@ QString getLocaleParts(const QString &locale, LocaleParts parts = LocaleParts::L
if (scnd != -1 && scnd - prim == 5) {
int thrd = locale.indexOf('-', scnd + 1);
if ((thrd == -1 && len - scnd == 3) || (thrd != -1 && thrd - scnd == 3))
out += locale.midRef(scnd, 3);
out += locale.mid(scnd, 3);
}
}
return out;

View File

@ -25,9 +25,13 @@ void CLogger::write(const QString &value)
text = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss ") + text;
QTextStream out(m_file);
#ifdef QT_VERSION_6
out.setEncoding(QStringConverter::Utf8);
#else
out.setCodec("UTF-8");
#endif
if ( m_file ) {
out << text << endl;
out << text << Qt::endl;
}
}

View File

@ -31,7 +31,6 @@
*/
#include "components/asctabwidget.h"
#include <QRegExp>
#include <QHBoxLayout>
#include <QApplication>
#include "casctabdata.h"

View File

@ -1,6 +1,7 @@
#include "components/canimatedicon.h"
#include <QPainter>
#include <QVariant>
#include <qtcomp/qnativeevent.h>
#define RELEASE_OBJECT(obj) if (obj) delete obj, obj = nullptr;
@ -44,8 +45,8 @@ void CAnimatedIcon::startSvg(const QString& source, const QString& eid)
if ( m_svg->load(source) ) {
// setFixedSize( m_svg->defaultSize() );
if ( !m_static && pixmap() ) {
m_static = new QPixmap(*pixmap());
if ( !m_static ) {
m_static = QtComp::Widget::copyPixmap(this);
}
if ( m_svg->animated() ) {

View File

@ -32,7 +32,7 @@
#include "components/cfiledialog.h"
#include <QFileDialog>
#include <QRegularExpression>
#include <qtcomp/qregexp.h>
#include "defines.h"
#include "utils.h"
#include "components/cmessage.h"
@ -132,11 +132,11 @@ bool CFileDialogWrapper::modalSaveAs(QString& fileName, int selected)
QFileInfo info(fileName);
_ext = info.suffix();
QRegExp reFilter("([\\w\\s]+\\(\\*\\."+_ext+"+\\))", Qt::CaseInsensitive);
QtComp::RegExp::QRegExp reFilter("([\\w\\s]+\\(\\*\\."+_ext+"+\\))", Qt::CaseInsensitive);
if ( !m_filters.isEmpty() ) {
_filters = m_filters;
if ( !(reFilter.indexIn(m_filters) < 0) ) {
if ( reFilter.match(m_filters) ) {
if ( _sel_filter.isEmpty() )
_sel_filter = reFilter.cap(1);
} else {
@ -196,7 +196,7 @@ bool CFileDialogWrapper::modalSaveAs(QString& fileName, int selected)
fileName = _exec_dialog(_parent, _croped_name, _filters, _sel_filter);
if ( !fileName.isEmpty() ) {
if ( !(reFilter.indexIn(_sel_filter) < 0) ) {
if ( reFilter.match(_sel_filter) ) {
_ext = reFilter.cap(1);
if (!fileName.endsWith(_ext))
@ -232,13 +232,13 @@ bool CFileDialogWrapper::modalSaveAs(QString& fileName, int selected)
QString CFileDialogWrapper::getFilter(const QString& extension) const
{
QString out = extension.toLower();
if (extension.contains(QRegExp("^docx?$"))) {
if (extension.contains(QtComp::RegExp::QRegExp("^docx?$"))) {
return tr("Word Document") + " (*." + out +")";
} else
if (extension.contains(QRegExp("^xlsx?$"))) {
if (extension.contains(QtComp::RegExp::QRegExp("^xlsx?$"))) {
return tr("Excel Workbook") + " (*." + out + ")";
} else
if (extension.contains(QRegExp("^pptx?$"))) {
if (extension.contains(QtComp::RegExp::QRegExp("^pptx?$"))) {
return tr("PowerPoint Presentation") + " (*." + out + ")";
} else {
out.replace(0, 1, extension.left(1).toUpper());

View File

@ -36,6 +36,8 @@
#include <QPainter>
#include <QLayout>
#include <QAction>
#include <qtcomp/qnativeevent.h>
#ifdef __linux__
# include <QX11Info>
#endif
@ -93,7 +95,7 @@ protected:
QSize icon_size(m_icon_size);
if (m_icon_size.isEmpty()) {
QStyleOption opt;
opt.init(this);
QtComp::Widget::initStyleOption(&opt, this);
int icSize = style()->pixelMetric(QStyle::PM_SmallIconSize, &opt, this);
icon_size.setWidth(icSize);
icon_size.setHeight(icSize);

View File

@ -49,6 +49,8 @@
#include <initializer_list>
#include <memory.h>
#include <qtcomp/qregexp.h>
#ifdef __linux__
# include "platform_linux/gtkmessage.h"
#else
@ -262,12 +264,12 @@ void QtMsg::setButtons(std::initializer_list<QString> btns)
close();
};
QRegExp reFocus("([^:]+)\\:?(default)?$");
QtComp::RegExp::QRegExp reFocus("([^:]+)\\:?(default)?$");
QPushButton * _btn;
int _btn_num(0);
for (auto &btn: btns) {
reFocus.indexIn(btn);
reFocus.match(btn);
_btn = new QPushButton(reFocus.cap(1));
if ( !reFocus.cap(2).isEmpty() ) {

View File

@ -61,6 +61,8 @@
# define GetPid() getpid()
#endif
#include <qtcomp/qdatetime.h>
#define modeToEnum(mod) ((mod == "silent") ? UpdateMode::SILENT : (mod == "ask") ? UpdateMode::ASK : UpdateMode::DISABLE)
#define packageToStr() QString(IsPackage(ISS) ? "iss" : IsPackage(MSI) ? "msi" : IsPackage(Portable) ? "portable" : "other")
#define WStrToTStr(str) QStrToTStr(QString::fromStdWString(str))
@ -174,7 +176,7 @@ auto currentArch()->QString
auto formattedTime(time_t timestamp)->QString
{
return (timestamp != 0) ? QLocale::system().toString(QDateTime::fromTime_t(timestamp), QLocale::ShortFormat) :
return (timestamp != 0) ? QLocale::system().toString(QtComp::DateTime::fromTimestamp(timestamp), QLocale::ShortFormat) :
QString("--.--.---- --:--");
}

View File

@ -0,0 +1,18 @@
#pragma once
#include <QDateTime>
namespace QtComp
{
namespace DateTime
{
QDateTime fromTimestamp(qint64 timestamp)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
return QDateTime::fromTime_t(static_cast<uint>(timestamp));
#else
return QDateTime::fromSecsSinceEpoch(timestamp);
#endif
}
}
}

View File

@ -0,0 +1,36 @@
#pragma once
#include <QRect>
#include <QWidget>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QApplication>
#include <QDesktopWidget>
#else
#include <QGuiApplication>
#include <QScreen>
#endif
namespace QtComp
{
namespace DesktopWidget
{
static QRect availableGeometry(const QWidget* widget = nullptr)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (widget)
return QApplication::desktop()->availableGeometry(widget);
else
return QApplication::desktop()->availableGeometry();
#else
QScreen* screen = nullptr;
if (widget) {
screen = QGuiApplication::screenAt(widget->geometry().center());
}
if (!screen)
screen = QGuiApplication::primaryScreen();
return screen ? screen->availableGeometry() : QRect();
#endif
}
};
}

View File

@ -0,0 +1,52 @@
#pragma once
#include <QLayout>
#include <QPixmap>
#include <QLabel>
#include <QStyleOption>
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
typedef long long_ptr;
#else
typedef qintptr long_ptr;
#endif
namespace QtComp
{
namespace Widget
{
static void setLayoutMargin(QLayout* layout, const int& margin)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
layout->setMargin(margin);
#else
layout->setContentsMargins(margin, margin, margin, margin);
#endif
}
static QPixmap* copyPixmap(QLabel* label)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
const QPixmap* pixmap = label->pixmap();
if (pixmap) {
return new QPixmap(*pixmap);
}
#else
QPixmap pixmap = label->pixmap();
if (!pixmap.isNull()) {
return new QPixmap(pixmap);
}
#endif
return nullptr;
}
static void initStyleOption(QStyleOption* option, const QWidget *w)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
option->init(w);
#else
option->initFrom(w);
#endif
}
}
}

View File

@ -0,0 +1,15 @@
#pragma once
#include <QPalette>
namespace QtComp
{
namespace Palette
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
constexpr QPalette::ColorRole Background = QPalette::Background;
#else
constexpr QPalette::ColorRole Background = QPalette::Window;
#endif
}
}

View File

@ -0,0 +1,86 @@
#pragma once
#include <QString>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QRegExp>
#else
#include <QRegularExpression>
#include <QRegularExpressionMatch>
#endif
namespace QtComp
{
namespace RegExp
{
class QRegExp
{
public:
QRegExp(const QString& pattern = QString(), bool caseInsensitive = false)
{
setPattern(pattern, caseInsensitive);
}
void setPattern(const QString& pattern, bool caseInsensitive = false)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
m_re = QRegExp(pattern,
caseInsensitive ? Qt::CaseInsensitive : Qt::CaseSensitive);
#else
QRegularExpression::PatternOptions opts =
caseInsensitive ? QRegularExpression::CaseInsensitiveOption
: QRegularExpression::NoPatternOption;
m_re.setPattern(pattern);
m_re.setPatternOptions(opts);
#endif
}
bool match(const QString& text)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
m_lastIndex = m_re.indexIn(text);
return m_lastIndex >= 0;
#else
m_match = m_re.match(text);
return m_match.hasMatch();
#endif
}
QString cap(int n) const
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
return m_re.cap(n);
#else
return m_match.captured(n);
#endif
}
QString captured(int n) const { return cap(n); }
static QString escape(const QString& str)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
return QRegExp::escape(str);
#else
return QRegularExpression::escape(str);
#endif
}
// Неявные конверсии — позволяют использовать в QString::contains()
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
operator QRegExp() const { return m_re; }
#else
operator QRegularExpression() const { return m_re; }
#endif
private:
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QRegExp m_re;
int m_lastIndex = -1;
#else
QRegularExpression m_re;
QRegularExpressionMatch m_match;
#endif
};
}
}

View File

@ -40,7 +40,6 @@
#include <QDir>
#include <QRegularExpression>
#include <QApplication>
#include <QDesktopWidget>
#include <QUrl>
#include <QUrlQuery>
#include <QJsonDocument>

View File

@ -211,7 +211,7 @@ QWidget * CEditorWindow::createMainPanel(QWidget * parent, const QString& title)
QGridLayout * mainGridLayout = new QGridLayout(mainPanel);
mainGridLayout->setSpacing(0);
mainGridLayout->setMargin(0);
QtComp::Widget::setLayoutMargin(mainGridLayout, 0);
mainPanel->setLayout(mainGridLayout);
if (isCustomWindowStyle()) {

View File

@ -48,6 +48,8 @@
#include <QGridLayout>
#include <QAction>
#include <qtcomp/qregexp.h>
#include <qtcomp/qnativeevent.h>
#define DEFAULT_BTNS_COUNT 6
#define ICON_SPACER_WIDTH 9
#define ICON_SIZE QSize(20,20)
@ -137,7 +139,7 @@ public:
leftboxbuttons = new QWidget;
leftboxbuttons->setLayout(new QHBoxLayout);
leftboxbuttons->layout()->setSpacing(0);
leftboxbuttons->layout()->setMargin(0);
QtComp::Widget::setLayoutMargin(leftboxbuttons->layout(), 0);
CSVGPushButton * btnHome = new CSVGPushButton;
btnHome->setProperty("class", "normal");
@ -408,7 +410,7 @@ public:
void onEditorActionRequest(int, const QString& json) override
{
if ( json.contains(QRegExp("action\\\":\\\"file:close")) ) {
if ( json.contains(QtComp::RegExp::QRegExp("action\\\":\\\"file:close")) ) {
window->closeWindow();
}
}
@ -939,7 +941,7 @@ public:
boxtitlelabel->setObjectName("boxtitlelabel");
boxtitlelabel->setLayout(new QHBoxLayout(boxtitlelabel));
boxtitlelabel->layout()->setSpacing(0);
boxtitlelabel->layout()->setMargin(0);
QtComp::Widget::setLayoutMargin(boxtitlelabel->layout(), 0);
boxtitlelabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
boxtitlelabel->layout()->addWidget(window->m_labelTitle);
if ( m_panel->data()->hasFeature(L"crypted\":true") && !iconcrypted ) {

View File

@ -42,16 +42,18 @@
#include "version.h"
#include "components/cmessage.h"
#include "ctabundockevent.h"
#include <QDesktopWidget>
#include <qtcomp/qdesktopwidget.h>
#include <QGridLayout>
#include <QTimer>
#include <QApplication>
#include <QAction>
#include <QRegularExpression>
#include <QJsonDocument>
#include <QJsonObject>
#include <QMimeData>
#include <qtcomp/qregexp.h>
#include <qtcomp/qpalette.h>
#ifdef _WIN32
# include "shlobj.h"
#endif
@ -483,7 +485,7 @@ QWidget* CMainWindow::createMainPanel(QWidget *parent)
QLinearGradient gradient(mainPanel->rect().topLeft(), QPoint(mainPanel->rect().left(), 29));
gradient.setColorAt(0, QColor(0xeee));
gradient.setColorAt(1, QColor(0xe4e4e4));
palette.setBrush(QPalette::Background, QBrush(gradient));
palette.setBrush(QtComp::Palette::Background, QBrush(gradient));
label->setFixedHeight(0);
}
@ -1299,7 +1301,7 @@ void CMainWindow::onEditorActionRequest(int vid, const QString& args)
{
int index = m_pTabs->tabIndexByView(vid);
if (!(index < 0)) {
if (args.contains(QRegExp("action\\\":\\\"file:close"))) {
if (args.contains(QtComp::RegExp::QRegExp("action\\\":\\\"file:close"))) {
bool _is_local = m_pTabs->isLocalByIndex(index);
onTabCloseRequest(index);
if (!_is_local) {

View File

@ -37,6 +37,7 @@
#include "utils.h"
#include <QGridLayout>
#include <clangater.h>
#include <qtcomp/qnativeevent.h>
using namespace std::placeholders;
@ -112,7 +113,7 @@ QWidget * CPresenterWindow::createMainPanel(QWidget * parent, const QString& tit
QGridLayout * mainGridLayout = new QGridLayout(mainPanel);
mainGridLayout->setSpacing(0);
mainGridLayout->setMargin(0);
QtComp::Widget::setLayoutMargin(mainGridLayout, 0);
mainPanel->setLayout(mainGridLayout);
m_boxTitleBtns = createTopPanel(mainPanel);

View File

@ -42,6 +42,8 @@
#include <QCoreApplication>
#include "utils.h"
#include <qtcomp/qnativeevent.h>
#define RESIZE_AREA_PART 0.14
@ -96,13 +98,16 @@ private:
if (!buttonAtPos(pos)) {
::ReleaseCapture();
::PostMessage(hwnd_root, cmd, isResizingAvailable() && isPointInResizeArea(pos.y()) ? HTTOP : HTCAPTION, POINTTOPOINTS(pt));
#ifndef QT_VERSION_6
// TODO: crash on mouse down
QCoreApplication::postEvent(parent(), new QEvent(QEvent::MouseButtonPress));
#endif
return true;
}
return false;
}
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result) override
virtual bool nativeEvent(const QByteArray &eventType, void *message, long_ptr *result) override
{
#if (QT_VERSION == QT_VERSION_CHECK(5, 11, 1))
MSG* msg = *reinterpret_cast<MSG**>(message);

View File

@ -35,7 +35,7 @@
#include "defines.h"
#include "utils.h"
#include <QTimer>
#include <QDesktopWidget>
#include <qtcomp/qdesktopwidget.h>
#include <QWindow>
#include <QScreen>
#include <QJsonObject>
@ -290,7 +290,7 @@ void CWindowPlatform::adjustGeometry()
if (isMaximized()) {
if (Utils::getWinVersion() < WinVer::Win10) {
QTimer::singleShot(25, this, [=]() {
auto rc = QApplication::desktop()->availableGeometry(this);
auto rc = QtComp::DesktopWidget::availableGeometry(this);
int offset = 0;
if (Utils::getWinVersion() == WinVer::WinXP) {
if (isTaskbarAutoHideOn())
@ -376,7 +376,7 @@ void CWindowPlatform::changeEvent(QEvent *event)
}
}
bool CWindowPlatform::nativeEvent(const QByteArray &eventType, void *message, long *result)
bool CWindowPlatform::nativeEvent(const QByteArray &eventType, void *message, long_ptr *result)
{
#if (QT_VERSION == QT_VERSION_CHECK(5, 11, 1))
MSG* msg = *reinterpret_cast<MSG**>(message);

View File

@ -35,7 +35,7 @@
#include "windows/cwindowbase.h"
#include <QtWidgets/QApplication>
#include <qtcomp/qnativeevent.h>
struct FRAME {
FRAME() : left(0), top(0)
@ -71,7 +71,7 @@ protected:
private:
virtual void changeEvent(QEvent*) final;
virtual bool nativeEvent(const QByteArray&, void*, long*) final;
virtual bool nativeEvent(const QByteArray&, void*, long_ptr*) final;
QTimer *m_propertyTimer;
double m_dpi;