1#include "repositionframesdialog.h"
2#include "ui_repositionframesdialog.h"
5#include <QListWidgetItem>
8#include "selectionmanager.h"
9#include "selectionpainter.h"
10#include "viewmanager.h"
11#include "toolmanager.h"
13#include "layermanager.h"
14#include "layerbitmap.h"
15#include "scribblearea.h"
18RepositionFramesDialog::RepositionFramesDialog(
QWidget* parent) :
25RepositionFramesDialog::~RepositionFramesDialog()
30void RepositionFramesDialog::setCore(
Editor *editor)
35void RepositionFramesDialog::initUI()
37 if (mEditor->layers()->currentLayer()->keyExists(mEditor->currentFrame()))
39 mRepositionFrame = mEditor->currentFrame();
43 mRepositionFrame = mEditor->layers()->currentLayer()->getSelectedFramesByPos().
at(0);
46 prepareRepositionSelectedImages(mRepositionFrame);
50 ui->rbAllKeyframes->setChecked(
true);
56 connect(mEditor->getScribbleArea(), &ScribbleArea::selectionUpdated,
this, &RepositionFramesDialog::updateDialogText);
57 connect(mEditor->select(), &SelectionManager::selectionReset,
this, &RepositionFramesDialog::closeClicked);
58 mEndPoint = mStartPoint =
QPoint(0,0);
59 mOriginalPolygonF = mEditor->select()->mySelectionRect();
60 updateDialogSelectedFrames();
64void RepositionFramesDialog::updateDialogText()
68 mOriginalPolygonF = mEditor->select()->mySelectionRect();
70 mCurrentPolygonF = mEditor->select()->selectionTransform().
map(mEditor->select()->mySelectionRect());
71 QPoint point = getRepositionPoint();
72 ui->labRepositioned->setText(
tr(
"Repositioned: ( %1, %2 )").arg(point.
x()).
arg(point.
y()));
75void RepositionFramesDialog::updateDialogSelectedFrames()
77 QList<int> framelist = mEditor->layers()->currentLayer()->getSelectedFramesByPos();
78 ui->labRepositionFrames->setText(
tr(
"Selected on Layer: %1").arg(mEditor->layers()->currentLayer()->name()));
79 ui->listSelectedFrames->clear();
80 for (
int i = 0; i < framelist.
count(); i++)
86void RepositionFramesDialog::repositionFrames()
88 if (mStartPoint == mEndPoint)
91 tr(
"Please move selection to desired destination\n"
97 QList<int> frames = mEditor->layers()->currentLayer()->getSelectedFramesByPos();
98 for (
int i = 0; i < frames.
size(); i++)
100 mEditor->repositionImage(mEndPoint, frames.
at(i));
103 if (!ui->listSelectedLayers->selectedItems().isEmpty())
105 auto layerManager = mEditor->layers();
108 if (ui->rbSameKeyframes->isChecked())
110 int currLayer = mEditor->currentLayerIndex();
111 for (
int j = 0; j < mLayerIndexes.
size(); j++)
116 layerManager->setCurrentLayer(mLayerIndexes.
at(j));
117 for (
int i = 0; i < frames.
size(); i++)
119 if (layerManager->currentLayer()->keyExists(frames.
at(i)))
121 mEditor->repositionImage(mEndPoint, frames.
at(i));
126 layerManager->setCurrentLayer(currLayer);
131 int currLayer = mEditor->currentLayerIndex();
132 for (
int i= 0; i < mLayerIndexes.
size(); i++)
137 layerManager->setCurrentLayer(mLayerIndexes.
at(i));
138 int keyframe = layerManager->currentLayer()->firstKeyFramePosition();
140 mEditor->repositionImage(mEndPoint, keyframe);
141 keyframe = layerManager->currentLayer()->getNextKeyFramePosition(keyframe);
143 while (mEditor->currentFrame() != layerManager->currentLayer()->getMaxKeyFramePosition());
146 layerManager->setCurrentLayer(currLayer);
149 mEditor->getScribbleArea()->applyTransformedSelection();
150 mEditor->select()->resetSelectionProperties();
151 mEditor->scrubTo(mRepositionFrame);
156void RepositionFramesDialog::updateRadioButtons()
158 if (ui->cbOtherLayers->isChecked())
160 ui->rbAllKeyframes->setEnabled(
true);
161 ui->rbSameKeyframes->setEnabled(
true);
162 ui->listSelectedLayers->setEnabled(
true);
166 ui->rbAllKeyframes->setEnabled(
false);
167 ui->rbSameKeyframes->setEnabled(
false);
168 ui->listSelectedLayers->setEnabled(
false);
172void RepositionFramesDialog::checkboxStateChanged(
int i)
177 updateLayersToSelect();
180 ui->listSelectedLayers->clear();
183 updateRadioButtons();
186void RepositionFramesDialog::updateLayersBox()
188 updateLayersToSelect();
191void RepositionFramesDialog::closeClicked()
196void RepositionFramesDialog::updateLayersToSelect()
198 ui->listSelectedLayers->clear();
200 mLayerIndexes.
clear();
201 auto layerManager = mEditor->layers();
202 if (ui->rbAllKeyframes->isChecked())
204 for (
int i = layerManager->count() - 1; i >= 0; i--)
206 if (layerManager->getLayer(i)->type() == Layer::BITMAP &&
207 i != layerManager->currentLayerIndex())
209 ui->listSelectedLayers->addItem(layerManager->getLayer(i)->name());
216 QList<int> frames = layerManager->currentLayer()->getSelectedFramesByPos();
218 for (
int i = layerManager->count() - 1; i >= 0; i--)
220 if (layerManager->getLayer(i)->type() == Layer::BITMAP &&
221 i != layerManager->currentLayerIndex())
223 Layer* layer = layerManager->getLayer(i);
224 for (
int j = 0; j < frames.
size(); j++)
226 if (layer->keyExists(frames.
at(j)))
231 ui->listSelectedLayers->addItem(layer->name());
241QPoint RepositionFramesDialog::getRepositionPoint()
249void RepositionFramesDialog::prepareRepositionSelectedImages(
int repositionFrame)
251 auto select = mEditor->select();
252 auto layers = mEditor->layers();
254 if (select->somethingSelected()) {
return; }
256 if (layers->currentLayer()->type() == Layer::BITMAP)
258 mEditor->scrubTo(repositionFrame);
260 QRect reposRect = layer->getFrameBounds(repositionFrame);
261 select->setSelection(reposRect);
void stateChanged(int state)
void append(const T &value)
const T & at(int i) const const
int count(const T &value) const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString tr(const char *sourceText, const char *disambiguation, int n)
QRectF boundingRect() const const
bool isEmpty() const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString number(int n, int base)