void Transcribe::connectVirtualKeyboard() { if (qApp->inputMethod()->isVisible()) { // The virtual keyboard is visible. The only way to detect typing is by // observing changes in the text area, the KeyCatcher doesn't respond to // it. connect(m_text_area, SIGNAL(textChanged()), &m_keeper, SLOT(keyTyped())); } else { // The virtual keyboard is not visible, so there's a physical keyboard that // is intercepted by the KeyCatcher and listening to text changes as well // would produce double signals. // Listening to the physical keyboard has a bit broader scope than the // virtual keyboard since it also responds to keyboard navigation and // such. disconnect(m_text_area, SIGNAL(textChanged()), &m_keeper, SLOT(keyTyped())); } }
void Transcribe::guiReady(QObject* root) { m_main_window = qobject_cast<QWindow*>(root); m_text_area = m_main_window->findChild<QObject*>("text_area"); // Set the icon, which, strangely enough, cannot be done from QML m_main_window->setIcon(QIcon("://window_icon")); #ifndef Q_OS_ANDROID // Restore window state QSettings settings; settings.beginGroup(CFG_GROUP_SCREEN); if (settings.value(CFG_SCREEN_IS_MAXIMIZED, false).toBool()) { m_main_window->setVisibility(QWindow::Maximized); } else { m_main_window->resize(settings.value(CFG_SCREEN_SIZE, QSize(640, 480)).toSize()); m_main_window->setPosition(settings.value(CFG_SCREEN_POS, QPoint(200, 200)).toPoint()); settings.endGroup();\ } #endif // Install the key filter and connect its signals KeyCatcher* catcher = new KeyCatcher(root); connect(catcher, SIGNAL(keyTyped()), &m_keeper, SLOT(keyTyped())); connect(catcher, SIGNAL(saveFile()), this, SLOT(saveText())); connect(catcher, SIGNAL(seekAudio(int)), m_player.get(), SLOT(skipSeconds(int))); connect(catcher, SIGNAL(togglePlayPause()), m_player.get(), SLOT(togglePlayPause())); connect(catcher, SIGNAL(togglePlayPause(bool)), m_player.get(), SLOT(togglePlayPause(bool))); connect(catcher, SIGNAL(boost(bool)), m_player.get(), SLOT(boost(bool))); root->installEventFilter(catcher); #ifdef Q_OS_ANDROID // On Android, we might connect the signals when using the virtual keyboard // in addition to the signals from the physical keyboard. connect(qApp->inputMethod(), SIGNAL(visibleChanged()), this, SLOT(connectVirtualKeyboard())); connectVirtualKeyboard(); #endif // Connect GUI events to their callbacks connect(m_main_window, SIGNAL(audioPositionChanged(int)), m_player.get(), SLOT(setPosition(int))); connect(m_main_window, SIGNAL(playingStateChanged(bool)), m_player.get(), SLOT(togglePlayPause(bool))); connect(m_main_window, SIGNAL(seekAudio(int)), m_player.get(), SLOT(skipSeconds(int))); connect(m_main_window, SIGNAL(boostAudio(bool)), m_player.get(), SLOT(boost(bool))); connect(m_main_window, SIGNAL(saveText()), this, SLOT(saveText())); #ifdef Q_OS_ANDROID connect(m_main_window, SIGNAL(shareText()), this, SLOT(shareText())); connect(m_main_window, SIGNAL(deleteText()), this, SLOT(deleteText())); #endif connect(m_main_window, SIGNAL(pickFiles()), this, SLOT(pickFiles())); connect(m_main_window, SIGNAL(historySelected(int)), this, SLOT(restoreHistory(int))); connect(m_main_window, SIGNAL(signalQuit()), this, SLOT(close())); connect(m_main_window, SIGNAL(numWordsDirty()), this, SLOT(countWords())); }
void EventRecorder::redisplay(double t, double dt) { if (isRecording) { recordedEvents.push_back(Event(t, dt, TerrainNode::nextGroundHeightAtCamera)); } else if (isPlaying) { ostringstream s; bool replay = true; isPlaying = false; while (replay && lastPlayed < recordedEvents.size()) { Event e = recordedEvents[lastPlayed++]; switch (e.kind) { case Event::DISPLAY: t = e.display.t; dt = e.display.dt; TerrainNode::nextGroundHeightAtCamera = e.display.groundHeight; replay = false; break; case Event::MOUSE: mouseClick((button) e.e.arg1, (state) e.e.arg2, (modifier) e.e.m, e.e.arg3, e.e.arg4); savedX = e.e.arg3; savedY = e.e.arg4; break; case Event::MOTION: mouseMotion(e.e.arg1, e.e.arg2); savedX = e.e.arg1; savedY = e.e.arg2; break; case Event::PASSIVEMOTION: mousePassiveMotion(e.e.arg1, e.e.arg2); savedX = e.e.arg1; savedY = e.e.arg2; break; case Event::WHEEL: mouseWheel((wheel) e.e.arg1, (modifier) e.e.m, e.e.arg2, e.e.arg3); savedX = e.e.arg2; savedY = e.e.arg3; break; case Event::KEYBOARD: if (e.e.arg4 == 0) { keyTyped(e.e.arg1, (modifier) e.e.m, e.e.arg2, e.e.arg3); if (e.e.arg1 == 27) { ::exit(0); } } else { keyReleased(e.e.arg1, (modifier) e.e.m, e.e.arg2, e.e.arg3); } break; case Event::SPECIAL: if (e.e.arg4 == 0) { specialKey((key) e.e.arg1, (modifier) e.e.m, e.e.arg2, e.e.arg3); } else { specialKeyReleased((key) e.e.arg1, (modifier) e.e.m, e.e.arg2, e.e.arg3); } break; } } isPlaying = lastPlayed < recordedEvents.size(); } if (next != NULL) { next->redisplay(t, dt); } if (isPlaying) { ptr<FrameBuffer> fb = FrameBuffer::getDefault(); vec4<GLint> vp = fb->getViewport(); fb->setBlend(true, ADD, SRC_ALPHA, ONE_MINUS_SRC_ALPHA, ADD, ZERO, ONE); fb->setColorMask(true, true, true, false); fb->setDepthMask(false); fb->setStencilMask(0, 0); correctU->set(vec3f(0.f, 0.f, 1.f)); rescaleU->set(vec4f(2.0f * (float)(savedX + 0.5f * cursW) / vp.z - 1.0f, 2.0f * (float)(vp.w - savedY - 0.5f * cursH) / vp.w - 1.0f, cursW / (float)vp.z, cursH / (float)vp.w)); cursorSamplerU->set(cursor); fb->drawQuad(cursorProg); fb->setBlend(false); fb->setColorMask(true, true, true, true); fb->setDepthMask(true); fb->setStencilMask(0xFFFFFFFF,0xFFFFFFFF); } if (isPlaying && saveVideo) { int frameCount = 0; if (lastSavedEvent >= 0) { double prevTime = recordedEvents[lastSavedEvent].display.t; double curTime = recordedEvents[lastPlayed - 1].display.t; assert(recordedEvents[lastSavedEvent].kind == Event::DISPLAY && prevTime > 0.0); assert(recordedEvents[lastPlayed - 1].kind == Event::DISPLAY && curTime > 0.0); frameCount = int(floor(curTime / 40000.0) - floor(prevTime / 40000.0)); } // if the delay between two recorded frames is more than 1/25 of a second // the first one must be saved several times in the video to keep a video // framerate of 25 frames per second. for (int i = 0; i < frameCount; ++i) { char name[256]; sprintf(name, frames, lastSavedFrame++); saveFrame(name); } lastSavedEvent = lastPlayed - 1; } }