add the possibility to set maximum number of character

preferencesAboutTextFull
Claudio Valerio 12 years ago
parent 9d0dcde212
commit a726171f1b
  1. 1
      src/gui/UBTeacherGuideWidget.cpp
  2. 14
      src/gui/UBTeacherGuideWidgetsTools.cpp
  3. 2
      src/gui/UBTeacherGuideWidgetsTools.h

@ -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)
@ -213,7 +225,9 @@ void UBTGAdaptableText::onTextChanged()
}
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;
};

Loading…
Cancel
Save