2013-08-09 06:57:18 +02:00
# include "lc_global.h"
# include "lc_qpreferencesdialog.h"
# include "ui_lc_qpreferencesdialog.h"
# include "lc_qutils.h"
2023-05-16 06:12:08 +02:00
# include "lc_categorydialog.h"
2013-08-09 06:57:18 +02:00
# include "lc_library.h"
# include "lc_application.h"
2016-06-14 01:57:31 +02:00
# include "lc_qutils.h"
2017-04-27 06:52:51 +02:00
# include "lc_glextensions.h"
2013-08-09 06:57:18 +02:00
# include "pieceinf.h"
2021-01-24 12:53:02 +01:00
# include "lc_edgecolordialog.h"
2023-05-21 15:53:59 +02:00
# include "lc_blenderpreferences.h"
2013-08-09 06:57:18 +02:00
2019-11-28 22:52:06 +01:00
static const char * gLanguageLocales [ ] =
{
2020-05-09 21:42:55 +02:00
" " , " cs_CZ " , " de_DE " , " en_US " , " fr_FR " , " pt_PT " , " es_ES "
2019-11-28 22:52:06 +01:00
} ;
2019-06-21 03:52:33 +02:00
lcQPreferencesDialog : : lcQPreferencesDialog ( QWidget * Parent , lcPreferencesDialogOptions * Options )
: QDialog ( Parent ) , mOptions ( Options ) , ui ( new Ui : : lcQPreferencesDialog )
2013-08-09 06:57:18 +02:00
{
2019-09-21 18:47:33 +02:00
ui - > setupUi ( this ) ;
2013-08-09 06:57:18 +02:00
2017-11-02 00:33:58 +01:00
# if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
ui - > povrayLabel - > hide ( ) ;
ui - > povrayExecutable - > hide ( ) ;
ui - > povrayExecutableBrowse - > hide ( ) ;
delete ui - > povrayLabel ;
delete ui - > povrayLayout ;
# endif
2021-02-20 19:53:12 +01:00
connect ( ui - > BackgroundSolidColorButton , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > BackgroundGradient1ColorButton , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > BackgroundGradient2ColorButton , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > ActiveViewColorButton , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > InactiveViewColorButton , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > AxesColorButton , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > TextColorButton , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > MarqueeBorderColorButton , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > MarqueeFillColorButton , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > OverlayColorButton , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > FadeStepsColor , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > HighlightNewPartsColor , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > gridStudColor , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > gridLineColor , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > ViewSphereColorButton , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > ViewSphereTextColorButton , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > ViewSphereHighlightColorButton , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
2021-11-25 00:20:08 +01:00
connect ( ui - > ObjectSelectedColorButton , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > ObjectFocusedColorButton , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > CameraColorButton , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > LightColorButton , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > ControlPointColorButton , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
connect ( ui - > ControlPointFocusedColorButton , & QToolButton : : clicked , this , & lcQPreferencesDialog : : ColorButtonClicked ) ;
2013-08-09 06:57:18 +02:00
connect ( ui - > categoriesTree , SIGNAL ( itemSelectionChanged ( ) ) , this , SLOT ( updateParts ( ) ) ) ;
ui - > shortcutEdit - > installEventFilter ( this ) ;
connect ( ui - > commandList , SIGNAL ( currentItemChanged ( QTreeWidgetItem * , QTreeWidgetItem * ) ) , this , SLOT ( commandChanged ( QTreeWidgetItem * ) ) ) ;
2016-04-25 07:26:34 +02:00
connect ( ui - > mouseTree , SIGNAL ( currentItemChanged ( QTreeWidgetItem * , QTreeWidgetItem * ) ) , this , SLOT ( MouseTreeItemChanged ( QTreeWidgetItem * ) ) ) ;
2021-01-25 13:35:04 +01:00
connect ( ui - > HighContrastButton , SIGNAL ( clicked ( ) ) , this , SLOT ( AutomateEdgeColor ( ) ) ) ;
2021-01-24 12:53:02 +01:00
connect ( ui - > AutomateEdgeColorButton , SIGNAL ( clicked ( ) ) , this , SLOT ( AutomateEdgeColor ( ) ) ) ;
2013-08-09 06:57:18 +02:00
2019-06-21 03:52:33 +02:00
ui - > partsLibrary - > setText ( mOptions - > LibraryPath ) ;
ui - > ColorConfigEdit - > setText ( mOptions - > ColorConfigPath ) ;
ui - > MinifigSettingsEdit - > setText ( mOptions - > MinifigSettingsPath ) ;
ui - > povrayExecutable - > setText ( mOptions - > POVRayPath ) ;
ui - > lgeoPath - > setText ( mOptions - > LGEOPath ) ;
ui - > authorName - > setText ( mOptions - > DefaultAuthor ) ;
ui - > mouseSensitivity - > setValue ( mOptions - > Preferences . mMouseSensitivity ) ;
2020-07-26 02:58:17 +02:00
const bool ColorThemeBlocked = ui - > ColorTheme - > blockSignals ( true ) ;
2020-07-25 22:21:22 +02:00
ui - > ColorTheme - > setCurrentIndex ( static_cast < int > ( mOptions - > Preferences . mColorTheme ) ) ;
2020-07-26 02:58:17 +02:00
ui - > ColorTheme - > blockSignals ( ColorThemeBlocked ) ;
2019-12-09 20:43:54 +01:00
for ( unsigned int LanguageIdx = 0 ; LanguageIdx < LC_ARRAY_COUNT ( gLanguageLocales ) ; LanguageIdx + + )
2019-11-28 22:52:06 +01:00
{
if ( mOptions - > Language = = gLanguageLocales [ LanguageIdx ] )
{
ui - > Language - > setCurrentIndex ( LanguageIdx ) ;
break ;
}
}
2019-06-21 03:52:33 +02:00
ui - > checkForUpdates - > setCurrentIndex ( mOptions - > CheckForUpdates ) ;
ui - > fixedDirectionKeys - > setChecked ( mOptions - > Preferences . mFixedAxes ) ;
ui - > autoLoadMostRecent - > setChecked ( mOptions - > Preferences . mAutoLoadMostRecent ) ;
2020-01-02 02:06:17 +01:00
ui - > RestoreTabLayout - > setChecked ( mOptions - > Preferences . mRestoreTabLayout ) ;
2021-01-24 12:53:02 +01:00
ui - > AutomateEdgeColor - > setChecked ( mOptions - > Preferences . mAutomateEdgeColor ) ;
2019-06-21 03:52:33 +02:00
ui - > antiAliasing - > setChecked ( mOptions - > AASamples ! = 1 ) ;
if ( mOptions - > AASamples = = 8 )
2013-08-09 06:57:18 +02:00
ui - > antiAliasingSamples - > setCurrentIndex ( 2 ) ;
2019-06-21 03:52:33 +02:00
else if ( mOptions - > AASamples = = 4 )
2013-08-09 06:57:18 +02:00
ui - > antiAliasingSamples - > setCurrentIndex ( 1 ) ;
else
ui - > antiAliasingSamples - > setCurrentIndex ( 0 ) ;
2019-06-21 03:52:33 +02:00
ui - > edgeLines - > setChecked ( mOptions - > Preferences . mDrawEdgeLines ) ;
2021-03-07 18:53:35 +01:00
ui - > ConditionalLinesCheckBox - > setChecked ( mOptions - > Preferences . mDrawConditionalLines ) ;
2020-06-06 20:16:01 +02:00
2021-03-07 20:04:53 +01:00
if ( ! gSupportsShaderObjects )
{
ui - > ConditionalLinesCheckBox - > setChecked ( false ) ;
ui - > ConditionalLinesCheckBox - > setEnabled ( false ) ;
}
2021-01-15 19:29:34 +01:00
# ifndef LC_OPENGLES
2020-12-27 22:05:55 +01:00
if ( QSurfaceFormat : : defaultFormat ( ) . samples ( ) > 1 )
{
glGetFloatv ( GL_SMOOTH_LINE_WIDTH_RANGE , mLineWidthRange ) ;
glGetFloatv ( GL_SMOOTH_LINE_WIDTH_GRANULARITY , & mLineWidthGranularity ) ;
}
else
2021-01-15 19:29:34 +01:00
# endif
2020-06-06 20:16:01 +02:00
{
glGetFloatv ( GL_ALIASED_LINE_WIDTH_RANGE , mLineWidthRange ) ;
mLineWidthGranularity = 1.0f ;
}
ui - > LineWidthSlider - > setRange ( 0 , ( mLineWidthRange [ 1 ] - mLineWidthRange [ 0 ] ) / mLineWidthGranularity ) ;
ui - > LineWidthSlider - > setValue ( ( mOptions - > Preferences . mLineWidth - mLineWidthRange [ 0 ] ) / mLineWidthGranularity ) ;
2019-11-28 21:47:19 +01:00
ui - > MeshLOD - > setChecked ( mOptions - > Preferences . mAllowLOD ) ;
2020-08-16 01:16:26 +02:00
ui - > MeshLODSlider - > setRange ( 0 , 1500.0f / mMeshLODMultiplier ) ;
ui - > MeshLODSlider - > setValue ( mOptions - > Preferences . mMeshLODDistance / mMeshLODMultiplier ) ;
2020-01-02 02:06:17 +01:00
ui - > FadeSteps - > setChecked ( mOptions - > Preferences . mFadeSteps ) ;
2020-04-25 20:36:28 +02:00
ui - > HighlightNewParts - > setChecked ( mOptions - > Preferences . mHighlightNewParts ) ;
2019-06-21 03:52:33 +02:00
ui - > gridStuds - > setChecked ( mOptions - > Preferences . mDrawGridStuds ) ;
ui - > gridLines - > setChecked ( mOptions - > Preferences . mDrawGridLines ) ;
ui - > gridLineSpacing - > setText ( QString : : number ( mOptions - > Preferences . mGridLineSpacing ) ) ;
2021-01-12 03:49:57 +01:00
ui - > GridOriginCheckBox - > setChecked ( mOptions - > Preferences . mDrawGridOrigin ) ;
2020-07-11 19:47:52 +02:00
ui - > AxisIconCheckBox - > setChecked ( mOptions - > Preferences . mDrawAxes ) ;
2019-01-20 20:59:18 +01:00
2021-05-30 20:52:13 +02:00
ui - > AxisIconLocationCombo - > setCurrentIndex ( ( int ) mOptions - > Preferences . mAxisIconLocation ) ;
2020-11-26 20:51:50 +01:00
if ( ! mOptions - > Preferences . mBackgroundGradient )
ui - > BackgroundSolidRadio - > setChecked ( true ) ;
else
ui - > BackgroundGradientRadio - > setChecked ( true ) ;
2019-06-21 03:52:33 +02:00
ui - > ViewSphereLocationCombo - > setCurrentIndex ( ( int ) mOptions - > Preferences . mViewSphereLocation ) ;
2019-01-20 20:59:18 +01:00
2020-01-05 20:38:24 +01:00
if ( mOptions - > Preferences . mViewSphereEnabled )
2019-01-20 20:59:18 +01:00
{
2020-01-05 20:38:24 +01:00
switch ( mOptions - > Preferences . mViewSphereSize )
{
case 200 :
ui - > ViewSphereSizeCombo - > setCurrentIndex ( 3 ) ;
break ;
case 100 :
ui - > ViewSphereSizeCombo - > setCurrentIndex ( 2 ) ;
break ;
case 50 :
ui - > ViewSphereSizeCombo - > setCurrentIndex ( 1 ) ;
break ;
default :
ui - > ViewSphereSizeCombo - > setCurrentIndex ( 0 ) ;
break ;
}
2019-01-20 20:59:18 +01:00
}
2020-01-05 20:38:24 +01:00
else
ui - > ViewSphereSizeCombo - > setCurrentIndex ( 0 ) ;
2017-08-25 21:57:14 +02:00
2020-10-03 12:02:27 +02:00
ui - > PreviewAxisIconCheckBox - > setChecked ( mOptions - > Preferences . mDrawPreviewAxis ) ;
ui - > PreviewViewSphereLocationCombo - > setCurrentIndex ( ( int ) mOptions - > Preferences . mPreviewViewSphereLocation ) ;
if ( mOptions - > Preferences . mPreviewViewSphereEnabled )
{
switch ( mOptions - > Preferences . mPreviewViewSphereSize )
{
case 100 :
ui - > PreviewViewSphereSizeCombo - > setCurrentIndex ( 3 ) ;
break ;
case 75 :
ui - > PreviewViewSphereSizeCombo - > setCurrentIndex ( 2 ) ;
break ;
case 50 :
ui - > PreviewViewSphereSizeCombo - > setCurrentIndex ( 1 ) ;
break ;
default :
ui - > PreviewViewSphereSizeCombo - > setCurrentIndex ( 0 ) ;
break ;
}
}
else
ui - > PreviewViewSphereSizeCombo - > setCurrentIndex ( 0 ) ;
2021-01-20 13:19:29 +01:00
if ( ! lcGetPiecesLibrary ( ) - > SupportsStudStyle ( ) )
ui - > studStyleCombo - > setEnabled ( false ) ;
2020-12-13 00:21:30 +01:00
2021-01-22 23:16:28 +01:00
ui - > studStyleCombo - > setCurrentIndex ( static_cast < int > ( mOptions - > StudStyle ) ) ;
2019-09-21 18:47:33 +02:00
2017-08-25 21:57:14 +02:00
if ( ! gSupportsShaderObjects )
2020-03-22 21:44:20 +01:00
ui - > ShadingMode - > removeItem ( static_cast < int > ( lcShadingMode : : DefaultLights ) ) ;
ui - > ShadingMode - > setCurrentIndex ( static_cast < int > ( mOptions - > Preferences . mShadingMode ) ) ;
2013-08-09 06:57:18 +02:00
2021-01-01 00:54:28 +01:00
auto SetButtonPixmap = [ ] ( quint32 Color , QToolButton * Button )
{
QPixmap Pixmap ( 12 , 12 ) ;
Pixmap . fill ( QColor ( LC_RGBA_RED ( Color ) , LC_RGBA_GREEN ( Color ) , LC_RGBA_BLUE ( Color ) ) ) ;
Button - > setIcon ( Pixmap ) ;
} ;
SetButtonPixmap ( mOptions - > Preferences . mBackgroundSolidColor , ui - > BackgroundSolidColorButton ) ;
SetButtonPixmap ( mOptions - > Preferences . mBackgroundGradientColorTop , ui - > BackgroundGradient1ColorButton ) ;
SetButtonPixmap ( mOptions - > Preferences . mBackgroundGradientColorBottom , ui - > BackgroundGradient2ColorButton ) ;
SetButtonPixmap ( mOptions - > Preferences . mAxesColor , ui - > AxesColorButton ) ;
SetButtonPixmap ( mOptions - > Preferences . mTextColor , ui - > TextColorButton ) ;
SetButtonPixmap ( mOptions - > Preferences . mMarqueeBorderColor , ui - > MarqueeBorderColorButton ) ;
SetButtonPixmap ( mOptions - > Preferences . mMarqueeFillColor , ui - > MarqueeFillColorButton ) ;
SetButtonPixmap ( mOptions - > Preferences . mOverlayColor , ui - > OverlayColorButton ) ;
SetButtonPixmap ( mOptions - > Preferences . mActiveViewColor , ui - > ActiveViewColorButton ) ;
SetButtonPixmap ( mOptions - > Preferences . mInactiveViewColor , ui - > InactiveViewColorButton ) ;
SetButtonPixmap ( mOptions - > Preferences . mFadeStepsColor , ui - > FadeStepsColor ) ;
SetButtonPixmap ( mOptions - > Preferences . mHighlightNewPartsColor , ui - > HighlightNewPartsColor ) ;
SetButtonPixmap ( mOptions - > Preferences . mGridStudColor , ui - > gridStudColor ) ;
SetButtonPixmap ( mOptions - > Preferences . mGridLineColor , ui - > gridLineColor ) ;
SetButtonPixmap ( mOptions - > Preferences . mViewSphereColor , ui - > ViewSphereColorButton ) ;
SetButtonPixmap ( mOptions - > Preferences . mViewSphereTextColor , ui - > ViewSphereTextColorButton ) ;
SetButtonPixmap ( mOptions - > Preferences . mViewSphereHighlightColor , ui - > ViewSphereHighlightColorButton ) ;
2021-11-25 00:20:08 +01:00
SetButtonPixmap ( mOptions - > Preferences . mObjectSelectedColor , ui - > ObjectSelectedColorButton ) ;
SetButtonPixmap ( mOptions - > Preferences . mObjectFocusedColor , ui - > ObjectFocusedColorButton ) ;
SetButtonPixmap ( mOptions - > Preferences . mCameraColor , ui - > CameraColorButton ) ;
SetButtonPixmap ( mOptions - > Preferences . mLightColor , ui - > LightColorButton ) ;
SetButtonPixmap ( mOptions - > Preferences . mControlPointColor , ui - > ControlPointColorButton ) ;
SetButtonPixmap ( mOptions - > Preferences . mControlPointFocusedColor , ui - > ControlPointFocusedColorButton ) ;
2019-01-20 20:59:18 +01:00
2021-01-26 02:05:10 +01:00
on_studStyleCombo_currentIndexChanged ( ui - > studStyleCombo - > currentIndex ( ) ) ;
2013-08-09 06:57:18 +02:00
on_antiAliasing_toggled ( ) ;
2021-01-24 12:53:02 +01:00
on_AutomateEdgeColor_toggled ( ) ;
2013-08-09 06:57:18 +02:00
on_edgeLines_toggled ( ) ;
2020-06-06 20:16:01 +02:00
on_LineWidthSlider_valueChanged ( ) ;
2020-08-16 01:16:26 +02:00
on_MeshLODSlider_valueChanged ( ) ;
2020-04-25 21:16:37 +02:00
on_FadeSteps_toggled ( ) ;
2020-04-25 20:36:28 +02:00
on_HighlightNewParts_toggled ( ) ;
2013-08-31 23:58:47 +02:00
on_gridStuds_toggled ( ) ;
on_gridLines_toggled ( ) ;
2019-07-14 21:58:20 +02:00
on_ViewSphereSizeCombo_currentIndexChanged ( ui - > ViewSphereSizeCombo - > currentIndex ( ) ) ;
2020-10-03 12:02:27 +02:00
on_PreviewViewSphereSizeCombo_currentIndexChanged ( ui - > PreviewViewSphereSizeCombo - > currentIndex ( ) ) ;
2013-08-09 06:57:18 +02:00
updateCategories ( ) ;
ui - > categoriesTree - > setCurrentItem ( ui - > categoriesTree - > topLevelItem ( 0 ) ) ;
updateCommandList ( ) ;
new lcQTreeWidgetColumnStretcher ( ui - > commandList , 0 ) ;
2017-04-14 02:26:40 +02:00
commandChanged ( nullptr ) ;
2016-04-25 07:26:34 +02:00
UpdateMouseTree ( ) ;
2017-07-11 23:25:06 +02:00
ui - > mouseTree - > header ( ) - > setSectionResizeMode ( 0 , QHeaderView : : Stretch ) ;
ui - > mouseTree - > header ( ) - > setSectionResizeMode ( 1 , QHeaderView : : ResizeToContents ) ;
ui - > mouseTree - > header ( ) - > setSectionResizeMode ( 2 , QHeaderView : : ResizeToContents ) ;
2017-04-14 02:26:40 +02:00
MouseTreeItemChanged ( nullptr ) ;
2013-08-09 06:57:18 +02:00
}
lcQPreferencesDialog : : ~ lcQPreferencesDialog ( )
{
2019-09-21 18:47:33 +02:00
delete ui ;
2013-08-09 06:57:18 +02:00
}
void lcQPreferencesDialog : : accept ( )
{
2013-09-01 23:45:19 +02:00
int gridLineSpacing = ui - > gridLineSpacing - > text ( ) . toInt ( ) ;
if ( gridLineSpacing < 1 )
{
QMessageBox : : information ( this , " LeoCAD " , tr ( " Grid spacing must be greater than 0. " ) ) ;
return ;
}
2019-06-21 03:52:33 +02:00
mOptions - > LibraryPath = ui - > partsLibrary - > text ( ) ;
mOptions - > MinifigSettingsPath = ui - > MinifigSettingsEdit - > text ( ) ;
mOptions - > ColorConfigPath = ui - > ColorConfigEdit - > text ( ) ;
mOptions - > POVRayPath = ui - > povrayExecutable - > text ( ) ;
mOptions - > LGEOPath = ui - > lgeoPath - > text ( ) ;
mOptions - > DefaultAuthor = ui - > authorName - > text ( ) ;
mOptions - > Preferences . mMouseSensitivity = ui - > mouseSensitivity - > value ( ) ;
2020-07-25 22:21:22 +02:00
mOptions - > Preferences . mColorTheme = static_cast < lcColorTheme > ( ui - > ColorTheme - > currentIndex ( ) ) ;
2021-01-24 12:53:02 +01:00
mOptions - > Preferences . mAutomateEdgeColor = ui - > AutomateEdgeColor - > isChecked ( ) ;
2019-11-28 22:52:06 +01:00
int Language = ui - > Language - > currentIndex ( ) ;
2020-10-03 12:02:27 +02:00
if ( Language < 0 | | Language > static_cast < int > ( LC_ARRAY_COUNT ( gLanguageLocales ) ) )
2019-11-28 22:52:06 +01:00
Language = 0 ;
mOptions - > Language = gLanguageLocales [ Language ] ;
2019-06-21 03:52:33 +02:00
mOptions - > CheckForUpdates = ui - > checkForUpdates - > currentIndex ( ) ;
mOptions - > Preferences . mFixedAxes = ui - > fixedDirectionKeys - > isChecked ( ) ;
mOptions - > Preferences . mAutoLoadMostRecent = ui - > autoLoadMostRecent - > isChecked ( ) ;
2020-01-02 02:06:17 +01:00
mOptions - > Preferences . mRestoreTabLayout = ui - > RestoreTabLayout - > isChecked ( ) ;
2013-08-09 06:57:18 +02:00
if ( ! ui - > antiAliasing - > isChecked ( ) )
2019-06-21 03:52:33 +02:00
mOptions - > AASamples = 1 ;
2013-08-09 06:57:18 +02:00
else if ( ui - > antiAliasingSamples - > currentIndex ( ) = = 2 )
2019-06-21 03:52:33 +02:00
mOptions - > AASamples = 8 ;
2013-08-09 06:57:18 +02:00
else if ( ui - > antiAliasingSamples - > currentIndex ( ) = = 1 )
2019-06-21 03:52:33 +02:00
mOptions - > AASamples = 4 ;
2013-08-09 06:57:18 +02:00
else
2019-06-21 03:52:33 +02:00
mOptions - > AASamples = 2 ;
2013-08-09 06:57:18 +02:00
2019-06-21 03:52:33 +02:00
mOptions - > Preferences . mDrawEdgeLines = ui - > edgeLines - > isChecked ( ) ;
2021-03-07 18:53:35 +01:00
mOptions - > Preferences . mDrawConditionalLines = ui - > ConditionalLinesCheckBox - > isChecked ( ) ;
2020-06-06 20:16:01 +02:00
mOptions - > Preferences . mLineWidth = mLineWidthRange [ 0 ] + static_cast < float > ( ui - > LineWidthSlider - > value ( ) ) * mLineWidthGranularity ;
2019-11-28 21:47:19 +01:00
mOptions - > Preferences . mAllowLOD = ui - > MeshLOD - > isChecked ( ) ;
2020-08-16 01:16:26 +02:00
mOptions - > Preferences . mMeshLODDistance = ui - > MeshLODSlider - > value ( ) * mMeshLODMultiplier ;
2020-01-02 02:06:17 +01:00
mOptions - > Preferences . mFadeSteps = ui - > FadeSteps - > isChecked ( ) ;
2020-04-25 20:36:28 +02:00
mOptions - > Preferences . mHighlightNewParts = ui - > HighlightNewParts - > isChecked ( ) ;
2013-08-09 06:57:18 +02:00
2019-06-21 03:52:33 +02:00
mOptions - > Preferences . mDrawGridStuds = ui - > gridStuds - > isChecked ( ) ;
mOptions - > Preferences . mDrawGridLines = ui - > gridLines - > isChecked ( ) ;
mOptions - > Preferences . mGridLineSpacing = gridLineSpacing ;
2021-01-12 03:49:57 +01:00
mOptions - > Preferences . mDrawGridOrigin = ui - > GridOriginCheckBox - > isChecked ( ) ;
2013-08-09 06:57:18 +02:00
2020-11-26 20:51:50 +01:00
mOptions - > Preferences . mBackgroundGradient = ui - > BackgroundGradientRadio - > isChecked ( ) ;
2020-07-11 19:47:52 +02:00
mOptions - > Preferences . mDrawAxes = ui - > AxisIconCheckBox - > isChecked ( ) ;
2021-05-30 20:52:13 +02:00
mOptions - > Preferences . mAxisIconLocation = ( lcAxisIconLocation ) ui - > AxisIconLocationCombo - > currentIndex ( ) ;
2020-12-30 22:44:08 +01:00
mOptions - > Preferences . mViewSphereEnabled = ui - > ViewSphereSizeCombo - > currentIndex ( ) > 0 ;
2019-06-21 03:52:33 +02:00
mOptions - > Preferences . mViewSphereLocation = ( lcViewSphereLocation ) ui - > ViewSphereLocationCombo - > currentIndex ( ) ;
2019-01-20 20:59:18 +01:00
switch ( ui - > ViewSphereSizeCombo - > currentIndex ( ) )
{
case 3 :
2019-06-21 03:52:33 +02:00
mOptions - > Preferences . mViewSphereSize = 200 ;
2019-01-20 20:59:18 +01:00
break ;
case 2 :
2019-06-21 03:52:33 +02:00
mOptions - > Preferences . mViewSphereSize = 100 ;
2019-01-20 20:59:18 +01:00
break ;
case 1 :
2019-06-21 03:52:33 +02:00
mOptions - > Preferences . mViewSphereSize = 50 ;
2019-01-20 20:59:18 +01:00
break ;
}
2019-06-21 03:52:33 +02:00
mOptions - > Preferences . mShadingMode = ( lcShadingMode ) ui - > ShadingMode - > currentIndex ( ) ;
2013-08-09 06:57:18 +02:00
2021-01-22 23:16:28 +01:00
mOptions - > StudStyle = static_cast < lcStudStyle > ( ui - > studStyleCombo - > currentIndex ( ) ) ;
2019-09-21 18:47:33 +02:00
2020-10-03 12:02:27 +02:00
mOptions - > Preferences . mDrawPreviewAxis = ui - > PreviewAxisIconCheckBox - > isChecked ( ) ;
2020-12-30 22:44:08 +01:00
mOptions - > Preferences . mPreviewViewSphereEnabled = ui - > PreviewViewSphereSizeCombo - > currentIndex ( ) > 0 ;
2020-10-03 12:02:27 +02:00
mOptions - > Preferences . mPreviewViewSphereLocation = ( lcViewSphereLocation ) ui - > PreviewViewSphereLocationCombo - > currentIndex ( ) ;
switch ( ui - > PreviewViewSphereSizeCombo - > currentIndex ( ) )
{
case 3 :
mOptions - > Preferences . mPreviewViewSphereSize = 100 ;
break ;
case 2 :
mOptions - > Preferences . mPreviewViewSphereSize = 75 ;
break ;
case 1 :
mOptions - > Preferences . mPreviewViewSphereSize = 50 ;
break ;
}
2013-08-09 06:57:18 +02:00
QDialog : : accept ( ) ;
}
void lcQPreferencesDialog : : on_partsLibraryBrowse_clicked ( )
{
2019-03-10 01:38:54 +01:00
QString result = QFileDialog : : getExistingDirectory ( this , tr ( " Select Parts Library Folder " ) , ui - > partsLibrary - > text ( ) ) ;
2019-03-06 19:54:17 +01:00
if ( ! result . isEmpty ( ) )
ui - > partsLibrary - > setText ( QDir : : toNativeSeparators ( result ) ) ;
}
void lcQPreferencesDialog : : on_partsArchiveBrowse_clicked ( )
{
2019-03-10 01:38:54 +01:00
QString result = QFileDialog : : getOpenFileName ( this , tr ( " Select Parts Library Archive " ) , ui - > partsLibrary - > text ( ) , tr ( " Supported Archives (*.zip *.bin);;All Files (*.*) " ) ) ;
2013-08-09 06:57:18 +02:00
if ( ! result . isEmpty ( ) )
ui - > partsLibrary - > setText ( QDir : : toNativeSeparators ( result ) ) ;
}
2023-05-21 15:53:59 +02:00
void lcQPreferencesDialog : : on_BlenderAddonSettingsButton_clicked ( )
{
int Width = 1280 ;
int Height = 720 ;
double Scale = 1.0f ;
lcBlenderPreferencesDialog : : GetBlenderPreferences (
Width ,
Height ,
Scale ,
this ) ;
Q_UNUSED ( Width )
Q_UNUSED ( Height )
Q_UNUSED ( Scale )
}
2019-06-21 03:52:33 +02:00
void lcQPreferencesDialog : : on_ColorConfigBrowseButton_clicked ( )
{
QString Result = QFileDialog : : getOpenFileName ( this , tr ( " Select Color Configuration File " ) , ui - > ColorConfigEdit - > text ( ) , tr ( " Settings Files (*.ldr);;All Files (*.*) " ) ) ;
if ( ! Result . isEmpty ( ) )
ui - > ColorConfigEdit - > setText ( QDir : : toNativeSeparators ( Result ) ) ;
}
void lcQPreferencesDialog : : on_MinifigSettingsBrowseButton_clicked ( )
{
QString Result = QFileDialog : : getOpenFileName ( this , tr ( " Select Minifig Settings File " ) , ui - > MinifigSettingsEdit - > text ( ) , tr ( " Settings Files (*.ini);;All Files (*.*) " ) ) ;
if ( ! Result . isEmpty ( ) )
ui - > MinifigSettingsEdit - > setText ( QDir : : toNativeSeparators ( Result ) ) ;
}
2013-08-17 23:54:07 +02:00
void lcQPreferencesDialog : : on_povrayExecutableBrowse_clicked ( )
2013-08-17 03:17:23 +02:00
{
# ifdef Q_OS_WIN
QString filter ( tr ( " Executable Files (*.exe) ; ; All Files ( * . * ) " )) ;
# else
QString filter ( tr ( " All Files (*.*) " )) ;
# endif
2019-06-21 03:52:33 +02:00
QString result = QFileDialog : : getOpenFileName ( this , tr ( " Select POV-Ray Executable " ) , ui - > povrayExecutable - > text ( ) , filter ) ;
2013-08-17 03:17:23 +02:00
if ( ! result . isEmpty ( ) )
ui - > povrayExecutable - > setText ( QDir : : toNativeSeparators ( result ) ) ;
}
2013-08-17 23:54:07 +02:00
void lcQPreferencesDialog : : on_lgeoPathBrowse_clicked ( )
2013-08-17 03:17:23 +02:00
{
2018-03-10 20:41:23 +01:00
QString result = QFileDialog : : getExistingDirectory ( this , tr ( " Open LGEO Folder " ) , ui - > lgeoPath - > text ( ) ) ;
2013-08-17 03:17:23 +02:00
if ( ! result . isEmpty ( ) )
2018-03-10 20:41:23 +01:00
ui - > lgeoPath - > setText ( QDir : : toNativeSeparators ( result ) ) ;
2013-08-17 03:17:23 +02:00
}
2020-08-16 00:23:44 +02:00
void lcQPreferencesDialog : : on_ColorTheme_currentIndexChanged ( int Index )
2020-07-25 22:21:22 +02:00
{
2020-08-16 00:23:44 +02:00
Q_UNUSED ( Index ) ;
2020-07-25 22:21:22 +02:00
if ( QMessageBox : : question ( this , tr ( " Reset Colors " ) , tr ( " Would you like to also reset the interface colors to match the color theme? " ) ) = = QMessageBox : : Yes )
mOptions - > Preferences . SetInterfaceColors ( static_cast < lcColorTheme > ( ui - > ColorTheme - > currentIndex ( ) ) ) ;
}
2019-01-20 20:59:18 +01:00
void lcQPreferencesDialog : : ColorButtonClicked ( )
2013-08-31 23:58:47 +02:00
{
2020-04-25 20:36:28 +02:00
QObject * Button = sender ( ) ;
QString Title ;
quint32 * Color = nullptr ;
QColorDialog : : ColorDialogOptions DialogOptions ;
2013-08-31 23:58:47 +02:00
2020-11-26 20:51:50 +01:00
if ( Button = = ui - > BackgroundSolidColorButton )
{
Color = & mOptions - > Preferences . mBackgroundSolidColor ;
Title = tr ( " Select Background Color " ) ;
}
else if ( Button = = ui - > BackgroundGradient1ColorButton )
{
Color = & mOptions - > Preferences . mBackgroundGradientColorTop ;
Title = tr ( " Select Gradient Top Color " ) ;
}
else if ( Button = = ui - > BackgroundGradient2ColorButton )
{
Color = & mOptions - > Preferences . mBackgroundGradientColorBottom ;
Title = tr ( " Select Gradient Bottom Color " ) ;
}
else if ( Button = = ui - > AxesColorButton )
2020-07-11 19:47:52 +02:00
{
Color = & mOptions - > Preferences . mAxesColor ;
Title = tr ( " Select Axes Color " ) ;
}
2020-12-30 22:44:08 +01:00
else if ( Button = = ui - > TextColorButton )
{
Color = & mOptions - > Preferences . mTextColor ;
Title = tr ( " Select Text Color " ) ;
}
2021-01-01 00:54:28 +01:00
else if ( Button = = ui - > MarqueeBorderColorButton )
{
Color = & mOptions - > Preferences . mMarqueeBorderColor ;
Title = tr ( " Select Marquee Border Color " ) ;
}
else if ( Button = = ui - > MarqueeFillColorButton )
{
Color = & mOptions - > Preferences . mMarqueeFillColor ;
Title = tr ( " Select Marquee Fill Color " ) ;
DialogOptions = QColorDialog : : ShowAlphaChannel ;
}
2020-07-11 19:47:52 +02:00
else if ( Button = = ui - > OverlayColorButton )
{
Color = & mOptions - > Preferences . mOverlayColor ;
Title = tr ( " Select Overlay Color " ) ;
}
2020-07-25 22:21:22 +02:00
else if ( Button = = ui - > ActiveViewColorButton )
{
Color = & mOptions - > Preferences . mActiveViewColor ;
Title = tr ( " Select Active View Color " ) ;
}
2020-12-12 03:37:16 +01:00
else if ( Button = = ui - > InactiveViewColorButton )
{
Color = & mOptions - > Preferences . mInactiveViewColor ;
Title = tr ( " Select Inactive View Color " ) ;
}
2020-07-11 19:47:52 +02:00
else if ( Button = = ui - > FadeStepsColor )
2020-04-25 21:16:37 +02:00
{
Color = & mOptions - > Preferences . mFadeStepsColor ;
Title = tr ( " Select Fade Color " ) ;
DialogOptions = QColorDialog : : ShowAlphaChannel ;
}
else if ( Button = = ui - > HighlightNewPartsColor )
2020-04-25 20:36:28 +02:00
{
Color = & mOptions - > Preferences . mHighlightNewPartsColor ;
Title = tr ( " Select Highlight Color " ) ;
DialogOptions = QColorDialog : : ShowAlphaChannel ;
}
else if ( Button = = ui - > gridStudColor )
2013-08-31 23:58:47 +02:00
{
2020-04-25 20:36:28 +02:00
Color = & mOptions - > Preferences . mGridStudColor ;
Title = tr ( " Select Grid Stud Color " ) ;
DialogOptions = QColorDialog : : ShowAlphaChannel ;
2013-08-31 23:58:47 +02:00
}
2020-04-25 20:36:28 +02:00
else if ( Button = = ui - > gridLineColor )
2013-08-31 23:58:47 +02:00
{
2020-04-25 20:36:28 +02:00
Color = & mOptions - > Preferences . mGridLineColor ;
Title = tr ( " Select Grid Line Color " ) ;
2013-08-31 23:58:47 +02:00
}
2020-04-25 20:36:28 +02:00
else if ( Button = = ui - > ViewSphereColorButton )
2019-01-20 20:59:18 +01:00
{
2020-04-25 20:36:28 +02:00
Color = & mOptions - > Preferences . mViewSphereColor ;
Title = tr ( " Select View Sphere Color " ) ;
2019-01-20 20:59:18 +01:00
}
2020-04-25 20:36:28 +02:00
else if ( Button = = ui - > ViewSphereTextColorButton )
2019-01-20 20:59:18 +01:00
{
2020-04-25 20:36:28 +02:00
Color = & mOptions - > Preferences . mViewSphereTextColor ;
Title = tr ( " Select View Sphere Text Color " ) ;
2019-01-20 20:59:18 +01:00
}
2020-04-25 20:36:28 +02:00
else if ( Button = = ui - > ViewSphereHighlightColorButton )
2019-01-20 20:59:18 +01:00
{
2020-04-25 20:36:28 +02:00
Color = & mOptions - > Preferences . mViewSphereHighlightColor ;
Title = tr ( " Select View Sphere Highlight Color " ) ;
2019-01-20 20:59:18 +01:00
}
2021-11-25 00:20:08 +01:00
else if ( Button = = ui - > ObjectSelectedColorButton )
{
Color = & mOptions - > Preferences . mObjectSelectedColor ;
2021-11-25 03:04:22 +01:00
Title = tr ( " Select Object Selected Color " ) ;
2021-11-25 00:20:08 +01:00
}
else if ( Button = = ui - > ObjectFocusedColorButton )
{
Color = & mOptions - > Preferences . mObjectFocusedColor ;
Title = tr ( " Select Object Focused Color " ) ;
}
else if ( Button = = ui - > CameraColorButton )
{
Color = & mOptions - > Preferences . mCameraColor ;
Title = tr ( " Select Camera Color " ) ;
}
else if ( Button = = ui - > LightColorButton )
{
Color = & mOptions - > Preferences . mLightColor ;
Title = tr ( " Select Light Color " ) ;
}
else if ( Button = = ui - > ControlPointColorButton )
{
Color = & mOptions - > Preferences . mControlPointColor ;
Title = tr ( " Select Control Point Color " ) ;
DialogOptions = QColorDialog : : ShowAlphaChannel ;
}
else if ( Button = = ui - > ControlPointFocusedColorButton )
{
Color = & mOptions - > Preferences . mControlPointFocusedColor ;
Title = tr ( " Select Control Point Focused Color " ) ;
DialogOptions = QColorDialog : : ShowAlphaChannel ;
}
2017-02-13 03:05:20 +01:00
else
return ;
2013-08-31 23:58:47 +02:00
2020-04-25 20:36:28 +02:00
QColor oldColor = QColor ( LC_RGBA_RED ( * Color ) , LC_RGBA_GREEN ( * Color ) , LC_RGBA_BLUE ( * Color ) , LC_RGBA_ALPHA ( * Color ) ) ;
QColor newColor = QColorDialog : : getColor ( oldColor , this , Title , DialogOptions ) ;
2013-08-31 23:58:47 +02:00
if ( newColor = = oldColor | | ! newColor . isValid ( ) )
return ;
2020-04-25 20:36:28 +02:00
* Color = LC_RGBA ( newColor . red ( ) , newColor . green ( ) , newColor . blue ( ) , newColor . alpha ( ) ) ;
2013-08-31 23:58:47 +02:00
QPixmap pix ( 12 , 12 ) ;
2021-01-01 00:54:28 +01:00
newColor . setAlpha ( 255 ) ;
2013-08-31 23:58:47 +02:00
pix . fill ( newColor ) ;
2020-04-25 20:36:28 +02:00
( ( QToolButton * ) Button ) - > setIcon ( pix ) ;
2013-08-31 23:58:47 +02:00
}
2013-08-09 06:57:18 +02:00
void lcQPreferencesDialog : : on_antiAliasing_toggled ( )
{
ui - > antiAliasingSamples - > setEnabled ( ui - > antiAliasing - > isChecked ( ) ) ;
}
void lcQPreferencesDialog : : on_edgeLines_toggled ( )
{
2021-03-07 18:53:35 +01:00
const bool Enable = ui - > edgeLines - > isChecked ( ) | | ui - > ConditionalLinesCheckBox - > isChecked ( ) ;
ui - > LineWidthSlider - > setEnabled ( Enable ) ;
ui - > LineWidthLabel - > setEnabled ( Enable ) ;
}
void lcQPreferencesDialog : : on_ConditionalLinesCheckBox_toggled ( )
{
const bool Enable = ui - > edgeLines - > isChecked ( ) | | ui - > ConditionalLinesCheckBox - > isChecked ( ) ;
ui - > LineWidthSlider - > setEnabled ( Enable ) ;
ui - > LineWidthLabel - > setEnabled ( Enable ) ;
2020-06-06 20:16:01 +02:00
}
void lcQPreferencesDialog : : on_LineWidthSlider_valueChanged ( )
{
float Value = mLineWidthRange [ 0 ] + static_cast < float > ( ui - > LineWidthSlider - > value ( ) ) * mLineWidthGranularity ;
ui - > LineWidthLabel - > setText ( QString : : number ( Value ) ) ;
2013-08-09 06:57:18 +02:00
}
2020-08-16 01:16:26 +02:00
void lcQPreferencesDialog : : on_MeshLODSlider_valueChanged ( )
{
float Value = ui - > MeshLODSlider - > value ( ) * mMeshLODMultiplier ;
ui - > MeshLODLabel - > setText ( QString : : number ( static_cast < int > ( Value ) ) ) ;
}
2020-04-25 21:16:37 +02:00
void lcQPreferencesDialog : : on_FadeSteps_toggled ( )
{
ui - > FadeStepsColor - > setEnabled ( ui - > FadeSteps - > isChecked ( ) ) ;
}
2020-04-25 20:36:28 +02:00
void lcQPreferencesDialog : : on_HighlightNewParts_toggled ( )
{
ui - > HighlightNewPartsColor - > setEnabled ( ui - > HighlightNewParts - > isChecked ( ) ) ;
}
2013-08-31 23:58:47 +02:00
void lcQPreferencesDialog : : on_gridStuds_toggled ( )
{
ui - > gridStudColor - > setEnabled ( ui - > gridStuds - > isChecked ( ) ) ;
}
void lcQPreferencesDialog : : on_gridLines_toggled ( )
2013-08-09 06:57:18 +02:00
{
2013-08-31 23:58:47 +02:00
ui - > gridLineColor - > setEnabled ( ui - > gridLines - > isChecked ( ) ) ;
2019-01-20 20:59:18 +01:00
ui - > gridLineSpacing - > setEnabled ( ui - > gridLines - > isChecked ( ) ) ;
}
2020-10-03 12:02:27 +02:00
void lcQPreferencesDialog : : on_PreviewViewSphereSizeCombo_currentIndexChanged ( int Index )
{
ui - > PreviewViewSphereLocationCombo - > setEnabled ( Index ! = 0 ) ;
}
2019-01-20 20:59:18 +01:00
void lcQPreferencesDialog : : on_ViewSphereSizeCombo_currentIndexChanged ( int Index )
{
2020-12-30 19:39:04 +01:00
ui - > ViewSphereLocationCombo - > setEnabled ( Index ! = 0 ) ;
2013-08-09 06:57:18 +02:00
}
2021-01-24 12:53:02 +01:00
void lcQPreferencesDialog : : on_AutomateEdgeColor_toggled ( )
{
ui - > AutomateEdgeColorButton - > setEnabled ( ui - > AutomateEdgeColor - > isChecked ( ) ) ;
}
2021-01-25 13:35:04 +01:00
void lcQPreferencesDialog : : on_studStyleCombo_currentIndexChanged ( int index )
{
2021-01-26 23:58:02 +01:00
ui - > HighContrastButton - > setEnabled ( lcIsHighContrast ( static_cast < lcStudStyle > ( index ) ) ) ;
2021-01-25 13:35:04 +01:00
}
2021-01-24 12:53:02 +01:00
void lcQPreferencesDialog : : AutomateEdgeColor ( )
{
2021-01-25 13:35:04 +01:00
lcAutomateEdgeColorDialog Dialog ( this , sender ( ) = = ui - > HighContrastButton ) ;
2021-01-24 12:53:02 +01:00
if ( Dialog . exec ( ) = = QDialog : : Accepted )
{
2023-04-17 18:37:56 +02:00
mOptions - > Preferences . mStudCylinderColorEnabled = Dialog . mStudCylinderColorEnabled ;
2021-01-26 16:42:19 +01:00
mOptions - > Preferences . mStudCylinderColor = Dialog . mStudCylinderColor ;
2023-04-17 18:37:56 +02:00
mOptions - > Preferences . mPartEdgeColorEnabled = Dialog . mPartEdgeColorEnabled ;
2021-01-26 16:42:19 +01:00
mOptions - > Preferences . mPartEdgeColor = Dialog . mPartEdgeColor ;
2023-04-17 18:37:56 +02:00
mOptions - > Preferences . mBlackEdgeColorEnabled = Dialog . mBlackEdgeColorEnabled ;
2021-01-25 13:35:04 +01:00
mOptions - > Preferences . mBlackEdgeColor = Dialog . mBlackEdgeColor ;
2023-04-17 18:37:56 +02:00
mOptions - > Preferences . mDarkEdgeColorEnabled = Dialog . mDarkEdgeColorEnabled ;
2021-01-25 13:35:04 +01:00
mOptions - > Preferences . mDarkEdgeColor = Dialog . mDarkEdgeColor ;
2021-01-24 12:53:02 +01:00
mOptions - > Preferences . mPartEdgeContrast = Dialog . mPartEdgeContrast ;
2021-01-25 08:34:22 +01:00
mOptions - > Preferences . mPartColorValueLDIndex = Dialog . mPartColorValueLDIndex ;
2021-01-24 12:53:02 +01:00
}
}
2013-08-09 06:57:18 +02:00
void lcQPreferencesDialog : : updateCategories ( )
{
2020-01-11 02:40:14 +01:00
QTreeWidgetItem * CategoryItem ;
QTreeWidget * CategoriesTree = ui - > categoriesTree ;
2013-08-09 06:57:18 +02:00
2020-01-11 02:40:14 +01:00
CategoriesTree - > clear ( ) ;
2013-08-09 06:57:18 +02:00
2020-01-11 02:40:14 +01:00
for ( int CategoryIndex = 0 ; CategoryIndex < static_cast < int > ( mOptions - > Categories . size ( ) ) ; CategoryIndex + + )
2013-08-09 06:57:18 +02:00
{
2020-01-11 02:40:14 +01:00
CategoryItem = new QTreeWidgetItem ( CategoriesTree , QStringList ( mOptions - > Categories [ CategoryIndex ] . Name ) ) ;
CategoryItem - > setData ( 0 , CategoryRole , QVariant ( CategoryIndex ) ) ;
2013-08-09 06:57:18 +02:00
}
2020-01-11 02:40:14 +01:00
CategoryItem = new QTreeWidgetItem ( CategoriesTree , QStringList ( tr ( " Unassigned " ) ) ) ;
CategoryItem - > setData ( 0 , CategoryRole , QVariant ( - 1 ) ) ;
2013-08-09 06:57:18 +02:00
}
void lcQPreferencesDialog : : updateParts ( )
{
2017-07-24 04:35:18 +02:00
lcPiecesLibrary * Library = lcGetPiecesLibrary ( ) ;
2013-08-09 06:57:18 +02:00
QTreeWidget * tree = ui - > partsTree ;
tree - > clear ( ) ;
QList < QTreeWidgetItem * > selectedItems = ui - > categoriesTree - > selectedItems ( ) ;
if ( selectedItems . empty ( ) )
return ;
QTreeWidgetItem * categoryItem = selectedItems . first ( ) ;
int categoryIndex = categoryItem - > data ( 0 , CategoryRole ) . toInt ( ) ;
if ( categoryIndex ! = - 1 )
{
2013-08-16 01:43:18 +02:00
lcArray < PieceInfo * > singleParts , groupedParts ;
2013-08-09 06:57:18 +02:00
2019-06-21 03:52:33 +02:00
Library - > GetCategoryEntries ( mOptions - > Categories [ categoryIndex ] . Keywords . constData ( ) , false , singleParts , groupedParts ) ;
2013-08-09 06:57:18 +02:00
for ( int partIndex = 0 ; partIndex < singleParts . GetSize ( ) ; partIndex + + )
{
PieceInfo * info = singleParts [ partIndex ] ;
QStringList rowList ( info - > m_strDescription ) ;
2017-07-27 18:21:55 +02:00
rowList . append ( info - > mFileName ) ;
2013-08-09 06:57:18 +02:00
new QTreeWidgetItem ( tree , rowList ) ;
}
}
else
{
2018-02-22 02:27:24 +01:00
for ( const auto & PartIt : Library - > mPieces )
2013-08-09 06:57:18 +02:00
{
2017-07-24 04:35:18 +02:00
PieceInfo * Info = PartIt . second ;
2013-08-09 06:57:18 +02:00
2020-01-11 02:40:14 +01:00
for ( categoryIndex = 0 ; categoryIndex < static_cast < int > ( mOptions - > Categories . size ( ) ) ; categoryIndex + + )
2013-08-09 06:57:18 +02:00
{
2019-06-21 03:52:33 +02:00
if ( Library - > PieceInCategory ( Info , mOptions - > Categories [ categoryIndex ] . Keywords . constData ( ) ) )
2013-08-09 06:57:18 +02:00
break ;
}
2020-01-11 02:40:14 +01:00
if ( categoryIndex = = static_cast < int > ( mOptions - > Categories . size ( ) ) )
2013-08-09 06:57:18 +02:00
{
2017-07-24 04:35:18 +02:00
QStringList rowList ( Info - > m_strDescription ) ;
2017-07-27 18:21:55 +02:00
rowList . append ( Info - > mFileName ) ;
2013-08-09 06:57:18 +02:00
new QTreeWidgetItem ( tree , rowList ) ;
}
}
}
tree - > resizeColumnToContents ( 0 ) ;
tree - > resizeColumnToContents ( 1 ) ;
}
void lcQPreferencesDialog : : on_newCategory_clicked ( )
{
lcLibraryCategory category ;
2023-05-16 06:02:17 +02:00
lcCategoryDialog dialog ( this , & category ) ;
2013-08-09 06:57:18 +02:00
if ( dialog . exec ( ) ! = QDialog : : Accepted )
return ;
2019-06-21 03:52:33 +02:00
mOptions - > CategoriesModified = true ;
mOptions - > CategoriesDefault = false ;
2020-01-11 02:40:14 +01:00
mOptions - > Categories . emplace_back ( std : : move ( category ) ) ;
2013-08-09 06:57:18 +02:00
updateCategories ( ) ;
2020-01-11 02:40:14 +01:00
ui - > categoriesTree - > setCurrentItem ( ui - > categoriesTree - > topLevelItem ( static_cast < int > ( mOptions - > Categories . size ( ) ) - 1 ) ) ;
2013-08-09 06:57:18 +02:00
}
void lcQPreferencesDialog : : on_editCategory_clicked ( )
{
QList < QTreeWidgetItem * > selectedItems = ui - > categoriesTree - > selectedItems ( ) ;
if ( selectedItems . empty ( ) )
return ;
QTreeWidgetItem * categoryItem = selectedItems . first ( ) ;
int categoryIndex = categoryItem - > data ( 0 , CategoryRole ) . toInt ( ) ;
if ( categoryIndex = = - 1 )
return ;
2023-05-16 06:02:17 +02:00
lcCategoryDialog dialog ( this , & mOptions - > Categories [ categoryIndex ] ) ;
2013-08-09 06:57:18 +02:00
if ( dialog . exec ( ) ! = QDialog : : Accepted )
return ;
2019-06-21 03:52:33 +02:00
mOptions - > CategoriesModified = true ;
mOptions - > CategoriesDefault = false ;
2013-08-09 06:57:18 +02:00
updateCategories ( ) ;
ui - > categoriesTree - > setCurrentItem ( ui - > categoriesTree - > topLevelItem ( categoryIndex ) ) ;
}
void lcQPreferencesDialog : : on_deleteCategory_clicked ( )
{
QList < QTreeWidgetItem * > selectedItems = ui - > categoriesTree - > selectedItems ( ) ;
if ( selectedItems . empty ( ) )
return ;
QTreeWidgetItem * categoryItem = selectedItems . first ( ) ;
int categoryIndex = categoryItem - > data ( 0 , CategoryRole ) . toInt ( ) ;
if ( categoryIndex = = - 1 )
return ;
2019-06-21 03:52:33 +02:00
QString question = tr ( " Are you sure you want to delete the category '%1'? " ) . arg ( mOptions - > Categories [ categoryIndex ] . Name ) ;
2013-08-09 06:57:18 +02:00
if ( QMessageBox : : question ( this , " LeoCAD " , question , QMessageBox : : Yes | QMessageBox : : No ) ! = QMessageBox : : Yes )
return ;
2019-06-21 03:52:33 +02:00
mOptions - > CategoriesModified = true ;
mOptions - > CategoriesDefault = false ;
2020-01-11 02:40:14 +01:00
mOptions - > Categories . erase ( mOptions - > Categories . begin ( ) + categoryIndex ) ;
2013-08-09 06:57:18 +02:00
updateCategories ( ) ;
}
void lcQPreferencesDialog : : on_importCategories_clicked ( )
{
2015-02-02 07:00:42 +01:00
QString FileName = QFileDialog : : getOpenFileName ( this , tr ( " Import Categories " ) , " " , tr ( " Text Files (*.txt);;All Files (*.*) " ) ) ;
2013-08-09 06:57:18 +02:00
2015-02-02 07:00:42 +01:00
if ( FileName . isEmpty ( ) )
2013-08-09 06:57:18 +02:00
return ;
2020-01-11 02:40:14 +01:00
std : : vector < lcLibraryCategory > Categories ;
2015-02-02 07:00:42 +01:00
if ( ! lcLoadCategories ( FileName , Categories ) )
2013-08-09 06:57:18 +02:00
{
QMessageBox : : warning ( this , " LeoCAD " , tr ( " Error loading categories file. " ) ) ;
return ;
}
2019-06-21 03:52:33 +02:00
mOptions - > Categories = Categories ;
mOptions - > CategoriesModified = true ;
mOptions - > CategoriesDefault = false ;
2013-08-09 06:57:18 +02:00
}
void lcQPreferencesDialog : : on_exportCategories_clicked ( )
{
2015-02-02 07:00:42 +01:00
QString FileName = QFileDialog : : getSaveFileName ( this , tr ( " Export Categories " ) , " " , tr ( " Text Files (*.txt);;All Files (*.*) " ) ) ;
2013-08-09 06:57:18 +02:00
2015-02-02 07:00:42 +01:00
if ( FileName . isEmpty ( ) )
2013-08-09 06:57:18 +02:00
return ;
2019-06-21 03:52:33 +02:00
if ( ! lcSaveCategories ( FileName , mOptions - > Categories ) )
2013-08-09 06:57:18 +02:00
{
QMessageBox : : warning ( this , " LeoCAD " , tr ( " Error saving categories file. " ) ) ;
return ;
}
}
void lcQPreferencesDialog : : on_resetCategories_clicked ( )
{
if ( QMessageBox : : question ( this , " LeoCAD " , tr ( " Are you sure you want to load the default categories? " ) , QMessageBox : : Yes | QMessageBox : : No ) ! = QMessageBox : : Yes )
return ;
2019-06-21 03:52:33 +02:00
lcResetCategories ( mOptions - > Categories ) ;
2013-08-09 06:57:18 +02:00
2019-06-21 03:52:33 +02:00
mOptions - > CategoriesModified = true ;
mOptions - > CategoriesDefault = true ;
2013-08-09 06:57:18 +02:00
updateCategories ( ) ;
}
bool lcQPreferencesDialog : : eventFilter ( QObject * object , QEvent * event )
{
2016-02-17 00:11:52 +01:00
Q_UNUSED ( object ) ;
2013-08-09 06:57:18 +02:00
if ( event - > type ( ) = = QEvent : : KeyPress )
{
QKeyEvent * keyEvent = static_cast < QKeyEvent * > ( event ) ;
int nextKey = keyEvent - > key ( ) ;
if ( nextKey = = Qt : : Key_Control | | nextKey = = Qt : : Key_Shift | | nextKey = = Qt : : Key_Meta | | nextKey = = Qt : : Key_Alt )
return true ;
Qt : : KeyboardModifiers state = keyEvent - > modifiers ( ) ;
2014-05-02 00:57:07 +02:00
QString text = QKeySequence ( nextKey ) . toString ( ) ;
if ( ( state & Qt : : ShiftModifier ) & & ( text . isEmpty ( ) | | ! text . at ( 0 ) . isPrint ( ) | | text . at ( 0 ) . isLetter ( ) | | text . at ( 0 ) . isSpace ( ) ) )
2013-08-09 06:57:18 +02:00
nextKey | = Qt : : SHIFT ;
if ( state & Qt : : ControlModifier )
nextKey | = Qt : : CTRL ;
if ( state & Qt : : MetaModifier )
nextKey | = Qt : : META ;
if ( state & Qt : : AltModifier )
nextKey | = Qt : : ALT ;
QKeySequence ks ( nextKey ) ;
ui - > shortcutEdit - > setText ( ks . toString ( QKeySequence : : NativeText ) ) ;
keyEvent - > accept ( ) ;
return true ;
}
2014-05-02 00:57:07 +02:00
if ( event - > type ( ) = = QEvent : : Shortcut | | event - > type ( ) = = QEvent : : KeyRelease | | event - > type ( ) = = QEvent : : ShortcutOverride )
2013-08-09 06:57:18 +02:00
{
event - > accept ( ) ;
return true ;
}
2017-04-21 03:56:35 +02:00
return QDialog : : eventFilter ( object , event ) ;
2013-08-09 06:57:18 +02:00
}
void lcQPreferencesDialog : : updateCommandList ( )
{
ui - > commandList - > clear ( ) ;
QMap < QString , QTreeWidgetItem * > sections ;
2020-12-10 23:58:22 +01:00
for ( unsigned int actionIdx = 0 ; actionIdx < LC_NUM_COMMANDS ; actionIdx + + )
2013-08-09 06:57:18 +02:00
{
2017-02-05 03:40:46 +01:00
if ( ! gCommands [ actionIdx ] . ID [ 0 ] )
continue ;
2016-06-13 01:05:26 +02:00
const QString identifier = tr ( gCommands [ actionIdx ] . ID ) ;
2013-08-09 06:57:18 +02:00
int pos = identifier . indexOf ( QLatin1Char ( ' . ' ) ) ;
int subPos = identifier . indexOf ( QLatin1Char ( ' . ' ) , pos + 1 ) ;
if ( subPos = = - 1 )
subPos = pos ;
const QString parentSection = identifier . left ( pos ) ;
if ( subPos ! = pos )
{
if ( ! sections . contains ( parentSection ) )
{
QTreeWidgetItem * categoryItem = new QTreeWidgetItem ( ui - > commandList , QStringList ( parentSection ) ) ;
QFont f = categoryItem - > font ( 0 ) ;
f . setBold ( true ) ;
categoryItem - > setFont ( 0 , f ) ;
sections . insert ( parentSection , categoryItem ) ;
ui - > commandList - > expandItem ( categoryItem ) ;
}
}
const QString section = identifier . left ( subPos ) ;
const QString subId = identifier . mid ( subPos + 1 ) ;
if ( ! sections . contains ( section ) )
{
QTreeWidgetItem * parent = sections [ parentSection ] ;
QTreeWidgetItem * categoryItem ;
QString subSection ;
if ( pos ! = subPos )
subSection = identifier . mid ( pos + 1 , subPos - pos - 1 ) ;
else
subSection = section ;
if ( parent )
categoryItem = new QTreeWidgetItem ( parent , QStringList ( subSection ) ) ;
else
categoryItem = new QTreeWidgetItem ( ui - > commandList , QStringList ( subSection ) ) ;
QFont f = categoryItem - > font ( 0 ) ;
f . setBold ( true ) ;
categoryItem - > setFont ( 0 , f ) ;
sections . insert ( section , categoryItem ) ;
ui - > commandList - > expandItem ( categoryItem ) ;
}
QTreeWidgetItem * item = new QTreeWidgetItem ;
2019-06-21 03:52:33 +02:00
QKeySequence sequence ( mOptions - > KeyboardShortcuts . mShortcuts [ actionIdx ] ) ;
2020-01-26 20:03:41 +01:00
item - > setText ( 0 , qApp - > translate ( " Menu " , gCommands [ actionIdx ] . MenuName ) . remove ( ' & ' ) . remove ( QLatin1String ( " ... " ) ) ) ;
2013-08-09 06:57:18 +02:00
item - > setText ( 1 , sequence . toString ( QKeySequence : : NativeText ) ) ;
2020-02-24 23:31:08 +01:00
item - > setData ( 0 , Qt : : UserRole , QVariant : : fromValue ( actionIdx ) ) ;
2013-08-09 06:57:18 +02:00
2019-06-21 03:52:33 +02:00
if ( mOptions - > KeyboardShortcuts . mShortcuts [ actionIdx ] ! = gCommands [ actionIdx ] . DefaultShortcut )
2013-08-09 06:57:18 +02:00
setShortcutModified ( item , true ) ;
sections [ section ] - > addChild ( item ) ;
}
}
void lcQPreferencesDialog : : setShortcutModified ( QTreeWidgetItem * treeItem , bool modified )
{
QFont font = treeItem - > font ( 0 ) ;
font . setItalic ( modified ) ;
treeItem - > setFont ( 0 , font ) ;
font . setBold ( modified ) ;
treeItem - > setFont ( 1 , font ) ;
}
void lcQPreferencesDialog : : commandChanged ( QTreeWidgetItem * current )
{
if ( ! current | | ! current - > data ( 0 , Qt : : UserRole ) . isValid ( ) )
{
ui - > shortcutEdit - > setText ( QString ( ) ) ;
ui - > shortcutGroup - > setEnabled ( false ) ;
return ;
}
ui - > shortcutGroup - > setEnabled ( true ) ;
int shortcutIndex = qvariant_cast < int > ( current - > data ( 0 , Qt : : UserRole ) ) ;
2019-06-21 03:52:33 +02:00
QKeySequence key ( mOptions - > KeyboardShortcuts . mShortcuts [ shortcutIndex ] ) ;
2013-08-09 06:57:18 +02:00
ui - > shortcutEdit - > setText ( key . toString ( QKeySequence : : NativeText ) ) ;
}
2019-05-12 01:46:37 +02:00
void lcQPreferencesDialog : : on_KeyboardFilterEdit_textEdited ( const QString & Text )
{
if ( Text . isEmpty ( ) )
{
std : : function < void ( QTreeWidgetItem * ) > ShowItems = [ & ShowItems ] ( QTreeWidgetItem * ParentItem )
{
for ( int ChildIdx = 0 ; ChildIdx < ParentItem - > childCount ( ) ; ChildIdx + + )
ShowItems ( ParentItem - > child ( ChildIdx ) ) ;
ParentItem - > setHidden ( false ) ;
} ;
ShowItems ( ui - > commandList - > invisibleRootItem ( ) ) ;
}
else
{
std : : function < bool ( QTreeWidgetItem * , bool ) > ShowItems = [ & ShowItems , & Text ] ( QTreeWidgetItem * ParentItem , bool ForceVisible )
{
2019-05-30 21:54:51 +02:00
ForceVisible | = ( bool ) ParentItem - > text ( 0 ) . contains ( Text , Qt : : CaseInsensitive ) | ( bool ) ParentItem - > text ( 1 ) . contains ( Text , Qt : : CaseInsensitive ) ;
2019-05-12 01:46:37 +02:00
bool Visible = ForceVisible ;
for ( int ChildIdx = 0 ; ChildIdx < ParentItem - > childCount ( ) ; ChildIdx + + )
Visible | = ShowItems ( ParentItem - > child ( ChildIdx ) , ForceVisible ) ;
ParentItem - > setHidden ( ! Visible ) ;
return Visible ;
} ;
ShowItems ( ui - > commandList - > invisibleRootItem ( ) , false ) ;
}
}
2013-08-09 06:57:18 +02:00
void lcQPreferencesDialog : : on_shortcutAssign_clicked ( )
{
2020-12-10 23:58:22 +01:00
QTreeWidgetItem * CurrentItem = ui - > commandList - > currentItem ( ) ;
2013-08-09 06:57:18 +02:00
2020-12-10 23:58:22 +01:00
if ( ! CurrentItem | | ! CurrentItem - > data ( 0 , Qt : : UserRole ) . isValid ( ) )
2013-08-09 06:57:18 +02:00
return ;
2020-12-10 23:58:22 +01:00
uint ShortcutIndex = CurrentItem - > data ( 0 , Qt : : UserRole ) . toUInt ( ) ;
QString ( & Shortcuts ) [ LC_NUM_COMMANDS ] = mOptions - > KeyboardShortcuts . mShortcuts ;
if ( ShortcutIndex > = LC_ARRAY_COUNT ( Shortcuts ) )
return ;
QString NewShortcut = ui - > shortcutEdit - > text ( ) ;
if ( ! NewShortcut . isEmpty ( ) )
{
for ( uint ExistingIndex = 0 ; ExistingIndex < LC_ARRAY_COUNT ( Shortcuts ) ; ExistingIndex + + )
{
2021-01-01 00:15:10 +01:00
if ( NewShortcut = = Shortcuts [ ExistingIndex ] & & ExistingIndex ! = ShortcutIndex )
2020-12-10 23:58:22 +01:00
{
2021-01-01 00:15:10 +01:00
QString ActionText = qApp - > translate ( " Menu " , gCommands [ ExistingIndex ] . MenuName ) . remove ( ' & ' ) . remove ( QLatin1String ( " ... " ) ) ;
QString QuestionText = tr ( " The shortcut '%1' is already assigned to '%2'. Do you want to replace it? " ) . arg ( NewShortcut , ActionText ) ;
2020-12-10 23:58:22 +01:00
2021-01-01 00:15:10 +01:00
if ( QMessageBox : : question ( this , tr ( " Override Shortcut " ) , QuestionText , QMessageBox : : Yes | QMessageBox : : No ) ! = QMessageBox : : Yes )
2020-12-10 23:58:22 +01:00
return ;
mOptions - > KeyboardShortcuts . mShortcuts [ ExistingIndex ] . clear ( ) ;
std : : function < QTreeWidgetItem * ( QTreeWidgetItem * ) > FindItem = [ & FindItem , ExistingIndex ] ( QTreeWidgetItem * ParentItem ) - > QTreeWidgetItem *
{
for ( int ChildIdx = 0 ; ChildIdx < ParentItem - > childCount ( ) ; ChildIdx + + )
{
QTreeWidgetItem * ChildItem = ParentItem - > child ( ChildIdx ) ;
uint ChildIndex = ChildItem - > data ( 0 , Qt : : UserRole ) . toUInt ( ) ;
if ( ChildIndex = = ExistingIndex )
return ChildItem ;
QTreeWidgetItem * ExistingItem = FindItem ( ChildItem ) ;
if ( ExistingItem )
return ExistingItem ;
}
return nullptr ;
} ;
QTreeWidgetItem * ExistingItem = FindItem ( ui - > commandList - > invisibleRootItem ( ) ) ;
if ( ExistingItem )
{
ExistingItem - > setText ( 1 , QString ( ) ) ;
setShortcutModified ( ExistingItem , gCommands [ ShortcutIndex ] . DefaultShortcut [ 0 ] ! = 0 ) ;
}
}
}
}
2013-08-09 06:57:18 +02:00
2020-12-10 23:58:22 +01:00
mOptions - > KeyboardShortcuts . mShortcuts [ ShortcutIndex ] = NewShortcut ;
CurrentItem - > setText ( 1 , NewShortcut ) ;
2013-08-09 06:57:18 +02:00
2020-12-10 23:58:22 +01:00
setShortcutModified ( CurrentItem , mOptions - > KeyboardShortcuts . mShortcuts [ ShortcutIndex ] ! = gCommands [ ShortcutIndex ] . DefaultShortcut ) ;
2013-08-09 06:57:18 +02:00
2019-06-21 03:52:33 +02:00
mOptions - > KeyboardShortcutsModified = true ;
mOptions - > KeyboardShortcutsDefault = false ;
2013-08-09 06:57:18 +02:00
}
void lcQPreferencesDialog : : on_shortcutRemove_clicked ( )
{
ui - > shortcutEdit - > setText ( QString ( ) ) ;
on_shortcutAssign_clicked ( ) ;
}
void lcQPreferencesDialog : : on_shortcutsImport_clicked ( )
{
2015-02-02 07:00:42 +01:00
QString FileName = QFileDialog : : getOpenFileName ( this , tr ( " Import shortcuts " ) , " " , tr ( " Text Files (*.txt);;All Files (*.*) " ) ) ;
2013-08-09 06:57:18 +02:00
2015-02-02 07:00:42 +01:00
if ( FileName . isEmpty ( ) )
2013-08-09 06:57:18 +02:00
return ;
2015-02-02 07:00:42 +01:00
lcKeyboardShortcuts Shortcuts ;
2015-09-27 09:02:57 +02:00
if ( ! Shortcuts . Load ( FileName ) )
2013-08-09 06:57:18 +02:00
{
QMessageBox : : warning ( this , " LeoCAD " , tr ( " Error loading keyboard shortcuts file. " ) ) ;
return ;
}
2019-06-21 03:52:33 +02:00
mOptions - > KeyboardShortcuts = Shortcuts ;
2013-08-09 06:57:18 +02:00
2019-06-21 03:52:33 +02:00
mOptions - > KeyboardShortcutsModified = true ;
mOptions - > KeyboardShortcutsDefault = false ;
2013-08-09 06:57:18 +02:00
}
void lcQPreferencesDialog : : on_shortcutsExport_clicked ( )
{
2015-02-02 07:00:42 +01:00
QString FileName = QFileDialog : : getSaveFileName ( this , tr ( " Export shortcuts " ) , " " , tr ( " Text Files (*.txt);;All Files (*.*) " ) ) ;
2013-08-09 06:57:18 +02:00
2015-02-02 07:00:42 +01:00
if ( FileName . isEmpty ( ) )
2013-08-09 06:57:18 +02:00
return ;
2019-06-21 03:52:33 +02:00
if ( ! mOptions - > KeyboardShortcuts . Save ( FileName ) )
2013-08-09 06:57:18 +02:00
{
QMessageBox : : warning ( this , " LeoCAD " , tr ( " Error saving keyboard shortcuts file. " ) ) ;
return ;
}
}
void lcQPreferencesDialog : : on_shortcutsReset_clicked ( )
{
if ( QMessageBox : : question ( this , " LeoCAD " , tr ( " Are you sure you want to load the default keyboard shortcuts? " ) , QMessageBox : : Yes | QMessageBox : : No ) ! = QMessageBox : : Yes )
return ;
2019-06-21 03:52:33 +02:00
mOptions - > KeyboardShortcuts . Reset ( ) ;
2013-08-09 06:57:18 +02:00
updateCommandList ( ) ;
2019-06-21 03:52:33 +02:00
mOptions - > KeyboardShortcutsModified = true ;
mOptions - > KeyboardShortcutsDefault = true ;
2016-04-25 07:26:34 +02:00
}
void lcQPreferencesDialog : : UpdateMouseTree ( )
{
ui - > mouseTree - > clear ( ) ;
2020-12-05 00:38:49 +01:00
for ( int ToolIdx = 0 ; ToolIdx < static_cast < int > ( lcTool : : Count ) ; ToolIdx + + )
2016-04-25 07:26:34 +02:00
UpdateMouseTreeItem ( ToolIdx ) ;
}
void lcQPreferencesDialog : : UpdateMouseTreeItem ( int ItemIndex )
{
2019-03-12 02:29:19 +01:00
auto GetShortcutText = [ ] ( Qt : : MouseButton Button , Qt : : KeyboardModifiers Modifiers )
2016-04-25 07:26:34 +02:00
{
2017-07-11 23:25:06 +02:00
QString Shortcut = QKeySequence ( Modifiers ) . toString ( QKeySequence : : NativeText ) ;
switch ( Button )
{
case Qt : : LeftButton :
Shortcut + = tr ( " Left Button " ) ;
break ;
2016-04-25 07:26:34 +02:00
2017-07-11 23:25:06 +02:00
case Qt : : MiddleButton :
Shortcut + = tr ( " Middle Button " ) ;
break ;
2016-04-25 07:26:34 +02:00
2017-07-11 23:25:06 +02:00
case Qt : : RightButton :
Shortcut + = tr ( " Right Button " ) ;
break ;
2016-04-25 07:26:34 +02:00
2017-07-11 23:25:06 +02:00
default :
Shortcut . clear ( ) ;
}
return Shortcut ;
} ;
2019-06-21 03:52:33 +02:00
QString Shortcut1 = GetShortcutText ( mOptions - > MouseShortcuts . mShortcuts [ ItemIndex ] . Button1 , mOptions - > MouseShortcuts . mShortcuts [ ItemIndex ] . Modifiers1 ) ;
QString Shortcut2 = GetShortcutText ( mOptions - > MouseShortcuts . mShortcuts [ ItemIndex ] . Button2 , mOptions - > MouseShortcuts . mShortcuts [ ItemIndex ] . Modifiers2 ) ;
2016-04-25 07:26:34 +02:00
QTreeWidgetItem * Item = ui - > mouseTree - > topLevelItem ( ItemIndex ) ;
if ( Item )
2017-07-11 23:25:06 +02:00
{
Item - > setText ( 1 , Shortcut1 ) ;
Item - > setText ( 2 , Shortcut2 ) ;
}
2016-04-25 07:26:34 +02:00
else
2017-07-11 23:25:06 +02:00
new QTreeWidgetItem ( ui - > mouseTree , QStringList ( ) < < tr ( gToolNames [ ItemIndex ] ) < < Shortcut1 < < Shortcut2 ) ;
2016-04-25 07:26:34 +02:00
}
void lcQPreferencesDialog : : on_mouseAssign_clicked ( )
{
QTreeWidgetItem * Current = ui - > mouseTree - > currentItem ( ) ;
if ( ! Current )
return ;
int ButtonIndex = ui - > mouseButton - > currentIndex ( ) ;
Qt : : MouseButton Button = Qt : : NoButton ;
Qt : : KeyboardModifiers Modifiers = Qt : : NoModifier ;
if ( ButtonIndex )
{
switch ( ButtonIndex )
{
case 1 :
Button = Qt : : LeftButton ;
break ;
case 2 :
Button = Qt : : MiddleButton ;
break ;
case 3 :
Button = Qt : : RightButton ;
break ;
}
if ( ui - > mouseControl - > isChecked ( ) )
Modifiers | = Qt : : ControlModifier ;
if ( ui - > mouseShift - > isChecked ( ) )
Modifiers | = Qt : : ShiftModifier ;
if ( ui - > mouseAlt - > isChecked ( ) )
Modifiers | = Qt : : AltModifier ;
2020-12-05 00:38:49 +01:00
for ( int ToolIdx = 0 ; ToolIdx < static_cast < int > ( lcTool : : Count ) ; ToolIdx + + )
2016-04-30 22:07:32 +02:00
{
2017-07-11 23:25:06 +02:00
if ( ToolIdx = = ButtonIndex )
continue ;
2019-06-21 03:52:33 +02:00
if ( mOptions - > MouseShortcuts . mShortcuts [ ToolIdx ] . Button2 = = Button & & mOptions - > MouseShortcuts . mShortcuts [ ToolIdx ] . Modifiers2 = = Modifiers )
2017-07-11 23:25:06 +02:00
{
if ( QMessageBox : : question ( this , tr ( " Override Shortcut " ) , tr ( " This shortcut is already assigned to '%1', do you want to replace it? " ) . arg ( tr ( gToolNames [ ToolIdx ] ) ) , QMessageBox : : Yes | QMessageBox : : No ) = = QMessageBox : : No )
return ;
2019-06-21 03:52:33 +02:00
mOptions - > MouseShortcuts . mShortcuts [ ToolIdx ] . Button2 = Qt : : NoButton ;
mOptions - > MouseShortcuts . mShortcuts [ ToolIdx ] . Modifiers2 = Qt : : NoModifier ;
2017-07-11 23:25:06 +02:00
}
2019-06-21 03:52:33 +02:00
if ( mOptions - > MouseShortcuts . mShortcuts [ ToolIdx ] . Button1 = = Button & & mOptions - > MouseShortcuts . mShortcuts [ ToolIdx ] . Modifiers1 = = Modifiers )
2016-05-08 22:06:11 +02:00
{
2016-06-13 01:05:26 +02:00
if ( QMessageBox : : question ( this , tr ( " Override Shortcut " ) , tr ( " This shortcut is already assigned to '%1', do you want to replace it? " ) . arg ( tr ( gToolNames [ ToolIdx ] ) ) , QMessageBox : : Yes | QMessageBox : : No ) = = QMessageBox : : No )
2016-05-08 22:06:11 +02:00
return ;
2016-04-30 22:07:32 +02:00
2019-06-21 03:52:33 +02:00
mOptions - > MouseShortcuts . mShortcuts [ ToolIdx ] . Button1 = mOptions - > MouseShortcuts . mShortcuts [ ToolIdx ] . Button2 ;
mOptions - > MouseShortcuts . mShortcuts [ ToolIdx ] . Modifiers1 = mOptions - > MouseShortcuts . mShortcuts [ ToolIdx ] . Modifiers2 ;
mOptions - > MouseShortcuts . mShortcuts [ ToolIdx ] . Button2 = Qt : : NoButton ;
mOptions - > MouseShortcuts . mShortcuts [ ToolIdx ] . Modifiers2 = Qt : : NoModifier ;
2020-12-28 18:51:35 +01:00
UpdateMouseTreeItem ( ToolIdx ) ;
2016-05-08 22:06:11 +02:00
}
2016-04-30 22:07:32 +02:00
}
}
2016-04-25 07:26:34 +02:00
int ItemIndex = ui - > mouseTree - > indexOfTopLevelItem ( Current ) ;
2019-06-21 03:52:33 +02:00
mOptions - > MouseShortcuts . mShortcuts [ ItemIndex ] . Button2 = mOptions - > MouseShortcuts . mShortcuts [ ItemIndex ] . Button1 ;
mOptions - > MouseShortcuts . mShortcuts [ ItemIndex ] . Modifiers2 = mOptions - > MouseShortcuts . mShortcuts [ ItemIndex ] . Modifiers1 ;
mOptions - > MouseShortcuts . mShortcuts [ ItemIndex ] . Button1 = Button ;
mOptions - > MouseShortcuts . mShortcuts [ ItemIndex ] . Modifiers1 = Modifiers ;
2016-04-25 07:26:34 +02:00
2019-06-21 03:52:33 +02:00
mOptions - > MouseShortcutsModified = true ;
mOptions - > MouseShortcutsDefault = false ;
2016-04-25 07:26:34 +02:00
UpdateMouseTreeItem ( ItemIndex ) ;
}
void lcQPreferencesDialog : : on_mouseRemove_clicked ( )
{
QTreeWidgetItem * Current = ui - > mouseTree - > currentItem ( ) ;
if ( ! Current )
return ;
int ItemIndex = ui - > mouseTree - > indexOfTopLevelItem ( Current ) ;
2019-06-21 03:52:33 +02:00
mOptions - > MouseShortcuts . mShortcuts [ ItemIndex ] . Button1 = mOptions - > MouseShortcuts . mShortcuts [ ItemIndex ] . Button2 ;
mOptions - > MouseShortcuts . mShortcuts [ ItemIndex ] . Modifiers1 = mOptions - > MouseShortcuts . mShortcuts [ ItemIndex ] . Modifiers2 ;
mOptions - > MouseShortcuts . mShortcuts [ ItemIndex ] . Button2 = Qt : : NoButton ;
mOptions - > MouseShortcuts . mShortcuts [ ItemIndex ] . Modifiers2 = Qt : : NoModifier ;
2016-04-25 07:26:34 +02:00
2019-06-21 03:52:33 +02:00
mOptions - > MouseShortcutsModified = true ;
mOptions - > MouseShortcutsDefault = false ;
2016-04-25 07:26:34 +02:00
UpdateMouseTreeItem ( ItemIndex ) ;
2017-07-11 23:25:06 +02:00
MouseTreeItemChanged ( Current ) ;
2016-04-25 07:26:34 +02:00
}
2020-08-23 03:47:03 +02:00
void lcQPreferencesDialog : : on_MouseImportButton_clicked ( )
{
QString FileName = QFileDialog : : getOpenFileName ( this , tr ( " Import Shortcuts " ) , " " , tr ( " Text Files (*.txt);;All Files (*.*) " ) ) ;
if ( FileName . isEmpty ( ) )
return ;
lcMouseShortcuts Shortcuts ;
if ( ! Shortcuts . Load ( FileName ) )
{
QMessageBox : : warning ( this , " LeoCAD " , tr ( " Error loading mouse shortcuts file. " ) ) ;
return ;
}
mOptions - > MouseShortcuts = Shortcuts ;
UpdateMouseTree ( ) ;
mOptions - > MouseShortcutsModified = true ;
mOptions - > MouseShortcutsDefault = false ;
}
void lcQPreferencesDialog : : on_MouseExportButton_clicked ( )
{
QString FileName = QFileDialog : : getSaveFileName ( this , tr ( " Export Shortcuts " ) , " " , tr ( " Text Files (*.txt);;All Files (*.*) " ) ) ;
if ( FileName . isEmpty ( ) )
return ;
if ( ! mOptions - > MouseShortcuts . Save ( FileName ) )
QMessageBox : : warning ( this , " LeoCAD " , tr ( " Error saving mouse shortcuts file. " ) ) ;
}
2016-04-25 07:26:34 +02:00
void lcQPreferencesDialog : : on_mouseReset_clicked ( )
{
if ( QMessageBox : : question ( this , " LeoCAD " , tr ( " Are you sure you want to load the default mouse shortcuts? " ) , QMessageBox : : Yes | QMessageBox : : No ) ! = QMessageBox : : Yes )
return ;
2019-06-21 03:52:33 +02:00
mOptions - > MouseShortcuts . Reset ( ) ;
2016-04-25 07:26:34 +02:00
UpdateMouseTree ( ) ;
2019-06-21 03:52:33 +02:00
mOptions - > MouseShortcutsModified = true ;
mOptions - > MouseShortcutsDefault = true ;
2016-04-25 07:26:34 +02:00
}
void lcQPreferencesDialog : : MouseTreeItemChanged ( QTreeWidgetItem * Current )
{
if ( ! Current )
{
ui - > MouseShortcutGroup - > setEnabled ( false ) ;
return ;
}
ui - > MouseShortcutGroup - > setEnabled ( true ) ;
int ToolIndex = ui - > mouseTree - > indexOfTopLevelItem ( Current ) ;
2019-06-21 03:52:33 +02:00
Qt : : MouseButton Button = mOptions - > MouseShortcuts . mShortcuts [ ToolIndex ] . Button1 ;
2016-04-25 07:26:34 +02:00
switch ( Button )
{
case Qt : : LeftButton :
ui - > mouseButton - > setCurrentIndex ( 1 ) ;
break ;
case Qt : : MiddleButton :
ui - > mouseButton - > setCurrentIndex ( 2 ) ;
break ;
case Qt : : RightButton :
ui - > mouseButton - > setCurrentIndex ( 3 ) ;
break ;
default :
ui - > mouseButton - > setCurrentIndex ( 0 ) ;
break ;
}
2019-06-21 03:52:33 +02:00
Qt : : KeyboardModifiers Modifiers = mOptions - > MouseShortcuts . mShortcuts [ ToolIndex ] . Modifiers1 ;
2016-04-25 07:26:34 +02:00
ui - > mouseControl - > setChecked ( ( Modifiers & Qt : : ControlModifier ) ! = 0 ) ;
ui - > mouseShift - > setChecked ( ( Modifiers & Qt : : ShiftModifier ) ! = 0 ) ;
ui - > mouseAlt - > setChecked ( ( Modifiers & Qt : : AltModifier ) ! = 0 ) ;
2013-08-09 06:57:18 +02:00
}