source: trunk/tools/designer/src/lib/uilib/resourcebuilder.cpp@ 5

Last change on this file since 5 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 6.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the Qt Designer of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "resourcebuilder_p.h"
43#include "ui4_p.h"
44#include <QtCore/QVariant>
45#include <QtCore/QFileInfo>
46#include <QtCore/QDir>
47#include <QtGui/QPixmap>
48#include <QtGui/QIcon>
49
50QT_BEGIN_NAMESPACE
51
52#ifdef QFORMINTERNAL_NAMESPACE
53namespace QFormInternal {
54#endif
55
56QResourceBuilder::QResourceBuilder()
57{
58
59}
60
61QResourceBuilder::~QResourceBuilder()
62{
63
64}
65
66int QResourceBuilder::iconStateFlags(const DomResourceIcon *dpi)
67{
68 int rc = 0;
69 if (dpi->hasElementNormalOff())
70 rc |= NormalOff;
71 if (dpi->hasElementNormalOn())
72 rc |= NormalOn;
73 if (dpi->hasElementDisabledOff())
74 rc |= DisabledOff;
75 if (dpi->hasElementDisabledOn())
76 rc |= DisabledOn;
77 if (dpi->hasElementActiveOff())
78 rc |= ActiveOff;
79 if (dpi->hasElementActiveOn())
80 rc |= ActiveOn;
81 if (dpi->hasElementSelectedOff())
82 rc |= SelectedOff;
83 if (dpi->hasElementSelectedOn())
84 rc |= SelectedOn;
85 return rc;
86}
87
88QVariant QResourceBuilder::loadResource(const QDir &workingDirectory, const DomProperty *property) const
89{
90 switch (property->kind()) {
91 case DomProperty::Pixmap: {
92 const DomResourcePixmap *dpx = property->elementPixmap();
93 QPixmap pixmap(QFileInfo(workingDirectory, dpx->text()).absoluteFilePath());
94 return qVariantFromValue(pixmap);
95 }
96 case DomProperty::IconSet: {
97 const DomResourceIcon *dpi = property->elementIconSet();
98 if (const int flags = iconStateFlags(dpi)) { // new, post 4.4 format
99 QIcon icon;
100 if (flags & NormalOff)
101 icon.addPixmap(QFileInfo(workingDirectory, dpi->elementNormalOff()->text()).absoluteFilePath(), QIcon::Normal, QIcon::Off);
102 if (flags & NormalOn)
103 icon.addPixmap(QFileInfo(workingDirectory, dpi->elementNormalOn()->text()).absoluteFilePath(), QIcon::Normal, QIcon::On);
104 if (flags & DisabledOff)
105 icon.addPixmap(QFileInfo(workingDirectory, dpi->elementDisabledOff()->text()).absoluteFilePath(), QIcon::Disabled, QIcon::Off);
106 if (flags & DisabledOn)
107 icon.addPixmap(QFileInfo(workingDirectory, dpi->elementDisabledOn()->text()).absoluteFilePath(), QIcon::Disabled, QIcon::On);
108 if (flags & ActiveOff)
109 icon.addPixmap(QFileInfo(workingDirectory, dpi->elementActiveOff()->text()).absoluteFilePath(), QIcon::Active, QIcon::Off);
110 if (flags & ActiveOn)
111 icon.addPixmap(QFileInfo(workingDirectory, dpi->elementActiveOn()->text()).absoluteFilePath(), QIcon::Active, QIcon::On);
112 if (flags & SelectedOff)
113 icon.addPixmap(QFileInfo(workingDirectory, dpi->elementSelectedOff()->text()).absoluteFilePath(), QIcon::Selected, QIcon::Off);
114 if (flags & SelectedOn)
115 icon.addPixmap(QFileInfo(workingDirectory, dpi->elementSelectedOn()->text()).absoluteFilePath(), QIcon::Selected, QIcon::On);
116 return qVariantFromValue(icon);
117 } else { // 4.3 legacy
118 const QIcon icon(QFileInfo(workingDirectory, dpi->text()).absoluteFilePath());
119 return qVariantFromValue(icon);
120 }
121 }
122 break;
123 default:
124 break;
125 }
126 return QVariant();
127}
128
129QVariant QResourceBuilder::toNativeValue(const QVariant &value) const
130{
131 return value;
132}
133
134DomProperty *QResourceBuilder::saveResource(const QDir &workingDirectory, const QVariant &value) const
135{
136 Q_UNUSED(workingDirectory)
137 Q_UNUSED(value)
138 return 0;
139}
140
141bool QResourceBuilder::isResourceProperty(const DomProperty *p) const
142{
143 switch (p->kind()) {
144 case DomProperty::Pixmap:
145 case DomProperty::IconSet:
146 return true;
147 default:
148 break;
149 }
150 return false;
151}
152
153bool QResourceBuilder::isResourceType(const QVariant &value) const
154{
155 switch (value.type()) {
156 case QVariant::Pixmap:
157 case QVariant::Icon:
158 return true;
159 default:
160 break;
161 }
162 return false;
163}
164
165#ifdef QFORMINTERNAL_NAMESPACE
166} // namespace QFormInternal
167#endif
168
169QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.