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; }
bool MultiLayer::eventFilter(QObject *object, QEvent *e) { if ( object != (QObject *)canvas) return FALSE; switch(e->type()) { case QEvent::MouseButtonPress: { const QMouseEvent *me = (const QMouseEvent *)e; if (me->button()==QMouseEvent::LeftButton && addTextOn) addTextLayer(me->pos()); return TRUE; } case QEvent::Resize: { const QResizeEvent *re = (const QResizeEvent *)e; resizeLayers(re); } default: ; } return QObject::eventFilter(object, e); }
bool MultiLayer::eventFilter(QObject *object, QEvent *e) { if (e->type() == QEvent::MouseButtonPress && object == (QObject *)canvas) { const QMouseEvent *me = (const QMouseEvent *)e; if (me->button() == Qt::LeftButton && addTextOn) addTextLayer(me->pos()); return false; } else if (e->type() == QEvent::Resize && object == (QObject *)canvas) { resizeLayers((const QResizeEvent *)e); } else if (e->type() == QEvent::ContextMenu && object == titleBar) { emit showTitleBarMenu(); ((QContextMenuEvent *)e)->accept(); return true; } return MyWidget::eventFilter(object, e); }