Commit 647f7332 authored by Thomas Zander's avatar Thomas Zander

Add a static method on KoParagraphStyle to create a style from a QTextBlockFormat

svn path=/trunk/koffice/; revision=648993
parent b1078694
......@@ -30,6 +30,70 @@
#include <KoStyleStack.h>
#include <KoXmlNS.h>
// all relevant properties.
static const int properties[] = {
QTextFormat::BlockTopMargin,
QTextFormat::BlockBottomMargin,
QTextFormat::BlockLeftMargin,
QTextFormat::BlockRightMargin,
QTextFormat::BlockAlignment,
QTextFormat::TextIndent,
QTextFormat::BlockIndent,
QTextFormat::BlockNonBreakableLines,
KoParagraphStyle::StyleId,
KoParagraphStyle::FixedLineHeight,
KoParagraphStyle::MinimumLineHeight,
KoParagraphStyle::LineSpacing,
KoParagraphStyle::LineSpacingFromFont,
// KoParagraphStyle::AlignLastLine,
// KoParagraphStyle::WidowThreshold,
// KoParagraphStyle::OrphanThreshold,
// KoParagraphStyle::DropCaps,
// KoParagraphStyle::DropCapsLength,
// KoParagraphStyle::DropCapsLines,
// KoParagraphStyle::DropCapsDistance,
// KoParagraphStyle::FollowDocBaseline,
KoParagraphStyle::BreakBefore,
KoParagraphStyle::BreakAfter,
// KoParagraphStyle::HasLeftBorder,
// KoParagraphStyle::HasTopBorder,
// KoParagraphStyle::HasRightBorder,
// KoParagraphStyle::HasBottomBorder,
// KoParagraphStyle::BorderLineWidth,
// KoParagraphStyle::SecondBorderLineWidth,
// KoParagraphStyle::DistanceToSecondBorder,
KoParagraphStyle::LeftPadding,
KoParagraphStyle::TopPadding,
KoParagraphStyle::RightPadding,
KoParagraphStyle::BottomPadding,
KoParagraphStyle::LeftBorderWidth,
KoParagraphStyle::LeftInnerBorderWidth,
KoParagraphStyle::LeftBorderSpacing,
KoParagraphStyle::LeftBorderStyle,
KoParagraphStyle::TopBorderWidth,
KoParagraphStyle::TopInnerBorderWidth,
KoParagraphStyle::TopBorderSpacing,
KoParagraphStyle::TopBorderStyle,
KoParagraphStyle::RightBorderWidth,
KoParagraphStyle::RightInnerBorderWidth,
KoParagraphStyle::RightBorderSpacing,
KoParagraphStyle::RightBorderStyle,
KoParagraphStyle::BottomBorderWidth,
KoParagraphStyle::BottomInnerBorderWidth,
KoParagraphStyle::BottomBorderSpacing,
KoParagraphStyle::BottomBorderStyle,
KoParagraphStyle::LeftBorderColor,
KoParagraphStyle::TopBorderColor,
KoParagraphStyle::RightBorderColor,
KoParagraphStyle::BottomBorderColor,
KoParagraphStyle::ExplicitListValue,
KoParagraphStyle::RestartListNumbering,
-1
};
KoParagraphStyle::KoParagraphStyle()
: m_charStyle(new KoCharacterStyle(this)),
m_listStyle(0),
......@@ -131,68 +195,6 @@ QColor KoParagraphStyle::propertyColor(int key) const {
}
void KoParagraphStyle::applyStyle(QTextBlockFormat &format) const {
// copy all relevant properties.
static const int properties[] = {
QTextFormat::BlockTopMargin,
QTextFormat::BlockBottomMargin,
QTextFormat::BlockLeftMargin,
QTextFormat::BlockRightMargin,
QTextFormat::BlockAlignment,
QTextFormat::TextIndent,
QTextFormat::BlockIndent,
QTextFormat::BlockNonBreakableLines,
StyleId,
FixedLineHeight,
MinimumLineHeight,
LineSpacing,
LineSpacingFromFont,
// AlignLastLine,
// WidowThreshold,
// OrphanThreshold,
// DropCaps,
// DropCapsLength,
// DropCapsLines,
// DropCapsDistance,
// FollowDocBaseline,
BreakBefore,
BreakAfter,
// HasLeftBorder,
// HasTopBorder,
// HasRightBorder,
// HasBottomBorder,
// BorderLineWidth,
// SecondBorderLineWidth,
// DistanceToSecondBorder,
LeftPadding,
TopPadding,
RightPadding,
BottomPadding,
LeftBorderWidth,
LeftInnerBorderWidth,
LeftBorderSpacing,
LeftBorderStyle,
TopBorderWidth,
TopInnerBorderWidth,
TopBorderSpacing,
TopBorderStyle,
RightBorderWidth,
RightInnerBorderWidth,
RightBorderSpacing,
RightBorderStyle,
BottomBorderWidth,
BottomInnerBorderWidth,
BottomBorderSpacing,
BottomBorderStyle,
LeftBorderColor,
TopBorderColor,
RightBorderColor,
BottomBorderColor,
ExplicitListValue,
RestartListNumbering,
-1
};
int i=0;
while(properties[i] != -1) {
QVariant const *variant = get(properties[i]);
......@@ -533,4 +535,23 @@ void KoParagraphStyle::loadOasis(KoStyleStack& styleStack) {
}
// static
KoParagraphStyle *KoParagraphStyle::fromBlockFormat(const QTextBlockFormat &format) {
KoParagraphStyle *answer = new KoParagraphStyle();
delete answer->characterStyle(); // TODO instead replace it with a character style from a QTextCharFormat
answer->m_charStyle = 0;
int i=0;
while(properties[i] != -1) {
int key = properties[i];
if(format.hasProperty(key))
answer->setProperty(key, format.property(key));
i++;
}
// listStyle ??
return answer;
}
#include "KoParagraphStyle.moc"
......@@ -349,10 +349,13 @@ public:
void setTextIndent (double margin) { setProperty(QTextFormat::TextIndent, margin); }
/// duplicated property from QTextBlockFormat
double textIndent () const { return propertyDouble(QTextFormat::TextIndent); }
#if 0
as this is a duplicate of leftMargin, lets make it very clear we are using that one.
/// duplicated property from QTextBlockFormat
void setIndent (int indent) { setProperty(QTextFormat::BlockIndent, indent); }
/// duplicated property from QTextBlockFormat
int indent () const { return propertyInt(QTextFormat::BlockIndent); }
#endif
/// duplicated property from QTextBlockFormat
void setNonBreakableLines(bool on) { setProperty(QTextFormat::BlockNonBreakableLines, on); }
/// duplicated property from QTextBlockFormat
......@@ -435,6 +438,8 @@ public:
*/
void loadOasis(KoStyleStack& styleStack);
static KoParagraphStyle *fromBlockFormat(const QTextBlockFormat &format);
private:
void setProperty(int key, const QVariant &value);
void remove(int key);
......
......@@ -53,7 +53,6 @@ KoStyleManager::KoStyleManager(QObject *parent)
d->standard->setBottomMargin(0);
d->standard->setRightMargin(0);
d->standard->setTextIndent(0);
d->standard->setIndent(0);
d->standard->setAlignment(Qt::AlignLeft);
d->standard->setName( i18n("[No Paragraph Style]"));
d->standard->characterStyle()->setName(i18n("[No Character Style]"));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment