src/hbcore/decorators/hbbatteryindicator.cpp
changeset 30 80e4d18b72f5
parent 28 b7da29130b0e
equal deleted inserted replaced
28:b7da29130b0e 30:80e4d18b72f5
   126 void HbBatteryIndicator::delayedConstruction()
   126 void HbBatteryIndicator::delayedConstruction()
   127 {
   127 {
   128 
   128 
   129 }
   129 }
   130 
   130 
       
   131 int HbBatteryIndicator::level() const
       
   132 { 
       
   133     Q_D(const HbBatteryIndicator);
       
   134     return d->mLevelPercent;
       
   135 }
       
   136 
       
   137 bool HbBatteryIndicator::isCharging() const
       
   138 {
       
   139     Q_D(const HbBatteryIndicator);
       
   140     // Cannot use mChargingOn only because this function must work
       
   141     // reliably even when called while being in setLevel(). On the
       
   142     // other hand the timer is stopped while being in sleep mode. So
       
   143     // check both.
       
   144     return d->mChargingTimer.isActive() || d->mChargingOn;
       
   145 }
       
   146 
       
   147 void HbBatteryIndicator::chargingEvent(bool start)
       
   148 {
       
   149     Q_D(HbBatteryIndicator);
       
   150     if (start) {
       
   151         if (d->mChargingOn) {
       
   152             d->mChargingTimer.start(250, this);
       
   153         }
       
   154     } else {
       
   155         d->mChargingTimer.stop();
       
   156     }
       
   157 }
       
   158 
   131 void HbBatteryIndicator::createPrimitives()
   159 void HbBatteryIndicator::createPrimitives()
   132 {
   160 {
   133     Q_D(HbBatteryIndicator);
   161     Q_D(HbBatteryIndicator);
   134     d->mBatteryIcon = HbStylePrivate::createPrimitive(HbStylePrivate::P_BatteryIndicator_icon, this);
   162     d->mBatteryIcon = HbStylePrivate::createPrimitive(HbStylePrivate::P_BatteryIndicator_icon, this);
   135     d->mBatteryBackgroundIcon = HbStylePrivate::createPrimitive(HbStylePrivate::P_BatteryLevel_background, this);
   163     d->mBatteryBackgroundIcon = HbStylePrivate::createPrimitive(HbStylePrivate::P_BatteryLevel_background, this);
   142     HbStyleOptionBatteryIndicator option;
   170     HbStyleOptionBatteryIndicator option;
   143     initStyleOption(&option);
   171     initStyleOption(&option);
   144     HbStylePrivate::updatePrimitive(d->mBatteryIcon, HbStylePrivate::P_BatteryIndicator_icon, &option);
   172     HbStylePrivate::updatePrimitive(d->mBatteryIcon, HbStylePrivate::P_BatteryIndicator_icon, &option);
   145     HbStylePrivate::updatePrimitive(d->mBatteryBackgroundIcon, HbStylePrivate::P_BatteryLevel_background, &option);
   173     HbStylePrivate::updatePrimitive(d->mBatteryBackgroundIcon, HbStylePrivate::P_BatteryLevel_background, &option);
   146     HbStylePrivate::updatePrimitive(d->mBatteryLevelIcon, HbStylePrivate::P_BatteryLevel_icon, &option);
   174     HbStylePrivate::updatePrimitive(d->mBatteryLevelIcon, HbStylePrivate::P_BatteryLevel_icon, &option);
   147 }
       
   148 
       
   149 int HbBatteryIndicator::level() const
       
   150 { 
       
   151     Q_D(const HbBatteryIndicator);
       
   152     return d->mLevelPercent;
       
   153 }
   175 }
   154 
   176 
   155 /*  
   177 /*  
   156     set battery strength level. \a level value should be between 0 and 100
   178     set battery strength level. \a level value should be between 0 and 100
   157     \a level value is ignored if out of range.
   179     \a level value is ignored if out of range.
   220         }
   242         }
   221     }
   243     }
   222     option->batteryValue = d->mLevelPercent;
   244     option->batteryValue = d->mLevelPercent;
   223 }
   245 }
   224 
   246 
   225 bool HbBatteryIndicator::isCharging() const
       
   226 {
       
   227     Q_D(const HbBatteryIndicator);
       
   228     // Cannot use mChargingOn only because this function must work
       
   229     // reliably even when called while being in setLevel(). On the
       
   230     // other hand the timer is stopped while being in sleep mode. So
       
   231     // check both.
       
   232     return d->mChargingTimer.isActive() || d->mChargingOn;
       
   233 }
       
   234 
       
   235 /*!
   247 /*!
   236     \reimp
   248     \reimp
   237 */
   249 */
   238 bool HbBatteryIndicator::event(QEvent *e)
   250 bool HbBatteryIndicator::event(QEvent *e)
   239 {
   251 {