Permalink
Browse files

Line width selection

  • Loading branch information...
feragon committed Aug 8, 2016
1 parent b16030f commit 943242e0ddfe65228e18d6b245a8b6c0f872d5fa
View
@@ -42,6 +42,7 @@ widgets/linepatternselect.h
widgets/linepatternpainter.h
widgets/linepatternpathpart.h
widgets/linepatternmodel.h
widgets/linewidthselect.h
lua/qtbridge.h
lua/luaqobject.h
dialogs/addlayerdialog.h
@@ -67,6 +68,7 @@ widgets/linepatternselect.cpp
widgets/linepatternpainter.cpp
widgets/linepatternpathpart.cpp
widgets/linepatternmodel.cpp
widgets/linewidthselect.cpp
lua/qtbridge.cpp
lua/luaqobject.cpp
dialogs/addlayerdialog.cpp
@@ -13,10 +13,12 @@ AddLayerDialog::AddLayerDialog(lc::Layer_CSPtr oldLayer, lc::Document_SPtr docum
ui->setupUi(this);
linePatternSelect = new LinePatternSelect(document, nullptr);
linePatternSelect = new LinePatternSelect(document, this);
lineWidthSelect = new LineWidthSelect(this);
auto layout = dynamic_cast<QFormLayout*>(this->layout());
if(layout) {
layout->setWidget(2, QFormLayout::FieldRole, lineWidthSelect);
layout->setWidget(3, QFormLayout::FieldRole, linePatternSelect);
}
@@ -28,8 +30,6 @@ AddLayerDialog::AddLayerDialog(lc::Layer_CSPtr oldLayer, lc::Document_SPtr docum
ui->b->setValue(oldLayer->color().blueI());
ui->a->setValue(oldLayer->color().alphaI());
ui->width->setValue(oldLayer->lineWidth().width());
if(oldLayer->linePattern() != nullptr) {
int linePatternIndex = linePatternSelect->findText(oldLayer->linePattern()->name().c_str());
@@ -56,7 +56,7 @@ void AddLayerDialog::accept() {
if(linePattern == nullptr) {
layer = std::make_shared<const lc::Layer>(
ui->name->text().toStdString(),
lc::MetaLineWidthByValue(ui->width->value()),
*lineWidthSelect->lineWidth(),
lc::Color(ui->r->value(),
ui->g->value(),
ui->b->value(),
@@ -67,7 +67,7 @@ void AddLayerDialog::accept() {
else {
layer = std::make_shared<const lc::Layer>(
ui->name->text().toStdString(),
lc::MetaLineWidthByValue(ui->width->value()),
*lineWidthSelect->lineWidth(),
lc::Color(ui->r->value(),
ui->g->value(),
ui->b->value(),
@@ -6,6 +6,7 @@
#include <QFormLayout>
#include "widgets/linepatternselect.h"
#include "widgets/linewidthselect.h"
#include <cad/meta/layer.h>
#include <cad/meta/metalinewidth.h>
@@ -36,5 +37,6 @@ class AddLayerDialog : public QDialog {
Ui::AddLayerDialog* ui;
lc::Document_SPtr _document;
LinePatternSelect* linePatternSelect;
LineWidthSelect* lineWidthSelect;
lc::Layer_CSPtr _oldLayer;
};
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>514</width>
<height>186</height>
<height>188</height>
</rect>
</property>
<property name="windowTitle">
@@ -115,25 +115,6 @@
</item>
</layout>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="width">
<property name="wrapping">
<bool>false</bool>
</property>
<property name="frame">
<bool>true</bool>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>100.000000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
@@ -77,7 +77,7 @@ void AddLinePatternDialog::generatePreview() {
QPixmap previewPixmap(ui->preview->frameSize());
LinePatternPainter painter(_linePattern, &previewPixmap);
LinePatternPainter painter(&previewPixmap, _linePattern);
painter.drawLinePattern();
ui->preview->setPixmap(previewPixmap);
View
@@ -154,6 +154,9 @@ void addQtWidgetsBindings(lua_State *L) {
.addFunction("setIconSize", &QAbstractButton::setIconSize)
.endClass()
.beginExtendClass<QComboBox, QWidget>("QComboBox")
.endClass()
.beginExtendClass<QPushButton, QAbstractButton>("QPushButton")
.addFactory([](QString name) {
return new QPushButton(name);
@@ -272,14 +275,21 @@ void addLCBindings(lua_State *L) {
.addFunction("setDocument", &LinePatternManager::setDocument)
.endClass()
.beginExtendClass<LinePatternSelect, QDialog>("LinePatternSelect")
.addFactory([](){
return new LinePatternSelect();
.beginExtendClass<LinePatternSelect, QComboBox>("LinePatternSelect")
.addFactory([](QWidget* parent){
return new LinePatternSelect(nullptr, parent);
})
.addFunction("setDocument", &LinePatternSelect::setDocument, LUA_ARGS(LuaIntf::_opt<lc::Document_SPtr>))
.addFunction("linePattern", &LinePatternSelect::linePattern)
.endClass()
.beginExtendClass<LineWidthSelect, QComboBox>("LineWidthSelect")
.addFactory([](QWidget* parent, bool showByLayer, bool showByBlock){
return new LineWidthSelect(parent, showByLayer, showByBlock);
})
.addFunction("lineWidth", &LineWidthSelect::lineWidth)
.endClass()
.endModule();
}
View
@@ -32,6 +32,7 @@ extern "C"
#include "widgets/layers.h"
#include "dialogs/linepatternmanager.h"
#include <drawables/tempentities.h>
#include "widgets/linewidthselect.h"
Q_DECLARE_METATYPE(lc::geo::Coordinate);
@@ -33,7 +33,7 @@ QVariant LinePatternModel::data(const QModelIndex &index, int role) const {
if(role == Qt::DecorationRole && index.column() == PREVIEW) {
QPixmap pixmap(PREVIEW_WIDTH, PREVIEW_HEIGHT);
auto painter = LinePatternPainter(linePattern, &pixmap);
auto painter = LinePatternPainter(&pixmap, linePattern);
painter.drawLinePattern();
@@ -1,21 +1,28 @@
#include "linepatternpainter.h"
LinePatternPainter::LinePatternPainter(lc::DxfLinePattern_CSPtr linePattern, QPaintDevice *device) :
LinePatternPainter::LinePatternPainter(QPaintDevice *device, lc::DxfLinePattern_CSPtr linePattern, int width) :
_device(device),
_linePattern(linePattern),
_device(device) {
_width(width) {
}
LinePatternPainter::LinePatternPainter(QPaintDevice *device, int width, lc::DxfLinePattern_CSPtr linePattern) :
_device(device),
_linePattern(linePattern),
_width(width) {
}
void LinePatternPainter::drawLinePattern() {
if(_linePattern == nullptr || _device == NULL) {
if(_device == NULL) {
return;
}
QPen pen;
if(_linePattern->length() != 0) {
if(_linePattern != nullptr && _linePattern->length() != 0) {
QVector<qreal> dashes;
for(auto a : _linePattern->lcPattern()) {
for(auto a : _linePattern->lcPattern(_width)) {
dashes << a;
}
@@ -28,7 +35,7 @@ void LinePatternPainter::drawLinePattern() {
}
pen.setColor(Qt::black);
pen.setWidth(1);
pen.setWidth(_width);
QPainter painter(_device);
painter.fillRect(QRect(0, 0, _device->width(), _device->height()), QBrush(Qt::white));
@@ -6,10 +6,12 @@
class LinePatternPainter {
public:
LinePatternPainter(lc::DxfLinePattern_CSPtr linePattern, QPaintDevice* device);
LinePatternPainter(QPaintDevice* device, lc::DxfLinePattern_CSPtr linePattern, int width = 1);
LinePatternPainter(QPaintDevice* device, int width, lc::DxfLinePattern_CSPtr linePattern = nullptr);
void drawLinePattern();
private:
lc::DxfLinePattern_CSPtr _linePattern;
QPaintDevice* _device;
lc::DxfLinePattern_CSPtr _linePattern;
int _width;
};
@@ -5,7 +5,7 @@ LinePatternSelect::LinePatternSelect(lc::Document_SPtr document, QWidget *parent
_showByLayer(showByLayer),
_showByBlock(showByBlock) {
qIconSize = QSize(256, 32);
qIconSize = QSize(128, 32);
setIconSize(qIconSize);
setDocument(document);
@@ -52,7 +52,7 @@ lc::DxfLinePattern_CSPtr LinePatternSelect::linePattern() {
QIcon LinePatternSelect::generateQIcon(lc::DxfLinePattern_CSPtr linePattern) {
QPixmap pixmap(qIconSize);
LinePatternPainter painter(linePattern, &pixmap);
LinePatternPainter painter(&pixmap, linePattern);
painter.drawLinePattern();
return QIcon(pixmap);
@@ -0,0 +1,66 @@
#include "linewidthselect.h"
LineWidthSelect::LineWidthSelect(QWidget* parent, bool showByLayer, bool showByBlock) :
QComboBox(parent) {
qIconSize = QSize(128, 32);
setIconSize(qIconSize);
if(showByLayer) {
addItem(BY_LAYER);
}
if(showByBlock) {
addItem(BY_BLOCK);
}
values["0.00mm"] = 0.00;
values["0.05mm"] = 0.05;
values["0.09mm"] = 0.09;
values["0.13mm (ISO)"] = 0.13;
values["0.15mm"] = 0.15;
values["0.18mm (ISO)"] = 0.18;
values["0.20mm"] = 0.20;
values["0.25mm (ISO)"] = 0.25;
values["0.30mm"] = 0.30;
values["0.35mm (ISO)"] = 0.35;
values["0.40mm"] = 0.40;
values["0.50mm (ISO)"] = 0.50;
values["0.53mm"] = 0.53;
values["0.60mm"] = 0.60;
values["0.70mm (ISO)"] = 0.70;
values["0.80mm"] = 0.80;
values["0.90mm"] = 0.90;
values["1.00mm (ISO)"] = 1.00;
values["1.06mm"] = 1.06;
values["1.20mm"] = 1.20;
values["1.40mm (ISO)"] = 1.40;
values["1.58mm"] = 1.58;
values["2.00mm (ISO)"] = 2.00;
values["2.11mm"] = 2.11;
createEntries();
}
void LineWidthSelect::createEntries() {
for(auto v : values) {
QPixmap pixmap(qIconSize);
LinePatternPainter painter(&pixmap, v.second);
painter.drawLinePattern();
addItem(QIcon(pixmap), v.first);
}
}
lc::MetaLineWidthByValue_CSPtr LineWidthSelect::lineWidth() {
if(currentText() == BY_BLOCK || currentText() == BY_LAYER) {
return nullptr;
}
try {
return std::make_shared<lc::MetaLineWidthByValue>(values.at(currentText()));
}
catch(std::out_of_range& e) {
return std::make_shared<lc::MetaLineWidthByValue>(0);
}
}
@@ -0,0 +1,23 @@
#pragma once
#include <QComboBox>
#include <QString>
#include <cad/meta/metalinewidth.h>
#include <widgets/linepatternpainter.h>
#define BY_BLOCK "ByBlock"
#define BY_LAYER "ByLayer"
class LineWidthSelect : public QComboBox {
public:
LineWidthSelect(QWidget* parent = 0, bool showByLayer = false, bool showByBlock = false);
lc::MetaLineWidthByValue_CSPtr lineWidth();
private:
void createEntries();
QSize qIconSize;
std::map<QString, double> values;
};
@@ -43,6 +43,11 @@ function active_metaInfo()
metaInfo:addDxfLinePattern(linePattern)
end
local lineWidth = lineWidthSelect:lineWidth()
if(lineWidth ~= nil) then
metaInfo:add(lineWidth)
end
return metaInfo
end
@@ -106,7 +111,8 @@ function create_main_window()
layers = lc.Layers(active_document())
mainWindow:addDockWidget(2, layers)
linePatternSelect = lc.LinePatternSelect()
linePatternSelect = lc.LinePatternSelect(mainWindow)
lineWidthSelect = lc.LineWidthSelect(mainWindow, true, true)
add_toolbar()
View
@@ -122,15 +122,11 @@ function add_toolbar()
luaInterface:luaConnect(removeButton, "pressed()", trim_entity)
--
-- Line Patterns
-- MetaInfo
--
local linePatternsGroup = quickAccess:addGroup("Entity properties")
local metaInfoGroup = quickAccess:addGroup("Entity properties")
quickAccess:addWidget(linePatternsGroup, linePatternSelect, 0, 0, 1, 1)
quickAccess:addWidget(metaInfoGroup, linePatternSelect, 0, 0, 1, 1)
quickAccess:addWidget(metaInfoGroup, lineWidthSelect, 0, 1, 1, 1)
local linePatternsButton = create_button("Line Patterns")
quickAccess:addButton(linePatternsGroup, linePatternsButton, 0, 1, 1, 1)
luaInterface:luaConnect(linePatternsButton, "pressed()", function()
lc.LinePatternManager(active_document())
end)
end

0 comments on commit 943242e

Please sign in to comment.