|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "histogrampopup.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Tnz6 includes
|
|
Toshihiro Shimizu |
890ddd |
#include "menubarcommandids.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tapp.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "previewer.h"
|
|
shun-iwasawa |
2cda63 |
#include "sceneviewer.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzQt includes
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/menubarcommand.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/combohistogram.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzLib includes
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/tframehandle.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// TnzCore includes
|
|
Toshihiro Shimizu |
890ddd |
#include "trasterimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tvectorimage.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "ttoonzimage.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Qt includes
|
|
Toshihiro Shimizu |
890ddd |
#include <qtimer></qtimer>
|
|
Toshihiro Shimizu |
890ddd |
#include <qmainwindow></qmainwindow>
|
|
shun-iwasawa |
2cda63 |
#include <qdesktopwidget></qdesktopwidget>
|
|
shun-iwasawa |
2cda63 |
#include <qfocusevent></qfocusevent>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using namespace DVGui;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
/*! \class HistogramPopup
|
|
Shinya Kitaoka |
120a6e |
\brief The HistogramPopup class provides a dialog to show an
|
|
Shinya Kitaoka |
120a6e |
histogram \b Histogram
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
Inherits \b Dialog.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
HistogramPopup::HistogramPopup(QString title)
|
|
Shinya Kitaoka |
120a6e |
: QDialog(TApp::instance()->getMainWindow()) {
|
|
Shinya Kitaoka |
120a6e |
setTitle(title);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_histogram = new ComboHistogram(this);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
QVBoxLayout *mainLay = new QVBoxLayout();
|
|
Shinya Kitaoka |
120a6e |
mainLay->setMargin(0);
|
|
Shinya Kitaoka |
120a6e |
mainLay->setSpacing(0);
|
|
Shinya Kitaoka |
120a6e |
{ mainLay->addWidget(m_histogram); }
|
|
Shinya Kitaoka |
120a6e |
setLayout(mainLay);
|
|
shun-iwasawa |
d5045c |
mainLay->setSizeConstraint(QLayout::SetFixedSize);
|
|
Shinya Kitaoka |
120a6e |
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void HistogramPopup::setTitle(QString title) { setWindowTitle(title); }
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void HistogramPopup::setImage(TImageP image) {
|
|
Shinya Kitaoka |
120a6e |
TRasterImageP rimg = (TRasterImageP)image;
|
|
Shinya Kitaoka |
120a6e |
TVectorImageP vimg = (TVectorImageP)image;
|
|
Shinya Kitaoka |
120a6e |
TToonzImageP timg = (TToonzImageP)image;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TPaletteP palette;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
TRasterP ras;
|
|
Shinya Kitaoka |
120a6e |
if (rimg)
|
|
Shinya Kitaoka |
120a6e |
ras = rimg->getRaster();
|
|
Shinya Kitaoka |
120a6e |
else if (timg) {
|
|
Shinya Kitaoka |
120a6e |
ras = timg->getRaster();
|
|
Shinya Kitaoka |
120a6e |
palette = timg->getPalette();
|
|
Shinya Kitaoka |
120a6e |
} else if (vimg)
|
|
Shinya Kitaoka |
120a6e |
ras = vimg->render(false);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_histogram->setRaster(ras, palette);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*! show the picked color
|
|
shun-iwasawa |
d5045c |
*/
|
|
Shinya Kitaoka |
120a6e |
void HistogramPopup::updateInfo(const TPixel32 &pix, const TPointD &imagePos) {
|
|
Shinya Kitaoka |
120a6e |
m_histogram->updateInfo(pix, imagePos);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
d5045c |
void HistogramPopup::updateInfo(const TPixel64 &pix, const TPointD &imagePos) {
|
|
shun-iwasawa |
d5045c |
m_histogram->updateInfo(pix, imagePos);
|
|
shun-iwasawa |
d5045c |
}
|
|
shun-iwasawa |
d5045c |
|
|
shun-iwasawa |
481b59 |
void HistogramPopup::updateInfo(const TPixelF &pix, const TPointD &imagePos) {
|
|
shun-iwasawa |
481b59 |
m_histogram->updateInfo(pix, imagePos);
|
|
shun-iwasawa |
481b59 |
}
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*! show the average-picked color
|
|
shun-iwasawa |
d5045c |
*/
|
|
Shinya Kitaoka |
120a6e |
void HistogramPopup::updateAverageColor(const TPixel32 &pix) {
|
|
Shinya Kitaoka |
120a6e |
m_histogram->updateAverageColor(pix);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
d5045c |
void HistogramPopup::updateAverageColor(const TPixel64 &pix) {
|
|
shun-iwasawa |
d5045c |
m_histogram->updateAverageColor(pix);
|
|
shun-iwasawa |
d5045c |
}
|
|
shun-iwasawa |
481b59 |
|
|
shun-iwasawa |
481b59 |
void HistogramPopup::updateAverageColor(const TPixelF &pix) {
|
|
shun-iwasawa |
481b59 |
m_histogram->updateAverageColor(pix);
|
|
shun-iwasawa |
481b59 |
}
|
|
shun-iwasawa |
d5045c |
//-----------------------------------------------------------------------------
|
|
shun-iwasawa |
d5045c |
|
|
shun-iwasawa |
d5045c |
void HistogramPopup::setShowCompare(bool on) {
|
|
shun-iwasawa |
d5045c |
m_histogram->setShowCompare(on);
|
|
shun-iwasawa |
d5045c |
}
|
|
shun-iwasawa |
d5045c |
|
|
shun-iwasawa |
d5045c |
//-----------------------------------------------------------------------------
|
|
shun-iwasawa |
d5045c |
|
|
shun-iwasawa |
d5045c |
void HistogramPopup::invalidateCompHisto() {
|
|
shun-iwasawa |
d5045c |
m_histogram->invalidateCompHisto();
|
|
shun-iwasawa |
d5045c |
}
|
|
shun-iwasawa |
d5045c |
|
|
shun-iwasawa |
2cda63 |
//-----------------------------------------------------------------------------
|
|
shun-iwasawa |
2cda63 |
|
|
shun-iwasawa |
2cda63 |
void HistogramPopup::moveNextToWidget(QWidget *widget) {
|
|
shun-iwasawa |
2cda63 |
if (!widget) return;
|
|
shun-iwasawa |
2cda63 |
const int margin = 5;
|
|
shun-iwasawa |
2cda63 |
|
|
shun-iwasawa |
2cda63 |
if (minimumSize().isEmpty()) grab();
|
|
shun-iwasawa |
2cda63 |
QSize popupSize = frameSize();
|
|
shun-iwasawa |
2cda63 |
|
|
shun-iwasawa |
2cda63 |
int currentScreen = QApplication::desktop()->screenNumber(widget);
|
|
shun-iwasawa |
2cda63 |
QRect screenRect = QApplication::desktop()->availableGeometry(currentScreen);
|
|
shun-iwasawa |
2cda63 |
QRect viewerRect = widget->rect();
|
|
shun-iwasawa |
2cda63 |
viewerRect.moveTo(widget->mapToGlobal(QPoint(0, 0)));
|
|
shun-iwasawa |
2cda63 |
// decide which side to open the popup
|
|
shun-iwasawa |
2cda63 |
QPoint popupPos = widget->mapToGlobal(QPoint(0, 0));
|
|
shun-iwasawa |
2cda63 |
// open at the left
|
|
shun-iwasawa |
2cda63 |
if (viewerRect.left() - screenRect.left() >
|
|
shun-iwasawa |
2cda63 |
screenRect.right() - viewerRect.right())
|
|
shun-iwasawa |
2cda63 |
popupPos.setX(std::max(viewerRect.left() - popupSize.width() - margin, 0));
|
|
shun-iwasawa |
2cda63 |
// open at the right
|
|
shun-iwasawa |
2cda63 |
else
|
|
shun-iwasawa |
2cda63 |
popupPos.setX(std::min(viewerRect.right() + margin,
|
|
shun-iwasawa |
2cda63 |
screenRect.right() - popupSize.width()));
|
|
shun-iwasawa |
2cda63 |
// adjust vertical position
|
|
shun-iwasawa |
2cda63 |
popupPos.setY(std::min(std::max(popupPos.y(), screenRect.top()),
|
|
shun-iwasawa |
2cda63 |
screenRect.bottom() - popupSize.height() - margin));
|
|
shun-iwasawa |
2cda63 |
move(popupPos);
|
|
shun-iwasawa |
2cda63 |
}
|
|
shun-iwasawa |
2cda63 |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
/*! \class ViewerHistogramPopup
|
|
Shinya Kitaoka |
120a6e |
\brief The ViewerHistogramPopup show the histogram pertain to
|
|
Shinya Kitaoka |
120a6e |
current viewer.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
Inherits \b Dialog.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
ViewerHistogramPopup::ViewerHistogramPopup()
|
|
Shinya Kitaoka |
120a6e |
: HistogramPopup(tr("Viewer Histogram")) {}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ViewerHistogramPopup::showEvent(QShowEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
connect(TApp::instance()->getCurrentFrame(), SIGNAL(frameSwitched()),
|
|
Shinya Kitaoka |
120a6e |
SLOT(setCurrentRaster()));
|
|
Shinya Kitaoka |
120a6e |
connect(Previewer::instance(), SIGNAL(activedChanged()),
|
|
Shinya Kitaoka |
120a6e |
SLOT(setCurrentRaster()));
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
setCurrentRaster();
|
|
shun-iwasawa |
2cda63 |
moveNextToWidget(TApp::instance()->getActiveViewer());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ViewerHistogramPopup::hideEvent(QHideEvent *e) {
|
|
Shinya Kitaoka |
120a6e |
disconnect(TApp::instance()->getCurrentFrame(), SIGNAL(frameSwitched()), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(setCurrentRaster()));
|
|
Shinya Kitaoka |
120a6e |
disconnect(Previewer::instance(), SIGNAL(activedChanged()), this,
|
|
Shinya Kitaoka |
120a6e |
SLOT(setCurrentRaster()));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void ViewerHistogramPopup::setCurrentRaster() {
|
|
Shinya Kitaoka |
120a6e |
TApp *app = TApp::instance();
|
|
Shinya Kitaoka |
120a6e |
Previewer *previewer = Previewer::instance();
|
|
Shinya Kitaoka |
120a6e |
TRasterP ras = 0;
|
|
Shinya Kitaoka |
120a6e |
if (previewer->isActive()) {
|
|
Shinya Kitaoka |
120a6e |
int currentFrame = app->getCurrentFrame()->getFrameIndex();
|
|
Shinya Kitaoka |
120a6e |
// Se il preview del frame non e' pronto richiamo questo metodo dopo un
|
|
Shinya Kitaoka |
120a6e |
// intervallo di 10 ms
|
|
Shinya Kitaoka |
120a6e |
if (!previewer->isFrameReady(currentFrame)) {
|
|
Shinya Kitaoka |
120a6e |
QTimer::singleShot(10, this, SLOT(setCurrentRaster()));
|
|
Shinya Kitaoka |
120a6e |
return;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
ras = previewer->getRaster(currentFrame);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
m_histogram->setRaster(ras);
|
|
Shinya Kitaoka |
120a6e |
update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
2cda63 |
OpenPopupCommandHandler<viewerhistogrampopup> openHistogramPopup(</viewerhistogrampopup>
|
|
shun-iwasawa |
2cda63 |
MI_ViewerHistogram);
|