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 = new UBTGAdaptableText(0, this, "UBTGSessionTitle");
mpSessionTitle->setPlaceHolderText(tr("Type session title here ...")); mpSessionTitle->setPlaceHolderText(tr("Type session title here ..."));
mpSessionTitle->setMaximumLength(1000);
mpButtonTitleLayout->addWidget(mpSessionTitle); mpButtonTitleLayout->addWidget(mpSessionTitle);
connect(this, SIGNAL(resized()), mpSessionTitle, SLOT(onTextChanged())); connect(this, SIGNAL(resized()), mpSessionTitle, SLOT(onTextChanged()));

@ -120,6 +120,7 @@ UBTGAdaptableText::UBTGAdaptableText(QTreeWidgetItem* widget, QWidget* parent, c
, mMinimumHeight(0) , mMinimumHeight(0)
, mHasPlaceHolder(false) , mHasPlaceHolder(false)
, mIsUpdatingSize(false) , mIsUpdatingSize(false)
, mMaximumLength(0)
{ {
setObjectName(name); setObjectName(name);
connect(this,SIGNAL(textChanged()),this,SLOT(onTextChanged())); 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) void UBTGAdaptableText::setPlaceHolderText(QString text)
{ {
mHasPlaceHolder = true; mHasPlaceHolder = true;
@ -166,6 +172,12 @@ void UBTGAdaptableText::keyReleaseEvent(QKeyEvent* e)
setTextColor(QColor(Qt::lightGray)); setTextColor(QColor(Qt::lightGray));
setPlainText(mPlaceHolderText); setPlainText(mPlaceHolderText);
} }
if(mMaximumLength && toPlainText().length()>mMaximumLength){
setPlainText(toPlainText().left(mMaximumLength));
QTextCursor tc(document());
tc.setPosition(mMaximumLength);
setTextCursor(tc);
}
} }
void UBTGAdaptableText::showEvent(QShowEvent* e) void UBTGAdaptableText::showEvent(QShowEvent* e)
@ -212,8 +224,10 @@ void UBTGAdaptableText::onTextChanged()
setFocus(); setFocus();
} }
mIsUpdatingSize = false; mIsUpdatingSize = false;
} }
void UBTGAdaptableText::setInitialText(const QString& text) void UBTGAdaptableText::setInitialText(const QString& text)
{ {
setText(text); setText(text);

@ -97,6 +97,7 @@ public:
void setPlaceHolderText(QString text); void setPlaceHolderText(QString text);
QString text(); QString text();
void setInitialText(const QString& text); void setInitialText(const QString& text);
void setMaximumLength(int length);
public slots: public slots:
void onTextChanged(); void onTextChanged();
@ -113,6 +114,7 @@ private:
bool mHasPlaceHolder; bool mHasPlaceHolder;
QString mPlaceHolderText; QString mPlaceHolderText;
bool mIsUpdatingSize; bool mIsUpdatingSize;
int mMaximumLength;
}; };

Loading…
Cancel
Save