Merge branch 'develop' of github.com:Sankore/Sankore-3.1 into develop

preferencesAboutTextFull
Aleksei Kanash 12 years ago
commit 373f2af074
  1. 4
      src/gui/UBTeacherGuideWidget.cpp
  2. 73
      src/gui/UBTeacherGuideWidgetsTools.cpp
  3. 7
      src/gui/UBTeacherGuideWidgetsTools.h

@ -1025,14 +1025,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(true);
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();

@ -24,6 +24,9 @@
#include <QApplication> #include <QApplication>
#include <QDomElement> #include <QDomElement>
#include <QWebFrame> #include <QWebFrame>
#include <QTextDocument>
#include <QTextBlock>
#include <QTextCursor>
#include "UBTeacherGuideWidgetsTools.h" #include "UBTeacherGuideWidgetsTools.h"
@ -148,30 +151,10 @@ void UBTGAdaptableText::setPlaceHolderText(QString text)
setPlainText(mPlaceHolderText); setPlainText(mPlaceHolderText);
} }
void UBTGAdaptableText::keyPressEvent(QKeyEvent* e)
{
if(isReadOnly()){
// this is important if you set a placeholder. In this case even if the text field is readonly the
// keypressed event came here. So if you don't ignore it you'll have a flick on the text zone
e->ignore();
return;
}
if(toPlainText() == mPlaceHolderText){
setPlainText("");
}
setTextColor(QColor(Qt::black));
QTextEdit::keyPressEvent(e);
}
void UBTGAdaptableText::keyReleaseEvent(QKeyEvent* e) void UBTGAdaptableText::keyReleaseEvent(QKeyEvent* e)
{ {
QTextEdit::keyReleaseEvent(e); QTextEdit::keyReleaseEvent(e);
if(toPlainText().isEmpty()){
setTextColor(QColor(Qt::lightGray));
setPlainText(mPlaceHolderText);
}
if(mMaximumLength && toPlainText().length()>mMaximumLength){ if(mMaximumLength && toPlainText().length()>mMaximumLength){
setPlainText(toPlainText().left(mMaximumLength)); setPlainText(toPlainText().left(mMaximumLength));
QTextCursor tc(document()); QTextCursor tc(document());
@ -183,8 +166,10 @@ 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));
setPlainText(mPlaceHolderText); setPlainText(mPlaceHolderText);
}
else else
// If the teacherguide is collapsed, don't updated the size. Or set the size as the expanded size // If the teacherguide is collapsed, don't updated the size. Or set the size as the expanded size
onTextChanged(); onTextChanged();
@ -201,19 +186,18 @@ QString UBTGAdaptableText::text()
void UBTGAdaptableText::onTextChanged() void UBTGAdaptableText::onTextChanged()
{ {
//qDebug() << ">> onTextChanged CALLED!";
qreal documentSize = document()->size().height(); qreal documentSize = document()->size().height();
//qDebug() << ">> documentSize: " << documentSize << ", height: " << height();
if(height() == documentSize + mBottomMargin){ if(height() == documentSize + mBottomMargin){
return; return;
} }
mIsUpdatingSize = true; mIsUpdatingSize = true;
if(documentSize < mMinimumHeight) if(documentSize < mMinimumHeight){
setFixedHeight(mMinimumHeight); setFixedHeight(mMinimumHeight);
else }else{
setFixedHeight(documentSize+mBottomMargin); setFixedHeight(documentSize+mBottomMargin);
}
updateGeometry(); updateGeometry();
//to trig a resize on the tree widget item //to trig a resize on the tree widget item
@ -224,8 +208,6 @@ void UBTGAdaptableText::onTextChanged()
setFocus(); setFocus();
} }
mIsUpdatingSize = false; mIsUpdatingSize = false;
} }
void UBTGAdaptableText::setInitialText(const QString& text) void UBTGAdaptableText::setInitialText(const QString& text)
@ -248,6 +230,43 @@ void UBTGAdaptableText::bottomMargin(int newValue)
onTextChanged(); onTextChanged();
} }
void UBTGAdaptableText::focusInEvent(QFocusEvent* e){
if(isReadOnly()){
e->ignore();
}
managePlaceholder(true);
QTextEdit::focusInEvent(e);
}
void UBTGAdaptableText::focusOutEvent(QFocusEvent* e){
managePlaceholder(false);
QTextEdit::focusOutEvent(e);
}
void UBTGAdaptableText::managePlaceholder(bool focus){
if(focus){
if(toPlainText() == mPlaceHolderText){
setTextColor(QColor(Qt::black));
setPlainText("");
}
setCursorToTheEnd();
}else{
if(toPlainText().isEmpty()){
setTextColor(QColor(Qt::lightGray));
setPlainText(mPlaceHolderText);
}
}
}
void UBTGAdaptableText::setCursorToTheEnd(){
QTextDocument* doc = document();
if(NULL != doc){
QTextBlock block = doc->lastBlock();
QTextCursor cursor(doc);
cursor.setPosition(block.position() + block.length() - 1);
setTextCursor(cursor);
}
}
/*************************************************************************** /***************************************************************************
* class UBTGDraggableWeb * * class UBTGDraggableWeb *

@ -26,6 +26,8 @@
#include <QMimeData> #include <QMimeData>
#include <QStackedWidget> #include <QStackedWidget>
#include <QWebView> #include <QWebView>
#include <QFocusEvent>
#include <QMouseEvent>
#include "customWidgets/UBMediaWidget.h" #include "customWidgets/UBMediaWidget.h"
@ -98,16 +100,19 @@ 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();
protected: protected:
void keyPressEvent(QKeyEvent* e);
void keyReleaseEvent(QKeyEvent* e); void keyReleaseEvent(QKeyEvent* e);
void showEvent(QShowEvent* e); void showEvent(QShowEvent* e);
void focusInEvent(QFocusEvent* e);
void focusOutEvent(QFocusEvent* e);
private: private:
void setCursorToTheEnd();
int mBottomMargin; int mBottomMargin;
QTreeWidgetItem* mpTreeWidgetItem; QTreeWidgetItem* mpTreeWidgetItem;
int mMinimumHeight; int mMinimumHeight;

Loading…
Cancel
Save