[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/krita/plugins/paintops/spray
From:       Lukáš Tvrdý <lukast.dev () gmail ! com>
Date:       2009-11-27 16:46:54
Message-ID: 1259340414.158340.6055.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1055234 by lukast:

After the loading of the image, the dimension of the particle is changed to dimension
of the image. You can now use the particle dimension to control the image size.
Useful for loading images with big resolution.

 M  +7 -8      kis_spray_paintop_settings.cpp  
 M  +1 -1      kis_spray_paintop_settings.h  
 M  +24 -4     kis_spray_shape_option.cpp  
 M  +4 -1      kis_spray_shape_option.h  
 M  +11 -8     spray_brush.cpp  
 M  +9 -13     spray_brush.h  


--- trunk/koffice/krita/plugins/paintops/spray/kis_spray_paintop_settings.cpp \
#1055233:1055234 @@ -219,14 +219,6 @@
 }
 
 
-
-const QString KisSprayPaintOpSettings::path() const
-{
-    return m_options->m_sprayShapeOption->path();
-}
-
-
-
 void KisSprayPaintOpSettings::changePaintOpSize(qreal x, qreal y) const
 {
     if (qAbs(x) > qAbs(y)){
@@ -277,3 +269,10 @@
 {
         return m_options->m_sprayShapeOption->followCursorWeigth();
 }
+
+
+
+QImage KisSprayPaintOpSettings::image() const
+{
+    return m_options->m_sprayShapeOption->image();
+}
--- trunk/koffice/krita/plugins/paintops/spray/kis_spray_paintop_settings.h \
#1055233:1055234 @@ -109,7 +109,7 @@
         }
     }
 
-    const QString path() const;
+    QImage image() const;
 
 
 private:
--- trunk/koffice/krita/plugins/paintops/spray/kis_spray_shape_option.cpp \
#1055233:1055234 @@ -18,6 +18,8 @@
 #include "kis_spray_shape_option.h"
 #include <klocale.h>
 
+#include <QImage>
+
 #include "ui_wdgshapeoptions.h"
 
 class KisShapeOptionsWidget: public QWidget, public Ui::WdgShapeOptions
@@ -46,6 +48,8 @@
 
     connect(m_options->randomSlider,SIGNAL(valueChanged(int)),this,SLOT(randomValueChanged(int)));
                
     connect(m_options->followSlider,SIGNAL(valueChanged(int)),this,SLOT(followValueChanged(int)));
 +
+    connect(m_options->imageUrl,SIGNAL(urlSelected(KUrl)),this,SLOT(prepareImage()));
  
     setConfigurationPage(m_options);
 }
@@ -113,10 +117,13 @@
 }
 
 
-QString KisSprayShapeOption::path() const
+
+
+QImage KisSprayShapeOption::image() 
 {
-    return m_options->imageUrl->url().toLocalFile();
-    
+    m_img = QImage( m_options->imageUrl->url().toLocalFile() );
+    m_img = m_img.scaled( width(), height() );
+    return m_img;
 }
 
 
@@ -145,7 +152,6 @@
 }
 
 
-
 bool KisSprayShapeOption::randomRotation() const
 {
     return m_options->randomRotation->isChecked();
@@ -170,3 +176,17 @@
     qreal relative = value / (qreal)m_options->followSlider->maximum() ;
     m_options->followCursorWeightSPBox->setValue( relative * \
m_options->followCursorWeightSPBox->maximum() );  }
+
+
+void KisSprayShapeOption::prepareImage()
+{
+    QString path = m_options->imageUrl->url().toLocalFile();
+    if (QFile::exists(path)){
+        m_img = QImage(path);
+        if (!m_img.isNull())
+        {
+            m_options->widthSpin->setValue( m_img.width() );
+            m_options->heightSpin->setValue( m_img.height() );
+        }
+    }
+}
\ No newline at end of file
--- trunk/koffice/krita/plugins/paintops/spray/kis_spray_shape_option.h \
#1055233:1055234 @@ -18,6 +18,7 @@
 #define KIS_SPRAY_SHAPE_OPTION_H
 
 #include <kis_paintop_option.h>
+#include <QImage>
 
 class KisShapeOptionsWidget;
 
@@ -54,7 +55,7 @@
     bool followCursor() const;
     qreal followCursorWeigth() const;
     
-    QString path() const;
+    QImage image();
     
     /// TODO
     void writeOptionSetting(KisPropertiesConfiguration* setting) const;
@@ -62,10 +63,12 @@
     void readOptionSetting(const KisPropertiesConfiguration* setting);
 private:
     KisShapeOptionsWidget * m_options;
+    QImage m_img;
 
 private slots:
             void randomValueChanged(int value);
             void followValueChanged(int value);
+            void prepareImage();
 };
 
 #endif // KIS_SPRAY_SHAPE_OPTION_H
--- trunk/koffice/krita/plugins/paintops/spray/spray_brush.cpp #1055233:1055234
@@ -100,10 +100,13 @@
     if (!m_painter) {
         m_painter = new KisPainter(dab);
         m_painter->setFillStyle(KisPainter::FillStyleForegroundColor);
-        m_painter->setMaskImageSize(m_width, m_height);
+        m_painter->setMaskImageSize(objectWidth(), objectHeight());
         m_pixelSize = dab->colorSpace()->pixelSize();
         
-        m_brushQImg = QImage(m_settings->path());
+        m_brushQImg = m_settings->image();
+        if (!m_brushQImg.isNull()){
+            m_brushQImg = m_brushQImg.scaled(objectWidth(), objectHeight());
+        }
         m_imgDevice = new KisPaintDevice( dab->colorSpace() );
     }
 
@@ -126,7 +129,7 @@
         y = y + ((2 * m_radius * drand48()) - m_radius) * m_amount;
     }
 
-    // this is wrong
+    // this is wrong for every shape except pixel and anti-aliased pixel 
     if (m_useDensity) {
         m_particlesCount = (m_coverage * (M_PI * m_radius * m_radius));
     }
@@ -226,17 +229,17 @@
         qreal jitteredHeight; 
 
         if (m_jitterShapeSize){
-            jitteredWidth = m_width * random + 1;
-            jitteredHeight = m_height * random + 1;
+            jitteredWidth = objectWidth() * random + 1;
+            jitteredHeight = objectHeight() * random + 1;
         }else{
-            jitteredWidth = m_width;
-            jitteredHeight = m_height;
+            jitteredWidth = objectWidth();
+            jitteredHeight = objectHeight();
         }
         switch (m_settings->shape()){
             // ellipse
             case 0:
             {
-                if (m_width == m_height){
+                if (objectWidth() == objectHeight()){
                     paintCircle(m_painter, nx + x, ny + y, qRound(jitteredWidth * \
0.5) , steps);  }else
                 { 
--- trunk/koffice/krita/plugins/paintops/spray/spray_brush.h #1055233:1055234
@@ -78,19 +78,6 @@
         m_height = height;
     }
 
-    // getters
-    qreal radius() {
-        return m_radius;
-    }
-
-    qreal objectWidth() {
-        return m_width;
-    }
-
-    qreal objectHeight() {
-        return m_height;
-    }
-
     // setters
 
     void setUseDensity(bool useDensity) {
@@ -151,6 +138,15 @@
     inline qreal linearInterpolation(qreal a, qreal b, qreal weight){
         return (1.0 - weight) * a + weight * b;
     }
+
+    /// particle dimension
+    inline qreal objectWidth() {
+        return m_width;
+    }
+    inline qreal objectHeight() {
+        return m_height;
+    }
+
 };
 
 #endif


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic