#include "ProjectionModel.h" #include "Channel.h" #include "Screen.h" #include "Warp.h" #include "RSync.h" #include "GUIControler.h" #include "gui/QProjectorWindow.h" #include using namespace projection; bool QProjectorWindow::m_bInitialized = false; QProjectorWindow::QProjectorWindow(QWidget* pParent, QGLWidget* pSharedWidget, Qt::WFlags flag) : QGLWidget(pParent, pSharedWidget, flag|Qt::Window) { m_pModel = NULL; m_pChannel = NULL; m_blendChannelIndex = 0; resize(640, 480); m_overlayFont.setFamily("Helvetica"); m_overlayFont.setPointSize(64); m_infoFont.setFamily("Helvetica"); m_infoFont.setPointSize(14); setFocusPolicy(Qt::StrongFocus); } QProjectorWindow::~QProjectorWindow() { } void QProjectorWindow::setModel(ProjectionModel* pModel) { m_pModel = pModel; } void QProjectorWindow::setChannel(Channel* pChannel) { m_pChannel = pChannel; updateTitle(); updateGL(); } void QProjectorWindow::updateTitle() { if (m_pChannel) setWindowTitle(m_pChannel->getName() + " - Projector Window"); } void QProjectorWindow::initializeGL() { if (!m_pModel->getRSync()->isServer() && m_bInitialized) { m_bInitialized = true; } glBlendFunc(GL_ONE, GL_ONE); glClearColor(0.0, 0.0, 0.0, 0.0); } void QProjectorWindow::resizeGL(int width, int height) { glViewport(0, 0, width, height); } void QProjectorWindow::paintGL() { m_pModel->setRenderContext(this); if (m_pChannel) { if (m_pModel->getDesignMode() == DESIGN_MODE_DISTORTIONMAP) m_pChannel->draw(CHANNEL_DRAWMODE_DESIGN_DISTORTIONMAP); else m_pChannel->draw(CHANNEL_DRAWMODE_DESIGN_BLENDMAP); if (m_pChannel->getOverlayName()) { QFontMetrics fontMet(m_overlayFont); renderText((width()-fontMet.width(m_pChannel->getName()))/2, (height()+fontMet.height()/2)/2, m_pChannel->getName(), m_overlayFont, 3000); } if (m_pModel->getRSync()->isServer() && m_pModel->getDesignMode() == DESIGN_MODE_BLENDMAP) { glPushAttrib(GL_CURRENT_BIT); glColor4f(1.0f, 0.0f, 0.0f, 1.0f); Channel* pChannel = m_pModel->getChannel(m_blendChannelIndex); if (pChannel) renderText(16, 32, QString("%1 Blend factor : %2").arg(pChannel->getName()).arg(QString::number(m_pChannel->getBlendFactor(pChannel->getName()), 'f', 2)), m_infoFont, 4000); renderText(16, 64, QString("[Space] : Select channel to edit blend factor."), m_infoFont, 4000); renderText(16, 88, QString("[B] : Brighten the selected channel."), m_infoFont, 4000); renderText(16, 112, QString("[D] : Darken the selected channel."), m_infoFont, 4000); glPopAttrib(); } } } void QProjectorWindow::keyReleaseEvent(QKeyEvent* pEvent) { switch (pEvent->key()) { case Qt::Key_Return: if (pEvent->modifiers() & Qt::AltModifier) { if (!isFullScreen()) showFullScreen(); else showNormal(); } break; case Qt::Key_Escape: if (!m_pModel->getRSync()->isServer()) { qApp->closeAllWindows(); return; } else close(); break; case Qt::Key_Space: if (m_pModel) { m_blendChannelIndex++; if (m_blendChannelIndex >= m_pModel->getNumChannels()) m_blendChannelIndex = 0; updateGL(); } break; case Qt::Key_B: if (m_pModel) { Channel* pChannel = m_pModel->getChannel(m_blendChannelIndex); if (pChannel) { float blendFactor = m_pChannel->getBlendFactor(pChannel->getName()); if ((pEvent->modifiers() & Qt::ShiftModifier) || (pEvent->modifiers() & Qt::ControlModifier)) blendFactor += 0.01f; else blendFactor += 0.1f; if (blendFactor > 1.0f) blendFactor = 1.0f; m_pChannel->setBlendFactor(pChannel->getName(), blendFactor); updateGL(); } } break; case Qt::Key_D: if (m_pModel) { Channel* pChannel = m_pModel->getChannel(m_blendChannelIndex); if (pChannel) { float blendFactor = m_pChannel->getBlendFactor(pChannel->getName()); if ((pEvent->modifiers() & Qt::ShiftModifier) || (pEvent->modifiers() & Qt::ControlModifier)) blendFactor -= 0.01f; else blendFactor -= 0.1f; if (blendFactor < 0.0f) blendFactor = 0.0f; m_pChannel->setBlendFactor(pChannel->getName(), blendFactor); updateGL(); } } break; } if (m_pModel->getRSync()->isServer()) { m_pModel->getGUI()->processChannelKeyEvent(m_pChannel, pEvent); } } void QProjectorWindow::mousePressEvent(QMouseEvent* pEvent) { if (m_pChannel) { if (m_pChannel->getCurrentWarp()->pick(pEvent->x(), pEvent->y())) updateGL(); } } void QProjectorWindow::mouseMoveEvent(QMouseEvent* pEvent) { if (pEvent->buttons() == Qt::LeftButton && m_pChannel) { if (m_pChannel->getCurrentWarp()->drag(pEvent->x(), pEvent->y())) { m_pChannel->updateData(); updateGL(); } } } void QProjectorWindow::wheelEvent(QWheelEvent* pEvent) { if (m_pChannel) { if (pEvent->delta() > 0) m_pChannel->getCurrentWarp()->setZoom(m_pChannel->getCurrentWarp()->getZoom()/1.2f); else m_pChannel->getCurrentWarp()->setZoom(m_pChannel->getCurrentWarp()->getZoom()*1.2f); updateGL(); } } void QProjectorWindow::closeEvent(QCloseEvent* pEvent) { if (m_pChannel) m_pChannel->clearWarpBuffer(); QGLWidget::closeEvent(pEvent); } void QProjectorWindow::initFromDOMElement(const QDomElement& element) { bool bShowFullScreen = false; if (!element.isNull()) { int posX = 16; int posY = 16; int width = 0; int height = 0; QDomElement geom = element.firstChildElement("Geometry"); posX = geom.attribute("posX").toInt(); posY = geom.attribute("posY").toInt(); width = geom.attribute("width").toInt(); height = geom.attribute("height").toInt(); move(posX, posY); if (width!=0 && height!=0) resize(width, height); bShowFullScreen = (geom.attribute("fullScreen").toLower() == "true"); } if (!element.isNull() && element.attribute("show")=="true") { if (bShowFullScreen) showFullScreen(); else showNormal(); } else hide(); } QDomElement QProjectorWindow::domElement(QDomDocument& doc) const { QDomElement de = doc.createElement("ProjectorWindow"); de.setAttribute("show", isVisible()?"true":"false"); QDomElement geom = doc.createElement("Geometry"); geom.setAttribute("fullScreen", isFullScreen()?"true":"false"); geom.setAttribute("posX", x()); geom.setAttribute("posY", y()); geom.setAttribute("width", width()); geom.setAttribute("height", height()); de.appendChild(geom); return de; }