shun-iwasawa 31accf
#include "stopmotionlight.h"
shun-iwasawa 31accf
shun-iwasawa 31accf
#include "tenv.h"
shun-iwasawa 31accf
#include "stopmotion.h"
shun-iwasawa 31accf
shun-iwasawa 31accf
#include <qdialog></qdialog>
shun-iwasawa 31accf
#include <qapplication></qapplication>
shun-iwasawa 31accf
#include <qdesktopwidget></qdesktopwidget>
shun-iwasawa 31accf
#include <qwindow></qwindow>
shun-iwasawa 31accf
shun-iwasawa 31accf
TEnv::IntVar StopMotionBlackCapture("StopMotionBlackCapture", 0);
shun-iwasawa 31accf
shun-iwasawa 31accf
//=============================================================================
shun-iwasawa 31accf
//=============================================================================
shun-iwasawa 31accf
shun-iwasawa 31accf
StopMotionLight::StopMotionLight() {
shun-iwasawa 31accf
  m_blackCapture = StopMotionBlackCapture;
shun-iwasawa 31accf
shun-iwasawa 31accf
  m_fullScreen1 = new QDialog();
shun-iwasawa 31accf
  m_fullScreen1->setModal(false);
shun-iwasawa 31accf
  m_fullScreen1->setStyleSheet("background-color:black;");
shun-iwasawa 31accf
  m_screenCount = QApplication::desktop()->screenCount();
shun-iwasawa 31accf
  if (m_screenCount > 1) {
shun-iwasawa 31accf
    m_fullScreen2 = new QDialog();
shun-iwasawa 31accf
    m_fullScreen2->setModal(false);
shun-iwasawa 31accf
    m_fullScreen2->setStyleSheet("background-color:black;");
shun-iwasawa 31accf
    if (m_screenCount > 2) {
shun-iwasawa 31accf
      m_fullScreen3 = new QDialog();
shun-iwasawa 31accf
      m_fullScreen3->setModal(false);
shun-iwasawa 31accf
      m_fullScreen3->setStyleSheet("background-color:black;");
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
}
shun-iwasawa 31accf
StopMotionLight::~StopMotionLight() {}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
void StopMotionLight::setBlackCapture(bool on) {
shun-iwasawa 31accf
  m_blackCapture         = on;
shun-iwasawa 31accf
  StopMotionBlackCapture = int(on);
shun-iwasawa 31accf
  emit(blackCaptureSignal(on));
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
void StopMotionLight::setScreen1Color(TPixel32 color) {
shun-iwasawa 31accf
  m_screen1Color = color;
shun-iwasawa 31accf
  emit(screen1ColorChanged(color));
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
void StopMotionLight::setScreen2Color(TPixel32 color) {
shun-iwasawa 31accf
  m_screen2Color = color;
shun-iwasawa 31accf
  emit(screen2ColorChanged(color));
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
void StopMotionLight::setScreen3Color(TPixel32 color) {
shun-iwasawa 31accf
  m_screen3Color = color;
shun-iwasawa 31accf
  emit(screen3ColorChanged(color));
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
void StopMotionLight::setScreen1UseOverlay(bool on) {
shun-iwasawa 31accf
  m_useScreen1Overlay = on;
shun-iwasawa 31accf
  emit(screen1OverlayChanged(on));
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
void StopMotionLight::setScreen2UseOverlay(bool on) {
shun-iwasawa 31accf
  m_useScreen2Overlay = on;
shun-iwasawa 31accf
  emit(screen2OverlayChanged(on));
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
void StopMotionLight::setScreen3UseOverlay(bool on) {
shun-iwasawa 31accf
  m_useScreen3Overlay = on;
shun-iwasawa 31accf
  emit(screen3OverlayChanged(on));
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
void StopMotionLight::showOverlays() {
shun-iwasawa 31accf
  if (getBlackCapture()) {
shun-iwasawa 31accf
    m_fullScreen1->setStyleSheet("background-color: rgb(0,0,0);");
shun-iwasawa 31accf
    if (m_screenCount > 1) {
shun-iwasawa 31accf
      m_fullScreen2->setStyleSheet("background-color: rgb(0,0,0);");
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
    if (m_screenCount > 2) {
shun-iwasawa 31accf
      m_fullScreen3->setStyleSheet("background-color: rgb(0,0,0);");
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
  } else {
shun-iwasawa 31accf
    QString style1 = QString("background-color: rgb(%1,%2,%3);")
shun-iwasawa 31accf
                         .arg(m_screen1Color.r)
shun-iwasawa 31accf
                         .arg(m_screen1Color.g)
shun-iwasawa 31accf
                         .arg(m_screen1Color.b);
shun-iwasawa 31accf
    m_fullScreen1->setStyleSheet(style1);
shun-iwasawa 31accf
    if (m_screenCount > 1) {
shun-iwasawa 31accf
      QString style2 = QString("background-color: rgb(%1,%2,%3);")
shun-iwasawa 31accf
                           .arg(m_screen2Color.r)
shun-iwasawa 31accf
                           .arg(m_screen2Color.g)
shun-iwasawa 31accf
                           .arg(m_screen2Color.b);
shun-iwasawa 31accf
      m_fullScreen2->setStyleSheet(style2);
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
    if (m_screenCount > 2) {
shun-iwasawa 31accf
      QString style3 = QString("background-color: rgb(%1,%2,%3);")
shun-iwasawa 31accf
                           .arg(m_screen3Color.r)
shun-iwasawa 31accf
                           .arg(m_screen3Color.g)
shun-iwasawa 31accf
                           .arg(m_screen3Color.b);
shun-iwasawa 31accf
      m_fullScreen3->setStyleSheet(style3);
shun-iwasawa 31accf
    }
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  bool shown       = false;
shun-iwasawa 31accf
  bool isTimeLapse = StopMotion::instance()->m_isTimeLapse;
shun-iwasawa 31accf
  if ((getBlackCapture() || m_useScreen1Overlay) && !isTimeLapse) {
shun-iwasawa 31accf
    m_fullScreen1->showFullScreen();
shun-iwasawa 31accf
    m_fullScreen1->setGeometry(QApplication::desktop()->screenGeometry(0));
shun-iwasawa 31accf
    shown = true;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  if (m_screenCount > 1 && (getBlackCapture() || m_useScreen2Overlay) &&
shun-iwasawa 31accf
      !isTimeLapse) {
shun-iwasawa 31accf
    m_fullScreen2->showFullScreen();
shun-iwasawa 31accf
    m_fullScreen2->setGeometry(QApplication::desktop()->screenGeometry(1));
shun-iwasawa 31accf
    shown = true;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  if (m_screenCount > 2 && (getBlackCapture() || m_useScreen3Overlay) &&
shun-iwasawa 31accf
      !isTimeLapse) {
shun-iwasawa 31accf
    m_fullScreen3->showFullScreen();
shun-iwasawa 31accf
    m_fullScreen3->setGeometry(QApplication::desktop()->screenGeometry(2));
shun-iwasawa 31accf
    shown = true;
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
shun-iwasawa 31accf
  if (shown) {
shun-iwasawa 31accf
    // this allows the full screen qdialogs to go full screen before
shun-iwasawa 31accf
    // taking a photo
shun-iwasawa 31accf
    qApp->processEvents(QEventLoop::AllEvents, 1500);
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  m_overlaysReady = true;
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
void StopMotionLight::hideOverlays() {
shun-iwasawa 31accf
  if ((getBlackCapture() || m_useScreen1Overlay)) {
shun-iwasawa 31accf
#ifndef WIN32
shun-iwasawa 31accf
    m_fullScreen1->showNormal();
shun-iwasawa 31accf
#endif
shun-iwasawa 31accf
    m_fullScreen1->close();
shun-iwasawa 31accf
    m_fullScreen1->windowHandle()->close();
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  if (m_screenCount > 1 && (getBlackCapture() || m_useScreen2Overlay)) {
shun-iwasawa 31accf
#ifndef WIN32
shun-iwasawa 31accf
    m_fullScreen2->showNormal();
shun-iwasawa 31accf
#endif
shun-iwasawa 31accf
    m_fullScreen2->close();
shun-iwasawa 31accf
    m_fullScreen2->windowHandle()->close();
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  if (m_screenCount > 2 && (getBlackCapture() || m_useScreen3Overlay)) {
shun-iwasawa 31accf
#ifndef WIN32
shun-iwasawa 31accf
    m_fullScreen3->showNormal();
shun-iwasawa 31accf
#endif
shun-iwasawa 31accf
    m_fullScreen3->close();
shun-iwasawa 31accf
    m_fullScreen3->windowHandle()->close();
shun-iwasawa 31accf
  }
shun-iwasawa 31accf
  m_overlaysReady = false;
shun-iwasawa 31accf
}
shun-iwasawa 31accf
shun-iwasawa 31accf
//-----------------------------------------------------------------
shun-iwasawa 31accf
shun-iwasawa 31accf
bool StopMotionLight::useOverlays() {
shun-iwasawa 31accf
  return m_blackCapture || m_useScreen1Overlay || m_useScreen2Overlay ||
shun-iwasawa 31accf
         m_useScreen3Overlay;
shun-iwasawa 31accf
}