17#include "pegbaralignmentdialog.h"
18#include "ui_pegbaralignmentdialog.h"
21#include <QListWidgetItem>
25#include "layermanager.h"
26#include "selectionmanager.h"
27#include "toolmanager.h"
28#include "scribblearea.h"
30#include <pegbaraligner.h>
32PegBarAlignmentDialog::PegBarAlignmentDialog(
Editor *editor,
QWidget *parent) :
41 connect(mEditor->layers(), &LayerManager::layerCountChanged,
this, &PegBarAlignmentDialog::updatePegRegLayers);
42 connect(mEditor->select(), &SelectionManager::selectionChanged,
this, &PegBarAlignmentDialog::updatePegRegDialog);
43 connect(mEditor, &
Editor::scrubbed,
this, &PegBarAlignmentDialog::updatePegRegDialog);
45 connect(mEditor->layers(), &LayerManager::currentLayerChanged,
this, &PegBarAlignmentDialog::updatePegRegDialog);
47 ui->btnAlign->setEnabled(
false);
50 mEditor->tools()->setCurrentTool(SELECT);
52 if (!mEditor->select()->somethingSelected()) {
53 QPoint centralPoint = mEditor->getScribbleArea()->getCentralPoint().toPoint();
54 mEditor->select()->setSelection(
QRect(centralPoint.
x()-100,centralPoint.
y()-50,200,100));
59PegBarAlignmentDialog::~PegBarAlignmentDialog()
64void PegBarAlignmentDialog::setLayerList(
QStringList layerList)
66 ui->lwLayers->clear();
67 mLayernames = layerList;
68 for (
int i = 0; i < mLayernames.
count(); i++)
70 ui->lwLayers->addItem(mLayernames.
at(i));
74 if (ui->lwLayers->count() > 0) {
75 ui->lwLayers->item(0)->setSelected(
true);
82 selectedLayers.
clear();
83 for (
int i = 0; i < ui->lwLayers->count(); i++)
85 if (!ui->lwLayers->item(i)->isSelected()) {
continue; }
87 selectedLayers.
append(ui->lwLayers->item(i)->text());
89 return selectedLayers;
92void PegBarAlignmentDialog::updateRefKeyLabel(
QString text)
94 ui->labRefKey->setText(text);
97void PegBarAlignmentDialog::setAreaSelected(
bool b)
103void PegBarAlignmentDialog::setReferenceSelected(
bool b)
105 mReferenceSelected = b;
109void PegBarAlignmentDialog::setLayerSelected(
bool b)
115void PegBarAlignmentDialog::updatePegRegLayers()
118 auto layerMan = mEditor->layers();
119 for (
int i = 0; i < layerMan->count(); i++)
121 const Layer* layer = layerMan->getLayer(i);
122 if (layer->type() != Layer::BITMAP) {
continue; }
124 bitmaplayers.
append(layer->name());
126 setLayerList(bitmaplayers);
127 updatePegRegDialog();
130void PegBarAlignmentDialog::updatePegRegDialog()
133 setAreaSelected(mEditor->select()->somethingSelected());
135 const Layer* currentLayer = mEditor->layers()->currentLayer();
137 KeyFrame* key = currentLayer->getLastKeyFrameAtPosition(mEditor->currentFrame());
139 if (key ==
nullptr) {
140 updateRefKeyLabel(
"-");
141 setReferenceSelected(
false);
145 bool isReferenceSelected = (currentLayer->type() == Layer::BITMAP &&
147 setReferenceSelected(isReferenceSelected);
152 setLayerSelected(!bitmaplayers.
isEmpty());
157void PegBarAlignmentDialog::alignPegs()
163 tr(
"No layers selected!",
"PegBar Dialog error message"),
178 mEditor->deselectAll();
182void PegBarAlignmentDialog::updateAlignButton()
184 if (mAreaSelected && mReferenceSelected && mLayerSelected)
185 ui->btnAlign->setEnabled(
true);
187 ui->btnAlign->setEnabled(
false);
190void PegBarAlignmentDialog::closeClicked()
void framesModified()
This should be emitted after modifying multiple frames.
void scrubbed(int frameNumber)
This should be emitted after scrubbing.
void clicked(const QModelIndex &index)
void append(const T &value)
const T & at(int i) const const
int count(const T &value) const const
bool isEmpty() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QRect toAlignedRect() const const
QString number(int n, int base)