Esempio n. 1
0
void FilmstripFrames::exponeFrame(int index) {
  int y0 = index2y(index);
  int y1 = y0 + m_iconSize.height() + fs_frameSpacing + fs_iconMarginTop +
           fs_iconMarginBottom;
  if (y1 > height()) setFixedHeight(y1);
  // else if(height()-y1>=m_iconSize.height()) updateContentHeight();
  m_scrollArea->ensureVisible(0, (y0 + y1) / 2, 50, (y1 - y0) / 2);
}
void FrameHeadGadget::drawOnionSkinSelection(QPainter &p, const QColor &lightColor, const QColor &darkColor)
{
	int currentRow = getCurrentFrame();
	int xa = 12;

	if (m_highlightedFosFrame >= 0 && m_highlightedFosFrame != currentRow) {
		int y = index2y(m_highlightedFosFrame) + 3;
		QRect rect(xa - 6, y + 1, 4, 4);
		p.setPen(Qt::blue); // grey150);
		p.drawRect(rect);
		p.fillRect(rect.adjusted(1, 1, 0, 0), QBrush(lightColor));
	}

	OnionSkinMask osMask = TApp::instance()->getCurrentOnionSkin()->getOnionSkinMask();
	if (!osMask.isEnabled())
		return;

	int i;
	for (i = 0; i < osMask.getFosCount(); i++) {
		int fos = osMask.getFos(i);
		if (fos == currentRow)
			continue;
		int y = index2y(fos) + 3;
		QRect rect(xa - 6, y + 1, 4, 4);
		p.setPen(Qt::black);
		p.drawRect(rect);
		p.fillRect(rect.adjusted(1, 1, 0, 0), QBrush(darkColor));
	}

	int lastY;
	int xc = xa - 10;
	int mosCount = osMask.getMosCount();
	for (i = 0; i < mosCount; i++) {
		int mos = osMask.getMos(i);
		int y = 0 + index2y(currentRow + mos) + 3;
		QRect rect(xa - 12, y + 1, 4, 4);
		p.setPen(Qt::black);
		p.drawRect(rect);
		p.fillRect(rect.adjusted(1, 1, 0, 0), QBrush(lightColor));
		if (i > 0 || mos > 0) {
			int ya = y;
			int yb;
			if (i == 0 || mos > 0 && osMask.getMos(i - 1) < 0) {
				ya = index2y(currentRow) + 10;
				yb = index2y(currentRow + mos) + 4;
			} 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 = index2y(currentRow);
			int yb = lastY + 5;
			p.setPen(Qt::black);
			p.drawLine(xc, ya, xc, yb);
		}
	}
}
void FrameHeadGadget::drawPlayingHead(QPainter &p, const QColor &lightColor, const QColor &darkColor)
{
	int currentFrame = getCurrentFrame();
	int yy = index2y(currentFrame);

	std::vector<QPointF> pts;
	int xa = 12; // m_a;
	int xx = xa; // m_a
	pts.push_back(QPointF(xx, yy));
	pts.push_back(QPointF(xx + 10, yy));
	pts.push_back(QPointF(xx + 13, yy + 1));
	pts.push_back(QPointF(xx + 17, yy + 5));
	pts.push_back(QPointF(xx + 13, yy + 9));
	pts.push_back(QPointF(xx + 10, yy + 10));
	pts.push_back(QPointF(xx, yy + 10));
	drawPolygon(p, pts, true, lightColor);
	p.setPen(darkColor);
	for (int i = 0; i < 4; i++)
		for (int j = 0; j < 4; j++)
			p.drawPoint(xx + 3 + i * 2, yy + 2 + j * 2);

	p.fillRect(QRect(xx - 7, yy + 1, 7, 9), QBrush(lightColor));
	p.setPen(darkColor);
	p.drawLine(xx - 9, yy + 5, xx - 8, yy + 5);

	p.setPen(Qt::black);
	p.drawLine(xx - 7, yy, xx - 1, yy);
	p.drawLine(xx - 7, yy + 10, xx - 1, yy + 10);

	p.setPen(Qt::black);
	xx = xa - 6;
	p.drawPoint(xx - 4, yy + 5);
	p.drawRect(QRect(xx - 6, yy, 4, 4));
	p.drawRect(QRect(xx - 6, yy + 6, 4, 4));

	p.fillRect(QRect(xx - 5, yy + 1, 3, 3), QBrush(lightColor));
	p.fillRect(QRect(xx - 5, yy + 7, 3, 3), QBrush(lightColor));
}
bool FilmstripFrameHeadGadget::eventFilter(QObject *obj, QEvent *e)
{
	if (!Preferences::instance()->isOnionSkinEnabled())
		return false;

	QWidget *viewer = dynamic_cast<QWidget *>(obj);

	if (e->type() == QEvent::MouseButtonPress) {

		//方針:上下タブをクリック→ドラッグでオニオンスキンの増減
		//   上下タブをダブルクリックでオニオンスキンの表示/非表示
		//		オニオンスキンの●エリア をクリックで各フレームのON/OFF切り替え→ドラッグで伸ばせる
		//		Fixedオニオンスキンの●エリアをクリックで Fixedオニオンスキンの位置の指定

		//----- それぞれのパーツの位置Rectの指定。各フレームの右上座標からのオフセットも含む。
		//OnionSkinの円の左上座標のy値
		int onionDotYPos = m_dy / 2 - 5;
		//OnionSkinの●のRect
		QRect onionDotRect(10, onionDotYPos, 10, 10);
		//FixedOnionSkinの●のRect
		QRect fixedOnionDotRect(0, onionDotYPos, 10, 10);
		//上方向のOnionSkinタブのRect
		QRect backOnionTabRect(0, m_dy - 15, 30, 15);
		//下方向のOnionSkinタブのRect
		QRect frontOnionTabRect(0, 0, 30, 15);
		//-----

		//----- ハイライト表示、actionのリセット
		m_action = None;

		// click
		if (m_highlightedFosFrame >= 0) {
			m_highlightedFosFrame = -1;
			viewer->update();
		}
		if (m_highlightedMosFrame >= 0) {
			m_highlightedMosFrame = -1;
			viewer->update();
		}

		//----- 以下、クリック位置に応じてアクションを変えていく
		//クリックされたフレームを取得
		QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent *>(e);
		int frame = y2index(mouseEvent->pos().y());
		m_buttonPressCellIndex = frame;
		int currentFrame = getCurrentFrame();

		//各フレーム左上からの位置
		QPoint clickedPos = mouseEvent->pos() + QPoint(0, -index2y(frame));

		//カレントフレームの場合、無視
		if (frame == currentFrame)
			return false;
		//カレントフレームの上下でタブをクリックした場合
		else if ((frame == currentFrame - 1 && backOnionTabRect.contains(clickedPos)) || (frame == currentFrame + 1 && frontOnionTabRect.contains(clickedPos))) {
			//ドラッグに備える
			m_action = ActivateMos;
		}
		//カレントフレーム以外の場合
		else {
			//通常のOnionSkinの場合
			if (onionDotRect.contains(clickedPos)) {
				// 既にオニオンスキンなら、オフにする
				bool on = !isMos(frame);
				//アクションが決まる
				m_action = on ? ActivateMos : DeactivateMos;
				//カレントフレームでなければ、オニオンスキンを切り替え
				setMos(frame, on);
			}
			//FixedOnionSkinの場合
			else if (fixedOnionDotRect.contains(clickedPos)) {
				// Fos
				bool on = !isFos(frame);
				m_action = on ? ActivateFos : DeactivateFos;
				setFos(frame, on);
			} else
				return false;
		}
		viewer->update();

	}
	//---- 上下タブのダブルクリックで表示/非表示の切り替え
	else if (e->type() == QEvent::MouseButtonDblClick) {
		QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent *>(e);
		if (mouseEvent->buttons() & Qt::LeftButton) {
			int frame = y2index(mouseEvent->pos().y());
			//各フレーム左上からの位置
			QPoint clickedPos = mouseEvent->pos() + QPoint(0, -index2y(frame));
			//カレントフレーム
			int currentFrame = getCurrentFrame();
			//上方向のOnionSkinタブのRect
			QRect backOnionTabRect(0, m_dy - 15, 30, 15);
			//下方向のOnionSkinタブのRect
			QRect frontOnionTabRect(0, 0, 30, 15);
			if ((currentFrame - 1 == frame && backOnionTabRect.contains(clickedPos)) || (currentFrame + 1 == frame && frontOnionTabRect.contains(clickedPos))) {
				enableOnionSkin(!isOnionSkinEnabled());
				viewer->update();
			}
		} else
			return false;
	}
	//----
	else if (e->type() == QEvent::MouseMove) {
		QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent *>(e);
		int frame = y2index(mouseEvent->pos().y());
		//各フレーム左上からの位置
		QPoint clickedPos = mouseEvent->pos() + QPoint(0, -index2y(frame));
		//カレントフレーム
		int currentFrame = getCurrentFrame();
		//マウスボタンが押されていない場合
		if (mouseEvent->buttons() == 0) {
			//----- それぞれのパーツの位置Rectの指定。各フレームの右上座標からのオフセットも含む。
			//OnionSkinの円の左上座標のy値
			int onionDotYPos = m_dy / 2 - 5;
			//OnionSkinの●のRect
			QRect onionDotRect(10, onionDotYPos, 10, 10);
			//FixedOnionSkinの●のRect
			QRect fixedOnionDotRect(0, onionDotYPos, 10, 10);
			//上方向のOnionSkinタブのRect
			QRect backOnionTabRect(0, m_dy - 15, 30, 15);
			//下方向のOnionSkinタブのRect
			QRect frontOnionTabRect(0, 0, 30, 15);
			//-----

			//----- Fixed Onion Skin の ハイライト
			int highlightedFrame;
			if (currentFrame != frame && fixedOnionDotRect.contains(clickedPos))
				highlightedFrame = frame;
			else
				highlightedFrame = -1;
			if (highlightedFrame != m_highlightedFosFrame) {
				m_highlightedFosFrame = highlightedFrame;
				viewer->update();
			}
			//-----
			//----- 通常の Onion Skin の ハイライト
			if (currentFrame != frame && onionDotRect.contains(clickedPos))
				highlightedFrame = frame;
			else
				highlightedFrame = -1;
			if (highlightedFrame != m_highlightedMosFrame) {
				m_highlightedMosFrame = highlightedFrame;
				viewer->update();
			}
			//-----
			//----- ツールチップの表示
			if (currentFrame == frame) {
				viewer->setToolTip(tr(""));
				return false;
			}
			//Fixed Onion Skin
			else if (fixedOnionDotRect.contains(clickedPos))
				viewer->setToolTip(tr("Click to Toggle Fixed Onion Skin"));
			//通常の Onion Skin
			else if (onionDotRect.contains(clickedPos))
				viewer->setToolTip(tr("Click / Drag to Toggle Onion Skin"));
			//カレントフレームの上下タブ
			else if ((currentFrame - 1 == frame && backOnionTabRect.contains(clickedPos)) || (currentFrame + 1 == frame && frontOnionTabRect.contains(clickedPos)))
				viewer->setToolTip(tr("Drag to Extend Onion Skin, Double Click to Toggle All"));
			else {
				viewer->setToolTip(tr(""));
				return false;
			}
		}

		//左ボタンドラッグの場合
		else if (mouseEvent->buttons() & Qt::LeftButton) {
			//指定されたアクションに従い、ドラッグされたフレームも同じアクションを行う
			// drag
			switch (m_action) {
			case MoveHead:
				setCurrentFrame(frame);
				break;
			case ActivateMos:
				setMos(frame, true);
				break;
			case DeactivateMos:
				setMos(frame, false);
				break;
			case ActivateFos:
				setFos(frame, true);
				break;
			case DeactivateFos:
				setFos(frame, false);
				break;
			default:
				return false;
			}
			viewer->update();
		} else if (mouseEvent->buttons() & Qt::MidButton)
			return false;
	} else
		return false;
	return true;
}
void FilmstripFrameHeadGadget::drawOnionSkinSelection(QPainter &p, const QColor &lightColor, const QColor &darkColor)
{
	int currentRow = getCurrentFrame();

	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);

	OnionSkinMask osMask = TApp::instance()->getCurrentOnionSkin()->getOnionSkinMask();
	int mosCount = osMask.getMosCount();

	int i;
	//OnionSkinの円の左上座標のy値
	int onionDotYPos = m_dy / 2 - 5;

	p.setPen(Qt::red);
	//--- OnionSkinが有効なら実線、無効なら点線
	if (!osMask.isEnabled()) {
		QPen currentPen = p.pen();
		currentPen.setStyle(Qt::DashLine);
		currentPen.setColor(QColor(128, 128, 128, 255));
		p.setPen(currentPen);
	}
	//カレントフレームにOnionSkinを伸ばすハンドルを描画
	{
		int angle180 = 16 * 180;
		QRectF handleRect(0, 0, 30, 30);

		//上向きのハンドル:1フレーム目のときは描画しない
		if (currentRow > 0) {
			int y0 = index2y(currentRow) - 15;
			p.setBrush(QBrush(backColor));
			p.drawChord(handleRect.translated(0, y0), 0, angle180);
		}

		//下向きのハンドル:最終フレームの時は描画しない
		std::vector<TFrameId> fids;
		m_filmstrip->getLevel()->getFids(fids);
		int frameCount = (int)fids.size();
		if (currentRow < frameCount - 1) {
			int y1 = index2y(currentRow + 1) - 15;
			p.setBrush(QBrush(frontColor));
			p.drawChord(handleRect.translated(0, y1), angle180, angle180);
		}

		//--- 動く Onion Skinの描画 その1
		//先に線を描く
		//まず OnionSkinの最大/最小値を取得
		int minMos = 0;
		int maxMos = 0;
		for (i = 0; i < mosCount; i++) {
			int mos = osMask.getMos(i);
			if (minMos > mos)
				minMos = mos;
			if (maxMos < mos)
				maxMos = mos;
		}
		p.setBrush(Qt::NoBrush);
		//min/maxが更新されていたら、線を描く
		if (minMos < 0) //上方向に伸ばす線
		{
			int y0 = index2y(currentRow + minMos) + onionDotYPos + 10; //10は●の直径
			int y1 = index2y(currentRow) - 15;
			p.drawLine(15, y0, 15, y1);
		}
		if (maxMos > 0) //下方向に伸ばす線
		{
			int y0 = index2y(currentRow + 1) + 15;
			int y1 = index2y(currentRow + maxMos) + onionDotYPos;
			p.drawLine(15, y0, 15, y1);
		}
	}

	//--- Fix Onion Skinの描画
	for (i = 0; i < osMask.getFosCount(); i++) {
		int fos = osMask.getFos(i);
		//if(fos == currentRow) continue;
		int y = index2y(fos) + onionDotYPos;
		p.setPen(Qt::red);
		//OnionSkinがDisableなら中空にする
		p.setBrush(osMask.isEnabled() ? QBrush(QColor(0, 255, 255, 128)) : Qt::NoBrush);
		p.drawEllipse(0, y, 10, 10);
	}
	//---

	//--- 動く Onion Skinの描画 その2

	//続いて、各OnionSkinの●を描く
	p.setPen(Qt::red);
	for (i = 0; i < mosCount; i++) {
		//mosはOnionSkinの描かれるフレームのオフセット値
		int mos = osMask.getMos(i);
		//100312 iwasawa ハイライトする場合は後で描くのでスキップする
		if (currentRow + mos == m_highlightedMosFrame)
			continue;

		int y = index2y(currentRow + mos) + onionDotYPos;

		p.setBrush(mos < 0 ? backColor : frontColor);

		p.drawEllipse(10, y, 10, 10);
	}

	//Fix Onion Skin ハイライトの描画 FixOnionSkinがマウスが乗ってハイライトされていて、
	//かつ 現在のフレームでないときに描画
	if (m_highlightedFosFrame >= 0 && m_highlightedFosFrame != currentRow) {
		p.setPen(QColor(255, 128, 0));
		p.setBrush(QBrush(QColor(255, 255, 0, 200)));
		p.drawEllipse(0, index2y(m_highlightedFosFrame) + onionDotYPos, 10, 10);
	}

	//通常のOnion Skin ハイライトの描画
	if (m_highlightedMosFrame >= 0 && m_highlightedMosFrame != currentRow) {
		p.setPen(QColor(255, 128, 0));
		p.setBrush(QBrush(QColor(255, 255, 0, 200)));
		p.drawEllipse(10, index2y(m_highlightedMosFrame) + onionDotYPos, 10, 10);
	}
}
bool FrameHeadGadget::eventFilter(QObject *obj, QEvent *e)
{
	QWidget *viewer = dynamic_cast<QWidget *>(obj);

	if (e->type() == QEvent::MouseButtonPress) {
		m_action = None;

		// click
		if (m_highlightedFosFrame >= 0) {
			m_highlightedFosFrame = -1;
			viewer->update();
		}

		QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent *>(e);
		int frame = y2index(mouseEvent->pos().y());
		m_buttonPressCellIndex = frame;
		int currentFrame = getCurrentFrame();
		int x = mouseEvent->pos().x();
		int y = mouseEvent->pos().y() - index2y(frame);

		if (x > 24 || x > 12 && frame != currentFrame)
			return false;
		if (y < 12) {
#ifdef STUDENT
			bool isMosArea = false;
#else
			bool isMosArea = x < 6;
#endif
			// click nel quadratino bianco.
			if (isMosArea) {
				// Mos
				bool on = !isMos(frame);
				m_action = on ? ActivateMos : DeactivateMos;
				if (frame != currentFrame)
					setMos(frame, on);
			} else if (frame == currentFrame)
				m_action = MoveHead;
			else {
				// Fos
				bool on = !isFos(frame);
				m_action = on ? ActivateFos : DeactivateFos;
				setFos(frame, on);
			}
		} else {
			// fuori dal quadratino bianco: muovo il frame corrente
			m_action = MoveHead;
			setCurrentFrame(frame);
		}
		viewer->update();
	} else if (e->type() == QEvent::MouseButtonRelease) {
		QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent *>(e);
		int frame = y2index(mouseEvent->pos().y());
		int currentFrame = getCurrentFrame();
		int x = mouseEvent->pos().x();
		int y = mouseEvent->pos().y() - index2y(frame);
		if (x > 24 || x > 12 && frame != currentFrame)
			return false;
		if (mouseEvent->button() == Qt::RightButton)
			return false;
#ifndef STUDENT
		if (x < 12 && y < 12 && frame == currentFrame && m_buttonPressCellIndex == frame) {
			enableOnionSkin(!isOnionSkinEnabled());
			viewer->update();
		}
#endif
	} else if (e->type() == QEvent::MouseMove) {
		QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent *>(e);
		int frame = y2index(mouseEvent->pos().y());
		int x = mouseEvent->pos().x();
		int y = mouseEvent->pos().y() - index2y(frame);
		if (mouseEvent->buttons() == 0) {
			// mouse move
			int highlightedFosFrame = (6 <= x && x <= 12 && y < 12) ? frame : -1;
			if (highlightedFosFrame != m_highlightedFosFrame) {
				m_highlightedFosFrame = highlightedFosFrame;
				viewer->update();
			}
			if (getCurrentFrame() == frame)
				viewer->setToolTip(tr("Current Frame"));
			else if (x < 7) {
#ifdef STUDENT
				viewer->setToolTip(tr("Relative Onion Skin Toggle"));
#else
				viewer->setToolTip("");
#endif
			} else if (x < 13)
				viewer->setToolTip(tr("Fixed Onion Skin Toggle"));
			else
				viewer->setToolTip(tr(""));
		} else if (mouseEvent->buttons() & Qt::LeftButton) {
			// drag
			switch (m_action) {
			case MoveHead:
				setCurrentFrame(frame);
				break;
#ifndef STUDENT
			case ActivateMos:
				setMos(frame, true);
				break;
#endif
			case DeactivateMos:
				setMos(frame, false);
				break;
			case ActivateFos:
				setFos(frame, true);
				break;
			case DeactivateFos:
				setFos(frame, false);
				break;
			default:
				return false;
			}
			viewer->update();
		} else if (mouseEvent->buttons() & Qt::MidButton)
			return false;
	} else
		return false;
	return true;
}
Esempio n. 7
0
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));
}
Esempio n. 8
0
void HistoryField::exposeCurrent()
{
	int currentIndex = TUndoManager::manager()->getCurrentHistoryIndex();

	m_scrollArea->ensureVisible(0, index2y(currentIndex) + 10, 50, 10);
}