Permalink
Browse files

Add line pattern select in toolbar

  • Loading branch information...
feragon committed Jul 28, 2016
1 parent 0964d93 commit bf99b25a1580b8d4973fb8b817ca2cca8ac9fdd0
View
@@ -240,6 +240,12 @@ void addLCBindings(lua_State *L) {
LuaIntf::_opt<int>,
LuaIntf::_opt<int>,
LuaIntf::_opt<int>))
.addFunction("addWidget", &ToolbarTab::addWidget, LUA_ARGS(QGroupBox*,
QWidget*,
LuaIntf::_opt<int>,
LuaIntf::_opt<int>,
LuaIntf::_opt<int>,
LuaIntf::_opt<int>))
.addFunction("addGroup", &ToolbarTab::addGroup)
.addFunction("buttonByText", &ToolbarTab::buttonByText)
.addFunction("groupByName", &ToolbarTab::groupByName)
@@ -252,16 +258,26 @@ void addLCBindings(lua_State *L) {
.endClass()
.beginExtendClass<Layers, QDockWidget>("Layers")
.addFactory([](QMdiArea* mdiArea) {
return new Layers(mdiArea);
.addFactory([]() {
return new Layers();
})
.addFunction("activeLayer", &Layers::activeLayer)
.addFunction("setDocument", &Layers::setDocument, LUA_ARGS(LuaIntf::_opt<lc::Document_SPtr>))
.endClass()
.beginExtendClass<LinePatternManager, QDialog>("LinePatternManager")
.addFactory([](lc::Document_SPtr document){
return new LinePatternManager(document);
})
.addFunction("setDocument", &LinePatternManager::setDocument)
.endClass()
.beginExtendClass<LinePatternSelect, QDialog>("LinePatternSelect")
.addFactory([](){
return new LinePatternSelect();
})
.addFunction("setDocument", &LinePatternSelect::setDocument, LUA_ARGS(LuaIntf::_opt<lc::Document_SPtr>))
.addFunction("linePattern", &LinePatternSelect::linePattern)
.endClass()
.endModule();
View
@@ -2,28 +2,45 @@
#include "layers.h"
#include "ui_layers.h"
Layers::Layers(QMdiArea* mdiArea, QWidget *parent) :
Layers::Layers(lc::Document_SPtr document, QWidget *parent) :
QDockWidget(parent),
ui(new Ui::Layers) {
ui->setupUi(this);
setDocument(document);
model = new LayerModel(this);
ui->layerList->setModel(model);
ui->layerList->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
ui->layerList->horizontalHeader()->setSectionResizeMode(LayerModel::NAME, QHeaderView::Stretch);
onSubwindowActivated(mdiArea->activeSubWindow());
connect(mdiArea, &QMdiArea::subWindowActivated, this, &Layers::onSubwindowActivated);
connect(model, &LayerModel::nameChanged, this, &Layers::changeLayerName);
}
Layers::~Layers() {
delete ui;
}
void Layers::setDocument(lc::Document_SPtr document) {
if(_document != nullptr) {
_document->addLayerEvent().disconnect<Layers, &Layers::on_addLayerEvent>(this);
_document->removeLayerEvent().disconnect<Layers, &Layers::on_removeLayerEvent>(this);
_document->replaceLayerEvent().disconnect<Layers, &Layers::on_replaceLayerEvent>(this);
}
_document = document;
if(_document != nullptr) {
_document->addLayerEvent().connect<Layers, &Layers::on_addLayerEvent>(this);
_document->removeLayerEvent().connect<Layers, &Layers::on_removeLayerEvent>(this);
_document->replaceLayerEvent().connect<Layers, &Layers::on_replaceLayerEvent>(this);
}
updateLayerList();
}
lc::Layer_CSPtr Layers::activeLayer() {
QModelIndexList selection = ui->layerList->selectionModel()->selectedRows();
@@ -43,7 +60,7 @@ lc::Layer_CSPtr Layers::activeLayer() {
}
void Layers::on_newButton_clicked() {
auto dialog = new AddLayerDialog(document, this);
auto dialog = new AddLayerDialog(_document, this);
dialog->show();
connect(dialog, &AddLayerDialog::newLayer, this, &Layers::createLayer);
@@ -55,28 +72,6 @@ void Layers::on_deleteButton_clicked() {
deleteLayer(model->layerAt(selection.first().row()));
}
void Layers::onSubwindowActivated(QMdiSubWindow *window) {
if(document != nullptr) {
document->addLayerEvent().disconnect<Layers, &Layers::on_addLayerEvent>(this);
document->removeLayerEvent().disconnect<Layers, &Layers::on_removeLayerEvent>(this);
document->replaceLayerEvent().disconnect<Layers, &Layers::on_replaceLayerEvent>(this);
}
if(window != 0) {
auto cadMdiChild = static_cast<CadMdiChild*>(window->widget());
document = cadMdiChild->document();
document->addLayerEvent().connect<Layers, &Layers::on_addLayerEvent>(this);
document->removeLayerEvent().connect<Layers, &Layers::on_removeLayerEvent>(this);
document->replaceLayerEvent().connect<Layers, &Layers::on_replaceLayerEvent>(this);
updateLayerList();
}
else {
document = nullptr;
}
}
void Layers::on_layerList_clicked(const QModelIndex& index) {
if(!index.isValid()) {
return;
@@ -93,7 +88,7 @@ void Layers::on_layerList_clicked(const QModelIndex& index) {
break;
case LayerModel::EDIT:
auto dialog = new AddLayerDialog(layer, document, this);
auto dialog = new AddLayerDialog(layer, _document, this);
dialog->show();
connect(dialog, &AddLayerDialog::editLayer, this, &Layers::replaceLayer);
@@ -129,31 +124,32 @@ void Layers::changeLayerName(lc::Layer_CSPtr& layer, const std::string& name) {
}
void Layers::createLayer(lc::Layer_CSPtr layer) {
if(document != nullptr) {
auto operation = std::make_shared<lc::operation::AddLayer>(document, layer);
if(_document != nullptr) {
auto operation = std::make_shared<lc::operation::AddLayer>(_document, layer);
operation->execute();
}
}
void Layers::deleteLayer(lc::Layer_CSPtr layer) {
if(document != nullptr) {
auto operation = std::make_shared<lc::operation::RemoveLayer>(document, layer);
if(_document != nullptr) {
auto operation = std::make_shared<lc::operation::RemoveLayer>(_document, layer);
operation->execute();
}
}
void Layers::replaceLayer(lc::Layer_CSPtr oldLayer, lc::Layer_CSPtr newLayer) {
if(document != nullptr) {
auto operation = std::make_shared<lc::operation::ReplaceLayer>(document, oldLayer, newLayer);
if(_document != nullptr) {
auto operation = std::make_shared<lc::operation::ReplaceLayer>(_document, oldLayer, newLayer);
operation->execute();
}
}
void Layers::updateLayerList() {
if(document != nullptr) {
auto layersMap = document->allLayers();
if(_document != nullptr) {
std::vector<lc::Layer_CSPtr> layersVector;
auto layersMap = _document->allLayers();
for(auto layer : layersMap) {
layersVector.push_back(layer.second);
}
View
@@ -19,16 +19,16 @@ class Layers : public QDockWidget {
Q_OBJECT
public:
Layers(QMdiArea* mdiArea, QWidget* parent = 0);
Layers(lc::Document_SPtr document = nullptr, QWidget* parent = 0);
~Layers();
void setDocument(lc::Document_SPtr document = nullptr);
lc::Layer_CSPtr activeLayer();
private slots:
void on_newButton_clicked();
void on_deleteButton_clicked();
void on_layerList_clicked(const QModelIndex& index);
void onSubwindowActivated(QMdiSubWindow *window);
void createLayer(lc::Layer_CSPtr layer);
void deleteLayer(lc::Layer_CSPtr layer);
@@ -39,7 +39,7 @@ class Layers : public QDockWidget {
private:
Ui::Layers* ui;
LayerModel* model;
std::shared_ptr<lc::Document> document;
lc::Document_SPtr _document;
void updateLayerList();
@@ -9,7 +9,6 @@ LinePatternSelect::LinePatternSelect(lc::Document_SPtr document, QWidget *parent
setIconSize(qIconSize);
setDocument(document);
createEntries();
connect(this, SIGNAL(activated(const QString&)), this, SLOT(onActivated(const QString&)));
}
@@ -28,6 +27,8 @@ void LinePatternSelect::setDocument(lc::Document_SPtr document) {
_document->removeLinePatternEvent().connect<LinePatternSelect, &LinePatternSelect::on_removeLinePatternEvent>(this);
_document->replaceLinePatternEvent().connect<LinePatternSelect, &LinePatternSelect::on_replaceLinePatternEvent>(this);
}
createEntries();
}
lc::DxfLinePattern_CSPtr LinePatternSelect::linePattern() {
@@ -15,8 +15,8 @@ class LinePatternSelect : public QComboBox {
Q_OBJECT
public:
LinePatternSelect(lc::Document_SPtr document, QWidget *parent, bool showByLayer = false, bool showByBlock = false);
void setDocument(lc::Document_SPtr document);
LinePatternSelect(lc::Document_SPtr document = nullptr, QWidget *parent = 0, bool showByLayer = false, bool showByBlock = false);
void setDocument(lc::Document_SPtr document = nullptr);
lc::DxfLinePattern_CSPtr linePattern();
@@ -51,6 +51,21 @@ QPushButton* ToolbarTab::addButtonStr(QGroupBox* groupBox, const char* buttonNam
return button;
}
void ToolbarTab::addWidget(QGroupBox *groupBox, QWidget *widget, int x, int y, int w, int h) {
if(groupBox == nullptr) {
return;
}
auto gridLayout = dynamic_cast<QGridLayout*>(groupBox->layout());
if(gridLayout) {
gridLayout->addWidget(widget, y, x, h, w);
}
else {
groupBox->layout()->addWidget(widget);
}
}
QGroupBox* ToolbarTab::groupByName(const char* groupName) {
auto nbGroups = _layout->count();
@@ -19,6 +19,7 @@ class ToolbarTab : public QWidget {
QGroupBox* addGroup(const char* name);
void addButton(QGroupBox* groupBox, QPushButton* buttonName, int x = 0, int y = 0, int w = 1, int h = 1);
void addWidget(QGroupBox *groupBox, QWidget* widget, int x = 0, int y = 0, int w = 0, int h = 1);
QPushButton* addButtonStr(QGroupBox* groupBox, const char* buttonName, int x = 0, int y = 0, int w = 1, int h = 1);
@@ -59,7 +59,7 @@ function CircleOperations:getCircle(center, radius)
local d = active_widget():document()
local layer = active_layer()
local c = Circle(center, radius, layer)
local c = Circle(center, radius, layer, active_metaInfo())
c:setId(self.circle_id)
return c
@@ -74,11 +74,11 @@ function LineOperations:createLine(p1, p2)
local layer = active_layer()
local l
if(self.length == nil) then
l = Line(p1, p2, layer)
l = Line(p1, p2, layer, active_metaInfo())
else
local angle = p1:angleTo(p2)
local relativeCoordinate = Coordinate._fromAngle(angle):mulDouble(self.length)
l = Line(p1, p1:add(relativeCoordinate), layer)
l = Line(p1, p1:add(relativeCoordinate), layer, active_metaInfo())
end
l:setId(self.line_id)
View
@@ -1,14 +1,39 @@
function active_widget()
return mdiArea:activeSubWindow():widget()
local subWindow = mdiArea:activeSubWindow()
if(subWindow == nil) then
return nil
end
return subWindow:widget()
end
function active_document()
local widget = active_widget()
if(widget == nil) then
return nil
end
return active_widget():document()
end
local function click()
local position = active_widget():cursor():position()
local widget = active_widget()
if(widget == nil) then
return
end
local position = widget:cursor():position()
event.trigger('point', position)
end
local function mouseMove()
local position = active_widget():cursor():position()
local widget = active_widget()
if(widget == nil) then
return
end
local position = widget:cursor():position()
event.trigger('mouseMove', position)
end
View
@@ -35,11 +35,35 @@ function active_layer()
return layers:activeLayer()
end
function active_metaInfo()
local metaInfo = MetaInfo()
local linePattern = linePatternSelect:linePattern()
if(linePattern ~= nil) then
metaInfo:add(linePattern)
end
return metaInfo
end
local function open_lua_script()
local luaScript = lc.LuaScript(mdiArea, cliCommand)
luaScript:show()
end
local function onSubWindowChanged(window)
local document = active_document()
--setDocument called without parameters to use nullptr
if(document == nil) then
layers:setDocument()
linePatternSelect:setDocument()
else
layers:setDocument(document)
linePatternSelect:setDocument(document)
end
end
local function create_menu()
local menuBar = mainWindow:menuBar()
local drawMenu = menuBar:addMenuStr(qt.QString("Draw"))
@@ -68,6 +92,7 @@ function create_main_window()
mainWindow:setUnifiedTitleAndToolBarOnMac(true);
mdiArea = mainWindow:findChild("centralWidget"):findChild("mdiArea")
luaInterface:luaConnect(mdiArea, "subWindowActivated(QMdiSubWindow*)", onSubWindowChanged)
mdiArea:setHorizontalScrollBarPolicy(0)
mdiArea:setVerticalScrollBarPolicy(0)
@@ -78,9 +103,11 @@ function create_main_window()
add_commandline()
layers = lc.Layers(mdiArea)
layers = lc.Layers(active_document())
mainWindow:addDockWidget(2, layers)
linePatternSelect = lc.LinePatternSelect()
if(hideUI ~= true) then
add_toolbar()
Oops, something went wrong.

0 comments on commit bf99b25

Please sign in to comment.