From 21d622bd594b6e862bafcd6275dc90c5b8de33c6 Mon Sep 17 00:00:00 2001 From: leo Date: Sun, 25 Jan 2015 23:04:39 +0000 Subject: [PATCH] Merged main window classes. --- common/lc_application.cpp | 4 +- common/lc_context.cpp | 2 +- common/lc_mainwindow.cpp | 1422 +++++++++++++++++++++++++++++++++++-- common/lc_mainwindow.h | 56 +- common/project.cpp | 22 +- leocad.pro | 2 - qt/lc_qglwidget.cpp | 5 +- qt/lc_qmainwindow.cpp | 1336 ---------------------------------- qt/lc_qmainwindow.h | 111 --- qt/qtmain.cpp | 236 +----- 10 files changed, 1436 insertions(+), 1760 deletions(-) delete mode 100644 qt/lc_qmainwindow.cpp delete mode 100644 qt/lc_qmainwindow.h diff --git a/common/lc_application.cpp b/common/lc_application.cpp index 626e5b03..d80d5f9e 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -11,7 +11,6 @@ #include "lc_mainwindow.h" #include "lc_shortcuts.h" #include "view.h" -#include "lc_qmainwindow.h" lcApplication* g_App; @@ -238,7 +237,6 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal WavefrontName = argv[i]; } } - else if ((strcmp(Param, "-v") == 0) || (strcmp(Param, "--version") == 0)) { printf("LeoCAD Version " LC_VERSION_TEXT "\n"); @@ -290,7 +288,7 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal "Please visit http://www.leocad.org for information on how to download and install a library.", LC_MB_OK | LC_MB_ICONERROR); } - gMainWindow->mHandle = new lcQMainWindow; + gMainWindow->CreateWidgets(); // Create a new project. Project* NewProject = new Project(); diff --git a/common/lc_context.cpp b/common/lc_context.cpp index efe77907..8aa9dcfd 100644 --- a/common/lc_context.cpp +++ b/common/lc_context.cpp @@ -240,7 +240,7 @@ bool lcContext::SaveRenderToTextureImage(const QString& FileName, int Width, int bool Result = Writer.write(QImage(Buffer, Width, Height, QImage::Format_ARGB32)); if (!Result) - QMessageBox::information(gMainWindow->mHandle, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, Writer.errorString())); + QMessageBox::information(gMainWindow, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, Writer.errorString())); free(Buffer); diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index 9b456b5c..6651be21 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -1,30 +1,26 @@ #include "lc_global.h" #include "lc_mainwindow.h" -#include "lc_qmainwindow.h" -#include "lc_qimagedialog.h" -#include "lc_qhtmldialog.h" -#include "lc_qpovraydialog.h" -#include "lc_qpropertiesdialog.h" -#include "lc_qfinddialog.h" -#include "lc_qselectdialog.h" -#include "lc_qminifigdialog.h" -#include "lc_qarraydialog.h" -#include "lc_qgroupdialog.h" -#include "lc_qeditgroupsdialog.h" -#include "lc_qpreferencesdialog.h" -#include "lc_qupdatedialog.h" -#include "lc_qaboutdialog.h" +#include "lc_qglwidget.h" +#include "lc_qpartstree.h" +#include "lc_qcolorlist.h" +#include "lc_qpropertiestree.h" +#include "lc_qutils.h" #include "lc_profile.h" #include "preview.h" #include "view.h" #include "project.h" +#include "piece.h" +#include "group.h" +#include "pieceinf.h" +#include "lc_library.h" #include "lc_colors.h" lcMainWindow* gMainWindow; lcMainWindow::lcMainWindow() { - mHandle = NULL; + memset(mActions, 0, sizeof(mActions)); + mActiveView = NULL; mPreviewWidget = NULL; mTransformType = LC_TRANSFORM_RELATIVE_TRANSLATION; @@ -59,6 +55,906 @@ lcMainWindow::~lcMainWindow() gMainWindow = NULL; } +void lcMainWindow::CreateWidgets() +{ + setWindowIcon(QIcon(":/resources/icon64.png")); + setWindowFilePath(QString()); + + CreateActions(); + CreateToolBars(); + CreateMenus(); + CreateStatusBar(); + + QFrame* CentralFrame = new QFrame; + CentralFrame->setFrameShape(QFrame::StyledPanel); + CentralFrame->setFrameShadow(QFrame::Sunken); + setCentralWidget(CentralFrame); + + QGridLayout* CentralLayout = new QGridLayout(CentralFrame); + CentralLayout->setContentsMargins(0, 0, 0, 0); + + QWidget* ViewWidget = new lcQGLWidget(CentralFrame, mPiecePreviewWidget, new View(NULL), true); + CentralLayout->addWidget(ViewWidget, 0, 0, 1, 1); + + connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(ClipboardChanged())); + ClipboardChanged(); + + PiecePreview* Preview = (PiecePreview*)mPiecePreviewWidget->widget; + mPreviewWidget = Preview; + + lcPiecesLibrary* Library = lcGetPiecesLibrary(); + PieceInfo* Info = Library->FindPiece("3005", false); + + if (!Info) + Info = Library->mPieces[0]; + + if (Info) + mPreviewWidget->SetCurrentPiece(Info); + + QSettings Settings; + Settings.beginGroup("MainWindow"); + resize(QSize(800, 600)); + move(QPoint(200, 200)); + restoreGeometry(Settings.value("Geometry").toByteArray()); + restoreState(Settings.value("State").toByteArray()); + Settings.endGroup(); +} + +void lcMainWindow::CreateActions() +{ + for (int CommandIdx = 0; CommandIdx < LC_NUM_COMMANDS; CommandIdx++) + { + QAction* Action = new QAction(tr(gCommands[CommandIdx].MenuName), this); + Action->setStatusTip(tr(gCommands[CommandIdx].StatusText)); + connect(Action, SIGNAL(triggered()), this, SLOT(ActionTriggered())); + addAction(Action); + mActions[CommandIdx] = Action; + } + + mActions[LC_FILE_NEW]->setToolTip(tr("New Project")); + mActions[LC_FILE_OPEN]->setToolTip(tr("Open Project")); + mActions[LC_FILE_SAVE]->setToolTip(tr("Save Project")); + + mActions[LC_FILE_NEW]->setIcon(QIcon(":/resources/file_new.png")); + mActions[LC_FILE_OPEN]->setIcon(QIcon(":/resources/file_open.png")); + mActions[LC_FILE_SAVE]->setIcon(QIcon(":/resources/file_save.png")); + mActions[LC_FILE_SAVE_IMAGE]->setIcon(QIcon(":/resources/file_picture.png")); + mActions[LC_FILE_PRINT]->setIcon(QIcon(":/resources/file_print.png")); + mActions[LC_FILE_PRINT_PREVIEW]->setIcon(QIcon(":/resources/file_print_preview.png")); + mActions[LC_EDIT_UNDO]->setIcon(QIcon(":/resources/edit_undo.png")); + mActions[LC_EDIT_REDO]->setIcon(QIcon(":/resources/edit_redo.png")); + mActions[LC_EDIT_CUT]->setIcon(QIcon(":/resources/edit_cut.png")); + mActions[LC_EDIT_COPY]->setIcon(QIcon(":/resources/edit_copy.png")); + mActions[LC_EDIT_PASTE]->setIcon(QIcon(":/resources/edit_paste.png")); + mActions[LC_EDIT_ACTION_INSERT]->setIcon(QIcon(":/resources/action_insert.png")); + mActions[LC_EDIT_ACTION_LIGHT]->setIcon(QIcon(":/resources/action_light.png")); + mActions[LC_EDIT_ACTION_SPOTLIGHT]->setIcon(QIcon(":/resources/action_spotlight.png")); + mActions[LC_EDIT_ACTION_CAMERA]->setIcon(QIcon(":/resources/action_camera.png")); + mActions[LC_EDIT_ACTION_SELECT]->setIcon(QIcon(":/resources/action_select.png")); + mActions[LC_EDIT_ACTION_MOVE]->setIcon(QIcon(":/resources/action_move.png")); + mActions[LC_EDIT_ACTION_ROTATE]->setIcon(QIcon(":/resources/action_rotate.png")); + mActions[LC_EDIT_ACTION_DELETE]->setIcon(QIcon(":/resources/action_delete.png")); + mActions[LC_EDIT_ACTION_PAINT]->setIcon(QIcon(":/resources/action_paint.png")); + mActions[LC_EDIT_ACTION_ZOOM]->setIcon(QIcon(":/resources/action_zoom.png")); + mActions[LC_EDIT_ACTION_PAN]->setIcon(QIcon(":/resources/action_pan.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_TRANSFORM_RELATIVE]->setIcon(QIcon(":/resources/edit_transform_relative.png")); + 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")); + mActions[LC_HELP_EMAIL]->setIcon(QIcon(":/resources/help_email.png")); + + mActions[LC_EDIT_LOCK_X]->setCheckable(true); + mActions[LC_EDIT_LOCK_Y]->setCheckable(true); + mActions[LC_EDIT_LOCK_Z]->setCheckable(true); + mActions[LC_EDIT_TRANSFORM_RELATIVE]->setCheckable(true); + mActions[LC_VIEW_CAMERA_NONE]->setCheckable(true); + mActions[LC_VIEW_TIME_ADD_KEYS]->setCheckable(true); + + 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]); + } + + 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); + + QMenu* CameraMenu = new QMenu(tr("C&ameras"), this); + CameraMenu->addAction(mActions[LC_VIEW_CAMERA_NONE]); + + for (int actionIdx = LC_VIEW_CAMERA_FIRST; actionIdx <= LC_VIEW_CAMERA_LAST; actionIdx++) + CameraMenu->addAction(mActions[actionIdx]); + + CameraMenu->addSeparator(); + CameraMenu->addAction(mActions[LC_VIEW_CAMERA_RESET]); + + 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]); + QMenu* ExportMenu = FileMenu->addMenu(tr("&Export")); + ExportMenu->addAction(mActions[LC_FILE_EXPORT_3DS]); + ExportMenu->addAction(mActions[LC_FILE_EXPORT_BRICKLINK]); + 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(); + FileMenu->addAction(mActions[LC_FILE_PRINT]); + FileMenu->addAction(mActions[LC_FILE_PRINT_PREVIEW]); +// FileMenu->addAction(mActions[LC_FILE_PRINT_BOM]); + 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->addSeparator(); + EditMenu->addAction(mActions[LC_EDIT_FIND]); + EditMenu->addAction(mActions[LC_EDIT_FIND_NEXT]); + EditMenu->addAction(mActions[LC_EDIT_FIND_PREVIOUS]); + 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]); + + 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]); + QMenu* ViewpointsMenu = ViewMenu->addMenu(tr("&Viewpoints")); + ViewpointsMenu->addAction(mActions[LC_VIEW_VIEWPOINT_FRONT]); + ViewpointsMenu->addAction(mActions[LC_VIEW_VIEWPOINT_BACK]); + ViewpointsMenu->addAction(mActions[LC_VIEW_VIEWPOINT_LEFT]); + ViewpointsMenu->addAction(mActions[LC_VIEW_VIEWPOINT_RIGHT]); + ViewpointsMenu->addAction(mActions[LC_VIEW_VIEWPOINT_TOP]); + ViewpointsMenu->addAction(mActions[LC_VIEW_VIEWPOINT_BOTTOM]); + ViewpointsMenu->addAction(mActions[LC_VIEW_VIEWPOINT_HOME]); + ViewMenu->addMenu(CameraMenu); + QMenu* PerspectiveMenu = ViewMenu->addMenu(tr("Projection")); + PerspectiveMenu->addAction(mActions[LC_VIEW_PROJECTION_PERSPECTIVE]); + PerspectiveMenu->addAction(mActions[LC_VIEW_PROJECTION_ORTHO]); + 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]); + 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")); + ToolBarsMenu->addAction(mPartsToolBar->toggleViewAction()); + ToolBarsMenu->addAction(mPropertiesToolBar->toggleViewAction()); + ToolBarsMenu->addSeparator(); + ToolBarsMenu->addAction(mStandardToolBar->toggleViewAction()); + ToolBarsMenu->addAction(mToolsToolBar->toggleViewAction()); + ToolBarsMenu->addAction(mTimeToolBar->toggleViewAction()); + ViewMenu->addAction(mActions[LC_VIEW_FULLSCREEN]); + + QMenu* PieceMenu = menuBar()->addMenu(tr("&Piece")); + PieceMenu->addAction(mActions[LC_PIECE_INSERT]); + PieceMenu->addAction(mActions[LC_PIECE_DELETE]); + PieceMenu->addAction(mActions[LC_PIECE_ARRAY]); + PieceMenu->addAction(mActions[LC_PIECE_MINIFIG_WIZARD]); + PieceMenu->addSeparator(); + 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]); +// LC_PIECE_SHOW_EARLIER, +// LC_PIECE_SHOW_LATER, + PieceMenu->addSeparator(); + PieceMenu->addAction(mActions[LC_PIECE_HIDE_SELECTED]); + PieceMenu->addAction(mActions[LC_PIECE_HIDE_UNSELECTED]); + PieceMenu->addAction(mActions[LC_PIECE_UNHIDE_ALL]); + + QMenu* ModelMenu = menuBar()->addMenu(tr("&Model")); + ModelMenu->addAction(mActions[LC_MODEL_PROPERTIES]); + ModelMenu->addAction(mActions[LC_MODEL_NEW]); + ModelMenu->addSeparator(); + for (int ModelIdx = 0; ModelIdx < LC_MODEL_LAST - LC_MODEL_FIRST; ModelIdx++) + ModelMenu->addAction(mActions[LC_MODEL_FIRST + ModelIdx]); + ModelMenu->addAction(mActions[LC_MODEL_LIST]); + + QMenu* HelpMenu = menuBar()->addMenu(tr("&Help")); + HelpMenu->addAction(mActions[LC_HELP_HOMEPAGE]); + HelpMenu->addAction(mActions[LC_HELP_EMAIL]); +#if !LC_DISABLE_UPDATE_CHECK + HelpMenu->addAction(mActions[LC_HELP_UPDATES]); +#endif + HelpMenu->addSeparator(); + HelpMenu->addAction(mActions[LC_HELP_ABOUT]); +} + +void lcMainWindow::CreateToolBars() +{ + QMenu* LockMenu = new QMenu(tr("Lock Menu"), this); + LockMenu->addAction(mActions[LC_EDIT_LOCK_X]); + LockMenu->addAction(mActions[LC_EDIT_LOCK_Y]); + LockMenu->addAction(mActions[LC_EDIT_LOCK_Z]); + LockMenu->addAction(mActions[LC_EDIT_LOCK_NONE]); + + QAction* LockAction = new QAction(tr("Lock Menu"), this); + LockAction->setStatusTip(tr("Toggle mouse movement on specific axes")); + LockAction->setIcon(QIcon(":/resources/edit_lock.png")); + LockAction->setMenu(LockMenu); + + 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); + SnapMenu->addMenu(SnapXYMenu); + SnapMenu->addMenu(SnapZMenu); + + QAction* MoveAction = new QAction(tr("Snap Move"), this); + 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); + for (int actionIdx = LC_EDIT_SNAP_ANGLE0; actionIdx <= LC_EDIT_SNAP_ANGLE9; actionIdx++) + SnapAngleMenu->addAction(mActions[actionIdx]); + + QAction* AngleAction = new QAction(tr("Snap Rotate"), this); + 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->addAction(mActions[LC_FILE_PRINT]); + mStandardToolBar->addAction(mActions[LC_FILE_PRINT_PREVIEW]); + mStandardToolBar->addSeparator(); + mStandardToolBar->addAction(mActions[LC_EDIT_UNDO]); + mStandardToolBar->addAction(mActions[LC_EDIT_REDO]); + mStandardToolBar->addAction(mActions[LC_EDIT_CUT]); + mStandardToolBar->addAction(mActions[LC_EDIT_COPY]); + mStandardToolBar->addAction(mActions[LC_EDIT_PASTE]); + mStandardToolBar->addSeparator(); + mStandardToolBar->addAction(mActions[LC_EDIT_TRANSFORM_RELATIVE]); + mStandardToolBar->addAction(LockAction); + mStandardToolBar->addAction(MoveAction); + mStandardToolBar->addAction(AngleAction); + mStandardToolBar->addSeparator(); + mStandardToolBar->addAction(mActions[LC_EDIT_TRANSFORM]); + ((QToolButton*)mStandardToolBar->widgetForAction(LockAction))->setPopupMode(QToolButton::InstantPopup); + ((QToolButton*)mStandardToolBar->widgetForAction(MoveAction))->setPopupMode(QToolButton::InstantPopup); + ((QToolButton*)mStandardToolBar->widgetForAction(AngleAction))->setPopupMode(QToolButton::InstantPopup); + ((QToolButton*)mStandardToolBar->widgetForAction(mActions[LC_EDIT_TRANSFORM]))->setPopupMode(QToolButton::InstantPopup); + + QHBoxLayout* TransformLayout = new QHBoxLayout; + QWidget* TransformWidget = new QWidget(); + TransformWidget->setLayout(TransformLayout); + mTransformXEdit = new QLineEdit(); + mTransformXEdit->setMaximumWidth(75); + TransformLayout->addWidget(mTransformXEdit); + mTransformYEdit = new QLineEdit(); + mTransformYEdit->setMaximumWidth(75); + TransformLayout->addWidget(mTransformYEdit); + mTransformZEdit = new QLineEdit(); + mTransformZEdit->setMaximumWidth(75); + TransformLayout->addWidget(mTransformZEdit); + TransformLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum)); + mStandardToolBar->addWidget(TransformWidget); + 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())); + + mToolsToolBar = addToolBar(tr("Tools")); + mToolsToolBar->setObjectName("ToolsToolbar"); + insertToolBarBreak(mToolsToolBar); + mToolsToolBar->addAction(mActions[LC_EDIT_ACTION_INSERT]); + mToolsToolBar->addAction(mActions[LC_EDIT_ACTION_LIGHT]); + mToolsToolBar->addAction(mActions[LC_EDIT_ACTION_SPOTLIGHT]); + 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->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]); + + 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_PIECE_SHOW_EARLIER]); + mTimeToolBar->addAction(mActions[LC_PIECE_SHOW_LATER]); + mTimeToolBar->addAction(mActions[LC_VIEW_TIME_ADD_KEYS]); + // TODO: add missing menu items + + mPartsToolBar = new QDockWidget(tr("Parts"), this); + mPartsToolBar->setObjectName("PartsToolbar"); + mPartsToolBar->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + QWidget* PartsContents = new QWidget(); + QGridLayout* PartsLayout = new QGridLayout(PartsContents); + PartsLayout->setSpacing(6); + PartsLayout->setContentsMargins(6, 6, 6, 6); + QSplitter* PartsSplitter = new QSplitter(Qt::Vertical, PartsContents); + + QFrame* PreviewFrame = new QFrame(PartsSplitter); + PreviewFrame->setFrameShape(QFrame::StyledPanel); + PreviewFrame->setFrameShadow(QFrame::Sunken); + + QGridLayout* PreviewLayout = new QGridLayout(PreviewFrame); + PreviewLayout->setContentsMargins(0, 0, 0, 0); + + int AASamples = lcGetProfileInt(LC_PROFILE_ANTIALIASING_SAMPLES); + if (AASamples > 1) + { + QGLFormat format; + format.setSampleBuffers(true); + format.setSamples(AASamples); + QGLFormat::setDefaultFormat(format); + } + + mPiecePreviewWidget = new lcQGLWidget(PreviewFrame, NULL, new PiecePreview(), false); + mPiecePreviewWidget->preferredSize = QSize(200, 100); + PreviewLayout->addWidget(mPiecePreviewWidget, 0, 0, 1, 1); + + QSizePolicy treePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + treePolicy.setVerticalStretch(1); + + mPartsTree = new lcQPartsTree(PartsSplitter); + mPartsTree->setSizePolicy(treePolicy); + connect(mPartsTree, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(PartsTreeItemChanged(QTreeWidgetItem*, QTreeWidgetItem*))); + + mPartSearchEdit = new QLineEdit(PartsSplitter); + connect(mPartSearchEdit, SIGNAL(returnPressed()), this, SLOT(PartSearchReturn())); + connect(mPartSearchEdit, SIGNAL(textChanged(QString)), this, SLOT(PartSearchChanged(QString))); + + QCompleter* Completer = new QCompleter(this); + Completer->setModel(new lcQPartsListModel(Completer)); + Completer->setCaseSensitivity(Qt::CaseInsensitive); + mPartSearchEdit->setCompleter(Completer); + + QFrame* ColorFrame = new QFrame(PartsSplitter); + ColorFrame->setFrameShape(QFrame::StyledPanel); + ColorFrame->setFrameShadow(QFrame::Sunken); + + QGridLayout* ColorLayout = new QGridLayout(ColorFrame); + ColorLayout->setContentsMargins(0, 0, 0, 0); + + mColorList = new lcQColorList(PartsSplitter); + ColorLayout->addWidget(mColorList); + connect(mColorList, SIGNAL(colorChanged(int)), this, SLOT(ColorChanged(int))); + + PartsLayout->addWidget(PartsSplitter, 0, 0, 1, 1); + + mPartsToolBar->setWidget(PartsContents); + addDockWidget(Qt::RightDockWidgetArea, mPartsToolBar); + + mPropertiesToolBar = new QDockWidget(tr("Properties"), this); + mPropertiesToolBar->setObjectName("PropertiesToolbar"); + mPropertiesToolBar->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + + mPropertiesWidget = new lcQPropertiesTree(mPropertiesToolBar); + + mPropertiesToolBar->setWidget(mPropertiesWidget); + addDockWidget(Qt::RightDockWidgetArea, mPropertiesToolBar); + + tabifyDockWidget(mPartsToolBar, mPropertiesToolBar); + mPartsToolBar->raise(); +} + +void lcMainWindow::CreateStatusBar() +{ + QStatusBar* StatusBar = new QStatusBar(this); + setStatusBar(StatusBar); + + mStatusBarLabel = new QLabel(); + StatusBar->addWidget(mStatusBarLabel); + + mStatusPositionLabel = new QLabel(); + StatusBar->addPermanentWidget(mStatusPositionLabel); + + mStatusSnapLabel = new QLabel(); + StatusBar->addPermanentWidget(mStatusSnapLabel); + + mStatusTimeLabel = new QLabel(); + StatusBar->addPermanentWidget(mStatusTimeLabel); +} + +void lcMainWindow::closeEvent(QCloseEvent *event) +{ + if (SaveProjectIfModified()) + { + event->accept(); + + QSettings settings; + settings.beginGroup("MainWindow"); + settings.setValue("Geometry", saveGeometry()); + settings.setValue("State", saveState()); + settings.endGroup(); + } + else + event->ignore(); +} + +QMenu* lcMainWindow::createPopupMenu() +{ + QMenu* Menu = new QMenu(this); + + Menu->addAction(mPartsToolBar->toggleViewAction()); + Menu->addAction(mPropertiesToolBar->toggleViewAction()); + Menu->addSeparator(); + Menu->addAction(mStandardToolBar->toggleViewAction()); + Menu->addAction(mToolsToolBar->toggleViewAction()); + Menu->addAction(mTimeToolBar->toggleViewAction()); + + return Menu; +} + +void lcMainWindow::ClipboardChanged() +{ + const QString MimeType = QLatin1String("application/vnd.leocad-clipboard"); + const QMimeData* MimeData = QApplication::clipboard()->mimeData(); + QByteArray ClipboardData; + + if (MimeData->hasFormat(MimeType)) + ClipboardData = MimeData->data(MimeType); + + g_App->SetClipboard(ClipboardData); +} + +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::PartsTreeItemChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous) +{ + if (!Current) + return; + + PieceInfo* Info = (PieceInfo*)Current->data(0, lcQPartsTree::PieceInfoRole).value(); + + if (Info) + mPreviewWidget->SetCurrentPiece(Info); +} + +void lcMainWindow::ColorChanged(int ColorIndex) +{ + SetColorIndex(ColorIndex); +} + +void lcMainWindow::PartSearchReturn() +{ + mPartsTree->searchParts(mPartSearchEdit->text()); +} + +void lcMainWindow::PartSearchChanged(const QString& Text) +{ + const QByteArray TextConv = Text.toLocal8Bit(); + const char* SearchString = TextConv.data(); + int Length = strlen(SearchString); + + if (!Length) + return; + + lcPiecesLibrary* Library = lcGetPiecesLibrary(); + PieceInfo* BestMatch = NULL; + + for (int PartIdx = 0; PartIdx < Library->mPieces.GetSize(); PartIdx++) + { + PieceInfo* Info = Library->mPieces[PartIdx]; + + if (strncasecmp(SearchString, Info->m_strDescription, Length) == 0) + { + if (!BestMatch || strcasecmp(BestMatch->m_strDescription, Info->m_strDescription) > 0) + BestMatch = Info; + } + else if (strncasecmp(SearchString, Info->m_strName, Length) == 0) + { + if (!BestMatch || strcasecmp(BestMatch->m_strName, Info->m_strName) > 0) + BestMatch = Info; + } + } + + if (BestMatch) + mPartsTree->setCurrentPart(BestMatch); +} + +void lcMainWindow::Print(QPrinter* Printer) +{ + lcModel* Model = lcGetActiveModel(); + int DocCopies; + int PageCopies; + + int Rows = lcGetProfileInt(LC_PROFILE_PRINT_ROWS); + int Columns = lcGetProfileInt(LC_PROFILE_PRINT_COLUMNS); + int StepsPerPage = Rows * Columns; + int PageCount = (Model->GetLastStep() + StepsPerPage - 1) / StepsPerPage; + + 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; + } + + mPreviewWidget->MakeCurrent(); + lcContext* Context = mPreviewWidget->mContext; + + QRect PageRect = Printer->pageRect(); + + int StepWidth = PageRect.width() / Columns; + int StepHeight = PageRect.height() / Rows; + + GLint MaxTexture; + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &MaxTexture); + + MaxTexture = qMin(MaxTexture, 2048); + + int TileWidth = qMin(StepWidth, MaxTexture); + int TileHeight = qMin(StepHeight, MaxTexture); + float AspectRatio = (float)StepWidth / (float)StepHeight; + + View View(Model); + View.SetCamera(GetActiveView()->mCamera, false); + View.mWidth = TileWidth; + View.mHeight = TileHeight; + View.SetContext(Context); + + Context->BeginRenderToTexture(TileWidth, TileHeight); + + lcStep PreviousTime = Model->GetCurrentStep(); + + QPainter Painter(Printer); + lcuint8* Buffer = (lcuint8*)malloc(TileWidth * TileHeight * 4); + // 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) + { + free(Buffer); + Model->SetCurrentStep(PreviousTime); + Context->EndRenderToTexture(); + return; + } + + lcStep CurrentStep = 1 + ((Page - 1) * Rows * Columns); + + for (int Row = 0; Row < Rows; Row++) + { + for (int Column = 0; Column < Columns; Column++) + { + if (CurrentStep > Model->GetLastStep()) + break; + + Model->SetCurrentStep(CurrentStep); + + if (StepWidth > TileWidth || StepHeight > TileHeight) + { + lcuint8* ImageBuffer = (lcuint8*)malloc(StepWidth * StepHeight * 4); + + lcCamera* Camera = View.mCamera; + Camera->StartTiledRendering(TileWidth, TileHeight, StepWidth, StepHeight, AspectRatio); + do + { + View.OnDraw(); + + int TileRow, TileColumn, CurrentTileWidth, CurrentTileHeight; + Camera->GetTileInfo(&TileRow, &TileColumn, &CurrentTileWidth, &CurrentTileHeight); + + glFinish(); + glReadPixels(0, 0, CurrentTileWidth, CurrentTileHeight, GL_RGBA, GL_UNSIGNED_BYTE, Buffer); + + lcuint32 TileY = 0; + if (TileRow != 0) + TileY = TileRow * TileHeight - (TileHeight - StepHeight % TileHeight); + + lcuint32 tileStart = ((TileColumn * TileWidth) + (TileY * StepWidth)) * 4; + + for (int y = 0; y < CurrentTileHeight; y++) + { + lcuint8* src = Buffer + (CurrentTileHeight - y - 1) * CurrentTileWidth * 4; + lcuint8* dst = ImageBuffer + tileStart + y * StepWidth * 4; + + for (int x = 0; x < CurrentTileWidth; x++) + { + *dst++ = src[2]; + *dst++ = src[1]; + *dst++ = src[0]; + *dst++ = 255; + + src += 4; + } + } + } while (Camera->EndTile()); + + QImage Image = QImage((const lcuint8*)ImageBuffer, StepWidth, StepHeight, QImage::Format_ARGB32_Premultiplied); + + QRect Rect = Painter.viewport(); + int Left = Rect.x() + (StepWidth * Column); + int Bottom = Rect.y() + (StepHeight * Row); + + Painter.drawImage(Left, Bottom, Image); + + free(ImageBuffer); + } + else + { + View.OnDraw(); + + glFinish(); + glReadPixels(0, 0, TileWidth, TileHeight, GL_RGBA, GL_UNSIGNED_BYTE, Buffer); + + for (int y = 0; y < (TileHeight + 1) / 2; y++) + { + lcuint8* Top = (lcuint8*)Buffer + ((TileHeight - y - 1) * TileWidth * 4); + lcuint8* Bottom = (lcuint8*)Buffer + y * TileWidth * 4; + + for (int x = 0; x < TileWidth; x++) + { + lcuint8 Red = Top[0]; + lcuint8 Green = Top[1]; + lcuint8 Blue = Top[2]; + lcuint8 Alpha = 255;//top[3]; + + Top[0] = Bottom[2]; + Top[1] = Bottom[1]; + Top[2] = Bottom[0]; + Top[3] = 255;//Bottom[3]; + + Bottom[0] = Blue; + Bottom[1] = Green; + Bottom[2] = Red; + Bottom[3] = Alpha; + + Top += 4; + Bottom +=4; + } + } + + QImage image = QImage((const lcuint8*)Buffer, TileWidth, TileHeight, QImage::Format_ARGB32); + + QRect rect = Painter.viewport(); + int left = rect.x() + (StepWidth * Column); + int bottom = rect.y() + (StepHeight * Row); + + Painter.drawImage(left, bottom, image); + } + + // 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); + + QRect Rect = Painter.viewport(); + int Left = Rect.x() + (StepWidth * Column); + int Right = Rect.x() + (StepWidth * (Column + 1)); + int Top = Rect.y() + (StepHeight * Row); + int Bottom = Rect.y() + (StepHeight * (Row + 1)); + +// if (print text) + { + QFont Font("Helvetica", Printer->resolution()); + Painter.setFont(Font); + + QFontMetrics FontMetrics(Font); + + int TextTop = Top + Printer->resolution() / 2 + FontMetrics.ascent(); + int TextLeft = Left + Printer->resolution() / 2; + + Painter.drawText(TextLeft, TextTop, QString::number(CurrentStep)); + } + +// if (print border) + { + QPen BlackPen(Qt::black, 2); + Painter.setPen(BlackPen); + + if (Row == 0) + Painter.drawLine(Left, Top, Right, Top); + if (Column == 0) + Painter.drawLine(Left, Top, Left, Bottom); + Painter.drawLine(Left, Bottom, Right, Bottom); + Painter.drawLine(Right, Top, Right, Bottom); + } + + CurrentStep++; + } + } + + // TODO: print header and footer + + if (PageCopy < PageCopies - 1) + Printer->newPage(); + } + + if (Page == ToPage) + break; + + if (Ascending) + Page++; + else + Page--; + + Printer->newPage(); + } + + if (DocCopy < DocCopies - 1) + Printer->newPage(); + } + + free(Buffer); + + Model->SetCurrentStep(PreviousTime); + + Context->EndRenderToTexture(); +} + +void lcMainWindow::ShowPrintDialog() +{ + lcModel* Model = lcGetActiveModel(); + int Rows = lcGetProfileInt(LC_PROFILE_PRINT_ROWS); + int Columns = lcGetProfileInt(LC_PROFILE_PRINT_COLUMNS); + int StepsPerPage = Rows * Columns; + int PageCount = (Model->GetLastStep() + StepsPerPage - 1) / StepsPerPage; + + QPrinter Printer(QPrinter::HighResolution); + Printer.setFromTo(1, PageCount + 1); + + QPrintDialog PrintDialog(&Printer, this); + + if (PrintDialog.exec() == QDialog::Accepted) + Print(&Printer); +} + int lcMainWindow::DoMessageBox(const char* Text, const char* Caption, int Flags) { QMessageBox::StandardButton Result; @@ -88,19 +984,19 @@ int lcMainWindow::DoMessageBox(const char* Text, const char* Caption, int Flags) { default: case LC_MB_ICONINFORMATION: - Result = QMessageBox::information(mHandle, Caption, Text, Buttons); + Result = QMessageBox::information(this, Caption, Text, Buttons); break; case LC_MB_ICONQUESTION: - Result = QMessageBox::question(mHandle, Caption, Text, Buttons); + Result = QMessageBox::question(this, Caption, Text, Buttons); break; case LC_MB_ICONWARNING: - Result = QMessageBox::warning(mHandle, Caption, Text, Buttons); + Result = QMessageBox::warning(this, Caption, Text, Buttons); break; case LC_MB_ICONERROR: - Result = QMessageBox::critical(mHandle, Caption, Text, Buttons); + Result = QMessageBox::critical(this, Caption, Text, Buttons); break; } @@ -121,6 +1017,21 @@ int lcMainWindow::DoMessageBox(const char* Text, const char* Caption, int Flags) } } +// todo: call dialogs directly +#include "lc_qimagedialog.h" +#include "lc_qhtmldialog.h" +#include "lc_qpovraydialog.h" +#include "lc_qpropertiesdialog.h" +#include "lc_qfinddialog.h" +#include "lc_qselectdialog.h" +#include "lc_qminifigdialog.h" +#include "lc_qarraydialog.h" +#include "lc_qgroupdialog.h" +#include "lc_qeditgroupsdialog.h" +#include "lc_qpreferencesdialog.h" +#include "lc_qupdatedialog.h" +#include "lc_qaboutdialog.h" + bool lcMainWindow::DoDialog(LC_DIALOG_TYPE Type, void* Data) { switch (Type) @@ -135,15 +1046,15 @@ bool lcMainWindow::DoDialog(LC_DIALOG_TYPE Type, void* Data) switch (Type) { case LC_DIALOG_EXPORT_3DSTUDIO: - Result = QFileDialog::getSaveFileName(mHandle, tr("Export 3D Studio"), FileName, tr("3DS Files (*.3ds);;All Files (*.*)")); + Result = QFileDialog::getSaveFileName(this, tr("Export 3D Studio"), FileName, tr("3DS Files (*.3ds);;All Files (*.*)")); break; case LC_DIALOG_EXPORT_BRICKLINK: - Result = QFileDialog::getSaveFileName(mHandle, tr("Export BrickLink"), FileName, tr("XML Files (*.xml);;All Files (*.*)")); + Result = QFileDialog::getSaveFileName(this, tr("Export BrickLink"), FileName, tr("XML Files (*.xml);;All Files (*.*)")); break; case LC_DIALOG_EXPORT_CSV: - Result = QFileDialog::getSaveFileName(mHandle, tr("Export CSV"), FileName, tr("CSV Files (*.csv);;All Files (*.*)")); + Result = QFileDialog::getSaveFileName(this, tr("Export CSV"), FileName, tr("CSV Files (*.csv);;All Files (*.*)")); break; default: @@ -159,86 +1070,85 @@ bool lcMainWindow::DoDialog(LC_DIALOG_TYPE Type, void* Data) case LC_DIALOG_SAVE_IMAGE: { - lcQImageDialog Dialog(mHandle, Data); + lcQImageDialog Dialog(this, Data); return Dialog.exec() == QDialog::Accepted; } break; case LC_DIALOG_EXPORT_HTML: { - lcQHTMLDialog Dialog(mHandle, Data); + lcQHTMLDialog Dialog(this, Data); return Dialog.exec() == QDialog::Accepted; } break; case LC_DIALOG_EXPORT_POVRAY: { - lcQPOVRayDialog Dialog(mHandle, Data); + lcQPOVRayDialog Dialog(this, Data); return Dialog.exec() == QDialog::Accepted; } break; case LC_DIALOG_PROPERTIES: { - lcQPropertiesDialog Dialog(mHandle, Data); + lcQPropertiesDialog Dialog(this, Data); return Dialog.exec() == QDialog::Accepted; } break; case LC_DIALOG_PRINT: { - lcQMainWindow* MainWindow = (lcQMainWindow*)mHandle; - MainWindow->showPrintDialog(); + ShowPrintDialog(); return true; } break; case LC_DIALOG_FIND: { - lcQFindDialog Dialog(mHandle, Data); + lcQFindDialog Dialog(this, Data); return Dialog.exec() == QDialog::Accepted; } break; case LC_DIALOG_SELECT_BY_NAME: { - lcQSelectDialog Dialog(mHandle, Data); + lcQSelectDialog Dialog(this, Data); return Dialog.exec() == QDialog::Accepted; } break; case LC_DIALOG_MINIFIG: { - lcQMinifigDialog Dialog(mHandle, Data); + lcQMinifigDialog Dialog(this, Data); return Dialog.exec() == QDialog::Accepted; } break; case LC_DIALOG_PIECE_ARRAY: { - lcQArrayDialog Dialog(mHandle, Data); + lcQArrayDialog Dialog(this, Data); return Dialog.exec() == QDialog::Accepted; } break; case LC_DIALOG_PIECE_GROUP: { - lcQGroupDialog Dialog(mHandle, Data); + lcQGroupDialog Dialog(this, Data); return Dialog.exec() == QDialog::Accepted; } break; case LC_DIALOG_EDIT_GROUPS: { - lcQEditGroupsDialog Dialog(mHandle, Data); + lcQEditGroupsDialog Dialog(this, Data); return Dialog.exec() == QDialog::Accepted; } break; case LC_DIALOG_PREFERENCES: { - lcQPreferencesDialog Dialog(mHandle, Data); + lcQPreferencesDialog Dialog(this, Data); return Dialog.exec() == QDialog::Accepted; } break; case LC_DIALOG_ABOUT: { - lcQAboutDialog Dialog(mHandle, Data); + lcQAboutDialog Dialog(this, Data); return Dialog.exec() == QDialog::Accepted; } break; case LC_DIALOG_CHECK_UPDATES: { - lcQUpdateDialog Dialog(mHandle, Data); + lcQUpdateDialog Dialog(this, Data); return Dialog.exec() == QDialog::Accepted; } break; } @@ -296,7 +1206,11 @@ void lcMainWindow::SetTool(lcTool Tool) { mTool = Tool; - UpdateAction(mTool); + QAction* Action = mActions[LC_EDIT_ACTION_FIRST + mTool]; + + if (Action) + Action->setChecked(true); + UpdateAllViews(); } @@ -353,6 +1267,156 @@ void lcMainWindow::SetRelativeTransform(bool RelativeTransform) UpdateAllViews(); } +void lcMainWindow::SetTransformType(lcTransformType TransformType) +{ + mTransformType = TransformType; + + const char* IconNames[] = + { + ":/resources/edit_transform_absolute_translation.png", + ":/resources/edit_transform_relative_translation.png", + ":/resources/edit_transform_absolute_rotation.png", + ":/resources/edit_transform_relative_rotation.png" + }; + + if (TransformType >= 0 && TransformType <= 3) + { + mActions[LC_EDIT_TRANSFORM_ABSOLUTE_TRANSLATION + TransformType]->setChecked(true); + mActions[LC_EDIT_TRANSFORM]->setIcon(QIcon(IconNames[TransformType])); + } +} + +lcVector3 lcMainWindow::GetTransformAmount() +{ + lcVector3 Transform; + + Transform.x = mTransformXEdit->text().toFloat(); + Transform.y = mTransformYEdit->text().toFloat(); + Transform.z = mTransformZEdit->text().toFloat(); + + return Transform; +} + +void lcMainWindow::SplitView(Qt::Orientation Orientation) +{ + QWidget* Focus = focusWidget(); + + if (typeid(*Focus) != typeid(lcQGLWidget)) + return; + + QWidget* Parent = Focus->parentWidget(); + QSplitter* Splitter; + QList Sizes; + + if (Parent == centralWidget()) + { + Splitter = new QSplitter(Orientation, Parent); + Parent->layout()->addWidget(Splitter); + Splitter->addWidget(Focus); + Splitter->addWidget(new lcQGLWidget(centralWidget(), mPiecePreviewWidget, new View(lcGetActiveModel()), true)); + } + else + { + QSplitter* ParentSplitter = (QSplitter*)Parent; + Sizes = ParentSplitter->sizes(); + int FocusIndex = ParentSplitter->indexOf(Focus); + + Splitter = new QSplitter(Orientation, Parent); + ParentSplitter->insertWidget(FocusIndex, Splitter); + Splitter->addWidget(Focus); + Splitter->addWidget(new lcQGLWidget(centralWidget(), mPiecePreviewWidget, new View(lcGetActiveModel()), true)); + + ParentSplitter->setSizes(Sizes); + } + + Sizes.clear(); + Sizes.append(10); + Sizes.append(10); + Splitter->setSizes(Sizes); +} + +void lcMainWindow::SplitHorizontal() +{ + SplitView(Qt::Vertical); +} + +void lcMainWindow::SplitVertical() +{ + SplitView(Qt::Horizontal); +} + +void lcMainWindow::RemoveActiveView() +{ + QWidget* Focus = focusWidget(); + + if (typeid(*Focus) != typeid(lcQGLWidget)) + return; + + QWidget* Parent = Focus->parentWidget(); + + if (Parent == centralWidget()) + return; + + QWidget* ParentParentWidget = Parent->parentWidget(); + QSplitter* ParentSplitter = (QSplitter*)Parent; + int FocusIndex = ParentSplitter->indexOf(Focus); + + if (ParentParentWidget == centralWidget()) + { + QLayout* CentralLayout = ParentParentWidget->layout(); + + CentralLayout->addWidget(ParentSplitter->widget(!FocusIndex)); + CentralLayout->removeWidget(Parent); + + return; + } + + QSplitter* ParentParentSplitter = (QSplitter*)ParentParentWidget; + QList Sizes = ParentParentSplitter->sizes(); + + int ParentIndex = ParentParentSplitter->indexOf(Parent); + ParentParentSplitter->insertWidget(!ParentIndex, Focus); + + delete Parent; + + ParentParentSplitter->setSizes(Sizes); +} + +void lcMainWindow::ResetViews() +{ + QLayout* CentralLayout = centralWidget()->layout(); + delete CentralLayout->itemAt(0)->widget(); + CentralLayout->addWidget(new lcQGLWidget(centralWidget(), mPiecePreviewWidget, new View(lcGetActiveModel()), true)); +} + +void lcMainWindow::TogglePrintPreview() +{ + // todo: print preview inside main window + + lcModel* Model = lcGetActiveModel(); + int Rows = lcGetProfileInt(LC_PROFILE_PRINT_ROWS); + int Columns = lcGetProfileInt(LC_PROFILE_PRINT_COLUMNS); + int StepsPerPage = Rows * Columns; + int PageCount = (Model->GetLastStep() + StepsPerPage - 1) / StepsPerPage; + + QPrinter Printer(QPrinter::ScreenResolution); + Printer.setFromTo(1, PageCount + 1); + + QPrintPreviewDialog Preview(&Printer, this); + connect(&Preview, SIGNAL(paintRequested(QPrinter*)), SLOT(Print(QPrinter*))); + Preview.exec(); +} + +void lcMainWindow::ToggleFullScreen() +{ + // todo: hide toolbars and menu + // todo: create fullscreen toolbar or support esc key to go back + if (isFullScreen()) + showNormal(); + else + showFullScreen(); +} + void lcMainWindow::AddRecentFile(const QString& FileName) { QString SavedName = FileName; @@ -382,6 +1446,262 @@ void lcMainWindow::RemoveRecentFile(int FileIndex) UpdateRecentFiles(); } +void lcMainWindow::UpdateFocusObject(lcObject* Focus) +{ + mPropertiesWidget->updateFocusObject(Focus); + + lcVector3 Position; + lcGetActiveModel()->GetFocusPosition(Position); + + QString Label("X: %1 Y: %2 Z: %3"); + Label = Label.arg(QString::number(Position[0], 'f', 2), QString::number(Position[1], 'f', 2), QString::number(Position[2], 'f', 2)); + mStatusPositionLabel->setText(Label); +} + +void lcMainWindow::UpdateSelectedObjects(int Flags, int SelectedCount, lcObject* Focus) +{ + 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); + 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); + mActions[LC_PIECE_ARRAY]->setEnabled(Flags & LC_SEL_PIECE); + mActions[LC_PIECE_HIDE_SELECTED]->setEnabled(Flags & LC_SEL_PIECE); + mActions[LC_PIECE_UNHIDE_ALL]->setEnabled(Flags & LC_SEL_HIDDEN); + mActions[LC_PIECE_HIDE_UNSELECTED]->setEnabled(Flags & LC_SEL_UNSELECTED); + 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); + + QString Message; + + if ((SelectedCount == 1) && Focus) + { + if (Focus->IsPiece()) + Message = QString("%1 (ID: %2)").arg(Focus->GetName(), ((lcPiece*)Focus)->mPieceInfo->m_strName); + else + Message = Focus->GetName(); + } + else if (SelectedCount > 0) + { + if (SelectedCount == 1) + Message = "1 Object selected"; + else + Message = QString("%1 Objects selected").arg(QString::number(SelectedCount)); + + if (Focus && Focus->IsPiece()) + { + Message.append(QString(" - %1 (ID: %2)").arg(Focus->GetName(), ((lcPiece*)Focus)->mPieceInfo->m_strName)); + + const lcGroup* Group = ((lcPiece*)Focus)->GetGroup(); + if (Group && Group->m_strName[0]) + Message.append(QString(" in group '%1'").arg(Group->m_strName)); + } + } + + mStatusBarLabel->setText(Message); +} + +void lcMainWindow::UpdatePaste(bool Enabled) +{ + QAction* Action = mActions[LC_EDIT_PASTE]; + + if (Action) + Action->setEnabled(Enabled); +} + +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() +{ + mActions[LC_EDIT_TRANSFORM_RELATIVE]->setChecked(GetRelativeTransform()); + mActions[LC_EDIT_LOCK_X]->setChecked(GetLockX()); + mActions[LC_EDIT_LOCK_Y]->setChecked(GetLockY()); + mActions[LC_EDIT_LOCK_Z]->setChecked(GetLockZ()); +} + +void lcMainWindow::UpdateSnap() +{ + mActions[LC_EDIT_SNAP_MOVE_XY0 + GetMoveXYSnapIndex()]->setChecked(true); + mActions[LC_EDIT_SNAP_MOVE_Z0 + GetMoveZSnapIndex()]->setChecked(true); + mActions[LC_EDIT_SNAP_ANGLE0 + GetAngleSnapIndex()]->setChecked(true); + + mStatusSnapLabel->setText(QString(tr(" M: %1 %2 R: %3 ")).arg(GetMoveXYSnapText(), GetMoveZSnapText(), QString::number(GetAngleSnap()))); +} + +void lcMainWindow::UpdateColor() +{ + mColorList->setCurrentColor(mColorIndex); +} + +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")); + } +} + +void lcMainWindow::UpdateCameraMenu() +{ + const lcArray& Cameras = lcGetActiveModel()->GetCameras(); + lcCamera* CurrentCamera = mActiveView->mCamera; + int CurrentIndex = -1; + + for (int ActionIdx = LC_VIEW_CAMERA_FIRST; ActionIdx <= LC_VIEW_CAMERA_LAST; ActionIdx++) + { + QAction* Action = mActions[ActionIdx]; + int CameraIdx = ActionIdx - LC_VIEW_CAMERA_FIRST; + + if (CameraIdx < Cameras.GetSize()) + { + if (CurrentCamera == Cameras[CameraIdx]) + CurrentIndex = CameraIdx; + + Action->setText(Cameras[CameraIdx]->GetName()); + Action->setVisible(true); + } + else + Action->setVisible(false); + } + + UpdateCurrentCamera(CurrentIndex); +} + +void lcMainWindow::UpdateCurrentCamera(int CameraIndex) +{ + int ActionIndex = LC_VIEW_CAMERA_FIRST + CameraIndex; + + if (ActionIndex < LC_VIEW_CAMERA_FIRST || ActionIndex > LC_VIEW_CAMERA_LAST) + ActionIndex = LC_VIEW_CAMERA_NONE; + + mActions[ActionIndex]->setChecked(true); +} + +void lcMainWindow::UpdatePerspective() +{ + if (mActiveView->mCamera->IsOrtho()) + mActions[LC_VIEW_PROJECTION_ORTHO]->setChecked(true); + else + mActions[LC_VIEW_PROJECTION_PERSPECTIVE]->setChecked(true); +} + +void lcMainWindow::UpdateModels() +{ + const lcArray& Models = lcGetActiveProject()->GetModels(); + lcModel* CurrentModel = lcGetActiveModel(); + + for (int ActionIdx = LC_MODEL_FIRST; ActionIdx <= LC_MODEL_LAST; ActionIdx++) + { + QAction* Action = mActions[ActionIdx]; + int ModelIdx = ActionIdx - LC_MODEL_FIRST; + + if (ModelIdx < Models.GetSize()) + { + Action->setChecked(CurrentModel == Models[ModelIdx]); + Action->setText(QString::fromLatin1("&%1 %2").arg(QString::number(ModelIdx + 1), Models[ModelIdx]->GetProperties().mName)); + Action->setVisible(true); + } + else + Action->setVisible(false); + } + + mPartsTree->UpdateModels(); +} + +void lcMainWindow::UpdateCategories() +{ + mPartsTree->updateCategories(); +} + +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++) + mActions[ActionIdx]->setShortcut(QKeySequence(gKeyboardShortcuts.Shortcuts[ActionIdx])); +} + void lcMainWindow::NewProject() { if (!SaveProjectIfModified()) @@ -405,7 +1725,7 @@ bool lcMainWindow::OpenProject(const QString& FileName) if (LoadFileName.isEmpty()) LoadFileName = lcGetProfileString(LC_PROFILE_PROJECTS_PATH); - LoadFileName = QFileDialog::getOpenFileName(mHandle, tr("Open Project"), LoadFileName, tr("Supported Files (*.lcd *.ldr *.dat *.mpd);;All Files (*.*)")); + LoadFileName = QFileDialog::getOpenFileName(this, tr("Open Project"), LoadFileName, tr("Supported Files (*.lcd *.ldr *.dat *.mpd);;All Files (*.*)")); if (LoadFileName.isEmpty()) return false; @@ -430,12 +1750,12 @@ bool lcMainWindow::OpenProject(const QString& FileName) View->ZoomExtents(); } - gMainWindow->UpdateAllViews(); + UpdateAllViews(); return true; } - QMessageBox::information(mHandle, tr("LeoCAD"), tr("Error loading '%1'.").arg(LoadFileName)); + QMessageBox::information(this, tr("LeoCAD"), tr("Error loading '%1'.").arg(LoadFileName)); delete NewProject; return false; @@ -448,7 +1768,7 @@ void lcMainWindow::MergeProject() if (LoadFileName.isEmpty()) LoadFileName = lcGetProfileString(LC_PROFILE_PROJECTS_PATH); - LoadFileName = QFileDialog::getOpenFileName(mHandle, tr("Open Project"), LoadFileName, tr("Supported Files (*.lcd *.ldr *.dat *.mpd);;All Files (*.*)")); + LoadFileName = QFileDialog::getOpenFileName(this, tr("Open Project"), LoadFileName, tr("Supported Files (*.lcd *.ldr *.dat *.mpd);;All Files (*.*)")); if (LoadFileName.isEmpty()) return; @@ -462,13 +1782,13 @@ void lcMainWindow::MergeProject() lcGetActiveProject()->Merge(NewProject); if (NumModels == 1) - QMessageBox::information(mHandle, tr("LeoCAD"), tr("Merged 1 model.")); + QMessageBox::information(this, tr("LeoCAD"), tr("Merged 1 model.")); else - QMessageBox::information(mHandle, tr("LeoCAD"), tr("Merged %1 models.").arg(NumModels)); + QMessageBox::information(this, tr("LeoCAD"), tr("Merged %1 models.").arg(NumModels)); } else { - QMessageBox::information(mHandle, tr("LeoCAD"), tr("Error loading '%1'.").arg(LoadFileName)); + QMessageBox::information(this, tr("LeoCAD"), tr("Error loading '%1'.").arg(LoadFileName)); delete NewProject; } } @@ -487,7 +1807,7 @@ bool lcMainWindow::SaveProject(const QString& FileName) if (SaveFileName.isEmpty()) SaveFileName = QFileInfo(QDir(lcGetProfileString(LC_PROFILE_PROJECTS_PATH)), Project->GetTitle()).absoluteFilePath(); - SaveFileName = QFileDialog::getSaveFileName(mHandle, tr("Save Project"), SaveFileName, tr("Supported Files (*.ldr *.dat *.mpd);;All Files (*.*)")); + SaveFileName = QFileDialog::getSaveFileName(this, tr("Save Project"), SaveFileName, tr("Supported Files (*.ldr *.dat *.mpd);;All Files (*.*)")); if (SaveFileName.isEmpty()) return false; @@ -495,7 +1815,7 @@ bool lcMainWindow::SaveProject(const QString& FileName) if (QFileInfo(SaveFileName).suffix().toLower() == QLatin1String("lcd")) { - QMessageBox::warning(mHandle, tr("Error"), tr("Saving files in LCD format is no longer supported, please use the LDR format instead.")); + QMessageBox::warning(this, tr("Error"), tr("Saving files in LCD format is no longer supported, please use the LDR format instead.")); return false; } @@ -514,7 +1834,7 @@ bool lcMainWindow::SaveProjectIfModified() if (!Project->IsModified()) return true; - switch (QMessageBox::question(mHandle, tr("Save Project"), tr("Save changes to '%1'?").arg(Project->GetTitle()), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel)) + switch (QMessageBox::question(this, tr("Save Project"), tr("Save changes to '%1'?").arg(Project->GetTitle()), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel)) { default: case QMessageBox::Cancel: @@ -605,7 +1925,7 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId) break; case LC_FILE_EXIT: - Close(); + close(); break; case LC_EDIT_UNDO: @@ -629,7 +1949,7 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId) break; case LC_EDIT_FIND: - if (gMainWindow->DoDialog(LC_DIALOG_FIND, &gMainWindow->mSearchOptions)) + if (DoDialog(LC_DIALOG_FIND, &mSearchOptions)) lcGetActiveModel()->FindPiece(true, true); break; @@ -666,7 +1986,7 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId) break; case LC_VIEW_REMOVE_VIEW: - RemoveView(); + RemoveActiveView(); break; case LC_VIEW_RESET_VIEWS: diff --git a/common/lc_mainwindow.h b/common/lc_mainwindow.h index 990ab7c5..a9b0d8ce 100644 --- a/common/lc_mainwindow.h +++ b/common/lc_mainwindow.h @@ -8,6 +8,10 @@ class View; class PiecePreview; +class lcQGLWidget; +class lcQPartsTree; +class lcQColorList; +class lcQPropertiesTree; #define LC_MAX_RECENT_FILES 4 @@ -21,14 +25,16 @@ struct lcSearchOptions char Name[256]; }; -class lcMainWindow +class lcMainWindow : public QMainWindow { - Q_DECLARE_TR_FUNCTIONS(lcBaseWindow) + Q_OBJECT public: lcMainWindow(); ~lcMainWindow(); + void CreateWidgets(); + lcTool GetTool() const { return mTool; @@ -145,7 +151,6 @@ public: void SetLockZ(bool LockZ); void SetRelativeTransform(bool RelativeTransform); - void Close(); void NewProject(); bool OpenProject(const QString& FileName); void MergeProject(); @@ -158,7 +163,7 @@ public: void SplitHorizontal(); void SplitVertical(); - void RemoveView(); + void RemoveActiveView(); void ResetViews(); void TogglePrintPreview(); @@ -166,7 +171,6 @@ public: void UpdateFocusObject(lcObject* Focus); void UpdateSelectedObjects(int Flags, int SelectedCount, lcObject* Focus); - void UpdateAction(int NewAction); void UpdatePaste(bool Enabled); void UpdateCurrentStep(); void SetAddKeys(bool AddKeys); @@ -190,10 +194,28 @@ public: PiecePreview* mPreviewWidget; int mColorIndex; lcSearchOptions mSearchOptions; + QAction* mActions[LC_NUM_COMMANDS]; - QWidget* mHandle; +protected slots: + void ClipboardChanged(); + void ActionTriggered(); + void PartsTreeItemChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous); + void ColorChanged(int ColorIndex); + void PartSearchReturn(); + void PartSearchChanged(const QString& Text); + void Print(QPrinter* Printer); protected: + void closeEvent(QCloseEvent *event); + QMenu* createPopupMenu(); + + void CreateActions(); + void CreateMenus(); + void CreateToolBars(); + void CreateStatusBar(); + void SplitView(Qt::Orientation Orientation); + void ShowPrintDialog(); + View* mActiveView; lcArray mViews; @@ -207,6 +229,28 @@ protected: bool mLockY; bool mLockZ; bool mRelativeTransform; + + QAction* mActionFileRecentSeparator; + + QToolBar* mStandardToolBar; + QToolBar* mToolsToolBar; + QToolBar* mTimeToolBar; + QDockWidget* mPartsToolBar; + QDockWidget* mPropertiesToolBar; + + lcQGLWidget* mPiecePreviewWidget; + lcQPartsTree* mPartsTree; + QLineEdit* mPartSearchEdit; + lcQColorList* mColorList; + lcQPropertiesTree* mPropertiesWidget; + QLineEdit* mTransformXEdit; + QLineEdit* mTransformYEdit; + QLineEdit* mTransformZEdit; + + QLabel* mStatusBarLabel; + QLabel* mStatusPositionLabel; + QLabel* mStatusSnapLabel; + QLabel* mStatusTimeLabel; }; extern class lcMainWindow* gMainWindow; diff --git a/common/project.cpp b/common/project.cpp index 64375dec..fe5e61ff 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -109,7 +109,7 @@ void Project::CreateNewModel() { bool Ok = false; - Name = QInputDialog::getText(gMainWindow->mHandle, tr("New Model"), tr("Name:"), QLineEdit::Normal, Name, &Ok); + Name = QInputDialog::getText(gMainWindow, tr("New Model"), tr("Name:"), QLineEdit::Normal, Name, &Ok); if (!Ok) return; @@ -118,9 +118,9 @@ void Project::CreateNewModel() break; if (Name.isEmpty()) - QMessageBox::information(gMainWindow->mHandle, tr("Empty Name"), tr("The model name cannot be empty.")); + QMessageBox::information(gMainWindow, tr("Empty Name"), tr("The model name cannot be empty.")); else - QMessageBox::information(gMainWindow->mHandle, tr("Duplicate Model"), tr("A model named '%1' already exists in this project, please enter an unique name.").arg(Name)); + QMessageBox::information(gMainWindow, tr("Duplicate Model"), tr("A model named '%1' already exists in this project, please enter an unique name.").arg(Name)); } if (!Name.isEmpty()) @@ -146,7 +146,7 @@ void Project::ShowModelListDialog() Models.append(QPair(Model->GetProperties().mName, Model)); } - lcQModelListDialog Dialog(gMainWindow->mHandle, Models); + lcQModelListDialog Dialog(gMainWindow, Models); if (Dialog.exec() != QDialog::Accepted || Models.isEmpty()) return; @@ -197,7 +197,7 @@ bool Project::Load(const QString& FileName) if (!File.open(QIODevice::ReadOnly)) { - QMessageBox::warning(gMainWindow->mHandle, tr("Error"), tr("Error reading file '%1':\n%2").arg(FileName, File.errorString())); + QMessageBox::warning(gMainWindow, tr("Error"), tr("Error reading file '%1':\n%2").arg(FileName, File.errorString())); return false; } @@ -263,7 +263,7 @@ bool Project::Save(const QString& FileName) if (!File.open(QIODevice::WriteOnly)) { - QMessageBox::warning(gMainWindow->mHandle, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString())); + QMessageBox::warning(gMainWindow, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString())); return false; } @@ -1072,7 +1072,7 @@ void Project::ExportHTML() if (!File.open(QIODevice::WriteOnly)) { - QMessageBox::warning(gMainWindow->mHandle, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString())); + QMessageBox::warning(gMainWindow, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString())); return; } @@ -1103,7 +1103,7 @@ void Project::ExportHTML() if (!File.open(QIODevice::WriteOnly)) { - QMessageBox::warning(gMainWindow->mHandle, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString())); + QMessageBox::warning(gMainWindow, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString())); return; } @@ -1128,7 +1128,7 @@ void Project::ExportHTML() if (!File.open(QIODevice::WriteOnly)) { - QMessageBox::warning(gMainWindow->mHandle, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString())); + QMessageBox::warning(gMainWindow, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString())); return; } @@ -1162,7 +1162,7 @@ void Project::ExportHTML() if (!File.open(QIODevice::WriteOnly)) { - QMessageBox::warning(gMainWindow->mHandle, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString())); + QMessageBox::warning(gMainWindow, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, File.errorString())); return; } @@ -1570,7 +1570,7 @@ void Project::ExportWavefront(const QString& FileName) QString SaveFileName = FileName; if (SaveFileName.isEmpty()) { - SaveFileName = QFileDialog::getSaveFileName(gMainWindow->mHandle, tr("Export Wavefront"), SaveFileName, tr("Wavefront Files (*.obj);;All Files (*.*)")); + SaveFileName = QFileDialog::getSaveFileName(gMainWindow, tr("Export Wavefront"), SaveFileName, tr("Wavefront Files (*.obj);;All Files (*.*)")); if (SaveFileName.isEmpty()) return; diff --git a/leocad.pro b/leocad.pro index 2b0f0cdc..50a75d14 100644 --- a/leocad.pro +++ b/leocad.pro @@ -146,7 +146,6 @@ SOURCES += common/view.cpp \ common/group.cpp \ common/debug.cpp \ common/camera.cpp \ - qt/lc_qmainwindow.cpp \ qt/system.cpp \ qt/qtmain.cpp \ qt/lc_qpovraydialog.cpp \ @@ -210,7 +209,6 @@ HEADERS += \ common/group.h \ common/debug.h \ common/camera.h \ - qt/lc_qmainwindow.h \ qt/lc_config.h \ qt/lc_qpovraydialog.h \ qt/lc_qarraydialog.h \ diff --git a/qt/lc_qglwidget.cpp b/qt/lc_qglwidget.cpp index dd84579d..73ee1c41 100644 --- a/qt/lc_qglwidget.cpp +++ b/qt/lc_qglwidget.cpp @@ -4,7 +4,6 @@ #include "project.h" #include "lc_library.h" #include "lc_application.h" -#include "lc_qmainwindow.h" #include "lc_mainwindow.h" #include "lc_context.h" #include "view.h" @@ -38,9 +37,7 @@ void* lcGLWidget::GetExtensionAddress(const char* FunctionName) void lcGLWidget::ShowPopupMenu() { QGLWidget* Widget = (QGLWidget*)mWidget; - - lcQMainWindow *mainWindow = (lcQMainWindow*)gMainWindow->mHandle; - QAction **actions = mainWindow->actions; + QAction **actions = gMainWindow->mActions; QMenu *popup = new QMenu(Widget); diff --git a/qt/lc_qmainwindow.cpp b/qt/lc_qmainwindow.cpp deleted file mode 100644 index 6eabe6e0..00000000 --- a/qt/lc_qmainwindow.cpp +++ /dev/null @@ -1,1336 +0,0 @@ -#include "lc_global.h" -#include -#include -#include -#include "lc_qmainwindow.h" -#include "lc_qutils.h" -#include "lc_qglwidget.h" -#include "lc_library.h" -#include "lc_application.h" -#include "pieceinf.h" -#include "project.h" -#include "preview.h" -#include "piece.h" -#include "camera.h" -#include "view.h" -#include "group.h" -#include "lc_qpartstree.h" -#include "lc_qcolorlist.h" -#include "lc_qpropertiestree.h" -#include "lc_shortcuts.h" -#include "system.h" -#include "lc_mainwindow.h" -#include "lc_profile.h" - -lcQMainWindow::lcQMainWindow(QWidget *parent) - : QMainWindow(parent) -{ - memset(actions, 0, sizeof(actions)); - - setWindowIcon(QIcon(":/resources/icon64.png")); - setWindowFilePath(QString()); - - createActions(); - createToolBars(); - createMenus(); - createStatusBar(); - - QFrame *previewFrame = new QFrame; - previewFrame->setFrameShape(QFrame::StyledPanel); - previewFrame->setFrameShadow(QFrame::Sunken); - setCentralWidget(previewFrame); - - QGridLayout *previewLayout = new QGridLayout(previewFrame); - previewLayout->setContentsMargins(0, 0, 0, 0); - - QWidget *viewWidget = new lcQGLWidget(previewFrame, piecePreview, new View(NULL), true); - previewLayout->addWidget(viewWidget, 0, 0, 1, 1); - - connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardChanged())); - clipboardChanged(); - - PiecePreview* Preview = (PiecePreview*)piecePreview->widget; - gMainWindow->mPreviewWidget = Preview; - - QSettings settings; - settings.beginGroup("MainWindow"); - resize(QSize(800, 600)); - move(QPoint(200, 200)); - restoreGeometry(settings.value("Geometry").toByteArray()); - restoreState(settings.value("State").toByteArray()); - settings.endGroup(); -} - -lcQMainWindow::~lcQMainWindow() -{ -} - -void lcQMainWindow::LibraryLoaded() -{ - lcPiecesLibrary* Library = lcGetPiecesLibrary(); - PieceInfo* Info = Library->FindPiece("3005", false); - - if (!Info) - Info = Library->mPieces[0]; - - if (Info) - gMainWindow->mPreviewWidget->SetCurrentPiece(Info); - - QCompleter *completer = new QCompleter(this); - completer->setModel(new lcQPartsListModel(completer)); - completer->setCaseSensitivity(Qt::CaseInsensitive); - partSearch->setCompleter(completer); -} - -void lcQMainWindow::createActions() -{ - for (int Command = 0; Command < LC_NUM_COMMANDS; Command++) - { - QAction *action = new QAction(tr(gCommands[Command].MenuName), this); - action->setStatusTip(tr(gCommands[Command].StatusText)); - connect(action, SIGNAL(triggered()), this, SLOT(actionTriggered())); - addAction(action); - actions[Command] = action; - } - - actions[LC_FILE_NEW]->setToolTip(tr("New Project")); - actions[LC_FILE_OPEN]->setToolTip(tr("Open Project")); - actions[LC_FILE_SAVE]->setToolTip(tr("Save Project")); - - actions[LC_FILE_NEW]->setIcon(QIcon(":/resources/file_new.png")); - actions[LC_FILE_OPEN]->setIcon(QIcon(":/resources/file_open.png")); - actions[LC_FILE_SAVE]->setIcon(QIcon(":/resources/file_save.png")); - actions[LC_FILE_SAVE_IMAGE]->setIcon(QIcon(":/resources/file_picture.png")); - actions[LC_FILE_PRINT]->setIcon(QIcon(":/resources/file_print.png")); - actions[LC_FILE_PRINT_PREVIEW]->setIcon(QIcon(":/resources/file_print_preview.png")); - actions[LC_EDIT_UNDO]->setIcon(QIcon(":/resources/edit_undo.png")); - actions[LC_EDIT_REDO]->setIcon(QIcon(":/resources/edit_redo.png")); - actions[LC_EDIT_CUT]->setIcon(QIcon(":/resources/edit_cut.png")); - actions[LC_EDIT_COPY]->setIcon(QIcon(":/resources/edit_copy.png")); - actions[LC_EDIT_PASTE]->setIcon(QIcon(":/resources/edit_paste.png")); - actions[LC_EDIT_ACTION_INSERT]->setIcon(QIcon(":/resources/action_insert.png")); - actions[LC_EDIT_ACTION_LIGHT]->setIcon(QIcon(":/resources/action_light.png")); - actions[LC_EDIT_ACTION_SPOTLIGHT]->setIcon(QIcon(":/resources/action_spotlight.png")); - actions[LC_EDIT_ACTION_CAMERA]->setIcon(QIcon(":/resources/action_camera.png")); - actions[LC_EDIT_ACTION_SELECT]->setIcon(QIcon(":/resources/action_select.png")); - actions[LC_EDIT_ACTION_MOVE]->setIcon(QIcon(":/resources/action_move.png")); - actions[LC_EDIT_ACTION_ROTATE]->setIcon(QIcon(":/resources/action_rotate.png")); - actions[LC_EDIT_ACTION_DELETE]->setIcon(QIcon(":/resources/action_delete.png")); - actions[LC_EDIT_ACTION_PAINT]->setIcon(QIcon(":/resources/action_paint.png")); - actions[LC_EDIT_ACTION_ZOOM]->setIcon(QIcon(":/resources/action_zoom.png")); - actions[LC_EDIT_ACTION_PAN]->setIcon(QIcon(":/resources/action_pan.png")); - actions[LC_EDIT_ACTION_ROTATE_VIEW]->setIcon(QIcon(":/resources/action_rotate_view.png")); - actions[LC_EDIT_ACTION_ROLL]->setIcon(QIcon(":/resources/action_roll.png")); - actions[LC_EDIT_ACTION_ZOOM_REGION]->setIcon(QIcon(":/resources/action_zoom_region.png")); - actions[LC_EDIT_TRANSFORM_RELATIVE]->setIcon(QIcon(":/resources/edit_transform_relative.png")); - actions[LC_PIECE_SHOW_EARLIER]->setIcon(QIcon(":/resources/piece_show_earlier.png")); - actions[LC_PIECE_SHOW_LATER]->setIcon(QIcon(":/resources/piece_show_later.png")); - actions[LC_VIEW_SPLIT_HORIZONTAL]->setIcon(QIcon(":/resources/view_split_horizontal.png")); - actions[LC_VIEW_SPLIT_VERTICAL]->setIcon(QIcon(":/resources/view_split_vertical.png")); - actions[LC_VIEW_ZOOM_IN]->setIcon(QIcon(":/resources/view_zoomin.png")); - actions[LC_VIEW_ZOOM_OUT]->setIcon(QIcon(":/resources/view_zoomout.png")); - actions[LC_VIEW_ZOOM_EXTENTS]->setIcon(QIcon(":/resources/view_zoomextents.png")); - actions[LC_VIEW_TIME_FIRST]->setIcon(QIcon(":/resources/time_first.png")); - actions[LC_VIEW_TIME_PREVIOUS]->setIcon(QIcon(":/resources/time_previous.png")); - actions[LC_VIEW_TIME_NEXT]->setIcon(QIcon(":/resources/time_next.png")); - actions[LC_VIEW_TIME_LAST]->setIcon(QIcon(":/resources/time_last.png")); - actions[LC_VIEW_TIME_ADD_KEYS]->setIcon(QIcon(":/resources/time_add_keys.png")); - actions[LC_HELP_HOMEPAGE]->setIcon(QIcon(":/resources/help_homepage.png")); - actions[LC_HELP_EMAIL]->setIcon(QIcon(":/resources/help_email.png")); - - actions[LC_EDIT_LOCK_X]->setCheckable(true); - actions[LC_EDIT_LOCK_Y]->setCheckable(true); - actions[LC_EDIT_LOCK_Z]->setCheckable(true); - actions[LC_EDIT_TRANSFORM_RELATIVE]->setCheckable(true); - actions[LC_VIEW_CAMERA_NONE]->setCheckable(true); - actions[LC_VIEW_TIME_ADD_KEYS]->setCheckable(true); - - QActionGroup *actionSnapXYGroup = new QActionGroup(this); - for (int actionIdx = LC_EDIT_SNAP_MOVE_XY0; actionIdx <= LC_EDIT_SNAP_MOVE_XY9; actionIdx++) - { - actions[actionIdx]->setCheckable(true); - actionSnapXYGroup->addAction(actions[actionIdx]); - } - - QActionGroup *actionSnapZGroup = new QActionGroup(this); - for (int actionIdx = LC_EDIT_SNAP_MOVE_Z0; actionIdx <= LC_EDIT_SNAP_MOVE_Z9; actionIdx++) - { - actions[actionIdx]->setCheckable(true); - actionSnapZGroup->addAction(actions[actionIdx]); - } - - QActionGroup *actionSnapAngleGroup = new QActionGroup(this); - for (int actionIdx = LC_EDIT_SNAP_ANGLE0; actionIdx <= LC_EDIT_SNAP_ANGLE9; actionIdx++) - { - actions[actionIdx]->setCheckable(true); - actionSnapAngleGroup->addAction(actions[actionIdx]); - } - - QActionGroup *actionTransformTypeGroup = new QActionGroup(this); - for (int actionIdx = LC_EDIT_TRANSFORM_ABSOLUTE_TRANSLATION; actionIdx <= LC_EDIT_TRANSFORM_RELATIVE_ROTATION; actionIdx++) - { - actions[actionIdx]->setCheckable(true); - actionTransformTypeGroup->addAction(actions[actionIdx]); - } - - QActionGroup *actionToolGroup = new QActionGroup(this); - for (int actionIdx = LC_EDIT_ACTION_FIRST; actionIdx <= LC_EDIT_ACTION_LAST; actionIdx++) - { - actions[actionIdx]->setCheckable(true); - actionToolGroup->addAction(actions[actionIdx]); - } - - QActionGroup *actionCameraGroup = new QActionGroup(this); - actionCameraGroup->addAction(actions[LC_VIEW_CAMERA_NONE]); - for (int actionIdx = LC_VIEW_CAMERA_FIRST; actionIdx <= LC_VIEW_CAMERA_LAST; actionIdx++) - { - actions[actionIdx]->setCheckable(true); - actionCameraGroup->addAction(actions[actionIdx]); - } - - QActionGroup *actionPerspectiveGroup = new QActionGroup(this); - for (int actionIdx = LC_VIEW_PROJECTION_FIRST; actionIdx <= LC_VIEW_PROJECTION_LAST; actionIdx++) - { - actions[actionIdx]->setCheckable(true); - actionPerspectiveGroup->addAction(actions[actionIdx]); - } - - QActionGroup *menuGroup = new QActionGroup(this); - for (int actionIdx = LC_MODEL_FIRST; actionIdx <= LC_MODEL_LAST; actionIdx++) - { - actions[actionIdx]->setCheckable(true); - menuGroup->addAction(actions[actionIdx]); - } - - updateShortcuts(); -} - -void lcQMainWindow::createMenus() -{ - QMenu* transformMenu = new QMenu(tr("Transform"), this); - transformMenu->addAction(actions[LC_EDIT_TRANSFORM_RELATIVE_TRANSLATION]); - transformMenu->addAction(actions[LC_EDIT_TRANSFORM_ABSOLUTE_TRANSLATION]); - transformMenu->addAction(actions[LC_EDIT_TRANSFORM_RELATIVE_ROTATION]); - transformMenu->addAction(actions[LC_EDIT_TRANSFORM_ABSOLUTE_ROTATION]); - actions[LC_EDIT_TRANSFORM]->setMenu(transformMenu); - - menuCamera = new QMenu(tr("C&ameras"), this); - menuCamera->addAction(actions[LC_VIEW_CAMERA_NONE]); - - for (int actionIdx = LC_VIEW_CAMERA_FIRST; actionIdx <= LC_VIEW_CAMERA_LAST; actionIdx++) - menuCamera->addAction(actions[actionIdx]); - - menuCamera->addSeparator(); - menuCamera->addAction(actions[LC_VIEW_CAMERA_RESET]); - - menuFile = menuBar()->addMenu(tr("&File")); - menuFile->addAction(actions[LC_FILE_NEW]); - menuFile->addAction(actions[LC_FILE_OPEN]); - menuFile->addAction(actions[LC_FILE_MERGE]); - menuFile->addSeparator(); - menuFile->addAction(actions[LC_FILE_SAVE]); - menuFile->addAction(actions[LC_FILE_SAVEAS]); - menuFile->addAction(actions[LC_FILE_SAVE_IMAGE]); - QMenu* exportMenu = menuFile->addMenu(tr("&Export")); - exportMenu->addAction(actions[LC_FILE_EXPORT_3DS]); - exportMenu->addAction(actions[LC_FILE_EXPORT_BRICKLINK]); - exportMenu->addAction(actions[LC_FILE_EXPORT_CSV]); - exportMenu->addAction(actions[LC_FILE_EXPORT_HTML]); - exportMenu->addAction(actions[LC_FILE_EXPORT_POVRAY]); - exportMenu->addAction(actions[LC_FILE_EXPORT_WAVEFRONT]); - menuFile->addSeparator(); - menuFile->addAction(actions[LC_FILE_PRINT]); - menuFile->addAction(actions[LC_FILE_PRINT_PREVIEW]); -// menuFile->addAction(actions[LC_FILE_PRINT_BOM]); - menuFile->addSeparator(); - menuFile->addAction(actions[LC_FILE_RECENT1]); - menuFile->addAction(actions[LC_FILE_RECENT2]); - menuFile->addAction(actions[LC_FILE_RECENT3]); - menuFile->addAction(actions[LC_FILE_RECENT4]); - actionFileRecentSeparator = menuFile->addSeparator(); - menuFile->addAction(actions[LC_FILE_EXIT]); - - menuEdit = menuBar()->addMenu(tr("&Edit")); - menuEdit->addAction(actions[LC_EDIT_UNDO]); - menuEdit->addAction(actions[LC_EDIT_REDO]); - menuEdit->addSeparator(); - menuEdit->addAction(actions[LC_EDIT_CUT]); - menuEdit->addAction(actions[LC_EDIT_COPY]); - menuEdit->addAction(actions[LC_EDIT_PASTE]); - menuEdit->addSeparator(); - menuEdit->addAction(actions[LC_EDIT_FIND]); - menuEdit->addAction(actions[LC_EDIT_FIND_NEXT]); - menuEdit->addAction(actions[LC_EDIT_FIND_PREVIOUS]); - menuEdit->addSeparator(); - menuEdit->addAction(actions[LC_EDIT_SELECT_ALL]); - menuEdit->addAction(actions[LC_EDIT_SELECT_NONE]); - menuEdit->addAction(actions[LC_EDIT_SELECT_INVERT]); - menuEdit->addAction(actions[LC_EDIT_SELECT_BY_NAME]); - - menuView = menuBar()->addMenu(tr("&View")); - menuView->addAction(actions[LC_VIEW_PREFERENCES]); - menuView->addSeparator(); - menuView->addAction(actions[LC_VIEW_ZOOM_EXTENTS]); - menuView->addAction(actions[LC_VIEW_LOOK_AT]); - QMenu* menuViewpoints = menuView->addMenu(tr("&Viewpoints")); - menuViewpoints->addAction(actions[LC_VIEW_VIEWPOINT_FRONT]); - menuViewpoints->addAction(actions[LC_VIEW_VIEWPOINT_BACK]); - menuViewpoints->addAction(actions[LC_VIEW_VIEWPOINT_LEFT]); - menuViewpoints->addAction(actions[LC_VIEW_VIEWPOINT_RIGHT]); - menuViewpoints->addAction(actions[LC_VIEW_VIEWPOINT_TOP]); - menuViewpoints->addAction(actions[LC_VIEW_VIEWPOINT_BOTTOM]); - menuViewpoints->addAction(actions[LC_VIEW_VIEWPOINT_HOME]); - menuView->addMenu(menuCamera); - QMenu* menuPerspective = menuView->addMenu(tr("Projection")); - menuPerspective->addAction(actions[LC_VIEW_PROJECTION_PERSPECTIVE]); - menuPerspective->addAction(actions[LC_VIEW_PROJECTION_ORTHO]); - QMenu* menuStep = menuView->addMenu(tr("Ste&p")); - menuStep->addAction(actions[LC_VIEW_TIME_FIRST]); - menuStep->addAction(actions[LC_VIEW_TIME_PREVIOUS]); - menuStep->addAction(actions[LC_VIEW_TIME_NEXT]); - menuStep->addAction(actions[LC_VIEW_TIME_LAST]); - menuStep->addSeparator(); - menuStep->addAction(actions[LC_VIEW_TIME_INSERT]); - menuStep->addAction(actions[LC_VIEW_TIME_DELETE]); - menuView->addSeparator(); - menuView->addAction(actions[LC_VIEW_SPLIT_HORIZONTAL]); - menuView->addAction(actions[LC_VIEW_SPLIT_VERTICAL]); - menuView->addAction(actions[LC_VIEW_REMOVE_VIEW]); - menuView->addAction(actions[LC_VIEW_RESET_VIEWS]); - menuView->addSeparator(); - QMenu *menuToolBars = menuView->addMenu(tr("T&oolbars")); - menuToolBars->addAction(partsToolBar->toggleViewAction()); - menuToolBars->addAction(propertiesToolBar->toggleViewAction()); - menuToolBars->addSeparator(); - menuToolBars->addAction(standardToolBar->toggleViewAction()); - menuToolBars->addAction(toolsToolBar->toggleViewAction()); - menuToolBars->addAction(timeToolBar->toggleViewAction()); - menuView->addAction(actions[LC_VIEW_FULLSCREEN]); - - menuPiece = menuBar()->addMenu(tr("&Piece")); - menuPiece->addAction(actions[LC_PIECE_INSERT]); - menuPiece->addAction(actions[LC_PIECE_DELETE]); - menuPiece->addAction(actions[LC_PIECE_ARRAY]); - menuPiece->addAction(actions[LC_PIECE_MINIFIG_WIZARD]); - menuPiece->addSeparator(); - menuPiece->addAction(actions[LC_PIECE_GROUP]); - menuPiece->addAction(actions[LC_PIECE_UNGROUP]); - menuPiece->addAction(actions[LC_PIECE_GROUP_REMOVE]); - menuPiece->addAction(actions[LC_PIECE_GROUP_ADD]); - menuPiece->addAction(actions[LC_PIECE_GROUP_EDIT]); -// LC_PIECE_SHOW_EARLIER, -// LC_PIECE_SHOW_LATER, - menuPiece->addSeparator(); - menuPiece->addAction(actions[LC_PIECE_HIDE_SELECTED]); - menuPiece->addAction(actions[LC_PIECE_HIDE_UNSELECTED]); - menuPiece->addAction(actions[LC_PIECE_UNHIDE_ALL]); - - menuModel = menuBar()->addMenu(tr("&Model")); - menuModel->addAction(actions[LC_MODEL_PROPERTIES]); - menuModel->addAction(actions[LC_MODEL_NEW]); - menuModel->addSeparator(); - for (int ModelIdx = 0; ModelIdx < LC_MODEL_LAST - LC_MODEL_FIRST; ModelIdx++) - menuModel->addAction(actions[LC_MODEL_FIRST + ModelIdx]); - menuModel->addAction(actions[LC_MODEL_LIST]); - - menuHelp = menuBar()->addMenu(tr("&Help")); - menuHelp->addAction(actions[LC_HELP_HOMEPAGE]); - menuHelp->addAction(actions[LC_HELP_EMAIL]); -#if !LC_DISABLE_UPDATE_CHECK - menuHelp->addAction(actions[LC_HELP_UPDATES]); -#endif - menuHelp->addSeparator(); - menuHelp->addAction(actions[LC_HELP_ABOUT]); -} - -void lcQMainWindow::createToolBars() -{ - QMenu* lockMenu = new QMenu(tr("Lock Menu"), this); - lockMenu->addAction(actions[LC_EDIT_LOCK_X]); - lockMenu->addAction(actions[LC_EDIT_LOCK_Y]); - lockMenu->addAction(actions[LC_EDIT_LOCK_Z]); - lockMenu->addAction(actions[LC_EDIT_LOCK_NONE]); - - QAction* lockAction = new QAction(tr("Lock Menu"), this); - lockAction->setStatusTip(tr("Toggle mouse movement on specific axes")); - lockAction->setIcon(QIcon(":/resources/edit_lock.png")); - lockAction->setMenu(lockMenu); - - 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(actions[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(actions[actionIdx]); - - QMenu* snapMenu = new QMenu(tr("Snap Menu"), this); - snapMenu->addMenu(snapXYMenu); - snapMenu->addMenu(snapZMenu); - - QAction* moveAction = new QAction(tr("Snap Move"), this); - 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); - for (int actionIdx = LC_EDIT_SNAP_ANGLE0; actionIdx <= LC_EDIT_SNAP_ANGLE9; actionIdx++) - snapAngleMenu->addAction(actions[actionIdx]); - - QAction* angleAction = new QAction(tr("Snap Rotate"), this); - angleAction->setStatusTip(tr("Snap rotations to fixed intervals")); - angleAction->setIcon(QIcon(":/resources/edit_snap_angle.png")); - angleAction->setMenu(snapAngleMenu); - - standardToolBar = addToolBar(tr("Standard")); - standardToolBar->setObjectName("StandardToolbar"); - standardToolBar->addAction(actions[LC_FILE_NEW]); - standardToolBar->addAction(actions[LC_FILE_OPEN]); - standardToolBar->addAction(actions[LC_FILE_SAVE]); - standardToolBar->addAction(actions[LC_FILE_PRINT]); - standardToolBar->addAction(actions[LC_FILE_PRINT_PREVIEW]); - standardToolBar->addSeparator(); - standardToolBar->addAction(actions[LC_EDIT_UNDO]); - standardToolBar->addAction(actions[LC_EDIT_REDO]); - standardToolBar->addAction(actions[LC_EDIT_CUT]); - standardToolBar->addAction(actions[LC_EDIT_COPY]); - standardToolBar->addAction(actions[LC_EDIT_PASTE]); - standardToolBar->addSeparator(); - standardToolBar->addAction(actions[LC_EDIT_TRANSFORM_RELATIVE]); - standardToolBar->addAction(lockAction); - standardToolBar->addAction(moveAction); - standardToolBar->addAction(angleAction); - standardToolBar->addSeparator(); - standardToolBar->addAction(actions[LC_EDIT_TRANSFORM]); - ((QToolButton*)standardToolBar->widgetForAction(lockAction))->setPopupMode(QToolButton::InstantPopup); - ((QToolButton*)standardToolBar->widgetForAction(moveAction))->setPopupMode(QToolButton::InstantPopup); - ((QToolButton*)standardToolBar->widgetForAction(angleAction))->setPopupMode(QToolButton::InstantPopup); - ((QToolButton*)standardToolBar->widgetForAction(actions[LC_EDIT_TRANSFORM]))->setPopupMode(QToolButton::InstantPopup); - - QHBoxLayout *transformLayout = new QHBoxLayout; - QWidget *transformWidget = new QWidget(); - transformWidget->setLayout(transformLayout); - transformX = new QLineEdit(); - transformX->setMaximumWidth(75); - transformLayout->addWidget(transformX); - transformY = new QLineEdit(); - transformY->setMaximumWidth(75); - transformLayout->addWidget(transformY); - transformZ = new QLineEdit(); - transformZ->setMaximumWidth(75); - transformLayout->addWidget(transformZ); - transformLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum)); - standardToolBar->addWidget(transformWidget); - connect(transformX, SIGNAL(returnPressed()), actions[LC_EDIT_TRANSFORM], SIGNAL(triggered())); - connect(transformY, SIGNAL(returnPressed()), actions[LC_EDIT_TRANSFORM], SIGNAL(triggered())); - connect(transformZ, SIGNAL(returnPressed()), actions[LC_EDIT_TRANSFORM], SIGNAL(triggered())); - - toolsToolBar = addToolBar(tr("Tools")); - toolsToolBar->setObjectName("ToolsToolbar"); - insertToolBarBreak(toolsToolBar); - toolsToolBar->addAction(actions[LC_EDIT_ACTION_INSERT]); - toolsToolBar->addAction(actions[LC_EDIT_ACTION_LIGHT]); - toolsToolBar->addAction(actions[LC_EDIT_ACTION_SPOTLIGHT]); - toolsToolBar->addAction(actions[LC_EDIT_ACTION_CAMERA]); - toolsToolBar->addSeparator(); - toolsToolBar->addAction(actions[LC_EDIT_ACTION_SELECT]); - toolsToolBar->addAction(actions[LC_EDIT_ACTION_MOVE]); - toolsToolBar->addAction(actions[LC_EDIT_ACTION_ROTATE]); - toolsToolBar->addAction(actions[LC_EDIT_ACTION_DELETE]); - toolsToolBar->addAction(actions[LC_EDIT_ACTION_PAINT]); - toolsToolBar->addSeparator(); - toolsToolBar->addAction(actions[LC_EDIT_ACTION_ZOOM]); - toolsToolBar->addAction(actions[LC_EDIT_ACTION_PAN]); - toolsToolBar->addAction(actions[LC_EDIT_ACTION_ROTATE_VIEW]); - toolsToolBar->addAction(actions[LC_EDIT_ACTION_ROLL]); - toolsToolBar->addAction(actions[LC_EDIT_ACTION_ZOOM_REGION]); - - timeToolBar = addToolBar(tr("Time")); - timeToolBar->setObjectName("TimeToolbar"); - timeToolBar->addAction(actions[LC_VIEW_TIME_FIRST]); - timeToolBar->addAction(actions[LC_VIEW_TIME_PREVIOUS]); - timeToolBar->addAction(actions[LC_VIEW_TIME_NEXT]); - timeToolBar->addAction(actions[LC_VIEW_TIME_LAST]); - timeToolBar->addAction(actions[LC_PIECE_SHOW_EARLIER]); - timeToolBar->addAction(actions[LC_PIECE_SHOW_LATER]); - timeToolBar->addAction(actions[LC_VIEW_TIME_ADD_KEYS]); - // TODO: add missing menu items - - partsToolBar = new QDockWidget(tr("Parts"), this); - partsToolBar->setObjectName("PartsToolbar"); - partsToolBar->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - QWidget *partsContents = new QWidget(); - QGridLayout *partsLayout = new QGridLayout(partsContents); - partsLayout->setSpacing(6); - partsLayout->setContentsMargins(6, 6, 6, 6); - QSplitter *partsSplitter = new QSplitter(Qt::Vertical, partsContents); - - QFrame *previewFrame = new QFrame(partsSplitter); - previewFrame->setFrameShape(QFrame::StyledPanel); - previewFrame->setFrameShadow(QFrame::Sunken); - - QGridLayout *previewLayout = new QGridLayout(previewFrame); - previewLayout->setContentsMargins(0, 0, 0, 0); - - int AASamples = lcGetProfileInt(LC_PROFILE_ANTIALIASING_SAMPLES); - if (AASamples > 1) - { - QGLFormat format; - format.setSampleBuffers(true); - format.setSamples(AASamples); - QGLFormat::setDefaultFormat(format); - } - - piecePreview = new lcQGLWidget(previewFrame, NULL, new PiecePreview(), false); - piecePreview->preferredSize = QSize(200, 100); - previewLayout->addWidget(piecePreview, 0, 0, 1, 1); - - QSizePolicy treePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); - treePolicy.setVerticalStretch(1); - - partsTree = new lcQPartsTree(partsSplitter); - partsTree->setSizePolicy(treePolicy); - connect(partsTree, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(partsTreeItemChanged(QTreeWidgetItem*, QTreeWidgetItem*))); - - partSearch = new QLineEdit(partsSplitter); - connect(partSearch, SIGNAL(returnPressed()), this, SLOT(partSearchReturn())); - connect(partSearch, SIGNAL(textChanged(QString)), this, SLOT(partSearchChanged(QString))); - - QFrame *colorFrame = new QFrame(partsSplitter); - colorFrame->setFrameShape(QFrame::StyledPanel); - colorFrame->setFrameShadow(QFrame::Sunken); - - QGridLayout *colorLayout = new QGridLayout(colorFrame); - colorLayout->setContentsMargins(0, 0, 0, 0); - - colorList = new lcQColorList(partsSplitter); - colorLayout->addWidget(colorList); - connect(colorList, SIGNAL(colorChanged(int)), this, SLOT(colorChanged(int))); - - partsLayout->addWidget(partsSplitter, 0, 0, 1, 1); - - partsToolBar->setWidget(partsContents); - addDockWidget(Qt::RightDockWidgetArea, partsToolBar); - - propertiesToolBar = new QDockWidget(tr("Properties"), this); - propertiesToolBar->setObjectName("PropertiesToolbar"); - propertiesToolBar->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - - propertiesWidget = new lcQPropertiesTree(propertiesToolBar); - - propertiesToolBar->setWidget(propertiesWidget); - addDockWidget(Qt::RightDockWidgetArea, propertiesToolBar); - - tabifyDockWidget(partsToolBar, propertiesToolBar); - partsToolBar->raise(); -} - -void lcQMainWindow::createStatusBar() -{ - statusBar = new QStatusBar(this); - setStatusBar(statusBar); - - statusBarLabel = new QLabel(); - statusBar->addWidget(statusBarLabel); - - statusPositionLabel = new QLabel(); - statusBar->addPermanentWidget(statusPositionLabel); - - statusSnapLabel = new QLabel(); - statusBar->addPermanentWidget(statusSnapLabel); - - statusTimeLabel = new QLabel(); - statusBar->addPermanentWidget(statusTimeLabel); -} - -void lcQMainWindow::closeEvent(QCloseEvent *event) -{ - if (gMainWindow->SaveProjectIfModified()) - { - event->accept(); - - QSettings settings; - settings.beginGroup("MainWindow"); - settings.setValue("Geometry", saveGeometry()); - settings.setValue("State", saveState()); - settings.endGroup(); - } - else - event->ignore(); -} - -QMenu *lcQMainWindow::createPopupMenu() -{ - QMenu *menuToolBars = new QMenu(this); - - menuToolBars->addAction(partsToolBar->toggleViewAction()); - menuToolBars->addAction(propertiesToolBar->toggleViewAction()); - menuToolBars->addSeparator(); - menuToolBars->addAction(standardToolBar->toggleViewAction()); - menuToolBars->addAction(toolsToolBar->toggleViewAction()); - menuToolBars->addAction(timeToolBar->toggleViewAction()); - - return menuToolBars; -} - -void lcQMainWindow::actionTriggered() -{ - QObject *action = sender(); - - for (int Command = 0; Command < LC_NUM_COMMANDS; Command++) - { - if (action == actions[Command]) - { - gMainWindow->HandleCommand((lcCommandId)Command); - break; - } - } -} - -void lcQMainWindow::partsTreeItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) -{ - if (!current) - return; - - PieceInfo *info = (PieceInfo*)current->data(0, lcQPartsTree::PieceInfoRole).value(); - - if (info) - { - PiecePreview* preview = (PiecePreview*)piecePreview->widget; - preview->SetCurrentPiece(info); - } -} - -void lcQMainWindow::colorChanged(int colorIndex) -{ - gMainWindow->SetColorIndex(colorIndex); -} - -void lcQMainWindow::partSearchReturn() -{ - partsTree->searchParts(partSearch->text()); -} - -void lcQMainWindow::partSearchChanged(const QString& text) -{ - const QByteArray textConv = text.toLocal8Bit(); - const char* searchString = textConv.data(); - int length = strlen(searchString); - - if (!length) - return; - - lcPiecesLibrary *library = lcGetPiecesLibrary(); - PieceInfo* bestMatch = NULL; - - for (int partIndex = 0; partIndex < library->mPieces.GetSize(); partIndex++) - { - PieceInfo *info = library->mPieces[partIndex]; - - if (strncasecmp(searchString, info->m_strDescription, length) == 0) - { - if (!bestMatch || strcasecmp(bestMatch->m_strDescription, info->m_strDescription) > 0) - bestMatch = info; - } - else if (strncasecmp(searchString, info->m_strName, length) == 0) - { - if (!bestMatch || strcasecmp(bestMatch->m_strName, info->m_strName) > 0) - bestMatch = info; - } - } - - if (bestMatch) - partsTree->setCurrentPart(bestMatch); -} - -void lcQMainWindow::clipboardChanged() -{ - const QString mimeType("application/vnd.leocad-clipboard"); - const QMimeData *mimeData = QApplication::clipboard()->mimeData(); - QByteArray clipboardData; - - if (mimeData->hasFormat(mimeType)) - clipboardData = mimeData->data(mimeType); - - g_App->SetClipboard(clipboardData); -} - -void lcQMainWindow::splitView(Qt::Orientation Orientation) -{ - QWidget* Focus = focusWidget(); - - if (typeid(*Focus) != typeid(lcQGLWidget)) - return; - - QWidget* Parent = Focus->parentWidget(); - QSplitter* Splitter; - QList Sizes; - - if (Parent == centralWidget()) - { - Splitter = new QSplitter(Orientation, Parent); - Parent->layout()->addWidget(Splitter); - Splitter->addWidget(Focus); - Splitter->addWidget(new lcQGLWidget(centralWidget(), piecePreview, new View(lcGetActiveModel()), true)); - } - else - { - QSplitter* ParentSplitter = (QSplitter*)Parent; - Sizes = ParentSplitter->sizes(); - int FocusIndex = ParentSplitter->indexOf(Focus); - - Splitter = new QSplitter(Orientation, Parent); - ParentSplitter->insertWidget(FocusIndex, Splitter); - Splitter->addWidget(Focus); - Splitter->addWidget(new lcQGLWidget(centralWidget(), piecePreview, new View(lcGetActiveModel()), true)); - - ParentSplitter->setSizes(Sizes); - } - - Sizes.clear(); - Sizes.append(10); - Sizes.append(10); - Splitter->setSizes(Sizes); -} - -void lcQMainWindow::splitHorizontal() -{ - splitView(Qt::Vertical); -} - -void lcQMainWindow::splitVertical() -{ - splitView(Qt::Horizontal); -} - -void lcQMainWindow::removeView() -{ - QWidget *focus = focusWidget(); - - if (typeid(*focus) != typeid(lcQGLWidget)) - return; - - QWidget *parent = focus->parentWidget(); - - if (parent == centralWidget()) - return; - - QWidget *parentParentWidget = parent->parentWidget(); - QSplitter *parentSplitter = (QSplitter*)parent; - int focusIndex = parentSplitter->indexOf(focus); - - if (parentParentWidget == centralWidget()) - { - QLayout* centralLayout = parentParentWidget->layout(); - - centralLayout->addWidget(parentSplitter->widget(!focusIndex)); - centralLayout->removeWidget(parent); - - return; - } - - QSplitter* parentParentSplitter = (QSplitter*)parentParentWidget; - QList sizes = parentParentSplitter->sizes(); - - int parentIndex = parentParentSplitter->indexOf(parent); - parentParentSplitter->insertWidget(!parentIndex, focus); - - delete parent; - - parentParentSplitter->setSizes(sizes); -} - -void lcQMainWindow::resetViews() -{ - QLayout* centralLayout = centralWidget()->layout(); - delete centralLayout->itemAt(0)->widget(); - centralLayout->addWidget(new lcQGLWidget(centralWidget(), piecePreview, new View(lcGetActiveModel()), true)); -} - -void lcQMainWindow::print(QPrinter *printer) -{ - lcModel* Model = lcGetActiveModel(); - int docCopies; - int pageCopies; - - int rows = lcGetProfileInt(LC_PROFILE_PRINT_ROWS); - int columns = lcGetProfileInt(LC_PROFILE_PRINT_COLUMNS); - int stepsPerPage = rows * columns; - int pageCount = (Model->GetLastStep() + stepsPerPage - 1) / stepsPerPage; - - 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; - } - - gMainWindow->mPreviewWidget->MakeCurrent(); - lcContext* Context = gMainWindow->mPreviewWidget->mContext; - - QRect pageRect = printer->pageRect(); - - int stepWidth = pageRect.width() / columns; - int stepHeight = pageRect.height() / rows; - - GLint maxTexture; - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexture); - - maxTexture = qMin(maxTexture, 2048); - - int tileWidth = qMin(stepWidth, maxTexture); - int tileHeight = qMin(stepHeight, maxTexture); - float aspectRatio = (float)stepWidth / (float)stepHeight; - - View view(Model); - view.SetCamera(gMainWindow->GetActiveView()->mCamera, false); - view.mWidth = tileWidth; - view.mHeight = tileHeight; - view.SetContext(piecePreview->widget->mContext); - - Context->BeginRenderToTexture(tileWidth, tileHeight); - - lcStep previousTime = Model->GetCurrentStep(); - - QPainter painter(printer); - lcuint8 *buffer = (lcuint8*)malloc(tileWidth * tileHeight * 4); - // 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; - - lcStep currentStep = 1 + ((page - 1) * rows * columns); - - for (int row = 0; row < rows; row++) - { - for (int column = 0; column < columns; column++) - { - if (currentStep > Model->GetLastStep()) - break; - - Model->SetCurrentStep(currentStep); - - if (stepWidth > tileWidth || stepHeight > tileHeight) - { - lcuint8* imageBuffer = (lcuint8*)malloc(stepWidth * stepHeight * 4); - - lcCamera* camera = view.mCamera; - camera->StartTiledRendering(tileWidth, tileHeight, stepWidth, stepHeight, aspectRatio); - do - { - view.OnDraw(); - - int tileRow, tileColumn, currentTileWidth, currentTileHeight; - camera->GetTileInfo(&tileRow, &tileColumn, ¤tTileWidth, ¤tTileHeight); - - glFinish(); - glReadPixels(0, 0, currentTileWidth, currentTileHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer); - - lcuint32 tileY = 0; - if (tileRow != 0) - tileY = tileRow * tileHeight - (tileHeight - stepHeight % tileHeight); - - lcuint32 tileStart = ((tileColumn * tileWidth) + (tileY * stepWidth)) * 4; - - for (int y = 0; y < currentTileHeight; y++) - { - lcuint8* src = buffer + (currentTileHeight - y - 1) * currentTileWidth * 4; - lcuint8* dst = imageBuffer + tileStart + y * stepWidth * 4; - - for (int x = 0; x < currentTileWidth; x++) - { - *dst++ = src[2]; - *dst++ = src[1]; - *dst++ = src[0]; - *dst++ = 255; - - src += 4; - } - } - } while (camera->EndTile()); - - QImage image = QImage((const lcuint8*)imageBuffer, stepWidth, stepHeight, QImage::Format_ARGB32_Premultiplied); - - QRect rect = painter.viewport(); - int left = rect.x() + (stepWidth * column); - int bottom = rect.y() + (stepHeight * row); - - painter.drawImage(left, bottom, image); - - free(imageBuffer); - } - else - { - view.OnDraw(); - - glFinish(); - glReadPixels(0, 0, tileWidth, tileHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer); - - for (int y = 0; y < (tileHeight + 1) / 2; y++) - { - lcuint8* top = (lcuint8*)buffer + ((tileHeight - y - 1) * tileWidth * 4); - lcuint8* bottom = (lcuint8*)buffer + y * tileWidth * 4; - - for (int x = 0; x < tileWidth; x++) - { - lcuint8 red = top[0]; - lcuint8 green = top[1]; - lcuint8 blue = top[2]; - lcuint8 alpha = 255;//top[3]; - - top[0] = bottom[2]; - top[1] = bottom[1]; - top[2] = bottom[0]; - top[3] = 255;//bottom[3]; - - bottom[0] = blue; - bottom[1] = green; - bottom[2] = red; - bottom[3] = alpha; - - top += 4; - bottom +=4; - } - } - - QImage image = QImage((const lcuint8*)buffer, tileWidth, tileHeight, QImage::Format_ARGB32); - - QRect rect = painter.viewport(); - int left = rect.x() + (stepWidth * column); - int bottom = rect.y() + (stepHeight * row); - - painter.drawImage(left, bottom, image); - } - - // 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); - - QRect rect = painter.viewport(); - int left = rect.x() + (stepWidth * column); - int right = rect.x() + (stepWidth * (column + 1)); - int top = rect.y() + (stepHeight * row); - int bottom = rect.y() + (stepHeight * (row + 1)); - -// if (print text) - { - QFont font("Helvetica", printer->resolution()); - painter.setFont(font); - - QFontMetrics fontMetrics(font); - - int textTop = top + printer->resolution() / 2 + fontMetrics.ascent(); - int textLeft = left + printer->resolution() / 2; - - painter.drawText(textLeft, textTop, QString::number(currentStep)); - } - -// if (print border) - { - QPen blackPen(Qt::black, 2); - painter.setPen(blackPen); - - if (row == 0) - painter.drawLine(left, top, right, top); - if (column == 0) - painter.drawLine(left, top, left, bottom); - painter.drawLine(left, bottom, right, bottom); - painter.drawLine(right, top, right, bottom); - } - - currentStep++; - } - } - - // TODO: print header and footer - - if (pageCopy < pageCopies - 1) - printer->newPage(); - } - - if (page == toPage) - break; - - if (ascending) - page++; - else - page--; - - printer->newPage(); - } - - if (docCopy < docCopies - 1) - printer->newPage(); - } - - free(buffer); - - Model->SetCurrentStep(previousTime); - - Context->EndRenderToTexture(); -} - -void lcQMainWindow::showPrintDialog() -{ - lcModel* Model = lcGetActiveModel(); - int rows = lcGetProfileInt(LC_PROFILE_PRINT_ROWS); - int columns = lcGetProfileInt(LC_PROFILE_PRINT_COLUMNS); - int stepsPerPage = rows * columns; - int pageCount = (Model->GetLastStep() + stepsPerPage - 1) / stepsPerPage; - - QPrinter printer(QPrinter::HighResolution); - printer.setFromTo(1, pageCount + 1); - - QPrintDialog printDialog(&printer, this); - - if (printDialog.exec() == QDialog::Accepted) - print(&printer); -} - -void lcQMainWindow::togglePrintPreview() -{ - // todo: print preview inside main window - - lcModel* Model = lcGetActiveModel(); - int rows = lcGetProfileInt(LC_PROFILE_PRINT_ROWS); - int columns = lcGetProfileInt(LC_PROFILE_PRINT_COLUMNS); - int stepsPerPage = rows * columns; - int pageCount = (Model->GetLastStep() + stepsPerPage - 1) / stepsPerPage; - - QPrinter printer(QPrinter::ScreenResolution); - printer.setFromTo(1, pageCount + 1); - - QPrintPreviewDialog preview(&printer, this); - connect(&preview, SIGNAL(paintRequested(QPrinter*)), SLOT(print(QPrinter*))); - preview.exec(); -} - -void lcQMainWindow::toggleFullScreen() -{ - // todo: hide toolbars and menu - // todo: create fullscreen toolbar or support esc key to go back - if (isFullScreen()) - showNormal(); - else - showFullScreen(); -} - -void lcQMainWindow::updateFocusObject(lcObject* Focus) -{ - propertiesWidget->updateFocusObject(Focus); - - lcVector3 Position; - lcGetActiveModel()->GetFocusPosition(Position); - - QString Label("X: %1 Y: %2 Z: %3"); - Label = Label.arg(QString::number(Position[0], 'f', 2), QString::number(Position[1], 'f', 2), QString::number(Position[2], 'f', 2)); - statusPositionLabel->setText(Label); -} - -void lcQMainWindow::updateSelectedObjects(int flags, int selectedCount, lcObject* focus) -{ - actions[LC_EDIT_CUT]->setEnabled(flags & LC_SEL_SELECTED); - actions[LC_EDIT_COPY]->setEnabled(flags & LC_SEL_SELECTED); - actions[LC_EDIT_FIND]->setEnabled((flags & LC_SEL_NO_PIECES) == 0); - actions[LC_EDIT_FIND_NEXT]->setEnabled((flags & LC_SEL_NO_PIECES) == 0); - actions[LC_EDIT_FIND_PREVIOUS]->setEnabled((flags & LC_SEL_NO_PIECES) == 0); - actions[LC_EDIT_SELECT_INVERT]->setEnabled((flags & LC_SEL_NO_PIECES) == 0); - actions[LC_EDIT_SELECT_BY_NAME]->setEnabled((flags & LC_SEL_NO_PIECES) == 0); - actions[LC_EDIT_SELECT_NONE]->setEnabled(flags & LC_SEL_SELECTED); - actions[LC_EDIT_SELECT_ALL]->setEnabled(flags & LC_SEL_UNSELECTED); - - actions[LC_PIECE_DELETE]->setEnabled(flags & LC_SEL_SELECTED); - actions[LC_PIECE_ARRAY]->setEnabled(flags & LC_SEL_PIECE); - actions[LC_PIECE_HIDE_SELECTED]->setEnabled(flags & LC_SEL_PIECE); - actions[LC_PIECE_UNHIDE_ALL]->setEnabled(flags & LC_SEL_HIDDEN); - actions[LC_PIECE_HIDE_UNSELECTED]->setEnabled(flags & LC_SEL_UNSELECTED); - actions[LC_PIECE_GROUP]->setEnabled(flags & LC_SEL_CAN_GROUP); - actions[LC_PIECE_UNGROUP]->setEnabled(flags & LC_SEL_GROUPED); - actions[LC_PIECE_GROUP_ADD]->setEnabled((flags & (LC_SEL_GROUPED | LC_SEL_FOCUS_GROUPED)) == LC_SEL_GROUPED); - actions[LC_PIECE_GROUP_REMOVE]->setEnabled(flags & LC_SEL_FOCUS_GROUPED); - actions[LC_PIECE_GROUP_EDIT]->setEnabled((flags & LC_SEL_NO_PIECES) == 0); - actions[LC_PIECE_SHOW_EARLIER]->setEnabled(flags & LC_SEL_PIECE); // FIXME: disable if current step is 1 - actions[LC_PIECE_SHOW_LATER]->setEnabled(flags & LC_SEL_PIECE); - - QString message; - - if ((selectedCount == 1) && (focus != NULL)) - { - if (focus->IsPiece()) - message = QString("%1 (ID: %2)").arg(focus->GetName(), ((lcPiece*)focus)->mPieceInfo->m_strName); - else - message = focus->GetName(); - } - else if (selectedCount > 0) - { - if (selectedCount == 1) - message = "1 Object selected"; - else - message = QString("%1 Objects selected").arg(QString::number(selectedCount)); - - if ((focus != NULL) && focus->IsPiece()) - { - message.append(QString(" - %1 (ID: %2)").arg(focus->GetName(), ((lcPiece*)focus)->mPieceInfo->m_strName)); - - const lcGroup* pGroup = ((lcPiece*)focus)->GetGroup(); - if ((pGroup != NULL) && pGroup->m_strName[0]) - message.append(QString(" in group '%1'").arg(pGroup->m_strName)); - } - } - - statusBarLabel->setText(message); -} - -void lcQMainWindow::updateAction(int newAction) -{ - QAction *action = actions[LC_EDIT_ACTION_FIRST + newAction]; - - if (action) - action->setChecked(true); -} - -void lcQMainWindow::updatePaste(bool enabled) -{ - QAction *action = actions[LC_EDIT_PASTE]; - - if (action) - action->setEnabled(enabled); -} - -void lcQMainWindow::updateCurrentStep() -{ - lcModel* Model = lcGetActiveModel(); - lcStep currentStep = Model->GetCurrentStep(); - lcStep lastStep = Model->GetLastStep(); - - actions[LC_VIEW_TIME_FIRST]->setEnabled(currentStep != 1); - actions[LC_VIEW_TIME_PREVIOUS]->setEnabled(currentStep > 1); - actions[LC_VIEW_TIME_NEXT]->setEnabled(currentStep < LC_STEP_MAX); - actions[LC_VIEW_TIME_LAST]->setEnabled(currentStep != lastStep); - - statusTimeLabel->setText(QString(tr("Step %1")).arg(QString::number(currentStep))); -} - -void lcQMainWindow::setAddKeys(bool addKeys) -{ - actions[LC_VIEW_TIME_ADD_KEYS]->setChecked(addKeys); -} - -void lcQMainWindow::updateLockSnap() -{ - actions[LC_EDIT_TRANSFORM_RELATIVE]->setChecked(gMainWindow->GetRelativeTransform()); - actions[LC_EDIT_LOCK_X]->setChecked(gMainWindow->GetLockX()); - actions[LC_EDIT_LOCK_Y]->setChecked(gMainWindow->GetLockY()); - actions[LC_EDIT_LOCK_Z]->setChecked(gMainWindow->GetLockZ()); -} - -void lcQMainWindow::updateSnap() -{ - actions[LC_EDIT_SNAP_MOVE_XY0 + gMainWindow->GetMoveXYSnapIndex()]->setChecked(true); - actions[LC_EDIT_SNAP_MOVE_Z0 + gMainWindow->GetMoveZSnapIndex()]->setChecked(true); - actions[LC_EDIT_SNAP_ANGLE0 + gMainWindow->GetAngleSnapIndex()]->setChecked(true); - - statusSnapLabel->setText(QString(tr(" M: %1 %2 R: %3 ")).arg(gMainWindow->GetMoveXYSnapText(), gMainWindow->GetMoveZSnapText(), QString::number(gMainWindow->GetAngleSnap()))); -} - -void lcQMainWindow::updateColor() -{ - colorList->setCurrentColor(gMainWindow->mColorIndex); -} - -void lcQMainWindow::updateUndoRedo(const QString& UndoText, const QString& RedoText) -{ - QAction* UndoAction = actions[LC_EDIT_UNDO]; - QAction* RedoAction = actions[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")); - } -} - -void lcQMainWindow::updateTransformType(int newType) -{ - const char* iconNames[] = - { - ":/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_ASSERT(newType >= 0 && newType <= 3); - actions[LC_EDIT_TRANSFORM_ABSOLUTE_TRANSLATION + newType]->setChecked(true); - actions[LC_EDIT_TRANSFORM]->setIcon(QIcon(iconNames[newType])); -} - -void lcQMainWindow::updateCameraMenu() -{ - const lcArray& cameras = lcGetActiveModel()->GetCameras(); - lcCamera* currentCamera = gMainWindow->GetActiveView()->mCamera; - int actionIdx, currentIndex = -1; - - for (actionIdx = LC_VIEW_CAMERA_FIRST; actionIdx <= LC_VIEW_CAMERA_LAST; actionIdx++) - { - QAction* action = actions[actionIdx]; - int cameraIdx = actionIdx - LC_VIEW_CAMERA_FIRST; - - if (cameraIdx < cameras.GetSize()) - { - if (currentCamera == cameras[cameraIdx]) - currentIndex = cameraIdx; - - action->setText(cameras[cameraIdx]->GetName()); - action->setVisible(true); - } - else - action->setVisible(false); - } - - updateCurrentCamera(currentIndex); -} - -void lcQMainWindow::updateCurrentCamera(int cameraIndex) -{ - int actionIndex = LC_VIEW_CAMERA_FIRST + cameraIndex; - - if (actionIndex < LC_VIEW_CAMERA_FIRST || actionIndex > LC_VIEW_CAMERA_LAST) - actionIndex = LC_VIEW_CAMERA_NONE; - - actions[actionIndex]->setChecked(true); -} - -void lcQMainWindow::updatePerspective(View* view) -{ - if (view->mCamera->IsOrtho()) - actions[LC_VIEW_PROJECTION_ORTHO]->setChecked(true); - else - actions[LC_VIEW_PROJECTION_PERSPECTIVE]->setChecked(true); -} - -void lcQMainWindow::updateModels() -{ - const lcArray& Models = lcGetActiveProject()->GetModels(); - lcModel* CurrentModel = lcGetActiveModel(); - - for (int ActionIdx = LC_MODEL_FIRST; ActionIdx <= LC_MODEL_LAST; ActionIdx++) - { - QAction* Action = actions[ActionIdx]; - int ModelIdx = ActionIdx - LC_MODEL_FIRST; - - if (ModelIdx < Models.GetSize()) - { - Action->setChecked(CurrentModel == Models[ModelIdx]); - Action->setText(QString::fromLatin1("&%1 %2").arg(QString::number(ModelIdx + 1), Models[ModelIdx]->GetProperties().mName)); - Action->setVisible(true); - } - else - Action->setVisible(false); - } - - partsTree->UpdateModels(); -} - -void lcQMainWindow::updateCategories() -{ - partsTree->updateCategories(); -} - -void lcQMainWindow::updateTitle(const QString& title, bool modified) -{ - setWindowModified(modified); - setWindowFilePath(title); -} - -void lcQMainWindow::updateModified(bool modified) -{ - setWindowModified(modified); -} - -void lcQMainWindow::updateRecentFiles() -{ - for (int actionIdx = LC_FILE_RECENT_FIRST; actionIdx <= LC_FILE_RECENT_LAST; actionIdx++) - { - int fileIdx = actionIdx - LC_FILE_RECENT_FIRST; - QAction *action = actions[actionIdx]; - - if (!gMainWindow->mRecentFiles[fileIdx].isEmpty()) - { - action->setText(QString("&%1 %2").arg(QString::number(fileIdx + 1), QDir::toNativeSeparators(gMainWindow->mRecentFiles[fileIdx]))); - action->setVisible(true); - } - else - action->setVisible(false); - } - - actionFileRecentSeparator->setVisible(!gMainWindow->mRecentFiles[0].isEmpty()); -} - -void lcQMainWindow::updateShortcuts() -{ - for (int actionIdx = 0; actionIdx < LC_NUM_COMMANDS; actionIdx++) - actions[actionIdx]->setShortcut(QKeySequence(gKeyboardShortcuts.Shortcuts[actionIdx])); -} - -lcVector3 lcQMainWindow::getTransformAmount() -{ - lcVector3 transform; - - transform.x = transformX->text().toFloat(); - transform.y = transformY->text().toFloat(); - transform.z = transformZ->text().toFloat(); - - return transform; -} diff --git a/qt/lc_qmainwindow.h b/qt/lc_qmainwindow.h deleted file mode 100644 index 7e574252..00000000 --- a/qt/lc_qmainwindow.h +++ /dev/null @@ -1,111 +0,0 @@ -#ifndef _LC_QMAINWINDOW_H_ -#define _LC_QMAINWINDOW_H_ - -#include -#include -#include "lc_array.h" -#include "lc_commands.h" - -class QComboBox; -class lcQGLWidget; -class lcQPartsTree; -class lcQColorList; -class lcQPropertiesTree; -class View; - -class lcQMainWindow : public QMainWindow -{ - Q_OBJECT - -public: - explicit lcQMainWindow(QWidget *parent = 0); - ~lcQMainWindow(); - - void LibraryLoaded(); - - void showPrintDialog(); - - void splitHorizontal(); - void splitVertical(); - void removeView(); - void resetViews(); - void togglePrintPreview(); - void toggleFullScreen(); - - void updateFocusObject(lcObject *focus); - void updateSelectedObjects(int flags, int selectedCount, lcObject* focus); - void updateAction(int newAction); - void updatePaste(bool enabled); - void updateCurrentStep(); - void setAddKeys(bool addKeys); - void updateLockSnap(); - void updateSnap(); - void updateColor(); - void updateUndoRedo(const QString& UndoText, const QString& RedoText); - void updateTransformType(int newType); - void updateCameraMenu(); - void updateCurrentCamera(int cameraIndex); - void updatePerspective(View* view); - void updateModels(); - void updateCategories(); - void updateTitle(const QString& title, bool modified); - void updateModified(bool modified); - void updateRecentFiles(); - void updateShortcuts(); - - lcVector3 getTransformAmount(); - - QAction *actions[LC_NUM_COMMANDS]; - -private slots: - void print(QPrinter *printer); - void actionTriggered(); - void partsTreeItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); - void colorChanged(int colorIndex); - void partSearchReturn(); - void partSearchChanged(const QString& text); - void clipboardChanged(); - -private: - void createActions(); - void createMenus(); - void createToolBars(); - void createStatusBar(); - void splitView(Qt::Orientation orientation); - - void closeEvent(QCloseEvent *event); - QMenu *createPopupMenu(); - - QAction *actionFileRecentSeparator; - QMenu *menuCamera; - - QMenu *menuFile; - QMenu *menuEdit; - QMenu *menuView; - QMenu *menuPiece; - QMenu *menuModel; - QMenu *menuHelp; - - QToolBar *standardToolBar; - QToolBar *toolsToolBar; - QToolBar *timeToolBar; - QDockWidget *partsToolBar; - QDockWidget *propertiesToolBar; - - lcQGLWidget *piecePreview; - lcQPartsTree *partsTree; - QLineEdit *partSearch; - lcQColorList *colorList; - lcQPropertiesTree *propertiesWidget; - QLineEdit *transformX; - QLineEdit *transformY; - QLineEdit *transformZ; - - QStatusBar *statusBar; - QLabel *statusBarLabel; - QLabel *statusPositionLabel; - QLabel *statusSnapLabel; - QLabel *statusTimeLabel; -}; - -#endif // _LC_QMAINWINDOW_H_ diff --git a/qt/qtmain.cpp b/qt/qtmain.cpp index 7556d292..d203a317 100644 --- a/qt/qtmain.cpp +++ b/qt/qtmain.cpp @@ -1,6 +1,5 @@ #include "lc_global.h" #include "lc_application.h" -#include "lc_qmainwindow.h" #include "lc_qupdatedialog.h" #include "lc_mainwindow.h" #include "view.h" @@ -179,12 +178,10 @@ int main(int argc, char *argv[]) if (!g_App->Initialize(argc, argv, libPath, LDrawPath, cachePath.toLocal8Bit().data())) return 1; - lcQMainWindow* MainWindow = (lcQMainWindow*)gMainWindow->mHandle; - MainWindow->LibraryLoaded(); lcGetActiveModel()->UpdateInterface(); gMainWindow->SetColorIndex(lcGetColorIndex(4)); gMainWindow->UpdateRecentFiles(); - MainWindow->show(); + gMainWindow->show(); #if !LC_DISABLE_UPDATE_CHECK lcDoInitialUpdateCheck(); @@ -197,236 +194,5 @@ int main(int argc, char *argv[]) delete g_App; g_App = NULL; - delete MainWindow; - return execReturn; } - -void lcMainWindow::Close() -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - window->close(); -} - -void lcMainWindow::SplitHorizontal() -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->splitHorizontal(); -} - -void lcMainWindow::SplitVertical() -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->splitVertical(); -} - -void lcMainWindow::RemoveView() -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->removeView(); -} - -void lcMainWindow::ResetViews() -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->resetViews(); -} - -void lcMainWindow::TogglePrintPreview() -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->togglePrintPreview(); -} - -void lcMainWindow::ToggleFullScreen() -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->toggleFullScreen(); -} - -void lcMainWindow::UpdateFocusObject(lcObject* Focus) -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->updateFocusObject(Focus); -} - -void lcMainWindow::UpdateSelectedObjects(int Flags, int SelectedCount, lcObject* Focus) -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->updateSelectedObjects(Flags, SelectedCount, Focus); -} - -void lcMainWindow::UpdateAction(int NewAction) -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->updateAction(NewAction); -} - -void lcMainWindow::UpdatePaste(bool Enabled) -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->updatePaste(Enabled); -} - -void lcMainWindow::UpdateCurrentStep() -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->updateCurrentStep(); -} - -void lcMainWindow::SetAddKeys(bool AddKeys) -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->setAddKeys(AddKeys); - - mAddKeys = AddKeys; -} - -void lcMainWindow::UpdateLockSnap() -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->updateLockSnap(); -} - -void lcMainWindow::UpdateSnap() -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->updateSnap(); -} - -void lcMainWindow::UpdateColor() -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->updateColor(); -} - -void lcMainWindow::UpdateUndoRedo(const QString& UndoText, const QString& RedoText) -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->updateUndoRedo(UndoText, RedoText); -} - -void lcMainWindow::SetTransformType(lcTransformType TransformType) -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - mTransformType = TransformType; - - if (window) - window->updateTransformType(TransformType); -} - -void lcMainWindow::UpdateCameraMenu() -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->updateCameraMenu(); -} - -void lcMainWindow::UpdateCurrentCamera(int CameraIndex) -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->updateCurrentCamera(CameraIndex); -} - -void lcMainWindow::UpdatePerspective() -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->updatePerspective(mActiveView); -} - -void lcMainWindow::UpdateModels() -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->updateModels(); -} - -void lcMainWindow::UpdateCategories() -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->updateCategories(); -} - -void lcMainWindow::UpdateTitle() -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->updateTitle(lcGetActiveProject()->GetTitle(), lcGetActiveProject()->IsModified()); -} - -void lcMainWindow::UpdateModified(bool Modified) -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->updateModified(Modified); -} - -void lcMainWindow::UpdateRecentFiles() -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->updateRecentFiles(); -} - -void lcMainWindow::UpdateShortcuts() -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - window->updateShortcuts(); -} - -lcVector3 lcMainWindow::GetTransformAmount() -{ - lcQMainWindow* window = (lcQMainWindow*)mHandle; - - if (window) - return window->getTransformAmount(); - - return lcVector3(0.0f, 0.0f, 0.0f); -}