Increasing Decreasing full textItem backward capability now available

preferencesAboutTextFull
Ivan Ilin 13 years ago
parent 8063c98992
commit 8787a51dbb
  1. 16
      src/adaptors/UBSvgSubsetAdaptor.cpp
  2. 7
      src/domain/UBGraphicsScene.cpp
  3. 84
      src/domain/UBGraphicsTextItemDelegate.cpp
  4. 1
      src/domain/UBGraphicsTextItemDelegate.h

@ -2304,11 +2304,18 @@ UBGraphicsTextItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::textItemFromSvg()
//for new documents from version 4.5.0 //for new documents from version 4.5.0
if (mFileVersion >= 40500) { if (mFileVersion >= 40500) {
if (mXmlReader.name() == "itemTextContent") { if (mXmlReader.name() == "itemTextContent") {
QString text = mXmlReader.readElementText(); text = mXmlReader.readElementText();
textItem->setHtml(text); textItem->setHtml(text);
break; textItem->resize(width, height);
if (textItem->toPlainText().isEmpty()) {
delete textItem;
textItem = 0;
} }
//tracking for back capability with older versions return textItem;
}
//tracking for backward capability with older versions
} else if (mXmlReader.name() == "font") { } else if (mXmlReader.name() == "font") {
QFont font = textItem->font(); QFont font = textItem->font();
@ -2382,7 +2389,6 @@ UBGraphicsTextItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::textItemFromSvg()
} }
} }
if (false) {
if (text.isEmpty()) { if (text.isEmpty()) {
delete textItem; delete textItem;
textItem = 0; textItem = 0;
@ -2390,7 +2396,7 @@ UBGraphicsTextItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::textItemFromSvg()
textItem->setPlainText(text); textItem->setPlainText(text);
textItem->resize(width, height); textItem->resize(width, height);
} }
}
textItem->resize(width, height); textItem->resize(width, height);
return textItem; return textItem;

@ -150,6 +150,9 @@ UBGraphicsScene::~UBGraphicsScene()
void UBGraphicsScene::selectionChangedProcessing() void UBGraphicsScene::selectionChangedProcessing()
{ {
if (selectedItems().count())
UBApplication::showMessage("ZValue is " + QString::number(selectedItems().first()->zValue(), 'f'));
QList<QGraphicsItem *> allItemsList = items(); QList<QGraphicsItem *> allItemsList = items();
for( int i = 0; i < allItemsList.size(); i++ ) for( int i = 0; i < allItemsList.size(); i++ )
{ {
@ -1263,7 +1266,7 @@ UBGraphicsTextItem* UBGraphicsScene::addTextWithFont(const QString& pString, con
textItem->setPlainText(pString); textItem->setPlainText(pString);
textItem->setZValue(getNextObjectZIndex()); textItem->setZValue(getNextObjectZIndex());
QFont font; QFont font = textItem->font();
if (fontFamily == "") if (fontFamily == "")
{ {
@ -1280,7 +1283,7 @@ UBGraphicsTextItem* UBGraphicsScene::addTextWithFont(const QString& pString, con
} }
else else
{ {
font.setPixelSize(pointSize); font.setPointSize(pointSize);
} }
font.setBold(bold); font.setBold(bold);

@ -30,6 +30,7 @@
#include "board/UBBoardController.h" #include "board/UBBoardController.h"
const int UBGraphicsTextItemDelegate::sMinPixelSize = 8; const int UBGraphicsTextItemDelegate::sMinPixelSize = 8;
const int UBGraphicsTextItemDelegate::sMinPointSize = 8;
UBGraphicsTextItemDelegate::UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDelegated, QObject * parent) UBGraphicsTextItemDelegate::UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDelegated, QObject * parent)
: UBGraphicsItemDelegate(pDelegated,0, parent, true) : UBGraphicsItemDelegate(pDelegated,0, parent, true)
@ -46,23 +47,11 @@ UBGraphicsTextItemDelegate::UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDele
format.setFont(font); format.setFont(font);
curCursor.mergeCharFormat(format); curCursor.mergeCharFormat(format);
delegated()->setTextCursor(curCursor); delegated()->setTextCursor(curCursor);
delegated()->setFont(font);
delegated()->adjustSize(); delegated()->adjustSize();
delegated()->contentsChanged(); 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
} }
@ -71,7 +60,6 @@ UBGraphicsTextItemDelegate::~UBGraphicsTextItemDelegate()
// NOOP // NOOP
} }
QFont UBGraphicsTextItemDelegate::createDefaultFont() QFont UBGraphicsTextItemDelegate::createDefaultFont()
{ {
QTextCharFormat textFormat; QTextCharFormat textFormat;
@ -89,10 +77,15 @@ QFont UBGraphicsTextItemDelegate::createDefaultFont()
textFormat.setFontItalic(true); textFormat.setFontItalic(true);
QFont font(fFamily, -1, bold ? QFont::Bold : -1, italic); QFont font(fFamily, -1, bold ? QFont::Bold : -1, italic);
int pixSize = UBSettings::settings()->fontPixelSize(); // int pixSize = UBSettings::settings()->fontPixelSize();
if (pixSize > 0) { // if (pixSize > 0) {
mLastFontPixelSize = pixSize; // mLastFontPixelSize = pixSize;
font.setPixelSize(pixSize); // font.setPixelSize(pixSize);
// }
int pointSize = UBSettings::settings()->fontPointSize();
if (pointSize > 0) {
// mLastFontPixelSize = pointSize;
font.setPointSize(pointSize);
} }
return font; return font;
@ -115,7 +108,6 @@ void UBGraphicsTextItemDelegate::buildButtons()
mButtons << mFontButton << mColorButton << mDecreaseSizeButton << mIncreaseSizeButton; mButtons << mFontButton << mColorButton << mDecreaseSizeButton << mIncreaseSizeButton;
} }
void UBGraphicsTextItemDelegate::contentsChanged() void UBGraphicsTextItemDelegate::contentsChanged()
{ {
positionHandles(); positionHandles();
@ -128,8 +120,7 @@ void UBGraphicsTextItemDelegate::customize(QFontDialog &fontDialog)
{ {
fontDialog.setOption(QFontDialog::DontUseNativeDialog); fontDialog.setOption(QFontDialog::DontUseNativeDialog);
if (UBSettings::settings()->isDarkBackground()) if (UBSettings::settings()->isDarkBackground()) {
{
fontDialog.setStyleSheet("background-color: white;"); fontDialog.setStyleSheet("background-color: white;");
} }
@ -171,7 +162,6 @@ void UBGraphicsTextItemDelegate::customize(QFontDialog &fontDialog)
} }
} }
} }
QList<QComboBox*> comboBoxes = fontDialog.findChildren<QComboBox*>(); QList<QComboBox*> comboBoxes = fontDialog.findChildren<QComboBox*>();
if (comboBoxes.count() > 0) if (comboBoxes.count() > 0)
comboBoxes.at(0)->setEnabled(false); comboBoxes.at(0)->setEnabled(false);
@ -189,9 +179,6 @@ void UBGraphicsTextItemDelegate::pickFont()
{ {
QFont selectedFont = fontDialog.selectedFont(); QFont selectedFont = fontDialog.selectedFont();
UBSettings::settings()->setFontFamily(selectedFont.family()); UBSettings::settings()->setFontFamily(selectedFont.family());
QFontInfo fi(selectedFont);
mLastFontPixelSize = fi.pixelSize();
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()); UBSettings::settings()->setFontPointSize(selectedFont.pointSize());
@ -201,8 +188,9 @@ void UBGraphicsTextItemDelegate::pickFont()
QTextCharFormat format; QTextCharFormat format;
format.setFont(selectedFont); format.setFont(selectedFont);
curCursor.mergeCharFormat(format); curCursor.mergeCharFormat(format);
delegated()->setTextCursor(curCursor);
delegated()->setTextCursor(curCursor);
delegated()->setFont(selectedFont);
delegated()->setSelected(true); delegated()->setSelected(true);
delegated()->document()->adjustSize(); delegated()->document()->adjustSize();
delegated()->contentsChanged(); delegated()->contentsChanged();
@ -243,6 +231,15 @@ void UBGraphicsTextItemDelegate::pickColor()
void UBGraphicsTextItemDelegate::decreaseSize() void UBGraphicsTextItemDelegate::decreaseSize()
{ {
QTextCursor cursor = delegated()->textCursor();
QTextCharFormat textFormat;
QFont curFont = cursor.charFormat().font();
int pointSize = curFont.pointSize();
pointSize -= 5;
// QFontInfo fi(delegated()->font()); // QFontInfo fi(delegated()->font());
// int pixelSize = fi.pixelSize(); // int pixelSize = fi.pixelSize();
// if (-1 == mLastFontPixelSize) // if (-1 == mLastFontPixelSize)
@ -265,11 +262,28 @@ void UBGraphicsTextItemDelegate::decreaseSize()
// delegated()->document()->adjustSize(); // delegated()->document()->adjustSize();
// delegated()->contentsChanged();dddd // delegated()->contentsChanged();dddd
// } // }
curFont.setPointSize(pointSize);
textFormat.setFont(curFont);
cursor.mergeCharFormat(textFormat);
delegated()->setTextCursor(cursor);
UBSettings::settings()->setFontPixelSize(curFont.pixelSize());
UBSettings::settings()->setFontPointSize(pointSize);
delegated()->document()->adjustSize();
delegated()->setFont(curFont);
} }
void UBGraphicsTextItemDelegate::increaseSize() void UBGraphicsTextItemDelegate::increaseSize()
{ {
// QFontInfo fi(delegated()->font()); QTextCursor cursor = delegated()->textCursor();
QTextCharFormat textFormat;
QFont curFont = cursor.charFormat().font();
int pointSize = curFont.pointSize();
pointSize += 5;
// QFontInfo fi(cursor.charFormat().font());
// int pixelSize = fi.pixelSize(); // int pixelSize = fi.pixelSize();
// if (-1 == mLastFontPixelSize) // if (-1 == mLastFontPixelSize)
// mLastFontPixelSize = pixelSize; // mLastFontPixelSize = pixelSize;
@ -281,16 +295,18 @@ void UBGraphicsTextItemDelegate::increaseSize()
// if (pixelSize < mLastFontPixelSize && mLastFontPixelSize < newPixelSize) // if (pixelSize < mLastFontPixelSize && mLastFontPixelSize < newPixelSize)
// newPixelSize = mLastFontPixelSize; // newPixelSize = mLastFontPixelSize;
// QFont font = delegated()->font();
// font.setPixelSize(newPixelSize);
// delegated()->setFont(font);
// UBSettings::settings()->setFontPixelSize(newPixelSize);
// delegated()->document()->adjustSize(); curFont.setPointSize(pointSize);
// delegated()->contentsChanged(); textFormat.setFont(curFont);
cursor.mergeCharFormat(textFormat);
delegated()->setTextCursor(cursor);
// UBSettings::settings()->setFontPixelSize(curFont.pixelSize());
UBSettings::settings()->setFontPointSize(pointSize);
// qDebug() << newPixelSize;
delegated()->document()->adjustSize(); delegated()->document()->adjustSize();
delegated()->setFont(curFont);
// delegated()->contentsChanged();
} }
UBGraphicsTextItem* UBGraphicsTextItemDelegate::delegated() UBGraphicsTextItem* UBGraphicsTextItemDelegate::delegated()

@ -57,6 +57,7 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate
int mLastFontPixelSize; int mLastFontPixelSize;
static const int sMinPixelSize; static const int sMinPixelSize;
static const int sMinPointSize;
private: private:
void customize(QFontDialog &fontDialog); void customize(QFontDialog &fontDialog);

Loading…
Cancel
Save