Warning, file /office/calligra/libs/text/KoVariable.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-2009 Thomas Zander <zander@kde.org>
0003  * Copyright (C) 2008 Thorsten Zachmann <zachmann@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Library General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, write to
0017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019  */
0020 #ifndef __KOVARIABLE_H__
0021 #define __KOVARIABLE_H__
0022 
0023 // Calligra libs
0024 #include "KoInlineObject.h"
0025 #include "kotext_export.h"
0026 
0027 class KoProperties;
0028 class QWidget;
0029 class KoVariableManager;
0030 class KoVariablePrivate;
0031 
0032 /**
0033  * Base class for in-text variables.
0034  *
0035  * A variable is a field inserted into the text and the content is set to a specific value that
0036  * is used as text.  This class is pretty boring in that it has just a setValue() to alter the
0037  * text shown; we depend on plugin writers to create more exciting ways to update variables.
0038  */
0039 class KOTEXT_EXPORT KoVariable : public KoInlineObject
0040 {
0041     Q_OBJECT
0042 public:
0043     /**
0044      * Constructor.
0045      */
0046     explicit KoVariable(bool propertyChangeListener = false);
0047     ~KoVariable() override;
0048 
0049     /**
0050      * The new value this variable will show.
0051      * Will be used at the next repaint.
0052      * @param value the new value this variable shows.
0053      */
0054     void setValue(const QString &value);
0055 
0056     /// @return the current value of this variable.
0057     QString value() const;
0058 
0059     /**
0060      * Shortly after instantiating this variable the factory should set the
0061      * properties using this method.
0062      * Note that the loading mechanism will fill this properties object with the
0063      * attributes from the ODF file (if applicable), so it would be useful to synchronize
0064      * the property names based on that.
0065      */
0066     virtual void setProperties(const KoProperties *props) {
0067         Q_UNUSED(props);
0068     }
0069 
0070     /**
0071      * If this variable has user-editable options it should provide a widget that is capable
0072      * of manipulating these options so the text-tool can use it to show that to the user.
0073      * Note that all manipulations should have a direct effect on the variable itself.
0074      */
0075     virtual QWidget *createOptionsWidget() {
0076         return 0;
0077     }
0078 
0079 protected:
0080     /**
0081      * This hook is called whenever the variable gets a new position.
0082      * If this is a type of variable that needs to change its value based on that
0083      * you should implement this method and act on it.
0084      */
0085     virtual void variableMoved(const QTextDocument *document, int posInDocument);
0086 
0087     friend class KoVariableManager;
0088     /**
0089      * return the last known position in the document. Note that if the variable has not yet been layouted,
0090      * it does not know the position.
0091      */
0092     int positionInDocument() const;
0093 
0094     /// reimplemented
0095     void resize(const QTextDocument *document, QTextInlineObject &object,
0096                 int posInDocument, const QTextCharFormat &format, QPaintDevice *pd) override;
0097 private:
0098     void updatePosition(const QTextDocument *document,
0099                         int posInDocument, const QTextCharFormat &format) override;
0100     void paint(QPainter &painter, QPaintDevice *pd, const QTextDocument *document,
0101                const QRectF &rect, const QTextInlineObject &object, int posInDocument, const QTextCharFormat &format) override;
0102 
0103 private Q_SLOTS:
0104     void documentDestroyed();
0105 
0106 private:
0107     Q_DECLARE_PRIVATE(KoVariable)
0108 };
0109 
0110 #endif