[calligra] /: Improve the bullet list rendering

Cyrille Berger Skott cberger at cberger.net
Mon Feb 28 15:01:31 GMT 2011


Hi,

This patch breaks the kotext-odf-TestLoading test:
http://my.cdash.org/testDetails.php?test=5223148&build=162447

On Monday 28 February 2011, Lukáš Tvrdý wrote:
> Git commit c833109aac79cf630f46bc8f5962532510d73d0f by Lukáš Tvrdý.
> Committed on 28/02/2011 at 15:39.
> Pushed by lukast into branch 'master'.
> 
> Improve the bullet list rendering
> 
> o Load&save the text-properties in
>   list-level-style-* from the ODF spec.
> o Don't render the mark shapes with QPainter,
>   but use font directly (as OOo or MS Office does)
> 
> This patch includes also work from Gopalak's patch
> 
> M  +2    -0    libs/kotext/styles/KoCharacterStyle.h
> M  +41   -23   libs/kotext/styles/KoListLevelProperties.cpp
> M  +5    -4    libs/kotext/styles/KoListLevelProperties.h
> M  +2    -1    libs/kotext/styles/KoListStyle.h
> M  +12   -2    libs/kotext/styles/KoParagraphStyle.cpp
> M  +5    -1    libs/kotext/styles/KoParagraphStyle.h
> M  +74   -104  plugins/textshape/Layout.cpp
> 
> http://commits.kde.org/calligra/c833109aac79cf630f46bc8f5962532510d73d0f
> 
> diff --git a/libs/kotext/styles/KoCharacterStyle.h
> b/libs/kotext/styles/KoCharacterStyle.h index 58da5df..3cec793 100644
> --- a/libs/kotext/styles/KoCharacterStyle.h
> +++ b/libs/kotext/styles/KoCharacterStyle.h
> @@ -377,4 +377,6 @@ private:
>      Private * const d;
>  };
> 
> +Q_DECLARE_METATYPE(QSharedPointer<KoCharacterStyle>)
> +
>  #endif
> diff --git a/libs/kotext/styles/KoListLevelProperties.cpp
> b/libs/kotext/styles/KoListLevelProperties.cpp index a8afd7a..62a5175
> 100644
> --- a/libs/kotext/styles/KoListLevelProperties.cpp
> +++ b/libs/kotext/styles/KoListLevelProperties.cpp
> @@ -4,6 +4,7 @@
>   * Copyright (C) 2008 Pierre Ducroquet <pinaraf at pinaraf.info>
>   * Copyright (C) 2008 Girish Ramakrishnan <girish at forwardbias.in>
>   * Copyright (C) 2010 Nandita Suri <suri.nandita at gmail.com>
> + * Copyright (C) 2011 Lukáš Tvrdý <lukas.tvrdy at ixonos.com>
>   *
>   * This library is free software; you can redistribute it and/or
>   * modify it under the terms of the GNU Library General Public
> @@ -38,6 +39,7 @@
>  #include <KoImageCollection.h>
>  #include <KoImageData.h>
>  #include <KoOdfNumberDefinition.h>
> +#include <KoGenStyle.h>
> 
>  class KoListLevelProperties::Private
>  {
> @@ -225,24 +227,28 @@ int KoListLevelProperties::characterStyleId() const
>      return propertyInt(KoListStyle::CharacterStyleId);
>  }
> 
> -void KoListLevelProperties::setBulletCharacter(QChar character)
> +void KoListLevelProperties::setMarkCharacterStyle(QSharedPointer<
> KoCharacterStyle > style) {
> -    setProperty(KoListStyle::BulletCharacter, (int) character.unicode());
> +    setProperty(KoListStyle::MarkCharacterStyleId, QVariant::fromValue<
> QSharedPointer<KoCharacterStyle> >(style)); }
> 
> -QChar KoListLevelProperties::bulletCharacter() const
> +QSharedPointer<KoCharacterStyle>
> KoListLevelProperties::markCharacterStyle() const {
> -    return propertyInt(KoListStyle::BulletCharacter);
> +    const QVariant v =
> d->stylesPrivate.value(KoListStyle::MarkCharacterStyleId); +    if
> (v.isNull()) {
> +        return static_cast< QSharedPointer<KoCharacterStyle> >(0);
> +    }
> +    return v.value< QSharedPointer<KoCharacterStyle> >();
>  }
> 
> -void KoListLevelProperties::setBulletColor(QColor color)
> +void KoListLevelProperties::setBulletCharacter(QChar character)
>  {
> -    setProperty(KoListStyle::BulletColor, color);
> +    setProperty(KoListStyle::BulletCharacter, (int) character.unicode());
>  }
> 
> -QColor KoListLevelProperties::bulletColor() const
> +QChar KoListLevelProperties::bulletCharacter() const
>  {
> -    return propertyColor(KoListStyle::BulletColor);
> +    return propertyInt(KoListStyle::BulletCharacter);
>  }
> 
>  void KoListLevelProperties::setRelativeBulletSize(int percent)
> @@ -384,6 +390,7 @@ void
> KoListLevelProperties::loadOdf(KoShapeLoadingContext& scontext, const
> KoXml "display-levels", QString());
> 
>      const QString styleName = style.attributeNS(KoXmlNS::text,
> "style-name", QString()); +    KoCharacterStyle *cs = 0;
>      if (!styleName.isEmpty()) {
>  //         kDebug(32500) << "Should use the style =>" << styleName <<
> "<=";
> 
> @@ -393,7 +400,7 @@ void
> KoListLevelProperties::loadOdf(KoShapeLoadingContext& scontext, const
> KoXml textSharedData = dynamic_cast<KoTextSharedLoadingData
> *>(sharedData); }
>          if (textSharedData) {
> -            KoCharacterStyle *cs =
> textSharedData->characterStyle(styleName, context.useStylesAutoStyles());
> +            cs = textSharedData->characterStyle(styleName,
> context.useStylesAutoStyles()); if (!cs) {
>                 kWarning(32500) << "Missing KoCharacterStyle!";
>              }
> @@ -407,6 +414,10 @@ void
> KoListLevelProperties::loadOdf(KoShapeLoadingContext& scontext, const
> KoXml
> 
>      if (style.localName() == "list-level-style-bullet") {   // list with
> bullets
> 
> +        // special case bullets:
> +        //qDebug() << QChar(0x2202) << QChar(0x25CF) << QChar(0xF0B7) <<
> QChar(0xE00C) +        //<< QChar(0xE00A) << QChar(0x27A2)<< QChar(0x2794)
> << QChar(0x2714) << QChar(0x2d) << QChar(0x2717); +
>          //1.6: KoParagCounter::loadOasisListStyle
>          QString bulletChar = style.attributeNS(KoXmlNS::text,
> "bullet-char", QString()); //         kDebug(32500) <<
> "style.localName()=" << style.localName() << "level=" << level <<
> "displayLevel=" << displayLevel << "bulletChar=" << bulletChar; @@ -446,7
> +457,7 @@ void KoListLevelProperties::loadOdf(KoShapeLoadingContext&
> scontext, const KoXml break;
>              default:
>                  QChar customBulletChar = bulletChar[0];
> -                kDebug(32500) << "Unhandled bullet code 0x" <<
> QString::number((uint)customBulletChar.unicode(), 16); +               
> kDebug(32500) << "Unhandled bullet code 0x" <<
> QString::number((uint)customBulletChar.unicode(), 16) << bulletChar;
> kDebug(32500) << "Should use the style =>" <<
> style.attributeNS(KoXmlNS::text, "style-name", QString()) << "<=";
> setStyle(KoListStyle::CustomCharItem);
>                  /*
> @@ -563,12 +574,12 @@ void
> KoListLevelProperties::loadOdf(KoShapeLoadingContext& scontext, const
> KoXml qreal ti = textindent.isEmpty() ? 0 :
> KoUnit::parseValue(textindent); qreal ml = marginleft.isEmpty() ? 0 :
> KoUnit::parseValue(marginleft); setIndent(qMax<qreal>(0.0, ti + ml));
> -
> +
>                          setMinimumWidth(0);
>                          setMinimumDistance(0);
> -
> +
>                          //TODO support ODF 18.829 text:label-followed-by
> and 18.832 text:list-tab-stop-position -                     }
> +                     }
>                  }
>              } else { // default is mode == "label-width-and-position"
>                  // The text:space-before, text:min-label-width,
> text:minimum-label-distance and fo:text-align attributes @@ -599,10
> +610,13 @@ void KoListLevelProperties::loadOdf(KoShapeLoadingContext&
> scontext, const KoXml setHeight(KoUnit::parseValue(height));
>              }
>          } else if (localName == "text-properties") {
> -            // TODO
> -            QString color(property.attributeNS(KoXmlNS::fo, "color"));
> -            if (!color.isEmpty())
> -                setBulletColor(QColor(color));
> +            QSharedPointer<KoCharacterStyle> charStyle =
> QSharedPointer<KoCharacterStyle>(new KoCharacterStyle); +           
> context.styleStack().save();
> +            context.styleStack().push(style);
> +            context.styleStack().setTypeProperties("text");   // load all
> style attributes from "style:text-properties" +           
> charStyle->loadOdf(scontext);
> +            context.styleStack().restore();
> +            setMarkCharacterStyle(charStyle);
>          }
>      }
>  }
> @@ -690,13 +704,17 @@ void KoListLevelProperties::saveOdf(KoXmlWriter
> *writer) const writer->addAttribute("text:min-label-distance",
> toPoint(minimumDistance()));
> 
>      writer->endElement(); // list-level-properties
> -
> -    writer->startElement("style:text-properties", false);
> 
> -    if (d->stylesPrivate.contains(KoListStyle::BulletColor))
> -        writer->addAttribute("fo:color",bulletColor().name());
> -
> -    writer->endElement(); // text-properties
> +    // text properties
> +
> +    if (d->stylesPrivate.contains(KoListStyle::MarkCharacterStyleId)) {
> +        KoGenStyle liststyle(KoGenStyle::ListStyle);
> +
> +        QSharedPointer<KoCharacterStyle> cs = markCharacterStyle();
> +        cs->saveOdf(liststyle);
> +
> +        liststyle.writeStyleProperties(writer, KoGenStyle::TextType);
> +    }
> 
>  //   kDebug(32500) << "Key KoListStyle::ListItemPrefix :" <<
> d->stylesPrivate.value(KoListStyle::ListItemPrefix); //   kDebug(32500) <<
> "Key KoListStyle::ListItemSuffix :" <<
> d->stylesPrivate.value(KoListStyle::ListItemSuffix); diff --git
> a/libs/kotext/styles/KoListLevelProperties.h
> b/libs/kotext/styles/KoListLevelProperties.h index cfa765a..14814fe 100644
> --- a/libs/kotext/styles/KoListLevelProperties.h
> +++ b/libs/kotext/styles/KoListLevelProperties.h
> @@ -27,6 +27,7 @@
> 
>  #include <KoXmlReader.h>
> 
> +class KoCharacterStyle;
>  class KoListStyle;
>  class KoShapeLoadingContext;
>  class KoXmlWriter;
> @@ -78,14 +79,14 @@ public:
>      void setCharacterStyleId(int id);
>      /// return the styleId of the KoCharacterStyle to be used to layout
> the listitem int characterStyleId() const;
> +    /// set the style for the bullet or the number of the list
> +    void setMarkCharacterStyle(QSharedPointer<KoCharacterStyle> style);
> +    /// return the KoCharacterStyle for the bullet or the number of the
> list +    QSharedPointer<KoCharacterStyle> markCharacterStyle() const;
>      /// set the character to be used as the counter of the listitem
>      void setBulletCharacter(QChar character);
>      /// return the character to be used as the counter of the listitem
>      QChar bulletCharacter() const;
> -    /// set the color to be used as the counter of the listitem
> -    void setBulletColor(QColor color);
> -    /// return the color to be used as the counter of the listitem
> -    QColor bulletColor() const;
>      /// set the size, in percent, of the bullet counter relative to the
> fontsize of the counter void setRelativeBulletSize(int percent);
>      /// return the size, in percent, of the bullet counter relative to the
> fontsize of the counter diff --git a/libs/kotext/styles/KoListStyle.h
> b/libs/kotext/styles/KoListStyle.h index 6d7b67f..bee4eaf 100644
> --- a/libs/kotext/styles/KoListStyle.h
> +++ b/libs/kotext/styles/KoListStyle.h
> @@ -2,6 +2,7 @@
>   * Copyright (C) 2006-2010 Thomas Zander <zander at kde.org>
>   * Copyright (C) 2008 Girish Ramakrishnan <girish at forwardbias.in>
>   * Copyright (C) 2010 Nandita Suri <suri.nandita at gmail.com>
> + * Copyright (C) 2011 Lukáš Tvrdý <lukas.tvrdy at ixonos.com>
>   *
>   * This library is free software; you can redistribute it and/or
>   * modify it under the terms of the GNU Library General Public
> @@ -124,6 +125,7 @@ public:
>          Level,          ///< list nesting level, is 1 or higher, or zero
> when implied DisplayLevel,   ///< show this many levels. Is always lower
> than the (implied) level. CharacterStyleId,///< CharacterStyle used for
> markup of the counter +        MarkCharacterStyleId, ///< This stores the
> character style used for the mark of the list item BulletCharacter,///< an
> int with the unicode value of the character (for CustomCharItem)
> BulletSize,     ///< size in percent relative to the height of the text
> Alignment,      ///< Alignment of the counter
> @@ -138,7 +140,6 @@ public:
>          Width,          ///< The width, in pt, of  a picture bullet.
>          Height,         ///< The height, in pt, of a picture bullet.
>          BulletImageKey, ///< Bullet image stored as a key for lookup in
> the imageCollection -        BulletColor     ///< color of the counter
>      };
> 
>      /**
> diff --git a/libs/kotext/styles/KoParagraphStyle.cpp
> b/libs/kotext/styles/KoParagraphStyle.cpp index 4ca34b0..7243744 100644
> --- a/libs/kotext/styles/KoParagraphStyle.cpp
> +++ b/libs/kotext/styles/KoParagraphStyle.cpp
> @@ -5,6 +5,7 @@
>   * Copyright (C) 2008 Thorsten Zachmann <zachmann at kde.org>
>   * Copyright (C) 2008 Roopesh Chander <roop at forwardbias.in>
>   * Copyright (C) 2008 Girish Ramakrishnan <girish at forwardbias.in>
> + * Copyright (C) 2011 Gopalakrishna Bhat A <gopalakbhat at gmail.com>
>   *
>   * This library is free software; you can redistribute it and/or
>   * modify it under the terms of the GNU Library General Public
> @@ -1008,7 +1009,7 @@ void KoParagraphStyle::loadOdf(const KoXmlElement
> *element, KoShapeLoadingContex if (ok)
>              setDefaultOutlineLevel(level);
>      }
> -
> +
>      // 15.5.30 - 31
>      if (element->hasAttributeNS(KoXmlNS::text, "number-lines")) {
>          setLineNumbering(element->attributeNS(KoXmlNS::text,
> "number-lines", "false") == "true"); @@ -1019,7 +1020,7 @@ void
> KoParagraphStyle::loadOdf(const KoXmlElement *element,
> KoShapeLoadingContex setLineNumberStartValue(startValue);
>                  }
>              }
> -    }
> +    }
> 
>      //1.6: KoTextFormat::load
>      KoCharacterStyle *charstyle = characterStyle();
> @@ -1753,4 +1754,13 @@ void KoParagraphStyle::saveOdf(KoGenStyle &style,
> KoGenStyles &mainStyles) }
>  }
> 
> +bool KoParagraphStyle::hasDefaults() const
> +{
> +    int size=d->stylesPrivate.properties().size();
> +    if ((size == 0) || (size==1 &&
> d->stylesPrivate.properties().contains(StyleId))) { +        return true;
> +    }
> +    return false;
> +}
> +
>  #include <KoParagraphStyle.moc>
> diff --git a/libs/kotext/styles/KoParagraphStyle.h
> b/libs/kotext/styles/KoParagraphStyle.h index d531b96..851a5c5 100644
> --- a/libs/kotext/styles/KoParagraphStyle.h
> +++ b/libs/kotext/styles/KoParagraphStyle.h
> @@ -588,7 +588,11 @@ public:
>       * @returns a QVariant which holds the property value.
>       */
>      QVariant value(int key) const;
> -
> +    /**
> +     * Returns true if this pragraph style has default properties
> +     * Note that the value of StyleId property is not considered
> +     */
> +    bool hasDefaults() const;
>  signals:
>      void nameChanged(const QString &newName);
> 
> diff --git a/plugins/textshape/Layout.cpp b/plugins/textshape/Layout.cpp
> index 2dfb610..762c92b 100644
> --- a/plugins/textshape/Layout.cpp
> +++ b/plugins/textshape/Layout.cpp
> @@ -8,6 +8,8 @@
>   * Copyright (C) 2009-2010 Casper Boemann <cbo at boemann.dk>
>   * Copyright (C) 2010 Nandita Suri <suri.nandita at gmail.com>
>   * Copyright (C) 2010 Ajay Pundhir <ajay.pratap at iiitb.net>
> + * Copyright (C) 2011 Lukáš Tvrdý <lukas.tvrdy at ixonos.com>
> + * Copyright (C) 2011 Gopalakrishna Bhat A <gopalakbhat at gmail.com>
>   *
>   * This library is free software; you can redistribute it and/or
>   * modify it under the terms of the GNU Library General Public
> @@ -1951,73 +1953,115 @@ void Layout::drawListItem(QPainter *painter, const
> QTextBlock &block, KoImageCol QTextList *list = block.textList();
>      if (list && data->hasCounterData()) {
>          QTextListFormat listFormat = list->format();
> -        QTextCharFormat cf;
> -        bool filled = false;
> +        QTextCharFormat chFormatMaxFontSize;
> +
> +        KoCharacterStyle *cs = 0;
>          if (m_styleManager) {
>              const int id =
> listFormat.intProperty(KoListStyle::CharacterStyleId); -           
> KoCharacterStyle *cs = m_styleManager->characterStyle(id); +            cs
> = m_styleManager->characterStyle(id);
>              if (!cs) {
>                  KoParagraphStyle *ps = m_styleManager->paragraphStyle(
>                                        
> block.blockFormat().intProperty(KoParagraphStyle::StyleId)); -            
>    if (ps)
> +                if (ps && !ps->hasDefaults()) {
>                      cs = ps->characterStyle();
> +                }
> +            }
> +        }
> +
> +        if ( cs && cs->hasProperty(QTextFormat::FontPointSize) ) {
> +                cs->applyStyle(chFormatMaxFontSize);
> +        } else {
> +            // use format from the actual block of the list item
> +            QTextCharFormat chFormatBlock;
> +            if (block.text().size() == 0) {
> +                chFormatBlock = block.charFormat();
> +            } else {
> +                chFormatBlock = block.begin().fragment().charFormat();
>              }
> -            if (cs) {
> -                cs->applyStyle(cf);
> -                filled = true;
> +
> +            chFormatMaxFontSize = chFormatBlock;
> +
> +            QTextBlock::iterator it;
> +            QTextFragment currentFragment;
> +            for (it = block.begin(); !it.atEnd(); ++it) {
> +                currentFragment = it.fragment();
> +                if ( currentFragment.isValid() &&
> (chFormatMaxFontSize.fontPointSize() <
> currentFragment.charFormat().fontPointSize()) ) { +                   
> chFormatMaxFontSize = currentFragment.charFormat(); +                }
>              }
>          }
> -        if (!filled) {
> -            // use first char of first block.
> -            QTextBlock firstBlockOfList = list->item(0);
> -            QTextCursor cursor(firstBlockOfList);
> -            cf = cursor.charFormat();
> +
> +        // fetch the text properties of the list-level-style-bullet
> +        if (listFormat.hasProperty(KoListStyle::MarkCharacterStyleId)) {
> +            QVariant v =
> listFormat.property(KoListStyle::MarkCharacterStyleId); +           
> QSharedPointer<KoCharacterStyle> textPropertiesCharStyle = v.value<
> QSharedPointer<KoCharacterStyle> >(); +            if
> (!textPropertiesCharStyle.isNull()) {
> +                textPropertiesCharStyle->applyStyle( chFormatMaxFontSize
> ); +            }
>          }
> 
>          if (! data->counterText().isEmpty()) {
> -            QFont font(cf.font(), m_parent->paintDevice());
> -            QTextLayout layout(data->counterText(), font,
> m_parent->paintDevice()); +            QFont
> font(chFormatMaxFontSize.font(), m_parent->paintDevice()); +
> +            QString result = data->counterText();
> +            KoListStyle::Style listStyle =
> static_cast<KoListStyle::Style>(listFormat.style()); +            if
> (listStyle == KoListStyle::SquareItem            || listStyle ==
> KoListStyle::DiscItem       || +                listStyle ==
> KoListStyle::CircleItem            || listStyle == KoListStyle::BoxItem   
>     || +                listStyle == KoListStyle::RhombusItem           ||
> listStyle == KoListStyle::CustomCharItem || +                listStyle ==
> KoListStyle::HeavyCheckMarkItem    || listStyle ==
> KoListStyle::BallotXItem    || +                listStyle ==
> KoListStyle::RightArrowItem        || listStyle ==
> KoListStyle::RightArrowHeadItem) +            {
> +                QChar
> bulletChar(listFormat.intProperty(KoListStyle::BulletCharacter)); +       
>         result = bulletChar;
> +            }
> +
> +            QTextLayout layout(result , font, m_parent->paintDevice());
> +
>              QList<QTextLayout::FormatRange> layouts;
>              QTextLayout::FormatRange format;
>              format.start = 0;
>              format.length = data->counterText().length();
> -            format.format = cf;
> +            format.format = chFormatMaxFontSize;
> +
>              layouts.append(format);
>              layout.setAdditionalFormats(layouts);
> 
>              Qt::Alignment align =
> static_cast<Qt::Alignment>(listFormat.intProperty(KoListStyle::Alignment))
> ; -            if (align == 0)
> +
> +            if (align == 0) {
>                  align = Qt::AlignLeft;
> -            else if (align != Qt::AlignLeft)
> +            }
> +            else if (align != Qt::AlignLeft) {
>                  align |= Qt::AlignAbsolute;
> +            }
> +
>              QTextOption option(align);
>             
> option.setTextDirection(block.layout()->textOption().textDirection()); -  
>          if (option.textDirection() == Qt::RightToLeft ||
> data->counterText().isRightToLeft()) +
> +            if (option.textDirection() == Qt::RightToLeft ||
> data->counterText().isRightToLeft()) {
> option.setAlignment(Qt::AlignRight);
> +            }
> +
>              layout.setTextOption(option);
>              layout.beginLayout();
> +
>              QTextLine line = layout.createLine();
>              line.setLineWidth(data->counterWidth());
>              layout.endLayout();
> +
>              QPointF counterPosition = data->counterPosition();
>              if (block.layout()->lineCount() > 0) {
>                  // if there is text, then baseline align the counter.
>                  QTextLine firstParagLine = block.layout()->lineAt(0);
>                  counterPosition += QPointF(0, firstParagLine.ascent() -
> layout.lineAt(0).ascent()); }
> +
>              layout.draw(painter, counterPosition);
>          }
> 
> -        KoListStyle::Style listStyle =
> static_cast<KoListStyle::Style>(listFormat.style()); -        if
> (listStyle == KoListStyle::SquareItem || listStyle ==
> KoListStyle::DiscItem || -                listStyle ==
> KoListStyle::CircleItem || listStyle == KoListStyle::BoxItem || -         
>       listStyle == KoListStyle::RhombusItem || listStyle ==
> KoListStyle::CustomCharItem || -                listStyle ==
> KoListStyle::HeavyCheckMarkItem || listStyle == KoListStyle::BallotXItem
> || -                listStyle == KoListStyle::RightArrowItem || listStyle
> == KoListStyle::RightArrowHeadItem -           ) {
> -            QFontMetricsF fm(cf.font(), m_parent->paintDevice());
>  #if 0
> -// helper lines to show the anatomy of this font.
> +            QFontMetricsF fm(chFormatMaxFontSize.font(),
> m_parent->paintDevice()); +            // helper lines to show the anatomy
> of this font.
>              painter->setPen(Qt::green);
>              painter->drawLine(QLineF(-1, data->counterPosition().y(), 200,
> data->counterPosition().y())); painter->setPen(Qt::yellow);
> @@ -2027,84 +2071,10 @@ void Layout::drawListItem(QPainter *painter, const
> QTextBlock &block, KoImageCol painter->setPen(Qt::gray);
>              painter->drawLine(QLineF(-1, data->counterPosition().y() +
> fm.height(), 200, data->counterPosition().y() + fm.height())); #endif
> -            painter->save();
> -            QColor bulletColor =
> listFormat.colorProperty(KoListStyle::BulletColor); -            if
> (bulletColor.isValid()) {
> -                painter->setBrush(bulletColor);
> -                painter->setPen(QPen(bulletColor));
> -            }
> -            else {
> -                bulletColor = QColor(Qt::black);
> -            }
> 
> -            qreal width = fm.xHeight();
> -            qreal y = data->counterPosition().y() + fm.ascent() -
> fm.xHeight(); // at top of text. -            int percent =
> listFormat.intProperty(KoListStyle::BulletSize); -            if (percent
> > 0)
> -                width *= percent / 100.0;
> -            y -= width / 10.; // move it up just slightly
> -            qreal x = qMax(qreal(1), data->counterPosition().x() +
> fm.width(listFormat.stringProperty(KoListStyle::ListItemPrefix))); -      
>      switch (listStyle) {
> -            case KoListStyle::SquareItem: {
> -                painter->fillRect(QRectF(x, y, width, width),
> QBrush(bulletColor)); -            }
> -            break;
> -            case KoListStyle::DiscItem:
> -                painter->setBrush(bulletColor);
> -                // fall through!
> -            case KoListStyle::CircleItem: {
> -                painter->drawEllipse(QRectF(x, y, width, width));
> -            }
> -            break;
> -            case KoListStyle::BoxItem: {
> -                painter->drawRect(QRectF(x, y, width, width));
> -            }
> -            break;
> -            case KoListStyle::RhombusItem: {
> -                painter->translate(QPointF(x + (width / 2.0), y));
> -                painter->rotate(45.0);
> -                painter->fillRect(QRectF(0, 0, width, width),
> QBrush(bulletColor)); -            }
> -            break;
> -            case KoListStyle::RightArrowItem: {
> -                const qreal half = width / 2.0;
> -                painter->translate(QPointF(x, y));
> -                QPointF points[] = { QPointF(half, 0), QPointF(width,
> half), QPointF(half, width) }; -               
> painter->drawPolyline(points, 3);
> -                painter->drawLine(QLineF(0, half, width, half));
> -            }
> -            break;
> -            case KoListStyle::RightArrowHeadItem: {
> -                painter->translate(QPointF(x, y));
> -                QPointF points[] = { QPointF(0, 0), QPointF(width, width /
> 2.0), QPointF(0, width) }; -                painter->drawPolyline(points,
> 3);
> -            }
> -            break;
> -            case KoListStyle::HeavyCheckMarkItem: {
> -                const qreal half = width / 2.0;
> -                painter->translate(QPointF(x, y));
> -                QPointF points[] = { QPointF(half, half), QPointF(half,
> width), QPointF(width, 0) }; -               
> painter->drawPolyline(points, 3);
> -            }
> -            break;
> -            case KoListStyle::BallotXItem: {
> -                painter->translate(QPointF(x, y));
> -                painter->drawLine(QLineF(0.0, 0.0, width, width));
> -                painter->drawLine(QLineF(0.0, width, width, 0.0));
> -            }
> -            break;
> -            case KoListStyle::CustomCharItem:
> -                if
> (!QChar(listFormat.intProperty(KoListStyle::BulletCharacter)).isNull()){ -
>                    painter->drawText(0, 0,
> QChar(listFormat.intProperty(KoListStyle::BulletCharacter))); -           
>     }
> -                break;
> -            default:; // others we ignore.
> -            }
> -
> -            painter->restore();
> -
> -        } else if (listStyle == KoListStyle::ImageItem && imageCollection)
> { -            QFontMetricsF fm(cf.font(), m_parent->paintDevice()); +    
>    KoListStyle::Style listStyle =
> static_cast<KoListStyle::Style>(listFormat.style()); +        if
> (listStyle == KoListStyle::ImageItem && imageCollection) { +           
> QFontMetricsF fm(chFormatMaxFontSize.font(), m_parent->paintDevice());
> qreal x = qMax(qreal(1), data->counterPosition().x()); qreal width =
> qMax(listFormat.doubleProperty(KoListStyle::Width), (qreal)1.0); qreal
> height = qMax(listFormat.doubleProperty(KoListStyle::Height), (qreal)1.0);


-- 
Cyrille Berger Skott



More information about the calligra-devel mailing list