forked from qt-creator/qt-creator
QmlDesigner: Fix for Annotation Preview
Change-Id: I81d5d3bd85f1835759804ea7ebdd5448d58686c2 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -219,7 +219,7 @@ void FormEditorAnnotationIcon::contextMenuEvent(QGraphicsSceneContextMenuEvent *
|
|||||||
void FormEditorAnnotationIcon::drawReader()
|
void FormEditorAnnotationIcon::drawReader()
|
||||||
{
|
{
|
||||||
if (!childItems().isEmpty()) {
|
if (!childItems().isEmpty()) {
|
||||||
for (QGraphicsItem *item : childItems()) {
|
for (QGraphicsItem * const item : childItems()) {
|
||||||
item->show();
|
item->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -230,11 +230,9 @@ void FormEditorAnnotationIcon::drawReader()
|
|||||||
|
|
||||||
void FormEditorAnnotationIcon::hideReader()
|
void FormEditorAnnotationIcon::hideReader()
|
||||||
{
|
{
|
||||||
if (!childItems().isEmpty()) {
|
if (!childItems().isEmpty())
|
||||||
for (QGraphicsItem *item : childItems()) {
|
for (QGraphicsItem * const item : childItems())
|
||||||
item->hide();
|
item->hide();
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormEditorAnnotationIcon::quickResetReader()
|
void FormEditorAnnotationIcon::quickResetReader()
|
||||||
@@ -251,21 +249,31 @@ void FormEditorAnnotationIcon::resetReader()
|
|||||||
|
|
||||||
void FormEditorAnnotationIcon::createReader()
|
void FormEditorAnnotationIcon::createReader()
|
||||||
{
|
{
|
||||||
const qreal width = 290;
|
const qreal width = 290.;
|
||||||
const qreal height = 200;
|
const qreal height = 30.;
|
||||||
const qreal offset = 5;
|
const qreal offset = 5.;
|
||||||
|
|
||||||
const QRectF titleRect(0, 0, width, 30);
|
|
||||||
const QPointF cornerPosition(m_iconW + offset, 0);
|
|
||||||
|
|
||||||
QGraphicsItem *titleBubble = createTitleBubble(titleRect, m_customId, this);
|
QPointF cornerPosition(m_iconW + offset, 0);
|
||||||
titleBubble->setPos(cornerPosition);
|
qreal nextYAfterTitle = 40.;
|
||||||
|
|
||||||
|
if (!m_customId.isEmpty()) {
|
||||||
|
const QRectF titleRect(0., 0., width, height);
|
||||||
|
|
||||||
|
QGraphicsItem *titleBubble = createTitleBubble(titleRect, m_customId, this);
|
||||||
|
titleBubble->setPos(cornerPosition);
|
||||||
|
|
||||||
|
nextYAfterTitle = (titleRect.height() + (offset*2));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
nextYAfterTitle = 0.;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_annotation.hasComments()) {
|
if (m_annotation.hasComments()) {
|
||||||
QList<QGraphicsItem*> comments;
|
QList<QGraphicsItem*> comments;
|
||||||
|
|
||||||
QPointF commentPosition(cornerPosition.x(), 40);
|
QPointF commentPosition(cornerPosition.x(), nextYAfterTitle);
|
||||||
QRectF commentRect(0, 0, width, height);
|
QRectF commentRect(0., 0., width, height);
|
||||||
|
|
||||||
for (const Comment &comment : m_annotation.comments()) {
|
for (const Comment &comment : m_annotation.comments()) {
|
||||||
QGraphicsItem *commentBubble = createCommentBubble(commentRect, comment.title(),
|
QGraphicsItem *commentBubble = createCommentBubble(commentRect, comment.title(),
|
||||||
@@ -275,12 +283,12 @@ void FormEditorAnnotationIcon::createReader()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const qreal maxHeight = 650;
|
const qreal maxHeight = 650.;
|
||||||
const QPointF commentsStartPosition(cornerPosition.x(), cornerPosition.y() + titleRect.height() + (offset*2));
|
const QPointF commentsStartPosition(cornerPosition.x(), cornerPosition.y() + nextYAfterTitle);
|
||||||
QPointF newPos(commentsStartPosition);
|
QPointF newPos(commentsStartPosition);
|
||||||
qreal columnHeight = commentsStartPosition.y();
|
qreal columnHeight = commentsStartPosition.y();
|
||||||
|
|
||||||
for (QGraphicsItem *comment : comments) {
|
for (QGraphicsItem * const comment : comments) {
|
||||||
|
|
||||||
comment->setPos(newPos); //first place comment in its new position, then calculate position for next comment
|
comment->setPos(newPos); //first place comment in its new position, then calculate position for next comment
|
||||||
|
|
||||||
@@ -288,7 +296,7 @@ void FormEditorAnnotationIcon::createReader()
|
|||||||
const qreal itemWidth = comment->boundingRect().width();
|
const qreal itemWidth = comment->boundingRect().width();
|
||||||
|
|
||||||
const qreal possibleHeight = columnHeight + offset + itemHeight;
|
const qreal possibleHeight = columnHeight + offset + itemHeight;
|
||||||
qreal newX = 0;
|
qreal newX = 0.;
|
||||||
|
|
||||||
if ((itemWidth > (width + penWidth)) || (possibleHeight > maxHeight)) {
|
if ((itemWidth > (width + penWidth)) || (possibleHeight > maxHeight)) {
|
||||||
//move coords to the new column
|
//move coords to the new column
|
||||||
@@ -323,51 +331,86 @@ QGraphicsItem *FormEditorAnnotationIcon::createCommentBubble(QRectF rect, const
|
|||||||
font.setBold(true);
|
font.setBold(true);
|
||||||
|
|
||||||
QGraphicsRectItem *frameItem = new QGraphicsRectItem(rect, parent);
|
QGraphicsRectItem *frameItem = new QGraphicsRectItem(rect, parent);
|
||||||
|
const qreal frameX = frameItem->x();
|
||||||
|
qreal nextY = 0.;
|
||||||
|
|
||||||
QGraphicsTextItem *titleItem = new QGraphicsTextItem(frameItem);
|
const qreal offset = 5.; //used only in text block
|
||||||
titleItem->setPlainText(title);
|
qreal titleHeight = 0.;
|
||||||
titleItem->setFont(font);
|
qreal authorHeight = 0.;
|
||||||
titleItem->setDefaultTextColor(textColor);
|
qreal textHeight = 0.;
|
||||||
titleItem->setTextWidth(rect.width());
|
qreal dateHeight = 0.;
|
||||||
titleItem->update();
|
|
||||||
|
|
||||||
QGraphicsTextItem *authorItem = new QGraphicsTextItem(frameItem);
|
if (!title.isEmpty()) {
|
||||||
authorItem->setPlainText(tr("By: ") + author);
|
QGraphicsTextItem *titleItem = new QGraphicsTextItem(frameItem);
|
||||||
authorItem->setDefaultTextColor(textColor);
|
titleItem->setPlainText(title);
|
||||||
authorItem->setTextWidth(rect.width());
|
titleItem->setFont(font);
|
||||||
authorItem->setPos(titleItem->x(), titleItem->boundingRect().height() + titleItem->y());
|
titleItem->setDefaultTextColor(textColor);
|
||||||
authorItem->update();
|
titleItem->setTextWidth(rect.width());
|
||||||
|
titleItem->update();
|
||||||
|
|
||||||
QGraphicsTextItem *textItem = new QGraphicsTextItem(frameItem);
|
titleHeight = titleItem->boundingRect().height();
|
||||||
textItem->setHtml(text);
|
nextY = titleHeight + titleItem->y();
|
||||||
textItem->setDefaultTextColor(textColor);
|
|
||||||
textItem->setTextWidth(rect.width());
|
|
||||||
textItem->setPos(authorItem->x(), authorItem->boundingRect().height() + authorItem->y() + 5);
|
|
||||||
textItem->update();
|
|
||||||
|
|
||||||
if (textItem->boundingRect().width() > textItem->textWidth()) {
|
|
||||||
textItem->setTextWidth(textItem->boundingRect().width());
|
|
||||||
textItem->update();
|
|
||||||
|
|
||||||
rect.setWidth(textItem->boundingRect().width());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const qreal contentRect = titleItem->boundingRect().height()
|
if (!author.isEmpty()) {
|
||||||
+ authorItem->boundingRect().height()
|
QGraphicsTextItem *authorItem = new QGraphicsTextItem(frameItem);
|
||||||
+ textItem->boundingRect().height();
|
authorItem->setPlainText(tr("By: ") + author);
|
||||||
|
authorItem->setDefaultTextColor(textColor);
|
||||||
|
authorItem->setTextWidth(rect.width());
|
||||||
|
authorItem->setPos(frameX, nextY);
|
||||||
|
authorItem->update();
|
||||||
|
|
||||||
if ((contentRect + 60) > rect.height())
|
authorHeight = authorItem->boundingRect().height();
|
||||||
rect.setHeight(contentRect+60);
|
nextY = authorHeight + authorItem->y();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!text.isEmpty()) {
|
||||||
|
QGraphicsTextItem *textItem = new QGraphicsTextItem(frameItem);
|
||||||
|
textItem->setHtml(text);
|
||||||
|
|
||||||
|
//we can receive rich text qstr with html header, but without content
|
||||||
|
if (textItem->toPlainText().isEmpty()) {
|
||||||
|
delete textItem;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!title.isEmpty() || !author.isEmpty()) {
|
||||||
|
nextY += offset;
|
||||||
|
textHeight += offset;
|
||||||
|
}
|
||||||
|
textItem->setDefaultTextColor(textColor);
|
||||||
|
textItem->setTextWidth(rect.width());
|
||||||
|
textItem->setPos(frameX, nextY);
|
||||||
|
textItem->update();
|
||||||
|
|
||||||
|
if (textItem->boundingRect().width() > textItem->textWidth()) {
|
||||||
|
textItem->setTextWidth(textItem->boundingRect().width());
|
||||||
|
textItem->update();
|
||||||
|
rect.setWidth(textItem->boundingRect().width());
|
||||||
|
}
|
||||||
|
|
||||||
|
textHeight += textItem->boundingRect().height() + offset;
|
||||||
|
nextY = textHeight + textItem->y();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!date.isEmpty()) {
|
||||||
|
QGraphicsTextItem *dateItem = new QGraphicsTextItem(frameItem);
|
||||||
|
dateItem->setPlainText(tr("Edited: ") + date);
|
||||||
|
dateItem->setDefaultTextColor(textColor);
|
||||||
|
dateItem->setTextWidth(rect.width());
|
||||||
|
dateItem->setPos(frameX, nextY);
|
||||||
|
dateItem->update();
|
||||||
|
|
||||||
|
dateHeight = dateItem->boundingRect().height();
|
||||||
|
|
||||||
|
// nextY = dateHeight + dateItem->y();
|
||||||
|
}
|
||||||
|
|
||||||
|
const qreal contentRect = titleHeight + authorHeight + textHeight + dateHeight;
|
||||||
|
rect.setHeight(contentRect);
|
||||||
|
|
||||||
frameItem->setRect(rect);
|
frameItem->setRect(rect);
|
||||||
|
|
||||||
QGraphicsTextItem *dateItem = new QGraphicsTextItem(frameItem);
|
|
||||||
dateItem->setPlainText(tr("Edited: ") + date);
|
|
||||||
dateItem->setDefaultTextColor(textColor);
|
|
||||||
dateItem->setTextWidth(rect.width());
|
|
||||||
dateItem->setPos(frameItem->boundingRect().bottomLeft() + QPointF(0, -30));
|
|
||||||
dateItem->update();
|
|
||||||
|
|
||||||
QPen pen;
|
QPen pen;
|
||||||
pen.setCosmetic(true);
|
pen.setCosmetic(true);
|
||||||
pen.setWidth(penWidth);
|
pen.setWidth(penWidth);
|
||||||
|
Reference in New Issue
Block a user