File indexing completed on 2024-05-19 04:44:32

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 
0018 #include "KReportScriptField.h"
0019 
0020 #include <QSizeF>
0021 #include <QPointF>
0022 
0023 
0024 namespace Scripting
0025 {
0026 Field::Field(KReportItemField *f)
0027 {
0028     m_field = f;
0029 }
0030 
0031 
0032 Field::~Field()
0033 {
0034 }
0035 
0036 QString Field::source() const
0037 {
0038     return m_field->itemDataSource();
0039 }
0040 
0041 void Field::setSource(const QString& s)
0042 {
0043     m_field->setItemDataSource(s);
0044 }
0045 
0046 int Field::horizontalAlignment() const
0047 {
0048     const QString a = m_field->m_horizontalAlignment->value().toString().toLower();
0049 
0050     if (a == QLatin1String("left")) {
0051         return -1;
0052     }
0053     if (a == QLatin1String("center")) {
0054         return 0;
0055     }
0056     if (a == QLatin1String("right")) {
0057         return 1;
0058     }
0059     return -1;
0060 }
0061 void Field::setHorizonalAlignment(int a)
0062 {
0063     switch (a) {
0064     case -1:
0065         m_field->m_horizontalAlignment->setValue(QLatin1String("left"));
0066         break;
0067     case 0:
0068         m_field->m_horizontalAlignment->setValue(QLatin1String("center"));
0069         break;
0070     case 1:
0071         m_field->m_horizontalAlignment->setValue(QLatin1String("right"));
0072         break;
0073     default:
0074         m_field->m_horizontalAlignment->setValue(QLatin1String("left"));
0075         break;
0076     }
0077 }
0078 
0079 int Field::verticalAlignment() const
0080 {
0081     const QString a = m_field->m_horizontalAlignment->value().toString().toLower();
0082 
0083     if (a == QLatin1String("top")) {
0084         return -1;
0085     }
0086     if (a == QLatin1String("middle")) {
0087         return 0;
0088     }
0089     if (a == QLatin1String("bottom")) {
0090         return 1;
0091     }
0092     return -1;
0093 }
0094 void Field::setVerticalAlignment(int a)
0095 {
0096     switch (a) {
0097     case -1:
0098         m_field->m_verticalAlignment->setValue(QLatin1String("top"));
0099         break;
0100     case 0:
0101         m_field->m_verticalAlignment->setValue(QLatin1String("middle"));
0102         break;
0103     case 1:
0104         m_field->m_verticalAlignment->setValue(QLatin1String("bottom"));
0105         break;
0106     default:
0107         m_field->m_verticalAlignment->setValue(QLatin1String("middle"));
0108         break;
0109     }
0110 }
0111 
0112 QColor Field::backgroundColor() const
0113 {
0114     return m_field->m_backgroundColor->value().value<QColor>();
0115 }
0116 void Field::setBackgroundColor(const QColor& c)
0117 {
0118     m_field->m_backgroundColor->setValue(c);
0119 }
0120 
0121 QColor Field::foregroundColor() const
0122 {
0123     return m_field->m_foregroundColor->value().value<QColor>();
0124 }
0125 void Field::setForegroundColor(const QColor& c)
0126 {
0127     m_field->m_foregroundColor->setValue(c);
0128 }
0129 
0130 int Field::backgroundOpacity() const
0131 {
0132     return m_field->m_backgroundOpacity->value().toInt();
0133 }
0134 void Field::setBackgroundOpacity(int o)
0135 {
0136     m_field->m_backgroundOpacity->setValue(o);
0137 }
0138 
0139 QColor Field::lineColor() const
0140 {
0141     return m_field->m_lineColor->value().value<QColor>();
0142 }
0143 void Field::setLineColor(const QColor& c)
0144 {
0145     m_field->m_lineColor->setValue(c);
0146 }
0147 
0148 int Field::lineWeight() const
0149 {
0150     return m_field->m_lineWeight->value().toInt();
0151 }
0152 void Field::setLineWeight(int w)
0153 {
0154     m_field->m_lineWeight->setValue(w);
0155 }
0156 
0157 int Field::lineStyle() const
0158 {
0159     return m_field->m_lineStyle->value().toInt();
0160 }
0161 void Field::setLineStyle(int s)
0162 {
0163     if (s < 0 || s > 5) {
0164         s = 1;
0165     }
0166     m_field->m_lineStyle->setValue(s);
0167 }
0168 
0169 QPointF Field::position() const
0170 {
0171     return m_field->position();
0172 }
0173 void Field::setPosition(const QPointF &p)
0174 {
0175     m_field->setPosition(p);
0176 }
0177 
0178 QSizeF Field::size() const
0179 {
0180     return m_field->size();
0181 }
0182 void Field::setSize(const QSizeF &s)
0183 {
0184     m_field->setSize(s);
0185 }
0186 
0187 }