Warning, file /office/calligra/libs/textlayout/KoStyleThumbnailer.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2006 Thomas Zander <zander@kde.org>
0003  * Copyright (C) 2007 Sebastian Sauer <mail@dipe.org>
0004  * Copyright (C) 2008 Thorsten Zachmann <zachmann@kde.org>
0005  * Copyright (C) 2008 Girish Ramakrishnan <girish@forwardbias.in>
0006  * Copyright (C) 2009-2011 KO GmbH <cbo@kogmbh.com>
0007  * Copyright (C) 2011-2012 Pierre Stirnweiss <pstirnweiss@googlemail.com>
0008  * Copyright (C) 2012 Gopalakrishna Bhat A <gopalakbhat@gmail.com>
0009  *
0010  * This library is free software; you can redistribute it and/or
0011  * modify it under the terms of the GNU Library General Public
0012  * License as published by the Free Software Foundation; either
0013  * version 2 of the License, or (at your option) any later version.
0014  *
0015  * This library is distributed in the hope that it will be useful,
0016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0018  * Library General Public License for more details.
0019  *
0020  * You should have received a copy of the GNU Library General Public License
0021  * along with this library; see the file COPYING.LIB.  If not, write to
0022  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0023  * Boston, MA 02110-1301, USA.
0024  */
0025 
0026 #ifndef KOSTYLETHUMBNAILER_H
0027 #define KOSTYLETHUMBNAILER_H
0028 
0029 #include "kotextlayout_export.h"
0030 
0031 #include <QSize>
0032 
0033 class KoCharacterStyle;
0034 class KoParagraphStyle;
0035 
0036 class QImage;
0037 
0038 /**
0039  * Helper class to create (and cache) thumbnails of styles
0040  */
0041 class KOTEXTLAYOUT_EXPORT KoStyleThumbnailer
0042 {
0043 public:
0044     enum KoStyleThumbnailerFlag {
0045         NoFlags = 0,
0046         CenterAlignThumbnail = 1, ///< Vertically Center Align the layout of the thumbnail
0047                                   ///     i.e the layout is done at the center of the area
0048         UseStyleNameText = 2, ///< Use the style name as the text that is layouted inside the thumbnail
0049         ScaleThumbnailFont = 4 ///< If set, then when the layout size is more than the size available
0050                                ///  the font size is scaled down to fit the space available
0051     };
0052     Q_DECLARE_FLAGS(KoStyleThumbnailerFlags, KoStyleThumbnailerFlag)
0053 
0054     /**
0055      * Create a new style thumbnailer.
0056      */
0057     explicit KoStyleThumbnailer();
0058 
0059     /**
0060      * Destructor.
0061      */
0062     virtual ~KoStyleThumbnailer();
0063 
0064     /**
0065      * @returns a thumbnail representing the @param style, constrained into the @param size.
0066      * If there is no specified @param size, the thumbnail is the size specified with @fn setThumbnailSize or 250*48 pt if no size was provided.
0067      * If the given @param size is too small, the font size will be decreased, so the thumbnail fits.
0068      * The real font size is indicated in this case.
0069      * If @param recreateThumbnail is true, do not return the cached thumbnail if it exist, but recreate a new one.
0070      * The created thumbnail is cached.
0071      */
0072     QImage thumbnail(KoParagraphStyle *style,
0073                      const QSize &size = QSize(), bool recreateThumbnail = false,
0074                      KoStyleThumbnailerFlags flags =
0075                           KoStyleThumbnailerFlags(CenterAlignThumbnail | UseStyleNameText | ScaleThumbnailFont));
0076 
0077     /**
0078      * @returns a thumbnail representing the @param characterStyle applied on the given @param paragraphStyle, constrained into the @param size.
0079      * If there is no specified @param size, the thumbnail is the size specified with @fn setThumbnailSize or 250*48 pt if no size was provided.
0080      * If the given @param size is too small, the font size will be decreased, so the thumbnail fits.
0081      * The real font size is indicated in this case.
0082      * If @param recreateThumbnail is true, do not return the cached thumbnail if it exist, but recreate a new one.
0083      * The created thumbnail is cached.
0084      */
0085     QImage thumbnail(KoCharacterStyle *characterStyle, KoParagraphStyle *paragraphStyle = 0,
0086                      const QSize &size = QSize(), bool recreateThumbnail = false,
0087                      KoStyleThumbnailerFlags flags =
0088                           KoStyleThumbnailerFlags(CenterAlignThumbnail | UseStyleNameText | ScaleThumbnailFont));
0089 
0090     /**
0091      * Sets the size of the thumbnails returned by the @fn thumbnail with no size arguments.
0092      */
0093     void setThumbnailSize(const QSize &size);
0094 
0095     /**
0096      * Sets the text that will be layouted.
0097      * @param text The text that will be layouted inside the thumbnail
0098      *If the UseStyleNameText flag is set then this text will not be used
0099      */
0100     void setText(const QString &text);
0101 
0102     /**
0103      * remove all occurrences of the style from the cache
0104      */
0105     void removeFromCache(KoParagraphStyle *style);
0106 
0107     /**
0108      * remove all occurrences of the style from the cache
0109      */
0110     void removeFromCache(KoCharacterStyle *style);
0111 
0112 private:
0113     void layoutThumbnail(const QSize &size, QImage *im, KoStyleThumbnailerFlags flags);
0114     void removeFromCache(const QString &expr);
0115 
0116     class Private;
0117     Private* const d;
0118 };
0119 
0120 #endif