5 #include "cad/dochelpers/storagemanagerimpl.h"
6 #include "cad/dochelpers/documentimpl.h"
9 #include <cad/operations/layerops.h>
11 #include <QtWidgets/QFileDialog>
12 #include <QtWidgets/QMessageBox>
19 _activeLayer(nullptr) {
21 if (this->objectName().isEmpty()) {
22 this->setObjectName(QStringLiteral(
"CadMdiChild"));
25 this->resize(1078, 736);
27 QGridLayout* gridLayout =
new QGridLayout(
this);
28 gridLayout->setHorizontalSpacing(0);
29 gridLayout->setVerticalSpacing(0);
30 gridLayout->setObjectName(QStringLiteral(
"gridLayout"));
31 gridLayout->setContentsMargins(0, 0, 0, 0);
45 _viewer->setObjectName(QStringLiteral(
"viewer"));
46 _viewer->setGeometry(QRect(50, 30, 581, 401));
47 _viewer->setAutoFillBackground(
true);
48 _viewer->setContextMenuPolicy(Qt::CustomContextMenu);
49 _viewer->setFocusPolicy(Qt::StrongFocus);
50 connect(
_viewer, SIGNAL(customContextMenuRequested(
const QPoint&)),
this, SLOT(
ctxMenu(
const QPoint&)));
52 gridLayout->addWidget(
_viewer, 0, 0, 1, 1);
62 _viewer, SLOT(setHorizontalOffset(
int)));
64 _viewer, SLOT(setVerticalOffset(
int)));
84 _gradientBackground = std::make_shared<GradientBackground>(lc::Color(0x07, 0x15, 0x11), lc::Color(0x06, 0x35, 0x06));
86 _grid = std::make_shared<Grid>(20, lc::Color(0x40, 0x48, 0x40), lc::Color(0x80, 0x90, 0x80));
96 _snapManager->snapPointEvents().connect<LCViewer::Cursor, &LCViewer::Cursor::onSnapPointEvent>(
_cursor.get());
99 _viewer->
documentCanvas()->foreground().connect<LCViewer::TempEntities, &LCViewer::TempEntities::onDraw>(_tempEntities.get());
105 _dragPoints = std::make_shared<LCViewer::DragPoints>();
106 _dragManager->dragPointsEvent().connect<LCViewer::DragPoints, &LCViewer::DragPoints::setPoints>(
_dragPoints.get());
110 _undoManager = std::make_shared<lc::UndoManagerImpl>(10);
111 _document->commitProcessEvent().connect<lc::UndoManagerImpl, &lc::UndoManagerImpl::on_CommitProcessEvent>(_undoManager.get());
118 auto file = QFileDialog::getOpenFileName();
124 auto fileInfo = QFileInfo(file);
126 auto ext = fileInfo.suffix().toStdString();
127 auto availableLibraries = lc::File::getAvailableLibrariesForFormat(ext);
129 if(availableLibraries.size() > 0) {
132 lc::File::open(
_document, file.toStdString(), availableLibraries.begin()->first);
135 QMessageBox::critical(
nullptr,
"Open error",
"Unknown file extension ." + fileInfo.suffix());
145 QString selectedFilter;
147 auto availableTypes = lc::File::getAvailableFileTypes();
149 if(availableTypes.size() == 0) {
150 QMessageBox::critical(
nullptr,
"Save error",
"No library available for file saving.");
154 auto it = availableTypes.begin();
156 filterList = it->second.c_str();
159 while(it != availableTypes.end()) {
161 filterList += it->second.c_str();
166 auto file = QFileDialog::getSaveFileName(
nullptr,
"Save file",
"", filterList, &selectedFilter);
168 auto selectedType = selectedFilter.toStdString();
170 for(
auto availableType : availableTypes) {
171 if(selectedType == availableType.second) {
172 type = availableType.first;
177 lc::File::save(
_document, file.toStdString(), type);
181 QMenu* menu =
new QMenu;
182 menu->addAction(tr(
"Test Item"),
this, SLOT(test_slot()));
183 menu->exec(
_viewer->mapToGlobal(pos));
217 QWidget::keyPressEvent(event);
std::shared_ptr< LCViewer::Grid > _grid
void setActiveLayer(const lc::Layer_CSPtr &activeLayer)
lc::ui::MetaInfoManager_SPtr metaInfoManager() const
Get the MetaInfo manager.
std::shared_ptr< LCViewer::GradientBackground > _gradientBackground
lc::StorageManager_SPtr storageManager() const
LCViewer::TempEntities_SPtr _tempEntities
std::shared_ptr< lc::Document > _document
void setDocument(std::shared_ptr< lc::Document > document)
std::shared_ptr< LCViewer::Cursor > cursor() const
const LCViewer::SnapManagerImpl_SPtr & getSnapManager() const
LCViewer::LCADViewer * viewer() const
void keyPressEvent(QKeyEvent *event)
LCViewer::SnapManager_SPtr snapManager() const
QScrollBar * verticalScrollBar
void setId(unsigned int id)
Set window ID.
QScrollBar * horizontalScrollBar
bool openFile()
Load existing file.
lc::ui::MetaInfoManager_SPtr _metaInfoManager
lc::UndoManager_SPtr undoManager() const
void setDragManager(DragManager_SPtr dragManager)
LCViewer::DragPoints_SPtr _dragPoints
LCViewer::TempEntities_SPtr tempEntities()
Get container of temporary entities.
LCViewer::SnapManagerImpl_SPtr _snapManager
lc::Layer_CSPtr _activeLayer
void keyPressed(QKeyEvent *event)
std::vector< lc::entity::CADEntity_CSPtr > selection()
Get selected entities.
unsigned int id()
Get window ID.
void setSnapManager(std::shared_ptr< SnapManager > snapmanager)
LCViewer::DragManager_SPtr _dragManager
LuaIntf::LuaRef _destroyCallback
std::shared_ptr< LCViewer::Cursor > _cursor
LCViewer::LCADViewer * _viewer
void newDocument()
Create a new document.
std::shared_ptr< DocumentCanvas > documentCanvas() const
void ctxMenu(const QPoint &pos)
std::shared_ptr< lc::Document > document() const
CadMdiChild(QWidget *parent=0)
void setDestroyCallback(LuaIntf::LuaRef callback)
Give function to call when window is destroyed.
lc::StorageManager_SPtr _storageManager
lc::Layer_CSPtr activeLayer() const
Get the selected layer.
lc::UndoManagerImpl_SPtr _undoManager