void StudioPaletteCmd::updateAllLinkedStyles(TPaletteHandle *paletteHandle, TXsheetHandle *xsheetHandle) { if (!xsheetHandle) return; TXsheet *xsheet = xsheetHandle->getXsheet(); if (!xsheet) return; ToonzScene *scene = xsheet->getScene(); if (!scene) return; // emit signal only if something changed bool somethingChanged = false; StudioPalette *sp = StudioPalette::instance(); TLevelSet *levelSet = scene->getLevelSet(); for (int i = 0; i < levelSet->getLevelCount(); i++) { TXshLevel *xl = levelSet->getLevel(i); TXshSimpleLevel *sl = xl ? xl->getSimpleLevel() : 0; if (!sl) continue; TPalette *palette = sl->getPalette(); if (palette) { somethingChanged = somethingChanged | sp->updateLinkedColors(palette); if (sl->getType() == TZP_XSHLEVEL) { std::vector<TFrameId> fids; sl->getFids(fids); std::vector<TFrameId>::iterator it; for (it = fids.begin(); it != fids.end(); ++it) { TFrameId fid = *it; std::string id = sl->getImageId(fid); } } } } if (!paletteHandle || !paletteHandle->getPalette()) return; if (somethingChanged) paletteHandle->notifyColorStyleChanged(); }
void setCurrentColorWithUndo(const TPixel32 &color) { TTool::Application *app = TTool::getApplication(); TPaletteHandle *ph = app->getPaletteController()->getCurrentPalette(); int styleId = ph->getStyleIndex(); TPalette *palette = ph->getPalette(); TXshSimpleLevel *level = app->getCurrentLevel()->getSimpleLevel(); if (palette) TUndoManager::manager()->add( new UndoPickRGBM(palette, styleId, color, level)); setCurrentColor(color); if (level) { std::vector<TFrameId> fids; level->getFids(fids); invalidateIcons(level, fids); } }
void TApp::updateCurrentFrame() { ToonzScene *scene = m_currentScene->getScene(); m_currentFrame->setSceneFrameSize(scene->getFrameCount()); int f0, f1, step; scene->getProperties()->getPreviewProperties()->getRange(f0, f1, step); if (f0 > f1) { f0 = 0; f1 = scene->getFrameCount() - 1; } if (f0 != m_currentFrame->getStartFrame() || f1 != m_currentFrame->getEndFrame()) { m_currentFrame->setFrameRange(f0, f1); std::vector<TFrameId> fids; TXshSimpleLevel *sl = m_currentLevel->getSimpleLevel(); if (sl) { sl->getFids(fids); m_currentFrame->setFrameIds(fids); } } }
void RGBPickerTool::onImageChanged() { if (m_currentStyleId != 0 && m_makePick && (m_pickType.getValue() == POLYLINE_PICK || m_pickType.getValue() == RECT_PICK)) { TTool::Application *app = TTool::getApplication(); TPaletteHandle *ph = app->getPaletteController()->getCurrentPalette(); int styleId = ph->getStyleIndex(); TPalette *palette = ph->getPalette(); TXshSimpleLevel *level = app->getCurrentLevel()->getSimpleLevel(); if (palette) TUndoManager::manager()->add( new UndoPickRGBM(palette, styleId, m_currentValue, level)); setCurrentColor(m_currentValue); if (level) { std::vector<TFrameId> fids; level->getFids(fids); invalidateIcons(level, fids); } } m_makePick = false; }
void FilmstripFrames::keyPressEvent(QKeyEvent *event) { TFrameHandle *fh = TApp::instance()->getCurrentFrame(); TXshSimpleLevel *level = getLevel(); if (!level) return; std::vector<TFrameId> fids; level->getFids(fids); if (fids.empty()) return; fh->setFrameIds(fids); if (event->key() == Qt::Key_Up) fh->prevFrame(); else if (event->key() == Qt::Key_Down) fh->nextFrame(); else if (event->key() == Qt::Key_Home) fh->firstFrame(); else if (event->key() == Qt::Key_End) fh->lastFrame(); else if (event->key() == Qt::Key_PageDown) { int frameHeight = m_iconSize.height(); int visibleHeight = visibleRegion().rects()[0].height(); int visibleFrames = double(visibleHeight) / double(frameHeight); scroll(visibleFrames * frameHeight); return; } else if (event->key() == Qt::Key_PageUp) { int frameHeight = m_iconSize.height(); int visibleHeight = visibleRegion().rects()[0].height(); int visibleFrames = double(visibleHeight) / double(frameHeight); scroll(-visibleFrames * frameHeight); return; } else return; m_selection->selectNone(); if (getLevel()) m_selection->select(fh->getFid()); int index = fid2index(fh->getFid()); if (index >= 0) exponeFrame(index); }
void RGBPickerTool::pickStroke() { TImageP image = TImageP(getImage(false)); TTool::Application *app = TTool::getApplication(); TPaletteHandle *ph = app->getPaletteController()->getCurrentPalette(); int styleId = ph->getStyleIndex(); TPalette *palette = ph->getPalette(); if (!palette) return; StylePicker picker(image, palette); TStroke *stroke = new TStroke(*m_stroke); // iwsw commented out temporarily // if (m_viewer->get3DLutUtil() && // Preferences::instance()->isDoColorCorrectionByUsing3DLutEnabled()) // m_viewer->get3DLutUtil()->bindFBO(); m_currentValue = picker.pickColor(stroke); // iwsw commented out temporarily // if (m_viewer->get3DLutUtil() && // Preferences::instance()->isDoColorCorrectionByUsing3DLutEnabled()) // m_viewer->get3DLutUtil()->releaseFBO(); if (!(m_pickType.getValue() == POLYLINE_PICK)) { TXshSimpleLevel *level = app->getCurrentLevel()->getSimpleLevel(); TUndoManager::manager()->add( new UndoPickRGBM(palette, styleId, m_currentValue, level)); setCurrentColor(m_currentValue); if (level) { std::vector<TFrameId> fids; level->getFids(fids); invalidateIcons(level, fids); } } }
bool VectorizerPopup::apply() { std::set<TXshLevel *> levels; ToonzScene *scene = m_sceneHandle->getScene(); if (!scene) { assert(scene); return false; } TSceneProperties *sceneProp = scene->getProperties(); if (!sceneProp) return false; VectorizerParameters *vectorizerParameters = sceneProp->getVectorizerParameters(); if (!vectorizerParameters) return false; int r0 = 0; int c0 = 0; int r1 = 0; int c1 = 0; bool isCellSelection = getSelectedLevels(levels, r0, c0, r1, c1); if (levels.empty()) { error(tr("The current selection is invalid.")); return false; } //Initialize Progress bar m_progressDialog = new DVGui::ProgressDialog("", "Cancel", 0, 1); m_progressDialog->setWindowFlags(Qt::Dialog | Qt::WindowTitleHint); //Don't show ? and X buttons m_progressDialog->setWindowTitle(QString("Convert To Vector...")); m_progressDialog->setAttribute(Qt::WA_DeleteOnClose); m_progressDialog->setWindowModality(Qt::WindowModal); //No user interaction is allowed during vectorization m_progressDialog->setFixedSize(200, 100); //Initialize vectorizer m_vectorizer = new Vectorizer; m_vectorizer->setParameters(*vectorizerParameters); connect(m_vectorizer, SIGNAL(frameName(QString)), this, SLOT(onFrameName(QString)), Qt::QueuedConnection); connect(m_vectorizer, SIGNAL(frameDone(int)), this, SLOT(onFrameDone(int)), Qt::QueuedConnection); connect(m_vectorizer, SIGNAL(partialDone(int, int)), this, SLOT(onPartialDone(int, int)), Qt::QueuedConnection); //We DON'T want the progress bar to be hidden at cancel press - since its modal //behavior prevents the user to interfere with a possibly still active vectorization. disconnect(m_progressDialog, SIGNAL(canceled()), m_progressDialog, SLOT(onCancel())); //We first inform the vectorizer of a cancel press; bool ret = connect(m_progressDialog, SIGNAL(canceled()), m_vectorizer, SLOT(cancel())); //which eventually transmits the command to vectorization core, allowing full-time cancels ret = ret && connect(m_progressDialog, SIGNAL(canceled()), m_vectorizer, SIGNAL(transmitCancel())); //Only after the vectorizer has terminated its process - or got cancelled, we are allowed //to proceed here. ret = ret && connect(m_vectorizer, SIGNAL(finished()), this, SLOT(onFinished()), Qt::QueuedConnection); assert(ret); int newIndexColumn = c1 + 1; std::set<TXshLevel *>::iterator it = levels.begin(); for (it; it != levels.end(); it++) { TXshSimpleLevel *sl = dynamic_cast<TXshSimpleLevel *>(*it); if (!sl || !sl->getSimpleLevel() || !isLevelToConvert(sl)) { QString levelName = tr(toString(sl->getName()).c_str()); QString errorMsg = tr("Cannot convert to vector the current selection.") + levelName; error(errorMsg); continue; } std::vector<TFrameId> fids; if (isCellSelection) getSelectedFids(fids, sl, r0, c0, r1, c1); else sl->getFids(fids); assert(fids.size() > 0); close(); // Re-initialize progress Bar m_progressDialog->setMaximum(fids.size() * 100); m_progressDialog->setValue(0); m_currFrame = 0; // Re-initialize vectorizer m_vectorizer->setLevel(sl); m_vectorizer->setFids(fids); // Start vectorizing m_vectorizer->start(); m_progressDialog->show(); // Wait the vectorizer... while (!l_quitLoop) QCoreApplication::processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents); l_quitLoop = false; // Assign output X-sheet cells TXshSimpleLevel *vl = m_vectorizer->getVectorizedLevel(); if (isCellSelection && vl) { TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet(); xsheet->insertColumn(newIndexColumn); int r, c; for (c = c0; c <= c1; c++) { for (r = r0; r <= r1; r++) { TXshCell cell = xsheet->getCell(r, c); TXshSimpleLevel *level = (!cell.isEmpty()) ? cell.getSimpleLevel() : 0; if (level != sl) continue; TFrameId curFid = cell.getFrameId(); std::vector<TFrameId> newFids; vl->getFids(newFids); std::vector<TFrameId>::iterator it1 = newFids.begin(); for (it1; it1 != newFids.end(); it1++) { TFrameId id = *it1; if (id.getNumber() == curFid.getNumber() || // Hanno stesso numero di frame (id.getNumber() == 1 && curFid.getNumber() == -2)) // La vecchia cella non ha numero di frame xsheet->setCell(r, newIndexColumn, TXshCell(vl, id)); } } } newIndexColumn += 1; } else if (vl) { std::vector<TFrameId> gomi; scene->getXsheet()->exposeLevel(0, scene->getXsheet()->getFirstFreeColumnIndex(), vl, gomi); } if (m_vectorizer->isCanceled()) break; } m_progressDialog->close(); delete m_vectorizer; TApp::instance()->getCurrentScene()->notifyCastChange(); TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); return true; }
void FilmstripFrames::paintEvent(QPaintEvent *evt) { QPainter p(this); // p.setRenderHint(QPainter::Antialiasing, true); QRect clipRect = evt->rect(); p.fillRect(clipRect, Qt::black); // thumbnail rect, including offsets QRect iconImgRect = QRect(QPoint(fs_leftMargin + fs_iconMarginLR, fs_frameSpacing / 2 + fs_iconMarginTop), m_iconSize); // frame size with margins QSize frameSize = m_iconSize + QSize(fs_iconMarginLR * 2, fs_iconMarginTop + fs_iconMarginBottom); // .. and with offset QRect frameRect = QRect(QPoint(fs_leftMargin, fs_frameSpacing / 2), frameSize); int oneFrameHeight = frameSize.height() + fs_frameSpacing; // visible frame index range int i0 = y2index(clipRect.top()); int i1 = y2index(clipRect.bottom()); // fids, frameCount <- frames del livello std::vector<TFrameId> fids; TXshSimpleLevel *sl = getLevel(); if (sl) sl->getFids(fids); else { for (int i = i0; i <= i1; i++) { // draw white rectangles if obtaining the level is failed QRect iconRect = frameRect.translated(QPoint(0, oneFrameHeight * i)); p.setBrush(QColor(192, 192, 192)); p.setPen(Qt::NoPen); p.drawRect(iconRect); } return; } //--- compute navigator rect --- QRect naviRect; ComboViewerPanel *inknPaintViewerPanel = TApp::instance()->getInknPaintViewerPanel(); if (sl->getType() == TZP_XSHLEVEL && inknPaintViewerPanel) { // show navigator only if the inknpaint viewer is visible if (inknPaintViewerPanel->isVisible()) { SceneViewer *viewer = inknPaintViewerPanel->getSceneViewer(); // imgSize: image's pixel size QSize imgSize(sl->getProperties()->getImageRes().lx, sl->getProperties()->getImageRes().ly); // Viewer affine TAffine viewerAff = inknPaintViewerPanel->getSceneViewer()->getViewMatrix(); // pixel size which will be displayed with 100% scale in Viewer Stage TFrameId currentId = TApp::instance()->getCurrentFrame()->getFid(); double imgPixelWidth = (double)(imgSize.width()) / sl->getDpi(currentId).x * Stage::inch; double imgPixelHeight = (double)(imgSize.height()) / sl->getDpi(currentId).y * Stage::inch; // get the image's corner positions in viewer matrix (with current zoom // scale) TPointD imgTopRight = viewerAff * TPointD(imgPixelWidth / 2.0f, imgPixelHeight / 2.0f); TPointD imgBottomLeft = viewerAff * TPointD(-imgPixelWidth / 2.0f, -imgPixelHeight / 2.0f); // pixel size in viewer matrix ( with current zoom scale ) QSizeF imgSizeInViewer(imgTopRight.x - imgBottomLeft.x, imgTopRight.y - imgBottomLeft.y); // ratio of the Viewer frame's position and size QRectF naviRatio( (-(float)viewer->width() * 0.5f - (float)imgBottomLeft.x) / imgSizeInViewer.width(), 1.0f - ((float)viewer->height() * 0.5f - (float)imgBottomLeft.y) / imgSizeInViewer.height(), (float)viewer->width() / imgSizeInViewer.width(), (float)viewer->height() / imgSizeInViewer.height()); naviRect = QRect(iconImgRect.left() + (int)(naviRatio.left() * (float)iconImgRect.width()), iconImgRect.top() + (int)(naviRatio.top() * (float)iconImgRect.height()), (int)((float)iconImgRect.width() * naviRatio.width()), (int)((float)iconImgRect.height() * naviRatio.height())); // for drag move m_naviRectPos = naviRect.center(); naviRect = naviRect.intersected(frameRect); m_icon2ViewerRatio.setX(imgSizeInViewer.width() / (float)iconImgRect.width()); m_icon2ViewerRatio.setY(imgSizeInViewer.height() / (float)iconImgRect.height()); } } //--- compute navigator rect end --- int frameCount = (int)fids.size(); std::set<TFrameId> editableFrameRange; if (sl) editableFrameRange = sl->getEditableRange(); bool isReadOnly = false; if (sl) isReadOnly = sl->isReadOnly(); int i; int iconWidth = m_iconSize.width(); int x0 = m_frameLabelWidth; int x1 = x0 + iconWidth; int frameHeight = m_iconSize.height(); // linee orizzontali che separano i frames p.setPen(getLightLineColor()); for (i = i0; i <= i1; i++) { int y = index2y(i) + frameHeight; p.drawLine(0, y, x1, y); } TFilmstripSelection::InbetweenRange range = m_selection->getInbetweenRange(); // draw for each frames for (i = i0; i <= i1; i++) { QRect tmp_iconImgRect = iconImgRect.translated(QPoint(0, oneFrameHeight * i)); QRect tmp_frameRect = frameRect.translated(QPoint(0, oneFrameHeight * i)); bool isCurrentFrame = (i == sl->fid2index(TApp::instance()->getCurrentFrame()->getFid())); bool isSelected = (0 <= i && i < frameCount && m_selection->isSelected(fids[i])); if (0 <= i && i < frameCount) { TFrameId fid = fids[i]; // normal or inbetween (for vector levels) int flags = (sl->getType() == PLI_XSHLEVEL && range.first < fid && fid < range.second) ? F_INBETWEEN_RANGE : F_NORMAL; // draw icons drawFrameIcon(p, tmp_iconImgRect, i, fid, flags); p.setPen(Qt::NoPen); p.setBrush(Qt::NoBrush); p.drawRect(tmp_iconImgRect); // Frame number if (m_selection->isSelected(fids[i])) { if (TApp::instance()->getCurrentFrame()->isEditingLevel() && isCurrentFrame) p.setPen(Qt::red); else p.setPen(Qt::white); } else p.setPen(QColor(192, 192, 192)); p.setBrush(Qt::NoBrush); // for single frame QString text; if (fid.getNumber() == TFrameId::EMPTY_FRAME || fid.getNumber() == TFrameId::NO_FRAME) { text = QString("Single Frame"); } // for sequencial frame (with letter) else if (Preferences::instance()->isShowFrameNumberWithLettersEnabled()) { text = fidToFrameNumberWithLetter(fid.getNumber()); } // for sequencial frame else { text = QString::number(fid.getNumber()).rightJustified(4, '0'); } p.drawText(tmp_frameRect.adjusted(0, 0, -3, 2), text, QTextOption(Qt::AlignRight | Qt::AlignBottom)); p.setPen(Qt::NoPen); // Read-only frames (lock) if (0 <= i && i < frameCount) { if ((editableFrameRange.empty() && isReadOnly) || (isReadOnly && (!editableFrameRange.empty() && editableFrameRange.count(fids[i]) == 0))) { static QPixmap lockPixmap(":Resources/forbidden.png"); p.drawPixmap(tmp_frameRect.bottomLeft() + QPoint(3, -13), lockPixmap); } } } // navigator rect if (naviRect.isValid() && isCurrentFrame) { p.setPen(QPen(Qt::red, 1)); p.drawRect(naviRect.translated(0, oneFrameHeight * i)); p.setPen(Qt::NoPen); } // red frame for the current frame if (TApp::instance()->getCurrentFrame()->isEditingLevel() && (isCurrentFrame || isSelected)) { QPen pen; pen.setColor(Qt::red); pen.setWidth(2); pen.setJoinStyle(Qt::RoundJoin); p.setPen(pen); p.drawRect(tmp_frameRect.adjusted(-1, -1, 2, 2)); p.setPen(Qt::NoPen); } } // se sono in modalita' level edit faccio vedere la freccia che indica il // frame corrente if (TApp::instance()->getCurrentFrame()->isEditingLevel()) m_frameHeadGadget->draw(p, QColor(Qt::white), QColor(Qt::black)); }