void VCClock::mousePressEvent(QMouseEvent *e) { if (mode() == Doc::Design) { VCWidget::mousePressEvent(e); return; } if (e->button() == Qt::RightButton) { if (clockType() == Stopwatch) m_currentTime = 0; else if (clockType() == Countdown) m_currentTime = m_targetTime; update(); } else if (e->button() == Qt::LeftButton) { if (clockType() == Stopwatch || clockType() == Countdown) m_isPaused = !m_isPaused; update(); } VCWidget::mousePressEvent(e); }
void VCClock::paintEvent(QPaintEvent* e) { QPainter painter(this); if (clockType() == Clock) { QDateTime currTime = QDateTime::currentDateTime(); style()->drawItemText(&painter, rect(), Qt::AlignCenter | Qt::TextWordWrap, palette(), true, currTime.time().toString(), foregroundRole()); } else { quint32 secTime = m_currentTime; uint h, m; h = secTime / 3600; secTime -= (h * 3600); m = secTime / 60; secTime -= (m * 60); style()->drawItemText(&painter, rect(), Qt::AlignCenter | Qt::TextWordWrap, palette(), true, QString("%1:%2:%3").arg(h, 2, 10, QChar('0')) .arg(m, 2, 10, QChar('0')).arg(secTime, 2, 10, QChar('0')), foregroundRole()); } painter.end(); VCWidget::paintEvent(e); }
bool VCClock::saveXML(QDomDocument* doc, QDomElement* vc_root) { QDomElement root; Q_ASSERT(doc != NULL); Q_ASSERT(vc_root != NULL); /* VC Clock entry */ root = doc->createElement(KXMLQLCVCClock); vc_root->appendChild(root); /* Type */ ClockType type = clockType(); root.setAttribute(KXMLQLCVCClockType, typeToString(type)); if (type == Countdown) { root.setAttribute(KXMLQLCVCClockHours, getHours()); root.setAttribute(KXMLQLCVCClockMinutes, getMinutes()); root.setAttribute(KXMLQLCVCClockSeconds, getSeconds()); } saveXMLCommon(doc, &root); /* Window state */ saveXMLWindowState(doc, &root); /* Appearance */ saveXMLAppearance(doc, &root); foreach(VCClockSchedule sch, schedules()) sch.saveXML(doc, &root); return true; }
void AVClock::start() { qDebug("AVClock started!!!!!!!!"); timer.start(); correction_schedule_timer.stop(); // TODO: for all clock type if (clockType() != AudioClock) { t = QDateTime::currentMSecsSinceEpoch(); correction_schedule_timer.start(kCorrectionInterval*1000, this); } emit started(); }
void AVClock::updateExternalClock(qint64 msecs) { if (clock_type == AudioClock) return; qDebug("External clock change: %f ==> %f", value(), double(msecs) * kThousandth); pts_ = double(msecs) * kThousandth; //can not use msec/1000. timer.restart(); last_pts = pts_; t = QDateTime::currentMSecsSinceEpoch(); if (clockType() == VideoClock) pts_v = pts_; }
void AVClock::restartCorrectionTimer() { nb_restarted = 0; avg_err = 0; correction_schedule_timer.stop(); if (clockType() == AudioClock) // TODO: for all clock type return; // parameters are reset. do not start correction timer if not running if (m_state != kRunning) return; // timer is always started in AVClock::start() if (!timer.isValid()) return; t = QDateTime::currentMSecsSinceEpoch(); correction_schedule_timer.start(kCorrectionInterval*1000, this); }
void AVClock::timerEvent(QTimerEvent *event) { Q_ASSERT_X(clockType() != AudioClock, "AVClock::timerEvent", "Internal error. AudioClock can not call this"); if (event->timerId() != correction_schedule_timer.timerId()) return; if (isPaused()) return; const double delta_pts = (value() - last_pts)/speed(); //const double err = double(correction_timer.restart()) * kThousandth - delta_pts; const qint64 now = QDateTime::currentMSecsSinceEpoch(); const double err = double(now - t) * kThousandth - delta_pts; t = now; // FIXME: avfoundation camera error is large (about -0.6s) if (qAbs(err*10.0) < kCorrectionInterval || clock_type == VideoClock) { avg_err += err/(nb_restarted+1); } //qDebug("correction timer event. error = %f, avg_err=%f, nb_restarted=%d", err, avg_err, nb_restarted); last_pts = value(); nb_restarted = 0; }
bool VCClock::loadXML(const QDomElement* root) { Q_ASSERT(root != NULL); if (root->tagName() != KXMLQLCVCClock) { qWarning() << Q_FUNC_INFO << "Clock node not found"; return false; } if (root->hasAttribute(KXMLQLCVCClockType)) { setClockType(stringToType(root->attribute(KXMLQLCVCClockType))); if (clockType() == Countdown) { int h = 0, m = 0, s = 0; if (root->hasAttribute(KXMLQLCVCClockHours)) h = root->attribute(KXMLQLCVCClockHours).toInt(); if (root->hasAttribute(KXMLQLCVCClockMinutes)) m = root->attribute(KXMLQLCVCClockMinutes).toInt(); if (root->hasAttribute(KXMLQLCVCClockSeconds)) s = root->attribute(KXMLQLCVCClockSeconds).toInt(); setCountdown(h, m ,s); } } /* Widget commons */ loadXMLCommon(root); /* Children */ QDomNode node = root->firstChild(); while (node.isNull() == false) { QDomElement tag = node.toElement(); if (tag.tagName() == KXMLQLCWindowState) { int x = 0, y = 0, w = 0, h = 0; bool visible = false; loadXMLWindowState(&tag, &x, &y, &w, &h, &visible); setGeometry(x, y, w, h); } else if (tag.tagName() == KXMLQLCVCWidgetAppearance) { loadXMLAppearance(&tag); } else if (tag.tagName() == KXMLQLCVCClockSchedule) { VCClockSchedule sch; if (sch.loadXML(&tag) == true) addSchedule(sch); } else { qWarning() << Q_FUNC_INFO << "Unknown clock tag:" << tag.tagName(); } node = node.nextSibling(); } return true; }