mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-12 12:18:35 -05:00
Add max length validation support for TextEdit
This commit is contained in:
committed by
WarmUpTill
parent
de8da553f1
commit
e13e4b5ddd
@@ -830,6 +830,8 @@ AdvSceneSwitcher.item.nameReserved="Name reserved!"
|
||||
|
||||
AdvSceneSwitcher.macroSegmentSelection.invalid="Invalid selection!"
|
||||
|
||||
AdvSceneSwitcher.validation.text.maxLength="Only %1 characters are allowed in this field!"
|
||||
|
||||
AdvSceneSwitcher.variable.select="--select variable--"
|
||||
AdvSceneSwitcher.variable.add="Add new variable"
|
||||
AdvSceneSwitcher.variable.configure="Configure variable settings"
|
||||
|
||||
@@ -352,6 +352,7 @@ MacroActionTwitchEdit::MacroActionTwitchEdit(
|
||||
_markerDescription->setMaxLength(140);
|
||||
_announcementMessage->setSizePolicy(QSizePolicy::MinimumExpanding,
|
||||
QSizePolicy::Preferred);
|
||||
_announcementMessage->setMaxLength(500);
|
||||
|
||||
auto spinBox = _duration->SpinBox();
|
||||
spinBox->setSuffix("s");
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "resizing-text-edit.hpp"
|
||||
|
||||
#include <obs-module.h>
|
||||
#include <utility.hpp>
|
||||
|
||||
namespace advss {
|
||||
|
||||
ResizingPlainTextEdit::ResizingPlainTextEdit(QWidget *parent,
|
||||
@@ -13,6 +16,18 @@ ResizingPlainTextEdit::ResizingPlainTextEdit(QWidget *parent,
|
||||
{
|
||||
QWidget::connect(this, SIGNAL(textChanged()), this,
|
||||
SLOT(ResizeTexteditArea()));
|
||||
QWidget::connect(this, SIGNAL(textChanged()), this,
|
||||
SLOT(PreventExceedingMaxLength()));
|
||||
}
|
||||
|
||||
int ResizingPlainTextEdit::maxLength()
|
||||
{
|
||||
return _maxLength;
|
||||
}
|
||||
|
||||
void ResizingPlainTextEdit::setMaxLength(int maxLength)
|
||||
{
|
||||
_maxLength = maxLength;
|
||||
}
|
||||
|
||||
void ResizingPlainTextEdit::ResizeTexteditArea()
|
||||
@@ -32,4 +47,19 @@ void ResizingPlainTextEdit::ResizeTexteditArea()
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
void ResizingPlainTextEdit::PreventExceedingMaxLength()
|
||||
{
|
||||
auto plainText = QPlainTextEdit::toPlainText();
|
||||
|
||||
if (_maxLength > -1 && plainText.length() > _maxLength) {
|
||||
QPlainTextEdit::setPlainText(plainText.left(_maxLength));
|
||||
QPlainTextEdit::moveCursor(QTextCursor::End);
|
||||
|
||||
DisplayMessage(
|
||||
QString(obs_module_text(
|
||||
"AdvSceneSwitcher.validation.text.maxLength"))
|
||||
.arg(QString::number(_maxLength)));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
|
||||
@@ -10,13 +10,18 @@ public:
|
||||
const int minLines = 3,
|
||||
const int paddingLines = 2);
|
||||
virtual ~ResizingPlainTextEdit(){};
|
||||
int maxLength();
|
||||
void setMaxLength(int maxLength);
|
||||
|
||||
private slots:
|
||||
void ResizeTexteditArea();
|
||||
void PreventExceedingMaxLength();
|
||||
|
||||
private:
|
||||
const int _scrollAt;
|
||||
const int _minLines;
|
||||
const int _paddingLines;
|
||||
int _maxLength = -1;
|
||||
};
|
||||
|
||||
} // namespace advss
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "variable-line-edit.hpp"
|
||||
|
||||
#include <obs-module.h>
|
||||
#include <utility.hpp>
|
||||
|
||||
namespace advss {
|
||||
|
||||
@@ -8,6 +9,9 @@ VariableLineEdit::VariableLineEdit(QWidget *parent) : QLineEdit(parent)
|
||||
{
|
||||
QLineEdit::setToolTip(
|
||||
obs_module_text("AdvSceneSwitcher.tooltip.availableVariables"));
|
||||
|
||||
QWidget::connect(this, SIGNAL(inputRejected()), this,
|
||||
SLOT(DisplayValidationMessages()));
|
||||
}
|
||||
|
||||
void VariableLineEdit::setText(const QString &string)
|
||||
@@ -27,4 +31,16 @@ void VariableLineEdit::setToolTip(const QString &string)
|
||||
obs_module_text("AdvSceneSwitcher.tooltip.availableVariables"));
|
||||
}
|
||||
|
||||
void VariableLineEdit::DisplayValidationMessages()
|
||||
{
|
||||
int maxLength = QLineEdit::maxLength();
|
||||
|
||||
if (QLineEdit::text().length() == maxLength) {
|
||||
DisplayMessage(
|
||||
QString(obs_module_text(
|
||||
"AdvSceneSwitcher.validation.text.maxLength"))
|
||||
.arg(QString::number(maxLength)));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace advss
|
||||
|
||||
@@ -13,6 +13,9 @@ public:
|
||||
void setText(const StringVariable &);
|
||||
void setToolTip(const QString &string);
|
||||
|
||||
private slots:
|
||||
void DisplayValidationMessages();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user