Resolved the placeholder issue in the new ubtgadaptabletext implementation

preferencesAboutTextFull
shibakaneki 12 years ago
parent 47dd119c76
commit 1d06110b5e
  1. 4
      src/gui/UBTeacherGuideWidget.cpp
  2. 26
      src/gui/UBTeacherGuideWidgetsTools.cpp
  3. 3
      src/gui/UBTeacherGuideWidgetsTools.h

@ -1023,14 +1023,18 @@ void UBTeacherGuidePageZeroWidget::switchToMode(tUBTGZeroPageMode mode)
QString inputStyleSheet("QTextEdit { background: white; border-radius: 10px; border: 2px;}");
mpModePushButton->hide();
mpSessionTitle->setReadOnly(false);
mpSessionTitle->managePlaceholder(false);
mpSessionTitle->setStyleSheet(inputStyleSheet);
QFont titleFont(QApplication::font().family(), 11, -1);
mpSessionTitle->document()->setDefaultFont(titleFont);
mpAuthors->setReadOnly(false);
mpAuthors->managePlaceholder(false);
mpAuthors->setStyleSheet(inputStyleSheet);
mpObjectives->setReadOnly(false);
mpObjectives->managePlaceholder(false);
mpObjectives->setStyleSheet(inputStyleSheet);
mpKeywords->setReadOnly(false);
mpKeywords->managePlaceholder(false);
mpKeywords->setStyleSheet(inputStyleSheet);
mpSchoolLevelValueLabel->hide();
mpSchoolLevelBox->show();

@ -163,7 +163,7 @@ void UBTGAdaptableText::keyReleaseEvent(QKeyEvent* e)
void UBTGAdaptableText::showEvent(QShowEvent* e)
{
Q_UNUSED(e);
if(!mIsUpdatingSize && mHasPlaceHolder && toPlainText().isEmpty()){
if(!mIsUpdatingSize && mHasPlaceHolder && toPlainText().isEmpty() && !isReadOnly()){
setTextColor(QColor(Qt::lightGray));
setPlainText(mPlaceHolderText);
}
@ -204,8 +204,6 @@ void UBTGAdaptableText::onTextChanged()
setFocus();
}
mIsUpdatingSize = false;
}
void UBTGAdaptableText::setInitialText(const QString& text)
@ -232,22 +230,26 @@ void UBTGAdaptableText::focusInEvent(QFocusEvent* e){
if(isReadOnly()){
e->ignore();
}
managePlaceholder();
managePlaceholder(true);
QTextEdit::focusInEvent(e);
}
void UBTGAdaptableText::focusOutEvent(QFocusEvent* e){
if(toPlainText().isEmpty()){
setTextColor(QColor(Qt::lightGray));
setPlainText(mPlaceHolderText);
}
managePlaceholder(false);
QTextEdit::focusOutEvent(e);
}
void UBTGAdaptableText::managePlaceholder(){
if(toPlainText() == mPlaceHolderText){
setTextColor(QColor(Qt::black));
setPlainText("");
void UBTGAdaptableText::managePlaceholder(bool focus){
if(focus){
if(toPlainText() == mPlaceHolderText){
setTextColor(QColor(Qt::black));
setPlainText("");
}
}else{
if(toPlainText().isEmpty()){
setTextColor(QColor(Qt::lightGray));
setPlainText(mPlaceHolderText);
}
}
}

@ -100,6 +100,7 @@ public:
QString text();
void setInitialText(const QString& text);
void setMaximumLength(int length);
void managePlaceholder(bool focus);
public slots:
void onTextChanged();
@ -111,8 +112,6 @@ protected:
void focusOutEvent(QFocusEvent* e);
private:
void managePlaceholder();
int mBottomMargin;
QTreeWidgetItem* mpTreeWidgetItem;
int mMinimumHeight;

Loading…
Cancel
Save