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. 20
      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;}"); QString inputStyleSheet("QTextEdit { background: white; border-radius: 10px; border: 2px;}");
mpModePushButton->hide(); mpModePushButton->hide();
mpSessionTitle->setReadOnly(false); mpSessionTitle->setReadOnly(false);
mpSessionTitle->managePlaceholder(false);
mpSessionTitle->setStyleSheet(inputStyleSheet); mpSessionTitle->setStyleSheet(inputStyleSheet);
QFont titleFont(QApplication::font().family(), 11, -1); QFont titleFont(QApplication::font().family(), 11, -1);
mpSessionTitle->document()->setDefaultFont(titleFont); mpSessionTitle->document()->setDefaultFont(titleFont);
mpAuthors->setReadOnly(false); mpAuthors->setReadOnly(false);
mpAuthors->managePlaceholder(false);
mpAuthors->setStyleSheet(inputStyleSheet); mpAuthors->setStyleSheet(inputStyleSheet);
mpObjectives->setReadOnly(false); mpObjectives->setReadOnly(false);
mpObjectives->managePlaceholder(false);
mpObjectives->setStyleSheet(inputStyleSheet); mpObjectives->setStyleSheet(inputStyleSheet);
mpKeywords->setReadOnly(false); mpKeywords->setReadOnly(false);
mpKeywords->managePlaceholder(false);
mpKeywords->setStyleSheet(inputStyleSheet); mpKeywords->setStyleSheet(inputStyleSheet);
mpSchoolLevelValueLabel->hide(); mpSchoolLevelValueLabel->hide();
mpSchoolLevelBox->show(); mpSchoolLevelBox->show();

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

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

Loading…
Cancel
Save