C

Qt Quick Ultralite Watch Demo

/****************************************************************************** ** ** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Ultralite module. ** ** $QT_BEGIN_LICENSE:COMM$ ** ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** $QT_END_LICENSE$ ** ******************************************************************************/
#include "WatchModel.h" #include <ctime> namespace { const int ONE_SECOND_ANGLE = 6; const int ONE_MINUTE_ANGLE = 6; const int ONE_HOUR_ANGLE = 30; const int MINUTES_PER_HOUR = 60; const int DEFAULT_VALUE = 0; int CalculateSecondsAngle(const tm *timeStruct) { return timeStruct->tm_sec * ONE_SECOND_ANGLE; } int CalculateMinutesAngle(const tm *timeStruct) { return timeStruct->tm_min * ONE_MINUTE_ANGLE; } int CalculateHoursAngle(const tm *timeStruct) { return timeStruct->tm_hour * ONE_HOUR_ANGLE + (ONE_HOUR_ANGLE * timeStruct->tm_min / MINUTES_PER_HOUR); } } // namespace WatchModel::WatchModel() : SecondAngle(DEFAULT_VALUE) , MinuteAngle(DEFAULT_VALUE) , HourAngle(DEFAULT_VALUE) , DayOfWeek(DEFAULT_VALUE) { update(); } void WatchModel::update() { const time_t currentTime = time(NULL); const tm *currentTimeDateStruct = gmtime(&currentTime); MinuteAngle.setValue(CalculateMinutesAngle(currentTimeDateStruct)); HourAngle.setValue(CalculateHoursAngle(currentTimeDateStruct)); SecondAngle.setValue(CalculateSecondsAngle(currentTimeDateStruct)); DayOfWeek.setValue(currentTimeDateStruct->tm_wday); }