From f13cceb40fb8563e3b2423f402ae92defefc21bd Mon Sep 17 00:00:00 2001 From: Ivan Ilin Date: Mon, 28 Nov 2011 19:34:51 +0200 Subject: [PATCH] CFF is about to be done --- src/adaptors/UBCFFSubsetAdaptor.cpp | 108 +++++++++-------- src/adaptors/UBCFFSubsetAdaptor.h | 3 + src/adaptors/UBSvgSubsetAdaptor.cpp | 134 ++++++++++---------- src/adaptors/UBSvgSubsetAdaptor.h | 4 +- src/core/UBSetting.h | 4 +- src/core/UBSettings.cpp | 11 +- src/core/UBSettings.h | 2 + src/domain/UBGraphicsItemDelegate.cpp | 5 +- src/domain/UBGraphicsScene.cpp | 6 +- src/domain/UBGraphicsTextItem.cpp | 28 ++--- src/domain/UBGraphicsTextItemDelegate.cpp | 141 +++++++++++++++------- src/domain/UBGraphicsTextItemDelegate.h | 3 + src/domain/UBGraphicsVideoItemDelegate.h | 2 +- 13 files changed, 271 insertions(+), 180 deletions(-) diff --git a/src/adaptors/UBCFFSubsetAdaptor.cpp b/src/adaptors/UBCFFSubsetAdaptor.cpp index aea6bcd7..00c10174 100644 --- a/src/adaptors/UBCFFSubsetAdaptor.cpp +++ b/src/adaptors/UBCFFSubsetAdaptor.cpp @@ -43,6 +43,7 @@ #include #include "core/memcheck.h" +#include "qtlogger.h" //tag names definition. Use them everiwhere! static QString tElement = "element"; @@ -548,7 +549,6 @@ void UBCFFSubsetAdaptor::UBCFFSubsetReader::parseTSpan(const QDomElement &parent QDomNode curNode = parent.firstChild(); while (!curNode.isNull()) { if (curNode.toElement().tagName() == tTspan) { - QDomElement curTSpan = curNode.toElement(); parseTextAttributes(curTSpan, fontSize, fontColor, fontFamily, fontStretch, italic , fontWeight, textAlign, fontTransform); @@ -579,73 +579,77 @@ void UBCFFSubsetAdaptor::UBCFFSubsetReader::parseTSpan(const QDomElement &parent curNode = curNode.nextSibling(); } } +void UBCFFSubsetAdaptor::UBCFFSubsetReader::parseTSpan(const QDomElement &element, QTextCursor &cursor + , QTextBlockFormat &blockFormat, QTextCharFormat &charFormat) +{ + QDomNode curNode = element.firstChild(); + while (!curNode.isNull()) { + if (curNode.toElement().tagName() == tTspan) { + QDomElement curTspan = curNode.toElement(); + readTextBlockAttr(curTspan, blockFormat); + readTextCharAttr(curTspan, charFormat); + cursor.setBlockFormat(blockFormat); + cursor.setCharFormat(charFormat); + parseTSpan(curTspan, cursor, blockFormat, charFormat); + + } else if (curNode.nodeType() == QDomNode::CharacterDataNode + || curNode.nodeType() == QDomNode::CDATASectionNode + || curNode.nodeType() == QDomNode::TextNode) { + + QDomCharacterData textData = curNode.toCharacterData(); + QString text = textData.data().trimmed(); + cursor.insertText(text, charFormat); + + } else if (curNode.nodeType() == QDomNode::ElementNode + && curNode.toElement().tagName() == tBreak) { + cursor.insertBlock(); + } + curNode = curNode.nextSibling(); + } +} bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgTextarea(const QDomElement &element) { - qreal x = element.attribute(aX).toDouble(); qreal y = element.attribute(aY).toDouble(); qreal width = element.attribute(aWidth).toDouble(); qreal height = element.attribute(aHeight).toDouble(); + QTextBlockFormat blockFormat; + blockFormat.setAlignment(Qt::AlignLeft); + QTextCharFormat textFormat; + textFormat.setFontPointSize(12 * 72 / QApplication::desktop()->physicalDpiY()); + textFormat.setForeground(qApp->palette().foreground().color()); + textFormat.setFontFamily("Arial"); + textFormat.setFontItalic(false); + textFormat.setFontWeight(QFont::Normal); -// qreal fontSize = 12; -// QColor fontColor(qApp->palette().foreground().color()); -// QString fontFamily = "Arial"; -// QString fontStretch = "normal"; -// bool italic = false; -// int fontWeight = QFont::Normal; -// int textAlign = Qt::AlignLeft; - QTransform fontTransform; -// parseTextAttributes(element, fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform); - -// QSvgGenerator *generator = createSvgGenerator(width, height); -// QPainter painter; -// painter.begin(generator); + readTextBlockAttr(element, blockFormat); + readTextCharAttr(element, textFormat); -// painter.setFont(QFont(fontFamily, fontSize, fontWeight, italic)); + QTextDocument doc; + doc.setPlainText(""); + QTextCursor tCursor(&doc); + tCursor.setBlockFormat(blockFormat); + tCursor.setCharFormat(textFormat); -// qreal curY = 0.0; -// qreal curX = 0.0; -// qreal linespacing = QFontMetricsF(painter.font()).leading(); - -//// remember if text area has transform -//// QString transformString; - QTransform transform = fontTransform; - bool hasTransform = false;//!fontTransform.isIdentity(); + parseTSpan(element, tCursor, blockFormat, textFormat); -// QRectF lastDrawnTextBoundingRect; -// //parse text area tags + UBGraphicsTextItem *svgItem = mCurrentScene->addTextHtml(doc.toHtml()); + svgItem->resize(width, height); -// //recursive call any tspan in text svg element -// parseTSpan(element, painter -// , curX, curY, width, height, linespacing, lastDrawnTextBoundingRect -// , fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform); - -// painter.end(); - - //add resulting svg file to scene -// UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); + QTransform transform; + QString textTransform = element.attribute(aTransform); + bool hastransform = false; + if (!textTransform.isNull()) { + transform = transformFromString(textTransform); + hastransform = true; + } - QFile file("/home/ilia/Documents/tmp/1/index.html"); - file.open(QIODevice::ReadOnly); - QByteArray barr = file.readAll(); - file.close(); - QString str(barr); - UBGraphicsTextItem *svgItem = mCurrentScene->addTextHtml(str); - svgItem->resize(width * mVBTransFactor, height * mVBTransFactor); - -// QTextCursor cursor; -// cursor.insertBlock(); -// cursor.insertText("way away"); -// cursor.insertBlock(); -// cursor.insertText("for the right"); -// svgItem->setTextCursor(cursor); - repositionSvgItem(svgItem, width, height, x, y, hasTransform, transform); -// hashSceneItem(element, svgItem); + repositionSvgItem(svgItem, width, height, x, y, hastransform, transform); + hashSceneItem(element, svgItem); -// delete generator; return true; } bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgImage(const QDomElement &element) diff --git a/src/adaptors/UBCFFSubsetAdaptor.h b/src/adaptors/UBCFFSubsetAdaptor.h index 82c8c5f3..d4def19b 100644 --- a/src/adaptors/UBCFFSubsetAdaptor.h +++ b/src/adaptors/UBCFFSubsetAdaptor.h @@ -34,6 +34,7 @@ class UBGraphicsItem; class QGraphicsItem; class QTextBlockFormat; class QTextCharFormat; +class QTextCursor; class UBCFFSubsetAdaptor @@ -100,6 +101,8 @@ private: , qreal &curX, qreal &curY, qreal &width, qreal &height, qreal &linespacing, QRectF &lastDrawnTextBoundingRect , qreal &fontSize, QColor &fontColor, QString &fontFamily, QString &fontStretch, bool &italic , int &fontWeight, int &textAlign, QTransform &fontTransform); + inline void parseTSpan(const QDomElement &element, QTextCursor &cursor + , QTextBlockFormat &blockFormat, QTextCharFormat &charFormat); inline void hashSceneItem(const QDomElement &element, UBGraphicsItem *item); // to kill diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index 0d1bc0a3..f01e804e 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -53,6 +53,7 @@ #include "pdf/PDFRenderer.h" #include "core/memcheck.h" +#include "qtlogger.h" const QString UBSvgSubsetAdaptor::nsSvg = "http://www.w3.org/2000/svg"; const QString UBSvgSubsetAdaptor::nsXHtml = "http://www.w3.org/1999/xhtml"; @@ -2216,38 +2217,51 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::textItemToSvg(UBGraphicsTextItem* it mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri , "fill-on-light-background", colorLightBg.name()); - mXmlWriter.writeStartElement(nsXHtml, "body"); - mXmlWriter.writeStartElement(nsXHtml, "div"); - mXmlWriter.writeStartElement(nsXHtml, "font"); + //for new documents from version 4.5.0 + if (true) { + mXmlWriter.writeStartElement("itemTextContent"); + mXmlWriter.writeCDATA(item->toHtml()); + mXmlWriter.writeEndElement(); //itemTextContent - QFont font = item->font(); + //tracking for back capability with older versions + } else if (false) { + mXmlWriter.writeStartElement(nsXHtml, "body"); + mXmlWriter.writeStartElement(nsXHtml, "div"); + mXmlWriter.writeStartElement(nsXHtml, "font"); - mXmlWriter.writeAttribute("face", font.family()); + QFont font = item->font(); - QFontInfo fi(font); - int pixelSize = fi.pixelSize(); + mXmlWriter.writeAttribute("face", font.family()); - mXmlWriter.writeAttribute("style", sFontSizePrefix + QString(" %1").arg(pixelSize) + sPixelUnit + "; " + - sFontWeightPrefix + " " + (fi.bold() ? "bold" : "normal") + "; " + - sFontStylePrefix + " " + (fi.italic() ? "italic" : "normal") + ";"); - mXmlWriter.writeAttribute("color", item->defaultTextColor().name()); + QFontInfo fi(font); + int pixelSize = fi.pixelSize(); - QString text = item->toPlainText(); - QStringList lines = text.split("\n"); + mXmlWriter.writeAttribute("style", sFontSizePrefix + QString(" %1").arg(pixelSize) + sPixelUnit + "; " + + sFontWeightPrefix + " " + (fi.bold() ? "bold" : "normal") + "; " + + sFontStylePrefix + " " + (fi.italic() ? "italic" : "normal") + ";"); + mXmlWriter.writeAttribute("color", item->defaultTextColor().name()); - for (int i = 0; i < lines.length() ; i++) - { - mXmlWriter.writeCharacters(lines.at(i)); + QString text = item->toPlainText(); + QStringList lines = text.split("\n"); - if (i < lines.length() - 1) - mXmlWriter.writeEmptyElement(nsXHtml, "br"); - } + for (int i = 0; i < lines.length() ; i++) + { + mXmlWriter.writeCharacters(lines.at(i)); - mXmlWriter.writeEndElement(); //font - mXmlWriter.writeEndElement(); //div - mXmlWriter.writeEndElement(); //body + if (i < lines.length() - 1) + mXmlWriter.writeEmptyElement(nsXHtml, "br"); + } + + mXmlWriter.writeEndElement(); //font + mXmlWriter.writeEndElement(); //div + mXmlWriter.writeEndElement(); //body + } mXmlWriter.writeEndElement(); //foreignObject + + QtLogger::start("/home/ilia/Documents/tmp/10/log.log"); + QtLogger::appendl(item->toHtml()); + QtLogger::finish(); } UBGraphicsTextItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::textItemFromSvg() @@ -2275,39 +2289,41 @@ UBGraphicsTextItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::textItemFromSvg() mXmlReader.readNext(); if (mXmlReader.isStartElement()) { - if (mXmlReader.name() == "font") - { + //for new documents from version 4.5.0 + if (true) { + if (mXmlReader.name() == "itemTextContent") { + QString text = mXmlReader.readElementText(); + // QtLogger::start("/home/ilia/Documents/tmp/10/log.log"); + // QtLogger::appendl(text); + // QtLogger::finish(); + // textItem->setPlainText(""); + textItem->setHtml(text); + break; + } + //tracking for back capability with older versions + } else if (mXmlReader.name() == "font") { QFont font = textItem->font(); QStringRef fontFamily = mXmlReader.attributes().value("face"); - if (!fontFamily.isNull()) - { + if (!fontFamily.isNull()) { font.setFamily(fontFamily.toString()); } - QStringRef fontStyle = mXmlReader.attributes().value("style"); - if (!fontStyle.isNull()) - { - foreach (QString styleToken, fontStyle.toString().split(";")) - { + if (!fontStyle.isNull()) { + foreach (QString styleToken, fontStyle.toString().split(";")) { styleToken = styleToken.trimmed(); - if (styleToken.startsWith(sFontSizePrefix) && styleToken.endsWith(sPixelUnit)) - { + if (styleToken.startsWith(sFontSizePrefix) && styleToken.endsWith(sPixelUnit)) { int fontSize = styleToken.mid( sFontSizePrefix.length(), styleToken.length() - sFontSizePrefix.length() - sPixelUnit.length()).toInt(); font.setPixelSize(fontSize); - } - else if (styleToken.startsWith(sFontWeightPrefix)) - { + } else if (styleToken.startsWith(sFontWeightPrefix)) { QString fontWeight = styleToken.mid( sFontWeightPrefix.length(), styleToken.length() - sFontWeightPrefix.length()); font.setBold(fontWeight.contains("bold")); - } - else if (styleToken.startsWith(sFontStylePrefix)) - { + } else if (styleToken.startsWith(sFontStylePrefix)) { QString fontStyle = styleToken.mid( sFontStylePrefix.length(), styleToken.length() - sFontStylePrefix.length()); @@ -2319,15 +2335,13 @@ UBGraphicsTextItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::textItemFromSvg() textItem->setFont(font); QStringRef fill = mXmlReader.attributes().value("color"); - if (!fill.isNull()) - { + if (!fill.isNull()) { QColor textColor; textColor.setNamedColor(fill.toString()); textItem->setDefaultTextColor(textColor); } - if (!ubFillOnDarkBackground.isNull()) - { + if (!ubFillOnDarkBackground.isNull()) { QColor color; color.setNamedColor(ubFillOnDarkBackground.toString()); if (!color.isValid()) @@ -2335,8 +2349,7 @@ UBGraphicsTextItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::textItemFromSvg() textItem->setColorOnDarkBackground(color); } - if (!ubFillOnLightBackground.isNull()) - { + if (!ubFillOnLightBackground.isNull()) { QColor color; color.setNamedColor(ubFillOnLightBackground.toString()); if (!color.isValid()) @@ -2344,20 +2357,16 @@ UBGraphicsTextItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::textItemFromSvg() textItem->setColorOnLightBackground(color); } - while (!(mXmlReader.isEndElement() && mXmlReader.name() == "font")) - { - if (mXmlReader.hasError()) - { + while (!(mXmlReader.isEndElement() && mXmlReader.name() == "font")) { + if (mXmlReader.hasError()) { break; } QXmlStreamReader::TokenType tt = mXmlReader.readNext(); - if (tt == QXmlStreamReader::Characters) - { + if (tt == QXmlStreamReader::Characters) { text += mXmlReader.text().toString(); } - if (mXmlReader.isStartElement() && mXmlReader.name() == "br") - { + if (mXmlReader.isStartElement() && mXmlReader.name() == "br") { text += "\n"; } } @@ -2365,16 +2374,16 @@ UBGraphicsTextItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::textItemFromSvg() } } - if (text.isEmpty()) - { - delete textItem; - textItem = 0; - } - else - { - textItem->setPlainText(text); - textItem->resize(width, height); + if (false) { + if (text.isEmpty()) { + delete textItem; + textItem = 0; + } else { + textItem->setPlainText(text); + textItem->resize(width, height); + } } + textItem->resize(width, height); return textItem; } @@ -2412,6 +2421,7 @@ UBGraphicsCurtainItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::curtainItemFromSvg QRectF rect = curtainItem->rect(); rect.setWidth(svgWidth.toString().toFloat()); rect.setHeight(svgHeight.toString().toFloat()); + rect.translate(- rect.center()); curtainItem->setRect(rect); diff --git a/src/adaptors/UBSvgSubsetAdaptor.h b/src/adaptors/UBSvgSubsetAdaptor.h index 4b52193e..2335c3cf 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.h +++ b/src/adaptors/UBSvgSubsetAdaptor.h @@ -92,7 +92,7 @@ class UBSvgSubsetAdaptor UBSvgSubsetReader(UBDocumentProxy* proxy, const QByteArray& pXmlData); - virtual ~UBSvgSubsetReader(){}; + virtual ~UBSvgSubsetReader(){} UBGraphicsScene* loadScene(); @@ -155,7 +155,7 @@ class UBSvgSubsetAdaptor bool persistScene(); - virtual ~UBSvgSubsetWriter(){}; + virtual ~UBSvgSubsetWriter(){} private: diff --git a/src/core/UBSetting.h b/src/core/UBSetting.h index 8475eb35..edfaf838 100644 --- a/src/core/UBSetting.h +++ b/src/core/UBSetting.h @@ -22,7 +22,7 @@ class UBSettings; class UBSetting : public QObject { - Q_OBJECT; + Q_OBJECT public: UBSetting(UBSettings* parent = 0); @@ -71,7 +71,7 @@ class UBSetting : public QObject class UBColorListSetting : public UBSetting { - Q_OBJECT; + Q_OBJECT public: UBColorListSetting(UBSettings* parent = 0); diff --git a/src/core/UBSettings.cpp b/src/core/UBSettings.cpp index 53d522b2..8d60a0a9 100644 --- a/src/core/UBSettings.cpp +++ b/src/core/UBSettings.cpp @@ -112,8 +112,6 @@ void UBSettings::destroy() } - - QSettings* UBSettings::getAppSettings() { if (!UBSettings::sAppSettings) @@ -689,6 +687,15 @@ void UBSettings::setFontPixelSize(int pixelSize) setValue("Board/FontPixelSize", pixelSize); } +int UBSettings::fontPointSize() +{ + return value("Board/FontPointSize", 12).toInt(); +} + +void UBSettings::setFontPointSize(int pointSize) +{ + setValue("Board/FontPointSize", pointSize); +} bool UBSettings::isBoldFont() { diff --git a/src/core/UBSettings.h b/src/core/UBSettings.h index 8bd9f136..f66ff7f9 100644 --- a/src/core/UBSettings.h +++ b/src/core/UBSettings.h @@ -75,6 +75,8 @@ class UBSettings : public QObject void setFontFamily(const QString &family); int fontPixelSize(); void setFontPixelSize(int pixelSize); + int fontPointSize(); + void setFontPointSize(int pointSize); bool isBoldFont(); void setBoldFont(bool bold); bool isItalicFont(); diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index ff8c38ed..7cc8fa96 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -163,8 +163,9 @@ bool UBGraphicsItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event) qDebug() << mDelegated->zValue(); qDebug() << scene->currentObjectZIndex(); - if (mDelegated->zValue() < scene->currentObjectZIndex() && !isLocked()) - mDelegated->setZValue(scene->getNextObjectZIndex()); +// To investigate. Z value behavior +// if (mDelegated->zValue() < scene->currentObjectZIndex() && !isLocked()) +// mDelegated->setZValue(scene->getNextObjectZIndex()); positionHandles(); diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index c27734e7..c6535f7a 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1316,6 +1316,7 @@ UBGraphicsTextItem *UBGraphicsScene::addTextHtml(const QString &pString) UBGraphicsTextItem *textItem = new UBGraphicsTextItem(); textItem->setPlainText(""); textItem->setHtml(pString); + textItem->setZValue(getNextObjectZIndex()); addItem(textItem); textItem->show(); @@ -1323,9 +1324,10 @@ UBGraphicsTextItem *UBGraphicsScene::addTextHtml(const QString &pString) UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, 0, textItem); UBApplication::undoStack->push(uc); - connect(textItem, SIGNAL(textUndoCommandAdded(UBGraphicsTextItem *)), this, SLOT(textUndoCommandAdded(UBGraphicsTextItem *))); + connect(textItem, SIGNAL(textUndoCommandAdded(UBGraphicsTextItem *)), + this, SLOT(textUndoCommandAdded(UBGraphicsTextItem *))); - textItem->setSelected(true); +// textItem->setSelected(true); textItem->setFocus(); setDocumentUpdated(); diff --git a/src/domain/UBGraphicsTextItem.cpp b/src/domain/UBGraphicsTextItem.cpp index 6125997c..fb69bc33 100644 --- a/src/domain/UBGraphicsTextItem.cpp +++ b/src/domain/UBGraphicsTextItem.cpp @@ -40,20 +40,20 @@ UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) mTypeTextHereLabel = tr(""); - if (lastUsedTextColor.isValid()) - { - setDefaultTextColor(lastUsedTextColor); - setColorOnDarkBackground(lastUsedTextColor); - setColorOnLightBackground(lastUsedTextColor); - } - else - { - QColor colorOnDarkBG = UBApplication::boardController->penColorOnDarkBackground(); - QColor colorOnLightBG = UBApplication::boardController->penColorOnLightBackground(); - - setColorOnDarkBackground(colorOnDarkBG); - setColorOnLightBackground(colorOnLightBG); - } +// if (lastUsedTextColor.isValid()) +// { +// setDefaultTextColor(lastUsedTextColor); +// setColorOnDarkBackground(lastUsedTextColor); +// setColorOnLightBackground(lastUsedTextColor); +// } +// else +// { +// QColor colorOnDarkBG = UBApplication::boardController->penColorOnDarkBackground(); +// QColor colorOnLightBG = UBApplication::boardController->penColorOnLightBackground(); + +// setColorOnDarkBackground(colorOnDarkBG); +// setColorOnLightBackground(colorOnLightBG); +// } setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); // setData(UBGraphicsItemData::ItemEditable, QVariant(true)); diff --git a/src/domain/UBGraphicsTextItemDelegate.cpp b/src/domain/UBGraphicsTextItemDelegate.cpp index 856919d6..c736c883 100644 --- a/src/domain/UBGraphicsTextItemDelegate.cpp +++ b/src/domain/UBGraphicsTextItemDelegate.cpp @@ -35,6 +35,33 @@ UBGraphicsTextItemDelegate::UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDele : UBGraphicsItemDelegate(pDelegated,0, parent, true) , mLastFontPixelSize(-1) { + delegated()->setData(UBGraphicsItemData::ItemEditable, QVariant(true)); + delegated()->setPlainText(""); + + QTextCursor curCursor = delegated()->textCursor(); + QTextCharFormat format; + QFont font(createDefaultFont()); + font.setPointSize(UBSettings::settings()->fontPointSize()); + + format.setFont(font); + curCursor.mergeCharFormat(format); + delegated()->setTextCursor(curCursor); + + delegated()->adjustSize(); + delegated()->contentsChanged(); + +// QTextCursor defcursor(createDefaultCursor()); +// defcursor.movePosition(QTextCursor::Start); +// delegated()->setTextCursor(defcursor); + + + // QFont selectedFont = fontDialog.selectedFont(); +// UBSettings::settings()->setFontFamily(selectedFont.family()); +// QFontInfo fi(selectedFont); +// mLastFontPixelSize = fi.pixelSize(); +// UBSettings::settings()->setFontPixelSize(mLastFontPixelSize); +// UBSettings::settings()->setBoldFont(selectedFont.bold()); +// UBSettings::settings()->setItalicFont(selectedFont.italic()); // NOOP } @@ -44,6 +71,32 @@ UBGraphicsTextItemDelegate::~UBGraphicsTextItemDelegate() } +QFont UBGraphicsTextItemDelegate::createDefaultFont() +{ + QTextCharFormat textFormat; + + QString fFamily = UBSettings::settings()->fontFamily(); + if (!fFamily.isEmpty()) + textFormat.setFontFamily(fFamily); + + bool bold = UBSettings::settings()->isBoldFont(); + if (bold) + textFormat.setFontWeight(QFont::Bold); + + bool italic = UBSettings::settings()->isItalicFont(); + if (italic) + textFormat.setFontItalic(true); + + QFont font(fFamily, -1, bold ? QFont::Bold : -1, italic); + int pixSize = UBSettings::settings()->fontPixelSize(); + if (pixSize > 0) { + mLastFontPixelSize = pixSize; + font.setPixelSize(pixSize); + } + + return font; +} + void UBGraphicsTextItemDelegate::buildButtons() { UBGraphicsItemDelegate::buildButtons(); @@ -128,7 +181,7 @@ void UBGraphicsTextItemDelegate::pickFont() { if (mDelegated && mDelegated->scene() && mDelegated->scene()->views().size() > 0) { - QFontDialog fontDialog(delegated()->font(), mDelegated->scene()->views().at(0)); + QFontDialog fontDialog(delegated()->textCursor().charFormat().font(), mDelegated->scene()->views().at(0)); customize(fontDialog); if (fontDialog.exec()) @@ -140,6 +193,7 @@ void UBGraphicsTextItemDelegate::pickFont() UBSettings::settings()->setFontPixelSize(mLastFontPixelSize); UBSettings::settings()->setBoldFont(selectedFont.bold()); UBSettings::settings()->setItalicFont(selectedFont.italic()); + UBSettings::settings()->setFontPointSize(selectedFont.pointSize()); //setting format for selected item QTextCursor curCursor = delegated()->textCursor(); @@ -192,54 +246,54 @@ void UBGraphicsTextItemDelegate::pickColor() void UBGraphicsTextItemDelegate::decreaseSize() { - QFontInfo fi(delegated()->font()); - int pixelSize = fi.pixelSize(); - if (-1 == mLastFontPixelSize) - mLastFontPixelSize = pixelSize; - - int newPixelSize = sMinPixelSize; - while (newPixelSize * 1.5 < pixelSize) - newPixelSize *= 1.5; - - if (newPixelSize < mLastFontPixelSize && mLastFontPixelSize < pixelSize) - newPixelSize = mLastFontPixelSize; - - if (pixelSize > newPixelSize) - { - QFont font = delegated()->font(); - font.setPixelSize(newPixelSize); - delegated()->setFont(font); - UBSettings::settings()->setFontPixelSize(newPixelSize); - - delegated()->document()->adjustSize(); - delegated()->contentsChanged(); - } - +// QFontInfo fi(delegated()->font()); +// int pixelSize = fi.pixelSize(); +// if (-1 == mLastFontPixelSize) +// mLastFontPixelSize = pixelSize; + +// int newPixelSize = sMinPixelSize; +// while (newPixelSize * 1.5 < pixelSize) +// newPixelSize *= 1.5; + +// if (newPixelSize < mLastFontPixelSize && mLastFontPixelSize < pixelSize) +// newPixelSize = mLastFontPixelSize; + +// if (pixelSize > newPixelSize) +// { +// QFont font = delegated()->font(); +// font.setPixelSize(newPixelSize); +// delegated()->setFont(font); +// UBSettings::settings()->setFontPixelSize(newPixelSize); + +// delegated()->document()->adjustSize(); +// delegated()->contentsChanged();dddd +// } } void UBGraphicsTextItemDelegate::increaseSize() { - QFontInfo fi(delegated()->font()); - int pixelSize = fi.pixelSize(); - if (-1 == mLastFontPixelSize) - mLastFontPixelSize = pixelSize; +// QFontInfo fi(delegated()->font()); +// int pixelSize = fi.pixelSize(); +// if (-1 == mLastFontPixelSize) +// mLastFontPixelSize = pixelSize; - int newPixelSize = sMinPixelSize; - while (newPixelSize <= pixelSize) - newPixelSize *= 1.5; +// int newPixelSize = sMinPixelSize; +// while (newPixelSize <= pixelSize) +// newPixelSize *= 1.5; - if (pixelSize < mLastFontPixelSize && mLastFontPixelSize < newPixelSize) - newPixelSize = mLastFontPixelSize; +// if (pixelSize < mLastFontPixelSize && mLastFontPixelSize < newPixelSize) +// newPixelSize = mLastFontPixelSize; - QFont font = delegated()->font(); - font.setPixelSize(newPixelSize); - delegated()->setFont(font); - UBSettings::settings()->setFontPixelSize(newPixelSize); +// QFont font = delegated()->font(); +// font.setPixelSize(newPixelSize); +// delegated()->setFont(font); +// UBSettings::settings()->setFontPixelSize(newPixelSize); - delegated()->document()->adjustSize(); - delegated()->contentsChanged(); +// delegated()->document()->adjustSize(); +// delegated()->contentsChanged(); - qDebug() << newPixelSize; +// qDebug() << newPixelSize; + delegated()->document()->adjustSize(); } UBGraphicsTextItem* UBGraphicsTextItemDelegate::delegated() @@ -270,10 +324,15 @@ void UBGraphicsTextItemDelegate::decorateMenu(QMenu *menu) mEditableAction = menu->addAction(tr("Editable"), this, SLOT(setEditable(bool))); mEditableAction->setCheckable(true); - mEditableAction->setChecked(true); + mEditableAction->setChecked(isEditable()); } void UBGraphicsTextItemDelegate::updateMenuActionState() { UBGraphicsItemDelegate::updateMenuActionState(); } +void UBGraphicsTextItemDelegate::positionHandles() +{ + UBGraphicsItemDelegate::positionHandles(); + setEditable(isEditable()); +} diff --git a/src/domain/UBGraphicsTextItemDelegate.h b/src/domain/UBGraphicsTextItemDelegate.h index f29d1070..ab467439 100644 --- a/src/domain/UBGraphicsTextItemDelegate.h +++ b/src/domain/UBGraphicsTextItemDelegate.h @@ -43,6 +43,8 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate virtual void decorateMenu(QMenu *menu); virtual void updateMenuActionState(); + virtual void positionHandles(); + private: UBGraphicsTextItem* delegated(); @@ -58,6 +60,7 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate private: void customize(QFontDialog &fontDialog); + QFont createDefaultFont(); QAction *mEditableAction; private slots: diff --git a/src/domain/UBGraphicsVideoItemDelegate.h b/src/domain/UBGraphicsVideoItemDelegate.h index d8943faa..8fd36bcc 100644 --- a/src/domain/UBGraphicsVideoItemDelegate.h +++ b/src/domain/UBGraphicsVideoItemDelegate.h @@ -68,7 +68,7 @@ class DelegateVideoControl: public QGraphicsRectItem class UBGraphicsVideoItemDelegate : public UBGraphicsItemDelegate { - Q_OBJECT; + Q_OBJECT public: UBGraphicsVideoItemDelegate(UBGraphicsVideoItem* pDelegated, Phonon::MediaObject* pMedia, QObject * parent = 0);