Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Changed see-through window implementation to allow full-screen canvas (Alt+F) to also be see-through

justburner521a74fa93db
diff --git a/toonz/sources/include/toonzqt/imageutils.h b/toonz/sources/include/toonzqt/imageutils.h
index 95d3ba1a3..99a54346c 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 000000000..7de2e96d7
--- /dev/null
+++ b/toonz/sources/include/toonzqt/seethroughwindow.h
@@ -0,0 +1,83 @@
+#pragma once
+
+#include "toonzqt/dvdialog.h"
+
+#include <QLabel>
+#include <QSlider>
+#include <QPushButton>
+#include <QBoxLayout>
+
+#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 06ee94973..ec2111359 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 11ff6c21b..578fc6d4d 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.h b/toonz/sources/toonz/seethroughwindowpopup.h
deleted file mode 100644
index 82170d203..000000000
--- a/toonz/sources/toonz/seethroughwindowpopup.h
+++ /dev/null
@@ -1,40 +0,0 @@
-#pragma once
-
-#include "toonzqt/dvdialog.h"
-
-#include <QLabel>
-#include <QSlider>
-#include <QPushButton>
-#include <QBoxLayout>
-
-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 b4c289713..0c44f516f 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 1ee0bf9c5..f3e7bd662 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/toonz/seethroughwindowpopup.cpp b/toonz/sources/toonzqt/seethroughwindow.cpp
similarity index 62%
rename from toonz/sources/toonz/seethroughwindowpopup.cpp
rename to toonz/sources/toonzqt/seethroughwindow.cpp
index 14fd84b8a..98ce46ee6 100644
--- a/toonz/sources/toonz/seethroughwindowpopup.cpp
+++ b/toonz/sources/toonzqt/seethroughwindow.cpp
@@ -1,7 +1,6 @@
-#include "seethroughwindowpopup.h"
+#include "toonzqt/seethroughwindow.h"
// Tnz6 includes
-#include "tapp.h"
#include "tenv.h"
// TnzQt includes
@@ -15,14 +14,17 @@ TEnv::IntVar SeeThroughWindowOpacity("SeeThroughWindowOpacity", 50);
//-----------------------------------------------------------------------------
-SeeThroughWindowPopup::SeeThroughWindowPopup()
- : Dialog(TApp::instance()->getMainWindow(), true, false, "SeeThroughWindow") {
+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_bckValue = 50;
+ m_mainWindow = mainWindow;
+ m_backupValue = 50;
m_layout = new QBoxLayout(QBoxLayout::LeftToRight);
@@ -38,9 +40,9 @@ SeeThroughWindowPopup::SeeThroughWindowPopup()
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.");
+ 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);
@@ -50,14 +52,14 @@ SeeThroughWindowPopup::SeeThroughWindowPopup()
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 = new QPushButton(tr("Close"));
+ m_closeBtn->setToolTip("Disable See-Through Window Mode and Close");
m_closeBtn->setDefault(true);
m_closeBtn->setFocusPolicy(Qt::NoFocus);
- beginVLayout();
+ beginHLayout();
addLayout(m_layout);
- endVLayout();
+ endHLayout();
addButtonBarWidget(m_closeBtn);
resizeEvent(nullptr); // set proper orientation
@@ -73,10 +75,39 @@ SeeThroughWindowPopup::SeeThroughWindowPopup()
//-----------------------------------------------------------------------------
+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());
}
@@ -85,13 +116,13 @@ void SeeThroughWindowPopup::showEvent(QShowEvent *e) {
void SeeThroughWindowPopup::hideEvent(QHideEvent *e) {
SeeThroughWindowOpacity = getOpacitySlider();
- TApp::instance()->getMainWindow()->setWindowOpacity(1.0);
+ changeOpacity(100);
}
//-----------------------------------------------------------------------------
void SeeThroughWindowPopup::resizeEvent(QResizeEvent *e) {
- bool portrait = width() >= height();
+ bool portrait = width() > height();
m_layout->setDirection(portrait ? QBoxLayout::LeftToRight
: QBoxLayout::TopToBottom);
m_opacitySlider->setOrientation(portrait ? Qt::Orientation::Horizontal
@@ -100,23 +131,9 @@ void SeeThroughWindowPopup::resizeEvent(QResizeEvent *e) {
//-----------------------------------------------------------------------------
-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);
+ changeOpacity(opacity);
m_opacitySlider->setToolTip(QString::number(opacity) + m_suffixTxtSlider);
if (m_opacityBtn->isChecked()) {
m_opacityBtn->setChecked(false);
@@ -130,10 +147,46 @@ 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);
+ 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);
+ }
+}