From 63ee88107b1fbeba39c1f325c9941135774b853f Mon Sep 17 00:00:00 2001 From: Rodney Date: Oct 16 2022 19:49:00 +0000 Subject: Merge pull request #4557 from shun-iwasawa/g/histogram_enhancements Histogram popup enhancements --- diff --git a/toonz/sources/include/toonzqt/combohistogram.h b/toonz/sources/include/toonzqt/combohistogram.h index 338961b..54f7739 100644 --- a/toonz/sources/include/toonzqt/combohistogram.h +++ b/toonz/sources/include/toonzqt/combohistogram.h @@ -51,6 +51,7 @@ private: QColor m_color; DisplayMode m_mode; + bool m_alphaVisible; public: ComboHistoRGBLabel(QColor color, QWidget *parent); @@ -59,6 +60,7 @@ public: void setColorAndUpdate(QColor color); void setDisplayMode(DisplayMode mode) { m_mode = mode; } + void setAlphaVisible(bool visible) { m_alphaVisible = visible; } protected: void paintEvent(QPaintEvent *pe) override; @@ -142,6 +144,9 @@ public: protected slots: void onShowAlphaButtonToggled(bool visible); + +signals: + void showButtonToggled(bool); }; //----------------------------------------------------------------------------- @@ -199,6 +204,7 @@ protected: protected slots: void onDisplayModeChanged(); + void onShowAlphaButtonToggled(bool); }; #endif diff --git a/toonz/sources/include/toonzqt/menubarcommand.h b/toonz/sources/include/toonzqt/menubarcommand.h index a940214..85c1c8d 100644 --- a/toonz/sources/include/toonzqt/menubarcommand.h +++ b/toonz/sources/include/toonzqt/menubarcommand.h @@ -63,10 +63,11 @@ enum CommandType { ToolModifierCommandType, ZoomCommandType, MiscCommandType, + StopMotionCommandType, + CellMarkCommandType, MenuCommandType, VisualizationButtonCommandType, - StopMotionCommandType, - CellMarkCommandType + HiddenCommandType }; //----------------------------------------------------------------------------- @@ -246,9 +247,15 @@ public: void execute() override { if (!m_popup) m_popup = new T(); - m_popup->show(); - m_popup->raise(); - m_popup->activateWindow(); + + // close popup when using the command while open + if (m_popup->isVisible()) + m_popup->hide(); + else { + m_popup->show(); + m_popup->raise(); + m_popup->activateWindow(); + } } }; diff --git a/toonz/sources/tnztools/stylepicker.cpp b/toonz/sources/tnztools/stylepicker.cpp index bee9eda..d083aa3 100644 --- a/toonz/sources/tnztools/stylepicker.cpp +++ b/toonz/sources/tnztools/stylepicker.cpp @@ -261,7 +261,7 @@ TPixel64 StylePicker::pickAverageColor16(const TRectD &rect) const { assert(raster64); if (!raster64) return TPixel64::Transparent; - UINT r = 0, g = 0, b = 0, m = 0, size = 0; + uint64_t r = 0, g = 0, b = 0, m = 0, size = 0; for (int y = topLeft.y; y < bottomRight.y; y++) { TPixel64 *p = &raster64->pixels(y)[topLeft.x]; for (int x = topLeft.x; x < bottomRight.x; x++, p++) { diff --git a/toonz/sources/toonz/flipbook.cpp b/toonz/sources/toonz/flipbook.cpp index b14c3b2..9900e22 100644 --- a/toonz/sources/toonz/flipbook.cpp +++ b/toonz/sources/toonz/flipbook.cpp @@ -266,7 +266,7 @@ void FlipBook::addFreezeButtonToTitleBar() { if (panel) { TPanelTitleBar *titleBar = panel->getTitleBar(); m_freezeButton = new TPanelTitleBarButton( - titleBar, getIconThemePath("actions/20/pane_freeze.svg")); + titleBar, getIconThemePath("actions/20/pane_freeze.svg")); m_freezeButton->setToolTip("Freeze"); titleBar->add(QPoint(-64, 0), m_freezeButton); connect(m_freezeButton, SIGNAL(toggled(bool)), this, SLOT(freeze(bool))); @@ -1763,9 +1763,12 @@ void FlipBook::onCloseButtonPressed() { void ImageViewer::showHistogram() { if (!m_isHistogramEnable) return; + + // close the popup when using the command while open if (m_histogramPopup->isVisible()) - m_histogramPopup->raise(); + m_histogramPopup->hide(); else { + m_histogramPopup->moveNextToWidget(this); m_histogramPopup->setImage(getImage()); m_histogramPopup->show(); } diff --git a/toonz/sources/toonz/histogrampopup.cpp b/toonz/sources/toonz/histogrampopup.cpp index 248ad32..c34ae64 100644 --- a/toonz/sources/toonz/histogrampopup.cpp +++ b/toonz/sources/toonz/histogrampopup.cpp @@ -6,6 +6,7 @@ #include "menubarcommandids.h" #include "tapp.h" #include "previewer.h" +#include "sceneviewer.h" // TnzQt includes #include "toonzqt/menubarcommand.h" @@ -22,6 +23,8 @@ // Qt includes #include #include +#include +#include using namespace DVGui; @@ -106,6 +109,35 @@ void HistogramPopup::invalidateCompHisto() { m_histogram->invalidateCompHisto(); } +//----------------------------------------------------------------------------- + +void HistogramPopup::moveNextToWidget(QWidget *widget) { + if (!widget) return; + const int margin = 5; + + if (minimumSize().isEmpty()) grab(); + QSize popupSize = frameSize(); + + int currentScreen = QApplication::desktop()->screenNumber(widget); + QRect screenRect = QApplication::desktop()->availableGeometry(currentScreen); + QRect viewerRect = widget->rect(); + viewerRect.moveTo(widget->mapToGlobal(QPoint(0, 0))); + // decide which side to open the popup + QPoint popupPos = widget->mapToGlobal(QPoint(0, 0)); + // open at the left + if (viewerRect.left() - screenRect.left() > + screenRect.right() - viewerRect.right()) + popupPos.setX(std::max(viewerRect.left() - popupSize.width() - margin, 0)); + // open at the right + else + popupPos.setX(std::min(viewerRect.right() + margin, + screenRect.right() - popupSize.width())); + // adjust vertical position + popupPos.setY(std::min(std::max(popupPos.y(), screenRect.top()), + screenRect.bottom() - popupSize.height() - margin)); + move(popupPos); +} + //============================================================================= /*! \class ViewerHistogramPopup \brief The ViewerHistogramPopup show the histogram pertain to @@ -127,6 +159,7 @@ void ViewerHistogramPopup::showEvent(QShowEvent *e) { SLOT(setCurrentRaster())); setCurrentRaster(); + moveNextToWidget(TApp::instance()->getActiveViewer()); } //----------------------------------------------------------------------------- @@ -160,4 +193,5 @@ void ViewerHistogramPopup::setCurrentRaster() { //============================================================================= -OpenPopupCommandHandler openHistogramPopup(MI_Histogram); +OpenPopupCommandHandler openHistogramPopup( + MI_ViewerHistogram); diff --git a/toonz/sources/toonz/histogrampopup.h b/toonz/sources/toonz/histogrampopup.h index 2e755c0..53cf39e 100644 --- a/toonz/sources/toonz/histogrampopup.h +++ b/toonz/sources/toonz/histogrampopup.h @@ -32,6 +32,7 @@ public: void updateAverageColor(const TPixel64 &pix); void setShowCompare(bool on); void invalidateCompHisto(); + void moveNextToWidget(QWidget *widget); }; //============================================================================= diff --git a/toonz/sources/toonz/mainwindow.cpp b/toonz/sources/toonz/mainwindow.cpp index ba2bda2..3eeda4c 100644 --- a/toonz/sources/toonz/mainwindow.cpp +++ b/toonz/sources/toonz/mainwindow.cpp @@ -2217,7 +2217,13 @@ void MainWindow::defineActions() { "", "shift_keys_up"); createRightClickMenuAction(MI_PasteNumbers, QT_TR_NOOP("&Paste Numbers"), "", "paste_numbers"); + createRightClickMenuAction(MI_Histogram, QT_TR_NOOP("&Histogram"), ""); + // MI_ViewerHistogram command is used as a proxy. It will be called when + // the MI_Histogram is used while the current flip console is in viewer. + createAction(MI_ViewerHistogram, QT_TR_NOOP("&Viewer Histogram"), "", + HiddenCommandType); + createRightClickMenuAction(MI_BlendColors, QT_TR_NOOP("&Blend colors"), ""); createToggle(MI_OnionSkin, QT_TR_NOOP("Onion Skin Toggle"), "/", false, RightClickMenuCommandType, "onionskin_toggle"); diff --git a/toonz/sources/toonz/menubarcommandids.h b/toonz/sources/toonz/menubarcommandids.h index 6197228..8cd71bb 100644 --- a/toonz/sources/toonz/menubarcommandids.h +++ b/toonz/sources/toonz/menubarcommandids.h @@ -190,6 +190,7 @@ #define MI_NoShift "MI_NoShift" #define MI_ResetShift "MI_ResetShift" #define MI_Histogram "MI_Histogram" +#define MI_ViewerHistogram "MI_ViewerHistogram" #define MI_FxParamEditor "MI_FxParamEditor" #define MI_Link "MI_Link" diff --git a/toonz/sources/toonz/sceneviewerevents.cpp b/toonz/sources/toonz/sceneviewerevents.cpp index 98d5045..83ccc0d 100644 --- a/toonz/sources/toonz/sceneviewerevents.cpp +++ b/toonz/sources/toonz/sceneviewerevents.cpp @@ -77,7 +77,7 @@ namespace { void initToonzEvent(TMouseEvent &toonzEvent, QMouseEvent *event, int widgetHeight, double pressure, int devPixRatio) { toonzEvent.m_pos = TPointD(event->pos().x() * devPixRatio, - widgetHeight - 1 - event->pos().y() * devPixRatio); + widgetHeight - 1 - event->pos().y() * devPixRatio); toonzEvent.m_mousePos = event->pos(); toonzEvent.m_pressure = 1.0; @@ -205,7 +205,7 @@ void SceneViewer::onButtonPressed(FlipConsole::EGadget button) { break; case FlipConsole::eHisto: { - QAction *action = CommandManager::instance()->getAction(MI_Histogram); + QAction *action = CommandManager::instance()->getAction(MI_ViewerHistogram); action->trigger(); break; } diff --git a/toonz/sources/toonz/vcrcommand.cpp b/toonz/sources/toonz/vcrcommand.cpp index ee0a28d..6451e74 100644 --- a/toonz/sources/toonz/vcrcommand.cpp +++ b/toonz/sources/toonz/vcrcommand.cpp @@ -227,7 +227,8 @@ VcrCommand playCommand(MI_Play, FlipConsole::ePlay), blueChannelGCommand(MI_BlueChannelGreyscale, FlipConsole::eGBlue), compareCommand(MI_CompareToSnapshot, FlipConsole::eCompare), - blankFramesCommand(MI_ToggleBlankFrames, FlipConsole::eBlankFrames); + blankFramesCommand(MI_ToggleBlankFrames, FlipConsole::eBlankFrames), + histogramCommand(MI_Histogram, FlipConsole::eHisto); NextDrawingCommand nextDrawingCommand; PrevDrawingCommand prevDrawingCommand; diff --git a/toonz/sources/toonzqt/combohistogram.cpp b/toonz/sources/toonzqt/combohistogram.cpp index 58ff114..a84494c 100644 --- a/toonz/sources/toonzqt/combohistogram.cpp +++ b/toonz/sources/toonzqt/combohistogram.cpp @@ -95,11 +95,10 @@ void ChannelHistoGraph::paintEvent(QPaintEvent *event) { p.drawLine(posx, 1, posx, COMBOHIST_RESOLUTION_H); } - QColor compColor = (m_channelIndex == 0) - ? Qt::red - : (m_channelIndex == 1) - ? Qt::green - : (m_channelIndex == 2) ? Qt::blue : Qt::magenta; + QColor compColor = (m_channelIndex == 0) ? Qt::red + : (m_channelIndex == 1) ? Qt::green + : (m_channelIndex == 2) ? Qt::blue + : Qt::magenta; compColor.setAlpha(120); int maxValue = m_maxValue[0]; @@ -192,8 +191,9 @@ void RGBHistoGraph::setValues(int *buf, bool) { imgPainter.setCompositionMode(QPainter::CompositionMode_Plus); for (int chan = 0; chan < 3; chan++) { - imgPainter.setPen((chan == 0) ? Qt::red - : (chan == 1) ? Qt::green : Qt::blue); + imgPainter.setPen((chan == 0) ? Qt::red + : (chan == 1) ? Qt::green + : Qt::blue); for (int i = 0; i < COMBOHIST_RESOLUTION_W; i++) { int v = m_rgbValues[chan][i]; @@ -339,14 +339,18 @@ void ChannelHisto::showCurrentChannelValue(int val) { void ChannelHisto::onShowAlphaButtonToggled(bool visible) { m_histogramGraph->setVisible(visible); m_colorBar->setVisible(visible); + emit showButtonToggled(visible); } //============================================================================= // ComboHistoRGBLabel //----------------------------------------------------------------------------- ComboHistoRGBLabel::ComboHistoRGBLabel(QColor color, QWidget *parent) - : QWidget(parent), m_color(color), m_mode(DisplayMode::Display_8bit) { - setFixedSize(COMBOHIST_RESOLUTION_W, 30); + : QWidget(parent) + , m_color(color) + , m_mode(DisplayMode::Display_8bit) + , m_alphaVisible(false) { + setFixedSize(COMBOHIST_RESOLUTION_W, 35); } void ComboHistoRGBLabel::setColorAndUpdate(QColor color) { @@ -388,12 +392,14 @@ void ComboHistoRGBLabel::paintEvent(QPaintEvent *pe) { font.setPixelSize(pixelSizes[(int)m_mode]); p.setFont(font); QString colorStr; + QString colorStr2 = QString(); switch (m_mode) { case Display_8bit: { colorStr = tr("R:%1 G:%2 B:%3") .arg(m_color.red()) .arg(m_color.green()) .arg(m_color.blue()); + if (m_alphaVisible) colorStr += tr(" A:%1").arg(m_color.alpha()); break; } case Display_16bit: { @@ -402,17 +408,34 @@ void ComboHistoRGBLabel::paintEvent(QPaintEvent *pe) { .arg(rgba64.red()) .arg(rgba64.green()) .arg(rgba64.blue()); + if (m_alphaVisible) colorStr += tr(" A:%1").arg(rgba64.alpha()); break; } case Display_0_1: { - colorStr = tr("R:%1 G:%2 B:%3") - .arg(m_color.redF()) - .arg(m_color.greenF()) - .arg(m_color.blueF()); + if (!m_alphaVisible) { + colorStr = tr("R:%1 G:%2 B:%3") + .arg(m_color.redF()) + .arg(m_color.greenF()) + .arg(m_color.blueF()); + } else { + // display in 2 lines + colorStr = tr("R:%1 G:%2 B:%3") + .arg(m_color.redF()) + .arg(m_color.greenF()) + .arg(m_color.blueF()); + colorStr2 = tr("A:%1").arg(m_color.alphaF()); + } break; } } - p.drawText(rect(), Qt::AlignCenter, colorStr); + if (colorStr2.isEmpty()) + p.drawText(rect(), Qt::AlignCenter, colorStr); + else { + QRect upRect = rect().adjusted(0, 0, 0, -rect().height() / 2); + p.drawText(upRect, Qt::AlignCenter, colorStr); + QRect dnRect = upRect.translated(0, rect().height() / 2); + p.drawText(dnRect, Qt::AlignCenter, colorStr2); + } } //============================================================================= @@ -472,18 +495,16 @@ ComboHistogram::ComboHistogram(QWidget *parent) 0, Qt::AlignLeft | Qt::AlignVCenter); mainLayout->addWidget(m_rectAverageRgbLabel, 0, Qt::AlignCenter); - QGridLayout *infoParamLay = new QGridLayout(); - infoParamLay->setHorizontalSpacing(3); - infoParamLay->setVerticalSpacing(5); + QHBoxLayout *infoParamLay = new QHBoxLayout(); + infoParamLay->setMargin(5); + infoParamLay->setSpacing(3); { - infoParamLay->addWidget(new QLabel(tr("X:"), this), 0, 0, + infoParamLay->addWidget(new QLabel(tr("X:"), this), 1, Qt::AlignRight | Qt::AlignVCenter); - infoParamLay->addWidget(m_xPosLabel, 0, 1, - Qt::AlignLeft | Qt::AlignVCenter); - infoParamLay->addWidget(new QLabel(tr("Y:"), this), 1, 0, + infoParamLay->addWidget(m_xPosLabel, 1, Qt::AlignLeft | Qt::AlignVCenter); + infoParamLay->addWidget(new QLabel(tr("Y:"), this), 1, Qt::AlignRight | Qt::AlignVCenter); - infoParamLay->addWidget(m_yPosLabel, 1, 1, - Qt::AlignLeft | Qt::AlignVCenter); + infoParamLay->addWidget(m_yPosLabel, 2, Qt::AlignLeft | Qt::AlignVCenter); } mainLayout->addLayout(infoParamLay, 0); @@ -499,6 +520,8 @@ ComboHistogram::ComboHistogram(QWidget *parent) connect(m_displayModeCombo, SIGNAL(activated(int)), this, SLOT(onDisplayModeChanged())); + connect(m_histograms[3], SIGNAL(showButtonToggled(bool)), this, + SLOT(onShowAlphaButtonToggled(bool))); } //----------------------------------------------------------------------------- @@ -595,6 +618,7 @@ void ComboHistogram::updateInfo(const TPixel32 &pix, const TPointD &imagePos) { m_histograms[0]->showCurrentChannelValue(-1); m_histograms[1]->showCurrentChannelValue(-1); m_histograms[2]->showCurrentChannelValue(-1); + m_histograms[3]->showCurrentChannelValue(-1); m_rgbLabel->setColorAndUpdate(Qt::transparent); m_xPosLabel->setText(""); m_yPosLabel->setText(""); @@ -603,7 +627,9 @@ void ComboHistogram::updateInfo(const TPixel32 &pix, const TPointD &imagePos) { m_histograms[0]->showCurrentChannelValue((int)pix.r); m_histograms[1]->showCurrentChannelValue((int)pix.g); m_histograms[2]->showCurrentChannelValue((int)pix.b); - m_rgbLabel->setColorAndUpdate(QColor((int)pix.r, (int)pix.g, (int)pix.b)); + m_histograms[3]->showCurrentChannelValue((int)pix.m); + m_rgbLabel->setColorAndUpdate( + QColor((int)pix.r, (int)pix.g, (int)pix.b, (int)pix.m)); m_xPosLabel->setText(QString::number(tround(imagePos.x))); m_yPosLabel->setText(QString::number(tround(imagePos.y))); } @@ -616,6 +642,7 @@ void ComboHistogram::updateInfo(const TPixel64 &pix, const TPointD &imagePos) { m_histograms[0]->showCurrentChannelValue(-1); m_histograms[1]->showCurrentChannelValue(-1); m_histograms[2]->showCurrentChannelValue(-1); + m_histograms[3]->showCurrentChannelValue(-1); m_rgbLabel->setColorAndUpdate(Qt::transparent); m_xPosLabel->setText(""); m_yPosLabel->setText(""); @@ -625,8 +652,9 @@ void ComboHistogram::updateInfo(const TPixel64 &pix, const TPointD &imagePos) { m_histograms[0]->showCurrentChannelValue((int)pix32.r); m_histograms[1]->showCurrentChannelValue((int)pix32.g); m_histograms[2]->showCurrentChannelValue((int)pix32.b); - m_rgbLabel->setColorAndUpdate( - QColor::fromRgba64((ushort)pix.r, (ushort)pix.g, (ushort)pix.b)); + m_histograms[3]->showCurrentChannelValue((int)pix32.m); + m_rgbLabel->setColorAndUpdate(QColor::fromRgba64( + (ushort)pix.r, (ushort)pix.g, (ushort)pix.b, (ushort)pix.m)); m_xPosLabel->setText(QString::number(tround(imagePos.x))); m_yPosLabel->setText(QString::number(tround(imagePos.y))); } @@ -639,7 +667,7 @@ void ComboHistogram::updateAverageColor(const TPixel32 &pix) { m_rectAverageRgbLabel->setColorAndUpdate(Qt::transparent); } else { m_rectAverageRgbLabel->setColorAndUpdate( - QColor((int)pix.r, (int)pix.g, (int)pix.b)); + QColor((int)pix.r, (int)pix.g, (int)pix.b, (int)pix.m)); } } @@ -649,8 +677,8 @@ void ComboHistogram::updateAverageColor(const TPixel64 &pix) { if (pix == TPixel64::Transparent) { m_rectAverageRgbLabel->setColorAndUpdate(Qt::transparent); } else { - m_rectAverageRgbLabel->setColorAndUpdate( - QColor::fromRgba64((ushort)pix.r, (ushort)pix.g, (ushort)pix.b)); + m_rectAverageRgbLabel->setColorAndUpdate(QColor::fromRgba64( + (ushort)pix.r, (ushort)pix.g, (ushort)pix.b, (ushort)pix.m)); } } @@ -695,4 +723,13 @@ void ComboHistogram::showEvent(QShowEvent *) { static_cast(envMode); m_rgbLabel->setDisplayMode(mode); m_rectAverageRgbLabel->setDisplayMode(mode); +} + +//----------------------------------------------------------------------------- + +void ComboHistogram::onShowAlphaButtonToggled(bool alphaVisible) { + m_rgbLabel->setAlphaVisible(alphaVisible); + m_rectAverageRgbLabel->setAlphaVisible(alphaVisible); + m_rgbLabel->update(); + m_rectAverageRgbLabel->update(); } \ No newline at end of file