-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
678 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#include "addlinepatterndialog.h" | ||
#include "ui_addlinepatterndialog.h" | ||
|
||
AddLinePatternDialog::AddLinePatternDialog(QWidget *parent) : | ||
AddLinePatternDialog(nullptr, parent) { | ||
} | ||
|
||
AddLinePatternDialog::AddLinePatternDialog(lc::DxfLinePattern_CSPtr linePattern, QWidget *parent) : | ||
QDialog(parent), | ||
ui(new Ui::AddLinePatternDialog), | ||
_linePattern(linePattern) { | ||
|
||
ui->setupUi(this); | ||
|
||
_layout = static_cast<QVBoxLayout*>(ui->pathList->layout()); | ||
if(!_layout) { | ||
throw "Unable to cast AddLinePatternDialog pathList layout to QVBoxLayout"; | ||
} | ||
|
||
connect(ui->newValueButton, &QPushButton::pressed, this, &AddLinePatternDialog::onNewValuePressed); | ||
|
||
if(linePattern != nullptr) { | ||
ui->name->setText(linePattern->name().c_str()); | ||
ui->description->setText(linePattern->description().c_str()); | ||
|
||
for (auto value : linePattern->path()) { | ||
auto pathPart = new LinePatternPathPart(value, this); | ||
connect(pathPart, &LinePatternPathPart::update, this, &AddLinePatternDialog::generatePreview); | ||
|
||
_layout->insertWidget(_layout->count() - 1, pathPart); | ||
} | ||
} | ||
} | ||
|
||
void AddLinePatternDialog::generatePreview() { | ||
std::string name = ui->name->text().toStdString(); | ||
if(name.empty()) { | ||
name = "tmp"; | ||
} | ||
|
||
std::vector<double> path; | ||
double length; | ||
|
||
auto parts = findChildren<LinePatternPathPart*>(); | ||
|
||
for(auto part : parts) { | ||
auto type = part->type(); | ||
auto value = part->value(); | ||
|
||
switch(type) { | ||
case LinePatternPathPart::PATH_DOT: | ||
path.push_back(0); | ||
break; | ||
|
||
case LinePatternPathPart::PATH_PLAIN: | ||
path.push_back(value); | ||
length += value; | ||
break; | ||
|
||
case LinePatternPathPart::PATH_SPACE: | ||
path.push_back(-value); | ||
length += value; | ||
break; | ||
} | ||
} | ||
|
||
_linePattern = std::make_shared<lc::DxfLinePattern>( | ||
name, | ||
ui->description->text().toStdString(), | ||
path, | ||
length); | ||
|
||
QPixmap previewPixmap(ui->preview->frameSize()); | ||
|
||
LinePatternPainter painter(_linePattern, &previewPixmap); | ||
painter.drawLinePattern(); | ||
|
||
ui->preview->setPixmap(previewPixmap); | ||
} | ||
|
||
|
||
void AddLinePatternDialog::onNewValuePressed() { | ||
auto pathPart = new LinePatternPathPart(this); | ||
connect(pathPart, &LinePatternPathPart::update, this, &AddLinePatternDialog::generatePreview); | ||
|
||
_layout->insertWidget(_layout->count() - 1, pathPart); | ||
} | ||
|
||
lc::DxfLinePattern_CSPtr AddLinePatternDialog::linePattern() { | ||
return _linePattern; | ||
} |
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,38 @@ | ||
#pragma once | ||
|
||
#include <cmath> | ||
|
||
#include <QDialog> | ||
#include <QHBoxLayout> | ||
#include <QComboBox> | ||
#include <QDoubleSpinBox> | ||
#include <QPushButton> | ||
|
||
#include <cad/meta/dxflinepattern.h> | ||
|
||
#include "widgets/linepatternpathpart.h" | ||
#include "widgets/linepatternpainter.h" | ||
|
||
namespace Ui { | ||
class AddLinePatternDialog; | ||
} | ||
|
||
class AddLinePatternDialog : public QDialog { | ||
Q_OBJECT | ||
|
||
public: | ||
AddLinePatternDialog(QWidget* parent = 0); | ||
AddLinePatternDialog(lc::DxfLinePattern_CSPtr linePattern, QWidget* parent = 0); | ||
|
||
lc::DxfLinePattern_CSPtr linePattern(); | ||
|
||
private slots: | ||
void onNewValuePressed(); | ||
void generatePreview(); | ||
|
||
private: | ||
Ui::AddLinePatternDialog* ui; | ||
QVBoxLayout* _layout; | ||
|
||
lc::DxfLinePattern_CSPtr _linePattern; | ||
}; |
Oops, something went wrong.