~ubuntu-branches/debian/sid/scribus/sid

« back to all changes in this revision

Viewing changes to scribus/vgradient.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Oleksandr Moskalenko
  • Date: 2008-07-02 13:42:07 UTC
  • mto: (4.1.1 sid) (1.2.1) (20.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20080702134207-h9h384v0wxjmaf8y
Tags: upstream-1.3.3.12.dfsg
ImportĀ upstreamĀ versionĀ 1.3.3.12.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
 
3
to the COPYING file provided with the program. Following this notice may exist
 
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
 
5
for which a new license (GPL+exception) is in place.
 
6
*/
1
7
/* This file is part of the KDE project
2
8
   Copyright (C) 2002, The Karbon Developers
3
9
 
17
23
   Boston, MA 02111-1307, USA.
18
24
*/
19
25
#include "vgradient.h"
 
26
#include <algorithm>
 
27
 
 
28
// colorStop comparison function for stable_sort function
 
29
bool compareStops( const VColorStop* item1, const VColorStop* item2 )
 
30
{
 
31
        double r1 = item1->rampPoint;
 
32
        double r2 = item2->rampPoint;
 
33
        return ( r1 < r2 ? true : false );
 
34
}
20
35
 
21
36
int VGradient::VColorStopList::compareItems( QPtrCollection::Item item1, QPtrCollection::Item item2 )
22
37
{
26
41
        return ( r1 == r2 ? 0 : r1 < r2 ? -1 : 1 );
27
42
} // VGradient::VColorStopList::compareItems
28
43
 
 
44
void VGradient::VColorStopList::inSort( QPtrCollection::Item d )
 
45
{
 
46
        int index = 0;
 
47
        first();
 
48
        register VColorStop *n = first();
 
49
        while ( n && compareItems((QPtrCollection::Item) n,d) <= 0 ){ // find position in list
 
50
                n = next();
 
51
                index++;
 
52
        }
 
53
        insertAt( index, d );
 
54
}
 
55
 
29
56
VGradient::VGradient( VGradientType type )
30
57
                : m_type( type )
31
58
{
57
84
 
58
85
        m_colorStops.clear();
59
86
        QPtrVector<VColorStop> cs = gradient.colorStops();
 
87
        std::stable_sort(cs.data(), cs.data() + cs.count(), compareStops);
60
88
        for( uint i = 0; i < cs.count(); ++i)
61
89
                m_colorStops.append( new VColorStop( *cs[i] ) );
62
 
        m_colorStops.sort();
63
90
} // VGradient::VGradient
64
91
 
65
92
VGradient& VGradient::operator=( const VGradient& gradient )
77
104
 
78
105
        m_colorStops.clear();
79
106
        QPtrVector<VColorStop> cs = gradient.colorStops();
 
107
        std::stable_sort(cs.data(), cs.data() + cs.count(), compareStops);
80
108
        for( uint i = 0; i < cs.count(); ++i )
81
109
                m_colorStops.append( new VColorStop( *cs[i] ) );
82
 
        m_colorStops.sort();
83
 
 
84
110
        return *this;
85
111
} // VGradient::operator=
86
112
 
127
153
        m_colorStops.remove( n );
128
154
}
129
155
 
 
156
void VGradient::filterStops(void)
 
157
{
 
158
        VColorStop* colorStop = NULL;
 
159
        bool zeroFound = false;
 
160
        colorStop = m_colorStops.last();
 
161
        while(colorStop != NULL)
 
162
        {
 
163
                if (colorStop->rampPoint == 0.0 && zeroFound)
 
164
                        m_colorStops.remove();
 
165
                else if (colorStop->rampPoint == 0.0)
 
166
                        zeroFound = true;
 
167
                colorStop = m_colorStops.prev();
 
168
        }
 
169
        bool oneFound = false;
 
170
        colorStop = m_colorStops.first();
 
171
        while(colorStop != NULL)
 
172
        {
 
173
                if (colorStop->rampPoint == 1.0 && oneFound)
 
174
                {
 
175
                        bool isLast = (colorStop == m_colorStops.getLast());
 
176
                        m_colorStops.remove();
 
177
                        if (isLast)
 
178
                                colorStop = m_colorStops.next();
 
179
                        colorStop = m_colorStops.current();
 
180
                }
 
181
                else if (colorStop->rampPoint == 1.0)
 
182
                {
 
183
                        oneFound = true;
 
184
                        colorStop = m_colorStops.next();
 
185
                }
 
186
                else
 
187
                        colorStop = m_colorStops.next();
 
188
        }
 
189
}
 
190
 
130
191
void VGradient::transform( const QWMatrix &m )
131
192
{
132
193
        double mx, my;