-rw-r--r-- | kabc/picture.cpp | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/kabc/picture.cpp b/kabc/picture.cpp index 6a34b98..57aa297 100644 --- a/kabc/picture.cpp +++ b/kabc/picture.cpp | |||
@@ -1,141 +1,167 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #include "picture.h" | 28 | #include "picture.h" |
29 | 29 | ||
30 | using namespace KABC; | 30 | using namespace KABC; |
31 | 31 | ||
32 | Picture::Picture() | 32 | Picture::Picture() |
33 | : mIntern( false ) | 33 | : mIntern( false ) |
34 | { | 34 | { |
35 | mUndefined = true; | 35 | mUndefined = true; |
36 | } | 36 | } |
37 | 37 | ||
38 | Picture::Picture( const QString &url ) | 38 | Picture::Picture( const QString &url ) |
39 | : mUrl( url ), mIntern( false ) | 39 | : mUrl( url ), mIntern( false ) |
40 | { | 40 | { |
41 | mUndefined = false; | 41 | mUndefined = false; |
42 | } | 42 | } |
43 | 43 | ||
44 | Picture::Picture( const QImage &data ) | 44 | Picture::Picture( const QImage &data ) |
45 | : mData( data ), mIntern( true ) | 45 | : mData( data ), mIntern( true ) |
46 | { | 46 | { |
47 | mUndefined = false; | 47 | mUndefined = false; |
48 | } | 48 | } |
49 | 49 | ||
50 | Picture::~Picture() | 50 | Picture::~Picture() |
51 | { | 51 | { |
52 | } | 52 | } |
53 | 53 | ||
54 | bool Picture::operator==( const Picture &p ) const | 54 | bool Picture::operator==( const Picture &p ) const |
55 | { | 55 | { |
56 | if ( mIntern != p.mIntern ) return false; | 56 | //qDebug("compare PIC "); |
57 | 57 | if ( mUndefined && p.mUndefined ) { | |
58 | //qDebug("compare PIC true 1 "); | ||
59 | return true; | ||
60 | } | ||
61 | if ( mUndefined || p.mUndefined ) { | ||
62 | //qDebug("compare PIC false 1"); | ||
63 | return false; | ||
64 | } | ||
65 | // now we should deal with two defined pics! | ||
66 | if ( mIntern != p.mIntern ) { | ||
67 | //qDebug("compare PIC false 2"); | ||
68 | return false; | ||
69 | } | ||
58 | if ( mIntern ) { | 70 | if ( mIntern ) { |
59 | if ( mData != p.mData ) | 71 | //qDebug("mIntern "); |
72 | if ( mData.isNull() && p.mData.isNull() ) { | ||
73 | //qDebug("compare PIC true 2 "); | ||
74 | return true; | ||
75 | } | ||
76 | if ( mData.isNull() || p.mData.isNull() ){ | ||
77 | //qDebug("compare PIC false 3-1"); | ||
78 | |||
79 | return false; | ||
80 | } | ||
81 | if ( mData != p.mData ) { | ||
82 | //qDebug("compare PIC false 3"); | ||
60 | return false; | 83 | return false; |
84 | } | ||
61 | } else { | 85 | } else { |
62 | if ( mUrl != p.mUrl ) | 86 | if ( mUrl != p.mUrl ) { |
63 | return false; | 87 | //qDebug("compare PIC false 4"); |
88 | return false; | ||
89 | } | ||
64 | } | 90 | } |
65 | 91 | //qDebug("compare PIC true "); | |
66 | return true; | 92 | return true; |
67 | } | 93 | } |
68 | 94 | ||
69 | bool Picture::operator!=( const Picture &p ) const | 95 | bool Picture::operator!=( const Picture &p ) const |
70 | { | 96 | { |
71 | return !( p == *this ); | 97 | return !( p == *this ); |
72 | } | 98 | } |
73 | 99 | ||
74 | void Picture::setUrl( const QString &url ) | 100 | void Picture::setUrl( const QString &url ) |
75 | { | 101 | { |
76 | mUrl = url; | 102 | mUrl = url; |
77 | mIntern = false; | 103 | mIntern = false; |
78 | mUndefined = false; | 104 | mUndefined = false; |
79 | } | 105 | } |
80 | 106 | ||
81 | void Picture::setData( const QImage &data ) | 107 | void Picture::setData( const QImage &data ) |
82 | { | 108 | { |
83 | mData = data; | 109 | mData = data; |
84 | mIntern = true; | 110 | mIntern = true; |
85 | mUndefined = false; | 111 | mUndefined = false; |
86 | } | 112 | } |
87 | 113 | ||
88 | void Picture::setType( const QString &type ) | 114 | void Picture::setType( const QString &type ) |
89 | { | 115 | { |
90 | mType = type; | 116 | mType = type; |
91 | } | 117 | } |
92 | 118 | ||
93 | bool Picture::isIntern() const | 119 | bool Picture::isIntern() const |
94 | { | 120 | { |
95 | return mIntern; | 121 | return mIntern; |
96 | } | 122 | } |
97 | 123 | ||
98 | QString Picture::url() const | 124 | QString Picture::url() const |
99 | { | 125 | { |
100 | return mUrl; | 126 | return mUrl; |
101 | } | 127 | } |
102 | 128 | ||
103 | QImage Picture::data() const | 129 | QImage Picture::data() const |
104 | { | 130 | { |
105 | return mData; | 131 | return mData; |
106 | } | 132 | } |
107 | QPixmap Picture::pixmap() const | 133 | QPixmap Picture::pixmap() const |
108 | { | 134 | { |
109 | QPixmap p; | 135 | QPixmap p; |
110 | p.convertFromImage ( mData ); | 136 | p.convertFromImage ( mData ); |
111 | return p; | 137 | return p; |
112 | } | 138 | } |
113 | 139 | ||
114 | QString Picture::type() const | 140 | QString Picture::type() const |
115 | { | 141 | { |
116 | return mType; | 142 | return mType; |
117 | } | 143 | } |
118 | bool Picture::undefined() const | 144 | bool Picture::undefined() const |
119 | { | 145 | { |
120 | return mUndefined; | 146 | return mUndefined; |
121 | } | 147 | } |
122 | 148 | ||
123 | 149 | ||
124 | QString Picture::asString() const | 150 | QString Picture::asString() const |
125 | { | 151 | { |
126 | if ( mIntern ) | 152 | if ( mIntern ) |
127 | return "intern picture"; | 153 | return "intern picture"; |
128 | else | 154 | else |
129 | return mUrl; | 155 | return mUrl; |
130 | } | 156 | } |
131 | 157 | ||
132 | QDataStream &KABC::operator<<( QDataStream &s, const Picture &picture ) | 158 | QDataStream &KABC::operator<<( QDataStream &s, const Picture &picture ) |
133 | { | 159 | { |
134 | return s << picture.mIntern << picture.mUrl << picture.mType << picture.mData; | 160 | return s << picture.mIntern << picture.mUrl << picture.mType << picture.mData; |
135 | } | 161 | } |
136 | 162 | ||
137 | QDataStream &KABC::operator>>( QDataStream &s, Picture &picture ) | 163 | QDataStream &KABC::operator>>( QDataStream &s, Picture &picture ) |
138 | { | 164 | { |
139 | s >> picture.mIntern >> picture.mUrl >> picture.mType >> picture.mData; | 165 | s >> picture.mIntern >> picture.mUrl >> picture.mType >> picture.mData; |
140 | return s; | 166 | return s; |
141 | } | 167 | } |