File indexing completed on 2024-05-12 04:43:22

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Lesser General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2.1 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0012  * Lesser General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Lesser General Public
0015  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0016  */
0017 #ifndef KRSCRIPTSECTION_H
0018 #define KRSCRIPTSECTION_H
0019 
0020 #include <QObject>
0021 #include <QtQml/QJSValue>
0022 
0023 class KReportSectionData;
0024 
0025 /**
0026  @brief Report section object user scripting API.
0027 
0028  Contains methods for a report section object which can be called by user scripts. \n
0029 
0030  Example: \n
0031  \code
0032  function detail()
0033  {
0034   this.OnRender = function()
0035   {
0036    debug.print("Rendering detail section!");
0037   }
0038  }
0039  reportname.section_detail.initialize(new detail())
0040  \endcode
0041 */
0042 namespace Scripting
0043 {
0044 class Section : public QObject
0045 {
0046     Q_OBJECT
0047 public:
0048     explicit Section(KReportSectionData*);
0049 
0050     ~Section() override;
0051 
0052 public Q_SLOTS:
0053     //! @return the background color of the section
0054     QColor backgroundColor() const;
0055 
0056     //! Sets the background color of the section to the given color
0057     void setBackgroundColor(const QColor&);
0058 
0059     //! @return the section height as a real number, in points
0060     qreal height() const;
0061 
0062     //! Sets the section height to the given value in points
0063     void setHeight(qreal);
0064 
0065     //! @return the name of the section
0066     QString name() const;
0067 
0068     //! @return an object in the section, by number
0069     QObject* objectByNumber(int);
0070 
0071     //! @return an object in the section, by name
0072     QObject* objectByName(const QString&);
0073 
0074     //! Assigns a user object to this section
0075     void initialize(const QJSValue &s);
0076 
0077     //! Executed when the report is opened.  If a handler exists for this in the user object it is called.
0078     void eventOnRender();
0079 
0080 private:
0081     KReportSectionData *m_section;
0082     QJSValue m_scriptObject;
0083 };
0084 }
0085 #endif