| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #include "rs_graphicview.h" |
| |
|
| | #include "lc_cursoroverlayinfo.h" |
| | #include "lc_eventhandler.h" |
| | #include "lc_graphicviewport.h" |
| | #include "lc_shortcuts_manager.h" |
| | #include "lc_widgetviewportrenderer.h" |
| | #include "rs_actioninterface.h" |
| | #include "rs_entitycontainer.h" |
| | #include "rs_graphic.h" |
| | #include "rs_grid.h" |
| | #include "rs_linetypepattern.h" |
| | #include "rs_selection.h" |
| | #include "rs_settings.h" |
| | #include "rs_snapper.h" |
| |
|
| | #ifdef EMU_C99 |
| | #include "emu_c99.h" |
| | #endif |
| |
|
| |
|
| | |
| | |
| | |
| | RS_GraphicView::RS_GraphicView(QWidget *parent, Qt::WindowFlags f) |
| | :QWidget(parent, f) |
| | , m_eventHandler{std::make_unique<LC_EventHandler>(this)} |
| | , m_viewport{std::make_unique<LC_GraphicViewport>()} |
| | , defaultSnapMode{std::make_unique<RS_SnapMode>()} |
| | , infoCursorOverlayPreferences{std::make_unique<LC_InfoCursorOverlayPrefs>()}{ |
| | m_viewport->addViewportListener(this); |
| | } |
| |
|
| | void RS_GraphicView::loadSettings() { |
| | LC_GROUP("Appearance"); |
| | { |
| | m_panOnZoom = LC_GET_BOOL("PanOnZoom", false); |
| | m_skipFirstZoom = LC_GET_BOOL("FirstTimeNoZoom", false); |
| |
|
| | } |
| | LC_GROUP_END(); |
| |
|
| | infoCursorOverlayPreferences->loadSettings(); |
| | m_viewport->loadSettings(); |
| | m_renderer->loadSettings(); |
| | } |
| |
|
| | RS_GraphicView::~RS_GraphicView() = default; |
| |
|
| | |
| | |
| | |
| | void RS_GraphicView::cleanUp() { |
| | m_bIsCleanUp = true; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | void RS_GraphicView::setContainer(RS_EntityContainer *c) { |
| | container = c; |
| | m_viewport->setContainer(c); |
| | |
| | } |
| |
|
| | |
| | |
| | |
| | RS_ActionInterface *RS_GraphicView::getDefaultAction() const { |
| | if (m_eventHandler!=nullptr) { |
| | return m_eventHandler->getDefaultAction(); |
| | } else { |
| | return nullptr; |
| | } |
| | } |
| |
|
| | void RS_GraphicView::hideOptions() const { |
| | if (m_eventHandler != nullptr) { |
| | auto defaultAction = m_eventHandler->getDefaultAction(); |
| | if (defaultAction != nullptr) { |
| | defaultAction->hideOptions(); |
| | } |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | void RS_GraphicView::setDefaultAction(RS_ActionInterface *action) const { |
| | if (m_eventHandler !=nullptr) { |
| | m_eventHandler->setDefaultAction(action); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | RS_ActionInterface *RS_GraphicView::getCurrentAction() const { |
| | return (nullptr != m_eventHandler) ? m_eventHandler->getCurrentAction() : nullptr; |
| | } |
| |
|
| | QString RS_GraphicView::getCurrentActionName() const { |
| | if (m_eventHandler !=nullptr) { |
| | QAction* qaction = m_eventHandler->getQAction(); |
| | if (qaction != nullptr){ |
| | |
| | return LC_ShortcutsManager::getPlainActionToolTip(qaction); |
| | } |
| | } |
| | return ""; |
| | } |
| |
|
| | QIcon RS_GraphicView::getCurrentActionIcon() const { |
| | if (m_eventHandler != nullptr) { |
| | QAction* qaction = m_eventHandler->getQAction(); |
| | if (qaction != nullptr){ |
| | return qaction->icon(); |
| | } |
| | } |
| | return {}; |
| | } |
| |
|
| | bool RS_GraphicView::setEventHandlerAction(std::shared_ptr<RS_ActionInterface> action){ |
| | bool actionActive = m_eventHandler->setCurrentAction(action); |
| | return actionActive; |
| | } |
| |
|
| | |
| | |
| | |
| | bool RS_GraphicView::setCurrentAction(std::shared_ptr<RS_ActionInterface> action) { |
| | if (m_eventHandler != nullptr) { |
| | m_viewport->markRelativeZero(); |
| | return setEventHandlerAction(action); |
| | } |
| |
|
| | return false; |
| | } |
| |
|
| | |
| | |
| | |
| | void RS_GraphicView::killAllActions() const { |
| | if (m_eventHandler != nullptr) { |
| | m_eventHandler->killAllActions(); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | void RS_GraphicView::back() const { |
| | if (m_eventHandler && m_eventHandler->hasAction()) { |
| | m_eventHandler->back(); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | void RS_GraphicView::processEnterKey() { |
| | if (m_eventHandler && m_eventHandler->hasAction()) { |
| | m_eventHandler->enter(); |
| | } |
| | } |
| |
|
| |
|
| | void RS_GraphicView::keyPressEvent(QKeyEvent *event) { |
| | if (m_eventHandler && m_eventHandler->hasAction()) { |
| | m_eventHandler->keyPressEvent(event); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | void RS_GraphicView::commandEvent(RS_CommandEvent *e) { |
| | if (m_eventHandler) { |
| | m_eventHandler->commandEvent(e); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | void RS_GraphicView::enableCoordinateInput() { |
| | if (m_eventHandler) { |
| | m_eventHandler->enableCoordinateInput(); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | void RS_GraphicView::disableCoordinateInput() { |
| | if (m_eventHandler) { |
| | m_eventHandler->disableCoordinateInput(); |
| | } |
| | } |
| |
|
| | void RS_GraphicView::zoomAuto(bool axis){ |
| | m_viewport->zoomAuto(axis); |
| | } |
| |
|
| |
|
| | void RS_GraphicView::onViewportChanged() { |
| | adjustOffsetControls(); |
| | adjustZoomControls(); |
| | QString info = m_viewport->getGrid()->getInfo(); |
| | updateGridStatusWidget(info); |
| | redraw(); |
| | } |
| |
|
| | void RS_GraphicView::onViewportRedrawNeeded() { |
| | redraw(RS2::RedrawDrawing); |
| | } |
| |
|
| | void RS_GraphicView::onUCSChanged(LC_UCS* ucs) { |
| | emit ucsChanged(ucs); |
| | QString info = m_viewport->getGrid()->getInfo(); |
| | updateGridStatusWidget(info); |
| | redraw(); |
| | } |
| |
|
| | void RS_GraphicView::notifyCurrentActionChanged(RS2::ActionType actionType) { |
| | emit currentActionChanged(actionType); |
| | } |
| |
|
| | bool RS_GraphicView::hasAction() { |
| | return getEventHandler()->hasAction(); |
| | } |
| |
|
| | void RS_GraphicView::notifyLastActionFinished() { |
| | return getEventHandler()->notifyLastActionFinished(); |
| | } |
| |
|
| | void RS_GraphicView::onRelativeZeroChanged(const RS_Vector &pos) { |
| | emit relativeZeroChanged(pos); |
| | redraw(RS2::RedrawOverlay); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | const RS_LineTypePattern *RS_GraphicView::getPattern(RS2::LineType t) { |
| | return RS_LineTypePattern::getPattern(t); |
| | } |
| |
|
| | RS2::SnapRestriction RS_GraphicView::getSnapRestriction() const { |
| | return defaultSnapRes; |
| | } |
| |
|
| | RS_SnapMode RS_GraphicView::getDefaultSnapMode() const { |
| | return *defaultSnapMode; |
| | } |
| |
|
| | |
| | |
| | |
| | void RS_GraphicView::setDefaultSnapMode(RS_SnapMode sm) { |
| | *defaultSnapMode = sm; |
| | if (m_eventHandler) { |
| | m_eventHandler->setSnapMode(sm); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | void RS_GraphicView::setSnapRestriction(RS2::SnapRestriction sr) { |
| | defaultSnapRes = sr; |
| |
|
| | if (m_eventHandler) { |
| | m_eventHandler->setSnapRestriction(sr); |
| | } |
| | } |
| |
|
| | LC_EventHandler *RS_GraphicView::getEventHandler() const { |
| | return m_eventHandler.get(); |
| | } |
| |
|
| | bool RS_GraphicView::isCurrentActionRunning(RS_ActionInterface* action) { |
| | return m_eventHandler->isValid(action); |
| | } |
| |
|
| | RS_Graphic *RS_GraphicView::getGraphic(bool resolve) const { |
| | if (container != nullptr){ |
| | if (resolve) { |
| | return container->getGraphic(); |
| | } |
| | if (container->rtti() == RS2::EntityGraphic) { |
| | return static_cast<RS_Graphic *>(container); |
| | } |
| | } |
| | return nullptr; |
| | } |
| |
|
| | RS_EntityContainer *RS_GraphicView::getContainer() const { |
| | return container; |
| | } |
| |
|
| | void RS_GraphicView::switchToDefaultAction() { |
| | killAllActions(); |
| | RS_Selection s(*container, m_viewport.get()); |
| | s.selectAll(false); |
| | redraw(RS2::RedrawAll); |
| | } |
| |
|
| | bool RS_GraphicView::isCleanUp(void) const { |
| | return m_bIsCleanUp; |
| | } |
| |
|
| | |
| | void RS_GraphicView::setRelativeZeroHiddenState(bool isHidden) { |
| | return m_viewport->setRelativeZeroHiddenState(isHidden); |
| | } |
| |
|
| | bool RS_GraphicView::isRelativeZeroHidden() { |
| | return m_viewport->isRelativeZeroHidden(); |
| | } |
| |
|
| | RS2::EntityType RS_GraphicView::getTypeToSelect() const { |
| | return typeToSelect; |
| | } |
| |
|
| | void RS_GraphicView::setTypeToSelect(RS2::EntityType mType) { |
| | typeToSelect = mType; |
| | } |
| |
|
| |
|
| | QString RS_GraphicView::obtainEntityDescription([[maybe_unused]]RS_Entity *entity, [[maybe_unused]]RS2::EntityDescriptionLevel descriptionLevel) { |
| | return ""; |
| | } |
| |
|
| | void RS_GraphicView::setShowEntityDescriptionOnHover(bool show) { |
| | showEntityDescriptionOnHover = show; |
| | } |
| |
|
| | bool RS_GraphicView::getPanOnZoom() const{ |
| | return m_panOnZoom; |
| | } |
| |
|
| | bool RS_GraphicView::getSkipFirstZoom() const{ |
| | return m_skipFirstZoom; |
| | } |
| |
|
| | LC_InfoCursorOverlayPrefs* RS_GraphicView::getInfoCursorOverlayPreferences(){ |
| | return infoCursorOverlayPreferences.get(); |
| | } |
| |
|
| | void RS_GraphicView::resizeEvent(QResizeEvent *event) { |
| | QWidget::resizeEvent(event); |
| | m_viewport->setSize(getWidth(), getHeight()); |
| | } |
| |
|
| | bool RS_GraphicView::isPrintPreview() const { |
| | return printPreview; |
| | } |
| |
|
| | void RS_GraphicView::setPrintPreview(bool pv) { |
| | printPreview = pv; |
| | } |
| |
|
| | void RS_GraphicView::setLineWidthScaling(bool state){ |
| | m_renderer->setLineWidthScaling(state); |
| | } |
| |
|
| | bool RS_GraphicView::getLineWidthScaling() const{ |
| | return m_renderer->getLineWidthScaling(); |
| | } |
| |
|
| | LC_WidgetViewPortRenderer* RS_GraphicView::getRenderer() const{ |
| | return m_renderer.get(); |
| | } |
| |
|
| | void RS_GraphicView::setRenderer(std::unique_ptr<LC_WidgetViewPortRenderer> renderer){ |
| | m_renderer = std::move(renderer); |
| | } |
| |
|