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. 134
      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 "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)

@ -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

@ -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);

@ -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:

@ -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);

@ -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()
{

@ -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();

@ -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();

@ -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();

@ -40,20 +40,20 @@ UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent)
mTypeTextHereLabel = tr("<Type Text Here>");
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));

@ -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());
}

@ -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:

@ -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);

Loading…
Cancel
Save