17#include "pegbaraligner.h"
21#include <pencilerror.h>
23#include <bitmapimage.h>
24#include <layerbitmap.h>
25#include <layermanager.h>
27PegStatus::PegStatus(ErrorCode code,
QPoint point)
28 :
Status(code), point(point)
32PegBarAligner::PegBarAligner(
Editor* editor,
QRect searchRect) :
33 mEditor(editor), mPegSearchRect(searchRect)
41 BitmapImage* img = layerBitmap->getBitmapImageAtFrame(mEditor->currentFrame());
46 return Status(Status::FAIL, tr(
"Peg hole not found!\nCheck selection, and please try again.",
"PegBar error message"));
49 const int pegX = result.point.
x();
50 const int pegY = result.point.
y();
52 for (
int i = 0; i < layers.
count(); i++)
54 layerBitmap =
static_cast<LayerBitmap*
>(mEditor->layers()->findLayerByName(layers.
at(i)));
55 for (
int k = layerBitmap->firstKeyFramePosition(); k <= layerBitmap->getMaxKeyFramePosition(); k++)
57 if (!layerBitmap->keyExists(k)) {
continue; }
59 img = layerBitmap->getBitmapImageAtFrame(k);
60 img->enableAutoCrop(
false);
62 result = findPoint(*img);
65 const QString errorDescription = tr(
"Peg bar not found at %2, %1").
arg(k).
arg(layerBitmap->name());
66 return Status(result.code(), errorDescription);
68 img->moveTopLeft(
QPoint(img->left() + (pegX - result.point.
x()), img->top() + (pegY - result.point.
y())));
74 mEditor->deselectAll();
83 const int left = mPegSearchRect.
left();
85 const int top = mPegSearchRect.
top();
86 const int bottom = mPegSearchRect.
bottom();
87 const int grayValue = mGrayThreshold;
91 for (
int x = left; x <=
right && !foundX; x++)
93 for (
int y = top; y <= bottom; y++)
95 const QRgb& scan = image.constScanLine(x,y);
96 if (qAlpha(scan) == 255 && qGray(scan) < grayValue)
107 for (
int y = top; y <= bottom && !foundY; y++)
109 for (
int x = left; x <=
right; x++)
111 const QRgb& scan = image.constScanLine(x,y);
112 if (qAlpha(scan) == 255 && qGray(scan) < grayValue)
122 if (foundX && foundY) {
void frameModified(int frameNumber)
This should be emitted after modifying the frame content.
const T & at(int i) const const
int count(const T &value) const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)