Commit a726171f authored by Claudio Valerio's avatar Claudio Valerio

add the possibility to set maximum number of character

parent 9d0dcde2
......@@ -697,6 +697,7 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons
mpSessionTitle = new UBTGAdaptableText(0, this, "UBTGSessionTitle");
mpSessionTitle->setPlaceHolderText(tr("Type session title here ..."));
mpSessionTitle->setMaximumLength(1000);
mpButtonTitleLayout->addWidget(mpSessionTitle);
connect(this, SIGNAL(resized()), mpSessionTitle, SLOT(onTextChanged()));
......
......@@ -120,6 +120,7 @@ UBTGAdaptableText::UBTGAdaptableText(QTreeWidgetItem* widget, QWidget* parent, c
, mMinimumHeight(0)
, mHasPlaceHolder(false)
, mIsUpdatingSize(false)
, mMaximumLength(0)
{
setObjectName(name);
connect(this,SIGNAL(textChanged()),this,SLOT(onTextChanged()));
......@@ -131,6 +132,11 @@ UBTGAdaptableText::UBTGAdaptableText(QTreeWidgetItem* widget, QWidget* parent, c
}
void UBTGAdaptableText::setMaximumLength(int length)
{
mMaximumLength = length;
}
void UBTGAdaptableText::setPlaceHolderText(QString text)
{
mHasPlaceHolder = true;
......@@ -166,6 +172,12 @@ void UBTGAdaptableText::keyReleaseEvent(QKeyEvent* e)
setTextColor(QColor(Qt::lightGray));
setPlainText(mPlaceHolderText);
}
if(mMaximumLength && toPlainText().length()>mMaximumLength){
setPlainText(toPlainText().left(mMaximumLength));
QTextCursor tc(document());
tc.setPosition(mMaximumLength);
setTextCursor(tc);
}
}
void UBTGAdaptableText::showEvent(QShowEvent* e)
......@@ -212,8 +224,10 @@ void UBTGAdaptableText::onTextChanged()
setFocus();
}
mIsUpdatingSize = false;
}
void UBTGAdaptableText::setInitialText(const QString& text)
{
setText(text);
......
......@@ -97,6 +97,7 @@ public:
void setPlaceHolderText(QString text);
QString text();
void setInitialText(const QString& text);
void setMaximumLength(int length);
public slots:
void onTextChanged();
......@@ -113,6 +114,7 @@ private:
bool mHasPlaceHolder;
QString mPlaceHolderText;
bool mIsUpdatingSize;
int mMaximumLength;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment