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

List:       kde-commits
Subject:    [krita/petrovic/live-brush-preview] libs/ui: implement first pass of smart zooming as brush size inc
From:       Scott Petrovic <null () kde ! org>
Date:       2017-09-30 17:00:57
Message-ID: E1dyL8L-0004Ep-PB () code ! kde ! org
[Download RAW message or body]

Git commit e326a29669b9a99f5246b1ac880a782c008ab84c by Scott Petrovic.
Committed on 30/09/2017 at 17:00.
Pushed by scottpetrovic into branch 'petrovic/live-brush-preview'.

implement first pass of smart zooming as brush size increases

M  +1    -1    libs/ui/forms/wdgpaintopsettings.ui
M  +36   -5    libs/ui/widgets/kis_preset_live_preview_view.cpp
M  +5    -1    libs/ui/widgets/kis_preset_live_preview_view.h

https://commits.kde.org/krita/e326a29669b9a99f5246b1ac880a782c008ab84c

diff --git a/libs/ui/forms/wdgpaintopsettings.ui \
b/libs/ui/forms/wdgpaintopsettings.ui index 4acfa039abb..78431f85374 100644
--- a/libs/ui/forms/wdgpaintopsettings.ui
+++ b/libs/ui/forms/wdgpaintopsettings.ui
@@ -151,7 +151,7 @@
        </property>
        <property name="minimumSize">
         <size>
-         <width>250</width>
+         <width>300</width>
          <height>50</height>
         </size>
        </property>
diff --git a/libs/ui/widgets/kis_preset_live_preview_view.cpp \
b/libs/ui/widgets/kis_preset_live_preview_view.cpp index a2c142f3f45..b13194aed56 \
                100644
--- a/libs/ui/widgets/kis_preset_live_preview_view.cpp
+++ b/libs/ui/widgets/kis_preset_live_preview_view.cpp
@@ -19,6 +19,7 @@
 #include <kis_preset_live_preview_view.h>
 #include <QDebug>
 #include <QGraphicsPixmapItem>
+#include "kis_paintop_settings.h"
 
 KisPresetLivePreviewView::KisPresetLivePreviewView(QWidget *parent): \
QGraphicsView(parent)  {
@@ -28,7 +29,6 @@ KisPresetLivePreviewView::~KisPresetLivePreviewView()
 {
 }
 
-
 void KisPresetLivePreviewView::setup()
 {
     noPreviewText = 0;
@@ -61,11 +61,12 @@ void KisPresetLivePreviewView::setup()
     // points for drawing an S curve
     // we are going to paint the stroke right in the middle of the canvas to make \
sure  // everything is captured for big brush strokes
-    m_curvePointPI1.setPos(QPointF(m_canvasCenterPoint.x()-this->width(),
+    //TODO: we need to update these points according to the brush size. Larger \
brushes need larger strokes +    \
m_curvePointPI1.setPos(QPointF(m_canvasCenterPoint.x() - (this->width()*0.4),  \
m_canvasCenterPoint.y()));  m_curvePointPI1.setPressure(0.0);
 
-    m_curvePointPI2.setPos(QPointF(m_canvasCenterPoint.x()+this->width(),
+    m_curvePointPI2.setPos(QPointF(m_canvasCenterPoint.x() + (this->width()*0.4),
                                    m_canvasCenterPoint.y()));
 
     m_curvePointPI2.setPressure(1.0);
@@ -88,6 +89,14 @@ void KisPresetLivePreviewView::paintStroke()
 {
     m_brushPreviewPainter->setPaintOpPreset(m_currentPreset, m_layer, m_image);
 
+
+    // scale the viewport if we are changing brush size
+    if (m_currentBrushSize != m_currentPreset->settings()->paintOpSize()) {
+        m_currentBrushSize = m_currentPreset->settings()->paintOpSize();
+        zoomToBrushSize();
+    }
+
+
     // clean up "no preview" text object if it exists
     if (noPreviewText) {
         this->scene()->removeItem(noPreviewText);
@@ -158,7 +167,6 @@ void KisPresetLivePreviewView::paintStroke()
     }
 
 
-    //m_brushPreviewPainter->paintLine(m_pi1, m_pi2, &m_currentDistance); // option \
to display line (works)  m_brushPreviewPainter->paintBezierCurve(m_curvePointPI1,
                                             QPointF(m_canvasCenterPoint.x(),
                                                     \
m_canvasCenterPoint.y()-this->height()), @@ -184,7 +192,6 @@ void \
KisPresetLivePreviewView::paintStroke()  
 }
 
-
 void KisPresetLivePreviewView::slotResetViewZoom()
 {
     scaleFactor = 1.0;
@@ -198,4 +205,28 @@ void KisPresetLivePreviewView::slotZoomViewOut()
     this->scale(scaleFactor, scaleFactor);
 }
 
+void KisPresetLivePreviewView::zoomToBrushSize() {
+
+    // m_currentBrushSize.
+    // when the zooming will start and stop
+    float minBrushVal = 1.0;
+    float maxBrushVal = 250.0;
+
+    // range of scale values
+    qreal minScale = 1.0;
+    qreal maxScale = 0.1;
+
+
+    // find the slope of the line (slope-intercept form)
+    float slope = (maxScale-minScale) / (maxBrushVal-minBrushVal);  // y2-y1 / x2-x1
+    float yIntercept = minScale - slope * minBrushVal;  // y1 − m * x1
+
+
+    // finally calculate our zoom level
+    float thresholdValue = qBound(minBrushVal, m_currentBrushSize, maxBrushVal);
+    scaleFactor = thresholdValue * slope + yIntercept; // y = mx + b
+
+    resetMatrix();
+    this->scale(scaleFactor,scaleFactor);
+}
 
diff --git a/libs/ui/widgets/kis_preset_live_preview_view.h \
b/libs/ui/widgets/kis_preset_live_preview_view.h index c0f16c8095e..66349ef235c \
                100644
--- a/libs/ui/widgets/kis_preset_live_preview_view.h
+++ b/libs/ui/widgets/kis_preset_live_preview_view.h
@@ -55,6 +55,7 @@ public Q_SLOTS:
     void slotZoomViewOut();
 
 
+
 private:
     KisImageSP m_image;
     KisLayerSP m_layer;
@@ -88,7 +89,10 @@ private:
 
     QImage temp_image;
 
-    qreal scaleFactor;
+    float scaleFactor;
+    float m_currentBrushSize = 1.0;
+
+    void zoomToBrushSize();
 
 
 


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

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