示例#1
0
/*! 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 undo() const
	{
		TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet();
		TXshCell cell = xsheet->getCell(m_r, m_c);
		TRasterImageP rasImage = (TRasterImageP)cell.getImage(true);
		if (!rasImage)
			return;
		rasImage->setRaster(((TRasterImageP)TImageCache::instance()->get(m_rasId, true))->getRaster()->clone());
		TXshSimpleLevel *simpleLevel = cell.getSimpleLevel();
		assert(simpleLevel);
		simpleLevel->touchFrame(cell.getFrameId());
		simpleLevel->setDirtyFlag(false);
		IconGenerator::instance()->invalidate(simpleLevel, cell.getFrameId());

		if (m_isLastInBlock) {
			TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
		}
	}
示例#3
0
void BinarizePopup::apply()
{
	if (getSelectedFrames() <= 0) {
		DVGui::error(tr("No raster frames selected"));
		return;
	}

	DVGui::ProgressDialog pd(tr("Binarizing images"), tr("Cancel"), 0, (int)m_frames.size(), 0);
	pd.show();
	qApp->processEvents();

	TBinarizer binarizer;
	binarizer.enableAlpha(!!m_alphaChk->checkState());

	TUndoManager::manager()->beginBlock();
	int count = 0;
	Frames::iterator it;
	for (it = m_frames.begin(); it != m_frames.end(); ++it) {
		TXshSimpleLevel *sl = it->first;
		if (!!m_alphaChk->checkState())
			sl->getProperties()->setHasAlpha(true);
		TFrameId fid = it->second;
		TBinarizeUndo *undo = new TBinarizeUndo(sl, fid, binarizer.isAlphaEnabled());
		TUndoManager::manager()->add(undo);
		TRasterImageP ri = sl->getFrame(fid, true);
		if (!ri)
			continue; // should never happen
		TRaster32P ras32 = ri->getRaster();
		if (!ras32)
			continue; // not yet handled
		binarizer.process(ras32);
		pd.setValue(count++);
		qApp->processEvents();
		sl->touchFrame(fid);
		sl->setDirtyFlag(true);
		IconGenerator::instance()->invalidate(sl, fid);
	}
	TUndoManager::manager()->endBlock();
	TApp::instance()->getCurrentLevel()->notifyLevelChange();
	TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
}
	void redo() const
	{
		TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet();
		TXshCell cell = xsheet->getCell(m_r, m_c);
		TImageP image = (TRasterImageP)cell.getImage(true);
		if (!image)
			return;
		TRasterP ras = image->raster();
		if (!ras)
			return;

		onChange(ras, m_threshold, m_softness);
		TXshSimpleLevel *simpleLevel = cell.getSimpleLevel();
		assert(simpleLevel);
		simpleLevel->touchFrame(cell.getFrameId());
		simpleLevel->setDirtyFlag(false);
		IconGenerator::instance()->invalidate(simpleLevel, cell.getFrameId());
		if (m_isLastInBlock) {
			TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
		}
	}
void AdjustLevelsUndo::redo() const
{
	TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet();
	TXshCell cell = xsheet->getCell(m_r, m_c);

	TRasterImageP rasImage = (TRasterImageP)cell.getImage(true);
	if (!rasImage)
		return;

	TRasterP ras = rasImage->getRaster();
	if (!ras)
		return;

	TRop::rgbmAdjust(ras, ras, m_in0, m_in1, m_out0, m_out1);

	TXshSimpleLevel *simpleLevel = cell.getSimpleLevel();
	assert(simpleLevel);
	simpleLevel->touchFrame(cell.getFrameId());
	simpleLevel->setDirtyFlag(true);
	IconGenerator::instance()->invalidate(simpleLevel, cell.getFrameId());

	if (m_isLastInBlock)
		TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();
}
void AntialiasPopup::apply()
{
	TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(TSelection::getCurrent());
	int threshold = m_thresholdField->getValue();
	int softness = m_softnessField->getValue();
	if (cellSelection) {
		std::set<TImage *> images;
		int r0, c0, r1, c1;
		cellSelection->getSelectedCells(r0, c0, r1, c1);
		TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet();
		bool oneImageChanged = false;
		int c, r;
		TUndoManager::manager()->beginBlock();
		for (c = c0; c <= c1; c++)
			for (r = r0; r <= r1; r++) {
				TXshCell cell = xsheet->getCell(r, c);
				TImageP image = cell.getImage(true);
				if (!image)
					continue;
				if (images.find(image.getPointer()) != images.end())
					continue;
				TRasterP ras = image->raster();
				if (!ras)
					continue;
				images.insert(image.getPointer());
				oneImageChanged = true;
				TUndoManager::manager()->add(new TRasterAntialiasUndo(threshold, softness, r, c, ras->clone()));
				onChange(ras, threshold, softness);
				TXshSimpleLevel *simpleLevel = cell.getSimpleLevel();
				assert(simpleLevel);
				simpleLevel->touchFrame(cell.getFrameId());
				simpleLevel->setDirtyFlag(true);
				IconGenerator::instance()->invalidate(simpleLevel, cell.getFrameId());
			}
		TUndoManager::manager()->endBlock();
		if (oneImageChanged) {
			close();
			return;
		}
	}
	TFilmstripSelection *filmstripSelection = dynamic_cast<TFilmstripSelection *>(TSelection::getCurrent());
	if (filmstripSelection) {
		TXshSimpleLevel *simpleLevel = TApp::instance()->getCurrentLevel()->getSimpleLevel();
		if (simpleLevel) {
			std::set<TFrameId> fids = filmstripSelection->getSelectedFids();
			std::set<TFrameId>::iterator it = fids.begin();
			bool oneImageChanged = false;
			for (it; it != fids.end(); it++) {
				TImageP image = simpleLevel->getFrame(*it, true);
				if (!image)
					continue;
				TRasterP ras = image->raster();
				if (!ras)
					continue;
				oneImageChanged = true;
				onChange(ras, threshold, softness);
				simpleLevel->touchFrame(*it);
				simpleLevel->setDirtyFlag(true);
				IconGenerator::instance()->invalidate(simpleLevel, *it);
			}
			if (oneImageChanged) {
				close();
				return;
			}
		}
	}

	DVGui::error(QObject::tr("The current selection is invalid."));
	return;
}
void AdjustLevelsPopup::apply()
{
	//Retrieve parameters
	int in0[5], in1[5], out0[5], out1[5];
	getParameters(in0, in1, out0, out1);

	//Operate depending on the selection kind
	TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(TSelection::getCurrent());
	if (cellSelection) {
		std::set<TRasterImage *> images; //Multiple cells may yield the same image...

		int r0, c0, r1, c1;
		cellSelection->getSelectedCells(r0, c0, r1, c1);
		TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet();
		bool oneImageChanged = false;

		TUndoManager::manager()->beginBlock();
		{
			int c, r;
			for (c = c0; c <= c1; c++) {
				for (r = r0; r <= r1; r++) {
					const TXshCell &cell = xsheet->getCell(r, c);

					TRasterImageP rasImage = (TRasterImageP)cell.getImage(true);
					if (!rasImage)
						continue;

					if (images.find(rasImage.getPointer()) != images.end())
						continue;

					TRasterP ras = rasImage->getRaster();
					if (!ras)
						continue;

					images.insert(rasImage.getPointer());
					oneImageChanged = true;

					TUndoManager::manager()->add(new AdjustLevelsUndo(in0, in1, out0, out1, r, c, ras->clone()));
					TRop::rgbmAdjust(ras, ras, in0, in1, out0, out1);

					TXshSimpleLevel *simpleLevel = cell.getSimpleLevel();
					assert(simpleLevel);
					simpleLevel->touchFrame(cell.getFrameId());
					simpleLevel->setDirtyFlag(true);

					IconGenerator::instance()->invalidate(simpleLevel, cell.getFrameId());
				}
			}
		}
		TUndoManager::manager()->endBlock();

		if (oneImageChanged) {
			close();
			return;
		}
	}

	TFilmstripSelection *filmstripSelection = dynamic_cast<TFilmstripSelection *>(TSelection::getCurrent());
	if (filmstripSelection) {
		TXshSimpleLevel *simpleLevel = TApp::instance()->getCurrentLevel()->getSimpleLevel();
		if (simpleLevel) {
			std::set<TFrameId> fids = filmstripSelection->getSelectedFids();
			bool oneImageChanged = false;

			std::set<TFrameId>::iterator it = fids.begin();
			for (it; it != fids.end(); it++) {
				TRasterImageP rasImage = (TRasterImageP)simpleLevel->getFrame(*it, true);
				if (!rasImage)
					continue;

				TRasterP ras = rasImage->getRaster();
				if (!ras)
					continue;

				oneImageChanged = true;
				TRop::rgbmAdjust(ras, ras, in0, in1, out0, out1);

				simpleLevel->touchFrame(*it);
				simpleLevel->setDirtyFlag(true);

				IconGenerator::instance()->invalidate(simpleLevel, *it);
			}

			if (oneImageChanged) {
				close();
				return;
			}
		}
	}

	DVGui::error(QObject::tr("The current selection is invalid."));
	return;
}
示例#8
0
void LinesFadePopup::apply()
{
	TCellSelection *cellSelection = dynamic_cast<TCellSelection *>(TSelection::getCurrent());
	TPixel32 color = m_linesColorField->getColor();
	int intensity = m_intensity->getValue();

	if (cellSelection) {
		std::set<TRasterImage *> images;
		int r0, c0, r1, c1;
		cellSelection->getSelectedCells(r0, c0, r1, c1);
		TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet();
		bool oneImageChanged = false;
		int c, r;
		TUndoManager::manager()->beginBlock();
		for (c = c0; c <= c1; c++)
			for (r = r0; r <= r1; r++) {
				TXshCell cell = xsheet->getCell(r, c);
				TRasterImageP rasImage = (TRasterImageP)cell.getImage(true);
				if (!rasImage)
					continue;
				if (images.find(rasImage.getPointer()) != images.end())
					continue;
				TRaster32P ras = rasImage->getRaster();
				if (!ras)
					continue;
				images.insert(rasImage.getPointer());
				TUndoManager::manager()->add(new TLineFadeUndo(color, intensity, r, c, ras->clone()));
				oneImageChanged = true;
				onChange(ras, ras, color, intensity);
				TXshSimpleLevel *simpleLevel = cell.getSimpleLevel();
				assert(simpleLevel);
				simpleLevel->touchFrame(cell.getFrameId());
				simpleLevel->setDirtyFlag(true);
				IconGenerator::instance()->invalidate(simpleLevel, cell.getFrameId());
			}
		TUndoManager::manager()->endBlock();
		images.clear();
		if (oneImageChanged) {
			close();
			return;
		}
	}
	TFilmstripSelection *filmstripSelection = dynamic_cast<TFilmstripSelection *>(TSelection::getCurrent());
	if (filmstripSelection) {
		TXshSimpleLevel *simpleLevel = TApp::instance()->getCurrentLevel()->getSimpleLevel();
		if (simpleLevel) {
			std::set<TFrameId> fids = filmstripSelection->getSelectedFids();
			bool oneImageChanged = false;
			for (auto const& fid : fids) {
				TRasterImageP rasImage = (TRasterImageP)simpleLevel->getFrame(fid, true);
				;
				if (!rasImage)
					continue;
				TRaster32P ras = rasImage->getRaster();
				if (!ras)
					continue;
				oneImageChanged = true;
				onChange(ras, ras, color, intensity);
				simpleLevel->touchFrame(fid);
				simpleLevel->setDirtyFlag(true);
				IconGenerator::instance()->invalidate(simpleLevel, fid);
			}
			if (oneImageChanged) {
				close();
				return;
			}
		}
	}

	DVGui::error(QObject::tr("The current selection is invalid."));
	return;
}