F:/KPlato/koffice/libs/koproperty/customproperty.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "customproperty.h"
00021 #include "property.h"
00022 
00023 #include <QSize>
00024 #include <QRect>
00025 #include <QSizePolicy>
00026 #include <QPoint>
00027 
00028 #include <klocale.h>
00029 #include <kdebug.h>
00030 
00031 using namespace KoProperty;
00032 
00033 CustomProperty::CustomProperty(Property *parent)
00034  : m_property(parent)
00035 {
00036 }
00037 
00038 CustomProperty::~CustomProperty()
00039 {
00040 }
00041 
00042 void
00043 CustomProperty::emitPropertyChanged()
00044 {
00045         m_property->emitPropertyChanged();
00046 }
00047 
00049 
00050 SizeCustomProperty::SizeCustomProperty(Property *property)
00051 : CustomProperty(property)
00052 {
00053         if(property && (property->type() == Size) ) {
00054                 QSize s = property->value().toSize();
00055                 new Property("width", s.width(), i18n("Width"), i18n("Width"), Size_Width, property);
00056                 new Property("height", s.height(), i18n("Height"), i18n("Height"), Size_Height, property);
00057         }
00058 }
00059 
00060 SizeCustomProperty::~SizeCustomProperty()
00061 {}
00062 
00063 bool
00064 SizeCustomProperty::handleValue() const
00065 {
00066         if(!m_property)
00067                 return false;
00068 
00069         switch(m_property->type()) {
00070                 case Size_Width: case Size_Height:
00071                         return true;
00072                 default:
00073                         return false;
00074         }
00075 }
00076 
00077 void
00078 SizeCustomProperty::setValue(const QVariant &value, bool rememberOldValue)
00079 {
00080         if(!m_property)
00081                 return;
00082 
00083         if(m_property->parent()) {
00084                 QSize s = m_property->parent()->value().toSize();
00085 
00086                 if(m_property->type() == Size_Height)
00087                         s.setHeight(value.toInt());
00088                 else if(m_property->type() == Size_Width)
00089                         s.setWidth(value.toInt());
00090 
00091                 m_property->parent()->setValue(s, true, false);
00092         }
00093         else{
00094                 QSize s = value.toSize();
00095                 m_property->child("width")->setValue(s.width(), rememberOldValue, false);
00096                 m_property->child("height")->setValue(s.height(), rememberOldValue, false);
00097         }
00098 }
00099 
00100 QVariant
00101 SizeCustomProperty::value() const
00102 {
00103         if(!m_property || !m_property->parent())
00104                 return QVariant();
00105 
00106         if(m_property->type() == Size_Height)
00107                 return m_property->parent()->value().toSize().height();
00108         else if(m_property->type() == Size_Width)
00109                 return m_property->parent()->value().toSize().width();
00110 
00111         return QVariant();
00112 }
00113 
00115 
00116 PointCustomProperty::PointCustomProperty(Property *property)
00117 : CustomProperty(property)
00118 {
00119         if(property && (property->type() == Point) ) {
00120                 QPoint p = property->value().toPoint();
00121                 new Property("x", p.x(), i18n("X"), i18n("X"), Point_X, property);
00122                 new Property("y", p.y(), i18n("Y"), i18n("Y"), Point_Y, property);
00123         }
00124 }
00125 
00126 PointCustomProperty::~PointCustomProperty()
00127 {}
00128 
00129 bool
00130 PointCustomProperty::handleValue() const
00131 {
00132         if(!m_property)
00133                 return false;
00134 
00135         switch(m_property->type()) {
00136                 case Point_X: case Point_Y:
00137                         return true;
00138                 default:
00139                         return false;
00140         }
00141 }
00142 
00143 void
00144 PointCustomProperty::setValue(const QVariant &value, bool rememberOldValue)
00145 {
00146         if(!m_property)
00147                 return;
00148 
00149         if(m_property->parent()) {
00150                 QPoint p = m_property->parent()->value().toPoint();
00151 
00152                 if(m_property->type() == Point_X)
00153                         p.setX(value.toInt());
00154                 else if(m_property->type() == Point_Y)
00155                         p.setY(value.toInt());
00156 
00157                 m_property->parent()->setValue(p, true, false);
00158         }
00159         else {
00160                 QPoint p = value.toPoint();
00161                 m_property->child("x")->setValue(p.x(), rememberOldValue, false);
00162                 m_property->child("y")->setValue(p.y(), rememberOldValue, false);
00163         }
00164 }
00165 
00166 QVariant
00167 PointCustomProperty::value() const
00168 {
00169         if(!m_property || !m_property->parent())
00170                 return QVariant();
00171 
00172         if(m_property->type() == Point_X)
00173                 return m_property->parent()->value().toPoint().x();
00174         else if(m_property->type() == Point_Y)
00175                 return m_property->parent()->value().toPoint().y();
00176 
00177         return QVariant();
00178 }
00179 
00181 
00182 RectCustomProperty::RectCustomProperty(Property *property)
00183 : CustomProperty(property)
00184 {
00185         if(property && (property->type() == Rect) ) {
00186                 QRect r = property->value().toRect();
00187                 new Property("x", r.x(), i18n("X"), i18n("X"), Rect_X, property);
00188                 new Property("y", r.y(), i18n("Y"), i18n("Y"), Rect_Y, property);
00189                 new Property("width", r.width(), i18n("Width"), i18n("Width"), Rect_Width, property);
00190                 new Property("height", r.height(), i18n("Height"), i18n("Height"), Rect_Height, property);
00191         }
00192 }
00193 
00194 RectCustomProperty::~RectCustomProperty()
00195 {}
00196 
00197 bool
00198 RectCustomProperty::handleValue() const
00199 {
00200         if(!m_property)
00201                 return false;
00202 
00203         switch(m_property->type()) {
00204                 case Rect_X: case Rect_Y: case Rect_Width: case Rect_Height:
00205                         return true;
00206                 default:
00207                         return false;
00208         }
00209 }
00210 
00211 void
00212 RectCustomProperty::setValue(const QVariant &value, bool rememberOldValue)
00213 {
00214         if(!m_property)
00215                 return;
00216 
00217         if(m_property->parent()) {
00218                 QRect r = m_property->parent()->value().toRect();
00219 
00220                 if(m_property->type() == Rect_X) {
00221                         //changing x component of Rect shouldn't change width
00222                         const int delta = value.toInt() - r.x();
00223                         r.setX(value.toInt());
00224                         r.setWidth(r.width()+delta);
00225                 }
00226                 else if(m_property->type() == Rect_Y) {
00227                         //changing y component of Rect shouldn't change height
00228                         const int delta = value.toInt() - r.y();
00229                         r.setY(value.toInt());
00230                         r.setHeight(r.height()+delta);
00231                 }
00232                 else if(m_property->type() == Rect_Width)
00233                         r.setWidth(value.toInt());
00234                 else if(m_property->type() == Rect_Height)
00235                         r.setHeight(value.toInt());
00236 
00237                 m_property->parent()->setValue(r, true, false);
00238         }
00239         else {
00240                 QRect r = value.toRect();
00241                 m_property->child("x")->setValue(r.x(), rememberOldValue, false);
00242                 m_property->child("y")->setValue(r.y(), rememberOldValue, false);
00243                 m_property->child("width")->setValue(r.width(), rememberOldValue, false);
00244                 m_property->child("height")->setValue(r.height(), rememberOldValue, false);
00245         }
00246 }
00247 
00248 QVariant
00249 RectCustomProperty::value() const
00250 {
00251         if(!m_property || !m_property->parent())
00252                 return QVariant();
00253 
00254         if(m_property->type() == Rect_X)
00255                 return m_property->parent()->value().toRect().x();
00256         else if(m_property->type() == Rect_Y)
00257                 return m_property->parent()->value().toRect().y();
00258         else if(m_property->type() == Rect_Width)
00259                 return m_property->parent()->value().toRect().width();
00260         else if(m_property->type() == Rect_Height)
00261                 return m_property->parent()->value().toRect().height();
00262 
00263         return QVariant();
00264 }
00265 
00266 
00268 
00269 SizePolicyCustomProperty::SizePolicyCustomProperty(Property *property)
00270 : CustomProperty(property)
00271 {
00272 #warning "kde4: port QVariant::SizePolicy"
00273 #if 0
00274         if(property && (property->type() == SizePolicy) ) {
00275 //              QMap<QString, QVariant> spValues;
00276                 Q3ValueList<QVariant> keys;
00277                 keys << QSizePolicy::Fixed
00278                         << QSizePolicy::Minimum
00279                         << QSizePolicy::Maximum
00280                         << QSizePolicy::Preferred
00281                         << QSizePolicy::Expanding
00282                         << QSizePolicy::MinimumExpanding
00283                         << QSizePolicy::Ignored;
00284                 QStringList strings;
00285                 strings << i18n("Size Policy", "Fixed")
00286                         << i18n("Size Policy", "Minimum")
00287                         << i18n("Size Policy", "Maximum")
00288                         << i18n("Size Policy", "Preferred")
00289                         << i18n("Size Policy", "Expanding")
00290                         << i18n("Size Policy", "Minimum Expanding")
00291                         << i18n("Size Policy", "Ignored");
00292 
00293                 new Property("hSizeType", new Property::ListData(keys, strings),
00294                         (int)property->value().toSizePolicy().horData(), 
00295                         i18n("Horz. Size Type"),i18n("Horizontal Size Type"),
00296                         SizePolicy_HorData, property);
00297                 new Property("vSizeType", new Property::ListData(keys, strings),
00298                         (int)property->value().toSizePolicy().verData(), 
00299                         i18n("Vert. Size Type"), i18n("Vertical Size Type"),
00300                         SizePolicy_VerData, property);
00301                 new Property("hStretch", 
00302                         property->value().toSizePolicy().horStretch(), 
00303                         i18n("Horz. Stretch"), i18n("Horizontal Stretch"),
00304                         SizePolicy_HorStretch, property);
00305                 new Property("vStretch", 
00306                         property->value().toSizePolicy().verStretch(), 
00307                         i18n("Vert. Stretch"), i18n("Vertical Stretch"),
00308                         SizePolicy_VerStretch, property);
00309         }
00310 #endif  
00311 }
00312 
00313 SizePolicyCustomProperty::~SizePolicyCustomProperty()
00314 {
00315 }
00316 
00317 bool
00318 SizePolicyCustomProperty::handleValue() const
00319 {
00320         if(!m_property)
00321                 return false;
00322 
00323         switch(m_property->type()) {
00324                 case SizePolicy_HorData:
00325                 case SizePolicy_VerData:
00326                 case SizePolicy_HorStretch:
00327                 case SizePolicy_VerStretch:
00328                         return true;
00329                 default:
00330                         return false;
00331         }
00332 }
00333 
00334 void
00335 SizePolicyCustomProperty::setValue(const QVariant &value, bool rememberOldValue)
00336 {
00337         if(!m_property)
00338                 return;
00339 
00340         if(m_property->parent()) {
00341 #warning "kde4: port it"                        
00342 #if 0                   
00343                 QSizePolicy v = m_property->parent()->value().toSizePolicy();
00344 
00345                 if(m_property->type() == SizePolicy_HorData)
00346                         v.setHorData(QSizePolicy::SizeType(value.toInt()));
00347                 else if(m_property->type() == SizePolicy_VerData)
00348                         v.setVerData(QSizePolicy::SizeType(value.toInt()));
00349                 else if(m_property->type() == SizePolicy_HorStretch)
00350                         v.setHorStretch(value.toInt());
00351                 else if(m_property->type() == SizePolicy_VerStretch)
00352                         v.setVerStretch(value.toInt());
00353 
00354                 m_property->parent()->setValue(v, true, false);
00355 #endif          
00356         }
00357         else {
00358 #warning "kde4: port QVariant::QSizePolicy"                     
00359 #if 0
00360                         QSizePolicy v = value.toSizePolicy();
00361                 m_property->child("hSizeType")->setValue(v.horData(), rememberOldValue, false);
00362                 m_property->child("vSizeType")->setValue(v.verData(), rememberOldValue, false);
00363                 m_property->child("hStretch")->setValue(v.horStretch(), rememberOldValue, false);
00364                 m_property->child("vStretch")->setValue(v.verStretch(), rememberOldValue, false);
00365 #endif          
00366         }
00367 }
00368 
00369 QVariant
00370 SizePolicyCustomProperty::value() const
00371 {
00372         if(!m_property || !m_property->parent())
00373                 return QVariant();
00374 #warning "kde4: port it"
00375 #if 0
00376         if(m_property->type() == SizePolicy_HorData)
00377                 return m_property->parent()->value().toSizePolicy().horData();
00378         else if(m_property->type() == SizePolicy_VerData)
00379                 return m_property->parent()->value().toSizePolicy().verData();
00380         else if(m_property->type() == SizePolicy_HorStretch)
00381                 return m_property->parent()->value().toSizePolicy().horStretch();
00382         else if(m_property->type() == SizePolicy_VerStretch)
00383                 return m_property->parent()->value().toSizePolicy().verStretch();
00384 #endif
00385         return QVariant();
00386 }

Généré le Wed Nov 22 23:41:06 2006 pour KPlato par  doxygen 1.5.1-p1