diff --git a/toonz/sources/toonz/sceneviewercontextmenu.cpp b/toonz/sources/toonz/sceneviewercontextmenu.cpp index 59fc78a..b6d752c 100644 --- a/toonz/sources/toonz/sceneviewercontextmenu.cpp +++ b/toonz/sources/toonz/sceneviewercontextmenu.cpp @@ -28,6 +28,7 @@ #include "toonz/txshcolumn.h" #include "toonz/tstageobjectspline.h" #include "toonz/tstageobjectid.h" +#include "toonz/preferences.h" // TnzCore includes #include "tvectorimage.h" @@ -163,7 +164,7 @@ SceneViewerContextMenu::SceneViewerContextMenu(SceneViewer *parent) // onion skin #ifndef STUDENT - if (!parent->isPreviewEnabled()) + if (Preferences::instance()->isOnionSkinEnabled() && !parent->isPreviewEnabled()) OnioniSkinMaskGUI::addOnionSkinCommand(this); #endif diff --git a/toonz/sources/toonz/xshrowviewer.cpp b/toonz/sources/toonz/xshrowviewer.cpp index c53fe61..c211e45 100644 --- a/toonz/sources/toonz/xshrowviewer.cpp +++ b/toonz/sources/toonz/xshrowviewer.cpp @@ -19,6 +19,7 @@ #include "toonz/txsheet.h" #include "toonz/sceneproperties.h" #include "toutputproperties.h" +#include "toonz/preferences.h" #include #include @@ -39,7 +40,7 @@ RowArea::RowArea(XsheetViewer *parent, Qt::WindowFlags flags) #else RowArea::RowArea(XsheetViewer *parent, Qt::WFlags flags) #endif - : QWidget(parent, flags), m_viewer(parent), m_xa(ColumnWidth / 2 - 12), m_row(-1), m_showOnionToSet(false), m_pos(-1, -1), m_playRangeActiveInMousePress(false), m_mousePressRow(-1), m_tooltip(tr("")), m_r0(0), m_r1(5), m_isPanning(false) + : QWidget(parent, flags), m_viewer(parent), m_xa(ColumnWidth / 2 - 12), m_row(-1), m_showOnionToSet(None), m_pos(-1, -1), m_playRangeActiveInMousePress(false), m_mousePressRow(-1), m_tooltip(tr("")), m_r0(0), m_r1(5), m_isPanning(false) { setFocusPolicy(Qt::NoFocus); setMouseTracking(true); @@ -197,6 +198,7 @@ void RowArea::drawPlayRange(QPainter &p, int r0, int r1) } QColor ArrowColor = (playRangeEnabled) ? QColor(255, 255, 255) : grey150; + p.setBrush(QBrush(ArrowColor)); if (m_r0 > r0 - 1 && r1 + 1 > m_r0) { int y0 = m_viewer->rowToY(m_r0); @@ -238,58 +240,106 @@ void RowArea::drawOnionSkinSelection(QPainter &p) assert(xsh); int currentRow = m_viewer->getCurrentRow(); - if (m_showOnionToSet) { - int y = m_viewer->rowToY(m_row) + 3; - QRect rect(m_xa - 6, y + 1, 4, 4); - p.setPen(m_viewer->getDarkLineColor()); - p.drawRect(rect); - p.fillRect(rect.adjusted(1, 1, 0, 0), QBrush(m_viewer->getLightLineColor())); + // get onion colors + TPixel frontPixel, backPixel; + bool inksOnly; + Preferences::instance()->getOnionData(frontPixel, backPixel, inksOnly); + QColor frontColor((int)frontPixel.r, (int)frontPixel.g, (int)frontPixel.b, 128); + QColor backColor((int)backPixel.r, (int)backPixel.g, (int)backPixel.b, 128); + + int onionDotDiam = 8; + int onionHandleDiam = RowHeight - 1; + int onionDotYPos = (RowHeight - onionDotDiam) / 2; + + // If the onion skin is disabled, draw dash line instead. + if (osMask.isEnabled()) + p.setPen(Qt::red); + else + { + QPen currentPen = p.pen(); + currentPen.setStyle(Qt::DashLine); + currentPen.setColor(QColor(128, 128, 128, 255)); + p.setPen(currentPen); } - if (!osMask.isEnabled()) - return; + // Draw onion skin extender handles. + QRectF handleRect(3, m_viewer->rowToY(currentRow) + 1, onionHandleDiam, onionHandleDiam ); + int angle180 = 16 * 180; + p.setBrush(QBrush(backColor)); + p.drawChord(handleRect, 0, angle180); + p.setBrush(QBrush(frontColor)); + p.drawChord(handleRect, angle180, angle180); + + //-- draw movable onions + + // draw line between onion skin range + int minMos = 0; + int maxMos = 0; + int mosCount = osMask.getMosCount(); + for (int i = 0; i < mosCount; i++) { + int mos = osMask.getMos(i); + if (minMos > mos) + minMos = mos; + if (maxMos < mos) + maxMos = mos; + } + p.setBrush(Qt::NoBrush); + if (minMos < 0) // previous frames + { + int y0 = m_viewer->rowToY(currentRow + minMos) + onionDotYPos + onionDotDiam; + int y1 = m_viewer->rowToY(currentRow); + p.drawLine(onionDotDiam*1.5, y0, onionDotDiam*1.5, y1); + } + if (maxMos > 0) // foward frames + { + int y0 = m_viewer->rowToY(currentRow + 1); + int y1 = m_viewer->rowToY(currentRow + maxMos) + onionDotYPos; + p.drawLine(onionDotDiam*1.5, y0, onionDotDiam*1.5, y1); + } + + // draw onion skin dots + p.setPen(Qt::red); + for (int i = 0; i < mosCount; i++) { + // mos : frame offset from the current frame + int mos = osMask.getMos(i); + // skip drawing if the frame is under the mouse cursor + if (m_showOnionToSet == Mos && currentRow + mos == m_row) + continue; + int y = m_viewer->rowToY(currentRow + mos) + onionDotYPos; - int i; - for (i = 0; i < osMask.getFosCount(); i++) { + if (osMask.isEnabled()) + p.setBrush(mos < 0 ? backColor : frontColor); + else + p.setBrush(Qt::NoBrush); + p.drawEllipse(onionDotDiam, y, onionDotDiam, onionDotDiam); + } + + //-- draw fixed onions + for (int i = 0; i < osMask.getFosCount(); i++) + { int fos = osMask.getFos(i); - if (fos == currentRow) + if (fos == currentRow) continue; + // skip drawing if the frame is under the mouse cursor + if (m_showOnionToSet == Fos && fos == m_row) continue; - int y = m_viewer->rowToY(fos) + 3; - QRect rect(m_xa - 6, y + 1, 4, 4); - p.setPen(Qt::black); - p.drawRect(rect); - p.fillRect(rect.adjusted(1, 1, 0, 0), QBrush(m_viewer->getDarkLineColor())); + int y = m_viewer->rowToY(fos) + onionDotYPos; + + if (osMask.isEnabled()) + p.setBrush(QBrush(QColor(0, 255, 255, 128))); + else + p.setBrush(Qt::NoBrush); + p.drawEllipse(0, y, onionDotDiam, onionDotDiam); } - int lastY; - int xc = m_xa - 10; -#ifndef STUDENT - int mosCount = osMask.getMosCount(); - for (i = 0; i < mosCount; i++) { - int mos = osMask.getMos(i); - int y = m_viewer->rowToY(currentRow + mos) + 3; - QRect rect(m_xa - 12, y + 1, 4, 4); - p.setPen(Qt::black); - p.drawRect(rect); - p.fillRect(rect.adjusted(1, 1, 0, 0), QBrush(m_viewer->getLightLineColor())); - if (i > 0 || mos > 0) { - int ya = y; - int yb; - if (i == 0 || mos > 0 && osMask.getMos(i - 1) < 0) - yb = m_viewer->rowToY(currentRow) + RowHeight; - else - yb = lastY + 5; - p.setPen(Qt::black); - p.drawLine(xc, ya, xc, yb); - } - lastY = y; - if (mos < 0 && (i == mosCount - 1 || osMask.getMos(i + 1) > 0)) { - int ya = m_viewer->rowToY(currentRow); - int yb = lastY + 5; - p.setPen(Qt::black); - p.drawLine(xc, ya, xc, yb); - } + + //-- draw highlighted onion + if (m_showOnionToSet != None) + { + int y = m_viewer->rowToY(m_row) + onionDotYPos; + int xPos = (m_showOnionToSet == Fos) ? 0 : onionDotDiam; + p.setPen(QColor(255, 128, 0)); + p.setBrush(QBrush(QColor(255, 255, 0, 200))); + p.drawEllipse(xPos, y, onionDotDiam, onionDotDiam); } -#endif } //----------------------------------------------------------------------------- @@ -309,14 +359,15 @@ void RowArea::paintEvent(QPaintEvent *event) //fill background p.fillRect(toBeUpdated, m_viewer->getBGColor()); - if (TApp::instance()->getCurrentFrame()->isEditingScene()) { + if (TApp::instance()->getCurrentFrame()->isEditingScene()) //current frame drawCurrentRowGadget(p, r0, r1); - //TODO: Scene上のオニオンスキン表示、オプション化するか検討 2016/1/6 shun_iwasawa - //drawOnionSkinSelection(p); - } drawRows(p, r0, r1); + + if (TApp::instance()->getCurrentFrame()->isEditingScene() && Preferences::instance()->isOnionSkinEnabled()) + drawOnionSkinSelection(p); + drawPlayRange(p, r0, r1); } @@ -326,37 +377,58 @@ void RowArea::mousePressEvent(QMouseEvent *event) { m_viewer->setQtModifiers(event->modifiers()); if (event->button() == Qt::LeftButton) { - bool playRangeModifierisClicked = false; + bool frameAreaIsClicked = false; TApp *app = TApp::instance(); TXsheet *xsh = app->getCurrentScene()->getScene()->getXsheet(); TPoint pos(event->pos().x(), event->pos().y()); + int currentFrame = TApp::instance()->getCurrentFrame()->getFrame(); int row = m_viewer->yToRow(pos.y); - QRect visibleRect = visibleRegion().boundingRect(); - int playR0, playR1, step; - XsheetGUI::getPlayRange(playR0, playR1, step); - - bool playRangeEnabled = playR0 <= playR1; - if (!playRangeEnabled) { - TXsheet *xsh = m_viewer->getXsheet(); - playR1 = xsh->getFrameCount() - 1; - playR0 = 0; + int onionDotDiam = 8; + if (Preferences::instance()->isOnionSkinEnabled() && + ((row == currentFrame && pos.x < RowHeight + 2) || (pos.x < onionDotDiam * 2))) + { + if (row == currentFrame) + { + setDragTool(XsheetGUI::DragTool::makeCurrentFrameModifierTool(m_viewer)); + frameAreaIsClicked = true; + } + else if (pos.x <= onionDotDiam) + setDragTool(XsheetGUI::DragTool::makeKeyOnionSkinMaskModifierTool(m_viewer, true)); + else + setDragTool(XsheetGUI::DragTool::makeKeyOnionSkinMaskModifierTool(m_viewer, false)); } + else + { + int playR0, playR1, step; + XsheetGUI::getPlayRange(playR0, playR1, step); + + bool playRangeEnabled = playR0 <= playR1; + if (!playRangeEnabled) { + TXsheet *xsh = m_viewer->getXsheet(); + playR1 = xsh->getFrameCount() - 1; + playR0 = 0; + } - if (playR1 == -1) { //getFrameCount = 0 i.e. xsheet is empty - setDragTool(XsheetGUI::DragTool::makeCurrentFrameModifierTool(m_viewer)); - } else if (m_xa <= pos.x && pos.x <= m_xa + 10 && (row == playR0 || row == playR1)) { - if (!playRangeEnabled) - XsheetGUI::setPlayRange(playR0, playR1, step); - setDragTool(XsheetGUI::DragTool::makePlayRangeModifierTool(m_viewer)); - playRangeModifierisClicked = true; - } else - setDragTool(XsheetGUI::DragTool::makeCurrentFrameModifierTool(m_viewer)); - + if (playR1 == -1) { //getFrameCount = 0 i.e. xsheet is empty + setDragTool(XsheetGUI::DragTool::makeCurrentFrameModifierTool(m_viewer)); + frameAreaIsClicked = true; + } + else if (m_xa <= pos.x && pos.x <= m_xa + 10 && (row == playR0 || row == playR1)) { + if (!playRangeEnabled) + XsheetGUI::setPlayRange(playR0, playR1, step); + setDragTool(XsheetGUI::DragTool::makePlayRangeModifierTool(m_viewer)); + } + else + { + setDragTool(XsheetGUI::DragTool::makeCurrentFrameModifierTool(m_viewer)); + frameAreaIsClicked = true; + } + } //when shift+click the row area, select a single row region in the cell area - if (!playRangeModifierisClicked && 0 != (event->modifiers() & Qt::ShiftModifier)) { + if (frameAreaIsClicked && 0 != (event->modifiers() & Qt::ShiftModifier)) { int filledCol; for (filledCol = xsh->getColumnCount() - 1; filledCol >= 0; filledCol--) { TXshColumn *currentColumn = xsh->getColumn(filledCol); @@ -408,20 +480,25 @@ void RowArea::mouseMoveEvent(QMouseEvent *event) m_pos = pos; m_viewer->dragToolDrag(event); - if (getDragTool()) { - m_showOnionToSet = false; + + m_showOnionToSet = None; + + if (getDragTool()) return; - } int currentRow = TApp::instance()->getCurrentFrame()->getFrame(); int row = m_viewer->yToRow(m_pos.y()); if (row < 0) return; // "decide" se mostrare la possibilita' di settare l'onion skin - if (7 <= x && x <= 13 && row != currentRow) - m_showOnionToSet = true; - else - m_showOnionToSet = false; + if (Preferences::instance()->isOnionSkinEnabled()) + { + int onionDotDiam = 8; + if (x <= onionDotDiam && row != currentRow) + m_showOnionToSet = Fos; + else if (x <= onionDotDiam * 2 && row != currentRow) + m_showOnionToSet = Mos; + } update(); if (m_xa <= x && x <= m_xa + 10 && row == m_r0) @@ -429,7 +506,16 @@ void RowArea::mouseMoveEvent(QMouseEvent *event) else if (m_xa <= x && x <= m_xa + 10 && row == m_r1) m_tooltip = tr("Playback End Marker"); else if (row == currentRow) - m_tooltip = tr("Curren Frame"); + { + if (Preferences::instance()->isOnionSkinEnabled() && x < RowHeight + 2) + m_tooltip = tr("Double Click to Toggle Onion Skin"); + else + m_tooltip = tr("Curren Frame"); + } + else if (m_showOnionToSet == Fos) + m_tooltip = tr("Fixed Onion Skin Toggle"); + else if (m_showOnionToSet == Mos) + m_tooltip = tr("Relative Onion Skin Toggle"); else m_tooltip = tr(""); } @@ -473,6 +559,12 @@ void RowArea::contextMenuEvent(QContextMenuEvent *event) menu->addSeparator(); + if (Preferences::instance()->isOnionSkinEnabled()) + { + OnioniSkinMaskGUI::addOnionSkinCommand(menu); + menu->addSeparator(); + } + CommandManager *cmdManager = CommandManager::instance(); menu->addAction(cmdManager->getAction(MI_InsertSceneFrame)); menu->addAction(cmdManager->getAction(MI_RemoveSceneFrame)); @@ -493,6 +585,26 @@ void RowArea::contextMenuEvent(QContextMenuEvent *event) //----------------------------------------------------------------------------- +void RowArea::mouseDoubleClickEvent(QMouseEvent* event) +{ + int currentFrame = TApp::instance()->getCurrentFrame()->getFrame(); + int row = m_viewer->yToRow(event->pos().y()); + if (TApp::instance()->getCurrentFrame()->isEditingScene() && + event->buttons() & Qt::LeftButton && + Preferences::instance()->isOnionSkinEnabled() && + row == currentFrame && + event->pos().x() < RowHeight + 2 ) + { + TOnionSkinMaskHandle *osmh = TApp::instance()->getCurrentOnionSkin(); + OnionSkinMask osm = osmh->getOnionSkinMask(); + osm.enable(!osm.isEnabled()); + osmh->setOnionSkinMask(osm); + osmh->notifyOnionSkinMaskChanged(); + } +} + +//----------------------------------------------------------------------------- + bool RowArea::event(QEvent *event) { if (event->type() == QEvent::ToolTip) { diff --git a/toonz/sources/toonz/xshrowviewer.h b/toonz/sources/toonz/xshrowviewer.h index d4b8d36..6a8496a 100644 --- a/toonz/sources/toonz/xshrowviewer.h +++ b/toonz/sources/toonz/xshrowviewer.h @@ -25,7 +25,13 @@ class RowArea : public QWidget XsheetViewer *m_viewer; int m_xa; int m_row; - bool m_showOnionToSet; + + enum ShowOnionToSetFlag + { + None = 0, + Fos, + Mos + }m_showOnionToSet;//TODO:�����͂����Fos,Mos�ǂ�����n�C���C�g���Ă���̂����肳����I�I�I�I // Play ranges int m_r0; @@ -62,6 +68,7 @@ protected: void mouseMoveEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); void contextMenuEvent(QContextMenuEvent *event); + void mouseDoubleClickEvent(QMouseEvent* event); bool event(QEvent *event); void setMarker(int index); diff --git a/toonz/sources/toonzlib/onionskinmask.cpp b/toonz/sources/toonzlib/onionskinmask.cpp index a6c9e23..26ace5a 100644 --- a/toonz/sources/toonzlib/onionskinmask.cpp +++ b/toonz/sources/toonzlib/onionskinmask.cpp @@ -234,10 +234,9 @@ void OnionSkinMaskModifier::click(int row, bool isFos) m_curMask.setMos(drow, false); } else if (drow == 0) { m_status = 8 + 4 + 1; // accendere mos; partito da 0 - } else if (!m_curMask.isEnabled()) { - // e' disabilitato e ho fatto click in un punto vuoto: non faccio niente - m_status = 128; // errore } else { + if (!m_curMask.isEnabled()) + m_curMask.enable(true); m_curMask.setMos(drow, true); m_status = 4 + 1; // accendere mos; } diff --git a/toonz/sources/toonzlib/preferences.cpp b/toonz/sources/toonzlib/preferences.cpp index ff15e7f..a3cf3ac 100644 --- a/toonz/sources/toonzlib/preferences.cpp +++ b/toonz/sources/toonzlib/preferences.cpp @@ -227,7 +227,7 @@ bool Preferences::LevelFormat::matches(const TFilePath &fp) const //********************************************************************************** Preferences::Preferences() - : m_units("mm"), m_cameraUnits("inch"), m_scanLevelType("tif"), m_defLevelWidth(0.0), m_defLevelHeight(0.0), m_defLevelDpi(0.0), m_iconSize(160, 120), m_blankColor(TPixel32::White), m_frontOnionColor(TPixel::Black), m_backOnionColor(TPixel::Black), m_transpCheckBg(TPixel::White), m_transpCheckInk(TPixel::Black), m_transpCheckPaint(TPixel(127, 127, 127)), m_autosavePeriod(15), m_chunkSize(10), m_rasterOptimizedMemory(0), m_shrink(1), m_step(1), m_blanksCount(0), m_keyframeType(3), m_animationStep(1), m_textureSize(0), m_xsheetStep(10), m_shmmax(-1), m_shmseg(-1), m_shmall(-1), m_shmmni(-1), m_onionPaperThickness(50), m_currentLanguage(0), m_currentStyleSheet(0), m_undoMemorySize(100), m_dragCellsBehaviour(0), m_lineTestFpsCapture(25), m_defLevelType(0), m_autocreationType(1), m_autoExposeEnabled(true), m_autoCreateEnabled(true), m_subsceneFolderEnabled(true), m_generatedMovieViewEnabled(true), m_xsheetAutopanEnabled(true), m_ignoreAlphaonColumn1Enabled(false), m_rewindAfterPlaybackEnabled(true), m_fitToFlipbookEnabled(false), m_previewAlwaysOpenNewFlipEnabled(false), m_autosaveEnabled(false), m_defaultViewerEnabled(false), m_saveUnpaintedInCleanup(true), m_askForOverrideRender(true), m_automaticSVNFolderRefreshEnabled(true), m_SVNEnabled(false), m_minimizeSaveboxAfterEditing(true), m_levelsBackupEnabled(false), m_sceneNumberingEnabled(false), m_animationSheetEnabled(false), m_inksOnly(false), m_fillOnlySavebox(false), m_show0ThickLines(true), m_regionAntialias(false), m_viewerBGColor(128, 128, 128, 255), m_previewBGColor(64, 64, 64, 255), m_chessboardColor1(180, 180, 180), m_chessboardColor2(230, 230, 230), m_showRasterImagesDarkenBlendedInViewer(false), m_actualPixelViewOnSceneEditingMode(false), m_viewerZoomCenter(0), m_initialLoadTlvCachingBehavior(0), m_removeSceneNumberFromLoadedLevelName(false), m_replaceAfterSaveLevelAs(true), m_showFrameNumberWithLetters(false), m_levelNameOnEachMarker(false), m_columnIconLoadingPolicy((int)LoadAtOnce), m_moveCurrentFrameByClickCellArea(true), m_onionSkinEnabled(false), m_multiLayerStylePickerEnabled(false), m_paletteTypeOnLoadRasterImageAsColorModel(0), m_showKeyframesOnXsheetCellArea(true) + : m_units("mm"), m_cameraUnits("inch"), m_scanLevelType("tif"), m_defLevelWidth(0.0), m_defLevelHeight(0.0), m_defLevelDpi(0.0), m_iconSize(160, 120), m_blankColor(TPixel32::White), m_frontOnionColor(TPixel::Black), m_backOnionColor(TPixel::Black), m_transpCheckBg(TPixel::White), m_transpCheckInk(TPixel::Black), m_transpCheckPaint(TPixel(127, 127, 127)), m_autosavePeriod(15), m_chunkSize(10), m_rasterOptimizedMemory(0), m_shrink(1), m_step(1), m_blanksCount(0), m_keyframeType(3), m_animationStep(1), m_textureSize(0), m_xsheetStep(10), m_shmmax(-1), m_shmseg(-1), m_shmall(-1), m_shmmni(-1), m_onionPaperThickness(50), m_currentLanguage(0), m_currentStyleSheet(0), m_undoMemorySize(100), m_dragCellsBehaviour(0), m_lineTestFpsCapture(25), m_defLevelType(0), m_autocreationType(1), m_autoExposeEnabled(true), m_autoCreateEnabled(true), m_subsceneFolderEnabled(true), m_generatedMovieViewEnabled(true), m_xsheetAutopanEnabled(true), m_ignoreAlphaonColumn1Enabled(false), m_rewindAfterPlaybackEnabled(true), m_fitToFlipbookEnabled(false), m_previewAlwaysOpenNewFlipEnabled(false), m_autosaveEnabled(false), m_defaultViewerEnabled(false), m_saveUnpaintedInCleanup(true), m_askForOverrideRender(true), m_automaticSVNFolderRefreshEnabled(true), m_SVNEnabled(false), m_minimizeSaveboxAfterEditing(true), m_levelsBackupEnabled(false), m_sceneNumberingEnabled(false), m_animationSheetEnabled(false), m_inksOnly(false), m_fillOnlySavebox(false), m_show0ThickLines(true), m_regionAntialias(false), m_viewerBGColor(128, 128, 128, 255), m_previewBGColor(64, 64, 64, 255), m_chessboardColor1(180, 180, 180), m_chessboardColor2(230, 230, 230), m_showRasterImagesDarkenBlendedInViewer(false), m_actualPixelViewOnSceneEditingMode(false), m_viewerZoomCenter(0), m_initialLoadTlvCachingBehavior(0), m_removeSceneNumberFromLoadedLevelName(false), m_replaceAfterSaveLevelAs(true), m_showFrameNumberWithLetters(false), m_levelNameOnEachMarker(false), m_columnIconLoadingPolicy((int)LoadAtOnce), m_moveCurrentFrameByClickCellArea(true), m_onionSkinEnabled(true), m_multiLayerStylePickerEnabled(false), m_paletteTypeOnLoadRasterImageAsColorModel(0), m_showKeyframesOnXsheetCellArea(true) { TCamera camera; m_defLevelType = PLI_XSHLEVEL;