Permalink
Browse files

DxfLinePattern ui support

  • Loading branch information...
feragon committed Jul 20, 2016
1 parent bc6369e commit 3fce229e8fa66ee52d44bdc43ae9981dfda44c4d
View
@@ -38,9 +38,13 @@ widgets/toolbar.h
widgets/toolbartab.h
widgets/layers.h
widgets/layermodel.h
widgets/linepatternselect.h
widgets/linepatternpainter.h
widgets/linepatternpathpart.h
lua/qtbridge.h
lua/luaqobject.h
dialogs/addlayerdialog.h)
dialogs/addlayerdialog.h
dialogs/addlinepatterndialog.h)
set(UI_srcs
cadmdichild.cpp
@@ -57,17 +61,23 @@ widgets/toolbar.cpp
widgets/toolbartab.cpp
widgets/layers.cpp
widgets/layermodel.cpp
widgets/linepatternselect.cpp
widgets/linepatternpainter.cpp
widgets/linepatternpathpart.cpp
lua/qtbridge.cpp
lua/luaqobject.cpp
dialogs/addlayerdialog.cpp)
dialogs/addlayerdialog.cpp
dialogs/addlinepatterndialog.cpp)
QT5_WRAP_UI(UI_HEADERS
widgets/clicommand.ui
widgets/luascript.ui
widgets/toolbar.ui
widgets/toolbartab.ui
widgets/layers.ui
dialogs/addlayerdialog.ui)
widgets/linepatternpathpart.ui
dialogs/addlayerdialog.ui
dialogs/addlinepatterndialog.ui)
qt5_add_resources(UI_RESOURCES
ui/resource.qrc)
@@ -1,11 +1,18 @@
#include "addlayerdialog.h"
#include "ui_addlayerdialog.h"
AddLayerDialog::AddLayerDialog(QWidget* parent) :
AddLayerDialog::AddLayerDialog(std::vector<lc::DxfLinePattern_CSPtr> linePatterns, QWidget* parent) :
QDialog(parent),
ui(new Ui::AddLayerDialog){
ui->setupUi(this);
linePatternSelect = new LinePatternSelect(linePatterns, nullptr);
auto layout = dynamic_cast<QFormLayout*>(this->layout());
if(layout) {
layout->setWidget(3, QFormLayout::FieldRole, linePatternSelect);
}
}
AddLayerDialog::~AddLayerDialog() {
@@ -18,15 +25,33 @@ void AddLayerDialog::accept() {
return;
}
auto layer = std::make_shared<const lc::Layer>(
ui->name->text().toStdString(),
lc::MetaLineWidthByValue(ui->width->value()),
lc::Color(ui->r->value(),
ui->g->value(),
ui->b->value(),
ui->a->value()
)
);
auto linePattern = linePatternSelect->linePattern();
lc::Layer_CSPtr layer;
if(linePattern == nullptr) {
layer = std::make_shared<const lc::Layer>(
ui->name->text().toStdString(),
lc::MetaLineWidthByValue(ui->width->value()),
lc::Color(ui->r->value(),
ui->g->value(),
ui->b->value(),
ui->a->value()
)
);
}
else {
layer = std::make_shared<const lc::Layer>(
ui->name->text().toStdString(),
lc::MetaLineWidthByValue(ui->width->value()),
lc::Color(ui->r->value(),
ui->g->value(),
ui->b->value(),
ui->a->value()
),
linePattern,
false
);
}
emit newLayer(layer);
@@ -3,6 +3,9 @@
#include <QDialog>
#include <QColorDialog>
#include <QToolTip>
#include <QFormLayout>
#include "widgets/linepatternselect.h"
#include <cad/meta/layer.h>
#include <cad/meta/metalinewidth.h>
@@ -15,7 +18,7 @@ class AddLayerDialog : public QDialog {
Q_OBJECT
public:
AddLayerDialog(QWidget* parent = 0);
AddLayerDialog(std::vector<lc::DxfLinePattern_CSPtr> linePatterns, QWidget* parent = 0);
~AddLayerDialog();
signals:
@@ -28,4 +31,5 @@ class AddLayerDialog : public QDialog {
private:
Ui::AddLayerDialog* ui;
LinePatternSelect* linePatternSelect;
};
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>514</width>
<height>178</height>
<height>186</height>
</rect>
</property>
<property name="windowTitle">
@@ -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;
}
@@ -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.

0 comments on commit 3fce229

Please sign in to comment.