diff --git a/toonz/sources/include/toonzqt/imageutils.h b/toonz/sources/include/toonzqt/imageutils.h index 95d3ba1..99a5434 100644 --- a/toonz/sources/include/toonzqt/imageutils.h +++ b/toonz/sources/include/toonzqt/imageutils.h @@ -171,8 +171,10 @@ public: QWidget *widget() const { return m_widget; } public slots: - bool toggleFullScreen(bool quit = false); + +private slots: + void opacityChanged(int value, bool &hideMain); }; //********************************************************************************************* diff --git a/toonz/sources/include/toonzqt/seethroughwindow.h b/toonz/sources/include/toonzqt/seethroughwindow.h new file mode 100644 index 0000000..7de2e96 --- /dev/null +++ b/toonz/sources/include/toonzqt/seethroughwindow.h @@ -0,0 +1,83 @@ +#pragma once + +#include "toonzqt/dvdialog.h" + +#include +#include +#include +#include + +#undef DVAPI +#undef DVVAR +#ifdef TOONZQT_EXPORTS +#define DVAPI DV_EXPORT_API +#define DVVAR DV_EXPORT_VAR +#else +#define DVAPI DV_IMPORT_API +#define DVVAR DV_IMPORT_VAR +#endif + +class SeeThroughWindowMode; + +class SeeThroughWindowPopup final : public DVGui::Dialog { + Q_OBJECT + + SeeThroughWindowMode *m_mode; + + int m_backupValue; + QWidget *m_mainWindow; + QBoxLayout *m_layout; + + QSlider *m_opacitySlider; + QPushButton *m_opacityBtn; + QPushButton *m_closeBtn; + QString m_suffixTxtSlider; + + QIcon m_seeThroughIcon_off; + QIcon m_seeThroughIcon_on; + +public: + SeeThroughWindowPopup(SeeThroughWindowMode *mode, QWidget *mainWindow); + QWidget *getMainWindow(); + + void toggleMode(); + + int getOpacitySlider(); + int setOpacitySlider(int opacity); + + void changeOpacity(int value); + +private: + void showEvent(QShowEvent *e) override; + void hideEvent(QHideEvent *e) override; + void resizeEvent(QResizeEvent *) override; + +private slots: + void sliderChanged(int value); + void opacityToggle(); +}; + +class DVAPI SeeThroughWindowMode final : public QObject { + Q_OBJECT + + SeeThroughWindowPopup *m_dialog; + +public: + static SeeThroughWindowMode *instance() { + static SeeThroughWindowMode _instance; + return &_instance; + } + + void toggleMode(QWidget *mainWindow); + QWidget *getMainWindow(); + int getOpacity(); + void refreshOpacity(); + +signals: + void opacityChanged(int value, bool &hideMain); + +private: + SeeThroughWindowMode(); + + void toggleMode_m(QWidget *mainWindow); +}; diff --git a/toonz/sources/toonz/CMakeLists.txt b/toonz/sources/toonz/CMakeLists.txt index 06ee949..ec21113 100644 --- a/toonz/sources/toonz/CMakeLists.txt +++ b/toonz/sources/toonz/CMakeLists.txt @@ -86,7 +86,6 @@ set(MOC_HEADERS sceneviewer.h sceneviewercontextmenu.h scriptconsolepanel.h - seethroughwindowpopup.h separatecolorspopup.h separatecolorsswatch.h shortcutpopup.h @@ -288,7 +287,6 @@ set(SOURCES sceneviewercontextmenu.cpp scenesettingspopup.cpp scriptconsolepanel.cpp - seethroughwindowpopup.cpp shortcutpopup.cpp soundtrackexport.cpp startuppopup.cpp diff --git a/toonz/sources/toonz/mainwindow.cpp b/toonz/sources/toonz/mainwindow.cpp index 11ff6c2..578fc6d 100644 --- a/toonz/sources/toonz/mainwindow.cpp +++ b/toonz/sources/toonz/mainwindow.cpp @@ -15,7 +15,6 @@ #include "startuppopup.h" #include "tooloptionsshortcutinvoker.h" #include "custompanelmanager.h" -#include "seethroughwindowpopup.h" // TnzTools includes #include "tools/toolcommandids.h" @@ -27,6 +26,7 @@ #include "toonzqt/viewcommandids.h" #include "toonzqt/updatechecker.h" #include "toonzqt/paletteviewer.h" +#include "toonzqt/seethroughwindow.h" // TnzLib includes #include "toonz/toonzfolders.h" @@ -1096,11 +1096,7 @@ void MainWindow::fullScreenWindow() { } void MainWindow::seeThroughWindow() { - static SeeThroughWindowPopup *popup = nullptr; - - if (!popup) popup = new SeeThroughWindowPopup(); - - popup->toggleMode(); + SeeThroughWindowMode::instance()->toggleMode(this); } //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonz/seethroughwindowpopup.cpp b/toonz/sources/toonz/seethroughwindowpopup.cpp deleted file mode 100644 index 14fd84b..0000000 --- a/toonz/sources/toonz/seethroughwindowpopup.cpp +++ /dev/null @@ -1,139 +0,0 @@ -#include "seethroughwindowpopup.h" - -// Tnz6 includes -#include "tapp.h" -#include "tenv.h" - -// TnzQt includes -#include "toonzqt/gutil.h" - -#include -#include -#include - -TEnv::IntVar SeeThroughWindowOpacity("SeeThroughWindowOpacity", 50); - -//----------------------------------------------------------------------------- - -SeeThroughWindowPopup::SeeThroughWindowPopup() - : Dialog(TApp::instance()->getMainWindow(), true, false, "SeeThroughWindow") { - setWindowTitle(tr("See Through Mode (Main Window)")); - setModal(false); - - m_suffixTxtSlider = "% " + tr("Opacity"); - - m_bckValue = 50; - - m_layout = new QBoxLayout(QBoxLayout::LeftToRight); - - m_opacitySlider = new QSlider(Qt::Horizontal); - m_opacitySlider->setRange(1, 50); - m_opacitySlider->setSingleStep(1); - m_opacitySlider->setPageStep(5); - setOpacitySlider(SeeThroughWindowOpacity); - m_opacitySlider->setMinimumHeight(25); - m_layout->addWidget(m_opacitySlider); - - m_seeThroughIcon_off = createQIcon("toggle_seethroughwin_off"); - m_seeThroughIcon_on = createQIcon("toggle_seethroughwin_on"); - - QString tooltip = - tr("Quickly toggle main window semi-transparency and full opacity.") + "\n" + - tr("Hold ALT while clicking to use full transparency instead.") + "\n" + - tr("When slider is at 100% it acts as ALT is held."); - - m_opacityBtn = new QPushButton(m_seeThroughIcon_on, ""); - m_opacityBtn->setCheckable(true); - m_opacityBtn->setToolTip(tooltip); - m_opacityBtn->setFocusPolicy(Qt::NoFocus); - m_opacityBtn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - m_opacityBtn->setFixedSize(25, 25); - m_layout->addWidget(m_opacityBtn); - - m_closeBtn = new QPushButton(tr("Disable See Through Mode")); - m_closeBtn->setToolTip(m_closeBtn->text()); - m_closeBtn->setDefault(true); - m_closeBtn->setFocusPolicy(Qt::NoFocus); - - beginVLayout(); - addLayout(m_layout); - endVLayout(); - addButtonBarWidget(m_closeBtn); - resizeEvent(nullptr); // set proper orientation - - bool ret = true; - - ret = ret && connect(m_opacitySlider, SIGNAL(valueChanged(int)), this, - SLOT(sliderChanged(int))); - ret = ret && - connect(m_opacityBtn, SIGNAL(clicked()), this, SLOT(opacityToggle())); - ret = ret && connect(m_closeBtn, SIGNAL(clicked()), this, SLOT(accept())); - assert(ret); -} - -//----------------------------------------------------------------------------- - -void SeeThroughWindowPopup::toggleMode() { setVisible(!isVisible()); } - -//----------------------------------------------------------------------------- - -void SeeThroughWindowPopup::showEvent(QShowEvent *e) { - sliderChanged(m_opacitySlider->value()); -} - -//----------------------------------------------------------------------------- - -void SeeThroughWindowPopup::hideEvent(QHideEvent *e) { - SeeThroughWindowOpacity = getOpacitySlider(); - TApp::instance()->getMainWindow()->setWindowOpacity(1.0); -} - -//----------------------------------------------------------------------------- - -void SeeThroughWindowPopup::resizeEvent(QResizeEvent *e) { - bool portrait = width() >= height(); - m_layout->setDirection(portrait ? QBoxLayout::LeftToRight - : QBoxLayout::TopToBottom); - m_opacitySlider->setOrientation(portrait ? Qt::Orientation::Horizontal - : Qt::Orientation::Vertical); -} - -//----------------------------------------------------------------------------- - -int SeeThroughWindowPopup::getOpacitySlider() { - return m_opacitySlider->value() * 2; -} - -//----------------------------------------------------------------------------- - -int SeeThroughWindowPopup::setOpacitySlider(int opacity) { - int value = std::min(std::max((int)opacity / 2, 1), 50); - m_opacitySlider->setValue(value); - return value; -} - -//----------------------------------------------------------------------------- - -void SeeThroughWindowPopup::sliderChanged(int value) { - int opacity = getOpacitySlider(); - TApp::instance()->getMainWindow()->setWindowOpacity((double)opacity / 100); - m_opacitySlider->setToolTip(QString::number(opacity) + m_suffixTxtSlider); - if (m_opacityBtn->isChecked()) { - m_opacityBtn->setChecked(false); - m_opacityBtn->setIcon(m_seeThroughIcon_on); - } -} - -//----------------------------------------------------------------------------- - -void SeeThroughWindowPopup::opacityToggle() { - if (m_opacityBtn->isChecked()) { - bool altMod = (QApplication::keyboardModifiers() & Qt::AltModifier); - if (m_opacitySlider->value() >= m_opacitySlider->maximum()) altMod = true; - TApp::instance()->getMainWindow()->setWindowOpacity(altMod ? 0.0 : 1.0); - m_opacityBtn->setIcon(altMod ? QIcon() : m_seeThroughIcon_off); - } else { - sliderChanged(m_opacitySlider->value()); - m_opacityBtn->setIcon(m_seeThroughIcon_on); - } -} diff --git a/toonz/sources/toonz/seethroughwindowpopup.h b/toonz/sources/toonz/seethroughwindowpopup.h deleted file mode 100644 index 82170d2..0000000 --- a/toonz/sources/toonz/seethroughwindowpopup.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include "toonzqt/dvdialog.h" - -#include -#include -#include -#include - -class SeeThroughWindowPopup final : public DVGui::Dialog { - Q_OBJECT - - int m_bckValue; - QBoxLayout *m_layout; - - QSlider *m_opacitySlider; - QPushButton *m_opacityBtn; - QPushButton *m_closeBtn; - QString m_suffixTxtSlider; - - QIcon m_seeThroughIcon_off; - QIcon m_seeThroughIcon_on; - -public: - SeeThroughWindowPopup(); - - void toggleMode(); - -private: - void showEvent(QShowEvent *e) override; - void hideEvent(QHideEvent *e) override; - void resizeEvent(QResizeEvent *) override; - - int getOpacitySlider(); - int setOpacitySlider(int opacity); - -private slots: - void sliderChanged(int value); - void opacityToggle(); -}; diff --git a/toonz/sources/toonzqt/CMakeLists.txt b/toonz/sources/toonzqt/CMakeLists.txt index b4c2897..0c44f51 100644 --- a/toonz/sources/toonzqt/CMakeLists.txt +++ b/toonz/sources/toonzqt/CMakeLists.txt @@ -54,6 +54,7 @@ set(MOC_HEADERS ../include/toonzqt/schematicviewer.h ../include/toonzqt/screenboard.h ../include/toonzqt/scriptconsole.h + ../include/toonzqt/seethroughwindow.h ../include/toonzqt/spectrumfield.h ../include/toonzqt/spreadsheetviewer.h ../include/toonzqt/stageschematicnode.h @@ -141,6 +142,7 @@ set(SOURCES popupbutton.cpp rasterimagedata.cpp scriptconsole.cpp + seethroughwindow.cpp selection.cpp stageobjectsdata.cpp spectrumfield.cpp diff --git a/toonz/sources/toonzqt/imageutils.cpp b/toonz/sources/toonzqt/imageutils.cpp index 1ee0bf9..f3e7bd6 100644 --- a/toonz/sources/toonzqt/imageutils.cpp +++ b/toonz/sources/toonzqt/imageutils.cpp @@ -1,6 +1,7 @@ // TnzQt includes +#include "toonzqt/seethroughwindow.h" #include "toonzqt/menubarcommand.h" #include "toonzqt/viewcommandids.h" #include "toonzqt/imageutils.h" @@ -894,6 +895,10 @@ FullScreenWidget::FullScreenWidget(QWidget *parent) : QWidget(parent) { layout->setMargin(0); layout->setSpacing(0); + // Attach see-through window signal so this can detect opacity changes + connect(SeeThroughWindowMode::instance(), SIGNAL(opacityChanged(int, bool &)), + this, SLOT(opacityChanged(int, bool &))); + setLayout(layout); } @@ -948,6 +953,9 @@ bool FullScreenWidget::toggleFullScreen( // Set the return value to indicate that the full screen mode has been // changed. fFullScreenStateToggled = true; + + // Refresh see-through window opacity + SeeThroughWindowMode::instance()->refreshOpacity(); } else { // There's no point to switching into full screen if the // application is in the process of quitting. @@ -1048,10 +1056,18 @@ bool FullScreenWidget::toggleFullScreen( // Set the return value to indicate that the full screen mode has been // changed. fFullScreenStateToggled = true; + + // Refresh see-through window opacity + SeeThroughWindowMode::instance()->refreshOpacity(); } } return (fFullScreenStateToggled); } +void FullScreenWidget::opacityChanged(int value, bool &hideMain) { + this->setWindowOpacity((double)value / 100); + if (this->windowState() & Qt::WindowFullScreen) hideMain = true; +} + } // namespace ImageUtils diff --git a/toonz/sources/toonzqt/seethroughwindow.cpp b/toonz/sources/toonzqt/seethroughwindow.cpp new file mode 100644 index 0000000..98ce46e --- /dev/null +++ b/toonz/sources/toonzqt/seethroughwindow.cpp @@ -0,0 +1,192 @@ +#include "toonzqt/seethroughwindow.h" + +// Tnz6 includes +#include "tenv.h" + +// TnzQt includes +#include "toonzqt/gutil.h" + +#include +#include +#include + +TEnv::IntVar SeeThroughWindowOpacity("SeeThroughWindowOpacity", 50); + +//----------------------------------------------------------------------------- + +SeeThroughWindowPopup::SeeThroughWindowPopup(SeeThroughWindowMode *mode, + QWidget *mainWindow) + : m_mode(mode), Dialog(mainWindow, true, false, "SeeThroughWindow") { + setWindowTitle(tr("See Through Mode (Main Window)")); + setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); + setModal(false); + + m_suffixTxtSlider = "% " + tr("Opacity"); + + m_mainWindow = mainWindow; + m_backupValue = 50; + + m_layout = new QBoxLayout(QBoxLayout::LeftToRight); + + m_opacitySlider = new QSlider(Qt::Horizontal); + m_opacitySlider->setRange(1, 50); + m_opacitySlider->setSingleStep(1); + m_opacitySlider->setPageStep(5); + setOpacitySlider(SeeThroughWindowOpacity); + m_opacitySlider->setMinimumHeight(25); + m_layout->addWidget(m_opacitySlider); + + m_seeThroughIcon_off = createQIcon("toggle_seethroughwin_off"); + m_seeThroughIcon_on = createQIcon("toggle_seethroughwin_on"); + + QString tooltip = + tr("Quickly toggle main window semi-transparency and full opacity.") + + "\n" + tr("Hold ALT while clicking to use full transparency instead.") + + "\n" + tr("When slider is at 100% it acts as ALT is held."); + + m_opacityBtn = new QPushButton(m_seeThroughIcon_on, ""); + m_opacityBtn->setCheckable(true); + m_opacityBtn->setToolTip(tooltip); + m_opacityBtn->setFocusPolicy(Qt::NoFocus); + m_opacityBtn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + m_opacityBtn->setFixedSize(25, 25); + m_layout->addWidget(m_opacityBtn); + + m_closeBtn = new QPushButton(tr("Close")); + m_closeBtn->setToolTip("Disable See-Through Window Mode and Close"); + m_closeBtn->setDefault(true); + m_closeBtn->setFocusPolicy(Qt::NoFocus); + + beginHLayout(); + addLayout(m_layout); + endHLayout(); + addButtonBarWidget(m_closeBtn); + resizeEvent(nullptr); // set proper orientation + + bool ret = true; + + ret = ret && connect(m_opacitySlider, SIGNAL(valueChanged(int)), this, + SLOT(sliderChanged(int))); + ret = ret && + connect(m_opacityBtn, SIGNAL(clicked()), this, SLOT(opacityToggle())); + ret = ret && connect(m_closeBtn, SIGNAL(clicked()), this, SLOT(accept())); + assert(ret); +} + +//----------------------------------------------------------------------------- + +QWidget *SeeThroughWindowPopup::getMainWindow() { return m_mainWindow; } + +//----------------------------------------------------------------------------- + +void SeeThroughWindowPopup::toggleMode() { setVisible(!isVisible()); } + +//----------------------------------------------------------------------------- + +int SeeThroughWindowPopup::getOpacitySlider() { + return m_opacitySlider->value() * 2; +} + +//----------------------------------------------------------------------------- + +int SeeThroughWindowPopup::setOpacitySlider(int opacity) { + int value = std::min(std::max((int)opacity / 2, 1), 50); + m_opacitySlider->setValue(value); + return value; +} + +//----------------------------------------------------------------------------- + +void SeeThroughWindowPopup::changeOpacity(int value) { + bool hideMain = false; + emit m_mode->opacityChanged(value, hideMain); + if (hideMain) + m_mainWindow->setWindowOpacity(0.0); + else + m_mainWindow->setWindowOpacity((double)value / 100.0); +} + +//----------------------------------------------------------------------------- + +void SeeThroughWindowPopup::showEvent(QShowEvent *e) { + sliderChanged(m_opacitySlider->value()); +} + +//----------------------------------------------------------------------------- + +void SeeThroughWindowPopup::hideEvent(QHideEvent *e) { + SeeThroughWindowOpacity = getOpacitySlider(); + changeOpacity(100); +} + +//----------------------------------------------------------------------------- + +void SeeThroughWindowPopup::resizeEvent(QResizeEvent *e) { + bool portrait = width() > height(); + m_layout->setDirection(portrait ? QBoxLayout::LeftToRight + : QBoxLayout::TopToBottom); + m_opacitySlider->setOrientation(portrait ? Qt::Orientation::Horizontal + : Qt::Orientation::Vertical); +} + +//----------------------------------------------------------------------------- + +void SeeThroughWindowPopup::sliderChanged(int value) { + int opacity = getOpacitySlider(); + changeOpacity(opacity); + m_opacitySlider->setToolTip(QString::number(opacity) + m_suffixTxtSlider); + if (m_opacityBtn->isChecked()) { + m_opacityBtn->setChecked(false); + m_opacityBtn->setIcon(m_seeThroughIcon_on); + } +} + +//----------------------------------------------------------------------------- + +void SeeThroughWindowPopup::opacityToggle() { + if (m_opacityBtn->isChecked()) { + bool altMod = (QApplication::keyboardModifiers() & Qt::AltModifier); + if (m_opacitySlider->value() >= m_opacitySlider->maximum()) altMod = true; + changeOpacity(altMod ? 0 : 100); + m_opacityBtn->setIcon(altMod ? QIcon() : m_seeThroughIcon_off); + } else { + sliderChanged(m_opacitySlider->value()); + m_opacityBtn->setIcon(m_seeThroughIcon_on); + } +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- + +SeeThroughWindowMode::SeeThroughWindowMode() : m_dialog(nullptr) {} + +//----------------------------------------------------------------------------- + +void SeeThroughWindowMode::toggleMode(QWidget *mainWindow) { + if (!m_dialog) m_dialog = new SeeThroughWindowPopup(this, mainWindow); + m_dialog->setVisible(!m_dialog->isVisible()); +} + +//----------------------------------------------------------------------------- + +QWidget *SeeThroughWindowMode::getMainWindow() { + return m_dialog->getMainWindow(); +} + +//----------------------------------------------------------------------------- + +int SeeThroughWindowMode::getOpacity() { + if (m_dialog) return m_dialog->getOpacitySlider(); + return 100; +} + +//----------------------------------------------------------------------------- + +void SeeThroughWindowMode::refreshOpacity() { + if (m_dialog) { + if (m_dialog->isVisible()) + m_dialog->changeOpacity(m_dialog->getOpacitySlider()); + else + m_dialog->changeOpacity(100); + } +}