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

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