From 1d06110b5ef99dd7b136cc12d52ac3b6b22e2837 Mon Sep 17 00:00:00 2001 From: shibakaneki Date: Mon, 10 Sep 2012 12:07:33 +0200 Subject: [PATCH] Resolved the placeholder issue in the new ubtgadaptabletext implementation --- src/gui/UBTeacherGuideWidget.cpp | 4 ++++ src/gui/UBTeacherGuideWidgetsTools.cpp | 26 ++++++++++++++------------ src/gui/UBTeacherGuideWidgetsTools.h | 3 +-- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/gui/UBTeacherGuideWidget.cpp b/src/gui/UBTeacherGuideWidget.cpp index 679da6a8..cfa76117 100644 --- a/src/gui/UBTeacherGuideWidget.cpp +++ b/src/gui/UBTeacherGuideWidget.cpp @@ -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(); diff --git a/src/gui/UBTeacherGuideWidgetsTools.cpp b/src/gui/UBTeacherGuideWidgetsTools.cpp index b71bf82f..7ecfbd27 100644 --- a/src/gui/UBTeacherGuideWidgetsTools.cpp +++ b/src/gui/UBTeacherGuideWidgetsTools.cpp @@ -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); + } } } diff --git a/src/gui/UBTeacherGuideWidgetsTools.h b/src/gui/UBTeacherGuideWidgetsTools.h index 364f3d99..933bdd30 100644 --- a/src/gui/UBTeacherGuideWidgetsTools.h +++ b/src/gui/UBTeacherGuideWidgetsTools.h @@ -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;