Merge remote-tracking branch 'origin/develop' into claudio-dev

preferencesAboutTextFull
Claudio Valerio 12 years ago
commit 757dc96ae3
  1. 199
      src/domain/UBGraphicsDelegateFrame.cpp
  2. 3
      src/domain/UBGraphicsDelegateFrame.h
  3. 3
      src/domain/UBGraphicsItemDelegate.cpp
  4. 4
      src/gui/UBTeacherGuideWidget.cpp
  5. 79
      src/gui/UBTeacherGuideWidgetsTools.cpp
  6. 7
      src/gui/UBTeacherGuideWidgetsTools.h

@ -286,18 +286,111 @@ bool UBGraphicsDelegateFrame::canResizeBottomRight(qreal width, qreal height, qr
return res; return res;
} }
QPointF UBGraphicsDelegateFrame::getFixedPointFromPos()
{
QPointF fixedPoint;
if (!moving() && !rotating())
{
if (resizingTop())
{
if (mMirrorX && mMirrorY)
{
if ((0 < mAngle) && (mAngle < 90))
fixedPoint = delegated()->sceneBoundingRect().topLeft();
else
fixedPoint = delegated()->sceneBoundingRect().topRight();
}
else
{
if ((0 < mAngle) && (mAngle <= 90))
fixedPoint = delegated()->sceneBoundingRect().bottomRight();
else
fixedPoint = delegated()->sceneBoundingRect().bottomLeft();
}
}
else if (resizingLeft())
{
if (mMirrorX && mMirrorY)
{
if ((0 < mAngle) && (mAngle < 90))
fixedPoint = delegated()->sceneBoundingRect().bottomLeft();
else
fixedPoint = delegated()->sceneBoundingRect().topLeft();
}
else
{
if ((0 < mAngle) && (mAngle <= 90))
fixedPoint = delegated()->sceneBoundingRect().topRight();
else
fixedPoint = delegated()->sceneBoundingRect().bottomRight();
}
}
}
return fixedPoint;
}
QSizeF UBGraphicsDelegateFrame::getResizeVector(qreal moveX, qreal moveY)
{
qreal dPosX = 0;
qreal dPosY = 0;
if (resizingTop())
{
if (mMirrorX && mMirrorY)
dPosY = moveY;
else
dPosY = -moveY;
}
else if (resizingLeft())
{
if (mMirrorX && mMirrorY)
dPosX = moveX;
else
dPosX = -moveX;
}
else if (resizingRight())
dPosX = (mMirrorX) ? -moveX : moveX;
else if (resizingBottom())
dPosY = mMirrorY ? -moveY : moveY;
return QSizeF(dPosX, dPosY);
}
void UBGraphicsDelegateFrame::resizeDelegate(qreal moveX, qreal moveY)
{
QPointF fixedPoint = getFixedPointFromPos();
UBResizableGraphicsItem* resizableItem = dynamic_cast<UBResizableGraphicsItem*>(delegated());
if (resizableItem)
{
QSizeF originalSize = delegated()->boundingRect().size();
resizableItem->resize(originalSize + getResizeVector(moveX, moveY));
if (resizingTop() || resizingLeft() || ((mMirrorX || mMirrorY) && resizingBottomRight()))
{
delegated()->setPos(delegated()->pos()-getFixedPointFromPos()+fixedPoint);
}
}
}
void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{ {
if (None == mCurrentTool) if (None == mCurrentTool)
return; return;
QLineF move(mStartingPoint, event->scenePos()); QLineF move;
if(rotating() || moving() || mOperationMode == Scaling)
move = QLineF(mStartingPoint, event->scenePos());
else
move = QLineF(event->lastScenePos(), event->scenePos());
qreal moveX = move.length() * cos((move.angle() - mAngle) * PI / 180); qreal moveX = move.length() * cos((move.angle() - mAngle) * PI / 180);
qreal moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180); qreal moveY = -move.length() * sin((move.angle() - mAngle) * PI / 180);
qreal width = delegated()->boundingRect().width() * mTotalScaleX; qreal width = delegated()->boundingRect().width() * mTotalScaleX;
qreal height = delegated()->boundingRect().height() * mTotalScaleY; qreal height = delegated()->boundingRect().height() * mTotalScaleY;
if(mOperationMode == Scaling) if(!rotating())
{ {
mTranslateX = moveX; mTranslateX = moveX;
// Perform the resize // Perform the resize
@ -398,44 +491,7 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
} }
} }
} }
else if (mOperationMode == Resizing || mOperationMode == ResizingHorizontally)
{
mTranslateX = moveX;
UBResizableGraphicsItem* resizableItem = dynamic_cast<UBResizableGraphicsItem*>(delegated());
if (resizableItem)
{
QLineF mousePosDelta(delegated()->mapFromScene(event->lastScenePos())
, delegated()->mapFromScene(event->scenePos()));
QSizeF incVector(0, 0);
if (resizingBottomRight())
{
incVector = QSizeF(mousePosDelta.dx(), mousePosDelta.dy());
}
else if (resizingRight())
{
incVector = QSizeF(mousePosDelta.dx(), 0);
}
else if (resizingBottom())
{
incVector = QSizeF(0, mousePosDelta.dy());
}
else if (resizingLeft())
{
incVector = QSizeF(- mousePosDelta.dx(), 0);
}
else if (resizingTop())
{
incVector = QSizeF(0, - mousePosDelta.dy());
}
QSizeF newSize = resizableItem->size() + incVector;
resizableItem->resize(newSize);
}
}
if (rotating()) if (rotating())
{ {
mTranslateX = 0; mTranslateX = 0;
@ -483,49 +539,56 @@ void UBGraphicsDelegateFrame::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
// we just detects coordinates of corner before and after scaling and then moves object at diff between them. // we just detects coordinates of corner before and after scaling and then moves object at diff between them.
if (resizingBottomRight() && mMirrorX) if (resizingBottomRight() && mMirrorX)
{
mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomRight()).x() - tr.map(delegated()->boundingRect().bottomRight()).x(); mTranslateX += mInitialTransform.map(delegated()->boundingRect().bottomRight()).x() - tr.map(delegated()->boundingRect().bottomRight()).x();
else
mTranslateX += mInitialTransform.map(delegated()->boundingRect().topLeft()).x() - tr.map(delegated()->boundingRect().topLeft()).x();
if (resizingBottomRight() && mMirrorY)
mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomRight()).y() - tr.map(delegated()->boundingRect().bottomRight()).y(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().bottomRight()).y() - tr.map(delegated()->boundingRect().bottomRight()).y();
}
else else
{
mTranslateX += mInitialTransform.map(delegated()->boundingRect().topLeft()).x() - tr.map(delegated()->boundingRect().topLeft()).x();
mTranslateY += mInitialTransform.map(delegated()->boundingRect().topLeft()).y() - tr.map(delegated()->boundingRect().topLeft()).y(); mTranslateY += mInitialTransform.map(delegated()->boundingRect().topLeft()).y() - tr.map(delegated()->boundingRect().topLeft()).y();
}
}
else if (resizingTop() || resizingLeft())
{
QPointF bottomRight = tr.map(delegated()->boundingRect().bottomRight());
QPointF fixedPoint = mInitialTransform.map(delegated()->boundingRect().bottomRight());
mTranslateX += fixedPoint.x() - bottomRight.x();
mTranslateY += fixedPoint.y() - bottomRight.y();
}
// Update the transform
if (mOperationMode == Scaling || moving() || rotating())
{
tr = buildTransform(); tr = buildTransform();
delegated()->setTransform(tr);
} }
else if (resizingTop() || resizingLeft()) else if (mOperationMode == Resizing)
{ {
if (mOperationMode == Scaling) if (!moving() && !rotating())
{ {
QPointF bottomRight = tr.map(delegated()->boundingRect().bottomRight()); if (resizingBottomRight())
QPointF fixedPoint = mInitialTransform.map(delegated()->boundingRect().bottomRight());
mTranslateX += fixedPoint.x() - bottomRight.x();
mTranslateY += fixedPoint.y() - bottomRight.y();
}
else
{
QLineF vector;
if (resizingLeft())
{ {
QPointF topRight1 = mInitialTransform.map(QPointF(delegated()->boundingRect().width() - moveX, 0)); if (mMirrorX && mMirrorY)
QPointF topRight2 = mInitialTransform.map(QPointF(delegated()->boundingRect().width(), 0)); mCurrentTool = ResizeTop;
vector.setPoints(topRight1, topRight2); else
mCurrentTool = ResizeBottom;
resizeDelegate(moveX, moveY);
if (mMirrorX && mMirrorY)
mCurrentTool = ResizeLeft;
else
mCurrentTool = ResizeRight;
resizeDelegate(moveX, moveY);
mCurrentTool = ResizeBottomRight;
} }
else else
{ resizeDelegate(moveX, moveY);
QPointF bottomLeft1 = mInitialTransform.map(QPointF(0, delegated()->boundingRect().height() - moveY));
QPointF bottomLeft2 = mInitialTransform.map(QPointF(0, delegated()->boundingRect().height()));
vector.setPoints(bottomLeft1, bottomLeft2);
}
mTranslateX = vector.dx();
mTranslateY = vector.dy();
} }
tr = buildTransform();
} }
delegated()->setTransform(tr);
event->accept(); event->accept();
} }

@ -37,6 +37,9 @@ class UBGraphicsDelegateFrame: public QGraphicsRectItem, public QObject
QPainterPath shape() const; QPainterPath shape() const;
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
QPointF getFixedPointFromPos();
QSizeF getResizeVector(qreal moveX, qreal moveY);
void resizeDelegate(qreal moveX, qreal moveY);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);

@ -166,7 +166,8 @@ void UBGraphicsItemDelegate::init()
UBGraphicsItemDelegate::~UBGraphicsItemDelegate() UBGraphicsItemDelegate::~UBGraphicsItemDelegate()
{ {
disconnect(UBApplication::boardController, SIGNAL(zoomChanged(qreal)), this, SLOT(onZoomChanged())); if (UBApplication::boardController)
disconnect(UBApplication::boardController, SIGNAL(zoomChanged(qreal)), this, SLOT(onZoomChanged()));
// do not release mMimeData. // do not release mMimeData.
// the mMimeData is owned by QDrag since the setMimeData call as specified in the documentation // the mMimeData is owned by QDrag since the setMimeData call as specified in the documentation
} }

@ -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()){
setPlainText(mPlaceHolderText); setTextColor(QColor(Qt::lightGray));
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