mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 21:33:27 -07:00
Fix validation text doesn't update on mouse click selection
This commit is contained in:
parent
6ab35512da
commit
a9906e5d2a
2 changed files with 38 additions and 30 deletions
|
@ -162,6 +162,8 @@ Private::FileLineEdit::FileLineEdit(QWidget *parent)
|
||||||
|
|
||||||
m_completer->setModel(m_completerModel);
|
m_completer->setModel(m_completerModel);
|
||||||
setCompleter(m_completer);
|
setCompleter(m_completer);
|
||||||
|
|
||||||
|
connect(this, &QLineEdit::textChanged, this, &FileLineEdit::validateText);
|
||||||
}
|
}
|
||||||
|
|
||||||
Private::FileLineEdit::~FileLineEdit()
|
Private::FileLineEdit::~FileLineEdit()
|
||||||
|
@ -215,35 +217,6 @@ void Private::FileLineEdit::keyPressEvent(QKeyEvent *e)
|
||||||
m_completerModel->setRootPath(Path(text()).data());
|
m_completerModel->setRootPath(Path(text()).data());
|
||||||
showCompletionPopup();
|
showCompletionPopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto *validator = qobject_cast<const FileSystemPathValidator *>(this->validator());
|
|
||||||
if (validator)
|
|
||||||
{
|
|
||||||
const FileSystemPathValidator::TestResult lastTestResult = validator->lastTestResult();
|
|
||||||
const QValidator::State lastState = validator->lastValidationState();
|
|
||||||
if (lastTestResult == FileSystemPathValidator::TestResult::OK)
|
|
||||||
{
|
|
||||||
delete m_warningAction;
|
|
||||||
m_warningAction = nullptr;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!m_warningAction)
|
|
||||||
{
|
|
||||||
m_warningAction = new QAction(this);
|
|
||||||
addAction(m_warningAction, QLineEdit::TrailingPosition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_warningAction)
|
|
||||||
{
|
|
||||||
if (lastState == QValidator::Invalid)
|
|
||||||
m_warningAction->setIcon(style()->standardIcon(QStyle::SP_MessageBoxCritical));
|
|
||||||
else if (lastState == QValidator::Intermediate)
|
|
||||||
m_warningAction->setIcon(style()->standardIcon(QStyle::SP_MessageBoxInformation));
|
|
||||||
m_warningAction->setToolTip(warningText(lastTestResult));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Private::FileLineEdit::contextMenuEvent(QContextMenuEvent *event)
|
void Private::FileLineEdit::contextMenuEvent(QContextMenuEvent *event)
|
||||||
|
@ -266,6 +239,39 @@ void Private::FileLineEdit::showCompletionPopup()
|
||||||
m_completer->complete();
|
m_completer->complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Private::FileLineEdit::validateText()
|
||||||
|
{
|
||||||
|
const auto *validator = qobject_cast<const FileSystemPathValidator *>(this->validator());
|
||||||
|
if (!validator)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const FileSystemPathValidator::TestResult lastTestResult = validator->lastTestResult();
|
||||||
|
const QValidator::State lastState = validator->lastValidationState();
|
||||||
|
|
||||||
|
if (lastTestResult == FileSystemPathValidator::TestResult::OK)
|
||||||
|
{
|
||||||
|
delete m_warningAction;
|
||||||
|
m_warningAction = nullptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!m_warningAction)
|
||||||
|
{
|
||||||
|
m_warningAction = new QAction(this);
|
||||||
|
addAction(m_warningAction, QLineEdit::TrailingPosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_warningAction)
|
||||||
|
{
|
||||||
|
if (lastState == QValidator::Invalid)
|
||||||
|
m_warningAction->setIcon(style()->standardIcon(QStyle::SP_MessageBoxCritical));
|
||||||
|
else if (lastState == QValidator::Intermediate)
|
||||||
|
m_warningAction->setIcon(style()->standardIcon(QStyle::SP_MessageBoxInformation));
|
||||||
|
m_warningAction->setToolTip(warningText(lastTestResult));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString Private::FileLineEdit::warningText(const FileSystemPathValidator::TestResult result)
|
QString Private::FileLineEdit::warningText(const FileSystemPathValidator::TestResult result)
|
||||||
{
|
{
|
||||||
using TestResult = FileSystemPathValidator::TestResult;
|
using TestResult = FileSystemPathValidator::TestResult;
|
||||||
|
|
|
@ -130,8 +130,10 @@ namespace Private
|
||||||
void contextMenuEvent(QContextMenuEvent *event) override;
|
void contextMenuEvent(QContextMenuEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QString warningText(FileSystemPathValidator::TestResult result);
|
|
||||||
void showCompletionPopup();
|
void showCompletionPopup();
|
||||||
|
void validateText();
|
||||||
|
|
||||||
|
static QString warningText(FileSystemPathValidator::TestResult result);
|
||||||
|
|
||||||
QFileSystemModel *m_completerModel = nullptr;
|
QFileSystemModel *m_completerModel = nullptr;
|
||||||
QCompleter *m_completer = nullptr;
|
QCompleter *m_completer = nullptr;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue