refactor: LineEditValidator, adjust border style based on the Qt Style in use

This commit is contained in:
sithlord48 2025-12-23 23:42:56 -05:00 committed by Nick Bolton
parent 2b8e7fa6b2
commit b8b7799a47
2 changed files with 26 additions and 6 deletions

View file

@ -12,9 +12,6 @@ namespace deskflow::gui {
const auto kColorError = "#ec4c47";
const auto kStyleLineEditErrorBorder =
QStringLiteral("border: 1px solid %1; border-radius: 2px; padding: 2px;").arg(kColorError);
const auto kStyleErrorActiveLabel = //
QStringLiteral(
"padding: 3px 5px; border-radius: 3px; "

View file

@ -1,5 +1,6 @@
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
* SPDX-FileCopyrightText: (C) 2021 Symless Ltd.
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
*/
@ -8,6 +9,8 @@
#include "gui/Styles.h"
#include <QApplication>
#include <QStyle>
#include <QValidator>
using namespace deskflow::gui;
@ -42,9 +45,29 @@ QValidator::State LineEditValidator::validate(QString &input, int &) const
}
if (errorMessage.isEmpty()) {
m_pLineEdit->setStyleSheet("");
} else {
m_pLineEdit->setStyleSheet(kStyleLineEditErrorBorder);
m_pLineEdit->setStyleSheet({});
} else { // The values here are for fusion style
int radius = 3;
int padVer = 2;
int padHor = 0;
int borderWidth = 1;
if (const auto wStyle = QApplication::style()->name().toLower(); wStyle == QStringLiteral("breeze")) {
radius = 6;
padVer = 5;
padHor = 5;
} else if (wStyle == QStringLiteral("macos")) {
radius = 4;
padVer = 1;
borderWidth = 3;
} else if (wStyle == QStringLiteral("windows")) {
padVer = 1;
padHor = 1;
}
m_pLineEdit->setStyleSheet(QStringLiteral("border-radius: %1px; padding: %2px %3px; border: %4px solid %5;")
.arg(
QString::number(radius), QString::number(padVer), QString::number(padHor),
QString::number(borderWidth), kColorError
));
}
if (m_pError) {