myTimeLayer *addTimeLayer(int align, int font_size, int y, GColor c) { myTimeLayer *mtl; mtl = (myTimeLayer *)malloc(sizeof(myTimeLayer)); Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); int x1; int x2; int x3; int col_size = (bounds.size.w) / 12; switch(align) { case 2: x1 = 4 * col_size; x2 = 10 * col_size; x3 = 12 * col_size; break; case 1: x1 = 0 * col_size; x2 = 4 * col_size; x3 = 6 * col_size; break; default: x1 = 1 * col_size; x2 = 7 * col_size; x3 = 11 * col_size; break; } mtl->big_digits = addTextLayer(GRect(x1, y, x2-x1, 20),GTextAlignmentRight,font_size,y,c," --:-- "); mtl->exp_digits = addTextLayer(GRect(x2, y, x3-x2, 10),GTextAlignmentLeft,font_size-2,y,c,"--"); setTimeColor(mtl,c); return mtl; }
WallClock::WallClock(QWidget *parent) : WidgetWithBackground(parent) { m_timer = new QTimer(this); m_timer->setInterval(1000); connect(m_timer, SIGNAL(timeout()), this, SLOT(updateTime())); setDigitOffset(75); setDateOffset(0); setTimeOffset(0); // -12 setDayOffset(0); // 9 setDigitColor(QColor(0,0,0)); setDateColor(QColor(0,0,0)); setTimeColor(QColor(0,0,192)); setDayColor(QColor(0,96,0)); m_digitFont.setPointSize(23); m_dateFont.setPointSize(21); m_timeFont.setPointSize(30); m_dayFont.setPointSize(16); // QWidget setSizePolicy (QSizePolicy::Expanding, QSizePolicy::Expanding); setWindowTitle(tr("Analog Clock")); resize(220, 220); m_dateTime = QDateTime::currentDateTime(); setShowCurrentDateTime(true); }