homescreenapp/widgetplugins/hsclockwidgetplugin/styles/hsanalogclockstyleplugin/src/hsanalogclockstyleplugin.cpp
changeset 39 4e8ebe173323
parent 36 cdae8c6c3876
child 42 517f4fb5ec74
child 46 23b5d6a29cce
equal deleted inserted replaced
36:cdae8c6c3876 39:4e8ebe173323
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description:  Analog clock style plugin.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "hsanalogclockstyleplugin.h"
       
    19 
       
    20 #include <hbstyle.h>
       
    21 #include <hbiconitem.h>
       
    22 
       
    23 #include "hsanalogclockstyleoption.h"
       
    24 
       
    25 /*!
       
    26     \class HsAnalogClockStylePlugin
       
    27     \brief Screensaver analog clock style plugin.
       
    28  */
       
    29 
       
    30 /*!
       
    31     @copydoc HbStyleInterface::primitiveCount()
       
    32  */
       
    33 int HsAnalogClockStylePlugin::primitiveCount() const
       
    34 {
       
    35     return 3;
       
    36 }
       
    37 
       
    38 /*!
       
    39     @copydoc HbStyleInterface::createPrimitive()
       
    40  */
       
    41 QGraphicsItem* HsAnalogClockStylePlugin::createPrimitive(HbStyle::Primitive primitive, QGraphicsItem *parent) const
       
    42 {
       
    43     if (primitive == backgroundItemIndex) {
       
    44         HbIconItem *item = new HbIconItem("qtg_graf_clock_day_bg", parent);
       
    45         HbStyle::setItemName(item, "clock_background");
       
    46         return item;
       
    47     }
       
    48     else if (primitive == hourHandItemIndex) {
       
    49         HbIconItem *item = new HbIconItem("qtg_graf_clock_day_hour", parent);
       
    50         HbStyle::setItemName(item, "clock_hour_hand");
       
    51         return item;
       
    52     }
       
    53     else if (primitive == minuteHandItemIndex) {
       
    54         HbIconItem *item = new HbIconItem("qtg_graf_clock_day_min", parent);
       
    55         HbStyle::setItemName(item, "clock_minute_hand");
       
    56         return item;
       
    57     }
       
    58     return 0;
       
    59 }
       
    60 
       
    61 /*!
       
    62     @copydoc HbStyleInterface::updatePrimitive()
       
    63  */
       
    64 void HsAnalogClockStylePlugin::updatePrimitive(QGraphicsItem *item, HbStyle::Primitive primitive, const QStyleOption *option ) const
       
    65 {
       
    66     const HsAnalogClockStyleOption *opt = qstyleoption_cast<const HsAnalogClockStyleOption *>(option);
       
    67     if (!opt || !item) {
       
    68         return;
       
    69     }
       
    70 
       
    71     HbIconItem *iconItem = static_cast<HbIconItem *>(item);
       
    72     
       
    73     // these should work but don't
       
    74     //int x = iconItem->iconItemSize().width()/2;
       
    75     //int y = iconItem->iconItemSize().height()/2;
       
    76 
       
    77     // workaround
       
    78     int x = iconItem->preferredSize().width()/2;
       
    79     int y = iconItem->preferredSize().height()/2;
       
    80 
       
    81     if (primitive == hourHandItemIndex) {
       
    82         iconItem->setTransform(QTransform().translate(x, y).rotate(opt->mH).translate(-x, -y));
       
    83     }
       
    84     else if (primitive == minuteHandItemIndex) {
       
    85         iconItem->setTransform(QTransform().translate(x, y).rotate(opt->mM).translate(-x, -y));
       
    86     }
       
    87 }
       
    88 
       
    89 /*!
       
    90     @copydoc HbStyleInterface::layoutPath()
       
    91  */
       
    92 QString HsAnalogClockStylePlugin::layoutPath() const
       
    93 {
       
    94     return QString(":/");
       
    95 }
       
    96 
       
    97 #ifndef COVERAGE_MEASUREMENT
       
    98 Q_EXPORT_PLUGIN2(hsanalogclockstyleplugin, HsAnalogClockStylePlugin)
       
    99 #endif //COVERAGE_MEASUREMENT