本文整理汇总了C++中KoParagraphStyle类的典型用法代码示例。如果您正苦于以下问题:C++ KoParagraphStyle类的具体用法?C++ KoParagraphStyle怎么用?C++ KoParagraphStyle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KoParagraphStyle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: slotApply
void ParagraphSettingsDialog::slotApply()
{
if (!m_styleChanged) {
return;
}
KoParagraphStyle chosenStyle;
m_paragraphGeneral->save(&chosenStyle);
QTextCharFormat cformat;
QTextBlockFormat format;
chosenStyle.KoCharacterStyle::applyStyle(cformat);
chosenStyle.applyStyle(format);
KoListLevelProperties llp;
if (chosenStyle.listStyle()) {
llp = chosenStyle.listStyle()->levelProperties(chosenStyle.listStyle()->listLevels().first());
} else {
llp.setStyle(KoListStyle::None);
}
m_editor->applyDirectFormatting(cformat, format, llp);
m_styleChanged = false;
}
示例2: QString
QString KoTextWriter::saveParagraphStyle(const QTextBlockFormat &blockFormat, const QTextCharFormat &charFormat, KoStyleManager * styleManager, KoShapeSavingContext &context)
{
KoParagraphStyle *defaultParagraphStyle = styleManager->defaultParagraphStyle();
KoParagraphStyle *originalParagraphStyle = styleManager->paragraphStyle(blockFormat.intProperty(KoParagraphStyle::StyleId));
if (!originalParagraphStyle)
originalParagraphStyle = defaultParagraphStyle;
QString generatedName;
QString displayName = originalParagraphStyle->name();
QString internalName = QString(QUrl::toPercentEncoding(displayName, "", " ")).replace('%', '_');
// we'll convert the blockFormat to a KoParagraphStyle to check for local changes.
KoParagraphStyle paragStyle(blockFormat, charFormat);
if (paragStyle == (*originalParagraphStyle)) { // This is the real, unmodified character style.
// TODO zachmann: this could use the name of the saved style without saving it again
// therefore we would need to store that information in the saving context
if (originalParagraphStyle != defaultParagraphStyle) {
KoGenStyle style(KoGenStyle::ParagraphStyle, "paragraph");
originalParagraphStyle->saveOdf(style, context);
generatedName = context.mainStyles().insert(style, internalName, KoGenStyles::DontAddNumberToName);
}
} else { // There are manual changes... We'll have to store them then
KoGenStyle style(KoGenStyle::ParagraphAutoStyle, "paragraph", internalName);
if (context.isSet(KoShapeSavingContext::AutoStyleInStyleXml))
style.setAutoStyleInStylesDotXml(true);
if (originalParagraphStyle) {
paragStyle.removeDuplicates(*originalParagraphStyle);
paragStyle.setParentStyle(originalParagraphStyle);
}
paragStyle.saveOdf(style, context);
generatedName = context.mainStyles().insert(style, "P");
}
return generatedName;
}
示例3: styleAltered
void ParagraphGeneral::save(KoParagraphStyle *style)
{
KoParagraphStyle *savingStyle;
if (style == 0) {
if (m_style == 0)
return;
else
savingStyle = m_style;
}
else
savingStyle = style;
m_paragraphIndentSpacing->save(savingStyle);
m_paragraphLayout->save(savingStyle);
m_paragraphBulletsNumbers->save(savingStyle);
m_paragraphDecorations->save(savingStyle);
savingStyle->setNextStyle(widget.nextStyle->itemData(widget.nextStyle->currentIndex()).toInt());
emit styleAltered(savingStyle);
/* int parentStyleId = widget.inheritStyle->itemData(widget.inheritStyle->currentIndex()).toInt();
if (parentStyleId == 0)
m_style->setParentStyle(0);
else {
foreach(KoParagraphStyle *style, m_paragraphStyles) {
if (style->styleId() == parentStyleId) {
m_style->setParentStyle(style);
break;
}
}
}
*/
}
示例4: foreach
void StylesWidget::setCurrentFormat(const QTextBlockFormat &format)
{
if (format == m_currentBlockFormat)
return;
m_currentBlockFormat = format;
int id = m_currentBlockFormat.intProperty(KoParagraphStyle::StyleId);
// bool unchanged = true;
KoParagraphStyle *usedStyle = 0;
if (m_styleManager)
usedStyle = m_styleManager->paragraphStyle(id);
if (usedStyle) {
foreach(int property, m_currentBlockFormat.properties().keys()) {
if (property == QTextFormat::ObjectIndex)
continue;
if (property == KoParagraphStyle::ListStyleId)
continue;
if (m_currentBlockFormat.property(property) != usedStyle->value(property)) {
// unchanged = false;
break;
}
}
}
m_blockSignals = true;
// m_stylesModel->setCurrentParagraphStyle(id, unchanged);
m_blockSignals = false;
widget.stylesView->setCurrentIndex(m_stylesModel->indexOf(*usedStyle));
}
示例5: QImage
QImage KoStyleThumbnailer::thumbnail(KoCharacterStyle *characterStyle, KoParagraphStyle *paragraphStyle, QSize size, bool recreateThumbnail, KoStyleThumbnailerFlags flags)
{
if ((flags & UseStyleNameText) && (!characterStyle || characterStyle->name().isNull())) {
return QImage();
} else if ((! (flags & UseStyleNameText)) && d->thumbnailText.isEmpty()) {
return QImage();
}
else if (characterStyle == 0) {
return QImage();
}
if (!size.isValid() || size.isNull()) {
size = d->defaultSize;
}
QString imageKey = "c_" + QString::number(reinterpret_cast<unsigned long>(characterStyle)) + "_"
+ "p_" + QString::number(reinterpret_cast<unsigned long>(paragraphStyle)) + "_"
+ QString::number(size.width()) + "_" + QString::number(size.height());
if (!recreateThumbnail && d->thumbnailCache.object(imageKey)) {
return QImage(*(d->thumbnailCache.object(imageKey)));
}
QImage *im = new QImage(size.width(), size.height(), QImage::Format_ARGB32_Premultiplied);
im->fill(QColor(Qt::transparent).rgba());
QTextCursor cursor(d->thumbnailHelperDocument);
QTextCharFormat format;
// Default to black as text color, to match what KoTextLayoutArea::paint(...)
// does, setting solid black if no brush is set. Otherwise the UI text color
// would be used, which might be too bright with dark UI color schemes
format.setForeground(QColor(Qt::black));
KoCharacterStyle *characterStyleClone = characterStyle->clone();
characterStyleClone->applyStyle(format);
cursor.select(QTextCursor::Document);
cursor.setBlockFormat(QTextBlockFormat());
cursor.setBlockCharFormat(QTextCharFormat());
cursor.setCharFormat(QTextCharFormat());
if (paragraphStyle) {
KoParagraphStyle *paragraphStyleClone = paragraphStyle->clone();
// paragraphStyleClone->KoCharacterStyle::applyStyle(format);
QTextBlock block = cursor.block();
paragraphStyleClone->applyStyle(block, true);
delete paragraphStyleClone;
paragraphStyleClone = 0;
}
if (flags & UseStyleNameText) {
cursor.insertText(characterStyleClone->name(), format);
} else {
cursor.insertText(d->thumbnailText, format);
}
layoutThumbnail(size, im, flags);
d->thumbnailCache.insert(imageKey, im);
delete characterStyleClone;
return QImage(*im);
}
示例6: styleNameToStyleId
int KoBibliographyInfo::styleNameToStyleId(KoTextSharedLoadingData *sharedLoadingData, const QString &styleName)
{
KoParagraphStyle * style = sharedLoadingData->paragraphStyle(styleName, true);
if (style) {
return style->styleId();
}
return 0;
}
示例7: deleteLater
void ChangeFollower::processUpdates(const QList<int> &changedStyles)
{
KoStyleManager *sm = m_styleManager.data();
if (!sm) {
// since the stylemanager would be the one calling this method, I doubt this
// will ever happen. But better safe than sorry..
deleteLater();
return;
}
// optimization strategy; store the formatid of the formats we checked into
// a qset for 'hits' and 'ignores' and avoid the copying of the format
// (fragment.charFormat() / block.blockFormat()) when the formatId is
// already checked previosly
QTextCursor cursor(m_document);
QTextBlock block = cursor.block();
while (block.isValid()) {
QTextBlockFormat bf = block.blockFormat();
int id = bf.intProperty(KoParagraphStyle::StyleId);
if (id > 0 && changedStyles.contains(id)) {
cursor.setPosition(block.position());
KoParagraphStyle *style = sm->paragraphStyle(id);
Q_ASSERT(style);
style->applyStyle(bf);
cursor.setBlockFormat(bf);
}
QTextCharFormat cf = block.charFormat();
id = cf.intProperty(KoCharacterStyle::StyleId);
if (id > 0 && changedStyles.contains(id)) {
KoCharacterStyle *style = sm->characterStyle(id);
Q_ASSERT(style);
style->applyStyle(block);
}
QTextBlock::iterator iter = block.begin();
while (! iter.atEnd()) {
QTextFragment fragment = iter.fragment();
cf = fragment.charFormat();
id = cf.intProperty(KoCharacterStyle::StyleId);
if (id > 0 && changedStyles.contains(id)) {
// create selection
cursor.setPosition(fragment.position());
cursor.setPosition(fragment.position() + fragment.length(), QTextCursor::KeepAnchor);
KoCharacterStyle *style = sm->characterStyle(id);
Q_ASSERT(style);
style->applyStyle(cf);
cursor.mergeCharFormat(cf);
}
iter++;
}
block = block.next();
}
}
示例8: data
void TestBorder::testBorder()
{
KoParagraphStyle style;
style.setLeftBorderWidth(4.0);
style.setLeftBorderSpacing(2.0);
style.setLeftInnerBorderWidth(1.0);
style.setTopBorderWidth(6.0);
style.setTopBorderSpacing(7.0);
style.setTopInnerBorderWidth(8.0);
QTextBlockFormat format;
style.applyStyle(format);
KoTextBlockBorderData data(QRectF(10, 10, 100, 100));
data.setEdge(KoTextBlockBorderData::Left, format, KoParagraphStyle::LeftBorderStyle,
KoParagraphStyle::LeftBorderWidth, KoParagraphStyle::LeftBorderColor,
KoParagraphStyle::LeftBorderSpacing, KoParagraphStyle::LeftInnerBorderWidth);
data.setEdge(KoTextBlockBorderData::Top, format, KoParagraphStyle::TopBorderStyle,
KoParagraphStyle::TopBorderWidth, KoParagraphStyle::TopBorderColor,
KoParagraphStyle::TopBorderSpacing, KoParagraphStyle::TopInnerBorderWidth);
//QCOMPARE(QRectF(10, 10, 100, 80), data.rect());
QCOMPARE(7., data.inset(KoTextBlockBorderData::Left));
QCOMPARE(0., data.inset(KoTextBlockBorderData::Right));
QCOMPARE(21., data.inset(KoTextBlockBorderData::Top));
QCOMPARE(0., data.inset(KoTextBlockBorderData::Bottom));
}
示例9: testAddAppliedParagraphStyle
void TestStyleManager::testAddAppliedParagraphStyle()
{
// Create style, apply it, then add it to the manager.
KoParagraphStyle paragraphStyle;
QTextBlock block = m_doc->begin();
paragraphStyle.applyStyle(block);
m_styleManager->beginEdit();
m_styleManager->add(¶graphStyle);
m_styleManager->endEdit();
// Check that style is marked as used.
QVERIFY(m_styleManager->usedParagraphStyles().contains(paragraphStyle.styleId()));
}
示例10: initForNewTest
void TestDocumentLayout::testBasicList()
{
initForNewTest("Base\nListItem\nListItem2: The quick brown fox jums over the lazy dog.\nNormal\nNormal");
KoParagraphStyle style;
QTextBlock block = m_doc->begin();
style.applyStyle(block);
block = block.next();
QVERIFY(block.isValid());
KoListStyle listStyle;
KoListLevelProperties level1;
level1.setStyle(KoListStyle::Bullet);
listStyle.setLevelProperties(level1);
style.setListStyle(&listStyle);
style.applyStyle(block); // make this a listStyle
QVERIFY(block.textList());
QCOMPARE(block.textList()->format().intProperty(QTextListFormat::ListStyle), (int) KoListStyle::Bullet);
block = block.next();
QVERIFY(block.isValid());
style.applyStyle(block); // make this a listStyle
m_layout->layout();
QTextLayout *blockLayout = m_block.layout();
QCOMPARE(blockLayout->lineAt(0).x(), 0.0);
block = m_doc->begin().next();
QVERIFY(block.isValid());
blockLayout = block.layout(); // parag 2
KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(block.userData());
QVERIFY(data);
qreal counterSpacing = data->counterSpacing();
QVERIFY(counterSpacing > 0.);
// 12 is hardcoded to be the width of a discitem (taken from the default font):
QCOMPARE(blockLayout->lineAt(0).x(), 12.0 + counterSpacing);
block = block.next();
QVERIFY(block.isValid());
blockLayout = block.layout(); // parag 3
QCOMPARE(blockLayout->lineAt(0).x(), 12.0 + counterSpacing);
QVERIFY(blockLayout->lineCount() > 1);
QCOMPARE(blockLayout->lineAt(1).x(), 12.0 + counterSpacing); // make sure not only the first line is indented
block = block.next();
QVERIFY(block.isValid());
blockLayout = block.layout(); // parag 4
QCOMPARE(blockLayout->lineAt(0).x(), 0.0);
}
示例11: QModelIndex
void ValidParentStylesProxyModel::createMapping()
{
if (!m_styleManager || !m_sourceModel) {
return;
}
m_sourceToProxy.clear();
m_proxyToSource.clear();
for(int i = 0; i < m_sourceModel->rowCount(QModelIndex()); ++i) {
QModelIndex index = m_sourceModel->index(i, 0, QModelIndex());
int id = (int)index.internalId();
KoParagraphStyle *paragraphStyle = m_styleManager->paragraphStyle(id);
if (paragraphStyle) {
bool ok = true;
KoParagraphStyle *testStyle = paragraphStyle;
while (testStyle && ok) {
ok = testStyle->styleId() != m_currentChildStyleId;
testStyle = testStyle->parentStyle();
}
if (!ok) {
continue; //we cannot inherit ourself even indirectly through the parent chain
}
m_proxyToSource.append(i); //the style is ok for parenting
}
else {
KoCharacterStyle *characterStyle = m_styleManager->characterStyle(id);
if (characterStyle) {
bool ok = true;
KoCharacterStyle *testStyle = characterStyle;
while (testStyle && ok) {
ok = testStyle->styleId() != m_currentChildStyleId;
testStyle = testStyle->parentStyle();
}
if (!ok) {
continue; //we cannot inherit ourself even indirectly through the parent chain
}
m_proxyToSource.append(i); //the style is ok for parenting
}
}
}
m_sourceToProxy.fill(-1, m_sourceModel->rowCount(QModelIndex()));
for(int i = 0; i < m_proxyToSource.count(); ++i) {
m_sourceToProxy[m_proxyToSource.at(i)] = i;
}
}
示例12: appliedSignalSpy
void TestStyleManager::testApplyAddedParagraphStyle()
{
QSignalSpy appliedSignalSpy(m_styleManager, SIGNAL(styleApplied(const KoParagraphStyle*)));
// Create style, add it to the manager, then apply it.
KoParagraphStyle paragraphStyle;
m_styleManager->beginEdit();
m_styleManager->add(¶graphStyle);
m_styleManager->endEdit();
QTextBlock block = m_doc->begin();
paragraphStyle.applyStyle(block);
// Check that style is marked as used and that the correct signal was emitted.
QVERIFY(m_styleManager->usedParagraphStyles().contains(paragraphStyle.styleId()));
QCOMPARE(appliedSignalSpy.count(), 1);
QCOMPARE(appliedSignalSpy.at(0).at(0).value<const KoParagraphStyle *>(), ¶graphStyle);
}
示例13: length1
void TestStyles::testCopyParagraphStyle()
{
QTextLength length1(QTextLength::FixedLength, 10.0);
QTextLength length2(QTextLength::FixedLength, 20.0);
QTextLength length3(QTextLength::FixedLength, 30.0);
KoParagraphStyle style1;
KoParagraphStyle style2;
style2.setParentStyle(&style1);
style1.setLeftMargin(length1);
style1.setRightMargin(length3);
style2.setRightMargin(length2);
KoParagraphStyle newStyle;
newStyle.copyProperties(&style2);
QCOMPARE(newStyle.leftMargin(), 10.0);
QCOMPARE(newStyle.rightMargin(), 20.0);
}
示例14: styleNameToStyleId
int KoTableOfContentsGeneratorInfo::styleNameToStyleId(KoTextSharedLoadingData *sharedLoadingData, QString styleName)
{
//find styleId of a style based on its style:name property
KoParagraphStyle * style = sharedLoadingData->paragraphStyle(styleName, true);
if (style) {
return style->styleId();
}
//if the previous way of finding styles fails fall back on using style:display-name property of a style
QList<KoParagraphStyle *> paragraphStyles = sharedLoadingData->paragraphStyles(true);
QList<KoParagraphStyle *>::const_iterator iter = paragraphStyles.constBegin();
for (; iter != paragraphStyles.constEnd(); ++iter) {
if ((*iter)->name() == styleName) {
return (*iter)->styleId();
}
}
return 0;
}
示例15: addSignalSpy
void TestStyleManager::testAddRemoveParagraphStyle()
{
// Add paragraph style.
KoParagraphStyle paragraphStyle;
paragraphStyle.setName("Test Paragraph Style");
QSignalSpy addSignalSpy(m_styleManager, SIGNAL(styleAdded(KoParagraphStyle*)));
m_styleManager->beginEdit();
m_styleManager->add(¶graphStyle);
m_styleManager->endEdit();
QVERIFY(paragraphStyle.styleId() > 0);
QVERIFY(!m_styleManager->usedParagraphStyles().contains(paragraphStyle.styleId()));
QCOMPARE(m_styleManager->paragraphStyles().count(¶graphStyle), 1);
QCOMPARE(m_styleManager->paragraphStyle(paragraphStyle.styleId()), ¶graphStyle);
QCOMPARE(m_styleManager->paragraphStyle("Test Paragraph Style"), ¶graphStyle);
QCOMPARE(addSignalSpy.count(), 1);
QCOMPARE(addSignalSpy.at(0).at(0).value<KoParagraphStyle *>(), ¶graphStyle);
// Remove paragraph style.
QSignalSpy removeSignalSpy(m_styleManager, SIGNAL(styleRemoved(KoParagraphStyle*)));
m_styleManager->beginEdit();
m_styleManager->remove(¶graphStyle);
m_styleManager->endEdit();
QVERIFY(!m_styleManager->paragraphStyles().contains(¶graphStyle));
QVERIFY(!m_styleManager->paragraphStyle(paragraphStyle.styleId()));
QVERIFY(!m_styleManager->paragraphStyle("Test Paragraph Style"));
QCOMPARE(removeSignalSpy.count(), 1);
QCOMPARE(removeSignalSpy.at(0).at(0).value<KoParagraphStyle *>(), ¶graphStyle);
}