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

List:       kde-commits
Subject:    koffice/karbon
From:       Jan Hambrecht <jaham () gmx ! net>
Date:       2009-03-29 17:46:50
Message-ID: 1238348810.163910.26538.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 946572 by jaham:

as long as we have no proper color dialog use the kde color dialog for setting \
gradient stop colors



 M  +44 -0     common/KarbonGradientHelper.cpp  
 M  +3 -0      common/KarbonGradientHelper.h  
 M  +21 -30    ui/widgets/KarbonGradientWidget.cpp  


--- trunk/koffice/karbon/common/KarbonGradientHelper.cpp #946571:946572
@@ -215,3 +215,47 @@
 
     return newGradient;
 }
+
+QColor KarbonGradientHelper::colorAt( qreal position, const QGradientStops &stops )
+{
+    if( ! stops.count() )
+        return QColor();
+
+    if( stops.count() == 1 )
+        return stops.first().second;
+    
+    QGradientStop prevStop( -1.0, QColor() );
+    QGradientStop nextStop( 2.0, QColor() );
+    // find framing gradient stops
+    foreach( const QGradientStop & stop, stops )
+    {
+        if( stop.first > prevStop.first && stop.first < position )
+            prevStop = stop;
+        if( stop.first < nextStop.first && stop.first > position )
+            nextStop = stop;
+    }
+    
+    QColor theColor;
+    
+    if( prevStop.first < 0.0 )
+    {
+        // new stop is before the first stop
+        theColor = nextStop.second;
+    }
+    else if( nextStop.first > 1.0 )
+    {
+        // new stop is after the last stop
+        theColor = prevStop.second;
+    }
+    else
+    {
+        // linear interpolate colors between framing stops
+        QColor prevColor = prevStop.second, nextColor = nextStop.second;
+        qreal colorScale = (position - prevStop.first) / (nextStop.first - \
prevStop.first); +        theColor.setRedF( prevColor.redF() + colorScale * \
(nextColor.redF()-prevColor.redF()) ); +        theColor.setGreenF( \
prevColor.greenF() + colorScale * (nextColor.greenF()-prevColor.greenF()) ); +        \
theColor.setBlueF( prevColor.blueF() + colorScale * \
(nextColor.blueF()-prevColor.blueF()) ); +        theColor.setAlphaF( \
prevColor.alphaF() + colorScale * (nextColor.alphaF()-prevColor.alphaF()) ); +    }
+    return theColor;
+}
\ No newline at end of file
--- trunk/koffice/karbon/common/KarbonGradientHelper.h #946571:946572
@@ -42,6 +42,9 @@
     static QGradient * defaultGradient( const QSizeF &size, QGradient::Type type, \
QGradient::Spread spread, const QGradientStops &stops );  /// Converts gradient type, \
                preserving as much data as possible
     static QGradient * convertGradient( const QGradient * gradient, QGradient::Type \
newType ); +    
+    /// Calculates color at given position from given gradient stops
+    static QColor colorAt( qreal position, const QGradientStops &stops );
 };
 
 #endif // KARBONGRADIENTHELPER_H
--- trunk/koffice/karbon/ui/widgets/KarbonGradientWidget.cpp #946571:946572
@@ -28,21 +28,21 @@
 
 #include "KarbonGradientWidget.h"
 #include "KarbonCursor.h"
+#include "KarbonGradientHelper.h"
 
-#include <KoUniColorDialog.h>
+#include <KLocale>
+#include <KIconLoader>
+#include <KColorDialog>
 
-#include <klocale.h>
-#include <kiconloader.h>
+#include <QtGui/QLabel>
+#include <QtGui/QBitmap>
+#include <QtGui/QPaintEvent>
+#include <QtGui/QPixmap>
+#include <QtGui/QMouseEvent>
+#include <QtGui/QPainter>
+#include <QtCore/QPointF>
+#include <QtCore/QRectF>
 
-#include <QLabel>
-#include <QBitmap>
-#include <QPaintEvent>
-#include <QPixmap>
-#include <QMouseEvent>
-#include <QPointF>
-#include <QRectF>
-#include <QPainter>
-
 #include <limits>
 
 #define midPoint_width 7
@@ -208,33 +208,24 @@
 
     if( m_currentStop >= 0 )
     {
-        // ramp point hit -> change color
-        KoColor oldColor;
-        oldColor.fromQColor( m_stops[m_currentStop].second );
-
-        KoUniColorDialog * d = new KoUniColorDialog( oldColor, \
                this->topLevelWidget() );
-        if( d->exec() == QDialog::Accepted )
-        {
-            m_stops[m_currentStop].second = d->color().toQColor();
+        // color stop hit -> change color
+        int result = KColorDialog::getColor( m_stops[m_currentStop].second, this );
+        if ( result == KColorDialog::Accepted ) {
             update();
             emit changed();
         }
-        delete d;
     }
     else if( m_currentStop == -1 )
     {
-        KoColor newColor;
-        newColor.fromQColor( m_stops[0].second );
-
-        // no point hit -> create new color stop
-        KoUniColorDialog * d = new KoUniColorDialog( newColor, \
                this->topLevelWidget() );
-        if( d->exec() == QDialog::Accepted )
-        {
-            m_stops.append( QGradientStop((qreal)( e->x()-m_pntArea.left() ) / \
m_pntArea.width(), d->color().toQColor()) ); +        // no color stop hit -> new \
color stop +        qreal newStopPosition = static_cast<qreal>( \
e->x()-m_pntArea.left() ) / m_pntArea.width(); +        QColor newStopColor = \
KarbonGradientHelper::colorAt( newStopPosition, m_stops ); +        int result = \
KColorDialog::getColor( newStopColor, this ); +        if ( result == \
KColorDialog::Accepted ) { +            m_stops.append( \
QGradientStop(newStopPosition, newStopColor) );  update();
             emit changed();
         }
-        delete d;
     }
 }
 


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

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