Commit cfc2b625 authored by Thomas Zander's avatar Thomas Zander

Fixes: slowness on embedded devices.

Details: On embedded devices like n810 (which uses an Arm processor) usage
of double is incredably expensive.  In almost all cases our usage of double
can be done just as well using floats on those devices.
This is something that Qt does as well using the type 'qreal' which is a
double on all modern platforms but float on those that don't have double
natively.  So we get the best of both worlds by replacing double with qreal.

svn path=/trunk/koffice/; revision=851499
parent 42f7fbda
......@@ -50,7 +50,7 @@ void KisGrayU16ColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc, Q
{
const GrayU16Traits::channels_type* p = reinterpret_cast<const GrayU16Traits::channels_type*>( pixel );
QDomElement labElt = doc.createElement( "Gray" );
labElt.setAttribute("g", KoColorSpaceMaths< GrayU16Traits::channels_type, double>::scaleToA( p[0]) );
labElt.setAttribute("g", KoColorSpaceMaths< GrayU16Traits::channels_type, qreal>::scaleToA( p[0]) );
labElt.setAttribute("space", profile()->name() );
colorElt.appendChild( labElt );
}
......@@ -58,6 +58,6 @@ void KisGrayU16ColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc, Q
void KisGrayU16ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt) const
{
GrayU16Traits::channels_type* p = reinterpret_cast<GrayU16Traits::channels_type*>( pixel );
p[0] = KoColorSpaceMaths< double, GrayU16Traits::channels_type >::scaleToA(elt.attribute("g").toDouble());
p[0] = KoColorSpaceMaths< qreal, GrayU16Traits::channels_type >::scaleToA(elt.attribute("g").toDouble());
}
......@@ -51,7 +51,7 @@ void KisGrayColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc, QDom
{
const GrayU8Traits::channels_type* p = reinterpret_cast<const GrayU8Traits::channels_type*>( pixel );
QDomElement labElt = doc.createElement( "Gray" );
labElt.setAttribute("g", KoColorSpaceMaths< GrayU8Traits::channels_type, double>::scaleToA( p[0]) );
labElt.setAttribute("g", KoColorSpaceMaths< GrayU8Traits::channels_type, qreal>::scaleToA( p[0]) );
labElt.setAttribute("space", profile()->name() );
colorElt.appendChild( labElt );
}
......@@ -59,6 +59,6 @@ void KisGrayColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc, QDom
void KisGrayColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt) const
{
GrayU8Traits::channels_type* p = reinterpret_cast<GrayU8Traits::channels_type*>( pixel );
p[0] = KoColorSpaceMaths< double, GrayU8Traits::channels_type >::scaleToA(elt.attribute("g").toDouble());
p[0] = KoColorSpaceMaths< qreal, GrayU8Traits::channels_type >::scaleToA(elt.attribute("g").toDouble());
}
......@@ -62,9 +62,9 @@ void KisXyzU16ColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc, QD
{
const XyzU16Traits::Pixel* p = reinterpret_cast<const XyzU16Traits::Pixel*>( pixel );
QDomElement labElt = doc.createElement( "XYZ" );
labElt.setAttribute("x", KoColorSpaceMaths< XyzU16Traits::channels_type, double>::scaleToA( p->X) );
labElt.setAttribute("y", KoColorSpaceMaths< XyzU16Traits::channels_type, double>::scaleToA( p->Y) );
labElt.setAttribute("z", KoColorSpaceMaths< XyzU16Traits::channels_type, double>::scaleToA( p->Z) );
labElt.setAttribute("x", KoColorSpaceMaths< XyzU16Traits::channels_type, qreal>::scaleToA( p->X) );
labElt.setAttribute("y", KoColorSpaceMaths< XyzU16Traits::channels_type, qreal>::scaleToA( p->Y) );
labElt.setAttribute("z", KoColorSpaceMaths< XyzU16Traits::channels_type, qreal>::scaleToA( p->Z) );
labElt.setAttribute("space", profile()->name() );
colorElt.appendChild( labElt );
}
......@@ -72,8 +72,8 @@ void KisXyzU16ColorSpace::colorToXML( const quint8* pixel, QDomDocument& doc, QD
void KisXyzU16ColorSpace::colorFromXML( quint8* pixel, const QDomElement& elt) const
{
XyzU16Traits::Pixel* p = reinterpret_cast<XyzU16Traits::Pixel*>( pixel );
p->X = KoColorSpaceMaths< double, XyzU16Traits::channels_type >::scaleToA(elt.attribute("x").toDouble());
p->Y = KoColorSpaceMaths< double, XyzU16Traits::channels_type >::scaleToA(elt.attribute("y").toDouble());
p->Z = KoColorSpaceMaths< double, XyzU16Traits::channels_type >::scaleToA(elt.attribute("z").toDouble());
p->X = KoColorSpaceMaths< qreal, XyzU16Traits::channels_type >::scaleToA(elt.attribute("x").toDouble());
p->Y = KoColorSpaceMaths< qreal, XyzU16Traits::channels_type >::scaleToA(elt.attribute("y").toDouble());
p->Z = KoColorSpaceMaths< qreal, XyzU16Traits::channels_type >::scaleToA(elt.attribute("z").toDouble());
}
......@@ -154,7 +154,7 @@ KisLayerBox::KisLayerBox()
connect(m_wdgLayerBox->bnProperties, SIGNAL(clicked()), SLOT(slotPropertiesClicked()));
connect(m_wdgLayerBox->bnDuplicate, SIGNAL(clicked()), SLOT(slotDuplicateClicked()));
connect(m_wdgLayerBox->doubleOpacity, SIGNAL(valueChanged(double, bool)), SIGNAL(sigOpacityChanged(double, bool)));
connect(m_wdgLayerBox->doubleOpacity, SIGNAL(valueChanged(qreal, bool)), SIGNAL(sigOpacityChanged(qreal, bool)));
connect(m_wdgLayerBox->cmbComposite, SIGNAL(activated(const KoCompositeOp*)), SIGNAL(sigItemComposite(const KoCompositeOp*)));
}
......
......@@ -78,7 +78,7 @@ signals:
// use strings
void sigRequestNewNode( const QString & nodetype);
void sigRequestNodeProperties(KisNodeSP node);
void sigOpacityChanged(double opacity, bool final);
void sigOpacityChanged(qreal opacity, bool final);
void sigItemComposite(const KoCompositeOp*);
private slots:
......
......@@ -337,7 +337,7 @@ void KisNodeManager::nodeProperties( KisNodeSP node )
}
}
void KisNodeManager::nodeOpacityChanged( double opacity, bool final)
void KisNodeManager::nodeOpacityChanged( qreal opacity, bool final)
{
m_d->layerManager->layerOpacity( opacity, final );
}
......
......@@ -88,7 +88,7 @@ public slots:
void activateNode( KisNodeSP layer );
void nodesUpdated();
void nodeProperties( KisNodeSP node );
void nodeOpacityChanged( double opacity, bool final);
void nodeOpacityChanged( qreal opacity, bool final);
void nodeCompositeOpChanged( const KoCompositeOp* op );
void duplicateActiveNode( KisNodeSP node );
......
......@@ -125,7 +125,7 @@ QWidget * KisToolPaint::createOptionWidget()
m_slOpacity->setMaximum(100);
m_slOpacity->setDecimals(0);
m_slOpacity->setValue(m_opacity / OPACITY_OPAQUE * 100);
connect(m_slOpacity, SIGNAL(valueChanged(double, bool)), this, SLOT(slotSetOpacity(double, bool)));
connect(m_slOpacity, SIGNAL(valueChanged(qreal, bool)), this, SLOT(slotSetOpacity(qreal, bool)));
m_lbComposite = new QLabel(i18n("Mode: "), optionWidget);
m_cmbComposite = new KisCmbComposite(optionWidget);
......@@ -180,7 +180,7 @@ void KisToolPaint::addOptionWidgetOption(QWidget *control, QWidget *label)
m_optionWidgetLayout->addWidget(control, m_optionWidgetLayout->rowCount(), 0, 1, 2);
}
void KisToolPaint::slotSetOpacity(double opacityPerCent, bool final)
void KisToolPaint::slotSetOpacity(qreal opacityPerCent, bool final)
{
Q_UNUSED(final);
m_opacity = (int)(opacityPerCent * OPACITY_OPAQUE / 100);
......
......@@ -99,7 +99,7 @@ private:
private slots:
void slotPopupQuickHelp();
void slotSetOpacity(double opacityPerCent, bool final);
void slotSetOpacity(qreal opacityPerCent, bool final);
void slotSetCompositeMode(const KoCompositeOp* compositeOp);
protected:
......
......@@ -541,8 +541,8 @@ void KisView2::createGUI()
connect(m_d->layerBox, SIGNAL(sigRequestNodeProperties(KisNodeSP)),
m_d->nodeManager, SLOT(nodeProperties(KisNodeSP)));
connect(m_d->layerBox, SIGNAL(sigOpacityChanged(double, bool)),
m_d->nodeManager, SLOT(nodeOpacityChanged(double, bool)));
connect(m_d->layerBox, SIGNAL(sigOpacityChanged(qreal, bool)),
m_d->nodeManager, SLOT(nodeOpacityChanged(qreal, bool)));
connect(m_d->layerBox, SIGNAL(sigItemComposite(const KoCompositeOp*)),
m_d->nodeManager, SLOT(nodeCompositeOpChanged(const KoCompositeOp*)));
......
......@@ -67,10 +67,10 @@ public:
/**
* retrieve the grid size setting.
* The grid spacing will be provided in pt.
* @param horizontal a pointer to a double that will be filled with the horizontal grid-spacing
* @param vertical a pointer to a double that will be filled with the vertical grid-spacing
* @param horizontal a pointer to a qreal that will be filled with the horizontal grid-spacing
* @param vertical a pointer to a qreal that will be filled with the vertical grid-spacing
*/
virtual void gridSize(double *horizontal, double *vertical) const = 0;
virtual void gridSize(qreal *horizontal, qreal *vertical) const = 0;
/**
* return if snap to grid is enabled.
......
......@@ -60,8 +60,8 @@ public:
QSize documentSize;
QPoint documentOffset;
Viewport * viewportWidget;
double preferredCenterFractionX;
double preferredCenterFractionY;
qreal preferredCenterFractionX;
qreal preferredCenterFractionY;
bool ignoreScrollSignals;
};
......@@ -385,15 +385,15 @@ void KoCanvasController::zoomBy(const QPoint &center, qreal zoom )
void KoCanvasController::zoomTo(const QRect &viewRect)
{
double scale;
qreal scale;
if(1.0 * viewport()->width() / viewRect.width() > 1.0 * viewport()->height() / viewRect.height())
scale = 1.0 * viewport()->height() / viewRect.height();
else
scale = 1.0 * viewport()->width() / viewRect.width();
const double preferredCenterFractionX = 1.0 * viewRect.center().x() / m_d->documentSize.width();
const double preferredCenterFractionY = 1.0 * viewRect.center().y() / m_d->documentSize.height();
const qreal preferredCenterFractionX = 1.0 * viewRect.center().x() / m_d->documentSize.width();
const qreal preferredCenterFractionY = 1.0 * viewRect.center().y() / m_d->documentSize.height();
emit zoomBy(scale);
......@@ -572,7 +572,7 @@ void KoCanvasController::wheelEvent( QWheelEvent *event ) {
const QPoint offset( horizontalScrollBar()->value(), verticalScrollBar()->value() );
const QPoint mousePos( event->pos() + offset );
const double zoomLevel = event->delta() > 0 ? sqrt(2.0) : sqrt(0.5);
const qreal zoomLevel = event->delta() > 0 ? sqrt(2.0) : sqrt(0.5);
QPointF oldCenter = preferredCenter();
if ( visibleWidth() >= m_d->documentSize.width() )
......
......@@ -297,7 +297,7 @@ signals:
*
* @param factor by how much the zoom needs to change.
*/
void zoomBy( const double factor );
void zoomBy( const qreal factor );
public slots:
......
......@@ -154,7 +154,7 @@ public:
int intResource(int key) const;
/**
* Return the resource determined by param key as a double.
* Return the resource determined by param key as a qreal.
* @param key the indentifying key for the resource.
*/
bool doubleResource(int key) const;
......
......@@ -152,7 +152,7 @@ void KoConnectionShape::updatePath( const QSizeF &size )
{
Q_UNUSED( size );
const double MinimumEscapeLength = 20.0;
const qreal MinimumEscapeLength = 20.0;
clear();
switch( d->connectionType )
......@@ -186,7 +186,7 @@ void KoConnectionShape::updatePath( const QSizeF &size )
}
// check if we are going toward the other handle
double sp = scalarProd( direction1, edgePoint2-edgePoint1 );
qreal sp = scalarProd( direction1, edgePoint2-edgePoint1 );
if( sp >= 0.0 )
{
// if we are having the same direction, go all the way toward
......@@ -359,7 +359,7 @@ QPointF KoConnectionShape::escapeDirection( int handleId ) const
else
centerPoint = d->shape2->absolutePosition( KoFlake::CenteredPosition );
double angle = atan2( handlePoint.y()-centerPoint.y(), handlePoint.x()-centerPoint.x() );
qreal angle = atan2( handlePoint.y()-centerPoint.y(), handlePoint.x()-centerPoint.x() );
if( angle < 0.0 )
angle += 2.0*M_PI;
angle *= 180.0 / M_PI;
......@@ -383,16 +383,16 @@ QPointF KoConnectionShape::escapeDirection( int handleId ) const
bool KoConnectionShape::intersects( const QPointF &p1, const QPointF &d1, const QPointF &p2, const QPointF &d2, QPointF &isect )
{
double sp1 = scalarProd( d1, p2-p1 );
qreal sp1 = scalarProd( d1, p2-p1 );
if( sp1 < 0.0 )
return false;
double sp2 = scalarProd( d2, p1-p2 );
qreal sp2 = scalarProd( d2, p1-p2 );
if( sp2 < 0.0 )
return false;
// use cross product to check if rays intersects at all
double cp = crossProd( d1, d2 );
qreal cp = crossProd( d1, d2 );
if( cp == 0.0 )
{
// rays are parallel or coincidient
......@@ -418,12 +418,12 @@ bool KoConnectionShape::intersects( const QPointF &p1, const QPointF &d1, const
return true;
}
double KoConnectionShape::scalarProd( const QPointF &v1, const QPointF &v2 )
qreal KoConnectionShape::scalarProd( const QPointF &v1, const QPointF &v2 )
{
return v1.x()*v2.x() + v1.y()*v2.y();
}
double KoConnectionShape::crossProd( const QPointF &v1, const QPointF &v2 )
qreal KoConnectionShape::crossProd( const QPointF &v1, const QPointF &v2 )
{
return (v1.x()*v2.y() - v1.y()*v2.x() );
}
......@@ -431,7 +431,7 @@ double KoConnectionShape::crossProd( const QPointF &v1, const QPointF &v2 )
QPointF KoConnectionShape::perpendicularDirection( const QPointF &p1, const QPointF &d1, const QPointF &p2 )
{
QPointF perpendicular( d1.y(), -d1.x() );
double sp = scalarProd( perpendicular, p2-p1 );
qreal sp = scalarProd( perpendicular, p2-p1 );
if( sp < 0.0 )
perpendicular *= -1.0;
......
......@@ -105,8 +105,8 @@ private:
// reimplemented
virtual void notifyShapeChanged( KoShape * shape, ChangeType type );
double scalarProd( const QPointF &v1, const QPointF &v2 );
double crossProd( const QPointF &v1, const QPointF &v2 );
qreal scalarProd( const QPointF &v1, const QPointF &v2 );
qreal crossProd( const QPointF &v1, const QPointF &v2 );
struct Private;
Private * const d;
......
......@@ -251,12 +251,12 @@ const QSizeF KoImageData:: imageSize() {
image(); // make sure the image is loaded
if(d->image.dotsPerMeterX())
d->imageSize.setWidth( DM_TO_POINT(d->image.width() / (double) d->image.dotsPerMeterX() * 10.0) );
d->imageSize.setWidth( DM_TO_POINT(d->image.width() / (qreal) d->image.dotsPerMeterX() * 10.0) );
else
d->imageSize.setWidth( d->image.width() / 72.0);
if(d->image.dotsPerMeterY())
d->imageSize.setHeight( DM_TO_POINT(d->image.height() / (double) d->image.dotsPerMeterY() * 10.0) );
d->imageSize.setHeight( DM_TO_POINT(d->image.height() / (qreal) d->image.dotsPerMeterY() * 10.0) );
else
d->imageSize.setHeight( d->image.height() / 72.0);
}
......
......@@ -34,7 +34,7 @@ public:
* @param bottom the inset at the bottom
* @param right the inset at the right
*/
KoInsets(double top, double left, double bottom, double right) {
KoInsets(qreal top, qreal left, qreal bottom, qreal right) {
this->top = top;
this->left = left;
this->bottom = bottom;
......@@ -46,10 +46,10 @@ public:
*/
KoInsets() : top(0.), bottom(0.), left(0.), right(0.) {
}
double top; ///< Top inset
double bottom; ///< Bottom inset
double left; ///< Left inset
double right; ///< Right inset
qreal top; ///< Top inset
qreal bottom; ///< Bottom inset
qreal left; ///< Left inset
qreal right; ///< Right inset
};
#endif
......@@ -51,7 +51,7 @@ KoLineBorder::KoLineBorder( const KoLineBorder & other )
d->brush = other.d->brush;
}
KoLineBorder::KoLineBorder(double lineWidth, const QColor &color)
KoLineBorder::KoLineBorder(qreal lineWidth, const QColor &color)
: d(new Private())
{
d->pen.setWidthF( qMax(0.0,lineWidth) );
......@@ -131,7 +131,7 @@ void KoLineBorder::fillStyle( KoGenStyle &style, KoShapeSavingContext &context )
void KoLineBorder::borderInsets(const KoShape *shape, KoInsets &insets) {
Q_UNUSED(shape);
double lineWidth = d->pen.widthF();
qreal lineWidth = d->pen.widthF();
if(lineWidth < 0)
lineWidth = 1;
lineWidth /= 2; // since we draw a line half inside, and half outside the object.
......@@ -174,19 +174,19 @@ Qt::PenJoinStyle KoLineBorder::joinStyle() const {
return d->pen.joinStyle();
}
void KoLineBorder::setLineWidth( double lineWidth ) {
void KoLineBorder::setLineWidth( qreal lineWidth ) {
d->pen.setWidthF( qMax(0.0,lineWidth) );
}
double KoLineBorder::lineWidth() const {
qreal KoLineBorder::lineWidth() const {
return d->pen.widthF();
}
void KoLineBorder::setMiterLimit( double miterLimit ) {
void KoLineBorder::setMiterLimit( qreal miterLimit ) {
d->pen.setMiterLimit( miterLimit );
}
double KoLineBorder::miterLimit() const {
qreal KoLineBorder::miterLimit() const {
return d->pen.miterLimit();
}
......@@ -218,12 +218,12 @@ QVector<qreal> KoLineBorder::lineDashes() const
return d->pen.dashPattern();
}
void KoLineBorder::setDashOffset( double dashOffset )
void KoLineBorder::setDashOffset( qreal dashOffset )
{
d->pen.setDashOffset( dashOffset );
}
double KoLineBorder::dashOffset() const
qreal KoLineBorder::dashOffset() const
{
return d->pen.dashOffset();
}
......
......@@ -48,7 +48,7 @@ public:
* @param lineWidth the width, in pt
* @param color the color we draw the outline in.
*/
explicit KoLineBorder(double lineWidth, const QColor &color = Qt::black);
explicit KoLineBorder(qreal lineWidth, const QColor &color = Qt::black);
virtual ~KoLineBorder();
/// Assignment operator
......@@ -63,13 +63,13 @@ public:
/// Returns the lines join style
Qt::PenJoinStyle joinStyle() const;
/// Sets the line width
void setLineWidth( double lineWidth );
void setLineWidth( qreal lineWidth );
/// Returns the line width
double lineWidth() const;
qreal lineWidth() const;
/// Sets the miter limit
void setMiterLimit( double miterLimit );
void setMiterLimit( qreal miterLimit );
/// Returns the miter limit
double miterLimit() const;
qreal miterLimit() const;
/// Sets the line style
void setLineStyle( Qt::PenStyle style, const QVector<qreal> &dashes );
/// Returns the line style
......@@ -77,9 +77,9 @@ public:
/// Returns the line dashes
QVector<qreal> lineDashes() const;
/// Sets the dash offset
void setDashOffset( double dashOffset );
void setDashOffset( qreal dashOffset );
/// Returns the dash offset
double dashOffset() const;
qreal dashOffset() const;
/// Returns the color
const QColor & color() const;
......
......@@ -571,7 +571,7 @@ qreal KoPathSegment::length( qreal error ) const
QList<QPointF> ctrlPoints = controlPoints();
// calculate chord length
double chordLen = chordLength();
qreal chordLen = chordLength();
if( deg == 1 )
{
......@@ -579,7 +579,7 @@ qreal KoPathSegment::length( qreal error ) const
}
// calculate length of control polygon
double polyLength = 0.0;
qreal polyLength = 0.0;
for( int i = 0; i < deg; ++i )
{
......@@ -661,7 +661,7 @@ bool KoPathSegment::isFlat( qreal tolerance ) const
QPointF chord = d->second->point() - d->first->point();
// calculate angle of chord to the x-axis
double chordAngle = atan2( chord.y(), chord.x() );
qreal chordAngle = atan2( chord.y(), chord.x() );
QMatrix m;
m.translate( d->first->point().x(), d->first->point().y() );
m.rotate( chordAngle * M_PI / 180.0 );
......@@ -1023,7 +1023,7 @@ QList<qreal> KoPathSegment::extrema() const
}
else
{
double rx = b.x()*b.x() - 4.0*a.x()*c.x();
qreal rx = b.x()*b.x() - 4.0*a.x()*c.x();
if( rx < 0.0 )
rx = 0.0;
params.append( ( -b.x() + sqrt( rx ) ) / ( 2.0*a.x() ) );
......@@ -1037,7 +1037,7 @@ QList<qreal> KoPathSegment::extrema() const
}
else
{
double ry = b.y()*b.y() - 4.0*a.y()*c.y();
qreal ry = b.y()*b.y() - 4.0*a.y()*c.y();
if( ry < 0.0 )
ry = 0.0;
params.append( ( -b.y() + sqrt( ry ) ) / ( 2.0*a.y() ) );
......
......@@ -318,7 +318,7 @@ void KoPathShape::paintPoints( QPainter &painter, const KoViewConverter &convert
}
}
QRectF KoPathShape::handleRect( const QPointF &p, double radius ) const
QRectF KoPathShape::handleRect( const QPointF &p, qreal radius ) const
{
return QRectF( p.x()-radius, p.y()-radius, 2*radius, 2*radius );
}
......@@ -410,8 +410,8 @@ QSizeF KoPathShape::size() const
void KoPathShape::setSize( const QSizeF &newSize )
{
QSizeF oldSize = size();
double zoomX = oldSize.width() == 0.0 ? 1.0 : newSize.width() / oldSize.width();
double zoomY = oldSize.height() == 0.0 ? 1.0 : newSize.height() / oldSize.height();
qreal zoomX = oldSize.width() == 0.0 ? 1.0 : newSize.width() / oldSize.width();
qreal zoomY = oldSize.height() == 0.0 ? 1.0 : newSize.height() / oldSize.height();
QMatrix matrix( zoomX, 0, 0, zoomY, 0, 0 );
//qDebug() << "setSize" << zoomX << "," << zoomY << "," << newSize;
......@@ -470,7 +470,7 @@ KoPathPoint * KoPathShape::curveTo( const QPointF &c, const QPointF &p )
return point;
}
KoPathPoint * KoPathShape::arcTo( double rx, double ry, double startAngle, double sweepAngle )
KoPathPoint * KoPathShape::arcTo( qreal rx, qreal ry, qreal startAngle, qreal sweepAngle )
{
if ( m_subpaths.empty() )
{
......@@ -495,7 +495,7 @@ KoPathPoint * KoPathShape::arcTo( double rx, double ry, double startAngle, doubl
return newEndPoint;
}