1 #pragma once 2 3 #include "lc_application.h" 4 #include "lc_shortcuts.h" 5 #include "lc_array.h" 6 #include "lc_commands.h" 7 #include "lc_model.h" 8 9 class lcPartSelectionWidget; 10 class lcPreviewDockWidget; 11 class PiecePreview; 12 class lcQPartsTree; 13 class lcQColorList; 14 class lcQPropertiesTree; 15 class lcTimelineWidget; 16 class lcElidedLabel; 17 #ifdef QT_NO_PRINTER 18 class QPrinter; 19 #endif 20 21 #define LC_MAX_RECENT_FILES 4 22 23 class lcTabBar : public QTabBar 24 { 25 public: 26 lcTabBar(QWidget* Parent = nullptr) QTabBar(Parent)27 : QTabBar(Parent), mMousePressTab(-1) 28 { 29 } 30 31 protected: 32 void mousePressEvent(QMouseEvent* Event) override; 33 void mouseReleaseEvent(QMouseEvent* Event) override; 34 35 int mMousePressTab; 36 }; 37 38 class lcModelTabWidget : public QWidget 39 { 40 Q_OBJECT 41 42 public: lcModelTabWidget(lcModel * Model)43 lcModelTabWidget(lcModel* Model) 44 { 45 mModel = Model; 46 mActiveView = nullptr; 47 } 48 GetAnyViewWidget()49 QWidget* GetAnyViewWidget() 50 { 51 QWidget* Widget = layout()->itemAt(0)->widget(); 52 53 while (Widget->metaObject() == &QSplitter::staticMetaObject) 54 Widget = ((QSplitter*)Widget)->widget(0); 55 56 return Widget; 57 } 58 GetActiveView()59 lcView* GetActiveView() const 60 { 61 return mActiveView; 62 } 63 SetActiveView(lcView * ActiveView)64 void SetActiveView(lcView* ActiveView) 65 { 66 mActiveView = ActiveView; 67 } 68 RemoveView(lcView * View)69 void RemoveView(lcView* View) 70 { 71 if (View == mActiveView) 72 mActiveView = nullptr; 73 } 74 GetModel()75 lcModel* GetModel() const 76 { 77 return mModel; 78 } 79 80 protected: 81 lcModel* mModel; 82 lcView* mActiveView; 83 }; 84 85 class lcMainWindow : public QMainWindow 86 { 87 Q_OBJECT 88 89 public: 90 lcMainWindow(); 91 ~lcMainWindow(); 92 93 void CreateWidgets(); 94 GetTool()95 lcTool GetTool() const 96 { 97 return mTool; 98 } 99 GetTransformType()100 lcTransformType GetTransformType() const 101 { 102 return mTransformType; 103 } 104 GetAddKeys()105 bool GetAddKeys() const 106 { 107 return mAddKeys; 108 } 109 GetMoveXYSnap()110 float GetMoveXYSnap() const 111 { 112 const float SnapXYTable[] = { 0.0f, 1.0f, 5.0f, 8.0f, 10.0f, 20.0f, 40.0f, 60.0f, 80.0f, 160.0f }; 113 return mMoveSnapEnabled ? SnapXYTable[mMoveXYSnapIndex] : 0.0f; 114 } 115 GetMoveZSnap()116 float GetMoveZSnap() const 117 { 118 const float SnapZTable[] = { 0.0f, 1.0f, 5.0f, 8.0f, 10.0f, 20.0f, 24.0f, 48.0f, 96.0f, 192.0f }; 119 return mMoveSnapEnabled ? SnapZTable[mMoveZSnapIndex] : 0.0f; 120 } 121 GetAngleSnap()122 float GetAngleSnap() const 123 { 124 const float AngleTable[] = { 0.0f, 1.0f, 5.0f, 15.0f, 22.5f, 30.0f, 45.0f, 60.0f, 90.0f, 180.0f }; 125 return mAngleSnapEnabled ? AngleTable[mAngleSnapIndex] : 0.0f; 126 } 127 GetMoveXYSnapText()128 QString GetMoveXYSnapText() const 129 { 130 QString SnapXYText[] = { tr("0"), tr("1/20S"), tr("1/4S"), tr("1F"), tr("1/2S"), tr("1S"), tr("2S"), tr("3S"), tr("4S"), tr("8S") }; 131 return mMoveSnapEnabled ? SnapXYText[mMoveXYSnapIndex] : tr("None"); 132 } 133 GetMoveZSnapText()134 QString GetMoveZSnapText() const 135 { 136 QString SnapZText[] = { tr("0"), tr("1/20S"), tr("1/4S"), tr("1F"), tr("1/2S"), tr("1S"), tr("1B"), tr("2B"), tr("4B"), tr("8B") }; 137 return mMoveSnapEnabled ? SnapZText[mMoveZSnapIndex] : tr("None"); 138 } 139 GetAngleSnapText()140 QString GetAngleSnapText() const 141 { 142 return mAngleSnapEnabled ? QString::number(GetAngleSnap()) : tr("None"); 143 } 144 GetRelativeTransform()145 bool GetRelativeTransform() const 146 { 147 return mRelativeTransform; 148 } 149 GetSeparateTransform()150 bool GetSeparateTransform() const 151 { 152 return mLocalTransform; 153 } 154 GetSelectionMode()155 lcSelectionMode GetSelectionMode() const 156 { 157 return mSelectionMode; 158 } 159 GetCurrentPieceInfo()160 PieceInfo* GetCurrentPieceInfo() const 161 { 162 return mCurrentPieceInfo; 163 } 164 GetActiveView()165 lcView* GetActiveView() const 166 { 167 const lcModelTabWidget* const CurrentTab = mModelTabWidget ? (lcModelTabWidget*)mModelTabWidget->currentWidget() : nullptr; 168 return CurrentTab ? CurrentTab->GetActiveView() : nullptr; 169 } 170 171 lcModel* GetActiveModel() const; 172 lcModelTabWidget* GetTabForView(lcView* View) const; 173 GetCurrentTabModel()174 lcModel* GetCurrentTabModel() const 175 { 176 const lcModelTabWidget* const CurrentTab = (lcModelTabWidget*)mModelTabWidget->currentWidget(); 177 return CurrentTab ? CurrentTab->GetModel() : nullptr; 178 } 179 GetPartSelectionWidget()180 lcPartSelectionWidget* GetPartSelectionWidget() const 181 { 182 return mPartSelectionWidget; 183 } 184 GetPreviewWidget()185 lcPreviewDockWidget* GetPreviewWidget() const 186 { 187 return mPreviewWidget; 188 } 189 GetToolsMenu()190 QMenu* GetToolsMenu() const 191 { 192 return mToolsMenu; 193 } 194 GetViewpointMenu()195 QMenu* GetViewpointMenu() const 196 { 197 return mViewpointMenu; 198 } 199 GetCameraMenu()200 QMenu* GetCameraMenu() const 201 { 202 return mCameraMenu; 203 } 204 GetProjectionMenu()205 QMenu* GetProjectionMenu() const 206 { 207 return mProjectionMenu; 208 } 209 GetShadingMenu()210 QMenu* GetShadingMenu() const 211 { 212 return mShadingMenu; 213 } 214 215 QByteArray GetTabLayout(); 216 void RestoreTabLayout(const QByteArray& TabLayout); 217 void RemoveAllModelTabs(); 218 void CloseCurrentModelTab(); 219 void SetCurrentModelTab(lcModel* Model); 220 void ResetCameras(); 221 void AddView(lcView* View); 222 void RemoveView(lcView* View); 223 224 void SetTool(lcTool Tool); 225 void SetTransformType(lcTransformType TransformType); 226 void SetColorIndex(int ColorIndex); 227 void SetMoveSnapEnabled(bool Enabled); 228 void SetAngleSnapEnabled(bool Enabled); 229 void SetMoveXYSnapIndex(int Index); 230 void SetMoveZSnapIndex(int Index); 231 void SetAngleSnapIndex(int Index); 232 void SetRelativeTransform(bool RelativeTransform); 233 void SetSeparateTransform(bool SelectionTransform); 234 void SetCurrentPieceInfo(PieceInfo* Info); 235 void SetShadingMode(lcShadingMode ShadingMode); 236 void SetSelectionMode(lcSelectionMode SelectionMode); 237 void ToggleViewSphere(); 238 void ToggleAxisIcon(); 239 void ToggleGrid(); 240 void ToggleFadePreviousSteps(); 241 242 void NewProject(); 243 bool OpenProject(const QString& FileName); 244 void OpenRecentProject(int RecentFileIndex); 245 void MergeProject(); 246 void ImportLDD(); 247 void ImportInventory(); 248 bool SaveProject(const QString& FileName); 249 bool SaveProjectIfModified(); 250 bool SetModelFromFocus(); 251 void SetModelFromSelection(); 252 void HandleCommand(lcCommandId CommandId); 253 254 void AddRecentFile(const QString& FileName); 255 void RemoveRecentFile(int FileIndex); 256 257 void SplitHorizontal(); 258 void SplitVertical(); 259 void RemoveActiveView(); 260 void ResetViews(); 261 262 void TogglePrintPreview(); 263 void ToggleFullScreen(); 264 265 void UpdateSelectedObjects(bool SelectionChanged); 266 void UpdateTimeline(bool Clear, bool UpdateItems); 267 void UpdatePaste(bool Enabled); 268 void UpdateCurrentStep(); 269 void SetAddKeys(bool AddKeys); 270 void UpdateLockSnap(); 271 void UpdateSnap(); 272 void UpdateColor(); 273 void UpdateUndoRedo(const QString& UndoText, const QString& RedoText); 274 void UpdatePerspective(); 275 void UpdateCameraMenu(); 276 void UpdateShadingMode(); 277 void UpdateSelectionMode(); 278 void UpdateModels(); 279 void UpdateCategories(); 280 void UpdateTitle(); 281 void UpdateModified(bool Modified); 282 void UpdateRecentFiles(); 283 void UpdateShortcuts(); 284 285 lcVector3 GetTransformAmount(); 286 287 QString mRecentFiles[LC_MAX_RECENT_FILES]; 288 int mColorIndex; 289 QAction* mActions[LC_NUM_COMMANDS]; 290 291 public slots: 292 void ProjectFileChanged(const QString& Path); 293 void PreviewPiece(const QString& PartId, int ColorCode, bool ShowPreview); 294 void TogglePreviewWidget(bool Visible); 295 296 protected slots: 297 void ViewFocusReceived(); 298 void ViewCameraChanged(); 299 void UpdateDockWidgetActions(); 300 void UpdateGamepads(); 301 void ModelTabContextMenuRequested(const QPoint& Point); 302 void ModelTabCloseOtherTabs(); 303 void ModelTabClosed(int Index); 304 void ModelTabChanged(int Index); 305 void ClipboardChanged(); 306 void ActionTriggered(); 307 void ColorChanged(int ColorIndex); 308 void ColorButtonClicked(); 309 void Print(QPrinter* Printer); 310 void EnableWindowFlags(bool); 311 312 protected: 313 void closeEvent(QCloseEvent *event) override; 314 void dragEnterEvent(QDragEnterEvent* Event) override; 315 void dropEvent(QDropEvent* Event) override; 316 QMenu* createPopupMenu() override; 317 318 void CreateActions(); 319 void CreateMenus(); 320 void CreateToolBars(); 321 void CreateStatusBar(); 322 lcView* CreateView(lcModel* Model); 323 void SetActiveView(lcView* ActiveView); 324 void ToggleDockWidget(QWidget* DockWidget); 325 void SplitView(Qt::Orientation Orientation); 326 void ShowUpdatesDialog(); 327 void ShowAboutDialog(); 328 void ShowHTMLDialog(); 329 void ShowRenderDialog(); 330 void ShowInstructionsDialog(); 331 void ShowPrintDialog(); 332 void CreatePreviewWidget(); 333 334 bool OpenProjectFile(const QString& FileName); 335 GetTabWidgetForModel(const lcModel * Model)336 lcModelTabWidget* GetTabWidgetForModel(const lcModel* Model) const 337 { 338 for (int TabIdx = 0; TabIdx < mModelTabWidget->count(); TabIdx++) 339 { 340 lcModelTabWidget* TabWidget = (lcModelTabWidget*)mModelTabWidget->widget(TabIdx); 341 342 if (TabWidget->GetModel() == Model) 343 return TabWidget; 344 } 345 346 return nullptr; 347 } 348 349 QTimer mGamepadTimer; 350 QDateTime mLastGamepadUpdate; 351 352 bool mAddKeys; 353 lcTool mTool; 354 lcTransformType mTransformType; 355 bool mMoveSnapEnabled; 356 bool mAngleSnapEnabled; 357 int mMoveXYSnapIndex; 358 int mMoveZSnapIndex; 359 int mAngleSnapIndex; 360 bool mRelativeTransform; 361 bool mLocalTransform; 362 PieceInfo* mCurrentPieceInfo; 363 lcSelectionMode mSelectionMode; 364 int mModelTabWidgetContextMenuIndex; 365 366 QAction* mActionFileRecentSeparator; 367 368 QTabWidget* mModelTabWidget; 369 QToolBar* mStandardToolBar; 370 QToolBar* mToolsToolBar; 371 QToolBar* mTimeToolBar; 372 QDockWidget* mPreviewToolBar; 373 QDockWidget* mPartsToolBar; 374 QDockWidget* mColorsToolBar; 375 QDockWidget* mPropertiesToolBar; 376 QDockWidget* mTimelineToolBar; 377 378 lcPartSelectionWidget* mPartSelectionWidget; 379 lcQColorList* mColorList; 380 QToolButton* mColorButton; 381 lcQPropertiesTree* mPropertiesWidget; 382 lcTimelineWidget* mTimelineWidget; 383 QLineEdit* mTransformXEdit; 384 QLineEdit* mTransformYEdit; 385 QLineEdit* mTransformZEdit; 386 lcPreviewDockWidget* mPreviewWidget; 387 388 lcElidedLabel* mStatusBarLabel; 389 QLabel* mStatusPositionLabel; 390 QLabel* mStatusSnapLabel; 391 QLabel* mStatusTimeLabel; 392 393 QMenu* mTransformMenu; 394 QMenu* mToolsMenu; 395 QMenu* mViewpointMenu; 396 QMenu* mCameraMenu; 397 QMenu* mProjectionMenu; 398 QMenu* mShadingMenu; 399 QMenu* mSelectionModeMenu; 400 }; 401 402 extern class lcMainWindow* gMainWindow; 403