leocad/common/lc_mainwindow.h

421 lines
9 KiB
C
Raw Normal View History

#pragma once
2011-09-07 23:06:51 +02:00
2013-08-16 03:25:51 +02:00
#include "lc_basewindow.h"
2013-08-16 01:43:18 +02:00
#include "lc_array.h"
2014-12-04 02:47:28 +01:00
#include "lc_commands.h"
#include "lc_model.h"
2011-09-07 23:06:51 +02:00
2014-05-03 23:16:48 +02:00
class View;
class lcPartSelectionWidget;
2013-08-09 06:57:18 +02:00
class PiecePreview;
2015-01-26 00:04:39 +01:00
class lcQGLWidget;
class lcQPartsTree;
class lcQColorList;
class lcQPropertiesTree;
class lcTimelineWidget;
2017-02-11 21:41:00 +01:00
#ifdef QT_NO_PRINTER
class QPrinter;
#endif
2011-09-07 23:06:51 +02:00
2013-08-09 06:57:18 +02:00
#define LC_MAX_RECENT_FILES 4
2014-09-21 03:31:01 +02:00
struct lcSearchOptions
{
2017-11-19 23:12:27 +01:00
bool SearchValid;
2014-09-21 03:31:01 +02:00
bool MatchInfo;
bool MatchColor;
bool MatchName;
PieceInfo* Info;
int ColorIndex;
char Name[256];
};
2018-01-07 17:59:05 +01:00
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
typedef QTabWidget lcTabWidget;
#else
class lcTabWidget : public QTabWidget
{
public:
QTabBar* tabBar()
{
return QTabWidget::tabBar();
}
};
#endif
2016-03-06 02:47:00 +01:00
class lcModelTabWidget : public QWidget
{
Q_OBJECT
public:
lcModelTabWidget(lcModel* Model)
{
mModel = Model;
mActiveView = nullptr;
2016-03-06 02:47:00 +01:00
}
2017-03-26 19:28:58 +02:00
void ResetLayout();
void Clear();
2017-03-26 19:28:58 +02:00
QWidget* GetAnyViewWidget()
{
QWidget* Widget = layout()->itemAt(0)->widget();
while (Widget->metaObject() == &QSplitter::staticMetaObject)
Widget = ((QSplitter*)Widget)->widget(0);
return Widget;
}
2016-03-06 02:47:00 +01:00
View* GetActiveView() const
{
return mActiveView;
}
void SetActiveView(View* ActiveView)
{
mActiveView = ActiveView;
}
void AddView(View* View)
{
mViews.Add(View);
}
void RemoveView(View* View)
{
if (View == mActiveView)
mActiveView = nullptr;
2016-03-06 02:47:00 +01:00
mViews.Remove(View);
}
lcModel* GetModel() const
{
return mModel;
}
void SetModel(lcModel* Model)
{
mModel = Model;
}
2016-03-06 02:47:00 +01:00
const lcArray<View*>* GetViews() const
{
return &mViews;
}
protected:
lcModel* mModel;
View* mActiveView;
lcArray<View*> mViews;
};
2015-01-26 00:04:39 +01:00
class lcMainWindow : public QMainWindow
2011-09-07 23:06:51 +02:00
{
2015-01-26 00:04:39 +01:00
Q_OBJECT
2015-01-25 02:34:13 +01:00
2014-09-21 03:31:01 +02:00
public:
2013-08-09 06:57:18 +02:00
lcMainWindow();
~lcMainWindow();
2015-01-26 00:04:39 +01:00
void CreateWidgets();
2014-05-23 02:02:21 +02:00
lcTool GetTool() const
{
return mTool;
}
2014-08-27 18:17:09 +02:00
lcTransformType GetTransformType() const
{
return mTransformType;
}
2014-05-21 00:15:42 +02:00
bool GetAddKeys() const
{
return mAddKeys;
}
2015-04-25 00:11:50 +02:00
float GetMoveXYSnap() const
2014-10-05 07:21:51 +02:00
{
2015-04-25 00:11:50 +02:00
const float SnapXYTable[] = { 0.0f, 1.0f, 5.0f, 8.0f, 10.0f, 20.0f, 40.0f, 60.0f, 80.0f, 160.0f };
return mMoveSnapEnabled ? SnapXYTable[mMoveXYSnapIndex] : 0.0f;
2014-10-05 07:21:51 +02:00
}
2015-04-25 00:11:50 +02:00
float GetMoveZSnap() const
2014-10-05 07:21:51 +02:00
{
2015-04-25 00:11:50 +02:00
const float SnapZTable[] = { 0.0f, 1.0f, 5.0f, 8.0f, 10.0f, 20.0f, 24.0f, 48.0f, 96.0f, 192.0f };
return mMoveSnapEnabled ? SnapZTable[mMoveZSnapIndex] : 0.0f;
2014-10-05 07:21:51 +02:00
}
float GetAngleSnap() const
2014-10-05 07:21:51 +02:00
{
const float AngleTable[] = { 0.0f, 1.0f, 5.0f, 15.0f, 22.5f, 30.0f, 45.0f, 60.0f, 90.0f, 180.0f };
2015-04-25 00:11:50 +02:00
return mAngleSnapEnabled ? AngleTable[mAngleSnapIndex] : 0.0f;
2014-10-05 07:21:51 +02:00
}
2015-04-25 00:11:50 +02:00
QString GetMoveXYSnapText() const
2014-10-05 07:21:51 +02:00
{
2015-04-25 00:11:50 +02:00
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") };
return mMoveSnapEnabled ? SnapXYText[mMoveXYSnapIndex] : tr("None");
2014-10-05 07:21:51 +02:00
}
2015-04-25 00:11:50 +02:00
QString GetMoveZSnapText() const
2014-10-05 07:21:51 +02:00
{
2015-04-25 00:11:50 +02:00
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") };
return mMoveSnapEnabled ? SnapZText[mMoveZSnapIndex] : tr("None");
2014-10-05 07:21:51 +02:00
}
2015-04-25 00:11:50 +02:00
QString GetAngleSnapText() const
2014-10-05 07:21:51 +02:00
{
2015-04-25 00:11:50 +02:00
return mAngleSnapEnabled ? QString::number(GetAngleSnap()) : tr("None");
2014-10-05 07:21:51 +02:00
}
bool GetRelativeTransform() const
{
return mRelativeTransform;
}
2017-11-22 02:58:36 +01:00
lcSelectionMode GetSelectionMode() const
{
return mSelectionMode;
}
2016-12-16 21:52:36 +01:00
PieceInfo* GetCurrentPieceInfo() const
{
return mCurrentPieceInfo;
}
2014-05-03 23:16:48 +02:00
View* GetActiveView() const
{
lcModelTabWidget* CurrentTab = mModelTabWidget ? (lcModelTabWidget*)mModelTabWidget->currentWidget() : nullptr;
return CurrentTab ? CurrentTab->GetActiveView() : nullptr;
2014-05-03 23:16:48 +02:00
}
lcModel* GetActiveModel() const;
lcModel* GetCurrentTabModel() const
{
lcModelTabWidget* CurrentTab = (lcModelTabWidget*)mModelTabWidget->currentWidget();
return CurrentTab ? CurrentTab->GetModel() : nullptr;
}
2016-03-06 02:47:00 +01:00
const lcArray<View*>* GetViewsForModel(lcModel* Model) const
2014-05-03 23:16:48 +02:00
{
2016-03-06 02:47:00 +01:00
lcModelTabWidget* TabWidget = GetTabWidgetForModel(Model);
return TabWidget ? TabWidget->GetViews() : nullptr;
2016-03-06 02:47:00 +01:00
}
lcModelTabWidget* GetTabForView(View* View) const
{
for (int TabIdx = 0; TabIdx < mModelTabWidget->count(); TabIdx++)
{
lcModelTabWidget* TabWidget = (lcModelTabWidget*)mModelTabWidget->widget(TabIdx);
int ViewIndex = TabWidget->GetViews()->FindIndex(View);
if (ViewIndex != -1)
return TabWidget;
}
return nullptr;
2014-05-03 23:16:48 +02:00
}
2016-12-28 22:30:31 +01:00
lcPartSelectionWidget* GetPartSelectionWidget() const
{
return mPartSelectionWidget;
}
2017-11-14 23:56:37 +01:00
QMenu* GetToolsMenu() const
{
return mToolsMenu;
}
QMenu* GetViewpointMenu() const
{
return mViewpointMenu;
}
2015-12-04 21:32:10 +01:00
QMenu* GetCameraMenu() const
{
return mCameraMenu;
}
QMenu* GetProjectionMenu() const
2015-12-04 21:32:10 +01:00
{
return mProjectionMenu;
}
QMenu* GetShadingMenu() const
{
return mShadingMenu;
2015-12-04 21:32:10 +01:00
}
QByteArray GetTabLayout();
void RestoreTabLayout(const QByteArray& TabLayout);
2016-03-06 02:47:00 +01:00
void RemoveAllModelTabs();
void SetCurrentModelTab(lcModel* Model);
2015-01-16 03:07:31 +01:00
void ResetCameras();
2014-05-03 23:16:48 +02:00
void AddView(View* View);
void RemoveView(View* View);
void SetActiveView(View* ActiveView);
void UpdateAllViews();
2014-05-23 02:02:21 +02:00
void SetTool(lcTool Tool);
2014-08-27 18:17:09 +02:00
void SetTransformType(lcTransformType TransformType);
2013-08-09 06:57:18 +02:00
void SetColorIndex(int ColorIndex);
2015-04-25 00:11:50 +02:00
void SetMoveSnapEnabled(bool Enabled);
void SetAngleSnapEnabled(bool Enabled);
2014-10-05 07:21:51 +02:00
void SetMoveXYSnapIndex(int Index);
void SetMoveZSnapIndex(int Index);
void SetAngleSnapIndex(int Index);
void SetRelativeTransform(bool RelativeTransform);
void SetCurrentPieceInfo(PieceInfo* Info);
void SetShadingMode(lcShadingMode ShadingMode);
2017-11-22 02:58:36 +01:00
void SetSelectionMode(lcSelectionMode SelectionMode);
2014-10-05 07:21:51 +02:00
2014-12-04 02:47:28 +01:00
void NewProject();
bool OpenProject(const QString& FileName);
2014-12-16 00:55:17 +01:00
void MergeProject();
2017-06-26 03:20:34 +02:00
void ImportLDD();
2017-08-20 22:47:53 +02:00
void ImportInventory();
2014-12-04 02:47:28 +01:00
bool SaveProject(const QString& FileName);
bool SaveProjectIfModified();
bool SetModelFromFocus();
void SetModelFromSelection();
2014-12-04 02:47:28 +01:00
void HandleCommand(lcCommandId CommandId);
2013-08-09 06:57:18 +02:00
2014-10-12 19:34:18 +02:00
void AddRecentFile(const QString& FileName);
2013-08-09 06:57:18 +02:00
void RemoveRecentFile(int FileIndex);
2011-09-07 23:06:51 +02:00
2013-08-09 06:57:18 +02:00
void SplitHorizontal();
void SplitVertical();
2015-01-26 00:04:39 +01:00
void RemoveActiveView();
2013-08-09 06:57:18 +02:00
void ResetViews();
2011-09-07 23:06:51 +02:00
2013-08-09 06:57:18 +02:00
void TogglePrintPreview();
void ToggleFullScreen();
void UpdateSelectedObjects(bool SelectionChanged);
void UpdateTimeline(bool Clear, bool UpdateItems);
2013-08-09 06:57:18 +02:00
void UpdatePaste(bool Enabled);
2014-07-06 08:04:09 +02:00
void UpdateCurrentStep();
2014-05-21 00:15:42 +02:00
void SetAddKeys(bool AddKeys);
2014-10-05 07:21:51 +02:00
void UpdateLockSnap();
2013-08-09 06:57:18 +02:00
void UpdateSnap();
void UpdateColor();
2014-09-15 01:32:58 +02:00
void UpdateUndoRedo(const QString& UndoText, const QString& RedoText);
2013-08-09 06:57:18 +02:00
void UpdateCurrentCamera(int CameraIndex);
2014-05-03 23:16:48 +02:00
void UpdatePerspective();
void UpdateCameraMenu();
2017-08-25 21:57:14 +02:00
void UpdateShadingMode();
2017-11-22 02:58:36 +01:00
void UpdateSelectionMode();
2014-12-10 00:56:29 +01:00
void UpdateModels();
2013-08-09 06:57:18 +02:00
void UpdateCategories();
void UpdateTitle();
2013-08-09 06:57:18 +02:00
void UpdateModified(bool Modified);
void UpdateRecentFiles();
void UpdateShortcuts();
lcVector3 GetTransformAmount();
2014-10-12 19:34:18 +02:00
QString mRecentFiles[LC_MAX_RECENT_FILES];
2013-08-09 06:57:18 +02:00
int mColorIndex;
2014-09-21 03:31:01 +02:00
lcSearchOptions mSearchOptions;
2015-01-26 00:04:39 +01:00
QAction* mActions[LC_NUM_COMMANDS];
public slots:
void ProjectFileChanged(const QString& Path);
2014-05-03 23:16:48 +02:00
2015-01-26 00:04:39 +01:00
protected slots:
void UpdateGamepads();
void ModelTabContextMenuRequested(const QPoint& Point);
void ModelTabCloseOtherTabs();
void ModelTabResetViews();
2016-03-06 02:47:00 +01:00
void ModelTabClosed(int Index);
void ModelTabChanged(int Index);
2015-01-26 00:04:39 +01:00
void ClipboardChanged();
void ActionTriggered();
void ColorChanged(int ColorIndex);
void Print(QPrinter* Printer);
2015-01-25 02:34:13 +01:00
2014-05-03 23:16:48 +02:00
protected:
2015-01-26 00:04:39 +01:00
void closeEvent(QCloseEvent *event);
void dragEnterEvent(QDragEnterEvent* Event);
void dropEvent(QDropEvent* Event);
2015-01-26 00:04:39 +01:00
QMenu* createPopupMenu();
void CreateActions();
void CreateMenus();
void CreateToolBars();
void CreateStatusBar();
void SplitView(Qt::Orientation Orientation);
2017-11-19 23:12:27 +01:00
void ShowSearchDialog();
2016-08-01 05:44:15 +02:00
void ShowUpdatesDialog();
void ShowAboutDialog();
2017-12-11 03:12:31 +01:00
void ShowHTMLDialog();
2017-09-22 19:08:02 +02:00
void ShowRenderDialog();
2015-01-26 00:04:39 +01:00
void ShowPrintDialog();
2016-03-06 02:47:00 +01:00
lcModelTabWidget* GetTabWidgetForModel(lcModel* Model) const
{
for (int TabIdx = 0; TabIdx < mModelTabWidget->count(); TabIdx++)
{
lcModelTabWidget* TabWidget = (lcModelTabWidget*)mModelTabWidget->widget(TabIdx);
if (TabWidget->GetModel() == Model)
return TabWidget;
}
return nullptr;
2016-03-06 02:47:00 +01:00
}
2014-05-21 00:15:42 +02:00
QTimer mGamepadTimer;
QDateTime mLastGamepadUpdate;
2014-05-21 00:15:42 +02:00
bool mAddKeys;
2014-05-23 02:02:21 +02:00
lcTool mTool;
2014-08-27 18:17:09 +02:00
lcTransformType mTransformType;
2015-04-25 00:11:50 +02:00
bool mMoveSnapEnabled;
bool mAngleSnapEnabled;
2014-10-05 07:21:51 +02:00
int mMoveXYSnapIndex;
int mMoveZSnapIndex;
int mAngleSnapIndex;
bool mRelativeTransform;
PieceInfo* mCurrentPieceInfo;
2017-11-22 02:58:36 +01:00
lcSelectionMode mSelectionMode;
int mModelTabWidgetContextMenuIndex;
2015-01-26 00:04:39 +01:00
QAction* mActionFileRecentSeparator;
2018-01-07 17:59:05 +01:00
lcTabWidget* mModelTabWidget;
2015-01-26 00:04:39 +01:00
QToolBar* mStandardToolBar;
QToolBar* mToolsToolBar;
QToolBar* mTimeToolBar;
QDockWidget* mPartsToolBar;
2016-12-20 23:11:19 +01:00
QDockWidget* mColorsToolBar;
2015-01-26 00:04:39 +01:00
QDockWidget* mPropertiesToolBar;
QDockWidget* mTimelineToolBar;
2015-01-26 00:04:39 +01:00
lcPartSelectionWidget* mPartSelectionWidget;
2015-01-26 00:04:39 +01:00
lcQColorList* mColorList;
lcQPropertiesTree* mPropertiesWidget;
lcTimelineWidget* mTimelineWidget;
2015-01-26 00:04:39 +01:00
QLineEdit* mTransformXEdit;
QLineEdit* mTransformYEdit;
QLineEdit* mTransformZEdit;
QLabel* mStatusBarLabel;
QLabel* mStatusPositionLabel;
QLabel* mStatusSnapLabel;
QLabel* mStatusTimeLabel;
2015-12-04 21:32:10 +01:00
2017-11-14 23:56:37 +01:00
QMenu* mToolsMenu;
2015-12-04 21:32:10 +01:00
QMenu* mViewpointMenu;
QMenu* mCameraMenu;
QMenu* mProjectionMenu;
QMenu* mShadingMenu;
QMenu* mSelectionModeMenu;
2011-09-07 23:06:51 +02:00
};
2013-08-09 06:57:18 +02:00
extern class lcMainWindow* gMainWindow;