Get rid of latin-1 strings

Use UTF-8 strings everywhere.

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2020-12-22 20:46:39 +08:00
parent 996160256e
commit 7522273331
4 changed files with 41 additions and 67 deletions

View File

@ -83,16 +83,16 @@ bool Widget::isNormal() const
void Widget::setupUi() void Widget::setupUi()
{ {
contentsWidget = new ContentsWidget(this); contentsWidget = new ContentsWidget(this);
contentsWidget->setObjectName(QLatin1String("contentsWidget")); contentsWidget->setObjectName(QString::fromUtf8("contentsWidget"));
contentsWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); contentsWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
const QSize systemButtonSize = {qRound(titleBarHeight * 1.5), titleBarHeight}; const QSize systemButtonSize = {qRound(titleBarHeight * 1.5), titleBarHeight};
const QSize systemIconSize = {17, 17}; const QSize systemIconSize = {17, 17};
titleBarWidget = new QWidget(contentsWidget); titleBarWidget = new QWidget(contentsWidget);
titleBarWidget->setObjectName(QLatin1String("titleBarWidget")); titleBarWidget->setObjectName(QString::fromUtf8("titleBarWidget"));
titleBarWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); titleBarWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
titleBarWidget->setFixedHeight(titleBarHeight); titleBarWidget->setFixedHeight(titleBarHeight);
windowIconButton = new QPushButton(this); windowIconButton = new QPushButton(this);
windowIconButton->setObjectName(QLatin1String("windowIconButton")); windowIconButton->setObjectName(QString::fromUtf8("windowIconButton"));
windowIconButton->setFixedSize(systemIconSize); windowIconButton->setFixedSize(systemIconSize);
windowIconButton->setIconSize(systemIconSize); windowIconButton->setIconSize(systemIconSize);
connect(this, &Widget::windowIconChanged, windowIconButton, &QPushButton::setIcon); connect(this, &Widget::windowIconChanged, windowIconButton, &QPushButton::setIcon);
@ -102,16 +102,16 @@ void Widget::setupUi()
windowTitleLabel->setFont(f); windowTitleLabel->setFont(f);
connect(this, &Widget::windowTitleChanged, windowTitleLabel, &QLabel::setText); connect(this, &Widget::windowTitleChanged, windowTitleLabel, &QLabel::setText);
minimizeButton = new QPushButton(this); minimizeButton = new QPushButton(this);
minimizeButton->setObjectName(QLatin1String("minimizeButton")); minimizeButton->setObjectName(QString::fromUtf8("minimizeButton"));
minimizeButton->setFixedSize(systemButtonSize); minimizeButton->setFixedSize(systemButtonSize);
minimizeButton->setIconSize(systemButtonSize); minimizeButton->setIconSize(systemButtonSize);
minimizeButton->setIcon(QIcon(QLatin1String(":/images/button_minimize_black.svg"))); minimizeButton->setIcon(QIcon(QString::fromUtf8(":/images/button_minimize_black.svg")));
connect(minimizeButton, &QPushButton::clicked, this, &Widget::showMinimized); connect(minimizeButton, &QPushButton::clicked, this, &Widget::showMinimized);
maximizeButton = new QPushButton(this); maximizeButton = new QPushButton(this);
maximizeButton->setObjectName(QLatin1String("maximizeButton")); maximizeButton->setObjectName(QString::fromUtf8("maximizeButton"));
maximizeButton->setFixedSize(systemButtonSize); maximizeButton->setFixedSize(systemButtonSize);
maximizeButton->setIconSize(systemButtonSize); maximizeButton->setIconSize(systemButtonSize);
maximizeButton->setIcon(QIcon(QLatin1String(":/images/button_maximize_black.svg"))); maximizeButton->setIcon(QIcon(QString::fromUtf8(":/images/button_maximize_black.svg")));
connect(maximizeButton, &QPushButton::clicked, this, [this]() { connect(maximizeButton, &QPushButton::clicked, this, [this]() {
if (isMaximized()) { if (isMaximized()) {
showNormal(); showNormal();
@ -120,10 +120,10 @@ void Widget::setupUi()
} }
}); });
closeButton = new QPushButton(this); closeButton = new QPushButton(this);
closeButton->setObjectName(QLatin1String("closeButton")); closeButton->setObjectName(QString::fromUtf8("closeButton"));
closeButton->setFixedSize(systemButtonSize); closeButton->setFixedSize(systemButtonSize);
closeButton->setIconSize(systemButtonSize); closeButton->setIconSize(systemButtonSize);
closeButton->setIcon(QIcon(QLatin1String(":/images/button_close_black.svg"))); closeButton->setIcon(QIcon(QString::fromUtf8(":/images/button_close_black.svg")));
connect(closeButton, &QPushButton::clicked, this, &Widget::close); connect(closeButton, &QPushButton::clicked, this, &Widget::close);
const auto titleBarWidgetLayout = new QHBoxLayout(titleBarWidget); const auto titleBarWidgetLayout = new QHBoxLayout(titleBarWidget);
titleBarWidgetLayout->setSpacing(0); titleBarWidgetLayout->setSpacing(0);
@ -149,7 +149,7 @@ void Widget::setupUi()
backgroundWindowLayout->setSpacing(0); backgroundWindowLayout->setSpacing(0);
backgroundWindowLayout->addWidget(contentsWidget); backgroundWindowLayout->addWidget(contentsWidget);
setLayout(backgroundWindowLayout); setLayout(backgroundWindowLayout);
setStyleSheet(QLatin1String(R"( setStyleSheet(QString::fromUtf8(R"(
#contentsWidget { #contentsWidget {
background-color: #f0f0f0; background-color: #f0f0f0;
} }
@ -236,9 +236,8 @@ bool Widget::eventFilter(QObject *object, QEvent *event)
setFrameShadowEnabled(normal); setFrameShadowEnabled(normal);
framelessHelper()->setTitleBarHeight( framelessHelper()->setTitleBarHeight(
titleBarHeight + (normal ? framelessHelper()->getBorderHeight() : 0)); titleBarHeight + (normal ? framelessHelper()->getBorderHeight() : 0));
const QLatin1String maxIconPath = QLatin1String{":/images/button_maximize_black.svg"}; const QString maxIconPath = QString::fromUtf8(":/images/button_maximize_black.svg");
const QLatin1String restoreIconPath = QLatin1String{ const QString restoreIconPath = QString::fromUtf8(":/images/button_restore_black.svg");
":/images/button_restore_black.svg"};
maximizeButton->setIcon(QIcon(normal ? maxIconPath : restoreIconPath)); maximizeButton->setIcon(QIcon(normal ? maxIconPath : restoreIconPath));
} break; } break;
case QEvent::WindowActivate: { case QEvent::WindowActivate: {

View File

@ -52,7 +52,7 @@ int main(int argc, char *argv[])
QApplication application(argc, argv); QApplication application(argc, argv);
QApplication::setFont({QLatin1String("Microsoft YaHei")}); QApplication::setFont({QString::fromUtf8("Microsoft YaHei")});
Widget widget; Widget widget;

View File

@ -68,7 +68,7 @@ const char g_sUseNativeTitleBar[] = "WNEF_USE_NATIVE_TITLE_BAR";
const char g_sPreserveWindowFrame[] = "WNEF_FORCE_PRESERVE_WINDOW_FRAME"; const char g_sPreserveWindowFrame[] = "WNEF_FORCE_PRESERVE_WINDOW_FRAME";
const char g_sForceUseAcrylicEffect[] = "WNEF_FORCE_ACRYLIC_ON_WIN10"; const char g_sForceUseAcrylicEffect[] = "WNEF_FORCE_ACRYLIC_ON_WIN10";
const QLatin1String g_sSystemButtonsStyleSheet(R"( const QString g_sSystemButtonsStyleSheet = QString::fromUtf8(R"(
#iconButton, #minimizeButton, #maximizeButton, #closeButton { #iconButton, #minimizeButton, #maximizeButton, #closeButton {
border-style: none; border-style: none;
background-color: transparent; background-color: transparent;
@ -90,54 +90,28 @@ const QLatin1String g_sSystemButtonsStyleSheet(R"(
background-color: #8c0a15; background-color: #8c0a15;
} }
)"); )");
const
#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0)) const QString g_sTitleLabelStyleSheet = QString::fromUtf8(R"(
QString
#else
QLatin1String
#endif
g_sTitleLabelStyleSheet(
#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
QString::fromLatin1(
#endif
R"(
#titleLabel { #titleLabel {
color: rgb(%1, %2, %3); color: rgb(%1, %2, %3);
} }
)" )");
#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
) const QString g_sTitleBarStyleSheet = QString::fromUtf8(R"(
#endif
);
const
#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
QString
#else
QLatin1String
#endif
g_sTitleBarStyleSheet(
#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
QString::fromLatin1(
#endif
R"(
#titleBarWidget { #titleBarWidget {
background-color: rgba(%1, %2, %3, %4); background-color: rgba(%1, %2, %3, %4);
border-top: 1px solid rgba(%5, %6, %7, %8); border-top: 1px solid rgba(%5, %6, %7, %8);
} }
)" )");
#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
)
#endif
);
const QLatin1String g_sMinimizeButtonImageDark(":/images/button_minimize_black.svg"); const QString g_sMinimizeButtonImageDark = QString::fromUtf8(":/images/button_minimize_black.svg");
const QLatin1String g_sMaximizeButtonImageDark(":/images/button_maximize_black.svg"); const QString g_sMaximizeButtonImageDark = QString::fromUtf8(":/images/button_maximize_black.svg");
const QLatin1String g_sRestoreButtonImageDark(":/images/button_restore_black.svg"); const QString g_sRestoreButtonImageDark = QString::fromUtf8(":/images/button_restore_black.svg");
const QLatin1String g_sCloseButtonImageDark(":/images/button_close_black.svg"); const QString g_sCloseButtonImageDark = QString::fromUtf8(":/images/button_close_black.svg");
const QLatin1String g_sMinimizeButtonImageLight(":/images/button_minimize_white.svg"); const QString g_sMinimizeButtonImageLight = QString::fromUtf8(":/images/button_minimize_white.svg");
const QLatin1String g_sMaximizeButtonImageLight(":/images/button_maximize_white.svg"); const QString g_sMaximizeButtonImageLight = QString::fromUtf8(":/images/button_maximize_white.svg");
const QLatin1String g_sRestoreButtonImageLight(":/images/button_restore_white.svg"); const QString g_sRestoreButtonImageLight = QString::fromUtf8(":/images/button_restore_white.svg");
const QLatin1String g_sCloseButtonImageLight(":/images/button_close_white.svg"); const QString g_sCloseButtonImageLight = QString::fromUtf8(":/images/button_close_white.svg");
void updateQtFrame(const QWindow *window, const int tbh) void updateQtFrame(const QWindow *window, const int tbh)
{ {
@ -201,7 +175,7 @@ void Widget::setupUi()
resize(1056, 600); resize(1056, 600);
verticalLayout_3 = new QVBoxLayout(this); verticalLayout_3 = new QVBoxLayout(this);
titleBarWidget = new QWidget(this); titleBarWidget = new QWidget(this);
titleBarWidget->setObjectName(QLatin1String("titleBarWidget")); titleBarWidget->setObjectName(QString::fromUtf8("titleBarWidget"));
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
sizePolicy.setHorizontalStretch(0); sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0); sizePolicy.setVerticalStretch(0);
@ -219,12 +193,12 @@ void Widget::setupUi()
horizontalSpacer_7 = new QSpacerItem(3, 20, QSizePolicy::Fixed, QSizePolicy::Minimum); horizontalSpacer_7 = new QSpacerItem(3, 20, QSizePolicy::Fixed, QSizePolicy::Minimum);
horizontalLayout->addSpacerItem(horizontalSpacer_7); horizontalLayout->addSpacerItem(horizontalSpacer_7);
iconButton = new QPushButton(titleBarWidget); iconButton = new QPushButton(titleBarWidget);
iconButton->setObjectName(QLatin1String("iconButton")); iconButton->setObjectName(QString::fromUtf8("iconButton"));
horizontalLayout->addWidget(iconButton); horizontalLayout->addWidget(iconButton);
horizontalSpacer = new QSpacerItem(3, 20, QSizePolicy::Fixed, QSizePolicy::Minimum); horizontalSpacer = new QSpacerItem(3, 20, QSizePolicy::Fixed, QSizePolicy::Minimum);
horizontalLayout->addSpacerItem(horizontalSpacer); horizontalLayout->addSpacerItem(horizontalSpacer);
titleLabel = new QLabel(titleBarWidget); titleLabel = new QLabel(titleBarWidget);
titleLabel->setObjectName(QLatin1String("titleLabel")); titleLabel->setObjectName(QString::fromUtf8("titleLabel"));
QFont font; QFont font;
font.setPointSize(10); font.setPointSize(10);
titleLabel->setFont(font); titleLabel->setFont(font);
@ -232,7 +206,7 @@ void Widget::setupUi()
horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout->addSpacerItem(horizontalSpacer_2); horizontalLayout->addSpacerItem(horizontalSpacer_2);
minimizeButton = new QPushButton(titleBarWidget); minimizeButton = new QPushButton(titleBarWidget);
minimizeButton->setObjectName(QLatin1String("minimizeButton")); minimizeButton->setObjectName(QString::fromUtf8("minimizeButton"));
QSizePolicy sizePolicy1(QSizePolicy::Fixed, QSizePolicy::Fixed); QSizePolicy sizePolicy1(QSizePolicy::Fixed, QSizePolicy::Fixed);
sizePolicy1.setHorizontalStretch(0); sizePolicy1.setHorizontalStretch(0);
sizePolicy1.setVerticalStretch(0); sizePolicy1.setVerticalStretch(0);
@ -247,7 +221,7 @@ void Widget::setupUi()
minimizeButton->setIconSize(systemButtonSize); minimizeButton->setIconSize(systemButtonSize);
horizontalLayout->addWidget(minimizeButton); horizontalLayout->addWidget(minimizeButton);
maximizeButton = new QPushButton(titleBarWidget); maximizeButton = new QPushButton(titleBarWidget);
maximizeButton->setObjectName(QLatin1String("maximizeButton")); maximizeButton->setObjectName(QString::fromUtf8("maximizeButton"));
sizePolicy1.setHeightForWidth(maximizeButton->sizePolicy().hasHeightForWidth()); sizePolicy1.setHeightForWidth(maximizeButton->sizePolicy().hasHeightForWidth());
maximizeButton->setSizePolicy(sizePolicy1); maximizeButton->setSizePolicy(sizePolicy1);
maximizeButton->setMinimumSize(systemButtonSize); maximizeButton->setMinimumSize(systemButtonSize);
@ -258,7 +232,7 @@ void Widget::setupUi()
maximizeButton->setIconSize(systemButtonSize); maximizeButton->setIconSize(systemButtonSize);
horizontalLayout->addWidget(maximizeButton); horizontalLayout->addWidget(maximizeButton);
closeButton = new QPushButton(titleBarWidget); closeButton = new QPushButton(titleBarWidget);
closeButton->setObjectName(QLatin1String("closeButton")); closeButton->setObjectName(QString::fromUtf8("closeButton"));
sizePolicy1.setHeightForWidth(closeButton->sizePolicy().hasHeightForWidth()); sizePolicy1.setHeightForWidth(closeButton->sizePolicy().hasHeightForWidth());
closeButton->setSizePolicy(sizePolicy1); closeButton->setSizePolicy(sizePolicy1);
closeButton->setMinimumSize(systemButtonSize); closeButton->setMinimumSize(systemButtonSize);

View File

@ -650,7 +650,7 @@ using WNEF_CORE_DATA = struct _WNEF_CORE_DATA
WNEF_RESOLVE_WINAPI(User32, SetWindowLongPtrW) WNEF_RESOLVE_WINAPI(User32, SetWindowLongPtrW)
WNEF_RESOLVE_WINAPI(User32, GetClassLongPtrW) WNEF_RESOLVE_WINAPI(User32, GetClassLongPtrW)
WNEF_RESOLVE_WINAPI(User32, SetClassLongPtrW) WNEF_RESOLVE_WINAPI(User32, SetClassLongPtrW)
#else // Q_PROCESSOR_X86_64 #else // Q_PROCESSOR_X86_64
WNEF_RESOLVE_WINAPI(User32, GetWindowLongW) WNEF_RESOLVE_WINAPI(User32, GetWindowLongW)
WNEF_RESOLVE_WINAPI(User32, SetWindowLongW) WNEF_RESOLVE_WINAPI(User32, SetWindowLongW)
WNEF_RESOLVE_WINAPI(User32, GetClassLongW) WNEF_RESOLVE_WINAPI(User32, GetClassLongW)
@ -797,8 +797,9 @@ const int m_defaultBorderWidth = 8, m_defaultBorderHeight = 8, m_defaultTitleBar
const int kAutoHideTaskbarThicknessPx = 2; const int kAutoHideTaskbarThicknessPx = 2;
const int kAutoHideTaskbarThicknessPy = kAutoHideTaskbarThicknessPx; const int kAutoHideTaskbarThicknessPy = kAutoHideTaskbarThicknessPx;
const QLatin1String g_sDwmRegistryKey(R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM)"); const QString g_sDwmRegistryKey = QString::fromUtf8(
const QLatin1String g_sPersonalizeRegistryKey( R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM)");
const QString g_sPersonalizeRegistryKey = QString::fromUtf8(
R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)"); R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)");
const char m_framelessMode[] = "_WNEF_FRAMELESS_MODE_ENABLED"; const char m_framelessMode[] = "_WNEF_FRAMELESS_MODE_ENABLED";
@ -1616,8 +1617,8 @@ bool WinNativeEventFilter::isColorizationEnabled()
} }
bool ok = false; bool ok = false;
const QSettings registry(g_sDwmRegistryKey, QSettings::NativeFormat); const QSettings registry(g_sDwmRegistryKey, QSettings::NativeFormat);
const bool colorPrevalence = registry.value(QLatin1String("ColorPrevalence"), 0).toULongLong(&ok) const bool colorPrevalence
!= 0; = registry.value(QString::fromUtf8("ColorPrevalence"), 0).toULongLong(&ok) != 0;
return (ok && colorPrevalence); return (ok && colorPrevalence);
} }
@ -1686,6 +1687,6 @@ bool WinNativeEventFilter::isTransparencyEffectEnabled()
bool ok = false; bool ok = false;
const QSettings registry(g_sPersonalizeRegistryKey, QSettings::NativeFormat); const QSettings registry(g_sPersonalizeRegistryKey, QSettings::NativeFormat);
const bool enableTransparency const bool enableTransparency
= registry.value(QLatin1String("EnableTransparency"), 0).toULongLong(&ok) != 0; = registry.value(QString::fromUtf8("EnableTransparency"), 0).toULongLong(&ok) != 0;
return (ok && enableTransparency); return (ok && enableTransparency);
} }