Merge branch 'develop' of github.com:OpenEducationFoundation/OpenBoard into develop

preferencesAboutTextFull
Claudio Valerio 11 years ago
commit ec85baff3f
  1. 17
      src/adaptors/UBSvgSubsetAdaptor.cpp
  2. 8
      src/board/UBBoardController.cpp
  3. 2
      src/board/UBBoardPaletteManager.cpp
  4. 2
      src/core/UBSettings.cpp
  5. 2
      src/core/UBSettings.h
  6. 15
      src/domain/UBGraphicsGroupContainerItem.cpp
  7. 9
      src/domain/UBGraphicsItemDelegate.cpp
  8. 1
      src/domain/UBGraphicsItemDelegate.h
  9. 2
      src/domain/UBGraphicsItemZLevelUndoCommand.cpp
  10. 269
      src/domain/UBGraphicsTextItemDelegate.cpp
  11. 90
      src/domain/UBGraphicsTextItemDelegate.h
  12. 9
      src/domain/UBGraphicsWidgetItem.cpp
  13. 5
      src/domain/UBItem.cpp
  14. 1
      src/domain/UBItem.h
  15. 6
      src/gui/UBDocumentTreeWidget.cpp

@ -42,6 +42,7 @@
#include "domain/UBGraphicsStroke.h" #include "domain/UBGraphicsStroke.h"
#include "domain/UBGraphicsStrokesGroup.h" #include "domain/UBGraphicsStrokesGroup.h"
#include "domain/UBGraphicsGroupContainerItem.h" #include "domain/UBGraphicsGroupContainerItem.h"
#include "domain/UBGraphicsGroupContainerItemDelegate.h"
#include "domain/UBItem.h" #include "domain/UBItem.h"
#include "tools/UBGraphicsRuler.h" #include "tools/UBGraphicsRuler.h"
@ -924,7 +925,13 @@ void UBSvgSubsetAdaptor::UBSvgSubsetReader::readGroupRoot()
} }
else if (mXmlReader.isStartElement()) { else if (mXmlReader.isStartElement()) {
if (mXmlReader.name() == tGroup) { if (mXmlReader.name() == tGroup) {
QString ubLocked = mXmlReader.attributes().value(UBSettings::uniboardDocumentNamespaceUri, "locked").toString();
UBGraphicsGroupContainerItem *curGroup = readGroup(); UBGraphicsGroupContainerItem *curGroup = readGroup();
if (!ubLocked.isEmpty())
{
bool isLocked = ubLocked.contains(xmlTrue);
curGroup->Delegate()->setLocked(isLocked);
}
if (curGroup) { if (curGroup) {
mScene->addGroup(curGroup); mScene->addGroup(curGroup);
} }
@ -1276,6 +1283,9 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex)
if (curElement.hasAttribute(aId)) { if (curElement.hasAttribute(aId)) {
mXmlWriter.writeStartElement(curElement.tagName()); mXmlWriter.writeStartElement(curElement.tagName());
mXmlWriter.writeAttribute(aId, curElement.attribute(aId)); mXmlWriter.writeAttribute(aId, curElement.attribute(aId));
if(curElement.hasAttribute("locked")){
mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri,"locked",curElement.attribute("locked"));
}
QDomElement curSubElement = curElement.firstChildElement(); QDomElement curSubElement = curElement.firstChildElement();
while (!curSubElement.isNull()) { while (!curSubElement.isNull()) {
if (curSubElement.hasAttribute(aId)) { if (curSubElement.hasAttribute(aId)) {
@ -1320,6 +1330,13 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistGroupToDom(QGraphicsItem *gro
if (!uuid.isNull()) { if (!uuid.isNull()) {
QDomElement curGroupElement = groupDomDocument->createElement(tGroup); QDomElement curGroupElement = groupDomDocument->createElement(tGroup);
curGroupElement.setAttribute(aId, uuid); curGroupElement.setAttribute(aId, uuid);
UBGraphicsGroupContainerItem* group = dynamic_cast<UBGraphicsGroupContainerItem*>(groupItem);
if(group && group->Delegate()){
if(group->Delegate()->isLocked())
curGroupElement.setAttribute("locked", xmlTrue);
else
curGroupElement.setAttribute("locked", xmlFalse);
}
curParent->appendChild(curGroupElement); curParent->appendChild(curGroupElement);
foreach (QGraphicsItem *item, groupItem->childItems()) { foreach (QGraphicsItem *item, groupItem->childItems()) {
QUuid tmpUuid = UBGraphicsScene::getPersonalUuid(item); QUuid tmpUuid = UBGraphicsScene::getPersonalUuid(item);

@ -1634,7 +1634,7 @@ void UBBoardController::adjustDisplayViews()
int UBBoardController::autosaveTimeoutFromSettings() int UBBoardController::autosaveTimeoutFromSettings()
{ {
int value = UBSettings::settings()->timerInterval->get().toInt(); int value = UBSettings::settings()->autoSaveInterval->get().toInt();
int minute = 60 * 1000; int minute = 60 * 1000;
return value * minute; return value * minute;
@ -1773,8 +1773,8 @@ void UBBoardController::autosaveTimeout()
void UBBoardController::appMainModeChanged(UBApplicationController::MainMode md) void UBBoardController::appMainModeChanged(UBApplicationController::MainMode md)
{ {
int timerInterval = autosaveTimeoutFromSettings(); int autoSaveInterval = autosaveTimeoutFromSettings();
if (!timerInterval) { if (!autoSaveInterval) {
return; return;
} }
@ -1784,7 +1784,7 @@ void UBBoardController::appMainModeChanged(UBApplicationController::MainMode md)
} }
if (md == UBApplicationController::Board) { if (md == UBApplicationController::Board) {
mAutosaveTimer->start(timerInterval); mAutosaveTimer->start(autoSaveInterval);
} else if (mAutosaveTimer->isActive()) { } else if (mAutosaveTimer->isActive()) {
mAutosaveTimer->stop(); mAutosaveTimer->stop();
} }

@ -243,7 +243,7 @@ void UBBoardPaletteManager::setupPalettes()
mStylusPalette->stackUnder(mZoomPalette); mStylusPalette->stackUnder(mZoomPalette);
mTipPalette = new UBStartupHintsPalette(mContainer); //mTipPalette = new UBStartupHintsPalette(mContainer);
QList<QAction*> backgroundsActions; QList<QAction*> backgroundsActions;
backgroundsActions << UBApplication::mainWindow->actionPlainLightBackground; backgroundsActions << UBApplication::mainWindow->actionPlainLightBackground;

@ -353,7 +353,7 @@ void UBSettings::init()
boardShowToolsPalette = new UBSetting(this, "Board", "ShowToolsPalette", "false"); boardShowToolsPalette = new UBSetting(this, "Board", "ShowToolsPalette", "false");
magnifierDrawingMode = new UBSetting(this, "Board", "MagnifierDrawingMode", "0"); magnifierDrawingMode = new UBSetting(this, "Board", "MagnifierDrawingMode", "0");
timerInterval = new UBSetting(this, "Board", "Timer interval", "5"); autoSaveInterval = new UBSetting(this, "Board", "AutoSaveIntervalInMinutes", "3");
svgViewBoxMargin = new UBSetting(this, "SVG", "ViewBoxMargin", "50"); svgViewBoxMargin = new UBSetting(this, "SVG", "ViewBoxMargin", "50");

@ -373,7 +373,7 @@ class UBSettings : public QObject
UBSetting* libIconSize; UBSetting* libIconSize;
UBSetting* magnifierDrawingMode; UBSetting* magnifierDrawingMode;
UBSetting* timerInterval; UBSetting* autoSaveInterval;
public slots: public slots:

@ -79,9 +79,14 @@ void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item)
if (UBGraphicsItem::isRotatable(this) && !UBGraphicsItem::isRotatable(item)) { if (UBGraphicsItem::isRotatable(this) && !UBGraphicsItem::isRotatable(item)) {
Delegate()->setUBFlag(GF_REVOLVABLE, false); Delegate()->setUBFlag(GF_REVOLVABLE, false);
} }
} else { if (!UBGraphicsItem::isLocked(this) && UBGraphicsItem::isLocked(item)) {
Delegate()->setLocked(true);
}
}
else {
Delegate()->setUBFlag(GF_FLIPPABLE_ALL_AXIS, UBGraphicsItem::isFlippable(item)); Delegate()->setUBFlag(GF_FLIPPABLE_ALL_AXIS, UBGraphicsItem::isFlippable(item));
Delegate()->setUBFlag(GF_REVOLVABLE, UBGraphicsItem::isRotatable(item)); Delegate()->setUBFlag(GF_REVOLVABLE, UBGraphicsItem::isRotatable(item));
Delegate()->setLocked(UBGraphicsItem::isLocked(item));
} }
// COMBINE // COMBINE
@ -322,6 +327,7 @@ void UBGraphicsGroupContainerItem::pRemoveFromGroup(QGraphicsItem *item)
if (!UBGraphicsItem::isFlippable(item) || !UBGraphicsItem::isRotatable(item)) { if (!UBGraphicsItem::isFlippable(item) || !UBGraphicsItem::isRotatable(item)) {
bool flippableNow = true; bool flippableNow = true;
bool rotatableNow = true; bool rotatableNow = true;
bool lockedNow = false;
foreach (QGraphicsItem *item, childItems()) { foreach (QGraphicsItem *item, childItems()) {
if (!UBGraphicsItem::isFlippable(item)) { if (!UBGraphicsItem::isFlippable(item)) {
@ -330,12 +336,17 @@ void UBGraphicsGroupContainerItem::pRemoveFromGroup(QGraphicsItem *item)
if (!UBGraphicsItem::isRotatable(item)) { if (!UBGraphicsItem::isRotatable(item)) {
rotatableNow = false; rotatableNow = false;
} }
if (!rotatableNow && !flippableNow) { if(UBGraphicsItem::isLocked(item))
lockedNow = true;
if (!rotatableNow && !flippableNow && lockedNow) {
break; break;
} }
} }
Delegate()->setUBFlag(GF_FLIPPABLE_ALL_AXIS, flippableNow); Delegate()->setUBFlag(GF_FLIPPABLE_ALL_AXIS, flippableNow);
Delegate()->setUBFlag(GF_REVOLVABLE, rotatableNow); Delegate()->setUBFlag(GF_REVOLVABLE, rotatableNow);
Delegate()->setLocked(lockedNow);
} }
} }

@ -715,6 +715,15 @@ void UBGraphicsItemDelegate::showMenu()
mMenu->exec(cv->mapToGlobal(pinPos.bottomRight())); mMenu->exec(cv->mapToGlobal(pinPos.bottomRight()));
} }
void UBGraphicsItemDelegate::setLocked(bool pLocked)
{
Q_ASSERT(mDelegated);
if (mDelegated) {
mDelegated->setData(UBGraphicsItemData::ItemLocked, QVariant(pLocked));
}
}
void UBGraphicsItemDelegate::updateFrame() void UBGraphicsItemDelegate::updateFrame()
{ {
if (mFrame && !mFrame->scene() && mDelegated->scene()) if (mFrame && !mFrame->scene() && mDelegated->scene())

@ -279,6 +279,7 @@ class UBGraphicsItemDelegate : public QObject
void setMimeData(QMimeData* mimeData); void setMimeData(QMimeData* mimeData);
void setDragPixmap(const QPixmap &pix) {mDragPixmap = pix;} void setDragPixmap(const QPixmap &pix) {mDragPixmap = pix;}
void setLocked(bool pLocked);
void setButtonsVisible(bool visible); void setButtonsVisible(bool visible);
UBGraphicsToolBarItem* getToolBarItem() const { return mToolBarItem; } UBGraphicsToolBarItem* getToolBarItem() const { return mToolBarItem; }

@ -59,7 +59,7 @@ void UBGraphicsItemZLevelUndoCommand::undo(){
if(mDest == UBZLayerController::down || mDest == UBZLayerController::bottom){ if(mDest == UBZLayerController::down || mDest == UBZLayerController::bottom){
// Move up // Move up
QList<QGraphicsItem*>::iterator downIt = mItems.end(); QList<QGraphicsItem*>::iterator downIt = mItems.end();
for(downIt; downIt >= mItems.begin(); downIt--){ for(; downIt >= mItems.begin(); downIt--){
for(int i=0; i<zDiff; i++) for(int i=0; i<zDiff; i++)
mpScene->changeZLevelTo(*downIt, UBZLayerController::up); mpScene->changeZLevelTo(*downIt, UBZLayerController::up);
} }

@ -45,13 +45,64 @@
const int UBGraphicsTextItemDelegate::sMinPixelSize = 8; const int UBGraphicsTextItemDelegate::sMinPixelSize = 8;
const int UBGraphicsTextItemDelegate::sMinPointSize = 8; const int UBGraphicsTextItemDelegate::sMinPointSize = 8;
AlignTextButton::AlignTextButton(const QString &fileName, QGraphicsItem *pDelegated, QGraphicsItem *parent, Qt::WindowFrameSection section)
: DelegateButton(fileName, pDelegated, parent, section)
, lft(new QSvgRenderer(QString(":/images/plus.svg")))
, cntr(new QSvgRenderer(QString(":/images/pause.svg")))
, rght(new QSvgRenderer(QString(":/images/minus.svg")))
, mxd(new QSvgRenderer(QString(":/images/reload.svg")))
{
setKind(k_left);
}
AlignTextButton::~AlignTextButton()
{
if (lft) delete lft;
if (cntr) delete cntr;
if (rght) delete rght;
if (mxd) delete mxd;
}
void AlignTextButton::setKind(int pKind)
{
if (mHideMixed && pKind == k_mixed) {
qDebug() << "Mixed button is hidden, can't process it";
return;
}
mKind = pKind;
QSvgRenderer *rndrer = rndFromKind(pKind);
Q_ASSERT(rndrer);
setSharedRenderer(rndrer);
}
void AlignTextButton::setNextKind()
{
int mxKind = MAX_KIND;
if (mHideMixed) {
mxKind--;
}
setKind(mKind == mxKind ? 0 : ++mKind);
}
int AlignTextButton::nextKind() const
{
int mxKind = MAX_KIND;
if (mHideMixed) {
mxKind--;
}
int result = mKind;
return mKind == mxKind ? 0 : ++result;
}
UBGraphicsTextItemDelegate::UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDelegated, QObject *) UBGraphicsTextItemDelegate::UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDelegated, QObject *)
: UBGraphicsItemDelegate(pDelegated,0, GF_COMMON | GF_REVOLVABLE | GF_TOOLBAR_USED) : UBGraphicsItemDelegate(pDelegated,0, GF_COMMON | GF_REVOLVABLE | GF_TOOLBAR_USED)
, mFontButton(0)
, mColorButton(0)
, mDecreaseSizeButton(0)
, mIncreaseSizeButton(0)
, mAlignButton(0)
, mLastFontPixelSize(-1) , mLastFontPixelSize(-1)
, mAlignLeftButton(0)
, mAlignCenterButton(0)
, mAlignRightButton(0)
, mAlighMixed(0)
, delta(5) , delta(5)
{ {
delegated()->setData(UBGraphicsItemData::ItemEditable, QVariant(true)); delegated()->setData(UBGraphicsItemData::ItemEditable, QVariant(true));
@ -70,6 +121,9 @@ UBGraphicsTextItemDelegate::UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDele
delegated()->adjustSize(); delegated()->adjustSize();
delegated()->contentsChanged(); delegated()->contentsChanged();
connect(delegated()->document(), SIGNAL(cursorPositionChanged(QTextCursor)), this, SLOT(onCursorPositionChanged(QTextCursor)));
connect(delegated()->document(), SIGNAL(modificationChanged(bool)), this, SLOT(onModificationChanged(bool)));
// NOOP // NOOP
} }
@ -107,24 +161,35 @@ void UBGraphicsTextItemDelegate::buildButtons()
{ {
UBGraphicsItemDelegate::buildButtons(); UBGraphicsItemDelegate::buildButtons();
mFontButton = new DelegateButton(":/images/font.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); if (!mFontButton) {
mColorButton = new DelegateButton(":/images/color.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); mFontButton = new DelegateButton(":/images/font.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
mDecreaseSizeButton = new DelegateButton(":/images/minus.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); connect(mFontButton, SIGNAL(clicked(bool)), this, SLOT(pickFont()));
mIncreaseSizeButton = new DelegateButton(":/images/plus.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); }
if (!mColorButton) {
mColorButton = new DelegateButton(":/images/color.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
connect(mColorButton, SIGNAL(clicked(bool)), this, SLOT(pickColor()));
}
//Alignment buttons family if (!mDecreaseSizeButton) {
mAlignLeftButton = new DelegateButton(":/images/plus.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); mDecreaseSizeButton = new DelegateButton(":/images/minus.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
mAlignCenterButton = new DelegateButton(":/images/pause.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); connect(mDecreaseSizeButton, SIGNAL(clicked(bool)), this, SLOT(decreaseSize()));
mAlignRightButton = new DelegateButton(":/images/minus.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); }
mAlighMixed = new DelegateButton(":/images/reload.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
if (!mIncreaseSizeButton) {
mIncreaseSizeButton = new DelegateButton(":/images/plus.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
connect(mIncreaseSizeButton, SIGNAL(clicked(bool)), this, SLOT(increaseSize()));
}
// Alignment button
if (!mAlignButton) {
mAlignButton = new AlignTextButton(":/images/plus.svg", mDelegated, mToolBarItem, Qt::TitleBarArea);
connect(mAlignButton, SIGNAL(clicked()), this, SLOT(alignButtonProcess()));
}
connect(mFontButton, SIGNAL(clicked(bool)), this, SLOT(pickFont()));
connect(mColorButton, SIGNAL(clicked(bool)), this, SLOT(pickColor()));
connect(mDecreaseSizeButton, SIGNAL(clicked(bool)), this, SLOT(decreaseSize()));
connect(mIncreaseSizeButton, SIGNAL(clicked(bool)), this, SLOT(increaseSize()));
QList<QGraphicsItem*> itemsOnToolBar; QList<QGraphicsItem*> itemsOnToolBar;
itemsOnToolBar << mFontButton << mColorButton << mDecreaseSizeButton << mIncreaseSizeButton << mFontButton; itemsOnToolBar << mFontButton << mColorButton << mDecreaseSizeButton << mIncreaseSizeButton;
itemsOnToolBar << mAlignButton;
mToolBarItem->setItemsOnToolBar(itemsOnToolBar); mToolBarItem->setItemsOnToolBar(itemsOnToolBar);
mToolBarItem->setShifting(true); mToolBarItem->setShifting(true);
mToolBarItem->setVisibleOnBoard(true); mToolBarItem->setVisibleOnBoard(true);
@ -259,6 +324,58 @@ void UBGraphicsTextItemDelegate::increaseSize()
ChangeTextSize(delta, changeSize); ChangeTextSize(delta, changeSize);
} }
void UBGraphicsTextItemDelegate::alignButtonProcess()
{
qDebug() << "alignButtonProcess() clicked";
QObject *sndr = sender();
if (sndr == mAlignButton) {
qDebug() << "Align button";
AlignTextButton *asAlText = static_cast<AlignTextButton*>(mAlignButton);
if (asAlText->nextKind() == AlignTextButton::k_mixed) {
restoreTextCursorFormats();
}
asAlText->setNextKind();
QTextCursor cur = delegated()->textCursor();
QTextBlockFormat fmt = cur.blockFormat();
switch (asAlText->kind()) {
case AlignTextButton::k_left:
fmt.setAlignment(Qt::AlignLeft);
break;
case AlignTextButton::k_center:
fmt.setAlignment(Qt::AlignCenter);
break;
case AlignTextButton::k_right:
fmt.setAlignment(Qt::AlignRight);
break;
case AlignTextButton::k_mixed:
break;
}
delegated()->setTextCursor(cur);
cur.setBlockFormat(fmt);
}
qDebug() << "sender process" << sndr;
}
void UBGraphicsTextItemDelegate::onCursorPositionChanged(const QTextCursor &cursor)
{
qDebug() << "cursor position changed";
qDebug() << "-----------------------";
qDebug() << "we have a selection!" << cursor.selectionStart();
qDebug() << "-----------------------";
updateAlighButtonState();
}
void UBGraphicsTextItemDelegate::onModificationChanged(bool ch)
{
Q_UNUSED(ch);
qDebug() << "modification changed";
updateAlighButtonState();
}
UBGraphicsTextItem* UBGraphicsTextItemDelegate::delegated() UBGraphicsTextItem* UBGraphicsTextItemDelegate::delegated()
{ {
return static_cast<UBGraphicsTextItem*>(mDelegated); return static_cast<UBGraphicsTextItem*>(mDelegated);
@ -344,6 +461,47 @@ void UBGraphicsTextItemDelegate::positionHandles()
} }
} }
bool UBGraphicsTextItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
mSelectionData.mButtonIsPressed = true;
qDebug() << "Reporting selection of the cursor (mouse press)" << delegated()->textCursor().selection().isEmpty();
qDebug() << QString("Anchor: %1\nposition: %2 (mouse press)").arg(delegated()->textCursor().anchor()).arg(delegated()->textCursor().position());
if (!UBGraphicsItemDelegate::mousePressEvent(event)) {
return false;
}
return true;
}
bool UBGraphicsTextItemDelegate::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (mSelectionData.mButtonIsPressed) {
qDebug() << "Reporting selection of the cursor (mouse move)" << delegated()->textCursor().selection().isEmpty();
qDebug() << QString("Anchor: %1\nposition: %2 (mouse mouse move)").arg(delegated()->textCursor().anchor()).arg(delegated()->textCursor().position());
}
if (!UBGraphicsItemDelegate::mouseMoveEvent(event)) {
return false;
}
return true;
}
bool UBGraphicsTextItemDelegate::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
mSelectionData.mButtonIsPressed = false;
qDebug() << "Reporting selection of the cursor (mouse release)" << delegated()->textCursor().selection().isEmpty();
qDebug() << QString("Anchor: %1\nposition: %2 (mouse mouse release)").arg(delegated()->textCursor().anchor()).arg(delegated()->textCursor().position());
updateAlighButtonState();
if (!UBGraphicsItemDelegate::mouseReleaseEvent(event)) {
return false;
}
return true;
}
void UBGraphicsTextItemDelegate::ChangeTextSize(qreal factor, textChangeMode changeMode) void UBGraphicsTextItemDelegate::ChangeTextSize(qreal factor, textChangeMode changeMode)
{ {
if (scaleSize == changeMode) if (scaleSize == changeMode)
@ -352,8 +510,8 @@ void UBGraphicsTextItemDelegate::ChangeTextSize(qreal factor, textChangeMode cha
return; return;
} }
else else
if (0 == factor) if (0 == factor)
return; return;
UBGraphicsTextItem *item = dynamic_cast<UBGraphicsTextItem*>(delegated()); UBGraphicsTextItem *item = dynamic_cast<UBGraphicsTextItem*>(delegated());
@ -445,6 +603,77 @@ void UBGraphicsTextItemDelegate::ChangeTextSize(qreal factor, textChangeMode cha
delegated()->setTextCursor(cursor); delegated()->setTextCursor(cursor);
} }
void UBGraphicsTextItemDelegate::updateAlighButtonState()
{
if (!mAlignButton) {
return;
}
AlignTextButton *asAlBtn = static_cast<AlignTextButton*>(mAlignButton);
if (!oneBlockSelection()) {
asAlBtn->setMixedButtonVisible(true);
asAlBtn->setKind(AlignTextButton::k_mixed);
saveTextCursorFormats();
return;
}
asAlBtn->setMixedButtonVisible(false);
switch (static_cast<int>(delegated()->textCursor().blockFormat().alignment())) {
case Qt::AlignCenter :
asAlBtn->setKind(AlignTextButton::k_center);
break;
case Qt::AlignRight :
asAlBtn->setKind(AlignTextButton::k_right);
break;
default:
asAlBtn->setKind(AlignTextButton::k_left);
break;
}
}
bool UBGraphicsTextItemDelegate::oneBlockSelection()
{
const QTextCursor cursor = delegated()->textCursor();
int pos = cursor.position();
int anchor = cursor.anchor();
// no selection
if (pos == anchor) {
return true;
}
//selecton within one text block
QTextBlock blck = cursor.block();
if (blck.contains(pos) && blck.contains(anchor)) {
return true;
}
//otherwise
return false;
}
void UBGraphicsTextItemDelegate::saveTextCursorFormats()
{
mSelectionData.anchor = delegated()->textCursor().anchor();
mSelectionData.position = delegated()->textCursor().position();
mSelectionData.html = delegated()->document()->toHtml();
}
void UBGraphicsTextItemDelegate::restoreTextCursorFormats()
{
delegated()->document()->setHtml(mSelectionData.html);
int min = qMin(mSelectionData.position, mSelectionData.anchor);
int max = qMax(mSelectionData.position, mSelectionData.anchor);
int steps = max - min;
QTextCursor tcrsr = delegated()->textCursor();
tcrsr.setPosition(mSelectionData.position);
tcrsr.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor, steps);
delegated()->setTextCursor(tcrsr);
}
void UBGraphicsTextItemDelegate::scaleTextSize(qreal multiplyer) void UBGraphicsTextItemDelegate::scaleTextSize(qreal multiplyer)
{ {
ChangeTextSize(multiplyer, scaleSize); ChangeTextSize(multiplyer, scaleSize);

@ -37,6 +37,64 @@
class UBGraphicsTextItem; class UBGraphicsTextItem;
class AlignTextButton : public DelegateButton
{
Q_OBJECT
public:
static const int MAX_KIND = 3;
enum kind_t{
k_left = 0
, k_center
, k_right
, k_mixed
};
AlignTextButton(const QString & fileName, QGraphicsItem* pDelegated, QGraphicsItem * parent = 0, Qt::WindowFrameSection section = Qt::TopLeftSection);
virtual ~AlignTextButton();
void setKind(int pKind);
int kind() {return mKind;}
void setNextKind();
int nextKind() const;
void setMixedButtonVisible(bool v = true) {mHideMixed = !v;}
bool isMixedButtonVisible() {return !mHideMixed;}
private:
QSvgRenderer *rndFromKind(int pknd)
{
switch (pknd) {
case k_left:
return lft;
break;
case k_center:
return cntr;
break;
case k_right:
return rght;
break;
case k_mixed:
return mxd;
break;
}
return 0;
}
QSvgRenderer *curRnd() {return rndFromKind(mKind);}
QPointer<QSvgRenderer> lft;
QPointer<QSvgRenderer> cntr;
QPointer<QSvgRenderer> rght;
QPointer<QSvgRenderer> mxd;
int mKind;
bool mHideMixed;
};
class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate
{ {
Q_OBJECT Q_OBJECT
@ -67,8 +125,11 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate
virtual void positionHandles(); virtual void positionHandles();
private: virtual bool mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual bool mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual bool mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
private:
UBGraphicsTextItem* delegated(); UBGraphicsTextItem* delegated();
DelegateButton* mFontButton; DelegateButton* mFontButton;
@ -76,10 +137,7 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate
DelegateButton* mDecreaseSizeButton; DelegateButton* mDecreaseSizeButton;
DelegateButton* mIncreaseSizeButton; DelegateButton* mIncreaseSizeButton;
DelegateButton* mAlignLeftButton; DelegateButton* mAlignButton;
DelegateButton* mAlignCenterButton;
DelegateButton* mAlignRightButton;
DelegateButton* mAlighMixed;
int mLastFontPixelSize; int mLastFontPixelSize;
@ -89,9 +147,26 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate
private: private:
void customize(QFontDialog &fontDialog); void customize(QFontDialog &fontDialog);
void ChangeTextSize(qreal factor, textChangeMode changeMode); void ChangeTextSize(qreal factor, textChangeMode changeMode);
void updateAlighButtonState();
bool oneBlockSelection();
void saveTextCursorFormats();
void restoreTextCursorFormats();
QFont createDefaultFont(); QFont createDefaultFont();
QAction *mEditableAction; QAction *mEditableAction;
struct selectionData_t {
selectionData_t()
: mButtonIsPressed(false)
{}
bool mButtonIsPressed;
int position;
int anchor;
QString html;
QTextDocumentFragment selection;
QList<QTextBlockFormat> fmts;
} mSelectionData;
private slots: private slots:
@ -101,9 +176,12 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate
void decreaseSize(); void decreaseSize();
void increaseSize(); void increaseSize();
void alignButtonProcess();
void onCursorPositionChanged(const QTextCursor& cursor);
void onModificationChanged(bool ch);
private: private:
const int delta; const int delta;
}; };
#endif /* UBGRAPHICSTEXTITEMDELEGATE_H_ */ #endif /* UBGRAPHICSTEXTITEMDELEGATE_H_ */

@ -565,12 +565,9 @@ void UBGraphicsWidgetItem::injectInlineJavaScript()
void UBGraphicsWidgetItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void UBGraphicsWidgetItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
if (scene() && scene()->renderingContext() != UBGraphicsScene::Screen) {
painter->drawPixmap(0, 0, snapshot()); QGraphicsWebView::paint(painter, option, widget);
}
else {
QGraphicsWebView::paint(painter, option, widget);
}
if (!mInitialLoadDone) { if (!mInitialLoadDone) {
QString message; QString message;

@ -85,6 +85,11 @@ bool UBGraphicsItem::isRotatable(QGraphicsItem *item)
return item->data(UBGraphicsItemData::ItemRotatable).toBool(); return item->data(UBGraphicsItemData::ItemRotatable).toBool();
} }
bool UBGraphicsItem::isLocked(QGraphicsItem *item)
{
return item->data(UBGraphicsItemData::ItemLocked).toBool();
}
QUuid UBGraphicsItem::getOwnUuid(QGraphicsItem *item) QUuid UBGraphicsItem::getOwnUuid(QGraphicsItem *item)
{ {
QString idCandidate = item->data(UBGraphicsItemData::ItemUuid).toString(); QString idCandidate = item->data(UBGraphicsItemData::ItemUuid).toString();

@ -116,6 +116,7 @@ public:
static void assignZValue(QGraphicsItem*, qreal value); static void assignZValue(QGraphicsItem*, qreal value);
static bool isRotatable(QGraphicsItem *item); static bool isRotatable(QGraphicsItem *item);
static bool isFlippable(QGraphicsItem *item); static bool isFlippable(QGraphicsItem *item);
static bool isLocked(QGraphicsItem *item);
static QUuid getOwnUuid(QGraphicsItem *item); static QUuid getOwnUuid(QGraphicsItem *item);
static UBGraphicsItemDelegate *Delegate(QGraphicsItem *pItem); static UBGraphicsItemDelegate *Delegate(QGraphicsItem *pItem);

@ -261,7 +261,7 @@ void UBDocumentTreeWidget::dropEvent(QDropEvent *event)
UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti); UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti);
if (pi) if (pi)
{ {
if (mSelectedProxyTi->proxy()->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString()) if (mSelectedProxyTi->proxy()->metaData(UBSettings::documentDate).toString() >= pi->proxy()->metaData(UBSettings::documentDate).toString())
{ {
break; break;
} }
@ -380,7 +380,7 @@ void UBDocumentTreeWidget::documentUpdated(UBDocumentProxy *pDocument)
UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti); UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti);
if (pi) if (pi)
{ {
if (pDocument->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString()) if (pDocument->metaData(UBSettings::documentDate).toString() >= pi->proxy()->metaData(UBSettings::documentDate).toString())
{ {
bool selected = treeItem->isSelected(); bool selected = treeItem->isSelected();
parent->removeChild(treeItem); parent->removeChild(treeItem);
@ -416,7 +416,7 @@ UBDocumentProxyTreeItem::UBDocumentProxyTreeItem(QTreeWidgetItem * parent, UBDoc
UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti); UBDocumentProxyTreeItem* pi = dynamic_cast<UBDocumentProxyTreeItem*>(ti);
if (pi) if (pi)
{ {
if (proxy->metaData(UBSettings::documentUpdatedAt).toString() >= pi->proxy()->metaData(UBSettings::documentUpdatedAt).toString()) if (proxy->metaData(UBSettings::documentDate).toString() >= pi->proxy()->metaData(UBSettings::documentDate).toString())
{ {
break; break;
} }

Loading…
Cancel
Save