TImage *TTool::getImage(bool toBeModified, int subsampling) { assert(m_application); if (m_application->getCurrentFrame()->isPlaying()) toBeModified = false; // In playback mode, you are not going to modify images // Probably useless - tools are disabled when playing... const TXshCell &cell = getImageCell(); if (cell.isEmpty()) { TObjectHandle *currentObject = m_application->getCurrentObject(); return currentObject->isSpline() ? currentObject->getSplineImage() : (TImage *)0; } else return cell.getImage(toBeModified, subsampling).getPointer(); }
void SceneViewer::keyReleaseEvent(QKeyEvent *event) { if (m_freezedStatus != NO_FREEZED) return; TTool *tool = TApp::instance()->getCurrentTool()->getTool(); if (!tool || !tool->isEnabled()) return; tool->setViewer(this); int key = event->key(); if (key == Qt::Key_Shift || key == Qt::Key_Control || key == Qt::Key_Alt || key == Qt::Key_AltGr) { if (key == Qt::Key_Shift) modifiers &= ~Qt::ShiftModifier; else if (key == Qt::Key_Control) modifiers &= ~Qt::ControlModifier; else if (key == Qt::Key_Alt || key == Qt::Key_AltGr) modifiers &= ~Qt::AltModifier; // quando l'utente preme shift/ctrl ecc. alcuni tool (es. pinch) devono // cambiare subito la forma del cursore, senza aspettare il prossimo move TMouseEvent toonzEvent; initToonzEvent(toonzEvent, event); toonzEvent.m_pos = TPoint(m_lastMousePos.x(), height() - 1 - m_lastMousePos.y()); TPointD pos = tool->getMatrix().inv() * winToWorld(m_lastMousePos); TObjectHandle *objHandle = TApp::instance()->getCurrentObject(); if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) { pos.x /= m_dpiScale.x; pos.y /= m_dpiScale.y; } tool->mouseMove(pos, toonzEvent); setToolCursor(this, tool->getCursorId()); } if (tool->getName() == T_Type) event->accept(); else event->ignore(); }
void SceneViewer::mouseDoubleClickEvent(QMouseEvent *event) { if (m_freezedStatus != NO_FREEZED) return; int frame = TApp::instance()->getCurrentFrame()->getFrame(); if (frame == -1) return; TTool *tool = TApp::instance()->getCurrentTool()->getTool(); if (!tool || !tool->isEnabled()) return; TMouseEvent toonzEvent; initToonzEvent(toonzEvent, event, height(), m_pressure, m_tabletEvent, true); TPointD pos = tool->getMatrix().inv() * winToWorld(event->pos()); TObjectHandle *objHandle = TApp::instance()->getCurrentObject(); if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) { pos.x /= m_dpiScale.x; pos.y /= m_dpiScale.y; } if (event->button() == Qt::LeftButton) tool->leftButtonDoubleClick(pos, toonzEvent); }
/*! Notify change of current image: update icon and notify level change. If current object is a spline commit spline chenged. If current mode is EditingLevel touch current frame. */ void TTool::notifyImageChanged() { onImageChanged(); if (!m_application) return; m_application->getCurrentScene()->setDirtyFlag(true); if (m_application->getCurrentFrame()->isEditingLevel()) { TXshLevel *xl = m_application->getCurrentLevel()->getLevel(); if (!xl) return; TXshSimpleLevel *sl = xl->getSimpleLevel(); if (!sl) return; TFrameId fid = m_application->getCurrentFrame()->getFid(); sl->touchFrame(fid); // sl->setDirtyFlag(true); IconGenerator::instance()->invalidate(sl, fid); IconGenerator::instance()->invalidateSceneIcon(); } else { TXsheet *xsh = m_application->getCurrentXsheet()->getXsheet(); if (!xsh) return; TObjectHandle *currentObject = m_application->getCurrentObject(); if (currentObject->isSpline()) { m_application->getCurrentObject()->commitSplineChanges(); TStageObject *pegbar = xsh->getStageObject(currentObject->getObjectId()); IconGenerator::instance()->invalidate(pegbar->getSpline()); } else { int row = m_application->getCurrentFrame()->getFrame(); int col = m_application->getCurrentColumn()->getColumnIndex(); if (col < 0) return; TXshCell cell = xsh->getCell(row, col); TXshSimpleLevel *sl = cell.getSimpleLevel(); if (sl) { IconGenerator::instance()->invalidate(sl, cell.m_frameId); sl->touchFrame(cell.m_frameId); IconGenerator::instance()->invalidateSceneIcon(); } } } m_application->getCurrentLevel()->notifyLevelChange(); }
void FilmstripFrames::select(int index, SelectionMode mode) { TXshSimpleLevel *sl = getLevel(); bool outOfRange = !sl || index < 0 || index >= sl->getFrameCount(); TFrameId fid; if (!outOfRange) fid = index2fid(index); switch (mode) { // select one frame only case ONLY_SELECT: m_selection->selectNone(); if (!outOfRange) m_selection->select(fid); break; case SIMPLE_SELECT: // Bail out if fid is already selected if (!outOfRange && m_selection->isSelected(fid)) return; m_selection->selectNone(); if (!outOfRange) m_selection->select(fid); break; case SHIFT_SELECT: if (outOfRange) return; // Bail out if fid is already selected if (m_selection->isSelected(fid)) return; if (m_selection->isEmpty()) m_selection->select(fid); else { TXshSimpleLevel *sl = getLevel(); if (!sl) return; // seleziono il range da fid al piu' vicino frame selezionato (in entrambe // le direzioni) int frameCount = sl->getFrameCount(); // calcolo il limite inferiore della selezione int ia = index; while (ia > 0 && !m_selection->isSelected(sl->index2fid(ia - 1))) ia--; if (ia == 0) ia = index; // calcolo il limite superiore della selezione int ib = index; while (ib < frameCount - 1 && !m_selection->isSelected(sl->index2fid(ib + 1))) ib++; if (ib == frameCount - 1) ib = index; // seleziono for (int i = ia; i <= ib; i++) m_selection->select(sl->index2fid(i)); } break; case CTRL_SELECT: if (outOfRange) return; m_selection->select(fid, !m_selection->isSelected(fid)); break; case START_DRAG_SELECT: m_selection->selectNone(); if (outOfRange) { m_dragSelectionStartIndex = m_dragSelectionEndIndex = -1; break; } m_selection->select(fid); m_dragSelectionStartIndex = index; break; case DRAG_SELECT: if (outOfRange || m_dragSelectionStartIndex < 0 || m_dragSelectionEndIndex == index) return; m_dragSelectionEndIndex = index; m_selection->selectNone(); int ia = m_dragSelectionStartIndex; int ib = index; if (ia > ib) std::swap(ia, ib); for (int i = ia; i <= ib; ++i) m_selection->select(index2fid(i)); break; } TObjectHandle *objectHandle = TApp::instance()->getCurrentObject(); if (objectHandle->isSpline()) objectHandle->setIsSpline(false); // Update current selection m_selection->makeCurrent(); TSelectionHandle *selHandle = TApp::instance()->getCurrentSelection(); selHandle->notifySelectionChanged(); }
void SceneViewer::keyPressEvent(QKeyEvent *event) { if (m_freezedStatus != NO_FREEZED) return; int key = event->key(); if (changeFrameSkippingHolds(event)) { return; } if ((event->modifiers() & Qt::ShiftModifier) && (key == Qt::Key_Down || key == Qt::Key_Up)) { } TTool *tool = TApp::instance()->getCurrentTool()->getTool(); if (!tool) return; bool isTextToolActive = tool->getName() == T_Type && tool->isActive(); if (!isTextToolActive && ViewerZoomer(this).exec(event)) return; if (!isTextToolActive && SceneViewerShortcutReceiver(this).exec(event)) return; if (!tool->isEnabled()) return; tool->setViewer(this); // If this object is child of Viewer or ComboViewer // (m_isStyleShortcutSelective = true), // then consider about shortcut for the current style selection. if (m_isStyleShortcutSwitchable && Preferences::instance()->isUseNumpadForSwitchingStylesEnabled() && (!isTextToolActive) && (event->modifiers() == Qt::NoModifier || event->modifiers() == Qt::KeypadModifier) && ((Qt::Key_0 <= key && key <= Qt::Key_9) || key == Qt::Key_Tab || key == Qt::Key_Backtab)) { event->ignore(); return; } if (key == Qt::Key_Shift) modifiers |= Qt::SHIFT; else if (key == Qt::Key_Control) modifiers |= Qt::CTRL; else if (key == Qt::Key_Alt || key == Qt::Key_AltGr) modifiers |= Qt::ALT; if (key == Qt::Key_Shift || key == Qt::Key_Control || key == Qt::Key_Alt || key == Qt::Key_AltGr) { // quando l'utente preme shift/ctrl ecc. alcuni tool (es. pinch) devono // cambiare subito la forma del cursore, senza aspettare il prossimo move TMouseEvent toonzEvent; initToonzEvent(toonzEvent, event); toonzEvent.m_pos = TPoint(m_lastMousePos.x(), height() - 1 - m_lastMousePos.y()); TPointD pos = tool->getMatrix().inv() * winToWorld(m_lastMousePos); TObjectHandle *objHandle = TApp::instance()->getCurrentObject(); if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) { pos.x /= m_dpiScale.x; pos.y /= m_dpiScale.y; } tool->mouseMove(pos, toonzEvent); setToolCursor(this, tool->getCursorId()); } bool shiftButton = QApplication::keyboardModifiers() == Qt::ShiftModifier; TUINT32 flags = 0; TPoint pos; if (key == Qt::Key_Shift) flags = TwConsts::TK_ShiftPressed; else if (key == Qt::Key_Control) flags = TwConsts::TK_CtrlPressed; else if (key == Qt::Key_Alt) flags = TwConsts::TK_AltPressed; else if (key == Qt::Key_CapsLock) flags = TwConsts::TK_CapsLock; else if (key == Qt::Key_Backspace) key = TwConsts::TK_Backspace; else if (key == Qt::Key_Return) key = TwConsts::TK_Return; else if (key == Qt::Key_Left && !shiftButton) key = TwConsts::TK_LeftArrow; else if (key == Qt::Key_Right && !shiftButton) key = TwConsts::TK_RightArrow; else if (key == Qt::Key_Up && !shiftButton) key = TwConsts::TK_UpArrow; else if (key == Qt::Key_Down && !shiftButton) key = TwConsts::TK_DownArrow; else if (key == Qt::Key_Left && shiftButton) key = TwConsts::TK_ShiftLeftArrow; else if (key == Qt::Key_Right && shiftButton) key = TwConsts::TK_ShiftRightArrow; else if (key == Qt::Key_Up && shiftButton) key = TwConsts::TK_ShiftUpArrow; else if (key == Qt::Key_Down && shiftButton) key = TwConsts::TK_ShiftDownArrow; else if (key == Qt::Key_Home) key = TwConsts::TK_Home; else if (key == Qt::Key_End) key = TwConsts::TK_End; else if (key == Qt::Key_PageUp) key = TwConsts::TK_PageUp; else if (key == Qt::Key_PageDown) key = TwConsts::TK_PageDown; else if (key == Qt::Key_Insert) key = TwConsts::TK_Insert; else if (key == Qt::Key_Delete) key = TwConsts::TK_Delete; else if (key == Qt::Key_Escape) key = TwConsts::TK_Esc; else if (key == Qt::Key_F1) key = TwConsts::TK_F1; else if (key == Qt::Key_F2) key = TwConsts::TK_F2; else if (key == Qt::Key_F3) key = TwConsts::TK_F3; else if (key == Qt::Key_F4) key = TwConsts::TK_F4; else if (key == Qt::Key_F5) key = TwConsts::TK_F5; else if (key == Qt::Key_F6) key = TwConsts::TK_F6; else if (key == Qt::Key_F7) key = TwConsts::TK_F7; else if (key == Qt::Key_F8) key = TwConsts::TK_F8; else if (key == Qt::Key_F9) key = TwConsts::TK_F9; else if (key == Qt::Key_F10) key = TwConsts::TK_F10; else if (key == Qt::Key_F11) key = TwConsts::TK_F11; else if (key == Qt::Key_F12) key = TwConsts::TK_F12; else if (key == Qt::Key_Menu || key == Qt::Key_Meta) return; bool ret = false; if (tool) // && m_toolEnabled) { QString text = event->text(); if ((event->modifiers() & Qt::ShiftModifier)) text.toUpper(); std::wstring unicodeChar = text.toStdWString(); ret = tool->keyDown(key, unicodeChar, flags, pos); // per il textTool if (ret) { update(); return; } ret = tool->keyDown(key, flags, pos); // per gli altri tool } if (!ret) { TFrameHandle *fh = TApp::instance()->getCurrentFrame(); if (key == TwConsts::TK_UpArrow) fh->prevFrame(); else if (key == TwConsts::TK_DownArrow) fh->nextFrame(); else if (key == TwConsts::TK_Home) fh->firstFrame(); else if (key == TwConsts::TK_End) fh->lastFrame(); } update(); // TODO: devo accettare l'evento? }
void SceneViewer::mouseReleaseEvent(QMouseEvent *event) { // evita i release ripetuti if (!m_buttonClicked) return; m_buttonClicked = false; TTool *tool = TApp::instance()->getCurrentTool()->getTool(); if (!tool || !tool->isEnabled()) { if (!m_toolDisableReason.isEmpty() && m_mouseButton == Qt::LeftButton && !m_editPreviewSubCamera) DVGui::warning(m_toolDisableReason); } if (m_freezedStatus != NO_FREEZED) return; if (m_mouseButton != event->button()) return; if (m_current3DDevice != NONE) { m_mouseButton = Qt::NoButton; m_tabletEvent = false; m_pressure = 0; if (m_current3DDevice == SIDE_LEFT_3D) set3DLeftSideView(); else if (m_current3DDevice == SIDE_RIGHT_3D) set3DRightSideView(); else if (m_current3DDevice == TOP_3D) set3DTopView(); return; } if (m_mouseButton == Qt::LeftButton && m_editPreviewSubCamera) { if (!PreviewSubCameraManager::instance()->mouseReleaseEvent(this, event)) goto quit; } if (m_compareSettings.m_dragCompareX || m_compareSettings.m_dragCompareY) { m_compareSettings.m_dragCompareX = m_compareSettings.m_dragCompareY = false; goto quit; } m_pos = QPoint(0, 0); if (!tool || !tool->isEnabled()) goto quit; tool->setViewer(this); { TMouseEvent toonzEvent; initToonzEvent(toonzEvent, event, height(), m_pressure, m_tabletEvent, false); TPointD pos = tool->getMatrix().inv() * winToWorld(event->pos()); TObjectHandle *objHandle = TApp::instance()->getCurrentObject(); if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) { pos.x /= m_dpiScale.x; pos.y /= m_dpiScale.y; } if (m_mouseButton == Qt::LeftButton) { tool->leftButtonUp(pos, toonzEvent); TApp::instance()->getCurrentTool()->setToolBusy(false); } } quit: m_mouseButton = Qt::NoButton; m_tabletEvent = false; m_pressure = 0; }
void SceneViewer::mousePressEvent(QMouseEvent *event) { // evita i press ripetuti if (m_buttonClicked) return; m_buttonClicked = true; if (m_freezedStatus != NO_FREEZED) return; if (m_mouseButton != Qt::NoButton) return; m_pos = event->pos(); m_mouseButton = event->button(); // when using tablet, avoid unexpected drawing behavior occurs when // middle-click Qt::MouseButtons mousebuttons; mousebuttons = event->buttons(); if (m_tabletEvent && m_mouseButton == Qt::MidButton && (mousebuttons | Qt::LeftButton)) return; if (is3DView() && m_current3DDevice != NONE && m_mouseButton == Qt::LeftButton) return; else if (m_mouseButton == Qt::LeftButton && m_editPreviewSubCamera) { if (!PreviewSubCameraManager::instance()->mousePressEvent(this, event)) return; } else if (m_mouseButton == Qt::LeftButton && m_visualSettings.m_doCompare) { if (abs(m_pos.x() - width() * m_compareSettings.m_compareX) < 20) { m_compareSettings.m_dragCompareX = true; m_compareSettings.m_dragCompareY = false; m_compareSettings.m_compareY = ImagePainter::DefaultCompareValue; update(); m_tabletEvent = false; return; } else if (abs((height() - m_pos.y()) - height() * m_compareSettings.m_compareY) < 20) { m_compareSettings.m_dragCompareY = true; m_compareSettings.m_dragCompareX = false; m_compareSettings.m_compareX = ImagePainter::DefaultCompareValue; update(); m_tabletEvent = false; return; } else m_compareSettings.m_dragCompareX = m_compareSettings.m_dragCompareY = false; } if (m_freezedStatus != NO_FREEZED) return; TTool *tool = TApp::instance()->getCurrentTool()->getTool(); if (!tool || !tool->isEnabled()) { m_tabletEvent = false; return; } tool->setViewer(this); if (m_mouseButton == Qt::LeftButton && tool->preLeftButtonDown()) { tool = TApp::instance()->getCurrentTool()->getTool(); if (!tool || !tool->isEnabled()) { m_tabletEvent = false; return; } tool->setViewer(this); } TMouseEvent toonzEvent; if (m_pressure > 0 && !m_tabletEvent) m_tabletEvent = true; if (TApp::instance()->isPenCloseToTablet()) m_tabletEvent = true; initToonzEvent(toonzEvent, event, height(), m_pressure, m_tabletEvent, true); // if(!m_tabletEvent) qDebug() << "-----------------MOUSE PRESS 'PURO'. // POSSIBILE EMBOLO"; TPointD pos = tool->getMatrix().inv() * winToWorld(m_pos); TObjectHandle *objHandle = TApp::instance()->getCurrentObject(); if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) { pos.x /= m_dpiScale.x; pos.y /= m_dpiScale.y; } if (m_mouseButton == Qt::LeftButton) { TApp::instance()->getCurrentTool()->setToolBusy(true); tool->leftButtonDown(pos, toonzEvent); } if (m_mouseButton == Qt::RightButton) tool->rightButtonDown(pos, toonzEvent); }
void SceneViewer::mouseMoveEvent(QMouseEvent *event) { if (m_freezedStatus != NO_FREEZED) return; QPoint curPos = event->pos(); bool cursorSet = false; m_lastMousePos = curPos; if (m_editPreviewSubCamera) { if (!PreviewSubCameraManager::instance()->mouseMoveEvent(this, event)) return; } // if the "compare with snapshot" mode is activated, change the mouse cursor // on the border handle if (m_visualSettings.m_doCompare) { if (abs(curPos.x() - width() * m_compareSettings.m_compareX) < 20) { cursorSet = true; setToolCursor(this, ToolCursor::ScaleHCursor); } else if (abs((height() - curPos.y()) - height() * m_compareSettings.m_compareY) < 20) { cursorSet = true; setToolCursor(this, ToolCursor::ScaleVCursor); } } // control of the border handle when the "compare with snapshot" mode is // activated if (m_compareSettings.m_dragCompareX || m_compareSettings.m_dragCompareY) { if (m_compareSettings.m_dragCompareX) m_compareSettings.m_compareX += ((double)(curPos.x() - m_pos.x())) / width(); else if (m_compareSettings.m_dragCompareY) m_compareSettings.m_compareY -= ((double)(curPos.y() - m_pos.y())) / height(); m_compareSettings.m_compareX = tcrop(m_compareSettings.m_compareX, 0.0, 1.0); m_compareSettings.m_compareY = tcrop(m_compareSettings.m_compareY, 0.0, 1.0); update(); m_pos = curPos; } else if (m_mouseButton == Qt::NoButton || m_mouseButton == Qt::LeftButton) { if (is3DView() && m_current3DDevice != NONE && m_mouseButton == Qt::LeftButton) return; else if (is3DView() && m_mouseButton == Qt::NoButton) { TRectD rect = TRectD(TPointD(m_topRasterPos.x, m_topRasterPos.y), TDimensionD(20, 20)); if (rect.contains(TPointD(curPos.x(), curPos.y()))) m_current3DDevice = TOP_3D; else { rect = TRectD(TPointD(m_sideRasterPos.x, m_sideRasterPos.y), TDimensionD(20, 20)); if (rect.contains(TPointD(curPos.x(), curPos.y()))) { if (m_phi3D > 0) m_current3DDevice = SIDE_RIGHT_3D; else m_current3DDevice = SIDE_LEFT_3D; } else m_current3DDevice = NONE; } if (m_current3DDevice != NONE) { cursorSet = true; setToolCursor(this, ToolCursor::CURSOR_ARROW); } } // if the middle mouse button is pressed while dragging, then do panning Qt::MouseButtons mousebuttons; mousebuttons = event->buttons(); if (mousebuttons & Qt::MidButton) { // panning QPoint p = curPos - m_pos; if (m_pos == QPoint(0, 0) && p.manhattanLength() > 300) return; panQt(curPos - m_pos); m_pos = curPos; return; } TTool *tool = TApp::instance()->getCurrentTool()->getTool(); if (!tool || !tool->isEnabled()) { m_tabletEvent = false; return; } tool->setViewer(this); TMouseEvent toonzEvent; initToonzEvent(toonzEvent, event, height(), m_pressure, m_tabletEvent, false); TPointD worldPos = winToWorld(curPos); TPointD pos = tool->getMatrix().inv() * worldPos; if (m_locator) { m_locator->onChangeViewAff(worldPos); } TObjectHandle *objHandle = TApp::instance()->getCurrentObject(); if (tool->getToolType() & TTool::LevelTool && !objHandle->isSpline()) { pos.x /= m_dpiScale.x; pos.y /= m_dpiScale.y; } // qDebug() << "mouseMoveEvent. " << (m_tabletEvent?"tablet":"mouse") // << " pressure=" << m_pressure << " mouseButton=" << m_mouseButton // << " buttonClicked=" << m_buttonClicked; if ((m_tabletEvent && m_pressure > 0) || m_mouseButton == Qt::LeftButton) { // sometimes the mousePressedEvent is postponed to a wrong mouse move // event! if (m_buttonClicked) tool->leftButtonDrag(pos, toonzEvent); } else if (m_pressure == 0) { tool->mouseMove(pos, toonzEvent); // m_tabletEvent=false; } if (!cursorSet) setToolCursor(this, tool->getCursorId()); m_pos = curPos; } else if (m_mouseButton == Qt::MidButton) { if ((event->buttons() & Qt::MidButton) == 0) m_mouseButton = Qt::NoButton; else // panning panQt(curPos - m_pos); m_pos = curPos; return; } }