File indexing completed on 2024-06-16 04:17:36

0001 /*
0002  *  SPDX-FileCopyrightText: 2022 Agata Cacko <cacko.azh@gmail.com>
0003  *  SPDX-FileCopyrightText: 2008, 2009, 2010 Lukáš Tvrdý <lukast.dev@gmail.com>
0004  *
0005  *  SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 #include "KisSprayShapeOptionData.h"
0008 
0009 #include "kis_properties_configuration.h"
0010 
0011 
0012 const QString SPRAYSHAPE_ENABLED = "SprayShape/enabled";
0013 const QString SPRAYSHAPE_SHAPE = "SprayShape/shape";
0014 const QString SPRAYSHAPE_PROPORTIONAL = "SprayShape/proportional";
0015 const QString SPRAYSHAPE_WIDTH = "SprayShape/width";
0016 const QString SPRAYSHAPE_HEIGHT = "SprayShape/height";
0017 const QString SPRAYSHAPE_IMAGE_URL = "SprayShape/imageUrl";
0018 const QString SPRAYSHAPE_USE_ASPECT = "SprayShape/useAspect";
0019 
0020 
0021 bool KisSprayShapeOptionData::read(const KisPropertiesConfiguration *settings)
0022 {
0023     enabled = settings->getBool(SPRAYSHAPE_ENABLED, true);
0024     
0025     
0026     size.setWidth(settings->getInt(SPRAYSHAPE_WIDTH));
0027     size.setHeight(settings->getInt(SPRAYSHAPE_HEIGHT));
0028 
0029     proportional = settings->getBool(SPRAYSHAPE_PROPORTIONAL);
0030 
0031     // particle type size
0032     shape = settings->getInt(SPRAYSHAPE_SHAPE);
0033     // you have to check if the image is null in client
0034     QString url = settings->getString(SPRAYSHAPE_IMAGE_URL);
0035     if (url.isEmpty()) {
0036         image = QImage();
0037     }
0038     else {
0039         image = QImage(url);
0040     }
0041     imageUrl = url;
0042 
0043     return true;
0044 }
0045 
0046 void KisSprayShapeOptionData::write(KisPropertiesConfiguration *settings) const
0047 {
0048     // settings->setProperty(SHAPE_DYNAMICS_DRAWING_ANGLE_WEIGHT, followDrawingAngleWeight);
0049     settings->setProperty(SPRAYSHAPE_ENABLED, enabled);
0050 
0051     settings->setProperty(SPRAYSHAPE_WIDTH, size.width());
0052     settings->setProperty(SPRAYSHAPE_HEIGHT, size.height());
0053     settings->setProperty(SPRAYSHAPE_PROPORTIONAL, proportional);
0054 
0055     // particle type size
0056     settings->setProperty(SPRAYSHAPE_SHAPE, shape);
0057     // you have to check if the image is null in client
0058     settings->setProperty(SPRAYSHAPE_IMAGE_URL, imageUrl);
0059 }
0060 
0061 QSize KisSprayShapeOptionData::effectiveSize(int diameter, qreal scale) const
0062 {
0063     return !proportional ? size : size * diameter * scale / 100.0;
0064 }