Merge branch 'master' of github.com:Sankore/Sankore-3.1

preferencesAboutTextFull
shibakaneki 13 years ago
commit 5458a2733c
  1. 117
      src/adaptors/UBCFFSubsetAdaptor.cpp
  2. 5
      src/adaptors/UBCFFSubsetAdaptor.h
  3. 1
      src/adaptors/UBSvgSubsetAdaptor.cpp
  4. 4
      src/adaptors/UBSvgSubsetAdaptor.h
  5. 4
      src/core/UB.h
  6. 1
      src/domain/UBGraphicsItemDelegate.h
  7. 20
      src/domain/UBGraphicsScene.cpp
  8. 1
      src/domain/UBGraphicsScene.h
  9. 23
      src/domain/UBGraphicsTextItem.cpp
  10. 59
      src/domain/UBGraphicsTextItemDelegate.cpp
  11. 7
      src/domain/UBGraphicsTextItemDelegate.h

@ -27,6 +27,7 @@
#include "domain/UBGraphicsVideoItem.h" #include "domain/UBGraphicsVideoItem.h"
#include "domain/UBGraphicsAudioItem.h" #include "domain/UBGraphicsAudioItem.h"
#include "domain/UBGraphicsWidgetItem.h" #include "domain/UBGraphicsWidgetItem.h"
#include "domain/UBGraphicsTextItem.h"
#include "domain/UBW3CWidget.h" #include "domain/UBW3CWidget.h"
#include "frameworks/UBFileSystemUtils.h" #include "frameworks/UBFileSystemUtils.h"
@ -440,6 +441,49 @@ void UBCFFSubsetAdaptor::UBCFFSubsetReader::parseTextAttributes(const QDomElemen
if (!element.attribute(aTransform).isNull()) if (!element.attribute(aTransform).isNull())
fontTransform = transformFromString(element.attribute(aTransform)); fontTransform = transformFromString(element.attribute(aTransform));
} }
void UBCFFSubsetAdaptor::UBCFFSubsetReader::readTextBlockAttr(const QDomElement &element, QTextBlockFormat &format)
{
QString fontStretchText = element.attribute(aFontstretch);
if (!fontStretchText.isNull()) format.setAlignment(Qt::AlignJustify);
QString align = element.attribute(aTextalign);
if (!align.isNull()) {
if (align == "middle" || align == "center") format.setAlignment(Qt::AlignHCenter);
else if (align == "start") format.setAlignment(Qt::AlignLeft);
else if (align == "end") format.setAlignment(Qt::AlignRight);
else if (align == "justify") format.setAlignment(Qt::AlignJustify);
}
}
void UBCFFSubsetAdaptor::UBCFFSubsetReader::readTextCharAttr(const QDomElement &element, QTextCharFormat &format)
{
QString fontSz = element.attribute(aFontSize);
if (!fontSz.isNull()) {
qreal fontSize = fontSz.toDouble() * 72 / QApplication::desktop()->physicalDpiY();
format.setFontPointSize(fontSize);
}
QString fontColorText = element.attribute(aFill);
if (!fontColorText.isNull()) {
QColor fontColor = colorFromString(fontColorText);
if (fontColor.isValid()) format.setForeground(fontColor);
}
QString fontFamilyText = element.attribute(aFontfamily);
if (!fontFamilyText.isNull()) {
format.setFontFamily(fontFamilyText);
}
if (!element.attribute(aFontstyle).isNull()) {
bool italic = (element.attribute(aFontstyle) == "italic");
format.setFontItalic(italic);
}
QString weight = element.attribute(aFontweight);
if (!weight.isNull()) {
if (weight == "normal") format.setFontWeight(QFont::Normal);
else if (weight == "light") format.setFontWeight(QFont::Light);
else if (weight == "demibold") format.setFontWeight(QFont::DemiBold);
else if (weight == "bold") format.setFontWeight(QFont::Bold);
else if (weight == "black") format.setFontWeight(QFont::Black);
}
}
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgText(const QDomElement &element) bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgText(const QDomElement &element)
{ {
qreal x = element.attribute(aX).toDouble(); qreal x = element.attribute(aX).toDouble();
@ -538,53 +582,70 @@ void UBCFFSubsetAdaptor::UBCFFSubsetReader::parseTSpan(const QDomElement &parent
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();
qreal fontSize = 12;
QColor fontColor(qApp->palette().foreground().color());
QString fontFamily = "Arial"; // qreal fontSize = 12;
QString fontStretch = "normal"; // QColor fontColor(qApp->palette().foreground().color());
bool italic = false; // QString fontFamily = "Arial";
int fontWeight = QFont::Normal; // QString fontStretch = "normal";
int textAlign = Qt::AlignLeft; // bool italic = false;
// int fontWeight = QFont::Normal;
// int textAlign = Qt::AlignLeft;
QTransform fontTransform; QTransform fontTransform;
parseTextAttributes(element, fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform); // parseTextAttributes(element, fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform);
QSvgGenerator *generator = createSvgGenerator(width, height); // QSvgGenerator *generator = createSvgGenerator(width, height);
QPainter painter; // QPainter painter;
painter.begin(generator); // painter.begin(generator);
painter.setFont(QFont(fontFamily, fontSize, fontWeight, italic)); // painter.setFont(QFont(fontFamily, fontSize, fontWeight, italic));
qreal curY = 0.0; // qreal curY = 0.0;
qreal curX = 0.0; // qreal curX = 0.0;
qreal linespacing = QFontMetricsF(painter.font()).leading(); // qreal linespacing = QFontMetricsF(painter.font()).leading();
// remember if text area has transform //// remember if text area has transform
// QString transformString; //// QString transformString;
QTransform transform = fontTransform; QTransform transform = fontTransform;
bool hasTransform = !fontTransform.isIdentity(); bool hasTransform = false;//!fontTransform.isIdentity();
QRectF lastDrawnTextBoundingRect; // QRectF lastDrawnTextBoundingRect;
//parse text area tags // //parse text area tags
//recursive call any tspan in text svg element // //recursive call any tspan in text svg element
parseTSpan(element, painter // parseTSpan(element, painter
, curX, curY, width, height, linespacing, lastDrawnTextBoundingRect // , curX, curY, width, height, linespacing, lastDrawnTextBoundingRect
, fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform); // , fontSize, fontColor, fontFamily, fontStretch, italic, fontWeight, textAlign, fontTransform);
painter.end(); // painter.end();
//add resulting svg file to scene //add resulting svg file to scene
UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName())); // UBGraphicsSvgItem *svgItem = mCurrentScene->addSvg(QUrl::fromLocalFile(generator->fileName()));
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); repositionSvgItem(svgItem, width, height, x, y, hasTransform, transform);
hashSceneItem(element, svgItem); // hashSceneItem(element, svgItem);
delete generator; // delete generator;
return true; return true;
} }
bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgImage(const QDomElement &element) bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgImage(const QDomElement &element)

@ -32,6 +32,8 @@ class QTransform;
class QPainter; class QPainter;
class UBGraphicsItem; class UBGraphicsItem;
class QGraphicsItem; class QGraphicsItem;
class QTextBlockFormat;
class QTextCharFormat;
class UBCFFSubsetAdaptor class UBCFFSubsetAdaptor
@ -104,6 +106,9 @@ private:
inline void parseTextAttributes(const QDomElement &element, qreal &fontSize, QColor &fontColor, inline void parseTextAttributes(const QDomElement &element, qreal &fontSize, QColor &fontColor,
QString &fontFamily, QString &fontStretch, bool &italic, QString &fontFamily, QString &fontStretch, bool &italic,
int &fontWeight, int &textAlign, QTransform &fontTransform); int &fontWeight, int &textAlign, QTransform &fontTransform);
inline void parseTextAttributes(const QDomElement &element, QFont &font, QColor);
inline void readTextBlockAttr(const QDomElement &element, QTextBlockFormat &format);
inline void readTextCharAttr(const QDomElement &element, QTextCharFormat &format);
//elements parsing methods //elements parsing methods
bool parseDoc(); bool parseDoc();

@ -76,7 +76,6 @@ QString UBSvgSubsetAdaptor::toSvgTransform(const QMatrix& matrix)
.arg(matrix.m22(), 0 , 'g') .arg(matrix.m22(), 0 , 'g')
.arg(matrix.dx(), 0 , 'g') .arg(matrix.dx(), 0 , 'g')
.arg(matrix.dy(), 0 , 'g'); .arg(matrix.dy(), 0 , 'g');
} }

@ -46,8 +46,8 @@ class UBSvgSubsetAdaptor
{ {
private: private:
UBSvgSubsetAdaptor() {}; UBSvgSubsetAdaptor() {;}
virtual ~UBSvgSubsetAdaptor() {}; virtual ~UBSvgSubsetAdaptor() {;}
public: public:

@ -75,7 +75,9 @@ struct UBGraphicsItemData
{ {
enum Enum enum Enum
{ {
ItemLayerType, ItemLocked ItemLayerType
, ItemLocked
, ItemEditable//for text only
}; };
}; };

@ -169,7 +169,6 @@ class UBGraphicsItemDelegate : public QObject
virtual void gotoContentSource(bool checked); virtual void gotoContentSource(bool checked);
private: private:
QPointF mOffset; QPointF mOffset;

@ -1311,7 +1311,27 @@ UBGraphicsTextItem* UBGraphicsScene::addTextWithFont(const QString& pString, con
return textItem; return textItem;
} }
UBGraphicsTextItem *UBGraphicsScene::addTextHtml(const QString &pString)
{
UBGraphicsTextItem *textItem = new UBGraphicsTextItem();
textItem->setPlainText("");
textItem->setHtml(pString);
addItem(textItem);
textItem->show();
UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, 0, textItem);
UBApplication::undoStack->push(uc);
connect(textItem, SIGNAL(textUndoCommandAdded(UBGraphicsTextItem *)), this, SLOT(textUndoCommandAdded(UBGraphicsTextItem *)));
textItem->setSelected(true);
textItem->setFocus();
setDocumentUpdated();
return textItem;
}
void UBGraphicsScene::addItem(QGraphicsItem* item) void UBGraphicsScene::addItem(QGraphicsItem* item)
{ {

@ -91,6 +91,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
UBGraphicsTextItem* addTextWithFont(const QString& pString, const QPointF& pTopLeft = QPointF(0, 0) UBGraphicsTextItem* addTextWithFont(const QString& pString, const QPointF& pTopLeft = QPointF(0, 0)
, int pointSize = -1, const QString& fontFamily = "", bool bold = false, bool italic = false); , int pointSize = -1, const QString& fontFamily = "", bool bold = false, bool italic = false);
UBGraphicsTextItem* addTextHtml(const QString &pString = QString());
UBGraphicsW3CWidgetItem* addOEmbed(const QUrl& pContentUrl, const QPointF& pPos = QPointF(0, 0)); UBGraphicsW3CWidgetItem* addOEmbed(const QUrl& pContentUrl, const QPointF& pPos = QPointF(0, 0));

@ -56,8 +56,10 @@ UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent)
} }
setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object);
// setData(UBGraphicsItemData::ItemEditable, QVariant(true));
setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemIsSelectable, true);
// setFlag(QGraphicsItem::ItemIsMovable, true);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
setTextInteractionFlags(Qt::TextEditorInteraction); setTextInteractionFlags(Qt::TextEditorInteraction);
@ -65,11 +67,11 @@ UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent)
connect(document(), SIGNAL(contentsChanged()), mDelegate, SLOT(contentsChanged())); connect(document(), SIGNAL(contentsChanged()), mDelegate, SLOT(contentsChanged()));
connect(document(), SIGNAL(undoCommandAdded()), this, SLOT(undoCommandAdded())); connect(document(), SIGNAL(undoCommandAdded()), this, SLOT(undoCommandAdded()));
connect(document()->documentLayout(), SIGNAL(documentSizeChanged(const QSizeF &)), this, SLOT(documentSizeChanged(const QSizeF &))); connect(document()->documentLayout(), SIGNAL(documentSizeChanged(const QSizeF &)),
this, SLOT(documentSizeChanged(const QSizeF &)));
} }
UBGraphicsTextItem::~UBGraphicsTextItem() UBGraphicsTextItem::~UBGraphicsTextItem()
{ {
if (mDelegate) if (mDelegate)
@ -78,7 +80,6 @@ UBGraphicsTextItem::~UBGraphicsTextItem()
} }
} }
QVariant UBGraphicsTextItem::itemChange(GraphicsItemChange change, const QVariant &value) QVariant UBGraphicsTextItem::itemChange(GraphicsItemChange change, const QVariant &value)
{ {
if (QGraphicsItem::ItemSelectedChange == change) if (QGraphicsItem::ItemSelectedChange == change)
@ -106,9 +107,14 @@ QVariant UBGraphicsTextItem::itemChange(GraphicsItemChange change, const QVarian
return QGraphicsTextItem::itemChange(change, newValue); return QGraphicsTextItem::itemChange(change, newValue);
} }
void UBGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
if (mDelegate)
mDelegate->mousePressEvent(event);
if (!data(UBGraphicsItemData::ItemEditable).toBool())
return;
int elapsed = mLastMousePressTime.msecsTo(QTime::currentTime()); int elapsed = mLastMousePressTime.msecsTo(QTime::currentTime());
if (elapsed < UBApplication::app()->doubleClickInterval()) if (elapsed < UBApplication::app()->doubleClickInterval())
@ -126,12 +132,8 @@ void UBGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
if (mMultiClickState == 1) if (mMultiClickState == 1)
{ {
if (mDelegate) // setTextInteractionFlags(Qt::TextEditorInteraction);
mDelegate->mousePressEvent(event);
QGraphicsTextItem::mousePressEvent(event); QGraphicsTextItem::mousePressEvent(event);
setTextInteractionFlags(Qt::TextEditorInteraction);
setFocus(); setFocus();
} }
else if (mMultiClickState == 2) else if (mMultiClickState == 2)
@ -152,7 +154,6 @@ void UBGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
} }
} }
void UBGraphicsTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{ {
if (!mDelegate || !mDelegate->mouseMoveEvent(event)) if (!mDelegate || !mDelegate->mouseMoveEvent(event))
@ -161,7 +162,6 @@ void UBGraphicsTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
} }
} }
void UBGraphicsTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
if (mMultiClickState == 1) if (mMultiClickState == 1)
@ -177,7 +177,6 @@ void UBGraphicsTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
} }
} }
void UBGraphicsTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void UBGraphicsTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
QColor color = UBSettings::settings()->isDarkBackground() ? mColorOnDarkBackground : mColorOnLightBackground; QColor color = UBSettings::settings()->isDarkBackground() ? mColorOnDarkBackground : mColorOnLightBackground;

@ -27,6 +27,7 @@
#include "core/UBDisplayManager.h" // TODO UB 4.x clean that dependency #include "core/UBDisplayManager.h" // TODO UB 4.x clean that dependency
#include "core/memcheck.h" #include "core/memcheck.h"
#include "board/UBBoardController.h"
const int UBGraphicsTextItemDelegate::sMinPixelSize = 8; const int UBGraphicsTextItemDelegate::sMinPixelSize = 8;
@ -139,16 +140,21 @@ 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());
delegated()->setFont(selectedFont);
delegated()->setSelected(true);
//setting format for selected item
QTextCursor curCursor = delegated()->textCursor();
QTextCharFormat format;
format.setFont(selectedFont);
curCursor.mergeCharFormat(format);
delegated()->setTextCursor(curCursor);
delegated()->setSelected(true);
delegated()->document()->adjustSize(); delegated()->document()->adjustSize();
delegated()->contentsChanged(); delegated()->contentsChanged();
} }
} }
} }
void UBGraphicsTextItemDelegate::pickColor() void UBGraphicsTextItemDelegate::pickColor()
{ {
if (mDelegated && mDelegated->scene() && mDelegated->scene()->views().size() > 0) if (mDelegated && mDelegated->scene() && mDelegated->scene()->views().size() > 0)
@ -164,8 +170,17 @@ void UBGraphicsTextItemDelegate::pickColor()
{ {
QColor selectedColor = colorDialog.selectedColor(); QColor selectedColor = colorDialog.selectedColor();
delegated()->setDefaultTextColor(selectedColor); delegated()->setDefaultTextColor(selectedColor);
delegated()->setColorOnDarkBackground(selectedColor); // delegated()->setColorOnDarkBackground(selectedColor);
delegated()->setColorOnLightBackground(selectedColor); // delegated()->setColorOnLightBackground(selectedColor);
QTextCursor curCursor = delegated()->textCursor();
QTextCharFormat format;
format.setForeground(QBrush(selectedColor));
// format.setBackground(Qt::yellow);
curCursor.mergeCharFormat(format);
QTextBlockFormat blFormat;
blFormat.setAlignment(Qt::AlignCenter);
curCursor.setBlockFormat(blFormat);
delegated()->setTextCursor(curCursor);
UBGraphicsTextItem::lastUsedTextColor = selectedColor; UBGraphicsTextItem::lastUsedTextColor = selectedColor;
@ -175,7 +190,6 @@ void UBGraphicsTextItemDelegate::pickColor()
} }
} }
void UBGraphicsTextItemDelegate::decreaseSize() void UBGraphicsTextItemDelegate::decreaseSize()
{ {
QFontInfo fi(delegated()->font()); QFontInfo fi(delegated()->font());
@ -203,7 +217,6 @@ void UBGraphicsTextItemDelegate::decreaseSize()
} }
void UBGraphicsTextItemDelegate::increaseSize() void UBGraphicsTextItemDelegate::increaseSize()
{ {
QFontInfo fi(delegated()->font()); QFontInfo fi(delegated()->font());
@ -229,8 +242,38 @@ void UBGraphicsTextItemDelegate::increaseSize()
qDebug() << newPixelSize; qDebug() << newPixelSize;
} }
UBGraphicsTextItem* UBGraphicsTextItemDelegate::delegated() UBGraphicsTextItem* UBGraphicsTextItemDelegate::delegated()
{ {
return static_cast<UBGraphicsTextItem*>(mDelegated); return static_cast<UBGraphicsTextItem*>(mDelegated);
} }
void UBGraphicsTextItemDelegate::setEditable(bool editable)
{
if (editable) {
delegated()->setTextInteractionFlags(Qt::TextEditorInteraction);
mDelegated->setData(UBGraphicsItemData::ItemEditable, QVariant(true));
} else {
QTextCursor cursor(delegated()->document());
cursor.clearSelection();
delegated()->setTextCursor(cursor);
delegated()->setTextInteractionFlags(Qt::NoTextInteraction);
mDelegated->setData(UBGraphicsItemData::ItemEditable, QVariant(false));
}
}
bool UBGraphicsTextItemDelegate::isEditable()
{
return mDelegated->data(UBGraphicsItemData::ItemEditable).toBool();
}
void UBGraphicsTextItemDelegate::decorateMenu(QMenu *menu)
{
UBGraphicsItemDelegate::decorateMenu(menu);
mEditableAction = menu->addAction(tr("Editable"), this, SLOT(setEditable(bool)));
mEditableAction->setCheckable(true);
mEditableAction->setChecked(true);
}
void UBGraphicsTextItemDelegate::updateMenuActionState()
{
UBGraphicsItemDelegate::updateMenuActionState();
}

@ -27,17 +27,21 @@ class UBGraphicsTextItem;
class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate
{ {
Q_OBJECT; Q_OBJECT
public: public:
UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDelegated, QObject * parent = 0); UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDelegated, QObject * parent = 0);
virtual ~UBGraphicsTextItemDelegate(); virtual ~UBGraphicsTextItemDelegate();
bool isEditable();
public slots: public slots:
void contentsChanged(); void contentsChanged();
virtual void setEditable(bool);
protected: protected:
virtual void buildButtons(); virtual void buildButtons();
virtual void decorateMenu(QMenu *menu);
virtual void updateMenuActionState();
private: private:
@ -54,6 +58,7 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate
private: private:
void customize(QFontDialog &fontDialog); void customize(QFontDialog &fontDialog);
QAction *mEditableAction;
private slots: private slots:

Loading…
Cancel
Save