tools/designer/src/lib/uilib/resourcebuilder.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Designer of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    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 
       
    50 QT_BEGIN_NAMESPACE
       
    51 
       
    52 #ifdef QFORMINTERNAL_NAMESPACE
       
    53 namespace QFormInternal {
       
    54 #endif
       
    55 
       
    56 QResourceBuilder::QResourceBuilder()
       
    57 {
       
    58 
       
    59 }
       
    60 
       
    61 QResourceBuilder::~QResourceBuilder()
       
    62 {
       
    63 
       
    64 }
       
    65 
       
    66 int 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 
       
    88 QVariant 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.addFile(QFileInfo(workingDirectory, dpi->elementNormalOff()->text()).absoluteFilePath(), QSize(), QIcon::Normal, QIcon::Off);
       
   102                 if (flags & NormalOn)
       
   103                     icon.addFile(QFileInfo(workingDirectory, dpi->elementNormalOn()->text()).absoluteFilePath(), QSize(), QIcon::Normal, QIcon::On);
       
   104                 if (flags & DisabledOff)
       
   105                     icon.addFile(QFileInfo(workingDirectory, dpi->elementDisabledOff()->text()).absoluteFilePath(), QSize(), QIcon::Disabled, QIcon::Off);
       
   106                 if (flags & DisabledOn)
       
   107                     icon.addFile(QFileInfo(workingDirectory, dpi->elementDisabledOn()->text()).absoluteFilePath(), QSize(), QIcon::Disabled, QIcon::On);
       
   108                 if (flags & ActiveOff)
       
   109                     icon.addFile(QFileInfo(workingDirectory, dpi->elementActiveOff()->text()).absoluteFilePath(), QSize(), QIcon::Active, QIcon::Off);
       
   110                 if (flags & ActiveOn)
       
   111                     icon.addFile(QFileInfo(workingDirectory, dpi->elementActiveOn()->text()).absoluteFilePath(), QSize(), QIcon::Active, QIcon::On);
       
   112                 if (flags & SelectedOff)
       
   113                     icon.addFile(QFileInfo(workingDirectory, dpi->elementSelectedOff()->text()).absoluteFilePath(), QSize(), QIcon::Selected, QIcon::Off);
       
   114                 if (flags & SelectedOn)
       
   115                     icon.addFile(QFileInfo(workingDirectory, dpi->elementSelectedOn()->text()).absoluteFilePath(), QSize(), 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 
       
   129 QVariant QResourceBuilder::toNativeValue(const QVariant &value) const
       
   130 {
       
   131     return value;
       
   132 }
       
   133 
       
   134 DomProperty *QResourceBuilder::saveResource(const QDir &workingDirectory, const QVariant &value) const
       
   135 {
       
   136     Q_UNUSED(workingDirectory)
       
   137     Q_UNUSED(value)
       
   138     return 0;
       
   139 }
       
   140 
       
   141 bool 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 
       
   153 bool 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 
       
   169 QT_END_NAMESPACE