|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbCore module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 #include "hbframebackground.h" |
|
26 #include "hbframebackground_p.h" |
|
27 |
|
28 #include <QVariant> |
|
29 |
|
30 /*! |
|
31 @stable |
|
32 @hbcore |
|
33 \class HbFrameBackground |
|
34 \brief HbFrameBackground stores the frame data. |
|
35 |
|
36 This class is a data container for frame related data. It stores data that defines the |
|
37 frame background into single object that can be stored into QVariant. |
|
38 */ |
|
39 |
|
40 // Must be initialized dynamically because QIcon cannot be constructed |
|
41 // when static variables are constructed. |
|
42 static HbFrameBackgroundPrivate *shared_null = 0; |
|
43 |
|
44 static const int frameBackgroundMetaType = qRegisterMetaType<HbFrameBackground>(); |
|
45 |
|
46 // This constructor is used for shared_null instance only |
|
47 HbFrameBackgroundPrivate::HbFrameBackgroundPrivate() : |
|
48 frameGraphicsName(), |
|
49 type(HbFrameDrawer::Undefined) |
|
50 { |
|
51 ref.ref(); // Need to do extra ref so the shared null does not get destructed |
|
52 } |
|
53 |
|
54 HbFrameBackgroundPrivate::HbFrameBackgroundPrivate(const QString &frameGraphicsName, HbFrameDrawer::FrameType type) : |
|
55 frameGraphicsName(frameGraphicsName), |
|
56 type(type) |
|
57 { |
|
58 } |
|
59 |
|
60 /*! Default constructor. |
|
61 */ |
|
62 HbFrameBackground::HbFrameBackground() |
|
63 { |
|
64 // Construct shared_null if not done yet. |
|
65 if ( !shared_null ) { |
|
66 shared_null = new HbFrameBackgroundPrivate; |
|
67 } |
|
68 d = shared_null; |
|
69 } |
|
70 |
|
71 /*! Constructs a new frame background with the given \a frameGraphicsName and \a type . |
|
72 */ |
|
73 HbFrameBackground::HbFrameBackground(const QString &frameGraphicsName, HbFrameDrawer::FrameType type) : |
|
74 d(new HbFrameBackgroundPrivate(frameGraphicsName, type)) |
|
75 { |
|
76 } |
|
77 |
|
78 /*! |
|
79 * Copy constructs a new frame background using the \a other frame background. |
|
80 */ |
|
81 HbFrameBackground::HbFrameBackground( const HbFrameBackground &other ) : |
|
82 d(other.d) |
|
83 { |
|
84 } |
|
85 |
|
86 /*! |
|
87 * Destroys the frame background. |
|
88 */ |
|
89 HbFrameBackground::~HbFrameBackground() |
|
90 { |
|
91 } |
|
92 |
|
93 /*! |
|
94 * Assigns the \a other frame background to this frame background and returns a reference to |
|
95 * this frame background. Copy-on-write semantics is used, so this only does a shallow copy. |
|
96 */ |
|
97 HbFrameBackground &HbFrameBackground::operator=( const HbFrameBackground &other ) |
|
98 { |
|
99 if (&other != this) { |
|
100 d = other.d; |
|
101 } |
|
102 return *this; |
|
103 } |
|
104 |
|
105 /*! |
|
106 * Equality operator. |
|
107 */ |
|
108 bool HbFrameBackground::operator==( const HbFrameBackground &other ) const |
|
109 { |
|
110 return !( *this != other ); |
|
111 } |
|
112 |
|
113 /*! |
|
114 * Inequality operator. |
|
115 */ |
|
116 bool HbFrameBackground::operator!=( const HbFrameBackground &other ) const |
|
117 { |
|
118 if (d->frameGraphicsName != other.d->frameGraphicsName |
|
119 || d->frameGraphicsName.isNull() != other.d->frameGraphicsName.isNull()) { |
|
120 return true; |
|
121 } |
|
122 |
|
123 if (d->type != other.d->type) { |
|
124 return true; |
|
125 } |
|
126 |
|
127 return false; |
|
128 } |
|
129 |
|
130 /*! |
|
131 * Returns true if the frame background has been constructed with the default constructor |
|
132 * and the frame graphics name has not been set. |
|
133 */ |
|
134 bool HbFrameBackground::isNull() const |
|
135 { |
|
136 return d->frameGraphicsName.isNull(); |
|
137 } |
|
138 |
|
139 /*! |
|
140 * Returns the frame graphics name. |
|
141 * \sa HbFrameBackground::setFrameGraphicsName() |
|
142 */ |
|
143 QString HbFrameBackground::frameGraphicsName() const |
|
144 { |
|
145 return d->frameGraphicsName; |
|
146 } |
|
147 |
|
148 /*! |
|
149 * Sets the frame graphics name. See the HbFrameDrawer class description for the file name convention for different frame parts. |
|
150 * \sa HbFrameBackground::frameGraphicsName() |
|
151 */ |
|
152 void HbFrameBackground::setFrameGraphicsName(const QString &frameGraphicsName) |
|
153 { |
|
154 // Remove possible file extension |
|
155 QString nameWithoutExt = frameGraphicsName; |
|
156 int index = nameWithoutExt.lastIndexOf(QChar('.')); |
|
157 if (index>0) { |
|
158 nameWithoutExt.resize(index); |
|
159 } |
|
160 |
|
161 if (d->frameGraphicsName != nameWithoutExt |
|
162 || d->frameGraphicsName.isNull() != nameWithoutExt.isNull()) { |
|
163 d.detach(); |
|
164 d->frameGraphicsName = nameWithoutExt; |
|
165 } |
|
166 } |
|
167 |
|
168 /*! |
|
169 * Returns the frame type. |
|
170 * \sa HbFrameBackground::setFrameType() |
|
171 */ |
|
172 HbFrameDrawer::FrameType HbFrameBackground::frameType() const |
|
173 { |
|
174 return d->type; |
|
175 } |
|
176 |
|
177 /*! |
|
178 * Sets the frame type. |
|
179 * \sa HbFrameBackground::frameType() |
|
180 */ |
|
181 void HbFrameBackground::setFrameType(HbFrameDrawer::FrameType type) |
|
182 { |
|
183 if (d->type != type) { |
|
184 d.detach(); |
|
185 d->type = type; |
|
186 } |
|
187 } |
|
188 |
|
189 /*! |
|
190 * Returns the frame background as a QVariant. |
|
191 */ |
|
192 HbFrameBackground::operator QVariant() const |
|
193 { |
|
194 return QVariant::fromValue(*this); |
|
195 } |
|
196 |
|
197 // End of File |