Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,3 @@ qtmediate_add_library(${PROJECT_NAME} AUTOGEN
SKIP_AUTOMOC collections global text
PREFIX QM_CORE
)

if(QT_VERSION_MAJOR GREATER_EQUAL 6)
qm_link_qt(${PROJECT_NAME} PUBLIC Core5Compat)
endif()
1 change: 0 additions & 1 deletion src/core/global/qmsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <QDir>
#include <QFileInfo>
#include <QString>
#include <QTextCodec>

#include <QMCore/qmglobal.h>

Expand Down
8 changes: 8 additions & 0 deletions src/core/text/qmsimplevarexp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ static QString parseExpression(QString s, const QHash<QString, QString> &vars,
int lastIndex = 0;
while ((index = s.indexOf(reg, index, &match)) != -1) {
hasMatch = true;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(s).sliced(lastIndex, index - lastIndex);
#else
result += s.midRef(lastIndex, index - lastIndex);
#endif

const auto &name = match.captured(1);
QString val;
Expand All @@ -125,7 +129,11 @@ static QString parseExpression(QString s, const QHash<QString, QString> &vars,
index += match.captured(0).size();
lastIndex = index;
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(s).sliced(lastIndex);
#else
result += s.midRef(lastIndex);
#endif
s = result;
} while (hasMatch);
s.replace(QStringLiteral("$$"), QStringLiteral("$"));
Expand Down
49 changes: 45 additions & 4 deletions src/widgets/kernel/qmdecoratorv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,14 @@ QString QMDecoratorV2Private::replaceFontSizes(const QString &stylesheet, double
QString result;
result.reserve(stylesheet.size());
while ((index = stylesheet.indexOf(re, index, &match)) != -1) {
result += stylesheet.midRef(lastIndex, index - lastIndex);

QString matchString = match.captured(1);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(stylesheet).sliced(lastIndex, index - lastIndex);
double size = QStringView(matchString).sliced(0, matchString.size() - 2).toDouble();
#else
result += stylesheet.midRef(lastIndex, index - lastIndex);
double size = matchString.midRef(0, matchString.size() - 2).toDouble();
#endif
size *= ratio;
QString valueString = QStringLiteral("font-size: ") +
(rounding ? QString::number(int(size)) : QString::number(size)) +
Expand All @@ -569,7 +573,11 @@ QString QMDecoratorV2Private::replaceFontSizes(const QString &stylesheet, double
index += match.captured().size();
lastIndex = index;
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(stylesheet).sliced(lastIndex);
#else
result += stylesheet.midRef(lastIndex);
#endif
return result;
}

Expand All @@ -582,10 +590,15 @@ QString QMDecoratorV2Private::replaceSizes(const QString &stylesheet, double rat
QString result;
result.reserve(stylesheet.size());
while ((index = stylesheet.indexOf(re, index, &match)) != -1) {
result += stylesheet.midRef(lastIndex, index - lastIndex);

QString matchString = match.captured();
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(stylesheet).sliced(lastIndex, index - lastIndex);
double size = QStringView(matchString).sliced(0, matchString.size() - 2).toDouble();
#else
result += stylesheet.midRef(lastIndex, index - lastIndex);
double size = matchString.midRef(0, matchString.size() - 2).toDouble();
#endif

size *= ratio;
QString valueString =
(rounding ? QString::number(int(size)) : QString::number(size)) + QStringLiteral("px");
Expand All @@ -594,7 +607,11 @@ QString QMDecoratorV2Private::replaceSizes(const QString &stylesheet, double rat
index += matchString.size();
lastIndex = index;
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(stylesheet).sliced(lastIndex);
#else
result += stylesheet.midRef(lastIndex);
#endif
return result;
}

Expand All @@ -610,7 +627,11 @@ QString QMDecoratorV2Private::replaceCustomKeyWithQProperty(const QString &style
QString result;
result.reserve(stylesheet.size());
while ((index = stylesheet.indexOf(re, index, &match)) != -1) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(stylesheet).sliced(lastIndex, index - lastIndex);
#else
result += stylesheet.midRef(lastIndex, index - lastIndex);
#endif

QString matchString = match.captured();
int capturedIndex = match.capturedStart(2) - index;
Expand All @@ -623,7 +644,11 @@ QString QMDecoratorV2Private::replaceCustomKeyWithQProperty(const QString &style
index += matchString.size();
lastIndex = index;
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(stylesheet).sliced(lastIndex);
#else
result += stylesheet.midRef(lastIndex);
#endif
return result;
}

Expand All @@ -640,15 +665,23 @@ QString QMDecoratorV2Private::replaceCssGrammars(const QString &stylesheet) {
int index = 0;
int lastIndex = 0;
while ((index = stylesheet.indexOf(re, index, &match)) != -1) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(stylesheet).sliced(lastIndex, index - lastIndex);
#else
result += stylesheet.midRef(lastIndex, index - lastIndex);
#endif

QString matchString = match.captured();
QString valueString = QStringLiteral(":!") + match.captured(1).trimmed();
result += valueString;
index += matchString.size();
lastIndex = index;
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(stylesheet).sliced(lastIndex);
#else
result += stylesheet.midRef(lastIndex);
#endif
}

// Replace "svg(...);" to "url(\"[[...]].svgx\");"
Expand All @@ -671,12 +704,20 @@ QString QMDecoratorV2Private::removeAllComments(const QString &stylesheet) {
QString result;
result.reserve(stylesheet.size());
while ((index = stylesheet.indexOf(re, index, &match)) != -1) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(stylesheet).sliced(lastIndex, index - lastIndex);
#else
result += stylesheet.midRef(lastIndex, index - lastIndex);
#endif

index += match.captured(0).size();
lastIndex = index;
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
result += QStringView(stylesheet).sliced(lastIndex);
#else
result += stylesheet.midRef(lastIndex);
#endif
return result;
}

Expand Down
70 changes: 69 additions & 1 deletion src/widgets/widgets/ccombobox.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
#include "ccombobox.h"

#include <QGuiApplication>
#include <QListView>
#include <QStyleHints>

CComboBox::CComboBox(QWidget *parent) : QComboBox(parent), m_enableWheel(false) {
#ifdef Q_OS_WINDOWS
# include <dwmapi.h>
#endif

static CComboBox::CornerPreference g_defaultCornerPreference = CComboBox::RoundSmall;

CComboBox::CComboBox(QWidget *parent)
: QComboBox(parent), m_enableWheel(false), m_cornerPreference(g_defaultCornerPreference) {
setView(new QListView());

#ifdef Q_OS_WINDOWS
if (auto *popup = view()->parentWidget()) {
popup->setWindowFlag(Qt::NoDropShadowWindowHint, true);
}
#endif
}

CComboBox::~CComboBox() {
Expand All @@ -17,8 +32,61 @@ void CComboBox::setEnableWheel(bool enableWheel) {
m_enableWheel = enableWheel;
}

void CComboBox::setDefaultCornerPreference(CornerPreference preference) {
g_defaultCornerPreference = preference;
}

CComboBox::CornerPreference CComboBox::defaultCornerPreference() {
return g_defaultCornerPreference;
}

void CComboBox::setCornerPreference(CornerPreference preference) {
m_cornerPreference = preference;
}

CComboBox::CornerPreference CComboBox::cornerPreference() const {
return m_cornerPreference;
}

void CComboBox::wheelEvent(QWheelEvent *event) {
if (m_enableWheel) {
QComboBox::wheelEvent(event);
}
}

void CComboBox::showPopup() {
QComboBox::showPopup();

#ifdef Q_OS_WINDOWS
QWidget *popup = view() ? view()->window() : nullptr;
if (!popup || !popup->winId())
return;

constexpr int mgn = 1;
constexpr int DWMWA_USE_IMMERSIVE_DARK_MODE_ = 20;
constexpr int DWMWA_WINDOW_CORNER_PREFERENCE_ = 33;
constexpr int DWMWA_BORDER_COLOR_ = 34;
constexpr COLORREF DWMWA_COLOR_DEFAULT_ = 0xFFFFFFFF;
constexpr COLORREF DWMWA_COLOR_NONE_ = 0xFFFFFFFE;
DWMNCRENDERINGPOLICY ncrp = DWMNCRP_ENABLED;
INT dwcp = m_cornerPreference;
# if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
const UINT dark = QGuiApplication::styleHints()->colorScheme() != Qt::ColorScheme::Light;
# else
const UINT dark = 1;
# endif
MARGINS margins = {mgn, mgn, mgn, mgn};

HWND hwnd = reinterpret_cast<HWND>(popup->winId());
DwmSetWindowAttribute(hwnd, DWMWA_NCRENDERING_POLICY, &ncrp, sizeof(ncrp));
DwmExtendFrameIntoClientArea(hwnd, &margins);
DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE_, &dark, sizeof(dark));
DwmSetWindowAttribute(hwnd, DWMWA_WINDOW_CORNER_PREFERENCE_, &dwcp, sizeof(dwcp));
// Update the border color for the current scheme: suppress the DWM border in light mode,
// keep the default one in dark mode. Do NOT force a synchronous non-client refresh here
// (SWP_FRAMECHANGED + RDW_UPDATENOW): those synchronous cross-process calls can flood
// dwm.exe and freeze the desktop compositor.
const COLORREF borderColor = dark ? DWMWA_COLOR_DEFAULT_ : DWMWA_COLOR_NONE_;
DwmSetWindowAttribute(hwnd, DWMWA_BORDER_COLOR_, &borderColor, sizeof(borderColor));
#endif
}
13 changes: 13 additions & 0 deletions src/widgets/widgets/ccombobox.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,31 @@

class QM_WIDGETS_EXPORT CComboBox : public QComboBox {
Q_OBJECT
Q_PROPERTY(CornerPreference cornerPreference READ cornerPreference WRITE setCornerPreference)

public:
enum CornerPreference { Default = 0, DoNotRound = 1, Round = 2, RoundSmall = 3 };
Q_ENUM(CornerPreference)

explicit CComboBox(QWidget *parent = nullptr);
~CComboBox();

bool enableWheel() const;
void setEnableWheel(bool enableWheel);

static void setDefaultCornerPreference(CornerPreference preference);
static CornerPreference defaultCornerPreference();

void setCornerPreference(CornerPreference preference);
CornerPreference cornerPreference() const;

protected:
void wheelEvent(QWheelEvent *event) override;
void showPopup() override;

private:
bool m_enableWheel;
CornerPreference m_cornerPreference;
};

#endif // CCOMBOBOX_H
42 changes: 38 additions & 4 deletions src/widgets/widgets/cmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <QDebug>
#include <QFontMetrics>
#include <QStyleHints>

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
# include <QDesktopWidget>
Expand Down Expand Up @@ -483,11 +484,14 @@ void QMenuPrivate::ScrollerTearOffItem::updateScrollerRects(const QRect &rect) {
// CMenuImpl
// ======================================================================================

static CMenu::CornerPreference g_defaultCornerPreference = CMenu::RoundSmall;

class CMenuPrivate : public QObject {
public:
CMenu *q;
CMenu::CornerPreference cornerPreference;

CMenuPrivate(CMenu *q) : q(q) {
CMenuPrivate(CMenu *q) : q(q), cornerPreference(g_defaultCornerPreference) {
// Initialize Font
q->setFont(qApp->font());

Expand Down Expand Up @@ -532,9 +536,16 @@ class CMenuPrivate : public QObject {
// Constants defined to make older Windows SDK happy
constexpr int DWMWA_USE_IMMERSIVE_DARK_MODE_ = 20;
constexpr int DWMWA_WINDOW_CORNER_PREFERENCE_ = 33;
constexpr int DWMWA_BORDER_COLOR_ = 34;
constexpr COLORREF DWMWA_COLOR_DEFAULT_ = 0xFFFFFFFF;
constexpr COLORREF DWMWA_COLOR_NONE_ = 0xFFFFFFFE;
DWMNCRENDERINGPOLICY ncrp = DWMNCRP_ENABLED;
/*DWM_WINDOW_CORNER_PREFERENCE*/ INT dwcp = /*DWMWCP_ROUNDSMALL*/ 3;
UINT dark = 1;
INT dwcp = cornerPreference;
# if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
const UINT dark = QGuiApplication::styleHints()->colorScheme() != Qt::ColorScheme::Light;
# else
const UINT dark = 1;
# endif
MARGINS margins = {mgn, mgn, mgn, mgn};
Q_ASSERT(this->q->winId());
// Let DWM compose non-client area
Expand All @@ -552,8 +563,15 @@ class CMenuPrivate : public QObject {
// it doesn't look too off
DwmSetWindowAttribute(reinterpret_cast<HWND>(this->q->winId()),
DWMWA_WINDOW_CORNER_PREFERENCE_, &dwcp, sizeof(dwcp));
// Update the border color for the current scheme: suppress the DWM border in light
// mode, keep the default one in dark mode. Do NOT force a synchronous non-client
// refresh here (SWP_FRAMECHANGED + RDW_UPDATENOW): those synchronous cross-process
// calls can flood dwm.exe and freeze the compositor.
const COLORREF borderColor = dark ? DWMWA_COLOR_DEFAULT_ : DWMWA_COLOR_NONE_;
DwmSetWindowAttribute(reinterpret_cast<HWND>(this->q->winId()), DWMWA_BORDER_COLOR_,
&borderColor, sizeof(borderColor));
// Disconnect this connection, don't run again
disconnect(q, &CMenu::aboutToShow, this, &CMenuPrivate::_q_menuFirstAboutToShow);
// disconnect(q, &CMenu::aboutToShow, this, &CMenuPrivate::_q_menuFirstAboutToShow);
}
#endif
};
Expand All @@ -569,6 +587,22 @@ CMenu::~CMenu() {
delete d;
}

void CMenu::setDefaultCornerPreference(CornerPreference preference) {
g_defaultCornerPreference = preference;
}

CMenu::CornerPreference CMenu::defaultCornerPreference() {
return g_defaultCornerPreference;
}

void CMenu::setCornerPreference(CornerPreference preference) {
d->cornerPreference = preference;
}

CMenu::CornerPreference CMenu::cornerPreference() const {
return d->cornerPreference;
}

bool CMenu::event(QEvent *event) {
switch (event->type()) {
case QEvent::ActionAdded:
Expand Down
11 changes: 11 additions & 0 deletions src/widgets/widgets/cmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,22 @@ class CMenuPrivate;

class QM_WIDGETS_EXPORT CMenu : public QMenu {
Q_OBJECT
Q_PROPERTY(CornerPreference cornerPreference READ cornerPreference WRITE setCornerPreference)

public:
enum CornerPreference { Default = 0, DoNotRound = 1, Round = 2, RoundSmall = 3 };
Q_ENUM(CornerPreference)

explicit CMenu(QWidget *parent = nullptr);
explicit CMenu(const QString &title, QWidget *parent = nullptr);
~CMenu();

static void setDefaultCornerPreference(CornerPreference preference);
static CornerPreference defaultCornerPreference();

void setCornerPreference(CornerPreference preference);
CornerPreference cornerPreference() const;

protected:
bool event(QEvent *event) override;
void paintEvent(QPaintEvent *event) override;
Expand Down
Loading