Skip to content

Commit

Permalink
DxfLinePattern ui support
Browse files Browse the repository at this point in the history
  • Loading branch information
feragon committed Jul 20, 2016
1 parent bc6369e commit 3fce229
Show file tree
Hide file tree
Showing 23 changed files with 678 additions and 30 deletions.
16 changes: 13 additions & 3 deletions lcUI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
45 changes: 35 additions & 10 deletions lcUI/dialogs/addlayerdialog.cpp
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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);

Expand Down
6 changes: 5 additions & 1 deletion lcUI/dialogs/addlayerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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:
Expand All @@ -28,4 +31,5 @@ class AddLayerDialog : public QDialog {

private:
Ui::AddLayerDialog* ui;
LinePatternSelect* linePatternSelect;
};
2 changes: 1 addition & 1 deletion lcUI/dialogs/addlayerdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>514</width>
<height>178</height>
<height>186</height>
</rect>
</property>
<property name="windowTitle">
Expand Down
91 changes: 91 additions & 0 deletions lcUI/dialogs/addlinepatterndialog.cpp
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;
}
38 changes: 38 additions & 0 deletions lcUI/dialogs/addlinepatterndialog.h
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;
};
Loading

0 comments on commit 3fce229

Please sign in to comment.