|
justburner |
521a74 |
#include "toonzqt/seethroughwindow.h"
|
|
justburner |
e9f260 |
|
|
justburner |
e9f260 |
// Tnz6 includes
|
|
justburner |
e9f260 |
#include "tenv.h"
|
|
justburner |
e9f260 |
|
|
justburner |
e9f260 |
// TnzQt includes
|
|
justburner |
e9f260 |
#include "toonzqt/gutil.h"
|
|
justburner |
e9f260 |
|
|
justburner |
e9f260 |
#include <qapplication></qapplication>
|
|
justburner |
e9f260 |
#include <qmainwindow></qmainwindow>
|
|
justburner |
06cb33 |
#include <qdialog></qdialog>
|
|
justburner |
e9f260 |
|
|
justburner |
e9f260 |
TEnv::IntVar SeeThroughWindowOpacity("SeeThroughWindowOpacity", 50);
|
|
justburner |
e9f260 |
|
|
justburner |
e9f260 |
//-----------------------------------------------------------------------------
|
|
justburner |
e9f260 |
|
|
justburner |
521a74 |
SeeThroughWindowPopup::SeeThroughWindowPopup(SeeThroughWindowMode *mode,
|
|
justburner |
521a74 |
QWidget *mainWindow)
|
|
justburner |
521a74 |
: m_mode(mode), Dialog(mainWindow, true, false, "SeeThroughWindow") {
|
|
justburner |
06cb33 |
setWindowTitle(tr("See Through Mode (Main Window)"));
|
|
justburner |
521a74 |
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
|
|
justburner |
e9f260 |
setModal(false);
|
|
justburner |
e9f260 |
|
|
justburner |
06cb33 |
m_suffixTxtSlider = "% " + tr("Opacity");
|
|
justburner |
e9f260 |
|
|
justburner |
521a74 |
m_mainWindow = mainWindow;
|
|
justburner |
521a74 |
m_backupValue = 50;
|
|
justburner |
e9f260 |
|
|
justburner |
06cb33 |
m_layout = new QBoxLayout(QBoxLayout::LeftToRight);
|
|
justburner |
e9f260 |
|
|
justburner |
e9f260 |
m_opacitySlider = new QSlider(Qt::Horizontal);
|
|
justburner |
e9f260 |
m_opacitySlider->setRange(1, 50);
|
|
justburner |
e9f260 |
m_opacitySlider->setSingleStep(1);
|
|
justburner |
e9f260 |
m_opacitySlider->setPageStep(5);
|
|
justburner |
e9f260 |
setOpacitySlider(SeeThroughWindowOpacity);
|
|
justburner |
e9f260 |
m_opacitySlider->setMinimumHeight(25);
|
|
justburner |
06cb33 |
m_layout->addWidget(m_opacitySlider);
|
|
justburner |
e9f260 |
|
|
justburner |
e9f260 |
m_seeThroughIcon_off = createQIcon("toggle_seethroughwin_off");
|
|
justburner |
e9f260 |
m_seeThroughIcon_on = createQIcon("toggle_seethroughwin_on");
|
|
justburner |
e9f260 |
|
|
justburner |
e9f260 |
QString tooltip =
|
|
justburner |
521a74 |
tr("Quickly toggle main window semi-transparency and full opacity.") +
|
|
justburner |
521a74 |
"\n" + tr("Hold ALT while clicking to use full transparency instead.") +
|
|
justburner |
521a74 |
"\n" + tr("When slider is at 100% it acts as ALT is held.");
|
|
justburner |
e9f260 |
|
|
justburner |
e9f260 |
m_opacityBtn = new QPushButton(m_seeThroughIcon_on, "");
|
|
justburner |
e9f260 |
m_opacityBtn->setCheckable(true);
|
|
justburner |
e9f260 |
m_opacityBtn->setToolTip(tooltip);
|
|
justburner |
e9f260 |
m_opacityBtn->setFocusPolicy(Qt::NoFocus);
|
|
justburner |
06cb33 |
m_opacityBtn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
justburner |
06cb33 |
m_opacityBtn->setFixedSize(25, 25);
|
|
justburner |
06cb33 |
m_layout->addWidget(m_opacityBtn);
|
|
justburner |
e9f260 |
|
|
justburner |
521a74 |
m_closeBtn = new QPushButton(tr("Close"));
|
|
justburner |
521a74 |
m_closeBtn->setToolTip("Disable See-Through Window Mode and Close");
|
|
justburner |
e9f260 |
m_closeBtn->setDefault(true);
|
|
justburner |
e9f260 |
m_closeBtn->setFocusPolicy(Qt::NoFocus);
|
|
justburner |
e9f260 |
|
|
justburner |
521a74 |
beginHLayout();
|
|
justburner |
06cb33 |
addLayout(m_layout);
|
|
justburner |
521a74 |
endHLayout();
|
|
justburner |
06cb33 |
addButtonBarWidget(m_closeBtn);
|
|
justburner |
06cb33 |
resizeEvent(nullptr); // set proper orientation
|
|
justburner |
06cb33 |
|
|
justburner |
e9f260 |
bool ret = true;
|
|
justburner |
e9f260 |
|
|
justburner |
e9f260 |
ret = ret && connect(m_opacitySlider, SIGNAL(valueChanged(int)), this,
|
|
justburner |
e9f260 |
SLOT(sliderChanged(int)));
|
|
justburner |
e9f260 |
ret = ret &&
|
|
justburner |
e9f260 |
connect(m_opacityBtn, SIGNAL(clicked()), this, SLOT(opacityToggle()));
|
|
justburner |
e9f260 |
ret = ret && connect(m_closeBtn, SIGNAL(clicked()), this, SLOT(accept()));
|
|
justburner |
e9f260 |
assert(ret);
|
|
justburner |
e9f260 |
}
|
|
justburner |
e9f260 |
|
|
justburner |
e9f260 |
//-----------------------------------------------------------------------------
|
|
justburner |
e9f260 |
|
|
justburner |
521a74 |
QWidget *SeeThroughWindowPopup::getMainWindow() { return m_mainWindow; }
|
|
justburner |
521a74 |
|
|
justburner |
521a74 |
//-----------------------------------------------------------------------------
|
|
justburner |
521a74 |
|
|
justburner |
e9f260 |
void SeeThroughWindowPopup::toggleMode() { setVisible(!isVisible()); }
|
|
justburner |
e9f260 |
|
|
justburner |
e9f260 |
//-----------------------------------------------------------------------------
|
|
justburner |
e9f260 |
|
|
justburner |
521a74 |
int SeeThroughWindowPopup::getOpacitySlider() {
|
|
justburner |
521a74 |
return m_opacitySlider->value() * 2;
|
|
justburner |
521a74 |
}
|
|
justburner |
521a74 |
|
|
justburner |
521a74 |
//-----------------------------------------------------------------------------
|
|
justburner |
521a74 |
|
|
justburner |
521a74 |
int SeeThroughWindowPopup::setOpacitySlider(int opacity) {
|
|
justburner |
521a74 |
int value = std::min(std::max((int)opacity / 2, 1), 50);
|
|
justburner |
521a74 |
m_opacitySlider->setValue(value);
|
|
justburner |
521a74 |
return value;
|
|
justburner |
521a74 |
}
|
|
justburner |
521a74 |
|
|
justburner |
521a74 |
//-----------------------------------------------------------------------------
|
|
justburner |
521a74 |
|
|
justburner |
521a74 |
void SeeThroughWindowPopup::changeOpacity(int value) {
|
|
justburner |
521a74 |
bool hideMain = false;
|
|
justburner |
521a74 |
emit m_mode->opacityChanged(value, hideMain);
|
|
justburner |
521a74 |
if (hideMain)
|
|
justburner |
521a74 |
m_mainWindow->setWindowOpacity(0.0);
|
|
justburner |
521a74 |
else
|
|
justburner |
521a74 |
m_mainWindow->setWindowOpacity((double)value / 100.0);
|
|
justburner |
521a74 |
}
|
|
justburner |
521a74 |
|
|
justburner |
521a74 |
//-----------------------------------------------------------------------------
|
|
justburner |
521a74 |
|
|
justburner |
e9f260 |
void SeeThroughWindowPopup::showEvent(QShowEvent *e) {
|
|
justburner |
e9f260 |
sliderChanged(m_opacitySlider->value());
|
|
justburner |
e9f260 |
}
|
|
justburner |
e9f260 |
|
|
justburner |
e9f260 |
//-----------------------------------------------------------------------------
|
|
justburner |
e9f260 |
|
|
justburner |
e9f260 |
void SeeThroughWindowPopup::hideEvent(QHideEvent *e) {
|
|
justburner |
e9f260 |
SeeThroughWindowOpacity = getOpacitySlider();
|
|
justburner |
521a74 |
changeOpacity(100);
|
|
justburner |
e9f260 |
}
|
|
justburner |
e9f260 |
|
|
justburner |
e9f260 |
//-----------------------------------------------------------------------------
|
|
justburner |
e9f260 |
|
|
justburner |
06cb33 |
void SeeThroughWindowPopup::resizeEvent(QResizeEvent *e) {
|
|
justburner |
521a74 |
bool portrait = width() > height();
|
|
justburner |
06cb33 |
m_layout->setDirection(portrait ? QBoxLayout::LeftToRight
|
|
justburner |
06cb33 |
: QBoxLayout::TopToBottom);
|
|
justburner |
06cb33 |
m_opacitySlider->setOrientation(portrait ? Qt::Orientation::Horizontal
|
|
justburner |
06cb33 |
: Qt::Orientation::Vertical);
|
|
justburner |
06cb33 |
}
|
|
justburner |
06cb33 |
|
|
justburner |
06cb33 |
//-----------------------------------------------------------------------------
|
|
justburner |
06cb33 |
|
|
justburner |
e9f260 |
void SeeThroughWindowPopup::sliderChanged(int value) {
|
|
justburner |
e9f260 |
int opacity = getOpacitySlider();
|
|
justburner |
521a74 |
changeOpacity(opacity);
|
|
justburner |
06cb33 |
m_opacitySlider->setToolTip(QString::number(opacity) + m_suffixTxtSlider);
|
|
justburner |
e9f260 |
if (m_opacityBtn->isChecked()) {
|
|
justburner |
e9f260 |
m_opacityBtn->setChecked(false);
|
|
justburner |
e9f260 |
m_opacityBtn->setIcon(m_seeThroughIcon_on);
|
|
justburner |
e9f260 |
}
|
|
justburner |
e9f260 |
}
|
|
justburner |
e9f260 |
|
|
justburner |
e9f260 |
//-----------------------------------------------------------------------------
|
|
justburner |
e9f260 |
|
|
justburner |
e9f260 |
void SeeThroughWindowPopup::opacityToggle() {
|
|
justburner |
e9f260 |
if (m_opacityBtn->isChecked()) {
|
|
justburner |
e9f260 |
bool altMod = (QApplication::keyboardModifiers() & Qt::AltModifier);
|
|
justburner |
e9f260 |
if (m_opacitySlider->value() >= m_opacitySlider->maximum()) altMod = true;
|
|
justburner |
521a74 |
changeOpacity(altMod ? 0 : 100);
|
|
justburner |
e9f260 |
m_opacityBtn->setIcon(altMod ? QIcon() : m_seeThroughIcon_off);
|
|
justburner |
e9f260 |
} else {
|
|
justburner |
e9f260 |
sliderChanged(m_opacitySlider->value());
|
|
justburner |
e9f260 |
m_opacityBtn->setIcon(m_seeThroughIcon_on);
|
|
justburner |
e9f260 |
}
|
|
justburner |
e9f260 |
}
|
|
justburner |
521a74 |
|
|
justburner |
521a74 |
//-----------------------------------------------------------------------------
|
|
justburner |
521a74 |
//-----------------------------------------------------------------------------
|
|
justburner |
521a74 |
|
|
justburner |
521a74 |
SeeThroughWindowMode::SeeThroughWindowMode() : m_dialog(nullptr) {}
|
|
justburner |
521a74 |
|
|
justburner |
521a74 |
//-----------------------------------------------------------------------------
|
|
justburner |
521a74 |
|
|
justburner |
521a74 |
void SeeThroughWindowMode::toggleMode(QWidget *mainWindow) {
|
|
justburner |
521a74 |
if (!m_dialog) m_dialog = new SeeThroughWindowPopup(this, mainWindow);
|
|
justburner |
521a74 |
m_dialog->setVisible(!m_dialog->isVisible());
|
|
justburner |
521a74 |
}
|
|
justburner |
521a74 |
|
|
justburner |
521a74 |
//-----------------------------------------------------------------------------
|
|
justburner |
521a74 |
|
|
justburner |
521a74 |
QWidget *SeeThroughWindowMode::getMainWindow() {
|
|
justburner |
521a74 |
return m_dialog->getMainWindow();
|
|
justburner |
521a74 |
}
|
|
justburner |
521a74 |
|
|
justburner |
521a74 |
//-----------------------------------------------------------------------------
|
|
justburner |
521a74 |
|
|
justburner |
521a74 |
int SeeThroughWindowMode::getOpacity() {
|
|
justburner |
521a74 |
if (m_dialog) return m_dialog->getOpacitySlider();
|
|
justburner |
521a74 |
return 100;
|
|
justburner |
521a74 |
}
|
|
justburner |
521a74 |
|
|
justburner |
521a74 |
//-----------------------------------------------------------------------------
|
|
justburner |
521a74 |
|
|
justburner |
521a74 |
void SeeThroughWindowMode::refreshOpacity() {
|
|
justburner |
521a74 |
if (m_dialog) {
|
|
justburner |
521a74 |
if (m_dialog->isVisible())
|
|
justburner |
521a74 |
m_dialog->changeOpacity(m_dialog->getOpacitySlider());
|
|
justburner |
521a74 |
else
|
|
justburner |
521a74 |
m_dialog->changeOpacity(100);
|
|
justburner |
521a74 |
}
|
|
justburner |
521a74 |
}
|