CFF is about to be done

preferencesAboutTextFull
Ivan Ilin 13 years ago
parent c7cbce3099
commit f13cceb40f
  1. 108
      src/adaptors/UBCFFSubsetAdaptor.cpp
  2. 3
      src/adaptors/UBCFFSubsetAdaptor.h
  3. 82
      src/adaptors/UBSvgSubsetAdaptor.cpp
  4. 4
      src/adaptors/UBSvgSubsetAdaptor.h
  5. 4
      src/core/UBSetting.h
  6. 11
      src/core/UBSettings.cpp
  7. 2
      src/core/UBSettings.h
  8. 5
      src/domain/UBGraphicsItemDelegate.cpp
  9. 6
      src/domain/UBGraphicsScene.cpp
  10. 28
      src/domain/UBGraphicsTextItem.cpp
  11. 141
      src/domain/UBGraphicsTextItemDelegate.cpp
  12. 3
      src/domain/UBGraphicsTextItemDelegate.h
  13. 2
      src/domain/UBGraphicsVideoItemDelegate.h

@ -43,6 +43,7 @@
#include <QDomDocument> #include <QDomDocument>
#include "core/memcheck.h" #include "core/memcheck.h"
#include "qtlogger.h"
//tag names definition. Use them everiwhere! //tag names definition. Use them everiwhere!
static QString tElement = "element"; static QString tElement = "element";
@ -548,7 +549,6 @@ void UBCFFSubsetAdaptor::UBCFFSubsetReader::parseTSpan(const QDomElement &parent
QDomNode curNode = parent.firstChild(); QDomNode curNode = parent.firstChild();
while (!curNode.isNull()) { while (!curNode.isNull()) {
if (curNode.toElement().tagName() == tTspan) { if (curNode.toElement().tagName() == tTspan) {
QDomElement curTSpan = curNode.toElement(); QDomElement curTSpan = curNode.toElement();
parseTextAttributes(curTSpan, fontSize, fontColor, fontFamily, fontStretch, italic parseTextAttributes(curTSpan, fontSize, fontColor, fontFamily, fontStretch, italic
, fontWeight, textAlign, fontTransform); , fontWeight, textAlign, fontTransform);
@ -579,73 +579,77 @@ void UBCFFSubsetAdaptor::UBCFFSubsetReader::parseTSpan(const QDomElement &parent
curNode = curNode.nextSibling(); 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) bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgTextarea(const QDomElement &element)
{ {
qreal x = element.attribute(aX).toDouble(); qreal x = element.attribute(aX).toDouble();
qreal y = element.attribute(aY).toDouble(); qreal y = element.attribute(aY).toDouble();
qreal width = element.attribute(aWidth).toDouble(); qreal width = element.attribute(aWidth).toDouble();
qreal height = element.attribute(aHeight).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; readTextBlockAttr(element, blockFormat);
// QColor fontColor(qApp->palette().foreground().color()); readTextCharAttr(element, textFormat);
// 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);
// painter.setFont(QFont(fontFamily, fontSize, fontWeight, italic)); QTextDocument doc;
doc.setPlainText("");
QTextCursor tCursor(&doc);
tCursor.setBlockFormat(blockFormat);
tCursor.setCharFormat(textFormat);
// qreal curY = 0.0; parseTSpan(element, tCursor, blockFormat, textFormat);
// 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();
// QRectF lastDrawnTextBoundingRect; UBGraphicsTextItem *svgItem = mCurrentScene->addTextHtml(doc.toHtml());
// //parse text area tags svgItem->resize(width, height);
// //recursive call any tspan in text svg element QTransform transform;
// parseTSpan(element, painter QString textTransform = element.attribute(aTransform);
// , curX, curY, width, height, linespacing, lastDrawnTextBoundingRect bool hastransform = false;
// , fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform); if (!textTransform.isNull()) {
transform = transformFromString(textTransform);
// painter.end(); hastransform = true;
}
//add resulting svg file to scene
// UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName()));
QFile file("/home/ilia/Documents/tmp/1/index.html"); repositionSvgItem(svgItem, width, height, x, y, hastransform, transform);
file.open(QIODevice::ReadOnly); hashSceneItem(element, svgItem);
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);
// delete generator;
return true; return true;
} }
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgImage(const QDomElement &element) bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgImage(const QDomElement &element)

@ -34,6 +34,7 @@ class UBGraphicsItem;
class QGraphicsItem; class QGraphicsItem;
class QTextBlockFormat; class QTextBlockFormat;
class QTextCharFormat; class QTextCharFormat;
class QTextCursor;
class UBCFFSubsetAdaptor class UBCFFSubsetAdaptor
@ -100,6 +101,8 @@ private:
, qreal &curX, qreal &curY, qreal &width, qreal &height, qreal &linespacing, QRectF &lastDrawnTextBoundingRect , qreal &curX, qreal &curY, qreal &width, qreal &height, qreal &linespacing, QRectF &lastDrawnTextBoundingRect
, qreal &fontSize, QColor &fontColor, QString &fontFamily, QString &fontStretch, bool &italic , qreal &fontSize, QColor &fontColor, QString &fontFamily, QString &fontStretch, bool &italic
, int &fontWeight, int &textAlign, QTransform &fontTransform); , 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); inline void hashSceneItem(const QDomElement &element, UBGraphicsItem *item);
// to kill // to kill

@ -53,6 +53,7 @@
#include "pdf/PDFRenderer.h" #include "pdf/PDFRenderer.h"
#include "core/memcheck.h" #include "core/memcheck.h"
#include "qtlogger.h"
const QString UBSvgSubsetAdaptor::nsSvg = "http://www.w3.org/2000/svg"; const QString UBSvgSubsetAdaptor::nsSvg = "http://www.w3.org/2000/svg";
const QString UBSvgSubsetAdaptor::nsXHtml = "http://www.w3.org/1999/xhtml"; const QString UBSvgSubsetAdaptor::nsXHtml = "http://www.w3.org/1999/xhtml";
@ -2216,6 +2217,14 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::textItemToSvg(UBGraphicsTextItem* it
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri
, "fill-on-light-background", colorLightBg.name()); , "fill-on-light-background", colorLightBg.name());
//for new documents from version 4.5.0
if (true) {
mXmlWriter.writeStartElement("itemTextContent");
mXmlWriter.writeCDATA(item->toHtml());
mXmlWriter.writeEndElement(); //itemTextContent
//tracking for back capability with older versions
} else if (false) {
mXmlWriter.writeStartElement(nsXHtml, "body"); mXmlWriter.writeStartElement(nsXHtml, "body");
mXmlWriter.writeStartElement(nsXHtml, "div"); mXmlWriter.writeStartElement(nsXHtml, "div");
mXmlWriter.writeStartElement(nsXHtml, "font"); mXmlWriter.writeStartElement(nsXHtml, "font");
@ -2246,8 +2255,13 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::textItemToSvg(UBGraphicsTextItem* it
mXmlWriter.writeEndElement(); //font mXmlWriter.writeEndElement(); //font
mXmlWriter.writeEndElement(); //div mXmlWriter.writeEndElement(); //div
mXmlWriter.writeEndElement(); //body mXmlWriter.writeEndElement(); //body
}
mXmlWriter.writeEndElement(); //foreignObject mXmlWriter.writeEndElement(); //foreignObject
QtLogger::start("/home/ilia/Documents/tmp/10/log.log");
QtLogger::appendl(item->toHtml());
QtLogger::finish();
} }
UBGraphicsTextItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::textItemFromSvg() UBGraphicsTextItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::textItemFromSvg()
@ -2275,39 +2289,41 @@ UBGraphicsTextItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::textItemFromSvg()
mXmlReader.readNext(); mXmlReader.readNext();
if (mXmlReader.isStartElement()) 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(); QFont font = textItem->font();
QStringRef fontFamily = mXmlReader.attributes().value("face"); QStringRef fontFamily = mXmlReader.attributes().value("face");
if (!fontFamily.isNull()) if (!fontFamily.isNull()) {
{
font.setFamily(fontFamily.toString()); font.setFamily(fontFamily.toString());
} }
QStringRef fontStyle = mXmlReader.attributes().value("style"); QStringRef fontStyle = mXmlReader.attributes().value("style");
if (!fontStyle.isNull()) if (!fontStyle.isNull()) {
{ foreach (QString styleToken, fontStyle.toString().split(";")) {
foreach (QString styleToken, fontStyle.toString().split(";"))
{
styleToken = styleToken.trimmed(); styleToken = styleToken.trimmed();
if (styleToken.startsWith(sFontSizePrefix) && styleToken.endsWith(sPixelUnit)) if (styleToken.startsWith(sFontSizePrefix) && styleToken.endsWith(sPixelUnit)) {
{
int fontSize = styleToken.mid( int fontSize = styleToken.mid(
sFontSizePrefix.length(), sFontSizePrefix.length(),
styleToken.length() - sFontSizePrefix.length() - sPixelUnit.length()).toInt(); styleToken.length() - sFontSizePrefix.length() - sPixelUnit.length()).toInt();
font.setPixelSize(fontSize); font.setPixelSize(fontSize);
} } else if (styleToken.startsWith(sFontWeightPrefix)) {
else if (styleToken.startsWith(sFontWeightPrefix))
{
QString fontWeight = styleToken.mid( QString fontWeight = styleToken.mid(
sFontWeightPrefix.length(), sFontWeightPrefix.length(),
styleToken.length() - sFontWeightPrefix.length()); styleToken.length() - sFontWeightPrefix.length());
font.setBold(fontWeight.contains("bold")); font.setBold(fontWeight.contains("bold"));
} } else if (styleToken.startsWith(sFontStylePrefix)) {
else if (styleToken.startsWith(sFontStylePrefix))
{
QString fontStyle = styleToken.mid( QString fontStyle = styleToken.mid(
sFontStylePrefix.length(), sFontStylePrefix.length(),
styleToken.length() - sFontStylePrefix.length()); styleToken.length() - sFontStylePrefix.length());
@ -2319,15 +2335,13 @@ UBGraphicsTextItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::textItemFromSvg()
textItem->setFont(font); textItem->setFont(font);
QStringRef fill = mXmlReader.attributes().value("color"); QStringRef fill = mXmlReader.attributes().value("color");
if (!fill.isNull()) if (!fill.isNull()) {
{
QColor textColor; QColor textColor;
textColor.setNamedColor(fill.toString()); textColor.setNamedColor(fill.toString());
textItem->setDefaultTextColor(textColor); textItem->setDefaultTextColor(textColor);
} }
if (!ubFillOnDarkBackground.isNull()) if (!ubFillOnDarkBackground.isNull()) {
{
QColor color; QColor color;
color.setNamedColor(ubFillOnDarkBackground.toString()); color.setNamedColor(ubFillOnDarkBackground.toString());
if (!color.isValid()) if (!color.isValid())
@ -2335,8 +2349,7 @@ UBGraphicsTextItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::textItemFromSvg()
textItem->setColorOnDarkBackground(color); textItem->setColorOnDarkBackground(color);
} }
if (!ubFillOnLightBackground.isNull()) if (!ubFillOnLightBackground.isNull()) {
{
QColor color; QColor color;
color.setNamedColor(ubFillOnLightBackground.toString()); color.setNamedColor(ubFillOnLightBackground.toString());
if (!color.isValid()) if (!color.isValid())
@ -2344,20 +2357,16 @@ UBGraphicsTextItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::textItemFromSvg()
textItem->setColorOnLightBackground(color); textItem->setColorOnLightBackground(color);
} }
while (!(mXmlReader.isEndElement() && mXmlReader.name() == "font")) while (!(mXmlReader.isEndElement() && mXmlReader.name() == "font")) {
{ if (mXmlReader.hasError()) {
if (mXmlReader.hasError())
{
break; break;
} }
QXmlStreamReader::TokenType tt = mXmlReader.readNext(); QXmlStreamReader::TokenType tt = mXmlReader.readNext();
if (tt == QXmlStreamReader::Characters) if (tt == QXmlStreamReader::Characters) {
{
text += mXmlReader.text().toString(); text += mXmlReader.text().toString();
} }
if (mXmlReader.isStartElement() && mXmlReader.name() == "br") if (mXmlReader.isStartElement() && mXmlReader.name() == "br") {
{
text += "\n"; text += "\n";
} }
} }
@ -2365,16 +2374,16 @@ UBGraphicsTextItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::textItemFromSvg()
} }
} }
if (text.isEmpty()) if (false) {
{ if (text.isEmpty()) {
delete textItem; delete textItem;
textItem = 0; textItem = 0;
} } else {
else
{
textItem->setPlainText(text); textItem->setPlainText(text);
textItem->resize(width, height); textItem->resize(width, height);
} }
}
textItem->resize(width, height);
return textItem; return textItem;
} }
@ -2412,6 +2421,7 @@ UBGraphicsCurtainItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::curtainItemFromSvg
QRectF rect = curtainItem->rect(); QRectF rect = curtainItem->rect();
rect.setWidth(svgWidth.toString().toFloat()); rect.setWidth(svgWidth.toString().toFloat());
rect.setHeight(svgHeight.toString().toFloat()); rect.setHeight(svgHeight.toString().toFloat());
rect.translate(- rect.center());
curtainItem->setRect(rect); curtainItem->setRect(rect);

@ -92,7 +92,7 @@ class UBSvgSubsetAdaptor
UBSvgSubsetReader(UBDocumentProxy* proxy, const QByteArray& pXmlData); UBSvgSubsetReader(UBDocumentProxy* proxy, const QByteArray& pXmlData);
virtual ~UBSvgSubsetReader(){}; virtual ~UBSvgSubsetReader(){}
UBGraphicsScene* loadScene(); UBGraphicsScene* loadScene();
@ -155,7 +155,7 @@ class UBSvgSubsetAdaptor
bool persistScene(); bool persistScene();
virtual ~UBSvgSubsetWriter(){}; virtual ~UBSvgSubsetWriter(){}
private: private:

@ -22,7 +22,7 @@ class UBSettings;
class UBSetting : public QObject class UBSetting : public QObject
{ {
Q_OBJECT; Q_OBJECT
public: public:
UBSetting(UBSettings* parent = 0); UBSetting(UBSettings* parent = 0);
@ -71,7 +71,7 @@ class UBSetting : public QObject
class UBColorListSetting : public UBSetting class UBColorListSetting : public UBSetting
{ {
Q_OBJECT; Q_OBJECT
public: public:
UBColorListSetting(UBSettings* parent = 0); UBColorListSetting(UBSettings* parent = 0);

@ -112,8 +112,6 @@ void UBSettings::destroy()
} }
QSettings* UBSettings::getAppSettings() QSettings* UBSettings::getAppSettings()
{ {
if (!UBSettings::sAppSettings) if (!UBSettings::sAppSettings)
@ -689,6 +687,15 @@ void UBSettings::setFontPixelSize(int pixelSize)
setValue("Board/FontPixelSize", 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() bool UBSettings::isBoldFont()
{ {

@ -75,6 +75,8 @@ class UBSettings : public QObject
void setFontFamily(const QString &family); void setFontFamily(const QString &family);
int fontPixelSize(); int fontPixelSize();
void setFontPixelSize(int pixelSize); void setFontPixelSize(int pixelSize);
int fontPointSize();
void setFontPointSize(int pointSize);
bool isBoldFont(); bool isBoldFont();
void setBoldFont(bool bold); void setBoldFont(bool bold);
bool isItalicFont(); bool isItalicFont();

@ -163,8 +163,9 @@ bool UBGraphicsItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event)
qDebug() << mDelegated->zValue(); qDebug() << mDelegated->zValue();
qDebug() << scene->currentObjectZIndex(); qDebug() << scene->currentObjectZIndex();
if (mDelegated->zValue() < scene->currentObjectZIndex() && !isLocked()) // To investigate. Z value behavior
mDelegated->setZValue(scene->getNextObjectZIndex()); // if (mDelegated->zValue() < scene->currentObjectZIndex() && !isLocked())
// mDelegated->setZValue(scene->getNextObjectZIndex());
positionHandles(); positionHandles();

@ -1316,6 +1316,7 @@ UBGraphicsTextItem *UBGraphicsScene::addTextHtml(const QString &pString)
UBGraphicsTextItem *textItem = new UBGraphicsTextItem(); UBGraphicsTextItem *textItem = new UBGraphicsTextItem();
textItem->setPlainText(""); textItem->setPlainText("");
textItem->setHtml(pString); textItem->setHtml(pString);
textItem->setZValue(getNextObjectZIndex());
addItem(textItem); addItem(textItem);
textItem->show(); textItem->show();
@ -1323,9 +1324,10 @@ UBGraphicsTextItem *UBGraphicsScene::addTextHtml(const QString &pString)
UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, 0, textItem); UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, 0, textItem);
UBApplication::undoStack->push(uc); 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(); textItem->setFocus();
setDocumentUpdated(); setDocumentUpdated();

@ -40,20 +40,20 @@ UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent)
mTypeTextHereLabel = tr("<Type Text Here>"); mTypeTextHereLabel = tr("<Type Text Here>");
if (lastUsedTextColor.isValid()) // if (lastUsedTextColor.isValid())
{ // {
setDefaultTextColor(lastUsedTextColor); // setDefaultTextColor(lastUsedTextColor);
setColorOnDarkBackground(lastUsedTextColor); // setColorOnDarkBackground(lastUsedTextColor);
setColorOnLightBackground(lastUsedTextColor); // setColorOnLightBackground(lastUsedTextColor);
} // }
else // else
{ // {
QColor colorOnDarkBG = UBApplication::boardController->penColorOnDarkBackground(); // QColor colorOnDarkBG = UBApplication::boardController->penColorOnDarkBackground();
QColor colorOnLightBG = UBApplication::boardController->penColorOnLightBackground(); // QColor colorOnLightBG = UBApplication::boardController->penColorOnLightBackground();
setColorOnDarkBackground(colorOnDarkBG); // setColorOnDarkBackground(colorOnDarkBG);
setColorOnLightBackground(colorOnLightBG); // setColorOnLightBackground(colorOnLightBG);
} // }
setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);
// setData(UBGraphicsItemData::ItemEditable, QVariant(true)); // setData(UBGraphicsItemData::ItemEditable, QVariant(true));

@ -35,6 +35,33 @@ UBGraphicsTextItemDelegate::UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDele
: UBGraphicsItemDelegate(pDelegated,0, parent, true) : UBGraphicsItemDelegate(pDelegated,0, parent, true)
, mLastFontPixelSize(-1) , 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 // 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() void UBGraphicsTextItemDelegate::buildButtons()
{ {
UBGraphicsItemDelegate::buildButtons(); UBGraphicsItemDelegate::buildButtons();
@ -128,7 +181,7 @@ void UBGraphicsTextItemDelegate::pickFont()
{ {
if (mDelegated && mDelegated->scene() && mDelegated->scene()->views().size() > 0) 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); customize(fontDialog);
if (fontDialog.exec()) if (fontDialog.exec())
@ -140,6 +193,7 @@ void UBGraphicsTextItemDelegate::pickFont()
UBSettings::settings()->setFontPixelSize(mLastFontPixelSize); UBSettings::settings()->setFontPixelSize(mLastFontPixelSize);
UBSettings::settings()->setBoldFont(selectedFont.bold()); UBSettings::settings()->setBoldFont(selectedFont.bold());
UBSettings::settings()->setItalicFont(selectedFont.italic()); UBSettings::settings()->setItalicFont(selectedFont.italic());
UBSettings::settings()->setFontPointSize(selectedFont.pointSize());
//setting format for selected item //setting format for selected item
QTextCursor curCursor = delegated()->textCursor(); QTextCursor curCursor = delegated()->textCursor();
@ -192,54 +246,54 @@ void UBGraphicsTextItemDelegate::pickColor()
void UBGraphicsTextItemDelegate::decreaseSize() void UBGraphicsTextItemDelegate::decreaseSize()
{ {
QFontInfo fi(delegated()->font()); // QFontInfo fi(delegated()->font());
int pixelSize = fi.pixelSize(); // int pixelSize = fi.pixelSize();
if (-1 == mLastFontPixelSize) // if (-1 == mLastFontPixelSize)
mLastFontPixelSize = pixelSize; // mLastFontPixelSize = pixelSize;
int newPixelSize = sMinPixelSize; // int newPixelSize = sMinPixelSize;
while (newPixelSize * 1.5 < pixelSize) // while (newPixelSize * 1.5 < pixelSize)
newPixelSize *= 1.5; // newPixelSize *= 1.5;
if (newPixelSize < mLastFontPixelSize && mLastFontPixelSize < pixelSize) // if (newPixelSize < mLastFontPixelSize && mLastFontPixelSize < pixelSize)
newPixelSize = mLastFontPixelSize; // newPixelSize = mLastFontPixelSize;
if (pixelSize > newPixelSize) // if (pixelSize > newPixelSize)
{ // {
QFont font = delegated()->font(); // QFont font = delegated()->font();
font.setPixelSize(newPixelSize); // font.setPixelSize(newPixelSize);
delegated()->setFont(font); // delegated()->setFont(font);
UBSettings::settings()->setFontPixelSize(newPixelSize); // UBSettings::settings()->setFontPixelSize(newPixelSize);
delegated()->document()->adjustSize(); // delegated()->document()->adjustSize();
delegated()->contentsChanged(); // delegated()->contentsChanged();dddd
} // }
} }
void UBGraphicsTextItemDelegate::increaseSize() void UBGraphicsTextItemDelegate::increaseSize()
{ {
QFontInfo fi(delegated()->font()); // QFontInfo fi(delegated()->font());
int pixelSize = fi.pixelSize(); // int pixelSize = fi.pixelSize();
if (-1 == mLastFontPixelSize) // if (-1 == mLastFontPixelSize)
mLastFontPixelSize = pixelSize; // mLastFontPixelSize = pixelSize;
int newPixelSize = sMinPixelSize; // int newPixelSize = sMinPixelSize;
while (newPixelSize <= pixelSize) // while (newPixelSize <= pixelSize)
newPixelSize *= 1.5; // newPixelSize *= 1.5;
if (pixelSize < mLastFontPixelSize && mLastFontPixelSize < newPixelSize) // if (pixelSize < mLastFontPixelSize && mLastFontPixelSize < newPixelSize)
newPixelSize = mLastFontPixelSize; // newPixelSize = mLastFontPixelSize;
QFont font = delegated()->font(); // QFont font = delegated()->font();
font.setPixelSize(newPixelSize); // font.setPixelSize(newPixelSize);
delegated()->setFont(font); // delegated()->setFont(font);
UBSettings::settings()->setFontPixelSize(newPixelSize); // UBSettings::settings()->setFontPixelSize(newPixelSize);
delegated()->document()->adjustSize(); // delegated()->document()->adjustSize();
delegated()->contentsChanged(); // delegated()->contentsChanged();
qDebug() << newPixelSize; // qDebug() << newPixelSize;
delegated()->document()->adjustSize();
} }
UBGraphicsTextItem* UBGraphicsTextItemDelegate::delegated() UBGraphicsTextItem* UBGraphicsTextItemDelegate::delegated()
@ -270,10 +324,15 @@ void UBGraphicsTextItemDelegate::decorateMenu(QMenu *menu)
mEditableAction = menu->addAction(tr("Editable"), this, SLOT(setEditable(bool))); mEditableAction = menu->addAction(tr("Editable"), this, SLOT(setEditable(bool)));
mEditableAction->setCheckable(true); mEditableAction->setCheckable(true);
mEditableAction->setChecked(true); mEditableAction->setChecked(isEditable());
} }
void UBGraphicsTextItemDelegate::updateMenuActionState() void UBGraphicsTextItemDelegate::updateMenuActionState()
{ {
UBGraphicsItemDelegate::updateMenuActionState(); UBGraphicsItemDelegate::updateMenuActionState();
} }
void UBGraphicsTextItemDelegate::positionHandles()
{
UBGraphicsItemDelegate::positionHandles();
setEditable(isEditable());
}

@ -43,6 +43,8 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate
virtual void decorateMenu(QMenu *menu); virtual void decorateMenu(QMenu *menu);
virtual void updateMenuActionState(); virtual void updateMenuActionState();
virtual void positionHandles();
private: private:
UBGraphicsTextItem* delegated(); UBGraphicsTextItem* delegated();
@ -58,6 +60,7 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate
private: private:
void customize(QFontDialog &fontDialog); void customize(QFontDialog &fontDialog);
QFont createDefaultFont();
QAction *mEditableAction; QAction *mEditableAction;
private slots: private slots:

@ -68,7 +68,7 @@ class DelegateVideoControl: public QGraphicsRectItem
class UBGraphicsVideoItemDelegate : public UBGraphicsItemDelegate class UBGraphicsVideoItemDelegate : public UBGraphicsItemDelegate
{ {
Q_OBJECT; Q_OBJECT
public: public:
UBGraphicsVideoItemDelegate(UBGraphicsVideoItem* pDelegated, Phonon::MediaObject* pMedia, QObject * parent = 0); UBGraphicsVideoItemDelegate(UBGraphicsVideoItem* pDelegated, Phonon::MediaObject* pMedia, QObject * parent = 0);

Loading…
Cancel
Save