~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kspread/Style.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
class KSPREAD_EXPORT Style
58
58
{
59
59
public:
60
 
    enum HAlign
61
 
    {
 
60
    enum HAlign {
62
61
        Left = 1,
63
62
        Center = 2,
64
63
        Right = 3,
65
64
        HAlignUndefined = 0
66
65
    };
67
66
 
68
 
    enum VAlign
69
 
    {
 
67
    enum VAlign {
70
68
        Top = 1,
71
69
        Middle = 2,
72
70
        Bottom = 3,
 
71
        VDistributed = 4,
 
72
        VJustified = 5,
73
73
        VAlignUndefined = 0
74
74
    };
75
75
 
76
 
    enum FloatFormat
77
 
    {
 
76
    enum FloatFormat {
78
77
        DefaultFloatFormat = 0,
79
78
        AlwaysSigned = 1,
80
79
        AlwaysUnsigned = 2,
81
80
        OnlyNegSigned = DefaultFloatFormat
82
81
    };
83
82
 
84
 
    enum FloatColor
85
 
    {
 
83
    enum FloatColor {
86
84
        DefaultFloatColor = 0,
87
85
        NegRed = 1,
88
86
        AllBlack = DefaultFloatColor,
91
89
    };
92
90
 
93
91
    /// The style type
94
 
    enum StyleType
95
 
    {
 
92
    enum StyleType {
96
93
        BUILTIN,   ///< built-in style (the default style)
97
94
        CUSTOM,    ///< custom style (defined in the StyleManager dialog)
98
95
        AUTO,      ///< automatically generated on cell format changes
99
96
        TENTATIVE  ///< @internal temporary state
100
97
    };
101
98
 
102
 
    enum Key
103
 
    {
 
99
    enum Key {
104
100
        // special cases
105
101
        DefaultStyleKey,
106
102
        /**
156
152
    };
157
153
 
158
154
    Style();
159
 
    Style( const Style& style );
 
155
    Style(const Style& style);
160
156
    virtual ~Style();
161
157
 
162
158
    virtual StyleType type() const;
163
159
 
164
160
    QString parentName() const;
165
 
    void setParentName( const QString& name );
 
161
    void setParentName(const QString& name);
166
162
 
167
163
 
168
164
    bool loadXML(KoXmlElement& format, Paste::Mode pm = Paste::Normal);
169
165
    void saveXML(QDomDocument& doc, QDomElement& format, const StyleManager* styleManager) const;
170
 
    void loadOdfStyle( KoOdfStylesReader& stylesReader, const KoXmlElement& element,
171
 
                         Conditions& conditions, const StyleManager* styleManager );
 
166
    void loadOdfStyle(KoOdfStylesReader& stylesReader, const KoXmlElement& element,
 
167
                      Conditions& conditions, const StyleManager* styleManager);
172
168
    /**
173
169
     * Saves an OASIS automatic style.
174
170
     * Reimplemented by CustomStyle for OASIS user styles.
175
171
     * \return the OASIS style's name
176
172
     */
177
173
    virtual QString saveOdf(KoGenStyle& style, KoGenStyles& mainStyles,
178
 
                              const StyleManager* manager) const;
179
 
 
180
 
 
181
 
    void clearAttribute( Key key );
182
 
    bool hasAttribute( Key key ) const;
183
 
    void loadAttributes( const QList<SharedSubStyle>& subStyles );
 
174
                            const StyleManager* manager) const;
 
175
 
 
176
 
 
177
    void clearAttribute(Key key);
 
178
    bool hasAttribute(Key key) const;
 
179
    void loadAttributes(const QList<SharedSubStyle>& subStyles);
184
180
 
185
181
 
186
182
    uint bottomPenValue() const;
235
231
     * Does the real work by determining the used attributes.
236
232
     */
237
233
    void saveOdfStyle(const QSet<Key>& subStyles, KoGenStyle &style,
238
 
                        KoGenStyles &mainStyles, const StyleManager* manager) const;
 
234
                      KoGenStyles &mainStyles, const StyleManager* manager) const;
239
235
 
240
 
    void loadOdfDataStyle( KoOdfStylesReader& stylesReader, const KoXmlElement& element );
241
 
    void loadOdfParagraphProperties( KoOdfStylesReader& stylesReader, const KoStyleStack& element );
242
 
    void loadOdfTableCellProperties( KoOdfStylesReader& stylesReader, const KoStyleStack& element );
243
 
    void loadOdfTextProperties( KoOdfStylesReader& stylesReader, const KoStyleStack& element );
 
236
    void loadOdfDataStyle(KoOdfStylesReader& stylesReader, const KoXmlElement& element, Conditions& conditions, const StyleManager* styleManager);
 
237
    void loadOdfParagraphProperties(KoOdfStylesReader& stylesReader, const KoStyleStack& element);
 
238
    void loadOdfTableCellProperties(KoOdfStylesReader& stylesReader, const KoStyleStack& element);
 
239
    void loadOdfTextProperties(KoOdfStylesReader& stylesReader, const KoStyleStack& element);
244
240
 
245
241
public:
246
 
    void setHAlign( HAlign align );
247
 
    void setVAlign( VAlign align );
248
 
    void setFont( QFont const & font );
249
 
    void setFontFamily( QString const & fam );
250
 
    void setFontBold( bool enable );
251
 
    void setFontItalic( bool enable );
252
 
    void setFontUnderline( bool enable );
253
 
    void setFontStrikeOut( bool enable );
254
 
    void setFontSize( int size );
255
 
    void setFontColor( QColor const & color );
256
 
    void setRightBorderPen( QPen const & pen );
257
 
    void setBottomBorderPen( QPen const & pen );
258
 
    void setLeftBorderPen( QPen const & pen );
259
 
    void setTopBorderPen( QPen const & pen );
260
 
    void setFallDiagonalPen( QPen const & pen );
261
 
    void setGoUpDiagonalPen( QPen const & pen );
262
 
    void setAngle( int angle );
263
 
    void setIndentation( double indent );
264
 
    void setBackgroundBrush( QBrush const & brush );
265
 
    void setFloatFormat( FloatFormat format );
266
 
    void setFloatColor( FloatColor color );
267
 
    void setFormatType( Format::Type format );
268
 
    void setCustomFormat( QString const & strFormat );
269
 
    void setPrecision( int precision );
270
 
    void setPrefix( QString const & prefix );
271
 
    void setPostfix( QString const & postfix );
272
 
    void setCurrency( Currency const & currency );
273
 
    void setWrapText( bool enable );
274
 
    void setHideAll( bool enable );
275
 
    void setHideFormula( bool enable );
276
 
    void setNotProtected( bool enable );
277
 
    void setDontPrintText( bool enable );
278
 
    void setVerticalText( bool enable );
279
 
    void setBackgroundColor( QColor const & color );
 
242
    void setHAlign(HAlign align);
 
243
    void setVAlign(VAlign align);
 
244
    void setFont(QFont const & font);
 
245
    void setFontFamily(QString const & fam);
 
246
    void setFontBold(bool enable);
 
247
    void setFontItalic(bool enable);
 
248
    void setFontUnderline(bool enable);
 
249
    void setFontStrikeOut(bool enable);
 
250
    void setFontSize(int size);
 
251
    void setFontColor(QColor const & color);
 
252
    void setRightBorderPen(QPen const & pen);
 
253
    void setBottomBorderPen(QPen const & pen);
 
254
    void setLeftBorderPen(QPen const & pen);
 
255
    void setTopBorderPen(QPen const & pen);
 
256
    void setFallDiagonalPen(QPen const & pen);
 
257
    void setGoUpDiagonalPen(QPen const & pen);
 
258
    void setAngle(int angle);
 
259
    void setIndentation(double indent);
 
260
    void setBackgroundBrush(QBrush const & brush);
 
261
    void setFloatFormat(FloatFormat format);
 
262
    void setFloatColor(FloatColor color);
 
263
    void setFormatType(Format::Type format);
 
264
    void setCustomFormat(QString const & strFormat);
 
265
    void setPrecision(int precision);
 
266
    void setPrefix(QString const & prefix);
 
267
    void setPostfix(QString const & postfix);
 
268
    void setCurrency(Currency const & currency);
 
269
    void setWrapText(bool enable);
 
270
    void setHideAll(bool enable);
 
271
    void setHideFormula(bool enable);
 
272
    void setNotProtected(bool enable);
 
273
    void setDontPrintText(bool enable);
 
274
    void setVerticalText(bool enable);
 
275
    void setBackgroundColor(QColor const & color);
280
276
    void setDefault();
281
277
    void clear();
282
278
 
283
279
 
284
280
    // static functions
285
281
    //
286
 
    static Format::Type dateType( const QString& );
287
 
    static Format::Type timeType( const QString& );
288
 
    static Format::Type fractionType( const QString& );
 
282
    static Format::Type dateType(const QString&);
 
283
    static Format::Type timeType(const QString&);
 
284
    static Format::Type fractionType(const QString&);
 
285
    static Format::Type numberType(const QString&);
 
286
    static Currency numberCurrency(const QString&);
289
287
 
290
288
    /**
291
289
     * @return the name of the data style (number, currency, percentage, date,
292
290
     * boolean, text)
293
291
     */
294
 
    static QString saveOdfStyleNumeric( KoGenStyle &style, KoGenStyles &mainStyles, Format::Type _style,
295
 
                                          const QString &_prefix, const QString &_postfix, int _precision, const QString& symbol );
296
 
    static QString saveOdfStyleNumericDate( KoGenStyles &mainStyles, Format::Type _style,
297
 
                                              const QString &_prefix, const QString &_suffix );
298
 
    static QString saveOdfStyleNumericFraction( KoGenStyles &mainStyles, Format::Type _style,
299
 
                                                  const QString &_prefix, const QString &_suffix );
300
 
    static QString saveOdfStyleNumericTime( KoGenStyles& mainStyles, Format::Type _style,
301
 
                                              const QString &_prefix, const QString &_suffix );
302
 
    static QString saveOdfStyleNumericCustom( KoGenStyles&mainStyles, Format::Type _style,
303
 
                                                const QString &_prefix, const QString &_suffix );
304
 
    static QString saveOdfStyleNumericScientific( KoGenStyles&mainStyles, Format::Type _style,
305
 
                                                    const QString &_prefix, const QString &_suffix, int _precision );
306
 
    static QString saveOdfStyleNumericPercentage( KoGenStyles&mainStyles, Format::Type _style, int _precision,
307
 
                                                    const QString &_prefix, const QString &_suffix );
308
 
    static QString saveOdfStyleNumericMoney( KoGenStyles&mainStyles, Format::Type _style,
309
 
                                               const QString& symbol, int _precision,
310
 
                                               const QString &_prefix, const QString &_suffix );
311
 
    static QString saveOdfStyleNumericText( KoGenStyles&mainStyles, Format::Type _style, int _precision,
312
 
                                              const QString &_prefix, const QString &_suffix );
313
 
    static QString saveOdfStyleNumericNumber( KoGenStyles&mainStyles, Format::Type _style, int _precision,
314
 
                                                const QString &_prefix, const QString &_suffix );
315
 
    static QString saveOdfBackgroundStyle( KoGenStyles &mainStyles, const QBrush &brush );
 
292
    static QString saveOdfStyleNumeric(KoGenStyle &style, KoGenStyles &mainStyles, Format::Type _style,
 
293
                                       const QString &_prefix, const QString &_postfix, int _precision, const QString& symbol);
 
294
    static QString saveOdfStyleNumericDate(KoGenStyles &mainStyles, Format::Type _style,
 
295
                                           const QString &_prefix, const QString &_suffix);
 
296
    static QString saveOdfStyleNumericFraction(KoGenStyles &mainStyles, Format::Type _style,
 
297
            const QString &_prefix, const QString &_suffix);
 
298
    static QString saveOdfStyleNumericTime(KoGenStyles& mainStyles, Format::Type _style,
 
299
                                           const QString &_prefix, const QString &_suffix);
 
300
    static QString saveOdfStyleNumericCustom(KoGenStyles&mainStyles, Format::Type _style,
 
301
            const QString &_prefix, const QString &_suffix);
 
302
    static QString saveOdfStyleNumericScientific(KoGenStyles&mainStyles, Format::Type _style,
 
303
            const QString &_prefix, const QString &_suffix, int _precision);
 
304
    static QString saveOdfStyleNumericPercentage(KoGenStyles&mainStyles, Format::Type _style, int _precision,
 
305
            const QString &_prefix, const QString &_suffix);
 
306
    static QString saveOdfStyleNumericMoney(KoGenStyles&mainStyles, Format::Type _style,
 
307
                                            const QString& symbol, int _precision,
 
308
                                            const QString &_prefix, const QString &_suffix);
 
309
    static QString saveOdfStyleNumericText(KoGenStyles&mainStyles, Format::Type _style, int _precision,
 
310
                                           const QString &_prefix, const QString &_suffix);
 
311
    static QString saveOdfStyleNumericNumber(KoGenStyles&mainStyles, Format::Type _style, int _precision,
 
312
            const QString &_prefix, const QString &_suffix);
 
313
    static QString saveOdfBackgroundStyle(KoGenStyles &mainStyles, const QBrush &brush);
316
314
 
317
315
    /**
318
316
     * Returns the name of a color.  This is the same as returned by QColor::name, but an internal cache
319
317
     * is used to reduce the overhead when asking for the name of the same color.
320
318
     */
321
 
    static QString colorName( const QColor& color );
 
319
    static QString colorName(const QColor& color);
322
320
 
323
 
    static bool compare( const SubStyle* one, const SubStyle* two );
 
321
    static bool compare(const SubStyle* one, const SubStyle* two);
324
322
 
325
323
 
326
324
    /** Returns true if both styles have the same properties */
327
325
    bool operator== (const Style& style) const;
328
 
    inline bool operator!=( const Style& other ) const { return !operator==( other ); }
329
 
    void operator=( const Style& style );
 
326
    inline bool operator!=(const Style& other) const {
 
327
        return !operator==(other);
 
328
    }
 
329
    void operator=(const Style& style);
330
330
    Style operator-(const Style& style) const;
331
 
    void merge( const Style& style );
 
331
    void merge(const Style& style);
332
332
 
333
333
    /**
334
334
     * The keys, that are contained in this style, but not in \p other and
342
342
protected:
343
343
    QList<SharedSubStyle> subStyles() const;
344
344
 
345
 
    SharedSubStyle createSubStyle( Key key, const QVariant& value );
346
 
    virtual void insertSubStyle( Key key, const QVariant& value );
347
 
    void insertSubStyle( const SharedSubStyle& subStyle );
348
 
    bool releaseSubStyle( Key key );
 
345
    SharedSubStyle createSubStyle(Key key, const QVariant& value);
 
346
    virtual void insertSubStyle(Key key, const QVariant& value);
 
347
    void insertSubStyle(const SharedSubStyle& subStyle);
 
348
    bool releaseSubStyle(Key key);
349
349
 
350
350
private:
351
351
    friend class StyleStorage;
369
369
     * \param name The name of this style.
370
370
     * \param parent The style whose attributes are inherited - the parent style.
371
371
     */
372
 
    explicit CustomStyle( const QString& name, CustomStyle* parent = 0 );
 
372
    explicit CustomStyle(const QString& name, CustomStyle* parent = 0);
373
373
    virtual ~CustomStyle();
374
374
 
375
375
    virtual StyleType type() const;
376
 
    void setType( StyleType type );
 
376
    void setType(StyleType type);
377
377
 
378
 
    void setName( QString const & name );
 
378
    void setName(QString const & name);
379
379
    QString const & name() const;
380
380
 
381
 
    bool loadXML( KoXmlElement const & style, QString const & name );
 
381
    bool loadXML(KoXmlElement const & style, QString const & name);
382
382
    void save(QDomDocument & doc, QDomElement & styles, const StyleManager* styleManager);
383
383
 
384
384
    /**
388
388
     * @param style the DOM element defining the style
389
389
     * @param name the style's new name
390
390
     */
391
 
    void loadOdf( KoOdfStylesReader& stylesReader, const KoXmlElement& style,
392
 
                    const QString& name, Conditions& conditions,
393
 
                    const StyleManager* styleManager );
 
391
    void loadOdf(KoOdfStylesReader& stylesReader, const KoXmlElement& style,
 
392
                 const QString& name, Conditions& conditions,
 
393
                 const StyleManager* styleManager);
394
394
 
395
395
    /**
396
396
     * @reimp
398
398
     * @return the OASIS style's name
399
399
     */
400
400
    virtual QString saveOdf(KoGenStyle& style, KoGenStyles &mainStyles,
401
 
                              const StyleManager* manager) const;
402
 
 
403
 
 
404
 
    bool operator==( const CustomStyle& other ) const;
405
 
    inline bool operator!=( const CustomStyle& other ) const { return !operator==( other ); }
 
401
                            const StyleManager* manager) const;
 
402
 
 
403
 
 
404
    bool operator==(const CustomStyle& other) const;
 
405
    inline bool operator!=(const CustomStyle& other) const {
 
406
        return !operator==(other);
 
407
    }
406
408
 
407
409
    /**
408
410
     * @return the number of references to this style.
431
433
public:
432
434
    SubStyle() {}
433
435
    virtual ~SubStyle() {}
434
 
    virtual Style::Key type() const { return Style::DefaultStyleKey; }
435
 
    virtual void dump() const { kDebug() << debugData(); }
436
 
    virtual QString debugData( bool withName = true ) const { QString out; if (withName) out = name(Style::DefaultStyleKey); return out; }
437
 
    static QString name( Style::Key key );
 
436
    virtual Style::Key type() const {
 
437
        return Style::DefaultStyleKey;
 
438
    }
 
439
    virtual void dump() const {
 
440
        kDebug() << debugData();
 
441
    }
 
442
    virtual QString debugData(bool withName = true) const {
 
443
        QString out; if (withName) out = name(Style::DefaultStyleKey); return out;
 
444
    }
 
445
    static QString name(Style::Key key);
438
446
};
439
447
 
440
448
// Provides a default SubStyle for the tree.
447
455
public:
448
456
    inline SharedSubStyle() : d(new SubStyle()) {}
449
457
    inline SharedSubStyle(SubStyle* subStyle) : d(subStyle) {}
450
 
    inline const SubStyle *operator->() const { return d.data(); }
451
 
    inline const SubStyle *data() const { return d.data(); }
452
 
    inline bool operator<(const SharedSubStyle& o) const { return d.data() < o.d.data(); }
453
 
    inline bool operator==(const SharedSubStyle& o) const { return d.data() == o.d.data(); }
454
 
    inline bool operator!() const { return !d; }
 
458
    inline const SubStyle *operator->() const {
 
459
        return d.data();
 
460
    }
 
461
    inline const SubStyle *data() const {
 
462
        return d.data();
 
463
    }
 
464
    inline bool operator<(const SharedSubStyle& o) const {
 
465
        return d.data() < o.d.data();
 
466
    }
 
467
    inline bool operator==(const SharedSubStyle& o) const {
 
468
        return d.data() == o.d.data();
 
469
    }
 
470
    inline bool operator!() const {
 
471
        return !d;
 
472
    }
455
473
 
456
474
private:
457
475
    QSharedDataPointer<SubStyle> d;
460
478
class NamedStyle : public SubStyle
461
479
{
462
480
public:
463
 
    NamedStyle( const QString& n ) : SubStyle(), name( n ) {}
464
 
    virtual Style::Key type() const { return Style::NamedStyleKey; }
465
 
    virtual void dump() const { kDebug() << debugData(); }
466
 
    virtual QString debugData( bool withName = true ) const { QString out; if (withName) out = SubStyle::name(Style::NamedStyleKey) + ' '; out += name; return out; }
 
481
    NamedStyle(const QString& n) : SubStyle(), name(n) {}
 
482
    virtual Style::Key type() const {
 
483
        return Style::NamedStyleKey;
 
484
    }
 
485
    virtual void dump() const {
 
486
        kDebug() << debugData();
 
487
    }
 
488
    virtual QString debugData(bool withName = true) const {
 
489
        QString out; if (withName) out = SubStyle::name(Style::NamedStyleKey) + ' '; out += name; return out;
 
490
    }
467
491
    QString name;
468
492
};
469
493
 
471
495
class SubStyleOne : public SubStyle
472
496
{
473
497
public:
474
 
    SubStyleOne( const Value1& v = Value1() ) : SubStyle(), value1( v ) {}
475
 
    virtual Style::Key type() const { return key; }
476
 
    virtual void dump() const { kDebug(36006) << debugData(); }
477
 
    virtual QString debugData( bool withName = true ) const
478
 
    { QString out; if (withName) out = name(key) + ' '; QDebug qdbg(&out); qdbg << value1; return out; }
 
498
    SubStyleOne(const Value1& v = Value1()) : SubStyle(), value1(v) {}
 
499
    virtual Style::Key type() const {
 
500
        return key;
 
501
    }
 
502
    virtual void dump() const {
 
503
        kDebug(36006) << debugData();
 
504
    }
 
505
    virtual QString debugData(bool withName = true) const {
 
506
        QString out; if (withName) out = name(key) + ' '; QDebug qdbg(&out); qdbg << value1; return out;
 
507
    }
479
508
    Value1 value1;
480
509
};
481
510
 
482
511
} // namespace KSpread
483
512
 
484
 
Q_DECLARE_TYPEINFO( KSpread::Style, Q_MOVABLE_TYPE );
485
 
Q_DECLARE_TYPEINFO( KSpread::CustomStyle, Q_MOVABLE_TYPE );
486
 
Q_DECLARE_TYPEINFO( KSpread::SharedSubStyle, Q_MOVABLE_TYPE );
 
513
Q_DECLARE_TYPEINFO(KSpread::Style, Q_MOVABLE_TYPE);
 
514
Q_DECLARE_TYPEINFO(KSpread::CustomStyle, Q_MOVABLE_TYPE);
 
515
Q_DECLARE_TYPEINFO(KSpread::SharedSubStyle, Q_MOVABLE_TYPE);
487
516
 
488
517
#endif // KSPREAD_STYLE