这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions app/src/mainwindow2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,6 @@ void MainWindow2::openPegAlignDialog()

mPegAlign = new PegBarAlignmentDialog(mEditor, this);
mPegAlign->setAttribute(Qt::WA_DeleteOnClose);
mPegAlign->updatePegRegLayers();
mPegAlign->setRefLayer(mEditor->layers()->currentLayer()->name());
mPegAlign->setRefKey(mEditor->currentFrame());

Qt::WindowFlags flags = mPegAlign->windowFlags();
flags |= Qt::WindowStaysOnTopHint;
Expand Down Expand Up @@ -592,6 +589,8 @@ bool MainWindow2::openObject(const QString& strFilePath)
mRecentFileMenu->saveToDisk();
}

closeDialogs();

setWindowTitle(mEditor->object()->filePath().prepend("[*]"));
setWindowModified(false);

Expand Down Expand Up @@ -986,6 +985,8 @@ void MainWindow2::newObject()
object->createDefaultLayers();
mEditor->setObject(object);

closeDialogs();

setWindowTitle(PENCIL_WINDOW_TITLE);
}

Expand Down Expand Up @@ -1063,6 +1064,13 @@ bool MainWindow2::tryLoadPreset()
return true;
}

void MainWindow2::closeDialogs()
{
for (auto dialog : findChildren<QDialog*>(QString(), Qt::FindDirectChildrenOnly)) {
dialog->close();
}
}

void MainWindow2::readSettings()
{
QSettings settings(PENCIL2D, PENCIL2D);
Expand Down Expand Up @@ -1332,6 +1340,7 @@ void MainWindow2::makeConnections(Editor* editor, ColorInspector* colorInspector
void MainWindow2::makeConnections(Editor* editor, ScribbleArea* scribbleArea)
{
connect(editor->tools(), &ToolManager::toolChanged, scribbleArea, &ScribbleArea::setCurrentTool);
connect(editor->tools(), &ToolManager::toolChanged, mToolBox, &ToolBoxWidget::onToolSetActive);
connect(editor->tools(), &ToolManager::toolPropertyChanged, scribbleArea, &ScribbleArea::updateToolCursor);


Expand Down
1 change: 1 addition & 0 deletions app/src/mainwindow2.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public slots:
bool newObjectFromPresets(int presetIndex);
bool openObject(const QString& strFilename);
bool saveObject(QString strFileName);
void closeDialogs();

void createDockWidgets();
void createMenus();
Expand Down
95 changes: 52 additions & 43 deletions app/src/pegbaralignmentdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,40 @@ GNU General Public License for more details.
#include <QListWidget>
#include <QListWidgetItem>
#include <QMessageBox>

#include "keyframe.h"
#include "layermanager.h"
#include "selectionmanager.h"
#include "toolmanager.h"
#include "scribblearea.h"

#include <pegbaraligner.h>

PegBarAlignmentDialog::PegBarAlignmentDialog(Editor *editor, QWidget *parent) :
QDialog(parent),
ui(new Ui::PegBarAlignmentDialog)
ui(new Ui::PegBarAlignmentDialog), mEditor(editor)
{
ui->setupUi(this);
mEditor = editor;
connect(ui->btnAlign, &QPushButton::clicked, this, &PegBarAlignmentDialog::alignPegs);
connect(ui->btnCancel, &QPushButton::clicked, this, &PegBarAlignmentDialog::closeClicked);
connect(ui->lwLayers, &QListWidget::clicked, this, &PegBarAlignmentDialog::updatePegRegDialog);

connect(mEditor->layers(), &LayerManager::layerCountChanged, this, &PegBarAlignmentDialog::updatePegRegLayers);
connect(mEditor->select(), &SelectionManager::selectionChanged, this, &PegBarAlignmentDialog::updatePegRegDialog);
connect(mEditor, &Editor::scrubbed, this, &PegBarAlignmentDialog::updatePegRegDialog);
connect(mEditor, &Editor::framesModified, this, &PegBarAlignmentDialog::updatePegRegDialog);
connect(mEditor->layers(), &LayerManager::currentLayerChanged, this, &PegBarAlignmentDialog::updatePegRegDialog);

ui->btnAlign->setEnabled(false);
mLayernames.clear();

mEditor->tools()->setCurrentTool(SELECT);

if (!mEditor->select()->somethingSelected()) {
QPoint centralPoint = mEditor->getScribbleArea()->getCentralPoint().toPoint();
mEditor->select()->setSelection(QRect(centralPoint.x()-100,centralPoint.y()-50,200,100));
}
updatePegRegLayers();
}

PegBarAlignmentDialog::~PegBarAlignmentDialog()
Expand All @@ -55,6 +69,11 @@ void PegBarAlignmentDialog::setLayerList(QStringList layerList)
{
ui->lwLayers->addItem(mLayernames.at(i));
}

// Select the first layer.
if (ui->lwLayers->count() > 0) {
ui->lwLayers->item(0)->setSelected(true);
}
}

QStringList PegBarAlignmentDialog::getLayerList()
Expand All @@ -63,46 +82,49 @@ QStringList PegBarAlignmentDialog::getLayerList()
selectedLayers.clear();
for (int i = 0; i < ui->lwLayers->count(); i++)
{
if (ui->lwLayers->item(i)->isSelected())
selectedLayers.append(ui->lwLayers->item(i)->text());
if (!ui->lwLayers->item(i)->isSelected()) { continue; }

selectedLayers.append(ui->lwLayers->item(i)->text());
}
return selectedLayers;
}

void PegBarAlignmentDialog::updateRefKeyLabelText()
void PegBarAlignmentDialog::updateRefKeyLabel(QString text)
{
ui->labRefKey->setText(QStringLiteral("%1 - %2").arg(mRefLayer).arg(mRefkey));
ui->labRefKey->setText(text);
}

void PegBarAlignmentDialog::setAreaSelected(bool b)
{
mAreaSelected = b;
setBtnAlignEnabled();
updateAlignButton();
}

void PegBarAlignmentDialog::setReferenceSelected(bool b)
{
mReferenceSelected = b;
setBtnAlignEnabled();
updateAlignButton();
}

void PegBarAlignmentDialog::setLayerSelected(bool b)
{
mLayerSelected = b;
setBtnAlignEnabled();
updateAlignButton();
}

void PegBarAlignmentDialog::updatePegRegLayers()
{
QStringList bitmaplayers;
for (int i = 0; i < mEditor->layers()->count(); i++)
auto layerMan = mEditor->layers();
for (int i = 0; i < layerMan->count(); i++)
{
if (mEditor->layers()->getLayer(i)->type() == Layer::BITMAP)
{
bitmaplayers.append(mEditor->layers()->getLayer(i)->name());
}
const Layer* layer = layerMan->getLayer(i);
if (layer->type() != Layer::BITMAP) { continue; }

bitmaplayers.append(layer->name());
}
setLayerList(bitmaplayers);
updatePegRegDialog();
}

void PegBarAlignmentDialog::updatePegRegDialog()
Expand All @@ -112,28 +134,24 @@ void PegBarAlignmentDialog::updatePegRegDialog()

const Layer* currentLayer = mEditor->layers()->currentLayer();
// is the reference key valid?
setRefLayer(currentLayer->name());
setRefKey(mEditor->currentFrame());
KeyFrame* key = currentLayer->getLastKeyFrameAtPosition(mEditor->currentFrame());

if (key == nullptr) {
updateRefKeyLabel("-");
setReferenceSelected(false);
return;
}

bool isReferenceSelected = (currentLayer->type() == Layer::BITMAP &&
currentLayer->keyExists(mEditor->currentFrame()));
key->pos());
setReferenceSelected(isReferenceSelected);

// has minimum one layer been selected?
const QStringList bitmaplayers = getLayerList();

if (bitmaplayers.isEmpty())
{
setLayerSelected(false);
}
else
{
setRefLayer(currentLayer->name());
setRefKey(mEditor->currentFrame());
setLayerSelected(true);
}

setBtnAlignEnabled();
setLayerSelected(!bitmaplayers.isEmpty());
updateRefKeyLabel(QString::number(key->pos()));
updateAlignButton();
}

void PegBarAlignmentDialog::alignPegs()
Expand All @@ -147,37 +165,28 @@ void PegBarAlignmentDialog::alignPegs()
return;
}

Status result = mEditor->pegBarAlignment(bitmaplayers);

Status result = PegBarAligner(mEditor, mEditor->select()->mySelectionRect().toAlignedRect()).align(bitmaplayers);
if (!result.ok())
{
QMessageBox::information(this, "Pencil2D",
result.description(),
QMessageBox::Ok);
return;
}

mEditor->deselectAll();
done(QDialog::Accepted);
}

void PegBarAlignmentDialog::setBtnAlignEnabled()
void PegBarAlignmentDialog::updateAlignButton()
{
if (mAreaSelected && mReferenceSelected && mLayerSelected)
ui->btnAlign->setEnabled(true);
else
ui->btnAlign->setEnabled(false);
}

void PegBarAlignmentDialog::setRefLayer(QString s)
{
mRefLayer = s;
updateRefKeyLabelText();
}

void PegBarAlignmentDialog::setRefKey(int i)
{
mRefkey = i;
updateRefKeyLabelText();
}

void PegBarAlignmentDialog::closeClicked()
{
done(QDialog::Accepted);
Expand Down
25 changes: 9 additions & 16 deletions app/src/pegbaralignmentdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,21 @@ class PegBarAlignmentDialog : public QDialog
explicit PegBarAlignmentDialog(Editor* editor, QWidget* parent = nullptr);
~PegBarAlignmentDialog();

void setLayerList(QStringList layerList);
QStringList getLayerList();
int getRefKey() { return mRefkey; }
QString getRefLayer() { return mRefLayer; }
void updateRefKeyLabelText();

void setAreaSelected(bool b);
void setReferenceSelected(bool b);
void setLayerSelected(bool b);
public slots:
void updateAlignButton();

private:
void updatePegRegLayers();
void updatePegRegDialog();
void alignPegs();
void setLayerList(QStringList layerList);
void updateRefKeyLabel(QString text);

public slots:
void setBtnAlignEnabled();
void setRefLayer(QString s);
void setRefKey(int i);
QStringList getLayerList();

private:
void setAreaSelected(bool b);
void setReferenceSelected(bool b);
void setLayerSelected(bool b);
void closeClicked();

Ui::PegBarAlignmentDialog* ui;
Expand All @@ -61,8 +56,6 @@ public slots:
bool mAreaSelected = false;
bool mReferenceSelected = false;
bool mLayerSelected = false;
QString mRefLayer;
int mRefkey = 0;
};

#endif // PEGBARALIGNMENTDIALOG_H
Loading