Permalink
Browse files

ByLayer preview

  • Loading branch information...
feragon committed Aug 11, 2016
1 parent af6c836 commit 1c15b2da6662b27e9ce4c89b702f9019e3eb29a4
View
@@ -280,8 +280,8 @@ void addLCBindings(lua_State *L) {
.endClass()
.beginExtendClass<LinePatternSelect, QComboBox>("LinePatternSelect")
.addFactory([](QWidget* parent){
return new LinePatternSelect(nullptr, parent);
.addFactory([](QWidget* parent, bool showByLayer, bool showByBlock){
return new LinePatternSelect(nullptr, parent, showByLayer, showByBlock);
})
.addFunction("setDocument", &LinePatternSelect::setDocument, LUA_ARGS(LuaIntf::_opt<lc::Document_SPtr>))
.addFunction("linePattern", &LinePatternSelect::linePattern)
View
@@ -79,7 +79,7 @@ bool LuaInterface::qtConnect(QObject *sender, std::string signalName, QObject *r
int slotId = receiver->metaObject()->indexOfSlot(slotName.c_str());
if(slotId < 0) {
std::cout << "No such slot " << signalName << std::endl;
std::cout << "No such slot " << slotName << std::endl;
}
return QMetaObject::connect(sender, signalId, receiver, slotId);
@@ -71,4 +71,15 @@ void ColorSelect::onActivated(const QString& text) {
void ColorSelect::on_customColorChanged(const QColor &color) {
_customColor = color;
}
void ColorSelect::onLayerChanged(lc::Layer_CSPtr layer) {
auto index = findText(BY_LAYER);
if(index != -1) {
QColor color(layer->color().redI(), layer->color().greenI(), layer->color().blueI(), layer->color().alphaI());
QPixmap pixmap(qIconSize);
pixmap.fill(color);
setItemIcon(index, QIcon(pixmap));
}
}
@@ -6,6 +6,7 @@
#include <QColorDialog>
#include <cad/meta/metacolor.h>
#include <cad/meta/layer.h>
#define BY_BLOCK "ByBlock"
#define BY_LAYER "ByLayer"
@@ -19,6 +20,9 @@ class ColorSelect : public QComboBox {
lc::MetaColor_CSPtr metaColor();
lc::Color color();
public slots:
void onLayerChanged(lc::Layer_CSPtr layer);
private slots:
void onActivated(const QString& text);
void on_customColorChanged(const QColor& color);
View
@@ -52,6 +52,7 @@ lc::Layer_CSPtr Layers::activeLayer() {
}
ui->layerList->selectRow(0);
emit layerChanged(model->layerAt(0));
return model->layerAt(0);
}
@@ -103,6 +104,9 @@ void Layers::on_layerList_clicked(const QModelIndex& index) {
replaceLayer(layer, newLayer);
}
else {
emit layerChanged(layer);
}
}
void Layers::changeLayerName(lc::Layer_CSPtr& layer, const std::string& name) {
View
@@ -25,6 +25,9 @@ class Layers : public QDockWidget {
void setDocument(lc::Document_SPtr document = nullptr);
lc::Layer_CSPtr activeLayer();
signals:
void layerChanged(lc::Layer_CSPtr layer);
private slots:
void on_newButton_clicked();
void on_deleteButton_clicked();
@@ -64,10 +64,18 @@ void LinePatternSelect::onActivated(const QString& text) {
if(text.toStdString() == NEW_LP) {
auto dialog = new AddLinePatternDialog(_document, this);
dialog->show();
if(_showByLayer) {
setCurrentText(BY_LAYER);
}
}
else if(text == MANAGE_LP) {
auto dialog = new LinePatternManager(_document, this);
dialog->show();
if(_showByLayer) {
setCurrentText(BY_LAYER);
}
}
}
@@ -81,6 +89,7 @@ void LinePatternSelect::createEntries() {
if(_showByLayer) {
addItem(BY_LAYER);
setCurrentText(BY_LAYER);
}
if(_showByBlock) {
addItem(BY_BLOCK);
@@ -98,14 +107,27 @@ void LinePatternSelect::createEntries() {
}
}
void LinePatternSelect::on_addLinePatternEvent(const lc::AddLinePatternEvent &) {
void LinePatternSelect::on_addLinePatternEvent(const lc::AddLinePatternEvent& event) {
createEntries();
setCurrentText(event.linePattern()->name().c_str());
}
void LinePatternSelect::on_removeLinePatternEvent(const lc::RemoveLinePatternEvent &) {
void LinePatternSelect::on_removeLinePatternEvent(const lc::RemoveLinePatternEvent& event) {
createEntries();
}
void LinePatternSelect::on_replaceLinePatternEvent(const lc::ReplaceLinePatternEvent &) {
void LinePatternSelect::on_replaceLinePatternEvent(const lc::ReplaceLinePatternEvent& event) {
createEntries();
setCurrentText(event.newLinePattern()->name().c_str());
}
void LinePatternSelect::onLayerChanged(lc::Layer_CSPtr layer) {
auto index = findText(BY_LAYER);
if(index != -1) {
auto icon = generateQIcon(layer->linePattern());
setItemIcon(index, icon);
}
}
@@ -22,6 +22,9 @@ class LinePatternSelect : public QComboBox {
lc::DxfLinePattern_CSPtr linePattern();
public slots:
void onLayerChanged(lc::Layer_CSPtr layer);
private slots:
void onActivated(const QString& text);
@@ -1,3 +1,4 @@
#include <cad/meta/layer.h>
#include "linewidthselect.h"
LineWidthSelect::LineWidthSelect(QWidget* parent, bool showByLayer, bool showByBlock) :
@@ -65,4 +66,17 @@ lc::MetaLineWidthByValue_CSPtr LineWidthSelect::lineWidth() {
catch(std::out_of_range& e) {
return std::make_shared<lc::MetaLineWidthByValue>(0);
}
}
void LineWidthSelect::onLayerChanged(lc::Layer_CSPtr layer) {
auto index = findText(BY_LAYER);
if(index != -1) {
QPixmap pixmap(qIconSize);
LinePatternPainter painter(&pixmap, layer->lineWidth().width());
painter.drawLinePattern();
setItemIcon(index, QIcon(pixmap));
}
}
@@ -10,10 +10,15 @@
#define BY_LAYER "ByLayer"
class LineWidthSelect : public QComboBox {
Q_OBJECT
public:
LineWidthSelect(QWidget* parent = 0, bool showByLayer = false, bool showByBlock = false);
lc::MetaLineWidthByValue_CSPtr lineWidth();
public slots:
void onLayerChanged(lc::Layer_CSPtr layer);
private:
void createEntries();
@@ -139,10 +139,14 @@ function create_main_window()
layers = lc.Layers(active_document())
mainWindow:addDockWidget(2, layers)
linePatternSelect = lc.LinePatternSelect(mainWindow)
linePatternSelect = lc.LinePatternSelect(mainWindow, true, true)
lineWidthSelect = lc.LineWidthSelect(mainWindow, true, true)
colorSelect = lc.ColorSelect(mainWindow, true, true)
luaInterface:connect(layers, "layerChanged(lc::Layer_CSPtr)", linePatternSelect, "onLayerChanged(lc::Layer_CSPtr)")
luaInterface:connect(layers, "layerChanged(lc::Layer_CSPtr)", lineWidthSelect, "onLayerChanged(lc::Layer_CSPtr)")
luaInterface:connect(layers, "layerChanged(lc::Layer_CSPtr)", colorSelect, "onLayerChanged(lc::Layer_CSPtr)")
add_toolbar()
if(hideUI ~= true) then

0 comments on commit 1c15b2d

Please sign in to comment.