-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1285 from davidlamhauge/issue1177_import_position
#1177 Import drawings on wanted position
- Loading branch information
Showing
13 changed files
with
282 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "importpositiondialog.h" | ||
#include "ui_importpositiondialog.h" | ||
|
||
#include "editor.h" | ||
#include "viewmanager.h" | ||
|
||
#include "scribblearea.h" | ||
|
||
ImportPositionDialog::ImportPositionDialog(QWidget *parent) : | ||
QDialog(parent), | ||
ui(new Ui::ImportPositionDialog) | ||
{ | ||
ui->setupUi(this); | ||
|
||
ui->cbImagePosition->addItem(tr("Center of canvas")); | ||
ui->cbImagePosition->addItem(tr("Center of active camera")); | ||
|
||
connect(ui->cbImagePosition, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ImportPositionDialog::didChangeComboBoxIndex); | ||
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &ImportPositionDialog::changeImportView); | ||
|
||
QSettings settings(PENCIL2D, PENCIL2D); | ||
int value = settings.value(IMPORT_REPOSITION_TYPE).toInt(); | ||
|
||
ui->cbImagePosition->setCurrentIndex(value); | ||
didChangeComboBoxIndex(value); | ||
} | ||
|
||
ImportPositionDialog::~ImportPositionDialog() | ||
{ | ||
delete ui; | ||
} | ||
|
||
void ImportPositionDialog::didChangeComboBoxIndex(const int index) | ||
{ | ||
mImportOption = ImportPosition::getTypeFromIndex(index); | ||
} | ||
|
||
void ImportPositionDialog::changeImportView() | ||
{ | ||
QTransform transform; | ||
if (mImportOption == ImportPosition::Type::CenterOfCanvas) | ||
{ | ||
QPointF centralPoint = mEditor->getScribbleArea()->getCentralPoint(); | ||
transform = transform.fromTranslate(centralPoint.x(), centralPoint.y()); | ||
} | ||
else if (mImportOption == ImportPosition::Type::CenterOfCamera) | ||
{ | ||
QRectF cameraRect = mEditor->getScribbleArea()->getCameraRect(); | ||
transform = transform.fromTranslate(cameraRect.center().x(), cameraRect.center().y()); | ||
} | ||
mEditor->view()->setImportView(transform); | ||
|
||
QSettings settings(PENCIL2D, PENCIL2D); | ||
settings.setValue(IMPORT_REPOSITION_TYPE, ui->cbImagePosition->currentIndex()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#ifndef IMPORTPOSITIONDIALOG_H | ||
#define IMPORTPOSITIONDIALOG_H | ||
|
||
#include <QDialog> | ||
|
||
namespace Ui { | ||
class ImportPositionDialog; | ||
} | ||
|
||
class Editor; | ||
|
||
class ImportPositionDialog : public QDialog | ||
{ | ||
Q_OBJECT | ||
|
||
struct ImportPosition { | ||
|
||
enum Type { | ||
CenterOfCamera, | ||
CenterOfCanvas, | ||
None | ||
}; | ||
|
||
static Type getTypeFromIndex(int index) { | ||
switch (index) { | ||
case 0: | ||
return CenterOfCanvas; | ||
case 1: | ||
return CenterOfCamera; | ||
default: | ||
return None; | ||
} | ||
} | ||
}; | ||
|
||
public: | ||
explicit ImportPositionDialog(QWidget *parent = nullptr); | ||
~ImportPositionDialog(); | ||
|
||
void setCore(Editor* editor) { mEditor = editor; } | ||
|
||
private slots: | ||
void didChangeComboBoxIndex(const int index); | ||
void changeImportView(); | ||
|
||
private: | ||
Ui::ImportPositionDialog *ui; | ||
|
||
ImportPosition::Type mImportOption; | ||
Editor* mEditor = nullptr; | ||
}; | ||
|
||
#endif // IMPORTPOSITIONDIALOG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.