Increasing Decreasing full textItem backward capability now available

preferencesAboutTextFull
Ivan Ilin 13 years ago
parent 8063c98992
commit 8787a51dbb
  1. 28
      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
if (mFileVersion >= 40500) {
if (mXmlReader.name() == "itemTextContent") {
QString text = mXmlReader.readElementText();
text = mXmlReader.readElementText();
textItem->setHtml(text);
break;
textItem->resize(width, height);
if (textItem->toPlainText().isEmpty()) {
delete textItem;
textItem = 0;
}
return textItem;
}
//tracking for back capability with older versions
//tracking for backward capability with older versions
} else if (mXmlReader.name() == "font") {
QFont font = textItem->font();
@ -2382,15 +2389,14 @@ UBGraphicsTextItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::textItemFromSvg()
}
}
if (false) {
if (text.isEmpty()) {
delete textItem;
textItem = 0;
} else {
textItem->setPlainText(text);
textItem->resize(width, height);
}
if (text.isEmpty()) {
delete textItem;
textItem = 0;
} else {
textItem->setPlainText(text);
textItem->resize(width, height);
}
textItem->resize(width, height);
return textItem;

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

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

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

Loading…
Cancel
Save