leocad/common/lc_mainwindow.cpp

3479 lines
97 KiB
C++
Raw Normal View History

#include "lc_global.h"
2013-08-16 03:25:51 +02:00
#include "lc_mainwindow.h"
2015-02-01 03:33:42 +01:00
#include <QPrintDialog>
#include <QPrintPreviewDialog>
#include "lc_partselectionwidget.h"
2023-12-31 21:55:35 +01:00
#include "lc_propertieswidget.h"
#include "lc_timelinewidget.h"
2020-12-18 02:59:11 +01:00
#include "lc_viewwidget.h"
2023-04-30 04:48:30 +02:00
#include "lc_colorlist.h"
2015-01-26 00:04:39 +01:00
#include "lc_qutils.h"
2016-08-01 05:44:15 +02:00
#include "lc_qupdatedialog.h"
2023-04-30 04:55:54 +02:00
#include "lc_aboutdialog.h"
2017-08-20 22:47:53 +02:00
#include "lc_setsdatabasedialog.h"
2017-12-11 03:12:31 +01:00
#include "lc_qhtmldialog.h"
2017-09-22 19:08:02 +02:00
#include "lc_renderdialog.h"
2020-06-01 03:46:36 +02:00
#include "lc_instructionsdialog.h"
2013-08-09 06:57:18 +02:00
#include "lc_profile.h"
2020-12-25 19:43:22 +01:00
#include "lc_view.h"
#include "project.h"
2015-01-26 00:04:39 +01:00
#include "piece.h"
#include "camera.h"
2015-01-26 00:04:39 +01:00
#include "group.h"
#include "pieceinf.h"
#include "lc_library.h"
#include "lc_colors.h"
#include "lc_previewwidget.h"
2018-08-20 20:47:46 +02:00
#if LC_ENABLE_GAMEPAD
#include <QtGamepad/QGamepad>
#endif
2013-08-09 06:57:18 +02:00
lcMainWindow* gMainWindow;
#define LC_TAB_LAYOUT_VERSION 0x0001
2011-09-07 23:06:51 +02:00
void lcTabBar::mousePressEvent(QMouseEvent* Event)
{
2021-01-14 23:51:43 +01:00
if (Event->button() == Qt::MiddleButton)
mMousePressTab = tabAt(Event->pos());
else
QTabBar::mousePressEvent(Event);
}
void lcTabBar::mouseReleaseEvent(QMouseEvent* Event)
{
2021-01-14 23:51:43 +01:00
if (Event->button() == Qt::MiddleButton && tabAt(Event->pos()) == mMousePressTab)
tabCloseRequested(mMousePressTab);
else
QTabBar::mouseReleaseEvent(Event);
}
2013-08-09 06:57:18 +02:00
lcMainWindow::lcMainWindow()
2014-05-03 23:16:48 +02:00
{
2015-01-26 00:04:39 +01:00
memset(mActions, 0, sizeof(mActions));
2020-05-03 22:04:40 +02:00
mTransformType = lcTransformType::RelativeTranslation;
2011-09-07 23:06:51 +02:00
2020-07-25 22:21:22 +02:00
mColorIndex = lcGetColorIndex(7);
2020-12-05 00:38:49 +01:00
mTool = lcTool::Select;
2014-05-21 00:15:42 +02:00
mAddKeys = false;
2015-04-25 00:11:50 +02:00
mMoveSnapEnabled = true;
mAngleSnapEnabled = true;
2014-10-05 07:21:51 +02:00
mMoveXYSnapIndex = 4;
mMoveZSnapIndex = 3;
mAngleSnapIndex = 5;
mRelativeTransform = true;
mLocalTransform = false;
mCurrentPieceInfo = nullptr;
2020-05-03 22:04:40 +02:00
mSelectionMode = lcSelectionMode::Single;
2018-09-26 23:56:58 +02:00
mModelTabWidget = nullptr;
mPreviewToolBar = nullptr;
mPreviewWidget = nullptr;
2014-10-05 07:21:51 +02:00
2013-08-09 06:57:18 +02:00
for (int FileIdx = 0; FileIdx < LC_MAX_RECENT_FILES; FileIdx++)
2014-10-12 19:34:18 +02:00
mRecentFiles[FileIdx] = lcGetProfileString((LC_PROFILE_KEY)(LC_PROFILE_RECENT_FILE1 + FileIdx));
2011-09-07 23:06:51 +02:00
2018-05-14 02:37:02 +02:00
#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
connect(&mGamepadTimer, &QTimer::timeout, this, &lcMainWindow::UpdateGamepads);
mLastGamepadUpdate = QDateTime::currentDateTime();
mGamepadTimer.start(33);
#endif
2013-08-09 06:57:18 +02:00
gMainWindow = this;
2011-09-07 23:06:51 +02:00
}
2013-08-09 06:57:18 +02:00
lcMainWindow::~lcMainWindow()
2011-09-07 23:06:51 +02:00
{
if (mCurrentPieceInfo)
{
2017-01-23 04:28:05 +01:00
lcPiecesLibrary* Library = lcGetPiecesLibrary();
Library->ReleasePieceInfo(mCurrentPieceInfo);
mCurrentPieceInfo = nullptr;
}
2013-08-09 06:57:18 +02:00
for (int FileIdx = 0; FileIdx < LC_MAX_RECENT_FILES; FileIdx++)
lcSetProfileString((LC_PROFILE_KEY)(LC_PROFILE_RECENT_FILE1 + FileIdx), mRecentFiles[FileIdx]);
2011-09-07 23:06:51 +02:00
gMainWindow = nullptr;
2013-08-09 06:57:18 +02:00
}
2011-09-07 23:06:51 +02:00
2020-12-31 01:43:23 +01:00
void lcMainWindow::CreateWidgets()
2015-01-26 00:04:39 +01:00
{
setAcceptDrops(true);
2017-03-29 20:04:04 +02:00
setWindowIcon(QIcon(":/resources/leocad.png"));
2015-01-26 00:04:39 +01:00
setWindowFilePath(QString());
CreateActions();
CreateToolBars();
CreateMenus();
CreateStatusBar();
2021-01-08 19:35:52 +01:00
mModelTabWidget = new QTabWidget();
2018-01-07 17:59:05 +01:00
mModelTabWidget->tabBar()->setMovable(true);
2016-03-06 02:47:00 +01:00
mModelTabWidget->tabBar()->setTabsClosable(true);
mModelTabWidget->tabBar()->setContextMenuPolicy(Qt::CustomContextMenu);
2021-01-08 19:35:52 +01:00
setCentralWidget(mModelTabWidget);
connect(mModelTabWidget->tabBar(), SIGNAL(tabCloseRequested(int)), this, SLOT(ModelTabClosed(int)));
connect(mModelTabWidget->tabBar(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(ModelTabContextMenuRequested(const QPoint&)));
2016-03-06 02:47:00 +01:00
connect(mModelTabWidget, SIGNAL(currentChanged(int)), this, SLOT(ModelTabChanged(int)));
2015-01-26 00:04:39 +01:00
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(ClipboardChanged()));
ClipboardChanged();
QSettings Settings;
Settings.beginGroup("MainWindow");
resize(QSize(800, 600));
move(QPoint(200, 200));
restoreGeometry(Settings.value("Geometry").toByteArray());
restoreState(Settings.value("State").toByteArray());
2017-02-06 18:06:52 +01:00
mPartSelectionWidget->LoadState(Settings);
2015-01-26 00:04:39 +01:00
Settings.endGroup();
}
void lcMainWindow::CreateActions()
{
for (int CommandIdx = 0; CommandIdx < LC_NUM_COMMANDS; CommandIdx++)
{
QAction* Action = new QAction(qApp->translate("Menu", gCommands[CommandIdx].MenuName), this);
Action->setStatusTip(qApp->translate("Status", gCommands[CommandIdx].StatusText));
2015-01-26 00:04:39 +01:00
connect(Action, SIGNAL(triggered()), this, SLOT(ActionTriggered()));
addAction(Action);
mActions[CommandIdx] = Action;
}
mActions[LC_FILE_NEW]->setToolTip(tr("New Model"));
mActions[LC_FILE_OPEN]->setToolTip(tr("Open Model"));
mActions[LC_FILE_SAVE]->setToolTip(tr("Save Model"));
2015-01-26 00:04:39 +01:00
2015-10-03 20:57:59 +02:00
QIcon FileNewIcon;
FileNewIcon.addFile(":/resources/file_new.png");
FileNewIcon.addFile(":/resources/file_new_16.png");
mActions[LC_FILE_NEW]->setIcon(FileNewIcon);
QIcon FileSaveIcon;
FileSaveIcon.addFile(":/resources/file_save.png");
FileSaveIcon.addFile(":/resources/file_save_16.png");
mActions[LC_FILE_SAVE]->setIcon(FileSaveIcon);
QIcon FileOpenIcon;
FileOpenIcon.addFile(":/resources/file_open.png");
FileOpenIcon.addFile(":/resources/file_open_16.png");
mActions[LC_FILE_OPEN]->setIcon(FileOpenIcon);
QIcon FilePrintIcon;
FilePrintIcon.addFile(":/resources/file_print.png");
FilePrintIcon.addFile(":/resources/file_print_16.png");
mActions[LC_FILE_PRINT]->setIcon(FilePrintIcon);
QIcon FilePrintPreviewIcon;
FilePrintPreviewIcon.addFile(":/resources/file_print_preview.png");
FilePrintPreviewIcon.addFile(":/resources/file_print_preview_16.png");
mActions[LC_FILE_PRINT_PREVIEW]->setIcon(FilePrintPreviewIcon);
QIcon EditUndoIcon;
EditUndoIcon.addFile(":/resources/edit_undo.png");
EditUndoIcon.addFile(":/resources/edit_undo_16.png");
mActions[LC_EDIT_UNDO]->setIcon(EditUndoIcon);
QIcon EditRedoIcon;
EditRedoIcon.addFile(":/resources/edit_redo.png");
EditRedoIcon.addFile(":/resources/edit_redo_16.png");
mActions[LC_EDIT_REDO]->setIcon(EditRedoIcon);
QIcon EditCutIcon;
EditCutIcon.addFile(":/resources/edit_cut.png");
EditCutIcon.addFile(":/resources/edit_cut_16.png");
mActions[LC_EDIT_CUT]->setIcon(EditCutIcon);
QIcon EditCopyIcon;
EditCopyIcon.addFile(":/resources/edit_copy.png");
EditCopyIcon.addFile(":/resources/edit_copy_16.png");
mActions[LC_EDIT_COPY]->setIcon(EditCopyIcon);
QIcon EditPasteIcon;
EditPasteIcon.addFile(":/resources/edit_paste.png");
EditPasteIcon.addFile(":/resources/edit_paste_16.png");
mActions[LC_EDIT_PASTE]->setIcon(EditPasteIcon);
QIcon EditActionInsertIcon;
EditActionInsertIcon.addFile(":/resources/action_insert.png");
EditActionInsertIcon.addFile(":/resources/action_insert_16.png");
mActions[LC_EDIT_ACTION_INSERT]->setIcon(EditActionInsertIcon);
QIcon EditActionLightIcon;
EditActionLightIcon.addFile(":/resources/action_light.png");
EditActionLightIcon.addFile(":/resources/action_light_16.png");
2023-08-13 15:15:52 +02:00
mActions[LC_EDIT_ACTION_POINT_LIGHT]->setIcon(EditActionLightIcon);
2015-10-03 20:57:59 +02:00
2023-08-13 15:15:52 +02:00
QIcon EditActionSpotLightIcon;
EditActionSpotLightIcon.addFile(":/resources/action_spotlight.png");
EditActionSpotLightIcon.addFile(":/resources/action_spotlight_16.png");
mActions[LC_EDIT_ACTION_SPOTLIGHT]->setIcon(EditActionSpotLightIcon);
2023-07-05 03:13:47 +02:00
QIcon EditActionSunlightIcon;
EditActionSunlightIcon.addFile(":/resources/action_sunlight.png");
EditActionSunlightIcon.addFile(":/resources/action_sunlight_16.png");
2023-08-13 15:15:52 +02:00
mActions[LC_EDIT_ACTION_DIRECTIONAL_LIGHT]->setIcon(EditActionSunlightIcon);
2023-07-05 03:13:47 +02:00
2023-08-13 15:15:52 +02:00
QIcon EditActionArealightIcon;
EditActionArealightIcon.addFile(":/resources/action_arealight.png");
EditActionArealightIcon.addFile(":/resources/action_arealight_16.png");
mActions[LC_EDIT_ACTION_AREA_LIGHT]->setIcon(EditActionArealightIcon);
2015-10-03 20:57:59 +02:00
QIcon EditActionSelectIcon;
EditActionSelectIcon.addFile(":/resources/action_select.png");
EditActionSelectIcon.addFile(":/resources/action_select_16.png");
mActions[LC_EDIT_ACTION_SELECT]->setIcon(EditActionSelectIcon);
QIcon EditActionMoveIcon;
EditActionMoveIcon.addFile(":/resources/action_move.png");
EditActionMoveIcon.addFile(":/resources/action_move_16.png");
mActions[LC_EDIT_ACTION_MOVE]->setIcon(EditActionMoveIcon);
QIcon EditActionRotateIcon;
EditActionRotateIcon.addFile(":/resources/action_rotate.png");
EditActionRotateIcon.addFile(":/resources/action_rotate_16.png");
mActions[LC_EDIT_ACTION_ROTATE]->setIcon(EditActionRotateIcon);
QIcon EditActionDeleteIcon;
EditActionDeleteIcon.addFile(":/resources/action_delete.png");
EditActionDeleteIcon.addFile(":/resources/action_delete_16.png");
mActions[LC_EDIT_ACTION_DELETE]->setIcon(EditActionDeleteIcon);
QIcon EditActionPaintIcon;
EditActionPaintIcon.addFile(":/resources/action_paint.png");
EditActionPaintIcon.addFile(":/resources/action_paint_16.png");
mActions[LC_EDIT_ACTION_PAINT]->setIcon(EditActionPaintIcon);
QIcon EditActionColorPickerIcon;
EditActionColorPickerIcon.addFile(":/resources/action_color_picker.png");
EditActionColorPickerIcon.addFile(":/resources/action_color_picker_16.png");
mActions[LC_EDIT_ACTION_COLOR_PICKER]->setIcon(EditActionColorPickerIcon);
2015-10-03 20:57:59 +02:00
QIcon EditActionZoomIcon;
EditActionZoomIcon.addFile(":/resources/action_zoom.png");
EditActionZoomIcon.addFile(":/resources/action_zoom_16.png");
mActions[LC_EDIT_ACTION_ZOOM]->setIcon(EditActionZoomIcon);
QIcon EditActionPanIcon;
EditActionPanIcon.addFile(":/resources/action_pan.png");
EditActionPanIcon.addFile(":/resources/action_pan_16.png");
mActions[LC_EDIT_ACTION_PAN]->setIcon(EditActionPanIcon);
2023-05-21 11:17:00 +02:00
QIcon FileRenderPOVRayIcon;
FileRenderPOVRayIcon.addFile(":/resources/file_render_povray.png");
FileRenderPOVRayIcon.addFile(":/resources/file_render_povray_16.png");
mActions[LC_FILE_RENDER_POVRAY]->setIcon(FileRenderPOVRayIcon);
QIcon FileRenderBlenderIcon;
FileRenderBlenderIcon.addFile(":/resources/file_render_blender.png");
FileRenderBlenderIcon.addFile(":/resources/file_render_blender_16.png");
mActions[LC_FILE_RENDER_BLENDER]->setIcon(FileRenderBlenderIcon);
QIcon FileOpenInBlenderIcon;
FileOpenInBlenderIcon.addFile(":/resources/file_render_open_in_blender.png");
FileOpenInBlenderIcon.addFile(":/resources/file_render_open_in_blender_16.png");
mActions[LC_FILE_RENDER_OPEN_IN_BLENDER]->setIcon(FileOpenInBlenderIcon);
2015-01-26 00:04:39 +01:00
mActions[LC_EDIT_ACTION_CAMERA]->setIcon(QIcon(":/resources/action_camera.png"));
mActions[LC_EDIT_ACTION_ROTATE_VIEW]->setIcon(QIcon(":/resources/action_rotate_view.png"));
mActions[LC_EDIT_ACTION_ROLL]->setIcon(QIcon(":/resources/action_roll.png"));
mActions[LC_EDIT_ACTION_ZOOM_REGION]->setIcon(QIcon(":/resources/action_zoom_region.png"));
mActions[LC_EDIT_FIND]->setIcon(QIcon(":/resources/edit_find.png"));
2021-01-31 03:03:35 +01:00
mActions[LC_EDIT_FIND_NEXT]->setIcon(QIcon(":/resources/edit_find_next.png"));
mActions[LC_EDIT_FIND_PREVIOUS]->setIcon(QIcon(":/resources/edit_find_previous.png"));
2021-01-31 20:02:50 +01:00
mActions[LC_EDIT_FIND_ALL]->setIcon(QIcon(":/resources/edit_find_all.png"));
2021-02-04 04:23:38 +01:00
mActions[LC_EDIT_REPLACE_NEXT]->setIcon(QIcon(":/resources/edit_replace_next.png"));
mActions[LC_EDIT_REPLACE_ALL]->setIcon(QIcon(":/resources/edit_replace_all.png"));
2015-01-26 00:04:39 +01:00
mActions[LC_PIECE_SHOW_EARLIER]->setIcon(QIcon(":/resources/piece_show_earlier.png"));
mActions[LC_PIECE_SHOW_LATER]->setIcon(QIcon(":/resources/piece_show_later.png"));
mActions[LC_VIEW_SPLIT_HORIZONTAL]->setIcon(QIcon(":/resources/view_split_horizontal.png"));
mActions[LC_VIEW_SPLIT_VERTICAL]->setIcon(QIcon(":/resources/view_split_vertical.png"));
mActions[LC_VIEW_ZOOM_IN]->setIcon(QIcon(":/resources/view_zoomin.png"));
mActions[LC_VIEW_ZOOM_OUT]->setIcon(QIcon(":/resources/view_zoomout.png"));
mActions[LC_VIEW_ZOOM_EXTENTS]->setIcon(QIcon(":/resources/view_zoomextents.png"));
mActions[LC_VIEW_TIME_FIRST]->setIcon(QIcon(":/resources/time_first.png"));
mActions[LC_VIEW_TIME_PREVIOUS]->setIcon(QIcon(":/resources/time_previous.png"));
mActions[LC_VIEW_TIME_NEXT]->setIcon(QIcon(":/resources/time_next.png"));
mActions[LC_VIEW_TIME_LAST]->setIcon(QIcon(":/resources/time_last.png"));
mActions[LC_VIEW_TIME_ADD_KEYS]->setIcon(QIcon(":/resources/time_add_keys.png"));
mActions[LC_HELP_HOMEPAGE]->setIcon(QIcon(":/resources/help_homepage.png"));
2015-04-25 00:11:50 +02:00
mActions[LC_EDIT_SNAP_MOVE_TOGGLE]->setCheckable(true);
mActions[LC_EDIT_SNAP_ANGLE_TOGGLE]->setCheckable(true);
2015-01-26 00:04:39 +01:00
mActions[LC_VIEW_CAMERA_NONE]->setCheckable(true);
mActions[LC_VIEW_TIME_ADD_KEYS]->setCheckable(true);
for (int ActionIndex = LC_VIEW_TOOLBAR_FIRST; ActionIndex <= LC_VIEW_TOOLBAR_LAST; ActionIndex++)
mActions[ActionIndex]->setCheckable(true);
QActionGroup* ActionRelativeGroup = new QActionGroup(this);
for (int ActionIdx = LC_EDIT_TRANSFORM_RELATIVE; ActionIdx <= LC_EDIT_TRANSFORM_ABSOLUTE; ActionIdx++)
{
mActions[ActionIdx]->setCheckable(true);
ActionRelativeGroup->addAction(mActions[ActionIdx]);
}
QActionGroup* ActionSeparateGroup = new QActionGroup(this);
for (int ActionIdx = LC_EDIT_TRANSFORM_SEPARATELY; ActionIdx <= LC_EDIT_TRANSFORM_TOGETHER; ActionIdx++)
{
mActions[ActionIdx]->setCheckable(true);
ActionSeparateGroup->addAction(mActions[ActionIdx]);
}
2015-01-26 00:04:39 +01:00
QActionGroup* ActionSnapXYGroup = new QActionGroup(this);
for (int ActionIdx = LC_EDIT_SNAP_MOVE_XY0; ActionIdx <= LC_EDIT_SNAP_MOVE_XY9; ActionIdx++)
{
mActions[ActionIdx]->setCheckable(true);
ActionSnapXYGroup->addAction(mActions[ActionIdx]);
}
QActionGroup* ActionSnapZGroup = new QActionGroup(this);
for (int ActionIdx = LC_EDIT_SNAP_MOVE_Z0; ActionIdx <= LC_EDIT_SNAP_MOVE_Z9; ActionIdx++)
{
mActions[ActionIdx]->setCheckable(true);
ActionSnapZGroup->addAction(mActions[ActionIdx]);
}
QActionGroup* ActionSnapAngleGroup = new QActionGroup(this);
for (int ActionIdx = LC_EDIT_SNAP_ANGLE0; ActionIdx <= LC_EDIT_SNAP_ANGLE9; ActionIdx++)
{
mActions[ActionIdx]->setCheckable(true);
ActionSnapAngleGroup->addAction(mActions[ActionIdx]);
}
QActionGroup* ActionTransformTypeGroup = new QActionGroup(this);
for (int ActionIdx = LC_EDIT_TRANSFORM_ABSOLUTE_TRANSLATION; ActionIdx <= LC_EDIT_TRANSFORM_RELATIVE_ROTATION; ActionIdx++)
{
mActions[ActionIdx]->setCheckable(true);
ActionTransformTypeGroup->addAction(mActions[ActionIdx]);
}
QActionGroup* ActionToolGroup = new QActionGroup(this);
for (int ActionIdx = LC_EDIT_ACTION_FIRST; ActionIdx <= LC_EDIT_ACTION_LAST; ActionIdx++)
{
mActions[ActionIdx]->setCheckable(true);
ActionToolGroup->addAction(mActions[ActionIdx]);
}
QActionGroup* ActionCameraGroup = new QActionGroup(this);
ActionCameraGroup->addAction(mActions[LC_VIEW_CAMERA_NONE]);
for (int ActionIdx = LC_VIEW_CAMERA_FIRST; ActionIdx <= LC_VIEW_CAMERA_LAST; ActionIdx++)
{
mActions[ActionIdx]->setCheckable(true);
ActionCameraGroup->addAction(mActions[ActionIdx]);
}
QActionGroup* ActionPerspectiveGroup = new QActionGroup(this);
for (int ActionIdx = LC_VIEW_PROJECTION_FIRST; ActionIdx <= LC_VIEW_PROJECTION_LAST; ActionIdx++)
{
mActions[ActionIdx]->setCheckable(true);
ActionPerspectiveGroup->addAction(mActions[ActionIdx]);
}
2017-08-25 21:57:14 +02:00
QActionGroup* ActionShadingGroup = new QActionGroup(this);
for (int ActionIdx = LC_VIEW_SHADING_FIRST; ActionIdx <= LC_VIEW_SHADING_LAST; ActionIdx++)
{
mActions[ActionIdx]->setCheckable(true);
ActionShadingGroup->addAction(mActions[ActionIdx]);
}
2017-11-22 02:58:36 +01:00
QActionGroup* SelectionModeGroup = new QActionGroup(this);
for (int ActionIdx = LC_EDIT_SELECTION_MODE_FIRST; ActionIdx <= LC_EDIT_SELECTION_MODE_LAST; ActionIdx++)
{
mActions[ActionIdx]->setCheckable(true);
SelectionModeGroup->addAction(mActions[ActionIdx]);
}
2015-01-26 00:04:39 +01:00
QActionGroup* ModelGroup = new QActionGroup(this);
for (int ActionIdx = LC_MODEL_FIRST; ActionIdx <= LC_MODEL_LAST; ActionIdx++)
{
mActions[ActionIdx]->setCheckable(true);
ModelGroup->addAction(mActions[ActionIdx]);
}
UpdateShortcuts();
}
void lcMainWindow::CreateMenus()
{
QMenu* TransformMenu = new QMenu(tr("Transform"), this);
TransformMenu->addAction(mActions[LC_EDIT_TRANSFORM_RELATIVE_TRANSLATION]);
TransformMenu->addAction(mActions[LC_EDIT_TRANSFORM_ABSOLUTE_TRANSLATION]);
TransformMenu->addAction(mActions[LC_EDIT_TRANSFORM_RELATIVE_ROTATION]);
TransformMenu->addAction(mActions[LC_EDIT_TRANSFORM_ABSOLUTE_ROTATION]);
mActions[LC_EDIT_TRANSFORM]->setMenu(TransformMenu);
2015-12-04 21:32:10 +01:00
mCameraMenu = new QMenu(tr("C&ameras"), this);
mCameraMenu->addAction(mActions[LC_VIEW_CAMERA_NONE]);
2015-01-26 00:04:39 +01:00
for (int actionIdx = LC_VIEW_CAMERA_FIRST; actionIdx <= LC_VIEW_CAMERA_LAST; actionIdx++)
2015-12-04 21:32:10 +01:00
mCameraMenu->addAction(mActions[actionIdx]);
2015-01-26 00:04:39 +01:00
2024-02-20 02:51:34 +01:00
connect(mCameraMenu, &QMenu::aboutToShow, this, &lcMainWindow::CameraMenuAboutToShow);
2015-12-04 21:32:10 +01:00
mViewpointMenu = new QMenu(tr("&Viewpoints"), this);
mViewpointMenu->addAction(mActions[LC_VIEW_VIEWPOINT_FRONT]);
mViewpointMenu->addAction(mActions[LC_VIEW_VIEWPOINT_BACK]);
mViewpointMenu->addAction(mActions[LC_VIEW_VIEWPOINT_LEFT]);
mViewpointMenu->addAction(mActions[LC_VIEW_VIEWPOINT_RIGHT]);
mViewpointMenu->addAction(mActions[LC_VIEW_VIEWPOINT_TOP]);
mViewpointMenu->addAction(mActions[LC_VIEW_VIEWPOINT_BOTTOM]);
mViewpointMenu->addAction(mActions[LC_VIEW_VIEWPOINT_HOME]);
2015-01-26 00:04:39 +01:00
mProjectionMenu = new QMenu(tr("Projection"), this);
mProjectionMenu->addAction(mActions[LC_VIEW_PROJECTION_PERSPECTIVE]);
mProjectionMenu->addAction(mActions[LC_VIEW_PROJECTION_ORTHO]);
2024-02-20 02:51:34 +01:00
connect(mProjectionMenu, &QMenu::aboutToShow, this, &lcMainWindow::ProjectionMenuAboutToShow);
mShadingMenu = new QMenu(tr("Sh&ading"), this);
mShadingMenu->addAction(mActions[LC_VIEW_SHADING_WIREFRAME]);
mShadingMenu->addAction(mActions[LC_VIEW_SHADING_FLAT]);
mShadingMenu->addAction(mActions[LC_VIEW_SHADING_DEFAULT_LIGHTS]);
2017-11-14 23:56:37 +01:00
mToolsMenu = new QMenu(tr("Tools"), this);
mToolsMenu->addAction(mActions[LC_EDIT_ACTION_INSERT]);
2023-08-13 15:15:52 +02:00
mToolsMenu->addAction(mActions[LC_EDIT_ACTION_POINT_LIGHT]);
2017-11-14 23:56:37 +01:00
mToolsMenu->addAction(mActions[LC_EDIT_ACTION_SPOTLIGHT]);
2023-08-13 15:15:52 +02:00
mToolsMenu->addAction(mActions[LC_EDIT_ACTION_DIRECTIONAL_LIGHT]);
mToolsMenu->addAction(mActions[LC_EDIT_ACTION_AREA_LIGHT]);
2017-11-14 23:56:37 +01:00
mToolsMenu->addAction(mActions[LC_EDIT_ACTION_CAMERA]);
mToolsMenu->addSeparator();
mToolsMenu->addAction(mActions[LC_EDIT_ACTION_SELECT]);
mToolsMenu->addAction(mActions[LC_EDIT_ACTION_MOVE]);
mToolsMenu->addAction(mActions[LC_EDIT_ACTION_ROTATE]);
mToolsMenu->addAction(mActions[LC_EDIT_ACTION_DELETE]);
mToolsMenu->addAction(mActions[LC_EDIT_ACTION_PAINT]);
mToolsMenu->addAction(mActions[LC_EDIT_ACTION_COLOR_PICKER]);
2017-11-14 23:56:37 +01:00
mToolsMenu->addSeparator();
mToolsMenu->addAction(mActions[LC_EDIT_ACTION_ZOOM]);
mToolsMenu->addAction(mActions[LC_EDIT_ACTION_PAN]);
mToolsMenu->addAction(mActions[LC_EDIT_ACTION_ROTATE_VIEW]);
mToolsMenu->addAction(mActions[LC_EDIT_ACTION_ROLL]);
mToolsMenu->addAction(mActions[LC_EDIT_ACTION_ZOOM_REGION]);
2015-01-26 00:04:39 +01:00
QMenu* FileMenu = menuBar()->addMenu(tr("&File"));
FileMenu->addAction(mActions[LC_FILE_NEW]);
FileMenu->addAction(mActions[LC_FILE_OPEN]);
FileMenu->addAction(mActions[LC_FILE_MERGE]);
FileMenu->addSeparator();
FileMenu->addAction(mActions[LC_FILE_SAVE]);
FileMenu->addAction(mActions[LC_FILE_SAVEAS]);
FileMenu->addAction(mActions[LC_FILE_SAVE_IMAGE]);
2017-06-26 03:20:34 +02:00
QMenu* ImportMenu = FileMenu->addMenu(tr("&Import"));
ImportMenu->addAction(mActions[LC_FILE_IMPORT_LDD]);
2017-08-20 22:47:53 +02:00
ImportMenu->addAction(mActions[LC_FILE_IMPORT_INVENTORY]);
2015-01-26 00:04:39 +01:00
QMenu* ExportMenu = FileMenu->addMenu(tr("&Export"));
ExportMenu->addAction(mActions[LC_FILE_EXPORT_3DS]);
ExportMenu->addAction(mActions[LC_FILE_EXPORT_BRICKLINK]);
2017-08-11 03:40:43 +02:00
ExportMenu->addAction(mActions[LC_FILE_EXPORT_COLLADA]);
2015-01-26 00:04:39 +01:00
ExportMenu->addAction(mActions[LC_FILE_EXPORT_CSV]);
ExportMenu->addAction(mActions[LC_FILE_EXPORT_HTML]);
ExportMenu->addAction(mActions[LC_FILE_EXPORT_POVRAY]);
ExportMenu->addAction(mActions[LC_FILE_EXPORT_WAVEFRONT]);
FileMenu->addSeparator();
2023-05-21 11:17:00 +02:00
QMenu* RenderMenu = FileMenu->addMenu(tr("&Render"));
RenderMenu->addAction(mActions[LC_FILE_RENDER_POVRAY]);
RenderMenu->addAction(mActions[LC_FILE_RENDER_BLENDER]);
RenderMenu->addAction(mActions[LC_FILE_RENDER_OPEN_IN_BLENDER]);
2021-01-14 23:51:43 +01:00
FileMenu->addAction(mActions[LC_FILE_INSTRUCTIONS]);
2015-01-26 00:04:39 +01:00
FileMenu->addAction(mActions[LC_FILE_PRINT]);
FileMenu->addAction(mActions[LC_FILE_PRINT_PREVIEW]);
FileMenu->addSeparator();
FileMenu->addAction(mActions[LC_FILE_RECENT1]);
FileMenu->addAction(mActions[LC_FILE_RECENT2]);
FileMenu->addAction(mActions[LC_FILE_RECENT3]);
FileMenu->addAction(mActions[LC_FILE_RECENT4]);
mActionFileRecentSeparator = FileMenu->addSeparator();
FileMenu->addAction(mActions[LC_FILE_EXIT]);
QMenu* EditMenu = menuBar()->addMenu(tr("&Edit"));
EditMenu->addAction(mActions[LC_EDIT_UNDO]);
EditMenu->addAction(mActions[LC_EDIT_REDO]);
EditMenu->addSeparator();
EditMenu->addAction(mActions[LC_EDIT_CUT]);
EditMenu->addAction(mActions[LC_EDIT_COPY]);
EditMenu->addAction(mActions[LC_EDIT_PASTE]);
EditMenu->addAction(mActions[LC_EDIT_PASTE_STEPS]);
2015-01-26 00:04:39 +01:00
EditMenu->addSeparator();
EditMenu->addAction(mActions[LC_EDIT_FIND]);
EditMenu->addAction(mActions[LC_EDIT_FIND_NEXT]);
EditMenu->addAction(mActions[LC_EDIT_FIND_PREVIOUS]);
2021-01-31 00:37:17 +01:00
EditMenu->addAction(mActions[LC_EDIT_REPLACE]);
EditMenu->addAction(mActions[LC_EDIT_REPLACE_NEXT]);
2015-01-26 00:04:39 +01:00
EditMenu->addSeparator();
EditMenu->addAction(mActions[LC_EDIT_SELECT_ALL]);
EditMenu->addAction(mActions[LC_EDIT_SELECT_NONE]);
EditMenu->addAction(mActions[LC_EDIT_SELECT_INVERT]);
EditMenu->addAction(mActions[LC_EDIT_SELECT_BY_NAME]);
EditMenu->addMenu(mSelectionModeMenu);
2017-11-14 23:56:37 +01:00
EditMenu->addSeparator();
EditMenu->addMenu(mTransformMenu);
2017-11-14 23:56:37 +01:00
EditMenu->addMenu(mToolsMenu);
2015-01-26 00:04:39 +01:00
QMenu* ViewMenu = menuBar()->addMenu(tr("&View"));
ViewMenu->addAction(mActions[LC_VIEW_PREFERENCES]);
ViewMenu->addSeparator();
ViewMenu->addAction(mActions[LC_VIEW_ZOOM_EXTENTS]);
ViewMenu->addAction(mActions[LC_VIEW_LOOK_AT]);
2015-12-04 21:32:10 +01:00
ViewMenu->addMenu(mViewpointMenu);
ViewMenu->addMenu(mCameraMenu);
ViewMenu->addMenu(mProjectionMenu);
ViewMenu->addMenu(mShadingMenu);
2015-01-26 00:04:39 +01:00
QMenu* StepMenu = ViewMenu->addMenu(tr("Ste&p"));
StepMenu->addAction(mActions[LC_VIEW_TIME_FIRST]);
StepMenu->addAction(mActions[LC_VIEW_TIME_PREVIOUS]);
StepMenu->addAction(mActions[LC_VIEW_TIME_NEXT]);
StepMenu->addAction(mActions[LC_VIEW_TIME_LAST]);
StepMenu->addSeparator();
StepMenu->addAction(mActions[LC_VIEW_TIME_INSERT_BEFORE]);
StepMenu->addAction(mActions[LC_VIEW_TIME_INSERT_AFTER]);
2015-01-26 00:04:39 +01:00
StepMenu->addAction(mActions[LC_VIEW_TIME_DELETE]);
ViewMenu->addSeparator();
ViewMenu->addAction(mActions[LC_VIEW_SPLIT_HORIZONTAL]);
ViewMenu->addAction(mActions[LC_VIEW_SPLIT_VERTICAL]);
ViewMenu->addAction(mActions[LC_VIEW_REMOVE_VIEW]);
ViewMenu->addAction(mActions[LC_VIEW_RESET_VIEWS]);
ViewMenu->addSeparator();
QMenu* ToolBarsMenu = ViewMenu->addMenu(tr("T&oolbars"));
connect(ToolBarsMenu, SIGNAL(aboutToShow()), this, SLOT(UpdateDockWidgetActions()));
ToolBarsMenu->addAction(mActions[LC_VIEW_TOOLBAR_PARTS]);
ToolBarsMenu->addAction(mActions[LC_VIEW_TOOLBAR_COLORS]);
ToolBarsMenu->addAction(mActions[LC_VIEW_TOOLBAR_PROPERTIES]);
ToolBarsMenu->addAction(mActions[LC_VIEW_TOOLBAR_TIMELINE]);
ToolBarsMenu->addAction(mActions[LC_VIEW_TOOLBAR_PREVIEW]);
2015-01-26 00:04:39 +01:00
ToolBarsMenu->addSeparator();
ToolBarsMenu->addAction(mActions[LC_VIEW_TOOLBAR_STANDARD]);
ToolBarsMenu->addAction(mActions[LC_VIEW_TOOLBAR_TOOLS]);
ToolBarsMenu->addAction(mActions[LC_VIEW_TOOLBAR_TIME]);
2015-01-26 00:04:39 +01:00
ViewMenu->addAction(mActions[LC_VIEW_FULLSCREEN]);
QMenu* PieceMenu = menuBar()->addMenu(tr("&Piece"));
PieceMenu->addAction(mActions[LC_PIECE_INSERT]);
PieceMenu->addAction(mActions[LC_PIECE_DELETE]);
2017-03-09 00:55:38 +01:00
PieceMenu->addAction(mActions[LC_PIECE_DUPLICATE]);
PieceMenu->addAction(mActions[LC_PIECE_PAINT_SELECTED]);
2015-01-26 00:04:39 +01:00
PieceMenu->addAction(mActions[LC_PIECE_ARRAY]);
PieceMenu->addAction(mActions[LC_PIECE_MINIFIG_WIZARD]);
PieceMenu->addAction(mActions[LC_PIECE_RESET_PIVOT_POINT]);
PieceMenu->addAction(mActions[LC_PIECE_REMOVE_KEY_FRAMES]);
2015-01-26 00:04:39 +01:00
PieceMenu->addSeparator();
PieceMenu->addAction(mActions[LC_PIECE_EDIT_SELECTED_SUBMODEL]);
2018-10-14 17:47:28 +02:00
PieceMenu->addAction(mActions[LC_PIECE_EDIT_END_SUBMODEL]);
PieceMenu->addAction(mActions[LC_PIECE_VIEW_SELECTED_MODEL]);
2015-12-02 00:31:28 +01:00
PieceMenu->addAction(mActions[LC_PIECE_INLINE_SELECTED_MODELS]);
PieceMenu->addAction(mActions[LC_PIECE_MOVE_SELECTION_TO_MODEL]);
2015-12-02 00:31:28 +01:00
PieceMenu->addSeparator();
2015-01-26 00:04:39 +01:00
PieceMenu->addAction(mActions[LC_PIECE_GROUP]);
PieceMenu->addAction(mActions[LC_PIECE_UNGROUP]);
PieceMenu->addAction(mActions[LC_PIECE_GROUP_REMOVE]);
PieceMenu->addAction(mActions[LC_PIECE_GROUP_ADD]);
PieceMenu->addAction(mActions[LC_PIECE_GROUP_EDIT]);
PieceMenu->addSeparator();
PieceMenu->addAction(mActions[LC_PIECE_HIDE_SELECTED]);
PieceMenu->addAction(mActions[LC_PIECE_HIDE_UNSELECTED]);
2021-03-05 05:55:39 +01:00
PieceMenu->addAction(mActions[LC_PIECE_UNHIDE_SELECTED]);
2015-01-26 00:04:39 +01:00
PieceMenu->addAction(mActions[LC_PIECE_UNHIDE_ALL]);
QMenu* ModelMenu = menuBar()->addMenu(tr("Sub&model"));
2015-01-26 00:04:39 +01:00
ModelMenu->addAction(mActions[LC_MODEL_PROPERTIES]);
ModelMenu->addAction(mActions[LC_MODEL_NEW]);
ModelMenu->addAction(mActions[LC_MODEL_LIST]);
2015-01-26 00:04:39 +01:00
ModelMenu->addSeparator();
for (int ModelIdx = LC_MODEL_FIRST; ModelIdx <= LC_MODEL_LAST; ModelIdx++)
ModelMenu->addAction(mActions[ModelIdx]);
2015-01-26 00:04:39 +01:00
QMenu* HelpMenu = menuBar()->addMenu(tr("&Help"));
HelpMenu->addAction(mActions[LC_HELP_HOMEPAGE]);
HelpMenu->addAction(mActions[LC_HELP_BUG_REPORT]);
2015-01-26 00:04:39 +01:00
#if !LC_DISABLE_UPDATE_CHECK
HelpMenu->addAction(mActions[LC_HELP_UPDATES]);
#endif
#ifndef Q_OS_MACOS
2015-01-26 00:04:39 +01:00
HelpMenu->addSeparator();
#endif
2015-01-26 00:04:39 +01:00
HelpMenu->addAction(mActions[LC_HELP_ABOUT]);
}
void lcMainWindow::CreateToolBars()
{
mSelectionModeMenu = new QMenu(tr("Selection Mode"), this);
for (int ModeIdx = LC_EDIT_SELECTION_MODE_FIRST; ModeIdx <= LC_EDIT_SELECTION_MODE_LAST; ModeIdx++)
mSelectionModeMenu->addAction(mActions[ModeIdx]);
QAction* SelectionModeAction = new QAction(tr("Selection Mode"), this);
SelectionModeAction->setStatusTip(tr("Change selection mode"));
SelectionModeAction->setIcon(QIcon(":/resources/action_select.png"));
SelectionModeAction->setMenu(mSelectionModeMenu);
mTransformMenu = new QMenu(tr("Transform"), this);
mTransformMenu->addAction(mActions[LC_EDIT_TRANSFORM_RELATIVE]);
mTransformMenu->addAction(mActions[LC_EDIT_TRANSFORM_ABSOLUTE]);
mTransformMenu->addSeparator();
mTransformMenu->addAction(mActions[LC_EDIT_TRANSFORM_TOGETHER]);
mTransformMenu->addAction(mActions[LC_EDIT_TRANSFORM_SEPARATELY]);
QAction* TransformAction = new QAction(tr("Transform"), this);
TransformAction->setStatusTip(tr("Transform Options"));
TransformAction->setIcon(QIcon(":/resources/edit_transform_relative.png"));
TransformAction->setMenu(mTransformMenu);
2015-01-26 00:04:39 +01:00
QMenu* SnapXYMenu = new QMenu(tr("Snap XY"), this);
for (int actionIdx = LC_EDIT_SNAP_MOVE_XY0; actionIdx <= LC_EDIT_SNAP_MOVE_XY9; actionIdx++)
SnapXYMenu->addAction(mActions[actionIdx]);
QMenu* SnapZMenu = new QMenu(tr("Snap Z"), this);
for (int actionIdx = LC_EDIT_SNAP_MOVE_Z0; actionIdx <= LC_EDIT_SNAP_MOVE_Z9; actionIdx++)
SnapZMenu->addAction(mActions[actionIdx]);
QMenu* SnapMenu = new QMenu(tr("Snap Menu"), this);
2015-04-25 00:11:50 +02:00
SnapMenu->addAction(mActions[LC_EDIT_SNAP_MOVE_TOGGLE]);
SnapMenu->addSeparator();
2015-01-26 00:04:39 +01:00
SnapMenu->addMenu(SnapXYMenu);
SnapMenu->addMenu(SnapZMenu);
2015-04-25 00:11:50 +02:00
QAction* MoveAction = new QAction(tr("Movement Snap"), this);
2015-01-26 00:04:39 +01:00
MoveAction->setStatusTip(tr("Snap translations to fixed intervals"));
MoveAction->setIcon(QIcon(":/resources/edit_snap_move.png"));
MoveAction->setMenu(SnapMenu);
QMenu* SnapAngleMenu = new QMenu(tr("Snap Angle Menu"), this);
2015-04-25 00:11:50 +02:00
SnapAngleMenu->addAction(mActions[LC_EDIT_SNAP_ANGLE_TOGGLE]);
SnapAngleMenu->addSeparator();
2015-01-26 00:04:39 +01:00
for (int actionIdx = LC_EDIT_SNAP_ANGLE0; actionIdx <= LC_EDIT_SNAP_ANGLE9; actionIdx++)
SnapAngleMenu->addAction(mActions[actionIdx]);
2015-04-25 00:11:50 +02:00
QAction* AngleAction = new QAction(tr("Rotation Snap"), this);
2015-01-26 00:04:39 +01:00
AngleAction->setStatusTip(tr("Snap rotations to fixed intervals"));
AngleAction->setIcon(QIcon(":/resources/edit_snap_angle.png"));
AngleAction->setMenu(SnapAngleMenu);
mStandardToolBar = addToolBar(tr("Standard"));
mStandardToolBar->setObjectName("StandardToolbar");
mStandardToolBar->addAction(mActions[LC_FILE_NEW]);
mStandardToolBar->addAction(mActions[LC_FILE_OPEN]);
mStandardToolBar->addAction(mActions[LC_FILE_SAVE]);
mStandardToolBar->addSeparator();
mStandardToolBar->addAction(mActions[LC_EDIT_UNDO]);
mStandardToolBar->addAction(mActions[LC_EDIT_REDO]);
mStandardToolBar->addSeparator();
mStandardToolBar->addAction(SelectionModeAction);
mStandardToolBar->addAction(TransformAction);
2015-01-26 00:04:39 +01:00
mStandardToolBar->addAction(MoveAction);
mStandardToolBar->addAction(AngleAction);
((QToolButton*)mStandardToolBar->widgetForAction(SelectionModeAction))->setPopupMode(QToolButton::InstantPopup);
((QToolButton*)mStandardToolBar->widgetForAction(TransformAction))->setPopupMode(QToolButton::InstantPopup);
2015-01-26 00:04:39 +01:00
((QToolButton*)mStandardToolBar->widgetForAction(MoveAction))->setPopupMode(QToolButton::InstantPopup);
((QToolButton*)mStandardToolBar->widgetForAction(AngleAction))->setPopupMode(QToolButton::InstantPopup);
2017-11-14 01:54:14 +01:00
mTimeToolBar = addToolBar(tr("Time"));
mTimeToolBar->setObjectName("TimeToolbar");
mTimeToolBar->addAction(mActions[LC_VIEW_TIME_FIRST]);
mTimeToolBar->addAction(mActions[LC_VIEW_TIME_PREVIOUS]);
mTimeToolBar->addAction(mActions[LC_VIEW_TIME_NEXT]);
mTimeToolBar->addAction(mActions[LC_VIEW_TIME_LAST]);
mTimeToolBar->addAction(mActions[LC_VIEW_TIME_ADD_KEYS]);
2015-01-26 00:04:39 +01:00
mToolsToolBar = addToolBar(tr("Tools"));
mToolsToolBar->setObjectName("ToolsToolbar");
insertToolBarBreak(mToolsToolBar);
mToolsToolBar->addAction(mActions[LC_EDIT_ACTION_INSERT]);
2023-08-13 15:15:52 +02:00
mToolsToolBar->addAction(mActions[LC_EDIT_ACTION_POINT_LIGHT]);
2015-01-26 00:04:39 +01:00
mToolsToolBar->addAction(mActions[LC_EDIT_ACTION_SPOTLIGHT]);
2023-08-13 15:15:52 +02:00
mToolsToolBar->addAction(mActions[LC_EDIT_ACTION_DIRECTIONAL_LIGHT]);
mToolsToolBar->addAction(mActions[LC_EDIT_ACTION_AREA_LIGHT]);
2015-01-26 00:04:39 +01:00
mToolsToolBar->addAction(mActions[LC_EDIT_ACTION_CAMERA]);
mToolsToolBar->addSeparator();
mToolsToolBar->addAction(mActions[LC_EDIT_ACTION_SELECT]);
mToolsToolBar->addAction(mActions[LC_EDIT_ACTION_MOVE]);
mToolsToolBar->addAction(mActions[LC_EDIT_ACTION_ROTATE]);
mToolsToolBar->addAction(mActions[LC_EDIT_ACTION_DELETE]);
mToolsToolBar->addAction(mActions[LC_EDIT_ACTION_PAINT]);
mToolsToolBar->addAction(mActions[LC_EDIT_ACTION_COLOR_PICKER]);
2015-01-26 00:04:39 +01:00
mToolsToolBar->addSeparator();
mToolsToolBar->addAction(mActions[LC_EDIT_ACTION_ZOOM]);
mToolsToolBar->addAction(mActions[LC_EDIT_ACTION_PAN]);
mToolsToolBar->addAction(mActions[LC_EDIT_ACTION_ROTATE_VIEW]);
mToolsToolBar->addAction(mActions[LC_EDIT_ACTION_ROLL]);
mToolsToolBar->addAction(mActions[LC_EDIT_ACTION_ZOOM_REGION]);
2017-11-14 01:54:14 +01:00
mToolsToolBar->hide();
2015-01-26 00:04:39 +01:00
mPartsToolBar = new QDockWidget(tr("Parts"), this);
mPartsToolBar->setObjectName("PartsToolbar");
2017-02-06 18:06:52 +01:00
mPartSelectionWidget = new lcPartSelectionWidget(mPartsToolBar);
2016-12-20 23:11:19 +01:00
mPartsToolBar->setWidget(mPartSelectionWidget);
addDockWidget(Qt::RightDockWidgetArea, mPartsToolBar);
mColorsToolBar = new QDockWidget(tr("Colors"), this);
mColorsToolBar->setObjectName("ColorsToolbar");
mColorsToolBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
2015-01-26 00:04:39 +01:00
2023-04-30 04:48:30 +02:00
mColorList = new lcColorList();
2023-05-16 06:02:17 +02:00
connect(mColorList, &lcColorList::ColorChanged, this, &lcMainWindow::ColorChanged);
2016-12-29 16:37:24 +01:00
QWidget* ColorWidget = new QWidget(mColorsToolBar);
QVBoxLayout* ColorLayout = new QVBoxLayout(ColorWidget);
2020-12-30 04:27:40 +01:00
ColorLayout->setContentsMargins(0, 0, 0, 0);
QHBoxLayout* ColorButtonLayout = new QHBoxLayout();
ColorButtonLayout->setContentsMargins(0, 0, 0, 0);
ColorLayout->addLayout(ColorButtonLayout);
mColorButton = new QToolButton(ColorWidget);
mColorButton->setAutoRaise(true);
mColorButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
mColorButton->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
ColorButtonLayout->addWidget(mColorButton);
connect(mColorButton, SIGNAL(clicked()), this, SLOT(ColorButtonClicked()));
ColorLayout->addWidget(mColorList);
mColorsToolBar->setWidget(ColorWidget);
2016-12-20 23:11:19 +01:00
addDockWidget(Qt::RightDockWidgetArea, mColorsToolBar);
2015-01-26 00:04:39 +01:00
mPropertiesToolBar = new QDockWidget(tr("Properties"), this);
mPropertiesToolBar->setObjectName("PropertiesToolbar");
2017-11-14 01:54:14 +01:00
QWidget* PropertiesWidget = new QWidget(mPropertiesToolBar);
QVBoxLayout* PropertiesLayout = new QVBoxLayout(PropertiesWidget);
2020-12-30 19:48:51 +01:00
PropertiesLayout->setContentsMargins(0, 0, 0, 0);
2017-11-14 01:54:14 +01:00
2023-12-31 21:55:35 +01:00
QScrollArea* PropertiesScrollArea = new QScrollArea(PropertiesWidget);
PropertiesScrollArea->setWidgetResizable(true);
PropertiesLayout->addWidget(PropertiesScrollArea);
mPropertiesWidget = new lcPropertiesWidget(PropertiesScrollArea);
PropertiesScrollArea->setWidget(mPropertiesWidget);
2017-11-14 01:54:14 +01:00
QHBoxLayout* TransformLayout = new QHBoxLayout;
QWidget* TransformWidget = new QWidget();
TransformWidget->setLayout(TransformLayout);
QToolButton* TransformButton = new QToolButton(TransformWidget);
TransformButton->setDefaultAction(mActions[LC_EDIT_TRANSFORM]);
TransformButton->setPopupMode(QToolButton::InstantPopup);
TransformLayout->addWidget(TransformButton);
2017-11-14 02:24:36 +01:00
mTransformXEdit = new lcTransformLineEdit();
2017-11-14 01:54:14 +01:00
TransformLayout->addWidget(mTransformXEdit);
2017-11-14 02:24:36 +01:00
mTransformYEdit = new lcTransformLineEdit();
2017-11-14 01:54:14 +01:00
TransformLayout->addWidget(mTransformYEdit);
2017-11-14 02:24:36 +01:00
mTransformZEdit = new lcTransformLineEdit();
2017-11-14 01:54:14 +01:00
TransformLayout->addWidget(mTransformZEdit);
2017-11-14 02:24:36 +01:00
2017-11-14 01:54:14 +01:00
PropertiesLayout->addWidget(TransformWidget);
2017-11-14 02:24:36 +01:00
2017-11-14 01:54:14 +01:00
connect(mTransformXEdit, SIGNAL(returnPressed()), mActions[LC_EDIT_TRANSFORM], SIGNAL(triggered()));
connect(mTransformYEdit, SIGNAL(returnPressed()), mActions[LC_EDIT_TRANSFORM], SIGNAL(triggered()));
connect(mTransformZEdit, SIGNAL(returnPressed()), mActions[LC_EDIT_TRANSFORM], SIGNAL(triggered()));
2015-01-26 00:04:39 +01:00
2017-11-14 01:54:14 +01:00
mPropertiesToolBar->setWidget(PropertiesWidget);
2015-01-26 00:04:39 +01:00
addDockWidget(Qt::RightDockWidgetArea, mPropertiesToolBar);
mTimelineToolBar = new QDockWidget(tr("Timeline"), this);
mTimelineToolBar->setObjectName("TimelineToolbar");
2015-03-08 01:27:11 +01:00
mTimelineToolBar->setAcceptDrops(true);
mTimelineWidget = new lcTimelineWidget(mTimelineToolBar);
mTimelineToolBar->setWidget(mTimelineWidget);
addDockWidget(Qt::RightDockWidgetArea, mTimelineToolBar);
CreatePreviewWidget();
2017-02-06 18:06:52 +01:00
tabifyDockWidget(mPartsToolBar, mPropertiesToolBar);
tabifyDockWidget(mPropertiesToolBar, mTimelineToolBar);
2021-01-11 17:59:29 +01:00
tabifyDockWidget(mTimelineToolBar, mPreviewToolBar);
connect(mPropertiesToolBar, SIGNAL(topLevelChanged(bool)), this, SLOT(EnableWindowFlags(bool)));
connect(mTimelineToolBar, SIGNAL(topLevelChanged(bool)), this, SLOT(EnableWindowFlags(bool)));
connect(mPartsToolBar, SIGNAL(topLevelChanged(bool)), this, SLOT(EnableWindowFlags(bool)));
connect(mColorsToolBar, SIGNAL(topLevelChanged(bool)), this, SLOT(EnableWindowFlags(bool)));
2017-02-06 18:06:52 +01:00
mPartsToolBar->raise();
2015-01-26 00:04:39 +01:00
}
2020-12-25 19:54:33 +01:00
lcView* lcMainWindow::CreateView(lcModel* Model)
{
2020-12-25 19:54:33 +01:00
lcView* NewView = new lcView(lcViewType::View, Model);
2020-12-16 03:27:54 +01:00
connect(NewView, SIGNAL(FocusReceived()), this, SLOT(ViewFocusReceived()));
2020-12-25 02:14:36 +01:00
AddView(NewView);
return NewView;
}
void lcMainWindow::PreviewPiece(const QString& PartId, int ColorCode, bool ShowPreview)
{
if (ShowPreview)
mPreviewToolBar->show();
mPreviewWidget->SetCurrentPiece(PartId, ColorCode);
}
void lcMainWindow::CreatePreviewWidget()
{
mPreviewWidget = new lcPreviewDockWidget();
mPreviewToolBar = new QDockWidget(tr("Preview"), this);
2020-12-15 00:08:43 +01:00
mPreviewToolBar->setWindowTitle(tr("Preview"));
2020-12-26 20:44:41 +01:00
mPreviewToolBar->setObjectName("PreviewToolBar");
mPreviewToolBar->setWidget(mPreviewWidget);
addDockWidget(Qt::RightDockWidgetArea, mPreviewToolBar);
connect(mPreviewToolBar, SIGNAL(topLevelChanged(bool)), this, SLOT(EnableWindowFlags(bool)));
}
2020-12-18 21:15:35 +01:00
void lcMainWindow::TogglePreviewWidget(bool Visible)
{
2020-12-26 20:44:41 +01:00
if (mPreviewToolBar)
{
2020-12-18 21:15:35 +01:00
if (Visible)
mPreviewToolBar->show();
else
mPreviewToolBar->hide();
2020-12-26 20:44:41 +01:00
}
2023-08-13 15:15:52 +02:00
else if (Visible)
2020-12-26 20:44:41 +01:00
{
CreatePreviewWidget();
}
}
void lcMainWindow::EnableWindowFlags(bool Detached)
{
if (Detached)
{
QDockWidget* DockWidget = qobject_cast<QDockWidget*>(sender());
DockWidget->setWindowFlags(Qt::CustomizeWindowHint | Qt::Window | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint);
if (isVisible())
DockWidget->show();
}
}
2020-01-04 19:48:17 +01:00
class lcElidedLabel : public QFrame
{
public:
explicit lcElidedLabel(QWidget* Parent = nullptr)
: QFrame(Parent)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
}
void setText(const QString& Text)
{
mText = Text;
update();
}
protected:
void paintEvent(QPaintEvent* event) override;
QString mText;
};
void lcElidedLabel::paintEvent(QPaintEvent* event)
{
QFrame::paintEvent(event);
QPainter Painter(this);
QFontMetrics FontMetrics = Painter.fontMetrics();
int LineSpacing = FontMetrics.lineSpacing();
int y = 0;
QTextLayout TextLayout(mText, Painter.font());
TextLayout.beginLayout();
for (;;)
{
QTextLine Line = TextLayout.createLine();
if (!Line.isValid())
break;
Line.setLineWidth(width());
int NextLineY = y + LineSpacing;
if (height() >= NextLineY + LineSpacing)
{
Line.draw(&Painter, QPoint(0, y));
y = NextLineY;
}
else
{
QString LastLine = mText.mid(Line.textStart());
QString ElidedLastLine = FontMetrics.elidedText(LastLine, Qt::ElideRight, width());
Painter.drawText(QPoint(0, y + FontMetrics.ascent()), ElidedLastLine);
Line = TextLayout.createLine();
break;
}
}
TextLayout.endLayout();
}
2015-01-26 00:04:39 +01:00
void lcMainWindow::CreateStatusBar()
{
QStatusBar* StatusBar = new QStatusBar(this);
setStatusBar(StatusBar);
2020-01-04 19:48:17 +01:00
mStatusBarLabel = new lcElidedLabel();
StatusBar->addWidget(mStatusBarLabel, 1);
2015-01-26 00:04:39 +01:00
mStatusPositionLabel = new QLabel();
StatusBar->addPermanentWidget(mStatusPositionLabel);
mStatusSnapLabel = new QLabel();
StatusBar->addPermanentWidget(mStatusSnapLabel);
mStatusTimeLabel = new QLabel();
StatusBar->addPermanentWidget(mStatusTimeLabel);
}
2017-02-06 18:06:52 +01:00
void lcMainWindow::closeEvent(QCloseEvent* Event)
2015-01-26 00:04:39 +01:00
{
if (SaveProjectIfModified())
{
2017-02-06 18:06:52 +01:00
Event->accept();
QSettings Settings;
Settings.beginGroup("MainWindow");
Settings.setValue("Geometry", saveGeometry());
Settings.setValue("State", saveState());
mPartSelectionWidget->SaveState(Settings);
Settings.endGroup();
gApplication->SaveTabLayout();
2015-01-26 00:04:39 +01:00
}
else
2017-02-06 18:06:52 +01:00
Event->ignore();
2015-01-26 00:04:39 +01:00
}
void lcMainWindow::dragEnterEvent(QDragEnterEvent* Event)
{
if (Event->mimeData()->hasUrls())
Event->acceptProposedAction();
}
void lcMainWindow::dropEvent(QDropEvent* Event)
{
const QMimeData* MimeData = Event->mimeData();
2018-02-22 02:27:24 +01:00
const QList<QUrl> Urls = MimeData->urls();
for (const QUrl& Url : Urls)
if (OpenProject(Url.toLocalFile()))
break;
}
2015-01-26 00:04:39 +01:00
QMenu* lcMainWindow::createPopupMenu()
{
QMenu* Menu = new QMenu(this);
UpdateDockWidgetActions();
Menu->addAction(mActions[LC_VIEW_TOOLBAR_PARTS]);
Menu->addAction(mActions[LC_VIEW_TOOLBAR_COLORS]);
Menu->addAction(mActions[LC_VIEW_TOOLBAR_PROPERTIES]);
Menu->addAction(mActions[LC_VIEW_TOOLBAR_TIMELINE]);
Menu->addAction(mActions[LC_VIEW_TOOLBAR_PREVIEW]);
2015-01-26 00:04:39 +01:00
Menu->addSeparator();
Menu->addAction(mActions[LC_VIEW_TOOLBAR_STANDARD]);
Menu->addAction(mActions[LC_VIEW_TOOLBAR_TOOLS]);
Menu->addAction(mActions[LC_VIEW_TOOLBAR_TIME]);
2015-01-26 00:04:39 +01:00
return Menu;
}
void lcMainWindow::UpdateDockWidgetActions()
{
mActions[LC_VIEW_TOOLBAR_PARTS]->setChecked(mPartsToolBar->isVisible());
mActions[LC_VIEW_TOOLBAR_COLORS]->setChecked(mColorsToolBar->isVisible());
mActions[LC_VIEW_TOOLBAR_PROPERTIES]->setChecked(mPropertiesToolBar->isVisible());
mActions[LC_VIEW_TOOLBAR_TIMELINE]->setChecked(mTimelineToolBar->isVisible());
mActions[LC_VIEW_TOOLBAR_STANDARD]->setChecked(mStandardToolBar->isVisible());
mActions[LC_VIEW_TOOLBAR_TOOLS]->setChecked(mToolsToolBar->isVisible());
mActions[LC_VIEW_TOOLBAR_TIME]->setChecked(mTimeToolBar->isVisible());
mActions[LC_VIEW_TOOLBAR_PREVIEW]->setChecked(mPreviewToolBar->isVisible());
}
void lcMainWindow::UpdateGamepads()
{
2018-08-20 20:47:46 +02:00
#if LC_ENABLE_GAMEPAD
QDateTime Now = QDateTime::currentDateTime();
quint64 Elapsed = mLastGamepadUpdate.msecsTo(Now);
mLastGamepadUpdate = Now;
if (!gMainWindow)
return;
2020-12-25 19:54:33 +01:00
lcView* ActiveView = GetActiveView();
if (!ActiveView)
return;
const QList<int> Gamepads = QGamepadManager::instance()->connectedGamepads();
if (Gamepads.isEmpty())
return;
QGamepad Gamepad(Gamepads[0]);
float Scale = (float)Elapsed / 20.0f;
lcVector3 Distance(Scale * Gamepad.axisLeftX(), 0.0f, -Scale * Gamepad.axisLeftY());
if (fabsf(Distance.LengthSquared()) > 0.01f)
ActiveView->MoveCamera(Distance);
#endif
}
void lcMainWindow::ModelTabContextMenuRequested(const QPoint& Point)
{
QMenu* Menu = new QMenu;
mModelTabWidgetContextMenuIndex = mModelTabWidget->tabBar()->tabAt(Point);
if (mModelTabWidget->count() > 1)
Menu->addAction(tr("Close Other Tabs"), this, SLOT(ModelTabCloseOtherTabs()));
if (mModelTabWidgetContextMenuIndex == mModelTabWidget->currentIndex())
2020-01-05 20:38:24 +01:00
Menu->addAction(mActions[LC_VIEW_RESET_VIEWS]);
Menu->exec(QCursor::pos());
delete Menu;
}
void lcMainWindow::ModelTabCloseOtherTabs()
{
if (mModelTabWidgetContextMenuIndex == -1)
return;
while (mModelTabWidget->count() - 1 > mModelTabWidgetContextMenuIndex)
delete mModelTabWidget->widget(mModelTabWidgetContextMenuIndex + 1);
while (mModelTabWidget->count() > 1)
delete mModelTabWidget->widget(0);
}
2016-03-06 02:47:00 +01:00
void lcMainWindow::ModelTabClosed(int Index)
{
2016-12-28 22:30:31 +01:00
if (mModelTabWidget->count() != 1)
delete mModelTabWidget->widget(Index);
else
NewProject();
2016-03-06 02:47:00 +01:00
}
void lcMainWindow::ModelTabChanged(int Index)
{
Project* Project = lcGetActiveProject();
lcModelTabWidget* CurrentTab = (lcModelTabWidget*)mModelTabWidget->widget(Index);
2024-06-17 02:43:02 +02:00
Project->SetActiveModel(CurrentTab ? CurrentTab->GetModel() : nullptr);
2016-03-06 02:47:00 +01:00
}
2015-01-26 00:04:39 +01:00
void lcMainWindow::ClipboardChanged()
{
const QString MimeType = QLatin1String("application/vnd.leocad-clipboard");
const QMimeData* MimeData = QApplication::clipboard()->mimeData();
QByteArray ClipboardData;
2019-04-02 20:19:23 +02:00
if (MimeData && MimeData->hasFormat(MimeType))
2015-01-26 00:04:39 +01:00
ClipboardData = MimeData->data(MimeType);
gApplication->SetClipboard(ClipboardData);
2015-01-26 00:04:39 +01:00
}
void lcMainWindow::ActionTriggered()
{
QObject* Action = sender();
for (int CommandIdx = 0; CommandIdx < LC_NUM_COMMANDS; CommandIdx++)
{
if (Action == mActions[CommandIdx])
{
HandleCommand((lcCommandId)CommandIdx);
break;
}
}
}
void lcMainWindow::ColorChanged(int ColorIndex)
{
SetColorIndex(ColorIndex);
}
void lcMainWindow::ColorButtonClicked()
{
lcModel* ActiveModel = GetActiveModel();
if (ActiveModel)
ActiveModel->PaintSelectedPieces();
}
void lcMainWindow::ProjectFileChanged(const QString& Path)
{
static bool Ignore;
if (Ignore)
return;
2018-01-06 19:15:24 +01:00
QString Text = tr("The file '%1' has been modified by another application, do you want to reload it?").arg(QDir::toNativeSeparators(Path));
Project* CurrentProject = lcGetActiveProject();
Ignore = true;
if (QMessageBox::question(this, tr("File Changed"), Text, QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
{
Ignore = false;
CurrentProject->MarkAsModified();
UpdateTitle();
return;
}
Ignore = false;
2018-01-06 19:15:24 +01:00
QFileInfo FileInfo(Path);
2018-01-06 19:15:24 +01:00
if (FileInfo == QFileInfo(CurrentProject->GetFileName()))
{
2018-01-06 19:15:24 +01:00
Project* NewProject = new Project;
if (NewProject->Load(Path, true))
2018-01-06 19:15:24 +01:00
{
QByteArray TabLayout = GetTabLayout();
2018-01-06 19:15:24 +01:00
gApplication->SetProject(NewProject);
RestoreTabLayout(TabLayout);
2020-12-25 19:54:33 +01:00
lcView::UpdateAllViews();
2018-01-06 19:15:24 +01:00
}
}
else
{
2018-01-06 19:15:24 +01:00
PieceInfo* Info = lcGetPiecesLibrary()->FindPiece(FileInfo.fileName().toLatin1(), CurrentProject, false, true);
if (Info && Info->IsProject())
Info->GetProject()->Load(Path, true);
}
}
2015-01-26 00:04:39 +01:00
void lcMainWindow::Print(QPrinter* Printer)
{
2017-02-11 21:41:00 +01:00
#ifndef QT_NO_PRINTER
2015-01-26 00:04:39 +01:00
int DocCopies;
int PageCopies;
2021-01-15 03:19:58 +01:00
lcInstructions* Instructions = lcGetActiveProject()->GetInstructions();
const int PageCount = static_cast<int>(Instructions->mPages.size());
2015-01-26 00:04:39 +01:00
if (Printer->collateCopies())
{
DocCopies = 1;
PageCopies = Printer->supportsMultipleCopies() ? 1 : Printer->copyCount();
}
else
{
DocCopies = Printer->supportsMultipleCopies() ? 1 : Printer->copyCount();
PageCopies = 1;
}
int FromPage = Printer->fromPage();
int ToPage = Printer->toPage();
bool Ascending = true;
if (FromPage == 0 && ToPage == 0)
{
FromPage = 1;
ToPage = PageCount;
}
FromPage = qMax(1, FromPage);
ToPage = qMin(PageCount, ToPage);
if (ToPage < FromPage)
return;
if (Printer->pageOrder() == QPrinter::LastPageFirst)
{
int Tmp = FromPage;
FromPage = ToPage;
ToPage = Tmp;
Ascending = false;
}
2021-01-14 23:51:43 +01:00
QRect PageRect = Printer->pageLayout().paintRectPixels(Printer->resolution());
2019-12-31 01:45:28 +01:00
const int Resolution = Printer->resolution();
const int Margin = Resolution / 2; // todo: user setting
QRect MarginRect = QRect(PageRect.left() + Margin, PageRect.top() + Margin, PageRect.width() - Margin * 2, PageRect.height() - Margin * 2);
2015-01-26 00:04:39 +01:00
QPainter Painter(Printer);
2019-12-31 01:04:58 +01:00
bool FirstPage = true;
2015-01-26 00:04:39 +01:00
// TODO: option to print background
for (int DocCopy = 0; DocCopy < DocCopies; DocCopy++)
{
int Page = FromPage;
for (;;)
{
for (int PageCopy = 0; PageCopy < PageCopies; PageCopy++)
{
if (Printer->printerState() == QPrinter::Aborted || Printer->printerState() == QPrinter::Error)
return;
2019-12-31 01:04:58 +01:00
if (!FirstPage)
Printer->newPage();
else
FirstPage = false;
2015-01-26 00:04:39 +01:00
2019-12-31 01:45:28 +01:00
int StepWidth = MarginRect.width();
int StepHeight = MarginRect.height();
2015-01-26 00:04:39 +01:00
2021-01-15 03:19:58 +01:00
const lcInstructionsPage& PageLayout = Instructions->mPages[Page - 1];
2021-01-06 03:48:12 +01:00
lcModel* Model = PageLayout.Steps[0].Model;
lcStep Step = PageLayout.Steps[0].Step;
QImage Image = Model->GetStepImage(false, StepWidth, StepHeight, Step);
2015-01-26 00:04:39 +01:00
2019-12-31 01:45:28 +01:00
Painter.drawImage(MarginRect.left(), MarginRect.top(), Image);
2015-01-26 00:04:39 +01:00
2019-12-31 01:04:58 +01:00
// TODO: add print options somewhere but Qt doesn't allow changes to the page setup dialog
// DWORD dwPrint = theApp.GetProfileInt("Settings","Print", PRINT_NUMBERS|PRINT_BORDER);
2015-01-26 00:04:39 +01:00
2019-12-31 01:04:58 +01:00
// if (print text)
{
2019-12-31 01:19:46 +01:00
QFont Font("Helvetica", 96);
2019-12-31 01:04:58 +01:00
Painter.setFont(Font);
2015-01-26 00:04:39 +01:00
2019-12-31 01:04:58 +01:00
QFontMetrics FontMetrics(Font);
2015-01-26 00:04:39 +01:00
2019-12-31 01:45:28 +01:00
int TextMargin = Resolution / 2;
QRect TextRect = QRect(MarginRect.left() + TextMargin, MarginRect.top() + TextMargin, MarginRect.width() - TextMargin * 2, MarginRect.height() - TextMargin * 2);
2019-12-31 01:26:29 +01:00
2019-12-31 01:19:46 +01:00
Painter.drawText(TextRect, Qt::AlignTop | Qt::AlignLeft, QString::number(Step));
2019-12-31 01:04:58 +01:00
}
2019-12-31 01:45:28 +01:00
/*
2019-12-31 01:04:58 +01:00
// if (print border)
{
QPen BlackPen(Qt::black, 2);
Painter.setPen(BlackPen);
2015-01-26 00:04:39 +01:00
2019-12-31 01:45:28 +01:00
Painter.drawLine(MarginRect.left(), MarginRect.top(), MarginRect.right(), MarginRect.top());
Painter.drawLine(MarginRect.left(), MarginRect.bottom(), MarginRect.right(), MarginRect.bottom());
Painter.drawLine(MarginRect.left(), MarginRect.top(), MarginRect.left(), MarginRect.bottom());
Painter.drawLine(MarginRect.right(), MarginRect.top(), MarginRect.right(), MarginRect.bottom());
2015-01-26 00:04:39 +01:00
}
2019-12-31 01:45:28 +01:00
*/
2015-01-26 00:04:39 +01:00
// TODO: print header and footer
}
if (Page == ToPage)
break;
if (Ascending)
Page++;
else
Page--;
}
}
2017-02-11 21:41:00 +01:00
#endif
2015-01-26 00:04:39 +01:00
}
2016-08-01 05:44:15 +02:00
void lcMainWindow::ShowUpdatesDialog()
{
lcQUpdateDialog Dialog(this, false);
Dialog.exec();
}
void lcMainWindow::ShowAboutDialog()
{
2023-04-30 04:55:54 +02:00
lcAboutDialog Dialog(this);
2016-08-01 05:44:15 +02:00
Dialog.exec();
}
2017-12-11 03:12:31 +01:00
void lcMainWindow::ShowHTMLDialog()
{
lcHTMLExportOptions Options(lcGetActiveProject());
2017-12-11 03:12:31 +01:00
lcQHTMLDialog Dialog(this, &Options);
if (Dialog.exec() != QDialog::Accepted)
return;
Options.SaveDefaults();
2017-12-11 03:12:31 +01:00
lcGetActiveProject()->ExportHTML(Options);
}
2023-05-21 11:17:00 +02:00
void lcMainWindow::ShowRenderDialog(int Command)
2017-09-22 19:08:02 +02:00
{
2023-05-21 11:17:00 +02:00
lcRenderDialog Dialog(this, Command);
2017-09-22 19:08:02 +02:00
Dialog.exec();
}
2020-06-01 03:46:36 +02:00
void lcMainWindow::ShowInstructionsDialog()
{
lcInstructionsDialog* Dialog = new lcInstructionsDialog(this, lcGetActiveProject());
Dialog->setWindowModality(Qt::ApplicationModal);
Dialog->setAttribute(Qt::WA_DeleteOnClose);
Dialog->show();
}
2015-01-26 00:04:39 +01:00
void lcMainWindow::ShowPrintDialog()
{
2017-02-11 21:41:00 +01:00
#ifndef QT_NO_PRINTER
2021-01-15 03:19:58 +01:00
int PageCount = static_cast<int>(lcGetActiveProject()->GetInstructions()->mPages.size());
2015-01-26 00:04:39 +01:00
QPrinter Printer(QPrinter::HighResolution);
Printer.setFromTo(1, PageCount + 1);
QPrintDialog PrintDialog(&Printer, this);
if (PrintDialog.exec() == QDialog::Accepted)
Print(&Printer);
2017-02-11 21:41:00 +01:00
#endif
2015-01-26 00:04:39 +01:00
}
void lcMainWindow::SetShadingMode(lcShadingMode ShadingMode)
{
lcGetPreferences().mShadingMode = ShadingMode;
2020-12-25 19:37:59 +01:00
UpdateShadingMode();
2020-12-25 19:37:59 +01:00
2020-12-25 19:54:33 +01:00
lcView::UpdateAllViews();
2020-12-25 19:37:59 +01:00
if (mPartSelectionWidget)
2024-07-12 00:04:07 +02:00
mPartSelectionWidget->UpdateThumbnails();
}
2017-11-22 02:58:36 +01:00
void lcMainWindow::SetSelectionMode(lcSelectionMode SelectionMode)
{
mSelectionMode = SelectionMode;
2020-12-25 19:37:59 +01:00
2017-11-22 02:58:36 +01:00
UpdateSelectionMode();
}
2020-01-05 20:38:24 +01:00
void lcMainWindow::ToggleViewSphere()
{
lcGetPreferences().mViewSphereEnabled = !lcGetPreferences().mViewSphereEnabled;
2020-12-25 19:54:33 +01:00
lcView::UpdateAllViews();
2020-01-05 20:38:24 +01:00
}
void lcMainWindow::ToggleAxisIcon()
{
lcGetPreferences().mDrawAxes = !lcGetPreferences().mDrawAxes;
2020-12-25 19:54:33 +01:00
lcView::UpdateAllViews();
}
2020-12-24 04:10:54 +01:00
void lcMainWindow::ToggleGrid()
{
lcGetPreferences().mGridEnabled = !lcGetPreferences().mGridEnabled;
2020-12-25 19:54:33 +01:00
lcView::UpdateAllViews();
2020-12-24 04:10:54 +01:00
}
void lcMainWindow::ToggleFadePreviousSteps()
{
lcGetPreferences().mFadeSteps = !lcGetPreferences().mFadeSteps;
2020-12-25 19:54:33 +01:00
lcView::UpdateAllViews();
}
QByteArray lcMainWindow::GetTabLayout()
{
2019-05-18 20:33:27 +02:00
QByteArray TabLayoutData;
QDataStream DataStream(&TabLayoutData, QIODevice::WriteOnly);
DataStream << (quint32)LC_TAB_LAYOUT_VERSION;
qint32 NumTabs = mModelTabWidget->count();
DataStream << NumTabs;
2020-05-03 21:11:51 +02:00
DataStream << ((lcModelTabWidget*)mModelTabWidget->currentWidget())->GetModel()->GetProperties().mFileName;
for (int TabIdx = 0; TabIdx < NumTabs; TabIdx++)
{
lcModelTabWidget* TabWidget = (lcModelTabWidget*)mModelTabWidget->widget(TabIdx);
2020-05-03 21:11:51 +02:00
DataStream << TabWidget->GetModel()->GetProperties().mFileName;
std::function<void (QWidget*)> SaveWidget = [&DataStream, &SaveWidget, &TabWidget](QWidget* Widget)
{
2020-12-18 02:59:11 +01:00
if (Widget->metaObject() == &lcViewWidget::staticMetaObject)
{
2020-12-25 19:54:33 +01:00
lcView* CurrentView = ((lcViewWidget*)Widget)->GetView();
DataStream << (qint32)0;
DataStream << (qint32)(TabWidget->GetActiveView() == CurrentView ? 1 : 0);
2020-12-04 21:49:01 +01:00
const lcCamera* Camera = CurrentView->GetCamera();
if (Camera->IsSimple())
{
DataStream << (qint32)0;
DataStream << Camera->m_fovy;
DataStream << Camera->m_zNear;
DataStream << Camera->m_zFar;
DataStream << Camera->mPosition;
DataStream << Camera->mTargetPosition;
DataStream << Camera->mUpVector;
}
else
{
DataStream << (qint32)1;
2020-12-14 01:27:21 +01:00
DataStream << Camera->GetName();
}
}
else
{
QSplitter* Splitter = (QSplitter*)Widget;
DataStream << (qint32)(Splitter->orientation() == Qt::Horizontal ? 1 : 2);
DataStream << Splitter->sizes();
SaveWidget(Splitter->widget(0));
SaveWidget(Splitter->widget(1));
}
};
QLayout* TabLayout = TabWidget->layout();
SaveWidget(TabLayout->itemAt(0)->widget());
}
2019-05-18 20:33:27 +02:00
return TabLayoutData;
}
void lcMainWindow::RestoreTabLayout(const QByteArray& TabLayout)
{
if (TabLayout.isEmpty())
return;
QDataStream DataStream(TabLayout);
quint32 Version;
DataStream >> Version;
if (Version != LC_TAB_LAYOUT_VERSION)
return;
qint32 NumTabs;
DataStream >> NumTabs;
QString CurrentTabName;
DataStream >> CurrentTabName;
2021-03-02 02:21:13 +01:00
RemoveAllModelTabs();
for (int TabIdx = 0; TabIdx < NumTabs; TabIdx++)
{
QString ModelName;
DataStream >> ModelName;
lcModel* Model = lcGetActiveProject()->GetModel(ModelName);
lcModelTabWidget* TabWidget = nullptr;
if (Model)
{
SetCurrentModelTab(Model);
TabWidget = (lcModelTabWidget*)mModelTabWidget->widget(mModelTabWidget->count() - 1);
}
2018-01-16 02:03:08 +01:00
QWidget* ActiveWidget = nullptr;
2019-03-11 21:04:31 +01:00
std::function<void(QWidget*)> LoadWidget = [&DataStream, &LoadWidget, &ActiveWidget, this](QWidget* ParentWidget)
{
qint32 WidgetType;
DataStream >> WidgetType;
if (WidgetType == 0)
{
qint32 IsActive;
DataStream >> IsActive;
if (IsActive)
ActiveWidget = ParentWidget;
qint32 CameraType;
DataStream >> CameraType;
2020-12-25 19:54:33 +01:00
lcView* CurrentView = nullptr;
if (ParentWidget)
2020-12-25 19:54:33 +01:00
CurrentView = ((lcViewWidget*)ParentWidget)->GetView();
if (CameraType == 0)
{
float FoV, ZNear, ZFar;
lcVector3 Position, TargetPosition, UpVector;
DataStream >> FoV;
DataStream >> ZNear;
DataStream >> ZFar;
DataStream >> Position;
DataStream >> TargetPosition;
DataStream >> UpVector;
if (CurrentView)
{
2020-12-04 21:49:01 +01:00
lcCamera* Camera = CurrentView->GetCamera();
if (!std::isnan(FoV))
Camera->m_fovy = FoV;
if (!std::isnan(ZNear))
Camera->m_zNear = ZNear;
if (!std::isnan(ZFar))
Camera->m_zFar = ZFar;
if (!Position.IsNan() && !TargetPosition.IsNan() && !UpVector.IsNan())
{
2023-12-28 20:32:25 +01:00
Camera->SetPosition(Position, 1, false);
Camera->SetTargetPosition(TargetPosition, 1, false);
Camera->SetUpVector(UpVector, 1, false);
}
Camera->UpdatePosition(1);
}
}
else
{
QByteArray CameraName;
DataStream >> CameraName;
if (CurrentView)
CurrentView->SetCamera(CameraName);
}
}
else
{
QList<int> Sizes;
DataStream >> Sizes;
if (ParentWidget)
{
ParentWidget->setFocus();
if (WidgetType == 1)
SplitVertical();
else
SplitHorizontal();
QSplitter* Splitter = (QSplitter*)ParentWidget->parentWidget();
Splitter->setSizes(Sizes);
LoadWidget(Splitter->widget(0));
LoadWidget(Splitter->widget(1));
}
else
{
LoadWidget(nullptr);
LoadWidget(nullptr);
}
}
};
2018-01-06 19:15:24 +01:00
LoadWidget(TabWidget ? TabWidget->layout()->itemAt(0)->widget() : nullptr);
2018-01-16 02:03:08 +01:00
if (ActiveWidget && TabWidget)
2020-12-16 19:28:43 +01:00
ActiveWidget->setFocus();
}
2021-02-28 20:32:12 +01:00
if (!mModelTabWidget->count())
lcGetActiveProject()->SetActiveModel(0);
else
lcGetActiveProject()->SetActiveModel(CurrentTabName);
}
2016-03-06 02:47:00 +01:00
void lcMainWindow::RemoveAllModelTabs()
{
2021-03-02 02:21:13 +01:00
while (mModelTabWidget->count())
delete mModelTabWidget->widget(0);
2016-03-06 02:47:00 +01:00
}
void lcMainWindow::CloseCurrentModelTab()
{
if (mModelTabWidget->count() > 1)
delete mModelTabWidget->currentWidget();
else
NewProject();
}
2016-03-06 02:47:00 +01:00
void lcMainWindow::SetCurrentModelTab(lcModel* Model)
{
for (int TabIdx = 0; TabIdx < mModelTabWidget->count(); TabIdx++)
{
lcModelTabWidget* TabWidget = (lcModelTabWidget*)mModelTabWidget->widget(TabIdx);
if (TabWidget->GetModel() == Model)
{
mModelTabWidget->setCurrentIndex(TabIdx);
return;
}
}
2021-02-28 20:32:12 +01:00
lcModelTabWidget* TabWidget = new lcModelTabWidget(Model);
mModelTabWidget->addTab(TabWidget, Model->GetProperties().mFileName);
2016-03-06 02:47:00 +01:00
2021-02-28 20:32:12 +01:00
QVBoxLayout* CentralLayout = new QVBoxLayout(TabWidget);
CentralLayout->setContentsMargins(0, 0, 0, 0);
2021-02-28 20:32:12 +01:00
lcView* NewView = CreateView(Model);
lcViewWidget* ViewWidget = new lcViewWidget(TabWidget, NewView);
CentralLayout->addWidget(ViewWidget);
2021-02-28 20:32:12 +01:00
mModelTabWidget->setCurrentWidget(TabWidget);
2016-03-06 02:47:00 +01:00
ViewWidget->show();
2016-03-06 02:47:00 +01:00
ViewWidget->setFocus();
NewView->ZoomExtents();
}
2020-12-25 19:54:33 +01:00
void lcMainWindow::AddView(lcView* View)
2014-05-03 23:16:48 +02:00
{
lcModelTabWidget* TabWidget = GetTabWidgetForModel(View->GetModel());
2016-03-06 02:47:00 +01:00
if (!TabWidget)
return;
if (!TabWidget->GetActiveView())
TabWidget->SetActiveView(View);
2014-05-03 23:16:48 +02:00
}
2020-12-25 19:54:33 +01:00
void lcMainWindow::RemoveView(lcView* View)
2014-05-03 23:16:48 +02:00
{
2016-03-06 02:47:00 +01:00
lcModelTabWidget* TabWidget = GetTabForView(View);
2014-05-03 23:16:48 +02:00
2016-03-06 02:47:00 +01:00
if (TabWidget)
TabWidget->RemoveView(View);
2014-05-03 23:16:48 +02:00
}
2020-12-25 19:54:33 +01:00
void lcMainWindow::SetActiveView(lcView* ActiveView)
2014-05-03 23:16:48 +02:00
{
2016-03-06 02:47:00 +01:00
lcModelTabWidget* TabWidget = GetTabForView(ActiveView);
2021-01-31 00:37:17 +01:00
if (!TabWidget)
return;
2020-12-25 19:54:33 +01:00
lcView* CurrentActiveView = TabWidget->GetActiveView();
2016-03-06 02:47:00 +01:00
2021-01-31 00:37:17 +01:00
if (CurrentActiveView == ActiveView)
2014-05-03 23:16:48 +02:00
return;
if (CurrentActiveView)
CurrentActiveView->SetTopSubmodelActive();
2016-03-06 02:47:00 +01:00
TabWidget->SetActiveView(ActiveView);
2014-05-03 23:16:48 +02:00
}
2014-05-23 02:02:21 +02:00
void lcMainWindow::SetTool(lcTool Tool)
{
mTool = Tool;
2020-12-05 00:38:49 +01:00
QAction* Action = mActions[LC_EDIT_ACTION_FIRST + static_cast<int>(mTool)];
2015-01-26 00:04:39 +01:00
if (Action)
Action->setChecked(true);
2020-12-25 19:54:33 +01:00
lcView::UpdateAllViews();
2014-05-23 02:02:21 +02:00
}
2013-08-09 06:57:18 +02:00
void lcMainWindow::SetColorIndex(int ColorIndex)
2014-05-03 23:16:48 +02:00
{
2013-08-09 06:57:18 +02:00
mColorIndex = ColorIndex;
2016-12-28 22:30:31 +01:00
if (mPartSelectionWidget)
mPartSelectionWidget->SetColorIndex(ColorIndex);
UpdateColor();
2011-09-07 23:06:51 +02:00
}
2015-04-25 00:11:50 +02:00
void lcMainWindow::SetMoveSnapEnabled(bool Enabled)
{
mMoveSnapEnabled = Enabled;
UpdateSnap();
}
void lcMainWindow::SetAngleSnapEnabled(bool Enabled)
{
mAngleSnapEnabled = Enabled;
UpdateSnap();
}
2014-10-05 07:21:51 +02:00
void lcMainWindow::SetMoveXYSnapIndex(int Index)
{
mMoveXYSnapIndex = Index;
UpdateSnap();
}
void lcMainWindow::SetMoveZSnapIndex(int Index)
{
mMoveZSnapIndex = Index;
UpdateSnap();
}
void lcMainWindow::SetAngleSnapIndex(int Index)
{
mAngleSnapIndex = Index;
UpdateSnap();
}
void lcMainWindow::SetRelativeTransform(bool RelativeTransform)
{
mRelativeTransform = RelativeTransform;
UpdateLockSnap();
2020-12-25 19:54:33 +01:00
lcView::UpdateAllViews();
}
void lcMainWindow::SetSeparateTransform(bool SelectionTransform)
{
mLocalTransform = SelectionTransform;
UpdateLockSnap();
}
2015-01-26 00:04:39 +01:00
void lcMainWindow::SetTransformType(lcTransformType TransformType)
{
2020-05-03 22:04:40 +02:00
if (TransformType < lcTransformType::First || TransformType >= lcTransformType::Count)
return;
2015-01-26 00:04:39 +01:00
mTransformType = TransformType;
constexpr const char* IconNames[] =
2015-01-26 00:04:39 +01:00
{
":/resources/edit_transform_absolute_translation.png",
":/resources/edit_transform_relative_translation.png",
":/resources/edit_transform_absolute_rotation.png",
":/resources/edit_transform_relative_rotation.png"
};
LC_ARRAY_SIZE_CHECK(IconNames, lcTransformType::Count);
2020-05-03 22:04:40 +02:00
int TransformIndex = static_cast<int>(TransformType);
mActions[LC_EDIT_TRANSFORM_ABSOLUTE_TRANSLATION + TransformIndex]->setChecked(true);
mActions[LC_EDIT_TRANSFORM]->setIcon(QIcon(IconNames[TransformIndex]));
2015-01-26 00:04:39 +01:00
}
void lcMainWindow::SetCurrentPieceInfo(PieceInfo* Info)
{
2017-01-23 04:28:05 +01:00
lcPiecesLibrary* Library = lcGetPiecesLibrary();
if (mCurrentPieceInfo)
2017-01-23 04:28:05 +01:00
Library->ReleasePieceInfo(mCurrentPieceInfo);
mCurrentPieceInfo = Info;
if (mCurrentPieceInfo)
2017-01-23 04:28:05 +01:00
Library->LoadPieceInfo(mCurrentPieceInfo, true, true);
}
2015-01-26 00:04:39 +01:00
lcVector3 lcMainWindow::GetTransformAmount()
{
lcVector3 Transform;
Transform.x = lcParseValueLocalized(mTransformXEdit->text());
Transform.y = lcParseValueLocalized(mTransformYEdit->text());
Transform.z = lcParseValueLocalized(mTransformZEdit->text());
2015-01-26 00:04:39 +01:00
return Transform;
}
void lcMainWindow::SplitView(Qt::Orientation Orientation)
{
QWidget* Focus = focusWidget();
2020-12-18 02:59:11 +01:00
if (Focus->metaObject() != &lcViewWidget::staticMetaObject)
2015-01-26 00:04:39 +01:00
return;
QWidget* Parent = Focus->parentWidget();
QSplitter* Splitter;
QList<int> Sizes;
2016-03-07 19:30:25 +01:00
if (Parent->metaObject() == &lcModelTabWidget::staticMetaObject)
2015-01-26 00:04:39 +01:00
{
Splitter = new QSplitter(Orientation, Parent);
Parent->layout()->addWidget(Splitter);
Splitter->addWidget(Focus);
2020-12-18 02:59:11 +01:00
Splitter->addWidget(new lcViewWidget(mModelTabWidget->currentWidget(), CreateView(GetCurrentTabModel())));
2015-01-26 00:04:39 +01:00
}
else
{
QSplitter* ParentSplitter = (QSplitter*)Parent;
2015-01-26 00:04:39 +01:00
Sizes = ParentSplitter->sizes();
int FocusIndex = ParentSplitter->indexOf(Focus);
Splitter = new QSplitter(Orientation, Parent);
ParentSplitter->insertWidget(FocusIndex, Splitter);
Splitter->addWidget(Focus);
2020-12-18 02:59:11 +01:00
Splitter->addWidget(new lcViewWidget(mModelTabWidget->currentWidget(), CreateView(GetCurrentTabModel())));
2015-01-26 00:04:39 +01:00
ParentSplitter->setSizes(Sizes);
}
Sizes.clear();
Sizes.append(10);
Sizes.append(10);
Splitter->setSizes(Sizes);
2017-03-26 19:28:58 +02:00
Focus->setFocus();
2015-01-26 00:04:39 +01:00
}
void lcMainWindow::SplitHorizontal()
{
SplitView(Qt::Vertical);
}
void lcMainWindow::SplitVertical()
{
SplitView(Qt::Horizontal);
}
void lcMainWindow::RemoveActiveView()
{
QWidget* Focus = focusWidget();
2020-12-18 02:59:11 +01:00
if (Focus->metaObject() != &lcViewWidget::staticMetaObject)
2015-01-26 00:04:39 +01:00
return;
QWidget* Parent = Focus->parentWidget();
2016-03-07 19:30:25 +01:00
if (Parent->metaObject() == &lcModelTabWidget::staticMetaObject)
2015-01-26 00:04:39 +01:00
return;
QWidget* ParentParentWidget = Parent->parentWidget();
QSplitter* ParentSplitter = (QSplitter*)Parent;
int FocusIndex = ParentSplitter->indexOf(Focus);
2017-03-26 19:28:58 +02:00
QWidget* OtherWidget = ParentSplitter->widget(!FocusIndex);
2015-01-26 00:04:39 +01:00
2016-03-07 19:30:25 +01:00
if (ParentParentWidget->metaObject() == &lcModelTabWidget::staticMetaObject)
2015-01-26 00:04:39 +01:00
{
QLayout* CentralLayout = ParentParentWidget->layout();
2017-03-26 19:28:58 +02:00
CentralLayout->addWidget(OtherWidget);
2015-01-26 00:04:39 +01:00
CentralLayout->removeWidget(Parent);
2017-03-26 19:28:58 +02:00
}
else
{
QSplitter* ParentParentSplitter = (QSplitter*)ParentParentWidget;
QList<int> Sizes = ParentParentSplitter->sizes();
2015-01-26 00:04:39 +01:00
2017-03-26 19:28:58 +02:00
int ParentIndex = ParentParentSplitter->indexOf(Parent);
Parent->setParent(nullptr);
2017-03-26 19:28:58 +02:00
ParentParentSplitter->insertWidget(ParentIndex, OtherWidget);
ParentParentSplitter->setSizes(Sizes);
2015-01-26 00:04:39 +01:00
}
2017-03-26 19:28:58 +02:00
Parent->deleteLater();
2015-01-26 00:04:39 +01:00
2020-12-18 02:59:11 +01:00
if (OtherWidget->metaObject() != &lcViewWidget::staticMetaObject)
2017-03-26 19:28:58 +02:00
{
lcModelTabWidget* TabWidget = (lcModelTabWidget*)mModelTabWidget->currentWidget();
2015-01-26 00:04:39 +01:00
2017-03-26 19:28:58 +02:00
if (TabWidget)
OtherWidget = TabWidget->GetAnyViewWidget();
}
2015-01-26 00:04:39 +01:00
2017-03-26 19:28:58 +02:00
OtherWidget->setFocus();
2015-01-26 00:04:39 +01:00
}
void lcMainWindow::ResetViews()
{
2017-03-26 19:28:58 +02:00
lcModelTabWidget* TabWidget = (lcModelTabWidget*)mModelTabWidget->currentWidget();
2016-03-07 19:30:25 +01:00
if (!TabWidget)
return;
2021-02-28 20:32:12 +01:00
QLayout* TabLayout = TabWidget->layout();
QWidget* TopWidget = TabLayout->itemAt(0)->widget();
TopWidget->deleteLater();
lcView* NewView = CreateView(TabWidget->GetModel());
lcViewWidget* ViewWidget = new lcViewWidget(TabWidget, NewView);
TabLayout->addWidget(ViewWidget);
ViewWidget->show();
ViewWidget->setFocus();
NewView->ZoomExtents();
2015-01-26 00:04:39 +01:00
}
void lcMainWindow::ToggleDockWidget(QWidget* DockWidget)
{
if (DockWidget->isHidden())
DockWidget->show();
else
DockWidget->hide();
}
2015-01-26 00:04:39 +01:00
void lcMainWindow::TogglePrintPreview()
{
2017-02-11 21:41:00 +01:00
#ifndef QT_NO_PRINTER
2015-01-26 00:04:39 +01:00
// todo: print preview inside main window
2021-01-15 03:19:58 +01:00
int PageCount = static_cast<int>(lcGetActiveProject()->GetInstructions()->mPages.size());
2015-01-26 00:04:39 +01:00
QPrinter Printer(QPrinter::ScreenResolution);
Printer.setFromTo(1, PageCount + 1);
QPrintPreviewDialog Preview(&Printer, this);
connect(&Preview, SIGNAL(paintRequested(QPrinter*)), SLOT(Print(QPrinter*)));
Preview.exec();
2017-02-11 21:41:00 +01:00
#endif
2015-01-26 00:04:39 +01:00
}
void lcMainWindow::ToggleFullScreen()
{
// todo: hide toolbars and menu
// todo: create fullscreen toolbar or support esc key to go back
if (isFullScreen())
showNormal();
else
showFullScreen();
}
2014-10-12 19:34:18 +02:00
void lcMainWindow::AddRecentFile(const QString& FileName)
2011-09-07 23:06:51 +02:00
{
2014-10-12 19:34:18 +02:00
QString SavedName = FileName;
2013-08-09 06:57:18 +02:00
int FileIdx;
2011-09-07 23:06:51 +02:00
QFileInfo FileInfo(FileName);
2013-08-09 06:57:18 +02:00
for (FileIdx = 0; FileIdx < LC_MAX_RECENT_FILES; FileIdx++)
if (QFileInfo(mRecentFiles[FileIdx]) == FileInfo)
2011-09-07 23:06:51 +02:00
break;
2013-08-09 06:57:18 +02:00
for (FileIdx = lcMin(FileIdx, LC_MAX_RECENT_FILES - 1); FileIdx > 0; FileIdx--)
2014-10-12 19:34:18 +02:00
mRecentFiles[FileIdx] = mRecentFiles[FileIdx - 1];
2011-09-07 23:06:51 +02:00
2014-10-12 19:34:18 +02:00
mRecentFiles[0] = SavedName;
2011-09-07 23:06:51 +02:00
2013-08-09 06:57:18 +02:00
UpdateRecentFiles();
2011-09-07 23:06:51 +02:00
}
2013-08-09 06:57:18 +02:00
void lcMainWindow::RemoveRecentFile(int FileIndex)
2011-09-07 23:06:51 +02:00
{
2013-08-09 06:57:18 +02:00
for (int FileIdx = FileIndex; FileIdx < LC_MAX_RECENT_FILES - 1; FileIdx++)
2014-10-12 19:34:18 +02:00
mRecentFiles[FileIdx] = mRecentFiles[FileIdx + 1];
2011-09-07 23:06:51 +02:00
2014-10-12 19:34:18 +02:00
mRecentFiles[LC_MAX_RECENT_FILES - 1].clear();
2013-08-09 06:57:18 +02:00
UpdateRecentFiles();
2011-09-07 23:06:51 +02:00
}
2013-08-09 06:57:18 +02:00
void lcMainWindow::UpdateSelectedObjects(bool SelectionChanged)
2015-01-26 00:04:39 +01:00
{
int Flags = 0;
2024-05-15 05:45:09 +02:00
std::vector<lcObject*> Selection;
lcObject* Focus = nullptr;
2015-01-26 00:04:39 +01:00
lcModel* ActiveModel = GetActiveModel();
if (ActiveModel)
ActiveModel->GetSelectionInformation(&Flags, Selection, &Focus);
2015-01-26 00:04:39 +01:00
if (SelectionChanged)
{
mTimelineWidget->UpdateSelection();
mActions[LC_EDIT_CUT]->setEnabled(Flags & LC_SEL_SELECTED);
mActions[LC_EDIT_COPY]->setEnabled(Flags & LC_SEL_SELECTED);
mActions[LC_EDIT_FIND]->setEnabled((Flags & LC_SEL_NO_PIECES) == 0);
mActions[LC_EDIT_FIND_NEXT]->setEnabled((Flags & LC_SEL_NO_PIECES) == 0);
mActions[LC_EDIT_FIND_PREVIOUS]->setEnabled((Flags & LC_SEL_NO_PIECES) == 0);
2021-01-31 21:23:28 +01:00
mActions[LC_EDIT_FIND_ALL]->setEnabled((Flags & LC_SEL_NO_PIECES) == 0);
2021-01-31 03:03:35 +01:00
mActions[LC_EDIT_REPLACE]->setEnabled((Flags & LC_SEL_NO_PIECES) == 0);
mActions[LC_EDIT_REPLACE_NEXT]->setEnabled((Flags & LC_SEL_NO_PIECES) == 0);
2021-01-31 21:23:28 +01:00
mActions[LC_EDIT_REPLACE_ALL]->setEnabled((Flags & LC_SEL_NO_PIECES) == 0);
mActions[LC_EDIT_SELECT_INVERT]->setEnabled((Flags & LC_SEL_NO_PIECES) == 0);
mActions[LC_EDIT_SELECT_BY_NAME]->setEnabled((Flags & LC_SEL_NO_PIECES) == 0);
mActions[LC_EDIT_SELECT_NONE]->setEnabled(Flags & LC_SEL_SELECTED);
mActions[LC_EDIT_SELECT_ALL]->setEnabled(Flags & LC_SEL_UNSELECTED);
mActions[LC_PIECE_DELETE]->setEnabled(Flags & LC_SEL_SELECTED);
2017-03-09 00:55:38 +01:00
mActions[LC_PIECE_DUPLICATE]->setEnabled(Flags & LC_SEL_SELECTED);
mActions[LC_PIECE_PAINT_SELECTED]->setEnabled(Flags & LC_SEL_PIECE);
mActions[LC_PIECE_RESET_PIVOT_POINT]->setEnabled(Flags & LC_SEL_SELECTED);
mActions[LC_PIECE_REMOVE_KEY_FRAMES]->setEnabled(Flags & LC_SEL_SELECTED);
mActions[LC_PIECE_ARRAY]->setEnabled(Flags & LC_SEL_PIECE);
mActions[LC_PIECE_CONTROL_POINT_INSERT]->setEnabled(Flags & LC_SEL_CAN_ADD_CONTROL_POINT);
mActions[LC_PIECE_CONTROL_POINT_REMOVE]->setEnabled(Flags & LC_SEL_CAN_REMOVE_CONTROL_POINT);
mActions[LC_PIECE_HIDE_SELECTED]->setEnabled(Flags & LC_SEL_VISIBLE_SELECTED);
mActions[LC_PIECE_HIDE_UNSELECTED]->setEnabled(Flags & LC_SEL_UNSELECTED);
mActions[LC_PIECE_UNHIDE_SELECTED]->setEnabled(Flags & LC_SEL_HIDDEN_SELECTED);
mActions[LC_PIECE_UNHIDE_ALL]->setEnabled(Flags & LC_SEL_HIDDEN);
mActions[LC_PIECE_VIEW_SELECTED_MODEL]->setEnabled(Flags & LC_SEL_MODEL_SELECTED);
mActions[LC_PIECE_MOVE_SELECTION_TO_MODEL]->setEnabled(Flags & LC_SEL_PIECE);
mActions[LC_PIECE_INLINE_SELECTED_MODELS]->setEnabled(Flags & LC_SEL_MODEL_SELECTED);
mActions[LC_PIECE_EDIT_SELECTED_SUBMODEL]->setEnabled(Flags & LC_SEL_MODEL_SELECTED);
mActions[LC_PIECE_GROUP]->setEnabled(Flags & LC_SEL_CAN_GROUP);
mActions[LC_PIECE_UNGROUP]->setEnabled(Flags & LC_SEL_GROUPED);
mActions[LC_PIECE_GROUP_ADD]->setEnabled((Flags & (LC_SEL_GROUPED | LC_SEL_FOCUS_GROUPED)) == LC_SEL_GROUPED);
mActions[LC_PIECE_GROUP_REMOVE]->setEnabled(Flags & LC_SEL_FOCUS_GROUPED);
mActions[LC_PIECE_GROUP_EDIT]->setEnabled((Flags & LC_SEL_NO_PIECES) == 0);
mActions[LC_PIECE_SHOW_EARLIER]->setEnabled(Flags & LC_SEL_PIECE); // FIXME: disable if current step is 1
mActions[LC_PIECE_SHOW_LATER]->setEnabled(Flags & LC_SEL_PIECE);
mActions[LC_TIMELINE_MOVE_SELECTION]->setEnabled(Flags & LC_SEL_PIECE);
mActions[LC_TIMELINE_MOVE_SELECTION_BEFORE]->setEnabled(Flags & LC_SEL_PIECE);
mActions[LC_TIMELINE_MOVE_SELECTION_AFTER]->setEnabled(Flags & LC_SEL_PIECE);
2018-10-14 17:47:28 +02:00
mActions[LC_PIECE_EDIT_END_SUBMODEL]->setEnabled(GetCurrentTabModel() != ActiveModel);
}
2015-01-26 00:04:39 +01:00
mPropertiesWidget->Update(Selection, Focus);
2015-01-26 00:04:39 +01:00
if (Focus && Focus->IsPiece())
{
lcPiece* Piece = (lcPiece*)Focus;
int ColorIndex = Piece->GetColorIndex();
quint32 ColorCode = lcGetColorCode(ColorIndex);
PreviewPiece(Piece->mPieceInfo->mFileName, ColorCode, false);
}
2015-01-26 00:04:39 +01:00
QString Message;
2024-05-15 05:45:09 +02:00
if ((Selection.size() == 1) && Focus)
2015-01-26 00:04:39 +01:00
{
if (Focus->IsPiece())
2017-07-23 05:54:33 +02:00
Message = tr("%1 (ID: %2)").arg(Focus->GetName(), ((lcPiece*)Focus)->GetID());
2015-01-26 00:04:39 +01:00
else
Message = Focus->GetName();
}
2024-05-15 05:45:09 +02:00
else if (Selection.size() > 0)
2015-01-26 00:04:39 +01:00
{
2024-05-15 05:45:09 +02:00
Message = tr("%n Object(s) selected", "", static_cast<int>(Selection.size()));
2015-01-26 00:04:39 +01:00
if (Focus && Focus->IsPiece())
{
2017-07-23 05:54:33 +02:00
Message.append(tr(" - %1 (ID: %2)").arg(Focus->GetName(), ((lcPiece*)Focus)->GetID()));
2015-01-26 00:04:39 +01:00
const lcGroup* Group = ((lcPiece*)Focus)->GetGroup();
2015-10-21 17:03:45 +02:00
if (Group && !Group->mName.isEmpty())
Message.append(tr(" in group '%1'").arg(Group->mName));
2015-01-26 00:04:39 +01:00
}
}
mStatusBarLabel->setText(Message);
lcVector3 Position;
lcGetActiveModel()->GetFocusPosition(Position);
QString Label("X: %1 Y: %2 Z: %3");
Label = Label.arg(QLocale::system().toString(Position[0], 'f', 2), QLocale::system().toString(Position[1], 'f', 2), QLocale::system().toString(Position[2], 'f', 2));
mStatusPositionLabel->setText(Label);
2015-01-26 00:04:39 +01:00
}
void lcMainWindow::UpdateTimeline(bool Clear, bool UpdateItems)
{
mTimelineWidget->Update(Clear, UpdateItems);
}
2015-01-26 00:04:39 +01:00
void lcMainWindow::UpdatePaste(bool Enabled)
{
if (mActions[LC_EDIT_PASTE])
mActions[LC_EDIT_PASTE]->setEnabled(Enabled);
2015-01-26 00:04:39 +01:00
if (mActions[LC_EDIT_PASTE_STEPS])
mActions[LC_EDIT_PASTE_STEPS]->setEnabled(Enabled);
2015-01-26 00:04:39 +01:00
}
void lcMainWindow::UpdateCurrentStep()
{
lcModel* Model = lcGetActiveModel();
lcStep CurrentStep = Model->GetCurrentStep();
lcStep LastStep = Model->GetLastStep();
mActions[LC_VIEW_TIME_FIRST]->setEnabled(CurrentStep != 1);
mActions[LC_VIEW_TIME_PREVIOUS]->setEnabled(CurrentStep > 1);
mActions[LC_VIEW_TIME_NEXT]->setEnabled(CurrentStep < LC_STEP_MAX);
mActions[LC_VIEW_TIME_LAST]->setEnabled(CurrentStep != LastStep);
mStatusTimeLabel->setText(QString(tr("Step %1")).arg(QString::number(CurrentStep)));
}
void lcMainWindow::SetAddKeys(bool AddKeys)
{
QAction* Action = mActions[LC_VIEW_TIME_ADD_KEYS];
if (Action)
Action->setChecked(AddKeys);
mAddKeys = AddKeys;
}
void lcMainWindow::UpdateLockSnap()
{
if (GetRelativeTransform())
mActions[LC_EDIT_TRANSFORM_RELATIVE]->setChecked(true);
else
mActions[LC_EDIT_TRANSFORM_ABSOLUTE]->setChecked(true);
if (GetSeparateTransform())
mActions[LC_EDIT_TRANSFORM_SEPARATELY]->setChecked(true);
else
mActions[LC_EDIT_TRANSFORM_TOGETHER]->setChecked(true);
UpdateSnap();
2015-01-26 00:04:39 +01:00
}
void lcMainWindow::UpdateSnap()
{
2015-04-25 00:11:50 +02:00
mActions[LC_EDIT_SNAP_MOVE_TOGGLE]->setChecked(mMoveSnapEnabled);
mActions[LC_EDIT_SNAP_ANGLE_TOGGLE]->setChecked(mAngleSnapEnabled);
mActions[LC_EDIT_SNAP_MOVE_XY0 + mMoveXYSnapIndex]->setChecked(true);
mActions[LC_EDIT_SNAP_MOVE_Z0 + mMoveZSnapIndex]->setChecked(true);
mActions[LC_EDIT_SNAP_ANGLE0 + mAngleSnapIndex]->setChecked(true);
2015-01-26 00:04:39 +01:00
2021-01-30 00:23:22 +01:00
QString Relative = mRelativeTransform ? tr("Rel") : tr("Abs");
mStatusSnapLabel->setText(QString(tr(" M: %1 %2 R: %3 %4 ")).arg(GetMoveXYSnapText(), GetMoveZSnapText(), GetAngleSnapText(), Relative));
2015-01-26 00:04:39 +01:00
}
void lcMainWindow::UpdateColor()
{
2020-12-30 19:48:51 +01:00
QPixmap Pixmap(14, 14);
Pixmap.fill(QColor::fromRgbF(gColorList[mColorIndex].Value[0], gColorList[mColorIndex].Value[1], gColorList[mColorIndex].Value[2]));
mColorButton->setIcon(Pixmap);
mColorButton->setText(QString(" ") + gColorList[mColorIndex].Name);
2023-04-30 04:48:30 +02:00
mColorList->SetCurrentColor(mColorIndex);
2015-01-26 00:04:39 +01:00
}
void lcMainWindow::UpdateUndoRedo(const QString& UndoText, const QString& RedoText)
{
QAction* UndoAction = mActions[LC_EDIT_UNDO];
QAction* RedoAction = mActions[LC_EDIT_REDO];
if (!UndoText.isEmpty())
{
UndoAction->setEnabled(true);
UndoAction->setText(QString(tr("&Undo %1")).arg(UndoText));
}
else
{
UndoAction->setEnabled(false);
UndoAction->setText(tr("&Undo"));
}
if (!RedoText.isEmpty())
{
RedoAction->setEnabled(true);
RedoAction->setText(QString(tr("&Redo %1")).arg(RedoText));
}
else
{
RedoAction->setEnabled(false);
RedoAction->setText(tr("&Redo"));
}
}
2020-12-16 03:27:54 +01:00
void lcMainWindow::ViewFocusReceived()
{
SetActiveView(qobject_cast<lcView*>(sender()));
2020-12-16 03:27:54 +01:00
}
2024-02-20 02:51:34 +01:00
void lcMainWindow::CameraMenuAboutToShow()
2015-01-26 00:04:39 +01:00
{
2024-06-04 18:34:38 +02:00
const std::vector<std::unique_ptr<lcCamera>>& Cameras = lcGetActiveModel()->GetCameras();
2020-12-25 19:54:33 +01:00
lcView* ActiveView = GetActiveView();
2020-12-04 21:49:01 +01:00
const lcCamera* CurrentCamera = ActiveView ? ActiveView->GetCamera() : nullptr;
2020-12-15 19:20:14 +01:00
bool CurrentSet = false;
2015-01-26 00:04:39 +01:00
2024-06-04 18:34:38 +02:00
for (size_t ActionIndex = LC_VIEW_CAMERA_FIRST; ActionIndex <= LC_VIEW_CAMERA_LAST; ActionIndex++)
2015-01-26 00:04:39 +01:00
{
2024-06-04 18:34:38 +02:00
QAction* Action = mActions[ActionIndex];
size_t CameraIndex = ActionIndex - LC_VIEW_CAMERA_FIRST;
2015-01-26 00:04:39 +01:00
2024-06-04 18:34:38 +02:00
if (CameraIndex < Cameras.size())
2015-01-26 00:04:39 +01:00
{
2024-06-04 18:34:38 +02:00
if (CurrentCamera == Cameras[CameraIndex].get())
2020-12-15 19:20:14 +01:00
{
Action->setChecked(true);
CurrentSet = true;
}
2015-01-26 00:04:39 +01:00
2024-06-04 18:34:38 +02:00
Action->setText(Cameras[CameraIndex]->GetName());
2015-01-26 00:04:39 +01:00
Action->setVisible(true);
}
else
Action->setVisible(false);
}
2020-12-15 19:20:14 +01:00
if (!CurrentSet)
mActions[LC_VIEW_CAMERA_NONE]->setChecked(true);
2015-01-26 00:04:39 +01:00
}
2024-02-20 02:51:34 +01:00
void lcMainWindow::ProjectionMenuAboutToShow()
2015-01-26 00:04:39 +01:00
{
2020-12-25 19:54:33 +01:00
lcView* ActiveView = GetActiveView();
2016-03-06 02:47:00 +01:00
if (ActiveView)
{
2020-12-04 21:49:01 +01:00
if (ActiveView->GetCamera()->IsOrtho())
2016-03-06 02:47:00 +01:00
mActions[LC_VIEW_PROJECTION_ORTHO]->setChecked(true);
else
mActions[LC_VIEW_PROJECTION_PERSPECTIVE]->setChecked(true);
}
2015-01-26 00:04:39 +01:00
}
2017-08-25 21:57:14 +02:00
void lcMainWindow::UpdateShadingMode()
{
2020-03-22 21:44:20 +01:00
mActions[LC_VIEW_SHADING_FIRST + static_cast<int>(lcGetPreferences().mShadingMode)]->setChecked(true);
2017-08-25 21:57:14 +02:00
}
2017-11-22 02:58:36 +01:00
void lcMainWindow::UpdateSelectionMode()
{
switch (mSelectionMode)
{
2020-05-03 22:04:40 +02:00
case lcSelectionMode::Single:
2017-11-22 02:58:36 +01:00
mActions[LC_EDIT_SELECTION_SINGLE]->setChecked(true);
break;
2020-05-03 22:04:40 +02:00
case lcSelectionMode::Piece:
2017-11-22 02:58:36 +01:00
mActions[LC_EDIT_SELECTION_PIECE]->setChecked(true);
break;
2020-05-03 22:04:40 +02:00
case lcSelectionMode::Color:
2017-11-22 02:58:36 +01:00
mActions[LC_EDIT_SELECTION_COLOR]->setChecked(true);
break;
2020-05-03 22:04:40 +02:00
case lcSelectionMode::PieceColor:
2017-11-22 02:58:36 +01:00
mActions[LC_EDIT_SELECTION_PIECE_COLOR]->setChecked(true);
break;
}
}
2015-01-26 00:04:39 +01:00
void lcMainWindow::UpdateModels()
{
2024-06-17 02:43:02 +02:00
const std::vector<std::unique_ptr<lcModel>>& Models = lcGetActiveProject()->GetModels();
2015-01-26 00:04:39 +01:00
lcModel* CurrentModel = lcGetActiveModel();
2024-06-17 02:43:02 +02:00
for (size_t ActionIndex = LC_MODEL_FIRST; ActionIndex <= LC_MODEL_LAST; ActionIndex++)
2015-01-26 00:04:39 +01:00
{
2024-06-17 02:43:02 +02:00
QAction* Action = mActions[ActionIndex];
size_t ModelIndex = ActionIndex - LC_MODEL_FIRST;
2015-01-26 00:04:39 +01:00
2024-06-17 02:43:02 +02:00
if (ModelIndex < Models.size())
2015-01-26 00:04:39 +01:00
{
2024-06-17 02:43:02 +02:00
Action->setChecked(CurrentModel == Models[ModelIndex].get());
Action->setText(QString::fromLatin1("%1%2 %3").arg(ModelIndex < 9 ? QString("&") : QString(), QString::number(ModelIndex + 1), Models[ModelIndex]->GetProperties().mFileName));
2015-01-26 00:04:39 +01:00
Action->setVisible(true);
}
else
Action->setVisible(false);
}
2024-06-17 02:43:02 +02:00
auto HasModel = [&Models](lcModel* Model)
{
return std::find_if(Models.begin(), Models.end(), [Model](const std::unique_ptr<lcModel>& CheckModel) { return CheckModel.get() == Model; }) != Models.end();
};
2016-03-06 02:47:00 +01:00
for (int TabIdx = 0; TabIdx < mModelTabWidget->count(); )
{
lcModelTabWidget* TabWidget = (lcModelTabWidget*)mModelTabWidget->widget(TabIdx);
lcModel* Model = TabWidget->GetModel();
if (!Model)
TabIdx++;
2024-06-17 02:43:02 +02:00
else if (HasModel(Model))
2016-03-06 02:47:00 +01:00
{
2020-05-03 21:11:51 +02:00
mModelTabWidget->setTabText(TabIdx, Model->GetProperties().mFileName);
2016-03-06 02:47:00 +01:00
TabIdx++;
}
else
delete TabWidget;
}
2016-12-19 03:53:25 +01:00
mPartSelectionWidget->UpdateModels();
2016-12-28 22:30:31 +01:00
if (mCurrentPieceInfo && mCurrentPieceInfo->IsModel())
2024-06-17 02:43:02 +02:00
if (!HasModel(mCurrentPieceInfo->GetModel()))
SetCurrentPieceInfo(nullptr);
2015-01-26 00:04:39 +01:00
}
void lcMainWindow::UpdateCategories()
{
2016-12-20 23:11:19 +01:00
mPartSelectionWidget->UpdateCategories();
2015-01-26 00:04:39 +01:00
}
void lcMainWindow::UpdateTitle()
{
setWindowModified(lcGetActiveProject()->IsModified());
setWindowFilePath(lcGetActiveProject()->GetTitle());
}
void lcMainWindow::UpdateModified(bool Modified)
{
setWindowModified(Modified);
}
void lcMainWindow::UpdateRecentFiles()
{
for (int ActionIdx = LC_FILE_RECENT_FIRST; ActionIdx <= LC_FILE_RECENT_LAST; ActionIdx++)
{
int FileIdx = ActionIdx - LC_FILE_RECENT_FIRST;
QAction* Action = mActions[ActionIdx];
if (!mRecentFiles[FileIdx].isEmpty())
{
Action->setText(QString("&%1 %2").arg(QString::number(FileIdx + 1), QDir::toNativeSeparators(mRecentFiles[FileIdx])));
Action->setVisible(true);
}
else
Action->setVisible(false);
}
mActionFileRecentSeparator->setVisible(!mRecentFiles[0].isEmpty());
}
void lcMainWindow::UpdateShortcuts()
{
for (int ActionIdx = 0; ActionIdx < LC_NUM_COMMANDS; ActionIdx++)
2015-09-27 09:02:57 +02:00
mActions[ActionIdx]->setShortcut(QKeySequence(gKeyboardShortcuts.mShortcuts[ActionIdx]));
2015-01-26 00:04:39 +01:00
}
2014-12-04 02:47:28 +01:00
void lcMainWindow::NewProject()
{
if (!SaveProjectIfModified())
return;
Project* NewProject = new Project();
gApplication->SetProject(NewProject);
lcGetPiecesLibrary()->UnloadUnusedParts();
2014-12-04 02:47:28 +01:00
}
bool lcMainWindow::OpenProject(const QString& FileName)
{
if (!SaveProjectIfModified())
return false;
QString LoadFileName = FileName;
if (LoadFileName.isEmpty())
{
LoadFileName = lcGetActiveProject()->GetFileName();
if (LoadFileName.isEmpty())
LoadFileName = lcGetProfileString(LC_PROFILE_PROJECTS_PATH);
LoadFileName = QFileDialog::getOpenFileName(this, tr("Open Model"), LoadFileName, tr("Supported Files (*.lcd *.ldr *.dat *.mpd);;All Files (*.*)"));
2014-12-04 02:47:28 +01:00
if (LoadFileName.isEmpty())
return false;
lcSetProfileString(LC_PROFILE_PROJECTS_PATH, QFileInfo(LoadFileName).absolutePath());
2014-12-04 02:47:28 +01:00
}
return OpenProjectFile(LoadFileName);
}
void lcMainWindow::OpenRecentProject(int RecentFileIndex)
{
if (!SaveProjectIfModified())
return;
if (!OpenProjectFile(mRecentFiles[RecentFileIndex]))
RemoveRecentFile(RecentFileIndex);
}
bool lcMainWindow::OpenProjectFile(const QString& FileName)
{
2014-12-04 02:47:28 +01:00
Project* NewProject = new Project();
if (NewProject->Load(FileName, true))
2014-12-04 02:47:28 +01:00
{
gApplication->SetProject(NewProject);
AddRecentFile(FileName);
2020-12-25 19:54:33 +01:00
lcView::UpdateProjectViews(NewProject);
2014-12-31 00:45:27 +01:00
2014-12-04 02:47:28 +01:00
return true;
}
delete NewProject;
return false;
}
2014-12-16 00:55:17 +01:00
void lcMainWindow::MergeProject()
{
2014-12-23 18:02:23 +01:00
QString LoadFileName = lcGetActiveProject()->GetFileName();
2014-12-16 00:55:17 +01:00
if (LoadFileName.isEmpty())
2014-12-23 18:02:23 +01:00
LoadFileName = lcGetProfileString(LC_PROFILE_PROJECTS_PATH);
2014-12-16 00:55:17 +01:00
LoadFileName = QFileDialog::getOpenFileName(this, tr("Merge Model"), LoadFileName, tr("Supported Files (*.lcd *.ldr *.dat *.mpd);;All Files (*.*)"));
2014-12-16 00:55:17 +01:00
2014-12-23 18:02:23 +01:00
if (LoadFileName.isEmpty())
return;
2014-12-16 00:55:17 +01:00
lcSetProfileString(LC_PROFILE_PROJECTS_PATH, QFileInfo(LoadFileName).absolutePath());
2014-12-16 00:55:17 +01:00
Project* NewProject = new Project();
if (NewProject->Load(LoadFileName, true))
2014-12-16 00:55:17 +01:00
{
2024-06-17 02:43:02 +02:00
size_t ModelCount = NewProject->GetModels().size();
2014-12-16 00:55:17 +01:00
2014-12-23 18:02:23 +01:00
lcGetActiveProject()->Merge(NewProject);
2014-12-16 00:55:17 +01:00
2024-06-17 02:43:02 +02:00
if (ModelCount == 1)
QMessageBox::information(this, tr("LeoCAD"), tr("Merged 1 submodel."));
2014-12-23 18:02:23 +01:00
else
2024-06-17 02:43:02 +02:00
QMessageBox::information(this, tr("LeoCAD"), tr("Merged %1 submodels.").arg(ModelCount));
UpdateModels();
2014-12-23 18:02:23 +01:00
}
delete NewProject;
2014-12-16 00:55:17 +01:00
}
2017-06-26 03:20:34 +02:00
void lcMainWindow::ImportLDD()
{
if (!SaveProjectIfModified())
return;
QString LoadFileName = QFileDialog::getOpenFileName(this, tr("Import"), QString(), tr("LEGO Diginal Designer Files (*.lxf);;All Files (*.*)"));
if (LoadFileName.isEmpty())
return;
Project* NewProject = new Project();
if (NewProject->ImportLDD(LoadFileName))
{
gApplication->SetProject(NewProject);
2020-12-25 19:54:33 +01:00
lcView::UpdateProjectViews(NewProject);
2017-06-26 03:20:34 +02:00
}
else
delete NewProject;
}
2017-08-20 22:47:53 +02:00
void lcMainWindow::ImportInventory()
{
if (!SaveProjectIfModified())
return;
lcSetsDatabaseDialog Dialog(this);
if (Dialog.exec() != QDialog::Accepted)
return;
Project* NewProject = new Project();
if (NewProject->ImportInventory(Dialog.GetSetInventory(), Dialog.GetSetName(), Dialog.GetSetDescription()))
{
gApplication->SetProject(NewProject);
2020-12-25 19:54:33 +01:00
lcView::UpdateProjectViews(NewProject);
2017-08-20 22:47:53 +02:00
}
else
delete NewProject;
}
2014-12-04 02:47:28 +01:00
bool lcMainWindow::SaveProject(const QString& FileName)
{
QString SaveFileName = FileName;
2014-12-04 02:47:28 +01:00
Project* Project = lcGetActiveProject();
if (SaveFileName.isEmpty())
2014-12-04 02:47:28 +01:00
{
SaveFileName = Project->GetFileName();
2014-12-04 02:47:28 +01:00
if (SaveFileName.isEmpty())
SaveFileName = QFileInfo(QDir(lcGetProfileString(LC_PROFILE_PROJECTS_PATH)), Project->GetTitle()).absoluteFilePath();
2024-05-26 22:01:34 +02:00
QString Filter = (Project->GetModels().size() > 1) ? tr("Supported Files (*.mpd);;All Files (*.*)") : tr("Supported Files (*.ldr *.dat *.mpd);;All Files (*.*)");
2015-02-08 04:29:42 +01:00
SaveFileName = QFileDialog::getSaveFileName(this, tr("Save Model"), SaveFileName, Filter);
2014-12-04 02:47:28 +01:00
if (SaveFileName.isEmpty())
return false;
lcSetProfileString(LC_PROFILE_PROJECTS_PATH, QFileInfo(SaveFileName).absolutePath());
2014-12-04 02:47:28 +01:00
}
if (QFileInfo(SaveFileName).suffix().toLower() == QLatin1String("lcd"))
{
2015-02-08 04:29:42 +01:00
QMessageBox::warning(this, tr("Error"), tr("Saving files in LCD format is no longer supported, please use the LDR or MPD formats instead."));
2014-12-04 02:47:28 +01:00
return false;
}
if (!Project->Save(SaveFileName))
2014-12-04 02:47:28 +01:00
return false;
AddRecentFile(SaveFileName);
UpdateTitle();
2014-12-04 02:47:28 +01:00
return true;
}
bool lcMainWindow::SaveProjectIfModified()
{
Project* Project = lcGetActiveProject();
if (!Project->IsModified())
return true;
switch (QMessageBox::question(this, tr("Save Model"), tr("Save changes to '%1'?").arg(Project->GetTitle()), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel))
2014-12-04 02:47:28 +01:00
{
default:
case QMessageBox::Cancel:
return false;
case QMessageBox::Yes:
if (!SaveProject(Project->GetFileName()))
return false;
break;
case QMessageBox::No:
break;
}
return true;
}
bool lcMainWindow::SetModelFromFocus()
{
lcObject* FocusObject = GetActiveModel()->GetFocusObject();
if (!FocusObject || !FocusObject->IsPiece())
return false;
lcModel* Model = ((lcPiece*)FocusObject)->mPieceInfo->GetModel();
if (Model)
{
Project* Project = lcGetActiveProject();
2024-06-17 02:43:02 +02:00
Project->SetActiveModel(Model);
return true;
}
return false;
}
void lcMainWindow::SetModelFromSelection()
{
if (SetModelFromFocus())
return;
lcModel* Model = GetActiveModel()->GetFirstSelectedSubmodel();
if (Model)
{
Project* Project = lcGetActiveProject();
2024-06-17 02:43:02 +02:00
Project->SetActiveModel(Model);
}
}
lcModel* lcMainWindow::GetActiveModel() const
{
2020-12-25 19:54:33 +01:00
lcView* ActiveView = GetActiveView();
return ActiveView ? ActiveView->GetActiveModel() : nullptr;
}
2021-02-27 20:32:52 +01:00
lcModelTabWidget* lcMainWindow::GetTabForView(lcView* View) const
{
QWidget* Widget = View->GetWidget();
while (Widget)
{
lcModelTabWidget* TabWidget = qobject_cast<lcModelTabWidget*>(Widget);
if (TabWidget)
return TabWidget;
else
Widget = Widget->parentWidget();
}
return nullptr;
}
2014-12-04 02:47:28 +01:00
void lcMainWindow::HandleCommand(lcCommandId CommandId)
{
2020-12-25 19:54:33 +01:00
lcView* ActiveView = GetActiveView();
lcModel* ActiveModel = ActiveView ? ActiveView->GetActiveModel() : nullptr;
2016-03-06 02:47:00 +01:00
2014-12-04 02:47:28 +01:00
switch (CommandId)
{
case LC_FILE_NEW:
NewProject();
break;
case LC_FILE_OPEN:
OpenProject(QString());
break;
2014-12-16 00:55:17 +01:00
case LC_FILE_MERGE:
MergeProject();
break;
2014-12-04 02:47:28 +01:00
case LC_FILE_SAVE:
SaveProject(lcGetActiveProject()->GetFileName());
break;
case LC_FILE_SAVEAS:
SaveProject(QString());
break;
case LC_FILE_SAVE_IMAGE:
lcGetActiveProject()->SaveImage();
break;
2014-12-30 17:30:12 +01:00
2017-06-26 03:20:34 +02:00
case LC_FILE_IMPORT_LDD:
ImportLDD();
break;
2017-08-20 22:47:53 +02:00
case LC_FILE_IMPORT_INVENTORY:
ImportInventory();
break;
2014-12-04 02:47:28 +01:00
case LC_FILE_EXPORT_3DS:
lcGetActiveProject()->Export3DStudio(QString());
2014-12-04 02:47:28 +01:00
break;
2015-01-12 05:49:30 +01:00
2017-08-11 03:40:43 +02:00
case LC_FILE_EXPORT_COLLADA:
lcGetActiveProject()->ExportCOLLADA(QString());
2017-08-11 03:40:43 +02:00
break;
2014-12-04 02:47:28 +01:00
case LC_FILE_EXPORT_HTML:
2017-12-11 03:12:31 +01:00
ShowHTMLDialog();
2014-12-04 02:47:28 +01:00
break;
2015-01-12 05:49:30 +01:00
2014-12-04 02:47:28 +01:00
case LC_FILE_EXPORT_BRICKLINK:
lcGetActiveProject()->ExportBrickLink();
break;
case LC_FILE_EXPORT_CSV:
lcGetActiveProject()->ExportCSV(QString());
2014-12-04 02:47:28 +01:00
break;
case LC_FILE_EXPORT_POVRAY:
2017-09-22 19:08:02 +02:00
lcGetActiveProject()->ExportPOVRay(QString());
2014-12-04 02:47:28 +01:00
break;
case LC_FILE_EXPORT_WAVEFRONT:
lcGetActiveProject()->ExportWavefront(QString());
2014-12-04 02:47:28 +01:00
break;
2014-12-30 17:30:12 +01:00
2023-05-21 11:17:00 +02:00
case LC_FILE_RENDER_POVRAY:
case LC_FILE_RENDER_BLENDER:
case LC_FILE_RENDER_OPEN_IN_BLENDER:
ShowRenderDialog(CommandId - LC_FILE_RENDER_POVRAY);
2017-09-22 19:08:02 +02:00
break;
2020-06-01 03:46:36 +02:00
case LC_FILE_INSTRUCTIONS:
ShowInstructionsDialog();
break;
2014-12-04 02:47:28 +01:00
case LC_FILE_PRINT_PREVIEW:
TogglePrintPreview();
break;
case LC_FILE_PRINT:
2015-01-30 17:30:13 +01:00
ShowPrintDialog();
2014-12-04 02:47:28 +01:00
break;
case LC_FILE_RECENT1:
case LC_FILE_RECENT2:
case LC_FILE_RECENT3:
case LC_FILE_RECENT4:
OpenRecentProject(CommandId - LC_FILE_RECENT1);
2014-12-04 02:47:28 +01:00
break;
case LC_FILE_EXIT:
2015-01-26 00:04:39 +01:00
close();
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_UNDO:
if (ActiveModel)
ActiveModel->UndoAction();
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_REDO:
if (ActiveModel)
ActiveModel->RedoAction();
2014-12-04 02:47:28 +01:00
break;
2014-12-16 00:55:17 +01:00
case LC_EDIT_CUT:
if (ActiveModel)
ActiveModel->Cut();
2014-12-16 00:55:17 +01:00
break;
2014-12-04 02:47:28 +01:00
2014-12-16 00:55:17 +01:00
case LC_EDIT_COPY:
if (ActiveModel)
ActiveModel->Copy();
2014-12-16 00:55:17 +01:00
break;
2014-12-04 02:47:28 +01:00
2014-12-16 00:55:17 +01:00
case LC_EDIT_PASTE:
if (ActiveModel)
ActiveModel->Paste(true);
break;
case LC_EDIT_PASTE_STEPS:
if (ActiveModel)
ActiveModel->Paste(false);
2014-12-16 00:55:17 +01:00
break;
2014-12-04 02:47:28 +01:00
case LC_EDIT_FIND:
2021-01-31 00:37:17 +01:00
if (ActiveView)
ActiveView->ShowFindReplaceWidget(false);
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_FIND_NEXT:
if (ActiveModel)
ActiveModel->FindReplacePiece(true, false, false);
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_FIND_PREVIOUS:
if (ActiveModel)
ActiveModel->FindReplacePiece(false, false, false);
2021-01-31 20:02:50 +01:00
break;
case LC_EDIT_FIND_ALL:
if (ActiveModel)
ActiveModel->FindReplacePiece(true, true, false);
2021-01-31 00:37:17 +01:00
break;
case LC_EDIT_REPLACE:
if (ActiveView)
ActiveView->ShowFindReplaceWidget(true);
break;
2021-01-31 20:02:50 +01:00
case LC_EDIT_REPLACE_ALL:
if (ActiveModel)
ActiveModel->FindReplacePiece(true, true, true);
2021-01-31 20:02:50 +01:00
break;
2021-01-31 00:37:17 +01:00
case LC_EDIT_REPLACE_NEXT:
if (ActiveModel)
ActiveModel->FindReplacePiece(true, false, true);
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_SELECT_ALL:
if (ActiveModel)
ActiveModel->SelectAllPieces();
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_SELECT_NONE:
if (ActiveModel)
ActiveModel->ClearSelection(true);
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_SELECT_INVERT:
if (ActiveModel)
ActiveModel->InvertSelection();
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_SELECT_BY_NAME:
if (ActiveModel)
ActiveModel->ShowSelectByNameDialog();
2014-12-04 02:47:28 +01:00
break;
2017-11-22 02:58:36 +01:00
case LC_EDIT_SELECTION_SINGLE:
2020-05-03 22:04:40 +02:00
SetSelectionMode(lcSelectionMode::Single);
2017-11-22 02:58:36 +01:00
break;
case LC_EDIT_SELECTION_PIECE:
2020-05-03 22:04:40 +02:00
SetSelectionMode(lcSelectionMode::Piece);
2017-11-22 02:58:36 +01:00
break;
case LC_EDIT_SELECTION_COLOR:
2020-05-03 22:04:40 +02:00
SetSelectionMode(lcSelectionMode::Color);
2017-11-22 02:58:36 +01:00
break;
case LC_EDIT_SELECTION_PIECE_COLOR:
2020-05-03 22:04:40 +02:00
SetSelectionMode(lcSelectionMode::PieceColor);
2017-11-22 02:58:36 +01:00
break;
2014-12-04 02:47:28 +01:00
case LC_VIEW_SPLIT_HORIZONTAL:
SplitHorizontal();
break;
case LC_VIEW_SPLIT_VERTICAL:
SplitVertical();
break;
case LC_VIEW_REMOVE_VIEW:
2015-01-26 00:04:39 +01:00
RemoveActiveView();
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_RESET_VIEWS:
ResetViews();
break;
case LC_VIEW_TOOLBAR_STANDARD:
ToggleDockWidget(mStandardToolBar);
break;
case LC_VIEW_TOOLBAR_TOOLS:
ToggleDockWidget(mToolsToolBar);
break;
case LC_VIEW_TOOLBAR_TIME:
ToggleDockWidget(mTimeToolBar);
break;
case LC_VIEW_TOOLBAR_PARTS:
ToggleDockWidget(mPartsToolBar);
break;
case LC_VIEW_TOOLBAR_COLORS:
ToggleDockWidget(mColorsToolBar);
break;
case LC_VIEW_TOOLBAR_PROPERTIES:
ToggleDockWidget(mPropertiesToolBar);
break;
case LC_VIEW_TOOLBAR_TIMELINE:
ToggleDockWidget(mTimelineToolBar);
break;
case LC_VIEW_TOOLBAR_PREVIEW:
ToggleDockWidget(mPreviewToolBar);
break;
2014-12-04 02:47:28 +01:00
case LC_VIEW_FULLSCREEN:
ToggleFullScreen();
break;
case LC_VIEW_CLOSE_CURRENT_TAB:
CloseCurrentModelTab();
break;
2017-08-25 21:57:14 +02:00
case LC_VIEW_SHADING_WIREFRAME:
2020-03-22 21:44:20 +01:00
SetShadingMode(lcShadingMode::Wireframe);
2017-08-25 21:57:14 +02:00
break;
case LC_VIEW_SHADING_FLAT:
2020-03-22 21:44:20 +01:00
SetShadingMode(lcShadingMode::Flat);
2017-08-25 21:57:14 +02:00
break;
case LC_VIEW_SHADING_DEFAULT_LIGHTS:
2020-03-22 21:44:20 +01:00
SetShadingMode(lcShadingMode::DefaultLights);
2017-08-25 21:57:14 +02:00
break;
2014-12-04 02:47:28 +01:00
case LC_VIEW_PROJECTION_PERSPECTIVE:
2016-03-06 02:47:00 +01:00
if (ActiveView)
ActiveView->SetProjection(false);
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_PROJECTION_ORTHO:
2016-03-06 02:47:00 +01:00
if (ActiveView)
ActiveView->SetProjection(true);
2014-12-04 02:47:28 +01:00
break;
2020-01-05 20:38:24 +01:00
case LC_VIEW_TOGGLE_VIEW_SPHERE:
ToggleViewSphere();
break;
2015-01-17 19:36:09 +01:00
case LC_VIEW_TOGGLE_AXIS_ICON:
ToggleAxisIcon();
break;
2020-12-24 04:10:54 +01:00
case LC_VIEW_TOGGLE_GRID:
ToggleGrid();
break;
case LC_VIEW_FADE_PREVIOUS_STEPS:
ToggleFadePreviousSteps();
break;
2014-12-04 02:47:28 +01:00
case LC_PIECE_INSERT:
if (ActiveModel)
ActiveModel->AddPiece();
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_DELETE:
if (ActiveModel)
ActiveModel->DeleteSelectedObjects();
2014-12-04 02:47:28 +01:00
break;
2017-03-09 00:55:38 +01:00
case LC_PIECE_DUPLICATE:
if (ActiveModel)
ActiveModel->DuplicateSelectedPieces();
2017-03-09 00:55:38 +01:00
break;
case LC_PIECE_PAINT_SELECTED:
if (ActiveModel)
ActiveModel->PaintSelectedPieces();
break;
2015-12-14 19:01:17 +01:00
case LC_PIECE_RESET_PIVOT_POINT:
if (ActiveModel)
ActiveModel->ResetSelectedPiecesPivotPoint();
2015-12-14 19:01:17 +01:00
break;
case LC_PIECE_REMOVE_KEY_FRAMES:
if (ActiveModel)
ActiveModel->RemoveSelectedPiecesKeyFrames();
break;
case LC_PIECE_CONTROL_POINT_INSERT:
if (ActiveModel)
ActiveModel->InsertControlPoint();
break;
case LC_PIECE_CONTROL_POINT_REMOVE:
if (ActiveModel)
ActiveModel->RemoveFocusedControlPoint();
break;
2014-12-04 02:47:28 +01:00
case LC_PIECE_MOVE_PLUSX:
if (ActiveModel)
ActiveModel->MoveSelectedObjects(ActiveView->GetMoveDirection(lcVector3(lcMax(GetMoveXYSnap(), 0.1f), 0.0f, 0.0f)), true, false, true, true, true);
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_MOVE_MINUSX:
if (ActiveModel)
ActiveModel->MoveSelectedObjects(ActiveView->GetMoveDirection(lcVector3(-lcMax(GetMoveXYSnap(), 0.1f), 0.0f, 0.0f)), true, false, true, true, true);
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_MOVE_PLUSY:
if (ActiveModel)
ActiveModel->MoveSelectedObjects(ActiveView->GetMoveDirection(lcVector3(0.0f, lcMax(GetMoveXYSnap(), 0.1f), 0.0f)), true, false, true, true, true);
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_MOVE_MINUSY:
if (ActiveModel)
ActiveModel->MoveSelectedObjects(ActiveView->GetMoveDirection(lcVector3(0.0f, -lcMax(GetMoveXYSnap(), 0.1f), 0.0f)), true, false, true, true, true);
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_MOVE_PLUSZ:
if (ActiveModel)
ActiveModel->MoveSelectedObjects(ActiveView->GetMoveDirection(lcVector3(0.0f, 0.0f, lcMax(GetMoveZSnap(), 0.1f))), true, false, true, true, true);
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_MOVE_MINUSZ:
if (ActiveModel)
ActiveModel->MoveSelectedObjects(ActiveView->GetMoveDirection(lcVector3(0.0f, 0.0f, -lcMax(GetMoveZSnap(), 0.1f))), true, false, true, true, true);
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_ROTATE_PLUSX:
if (ActiveModel)
2023-09-04 19:59:16 +02:00
ActiveModel->RotateSelectedObjects(ActiveView->GetMoveDirection(lcVector3(lcMax(GetAngleSnap(), 1.0f), 0.0f, 0.0f)), true, false, true, true);
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_ROTATE_MINUSX:
if (ActiveModel)
2023-09-04 19:59:16 +02:00
ActiveModel->RotateSelectedObjects(ActiveView->GetMoveDirection(-lcVector3(lcMax(GetAngleSnap(), 1.0f), 0.0f, 0.0f)), true, false, true, true);
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_ROTATE_PLUSY:
if (ActiveModel)
2023-09-04 19:59:16 +02:00
ActiveModel->RotateSelectedObjects(ActiveView->GetMoveDirection(lcVector3(0.0f, lcMax(GetAngleSnap(), 1.0f), 0.0f)), true, false, true, true);
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_ROTATE_MINUSY:
if (ActiveModel)
2023-09-04 19:59:16 +02:00
ActiveModel->RotateSelectedObjects(ActiveView->GetMoveDirection(lcVector3(0.0f, -lcMax(GetAngleSnap(), 1.0f), 0.0f)), true, false, true, true);
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_ROTATE_PLUSZ:
if (ActiveModel)
2023-09-04 19:59:16 +02:00
ActiveModel->RotateSelectedObjects(ActiveView->GetMoveDirection(lcVector3(0.0f, 0.0f, lcMax(GetAngleSnap(), 1.0f))), true, false, true, true);
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_ROTATE_MINUSZ:
if (ActiveModel)
2023-09-04 19:59:16 +02:00
ActiveModel->RotateSelectedObjects(ActiveView->GetMoveDirection(lcVector3(0.0f, 0.0f, -lcMax(GetAngleSnap(), 1.0f))), true, false, true, true);
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_MINIFIG_WIZARD:
if (ActiveModel)
ActiveModel->ShowMinifigDialog();
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_ARRAY:
if (ActiveModel)
ActiveModel->ShowArrayDialog();
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_VIEW_SELECTED_MODEL:
SetModelFromSelection();
break;
2015-12-02 00:31:28 +01:00
case LC_PIECE_MOVE_SELECTION_TO_MODEL:
if (ActiveModel)
ActiveModel->MoveSelectionToModel(lcGetActiveProject()->CreateNewModel(false));
2015-12-02 00:31:28 +01:00
break;
case LC_PIECE_INLINE_SELECTED_MODELS:
if (ActiveModel)
ActiveModel->InlineSelectedModels();
2015-12-02 00:31:28 +01:00
break;
2018-10-14 17:47:28 +02:00
case LC_PIECE_EDIT_END_SUBMODEL:
if (ActiveView)
{
ActiveView->SetTopSubmodelActive();
if (ActiveModel)
{
2019-03-17 21:27:57 +01:00
std::vector<lcModel*> UpdatedModels;
ActiveModel->UpdatePieceInfo(UpdatedModels);
}
}
break;
case LC_PIECE_EDIT_SELECTED_SUBMODEL:
if (ActiveView)
ActiveView->SetSelectedSubmodelActive();
break;
2014-12-04 02:47:28 +01:00
case LC_PIECE_GROUP:
if (ActiveModel)
ActiveModel->GroupSelection();
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_UNGROUP:
if (ActiveModel)
ActiveModel->UngroupSelection();
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_GROUP_ADD:
if (ActiveModel)
ActiveModel->AddSelectedPiecesToGroup();
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_GROUP_REMOVE:
if (ActiveModel)
ActiveModel->RemoveFocusPieceFromGroup();
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_GROUP_EDIT:
if (ActiveModel)
ActiveModel->ShowEditGroupsDialog();
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_HIDE_SELECTED:
if (ActiveModel)
ActiveModel->HideSelectedPieces();
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_HIDE_UNSELECTED:
if (ActiveModel)
ActiveModel->HideUnselectedPieces();
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_UNHIDE_SELECTED:
if (ActiveModel)
ActiveModel->UnhideSelectedPieces();
break;
2014-12-04 02:47:28 +01:00
case LC_PIECE_UNHIDE_ALL:
if (ActiveModel)
ActiveModel->UnhideAllPieces();
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_SHOW_EARLIER:
if (ActiveModel)
ActiveModel->ShowSelectedPiecesEarlier();
2014-12-04 02:47:28 +01:00
break;
case LC_PIECE_SHOW_LATER:
if (ActiveModel)
ActiveModel->ShowSelectedPiecesLater();
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_PREFERENCES:
gApplication->ShowPreferencesDialog();
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_ZOOM_IN:
2016-03-06 02:47:00 +01:00
if (ActiveView)
ActiveView->Zoom(10.0f);
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_ZOOM_OUT:
2016-03-06 02:47:00 +01:00
if (ActiveView)
ActiveView->Zoom(-10.0f);
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_ZOOM_EXTENTS:
2016-03-06 02:47:00 +01:00
if (ActiveView)
ActiveView->ZoomExtents();
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_LOOK_AT:
2016-03-06 02:47:00 +01:00
if (ActiveView)
ActiveView->LookAt();
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_MOVE_FORWARD:
if (ActiveView)
ActiveView->MoveCamera(lcVector3(0.0f, 0.0f, -1.0f));
break;
case LC_VIEW_MOVE_BACKWARD:
if (ActiveView)
ActiveView->MoveCamera(lcVector3(0.0f, 0.0f, 1.0f));
break;
case LC_VIEW_MOVE_LEFT:
if (ActiveView)
ActiveView->MoveCamera(lcVector3(-1.0f, 0.0f, 0.0f));
break;
case LC_VIEW_MOVE_RIGHT:
if (ActiveView)
ActiveView->MoveCamera(lcVector3(1.0f, 0.0f, 0.0f));
break;
case LC_VIEW_MOVE_UP:
if (ActiveView)
ActiveView->MoveCamera(lcVector3(0.0f, 1.0f, 0.0f));
break;
case LC_VIEW_MOVE_DOWN:
if (ActiveView)
ActiveView->MoveCamera(lcVector3(0.0f, -1.0f, 0.0f));
break;
2014-12-04 02:47:28 +01:00
case LC_VIEW_TIME_NEXT:
if (ActiveModel)
ActiveModel->ShowNextStep();
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_TIME_PREVIOUS:
if (ActiveModel)
ActiveModel->ShowPreviousStep();
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_TIME_FIRST:
if (ActiveModel)
ActiveModel->ShowFirstStep();
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_TIME_LAST:
if (ActiveModel)
ActiveModel->ShowLastStep();
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_TIME_INSERT_BEFORE:
lcGetActiveModel()->InsertStep(lcGetActiveModel()->GetCurrentStep());
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_TIME_INSERT_AFTER:
lcGetActiveModel()->InsertStep(lcGetActiveModel()->GetCurrentStep() + 1);
break;
2014-12-04 02:47:28 +01:00
case LC_VIEW_TIME_DELETE:
lcGetActiveModel()->RemoveStep(lcGetActiveModel()->GetCurrentStep());
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_VIEWPOINT_FRONT:
2016-03-06 02:47:00 +01:00
if (ActiveView)
2020-12-13 01:58:40 +01:00
ActiveView->SetViewpoint(lcViewpoint::Front);
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_VIEWPOINT_BACK:
2016-03-06 02:47:00 +01:00
if (ActiveView)
2020-12-13 01:58:40 +01:00
ActiveView->SetViewpoint(lcViewpoint::Back);
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_VIEWPOINT_TOP:
2016-03-06 02:47:00 +01:00
if (ActiveView)
2020-12-13 01:58:40 +01:00
ActiveView->SetViewpoint(lcViewpoint::Top);
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_VIEWPOINT_BOTTOM:
2016-03-06 02:47:00 +01:00
if (ActiveView)
2020-12-13 01:58:40 +01:00
ActiveView->SetViewpoint(lcViewpoint::Bottom);
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_VIEWPOINT_LEFT:
2016-03-06 02:47:00 +01:00
if (ActiveView)
2020-12-13 01:58:40 +01:00
ActiveView->SetViewpoint(lcViewpoint::Left);
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_VIEWPOINT_RIGHT:
2016-03-06 02:47:00 +01:00
if (ActiveView)
2020-12-13 01:58:40 +01:00
ActiveView->SetViewpoint(lcViewpoint::Right);
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_VIEWPOINT_HOME:
2016-03-06 02:47:00 +01:00
if (ActiveView)
2020-12-13 01:58:40 +01:00
ActiveView->SetViewpoint(lcViewpoint::Home);
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_CAMERA_NONE:
2016-03-06 02:47:00 +01:00
if (ActiveView)
ActiveView->RemoveCamera();
2014-12-04 02:47:28 +01:00
break;
case LC_VIEW_CAMERA1:
case LC_VIEW_CAMERA2:
case LC_VIEW_CAMERA3:
case LC_VIEW_CAMERA4:
case LC_VIEW_CAMERA5:
case LC_VIEW_CAMERA6:
case LC_VIEW_CAMERA7:
case LC_VIEW_CAMERA8:
case LC_VIEW_CAMERA9:
case LC_VIEW_CAMERA10:
case LC_VIEW_CAMERA11:
case LC_VIEW_CAMERA12:
case LC_VIEW_CAMERA13:
case LC_VIEW_CAMERA14:
case LC_VIEW_CAMERA15:
case LC_VIEW_CAMERA16:
2016-03-06 02:47:00 +01:00
if (ActiveView)
ActiveView->SetCameraIndex(CommandId - LC_VIEW_CAMERA1);
2014-12-04 02:47:28 +01:00
break;
2014-12-13 00:42:09 +01:00
case LC_MODEL_NEW:
lcGetActiveProject()->CreateNewModel(true);
2014-12-13 00:42:09 +01:00
break;
2014-12-31 18:05:23 +01:00
case LC_MODEL_PROPERTIES:
lcGetActiveModel()->ShowPropertiesDialog();
break;
2014-12-13 00:42:09 +01:00
case LC_MODEL_LIST:
lcGetActiveProject()->ShowModelListDialog();
break;
case LC_MODEL_01:
case LC_MODEL_02:
case LC_MODEL_03:
case LC_MODEL_04:
case LC_MODEL_05:
case LC_MODEL_06:
case LC_MODEL_07:
case LC_MODEL_08:
case LC_MODEL_09:
case LC_MODEL_10:
case LC_MODEL_11:
case LC_MODEL_12:
case LC_MODEL_13:
case LC_MODEL_14:
case LC_MODEL_15:
case LC_MODEL_16:
2016-02-21 07:57:36 +01:00
case LC_MODEL_17:
case LC_MODEL_18:
case LC_MODEL_19:
case LC_MODEL_20:
case LC_MODEL_21:
case LC_MODEL_22:
case LC_MODEL_23:
case LC_MODEL_24:
case LC_MODEL_25:
case LC_MODEL_26:
case LC_MODEL_27:
case LC_MODEL_28:
case LC_MODEL_29:
case LC_MODEL_30:
case LC_MODEL_31:
case LC_MODEL_32:
case LC_MODEL_33:
case LC_MODEL_34:
case LC_MODEL_35:
case LC_MODEL_36:
case LC_MODEL_37:
case LC_MODEL_38:
case LC_MODEL_39:
case LC_MODEL_40:
2014-12-13 00:42:09 +01:00
lcGetActiveProject()->SetActiveModel(CommandId - LC_MODEL_01);
break;
2014-12-04 02:47:28 +01:00
case LC_HELP_HOMEPAGE:
2018-03-22 00:47:00 +01:00
QDesktopServices::openUrl(QUrl("https://www.leocad.org/"));
2014-12-04 02:47:28 +01:00
break;
case LC_HELP_BUG_REPORT:
QDesktopServices::openUrl(QUrl("https://github.com/leozide/leocad/issues"));
2014-12-04 02:47:28 +01:00
break;
case LC_HELP_UPDATES:
2016-08-01 05:44:15 +02:00
ShowUpdatesDialog();
2014-12-04 02:47:28 +01:00
break;
case LC_HELP_ABOUT:
2016-08-01 05:44:15 +02:00
ShowAboutDialog();
break;
2014-12-04 02:47:28 +01:00
case LC_VIEW_TIME_ADD_KEYS:
SetAddKeys(!GetAddKeys());
break;
case LC_EDIT_TRANSFORM_RELATIVE:
SetRelativeTransform(true);
break;
case LC_EDIT_TRANSFORM_ABSOLUTE:
SetRelativeTransform(false);
break;
case LC_EDIT_TRANSFORM_TOGGLE_RELATIVE:
SetRelativeTransform(!GetRelativeTransform());
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_TRANSFORM_SEPARATELY:
SetSeparateTransform(true);
break;
case LC_EDIT_TRANSFORM_TOGETHER:
SetSeparateTransform(false);
break;
case LC_EDIT_TRANSFORM_TOGGLE_SEPARATE:
SetSeparateTransform(!GetSeparateTransform());
break;
2015-04-25 00:11:50 +02:00
case LC_EDIT_SNAP_MOVE_TOGGLE:
SetMoveSnapEnabled(!mMoveSnapEnabled);
break;
2014-12-04 02:47:28 +01:00
case LC_EDIT_SNAP_MOVE_XY0:
case LC_EDIT_SNAP_MOVE_XY1:
case LC_EDIT_SNAP_MOVE_XY2:
case LC_EDIT_SNAP_MOVE_XY3:
case LC_EDIT_SNAP_MOVE_XY4:
case LC_EDIT_SNAP_MOVE_XY5:
case LC_EDIT_SNAP_MOVE_XY6:
case LC_EDIT_SNAP_MOVE_XY7:
case LC_EDIT_SNAP_MOVE_XY8:
case LC_EDIT_SNAP_MOVE_XY9:
SetMoveXYSnapIndex(CommandId - LC_EDIT_SNAP_MOVE_XY0);
break;
case LC_EDIT_SNAP_MOVE_Z0:
case LC_EDIT_SNAP_MOVE_Z1:
case LC_EDIT_SNAP_MOVE_Z2:
case LC_EDIT_SNAP_MOVE_Z3:
case LC_EDIT_SNAP_MOVE_Z4:
case LC_EDIT_SNAP_MOVE_Z5:
case LC_EDIT_SNAP_MOVE_Z6:
case LC_EDIT_SNAP_MOVE_Z7:
case LC_EDIT_SNAP_MOVE_Z8:
case LC_EDIT_SNAP_MOVE_Z9:
SetMoveZSnapIndex(CommandId - LC_EDIT_SNAP_MOVE_Z0);
break;
2015-04-25 00:11:50 +02:00
case LC_EDIT_SNAP_ANGLE_TOGGLE:
SetAngleSnapEnabled(!mAngleSnapEnabled);
break;
2014-12-04 02:47:28 +01:00
case LC_EDIT_SNAP_ANGLE0:
case LC_EDIT_SNAP_ANGLE1:
case LC_EDIT_SNAP_ANGLE2:
case LC_EDIT_SNAP_ANGLE3:
case LC_EDIT_SNAP_ANGLE4:
case LC_EDIT_SNAP_ANGLE5:
case LC_EDIT_SNAP_ANGLE6:
case LC_EDIT_SNAP_ANGLE7:
case LC_EDIT_SNAP_ANGLE8:
case LC_EDIT_SNAP_ANGLE9:
SetAngleSnapIndex(CommandId - LC_EDIT_SNAP_ANGLE0);
break;
case LC_EDIT_TRANSFORM:
if (ActiveModel)
ActiveModel->TransformSelectedObjects(GetTransformType(), GetTransformAmount());
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_TRANSFORM_ABSOLUTE_TRANSLATION:
2020-05-03 22:04:40 +02:00
SetTransformType(lcTransformType::AbsoluteTranslation);
break;
2014-12-04 02:47:28 +01:00
case LC_EDIT_TRANSFORM_RELATIVE_TRANSLATION:
2020-05-03 22:04:40 +02:00
SetTransformType(lcTransformType::RelativeTranslation);
break;
2014-12-04 02:47:28 +01:00
case LC_EDIT_TRANSFORM_ABSOLUTE_ROTATION:
2020-05-03 22:04:40 +02:00
SetTransformType(lcTransformType::AbsoluteRotation);
break;
2014-12-04 02:47:28 +01:00
case LC_EDIT_TRANSFORM_RELATIVE_ROTATION:
2020-05-03 22:04:40 +02:00
SetTransformType(lcTransformType::RelativeRotation);
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_ACTION_SELECT:
2020-12-05 00:38:49 +01:00
SetTool(lcTool::Select);
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_ACTION_INSERT:
2020-12-05 00:38:49 +01:00
SetTool(lcTool::Insert);
2014-12-04 02:47:28 +01:00
break;
2023-08-13 15:15:52 +02:00
case LC_EDIT_ACTION_POINT_LIGHT:
SetTool(lcTool::PointLight);
2014-12-04 02:47:28 +01:00
break;
2023-08-13 15:15:52 +02:00
case LC_EDIT_ACTION_AREA_LIGHT:
2023-07-05 03:13:47 +02:00
SetTool(lcTool::AreaLight);
break;
2023-08-13 15:15:52 +02:00
case LC_EDIT_ACTION_DIRECTIONAL_LIGHT:
SetTool(lcTool::DirectionalLight);
2023-07-05 03:13:47 +02:00
break;
2014-12-04 02:47:28 +01:00
case LC_EDIT_ACTION_SPOTLIGHT:
2023-09-10 03:25:34 +02:00
SetTool(lcTool::SpotLight);
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_ACTION_CAMERA:
2020-12-05 00:38:49 +01:00
SetTool(lcTool::Camera);
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_ACTION_MOVE:
2020-12-05 00:38:49 +01:00
SetTool(lcTool::Move);
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_ACTION_ROTATE:
2020-12-05 00:38:49 +01:00
SetTool(lcTool::Rotate);
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_ACTION_DELETE:
2020-12-05 00:38:49 +01:00
SetTool(lcTool::Eraser);
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_ACTION_PAINT:
2020-12-05 00:38:49 +01:00
SetTool(lcTool::Paint);
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_ACTION_COLOR_PICKER:
2020-12-05 00:38:49 +01:00
SetTool(lcTool::ColorPicker);
break;
2014-12-04 02:47:28 +01:00
case LC_EDIT_ACTION_ZOOM:
2020-12-05 00:38:49 +01:00
SetTool(lcTool::Zoom);
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_ACTION_ZOOM_REGION:
2020-12-05 00:38:49 +01:00
SetTool(lcTool::ZoomRegion);
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_ACTION_PAN:
2020-12-05 00:38:49 +01:00
SetTool(lcTool::Pan);
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_ACTION_ROTATE_VIEW:
2020-12-05 00:38:49 +01:00
SetTool(lcTool::RotateView);
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_ACTION_ROLL:
2020-12-05 00:38:49 +01:00
SetTool(lcTool::Roll);
2014-12-04 02:47:28 +01:00
break;
case LC_EDIT_CANCEL:
2021-01-31 00:37:17 +01:00
if (ActiveView && !ActiveView->CloseFindReplaceDialog())
2016-03-06 02:47:00 +01:00
ActiveView->CancelTrackingOrClearSelection();
2014-12-04 02:47:28 +01:00
break;
case LC_TIMELINE_INSERT_BEFORE:
mTimelineWidget->InsertStepBefore();
break;
case LC_TIMELINE_INSERT_AFTER:
mTimelineWidget->InsertStepAfter();
break;
case LC_TIMELINE_DELETE:
mTimelineWidget->RemoveStep();
break;
case LC_TIMELINE_MOVE_SELECTION:
mTimelineWidget->MoveSelection();
break;
case LC_TIMELINE_MOVE_SELECTION_BEFORE:
mTimelineWidget->MoveSelectionBefore();
break;
case LC_TIMELINE_MOVE_SELECTION_AFTER:
mTimelineWidget->MoveSelectionAfter();
break;
case LC_TIMELINE_SET_CURRENT:
mTimelineWidget->SetCurrentStep();
break;
2014-12-04 02:47:28 +01:00
case LC_NUM_COMMANDS:
break;
}
}