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"
# include "lc_qcategorydialog.h"
2013-08-16 03:25:51 +02:00
# include "lc_basewindow.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"
lcQPreferencesDialog : : lcQPreferencesDialog ( QWidget * parent , void * data ) :
QDialog ( parent ) ,
ui ( new Ui : : lcQPreferencesDialog )
{
ui - > setupUi ( this ) ;
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
2016-09-22 17:04:51 +02:00
ui - > lineWidth - > setValidator ( new QDoubleValidator ( ui - > lineWidth ) ) ;
2019-01-20 20:59:18 +01:00
connect ( ui - > gridStudColor , SIGNAL ( clicked ( ) ) , this , SLOT ( ColorButtonClicked ( ) ) ) ;
connect ( ui - > gridLineColor , SIGNAL ( clicked ( ) ) , this , SLOT ( ColorButtonClicked ( ) ) ) ;
connect ( ui - > ViewSphereColorButton , SIGNAL ( clicked ( ) ) , this , SLOT ( ColorButtonClicked ( ) ) ) ;
connect ( ui - > ViewSphereTextColorButton , SIGNAL ( clicked ( ) ) , this , SLOT ( ColorButtonClicked ( ) ) ) ;
connect ( ui - > ViewSphereHighlightColorButton , SIGNAL ( clicked ( ) ) , this , SLOT ( 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 * ) ) ) ;
2013-08-09 06:57:18 +02:00
options = ( lcPreferencesDialogOptions * ) data ;
ui - > authorName - > setText ( options - > DefaultAuthor ) ;
ui - > partsLibrary - > setText ( options - > LibraryPath ) ;
2013-08-17 03:17:23 +02:00
ui - > povrayExecutable - > setText ( options - > POVRayPath ) ;
ui - > lgeoPath - > setText ( options - > LGEOPath ) ;
2014-02-10 01:13:41 +01:00
ui - > mouseSensitivity - > setValue ( options - > Preferences . mMouseSensitivity ) ;
2013-08-20 03:23:41 +02:00
ui - > checkForUpdates - > setCurrentIndex ( options - > CheckForUpdates ) ;
2019-03-07 17:26:50 +01:00
ui - > fixedDirectionKeys - > setChecked ( options - > Preferences . mFixedAxes ) ;
2019-03-10 01:38:54 +01:00
ui - > autoLoadMostRecent - > setChecked ( options - > Preferences . mAutoLoadMostRecent ) ;
2013-08-09 06:57:18 +02:00
ui - > antiAliasing - > setChecked ( options - > AASamples ! = 1 ) ;
if ( options - > AASamples = = 8 )
ui - > antiAliasingSamples - > setCurrentIndex ( 2 ) ;
else if ( options - > AASamples = = 4 )
ui - > antiAliasingSamples - > setCurrentIndex ( 1 ) ;
else
ui - > antiAliasingSamples - > setCurrentIndex ( 0 ) ;
2014-02-10 01:13:41 +01:00
ui - > edgeLines - > setChecked ( options - > Preferences . mDrawEdgeLines ) ;
2016-06-14 01:57:31 +02:00
ui - > lineWidth - > setText ( lcFormatValueLocalized ( options - > Preferences . mLineWidth ) ) ;
2014-02-10 01:13:41 +01:00
ui - > gridStuds - > setChecked ( options - > Preferences . mDrawGridStuds ) ;
ui - > gridLines - > setChecked ( options - > Preferences . mDrawGridLines ) ;
ui - > gridLineSpacing - > setText ( QString : : number ( options - > Preferences . mGridLineSpacing ) ) ;
ui - > axisIcon - > setChecked ( options - > Preferences . mDrawAxes ) ;
2019-01-20 20:59:18 +01:00
2018-10-29 01:59:01 +01:00
ui - > ViewSphereLocationCombo - > setCurrentIndex ( ( int ) options - > Preferences . mViewSphereLocation ) ;
2019-01-20 20:59:18 +01:00
switch ( options - > 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 ;
}
2017-08-25 21:57:14 +02:00
if ( ! gSupportsShaderObjects )
ui - > ShadingMode - > removeItem ( LC_SHADING_DEFAULT_LIGHTS ) ;
ui - > ShadingMode - > setCurrentIndex ( options - > Preferences . mShadingMode ) ;
2013-08-09 06:57:18 +02:00
2013-08-31 23:58:47 +02:00
QPixmap pix ( 12 , 12 ) ;
2014-02-10 01:13:41 +01:00
pix . fill ( QColor ( LC_RGBA_RED ( options - > Preferences . mGridStudColor ) , LC_RGBA_GREEN ( options - > Preferences . mGridStudColor ) , LC_RGBA_BLUE ( options - > Preferences . mGridStudColor ) ) ) ;
2013-08-31 23:58:47 +02:00
ui - > gridStudColor - > setIcon ( pix ) ;
2014-02-10 01:13:41 +01:00
pix . fill ( QColor ( LC_RGBA_RED ( options - > Preferences . mGridLineColor ) , LC_RGBA_GREEN ( options - > Preferences . mGridLineColor ) , LC_RGBA_BLUE ( options - > Preferences . mGridLineColor ) ) ) ;
2013-08-31 23:58:47 +02:00
ui - > gridLineColor - > setIcon ( pix ) ;
2019-01-20 20:59:18 +01:00
pix . fill ( QColor ( LC_RGBA_RED ( options - > Preferences . mViewSphereColor ) , LC_RGBA_GREEN ( options - > Preferences . mViewSphereColor ) , LC_RGBA_BLUE ( options - > Preferences . mViewSphereColor ) ) ) ;
ui - > ViewSphereColorButton - > setIcon ( pix ) ;
pix . fill ( QColor ( LC_RGBA_RED ( options - > Preferences . mViewSphereTextColor ) , LC_RGBA_GREEN ( options - > Preferences . mViewSphereTextColor ) , LC_RGBA_BLUE ( options - > Preferences . mViewSphereTextColor ) ) ) ;
ui - > ViewSphereTextColorButton - > setIcon ( pix ) ;
pix . fill ( QColor ( LC_RGBA_RED ( options - > Preferences . mViewSphereHighlightColor ) , LC_RGBA_GREEN ( options - > Preferences . mViewSphereHighlightColor ) , LC_RGBA_BLUE ( options - > Preferences . mViewSphereHighlightColor ) ) ) ;
ui - > ViewSphereHighlightColorButton - > setIcon ( pix ) ;
2013-08-09 06:57:18 +02:00
on_antiAliasing_toggled ( ) ;
on_edgeLines_toggled ( ) ;
2013-08-31 23:58:47 +02:00
on_gridStuds_toggled ( ) ;
on_gridLines_toggled ( ) ;
2019-01-20 20:59:18 +01:00
on_ViewSphereSizeCombo_currentIndexChanged ( ( int ) options - > Preferences . mViewSphereLocation ) ;
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
# if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
ui - > mouseTree - > header ( ) - > setSectionResizeMode ( 0 , QHeaderView : : Stretch ) ;
ui - > mouseTree - > header ( ) - > setSectionResizeMode ( 1 , QHeaderView : : ResizeToContents ) ;
ui - > mouseTree - > header ( ) - > setSectionResizeMode ( 2 , QHeaderView : : ResizeToContents ) ;
# else
ui - > mouseTree - > header ( ) - > setResizeMode ( 0 , QHeaderView : : Stretch ) ;
ui - > mouseTree - > header ( ) - > setResizeMode ( 1 , QHeaderView : : ResizeToContents ) ;
ui - > mouseTree - > header ( ) - > setResizeMode ( 2 , QHeaderView : : ResizeToContents ) ;
# endif
2017-04-14 02:26:40 +02:00
MouseTreeItemChanged ( nullptr ) ;
2013-08-09 06:57:18 +02:00
}
lcQPreferencesDialog : : ~ lcQPreferencesDialog ( )
{
delete ui ;
}
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 ;
}
2015-01-31 22:44:57 +01:00
options - > DefaultAuthor = ui - > authorName - > text ( ) ;
options - > LibraryPath = ui - > partsLibrary - > text ( ) ;
options - > POVRayPath = ui - > povrayExecutable - > text ( ) ;
options - > LGEOPath = ui - > lgeoPath - > text ( ) ;
2014-02-10 01:13:41 +01:00
options - > Preferences . mMouseSensitivity = ui - > mouseSensitivity - > value ( ) ;
2013-08-20 03:23:41 +02:00
options - > CheckForUpdates = ui - > checkForUpdates - > currentIndex ( ) ;
2014-10-05 07:21:51 +02:00
options - > Preferences . mFixedAxes = ui - > fixedDirectionKeys - > isChecked ( ) ;
2019-03-10 01:38:54 +01:00
options - > Preferences . mAutoLoadMostRecent = ui - > autoLoadMostRecent - > isChecked ( ) ;
2013-08-09 06:57:18 +02:00
if ( ! ui - > antiAliasing - > isChecked ( ) )
options - > AASamples = 1 ;
else if ( ui - > antiAliasingSamples - > currentIndex ( ) = = 2 )
options - > AASamples = 8 ;
else if ( ui - > antiAliasingSamples - > currentIndex ( ) = = 1 )
options - > AASamples = 4 ;
else
options - > AASamples = 2 ;
2014-02-10 01:13:41 +01:00
options - > Preferences . mDrawEdgeLines = ui - > edgeLines - > isChecked ( ) ;
2016-06-14 01:57:31 +02:00
options - > Preferences . mLineWidth = lcParseValueLocalized ( ui - > lineWidth - > text ( ) ) ;
2013-08-09 06:57:18 +02:00
2014-02-10 01:13:41 +01:00
options - > Preferences . mDrawGridStuds = ui - > gridStuds - > isChecked ( ) ;
options - > Preferences . mDrawGridLines = ui - > gridLines - > isChecked ( ) ;
options - > Preferences . mGridLineSpacing = gridLineSpacing ;
2013-08-09 06:57:18 +02:00
2014-02-10 01:13:41 +01:00
options - > Preferences . mDrawAxes = ui - > axisIcon - > isChecked ( ) ;
2018-10-29 01:59:01 +01:00
options - > Preferences . mViewSphereLocation = ( lcViewSphereLocation ) ui - > ViewSphereLocationCombo - > currentIndex ( ) ;
2019-01-20 20:59:18 +01:00
switch ( ui - > ViewSphereSizeCombo - > currentIndex ( ) )
{
case 3 :
options - > Preferences . mViewSphereSize = 200 ;
break ;
case 2 :
options - > Preferences . mViewSphereSize = 100 ;
break ;
case 1 :
options - > Preferences . mViewSphereSize = 50 ;
break ;
default :
options - > Preferences . mViewSphereSize = 0 ;
break ;
}
2017-08-25 21:57:14 +02:00
options - > Preferences . mShadingMode = ( lcShadingMode ) ui - > ShadingMode - > currentIndex ( ) ;
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 ) ) ;
}
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
QString result = QFileDialog : : getOpenFileName ( this , tr ( " Open POV-Ray Executable " ) , ui - > povrayExecutable - > text ( ) , filter ) ;
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
}
2019-01-20 20:59:18 +01:00
void lcQPreferencesDialog : : ColorButtonClicked ( )
2013-08-31 23:58:47 +02:00
{
QObject * button = sender ( ) ;
QString title ;
2017-12-02 21:22:04 +01:00
quint32 * color = nullptr ;
2013-08-31 23:58:47 +02:00
QColorDialog : : ColorDialogOptions dialogOptions ;
if ( button = = ui - > gridStudColor )
{
2014-02-10 01:13:41 +01:00
color = & options - > Preferences . mGridStudColor ;
2013-08-31 23:58:47 +02:00
title = tr ( " Select Grid Stud Color " ) ;
dialogOptions = QColorDialog : : ShowAlphaChannel ;
}
else if ( button = = ui - > gridLineColor )
{
2014-02-10 01:13:41 +01:00
color = & options - > Preferences . mGridLineColor ;
2013-08-31 23:58:47 +02:00
title = tr ( " Select Grid Line Color " ) ;
dialogOptions = 0 ;
}
2019-01-20 20:59:18 +01:00
else if ( button = = ui - > ViewSphereColorButton )
{
color = & options - > Preferences . mViewSphereColor ;
title = tr ( " Select View Sphere Color " ) ;
dialogOptions = 0 ;
}
else if ( button = = ui - > ViewSphereTextColorButton )
{
color = & options - > Preferences . mViewSphereTextColor ;
title = tr ( " Select View Sphere Text Color " ) ;
dialogOptions = 0 ;
}
else if ( button = = ui - > ViewSphereHighlightColorButton )
{
color = & options - > Preferences . mViewSphereHighlightColor ;
title = tr ( " Select View Sphere Highlight Color " ) ;
dialogOptions = 0 ;
}
2017-02-13 03:05:20 +01:00
else
return ;
2013-08-31 23:58:47 +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 ) ;
if ( newColor = = oldColor | | ! newColor . isValid ( ) )
return ;
* color = LC_RGBA ( newColor . red ( ) , newColor . green ( ) , newColor . blue ( ) , newColor . alpha ( ) ) ;
QPixmap pix ( 12 , 12 ) ;
pix . fill ( newColor ) ;
( ( QToolButton * ) button ) - > setIcon ( pix ) ;
}
2013-08-09 06:57:18 +02:00
void lcQPreferencesDialog : : on_antiAliasing_toggled ( )
{
ui - > antiAliasingSamples - > setEnabled ( ui - > antiAliasing - > isChecked ( ) ) ;
}
void lcQPreferencesDialog : : on_edgeLines_toggled ( )
{
ui - > lineWidth - > setEnabled ( ui - > edgeLines - > 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 ( ) ) ;
}
void lcQPreferencesDialog : : on_ViewSphereSizeCombo_currentIndexChanged ( int Index )
{
bool Enabled = Index ! = 0 ;
ui - > ViewSphereLocationCombo - > setEnabled ( Enabled ) ;
ui - > ViewSphereColorButton - > setEnabled ( Enabled ) ;
ui - > ViewSphereTextColorButton - > setEnabled ( Enabled ) ;
ui - > ViewSphereHighlightColorButton - > setEnabled ( Enabled ) ;
2013-08-09 06:57:18 +02:00
}
void lcQPreferencesDialog : : updateCategories ( )
{
QTreeWidgetItem * categoryItem ;
QTreeWidget * tree = ui - > categoriesTree ;
tree - > clear ( ) ;
for ( int categoryIndex = 0 ; categoryIndex < options - > Categories . GetSize ( ) ; categoryIndex + + )
{
2017-02-08 18:41:48 +01:00
categoryItem = new QTreeWidgetItem ( tree , QStringList ( options - > Categories [ categoryIndex ] . Name ) ) ;
2013-08-09 06:57:18 +02:00
categoryItem - > setData ( 0 , CategoryRole , QVariant ( categoryIndex ) ) ;
}
categoryItem = new QTreeWidgetItem ( tree , QStringList ( tr ( " Unassigned " ) ) ) ;
categoryItem - > setData ( 0 , CategoryRole , QVariant ( - 1 ) ) ;
}
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
2017-07-24 04:35:18 +02:00
Library - > GetCategoryEntries ( options - > 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
for ( categoryIndex = 0 ; categoryIndex < options - > Categories . GetSize ( ) ; categoryIndex + + )
{
2017-07-24 04:35:18 +02:00
if ( Library - > PieceInCategory ( Info , options - > Categories [ categoryIndex ] . Keywords . constData ( ) ) )
2013-08-09 06:57:18 +02:00
break ;
}
if ( categoryIndex = = options - > Categories . GetSize ( ) )
{
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 ;
lcQCategoryDialog dialog ( this , & category ) ;
if ( dialog . exec ( ) ! = QDialog : : Accepted )
return ;
options - > CategoriesModified = true ;
options - > CategoriesDefault = false ;
options - > Categories . Add ( category ) ;
updateCategories ( ) ;
ui - > categoriesTree - > setCurrentItem ( ui - > categoriesTree - > topLevelItem ( options - > Categories . GetSize ( ) - 1 ) ) ;
}
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 ;
lcQCategoryDialog dialog ( this , & options - > Categories [ categoryIndex ] ) ;
if ( dialog . exec ( ) ! = QDialog : : Accepted )
return ;
options - > CategoriesModified = true ;
options - > CategoriesDefault = false ;
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 ;
2017-02-08 18:41:48 +01:00
QString question = tr ( " Are you sure you want to delete the category '%1'? " ) . arg ( options - > Categories [ categoryIndex ] . Name ) ;
2013-08-09 06:57:18 +02:00
if ( QMessageBox : : question ( this , " LeoCAD " , question , QMessageBox : : Yes | QMessageBox : : No ) ! = QMessageBox : : Yes )
return ;
options - > CategoriesModified = true ;
options - > CategoriesDefault = false ;
options - > Categories . RemoveIndex ( categoryIndex ) ;
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 ;
2015-02-02 07:00:42 +01:00
lcArray < lcLibraryCategory > Categories ;
if ( ! lcLoadCategories ( FileName , Categories ) )
2013-08-09 06:57:18 +02:00
{
QMessageBox : : warning ( this , " LeoCAD " , tr ( " Error loading categories file. " ) ) ;
return ;
}
2015-02-02 07:00:42 +01:00
options - > Categories = Categories ;
2013-08-09 06:57:18 +02:00
options - > CategoriesModified = true ;
options - > CategoriesDefault = false ;
}
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 ;
2015-02-02 07:00:42 +01:00
if ( ! lcSaveCategories ( FileName , options - > 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 ;
lcResetCategories ( options - > Categories ) ;
options - > CategoriesModified = true ;
options - > CategoriesDefault = true ;
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 ;
for ( int actionIdx = 0 ; actionIdx < LC_NUM_COMMANDS ; actionIdx + + )
{
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 ;
2015-09-27 09:02:57 +02:00
QKeySequence sequence ( options - > KeyboardShortcuts . mShortcuts [ actionIdx ] ) ;
2013-08-09 06:57:18 +02:00
item - > setText ( 0 , subId ) ;
item - > setText ( 1 , sequence . toString ( QKeySequence : : NativeText ) ) ;
item - > setData ( 0 , Qt : : UserRole , qVariantFromValue ( actionIdx ) ) ;
2015-09-27 09:02:57 +02:00
if ( options - > 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 ) ) ;
2015-09-27 09:02:57 +02:00
QKeySequence key ( options - > 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 )
{
ForceVisible | = ParentItem - > text ( 0 ) . contains ( Text , Qt : : CaseInsensitive ) | ParentItem - > text ( 1 ) . contains ( Text , Qt : : CaseInsensitive ) ;
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 ( )
{
QTreeWidgetItem * current = ui - > commandList - > currentItem ( ) ;
if ( ! current | | ! current - > data ( 0 , Qt : : UserRole ) . isValid ( ) )
return ;
int shortcutIndex = qvariant_cast < int > ( current - > data ( 0 , Qt : : UserRole ) ) ;
2015-09-27 09:02:57 +02:00
options - > KeyboardShortcuts . mShortcuts [ shortcutIndex ] = ui - > shortcutEdit - > text ( ) ;
2013-08-09 06:57:18 +02:00
current - > setText ( 1 , ui - > shortcutEdit - > text ( ) ) ;
2015-09-27 09:02:57 +02:00
setShortcutModified ( current , options - > KeyboardShortcuts . mShortcuts [ shortcutIndex ] ! = gCommands [ shortcutIndex ] . DefaultShortcut ) ;
2013-08-09 06:57:18 +02:00
2016-04-25 07:26:34 +02:00
options - > KeyboardShortcutsModified = true ;
options - > 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 ;
}
2015-02-02 07:00:42 +01:00
options - > KeyboardShortcuts = Shortcuts ;
2013-08-09 06:57:18 +02:00
2016-04-25 07:26:34 +02:00
options - > KeyboardShortcutsModified = true ;
options - > 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 ;
2015-09-27 09:02:57 +02:00
if ( ! options - > 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 ;
2015-09-27 09:02:57 +02:00
options - > KeyboardShortcuts . Reset ( ) ;
2013-08-09 06:57:18 +02:00
updateCommandList ( ) ;
2016-04-25 07:26:34 +02:00
options - > KeyboardShortcutsModified = true ;
options - > KeyboardShortcutsDefault = true ;
}
void lcQPreferencesDialog : : UpdateMouseTree ( )
{
ui - > mouseTree - > clear ( ) ;
for ( int ToolIdx = 0 ; ToolIdx < LC_NUM_TOOLS ; ToolIdx + + )
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
2016-09-22 17:04:51 +02:00
# if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 0))
2017-07-11 23:25:06 +02:00
case Qt : : MiddleButton :
Shortcut + = tr ( " Middle Button " ) ;
break ;
2016-09-22 17:04:51 +02:00
# endif
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 ;
} ;
QString Shortcut1 = GetShortcutText ( options - > MouseShortcuts . mShortcuts [ ItemIndex ] . Button1 , options - > MouseShortcuts . mShortcuts [ ItemIndex ] . Modifiers1 ) ;
QString Shortcut2 = GetShortcutText ( options - > MouseShortcuts . mShortcuts [ ItemIndex ] . Button2 , options - > 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 ;
2016-09-22 17:04:51 +02:00
# if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 0))
2016-04-25 07:26:34 +02:00
case 2 :
Button = Qt : : MiddleButton ;
break ;
2016-09-22 17:04:51 +02:00
# endif
2016-04-25 07:26:34 +02:00
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 ;
2016-05-08 22:06:11 +02:00
for ( int ToolIdx = 0 ; ToolIdx < LC_NUM_TOOLS ; ToolIdx + + )
2016-04-30 22:07:32 +02:00
{
2017-07-11 23:25:06 +02:00
if ( ToolIdx = = ButtonIndex )
continue ;
if ( options - > MouseShortcuts . mShortcuts [ ToolIdx ] . Button2 = = Button & & options - > MouseShortcuts . mShortcuts [ ToolIdx ] . Modifiers2 = = Modifiers )
{
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 ;
options - > MouseShortcuts . mShortcuts [ ToolIdx ] . Button2 = Qt : : NoButton ;
options - > MouseShortcuts . mShortcuts [ ToolIdx ] . Modifiers2 = Qt : : NoModifier ;
}
if ( options - > MouseShortcuts . mShortcuts [ ToolIdx ] . Button1 = = Button & & options - > 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
2017-07-11 23:25:06 +02:00
options - > MouseShortcuts . mShortcuts [ ToolIdx ] . Button1 = options - > MouseShortcuts . mShortcuts [ ToolIdx ] . Button2 ;
options - > MouseShortcuts . mShortcuts [ ToolIdx ] . Modifiers1 = options - > MouseShortcuts . mShortcuts [ ToolIdx ] . Modifiers2 ;
options - > MouseShortcuts . mShortcuts [ ToolIdx ] . Button2 = Qt : : NoButton ;
options - > MouseShortcuts . mShortcuts [ ToolIdx ] . Modifiers2 = Qt : : NoModifier ;
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 ) ;
2017-07-11 23:25:06 +02:00
options - > MouseShortcuts . mShortcuts [ ItemIndex ] . Button2 = options - > MouseShortcuts . mShortcuts [ ItemIndex ] . Button1 ;
options - > MouseShortcuts . mShortcuts [ ItemIndex ] . Modifiers2 = options - > MouseShortcuts . mShortcuts [ ItemIndex ] . Modifiers1 ;
options - > MouseShortcuts . mShortcuts [ ItemIndex ] . Button1 = Button ;
options - > MouseShortcuts . mShortcuts [ ItemIndex ] . Modifiers1 = Modifiers ;
2016-04-25 07:26:34 +02:00
options - > MouseShortcutsModified = true ;
options - > MouseShortcutsDefault = false ;
UpdateMouseTreeItem ( ItemIndex ) ;
}
void lcQPreferencesDialog : : on_mouseRemove_clicked ( )
{
QTreeWidgetItem * Current = ui - > mouseTree - > currentItem ( ) ;
if ( ! Current )
return ;
int ItemIndex = ui - > mouseTree - > indexOfTopLevelItem ( Current ) ;
2017-07-11 23:25:06 +02:00
options - > MouseShortcuts . mShortcuts [ ItemIndex ] . Button1 = options - > MouseShortcuts . mShortcuts [ ItemIndex ] . Button2 ;
options - > MouseShortcuts . mShortcuts [ ItemIndex ] . Modifiers1 = options - > MouseShortcuts . mShortcuts [ ItemIndex ] . Modifiers2 ;
options - > MouseShortcuts . mShortcuts [ ItemIndex ] . Button2 = Qt : : NoButton ;
options - > MouseShortcuts . mShortcuts [ ItemIndex ] . Modifiers2 = Qt : : NoModifier ;
2016-04-25 07:26:34 +02:00
options - > MouseShortcutsModified = true ;
options - > MouseShortcutsDefault = false ;
UpdateMouseTreeItem ( ItemIndex ) ;
2017-07-11 23:25:06 +02:00
MouseTreeItemChanged ( Current ) ;
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 ;
options - > MouseShortcuts . Reset ( ) ;
UpdateMouseTree ( ) ;
options - > MouseShortcutsModified = true ;
options - > MouseShortcutsDefault = true ;
}
void lcQPreferencesDialog : : MouseTreeItemChanged ( QTreeWidgetItem * Current )
{
if ( ! Current )
{
ui - > MouseShortcutGroup - > setEnabled ( false ) ;
return ;
}
ui - > MouseShortcutGroup - > setEnabled ( true ) ;
int ToolIndex = ui - > mouseTree - > indexOfTopLevelItem ( Current ) ;
2017-07-11 23:25:06 +02:00
Qt : : MouseButton Button = options - > MouseShortcuts . mShortcuts [ ToolIndex ] . Button1 ;
2016-04-25 07:26:34 +02:00
switch ( Button )
{
case Qt : : LeftButton :
ui - > mouseButton - > setCurrentIndex ( 1 ) ;
break ;
2016-09-22 17:04:51 +02:00
# if (QT_VERSION >= QT_VERSION_CHECK(4, 7, 0))
2016-04-25 07:26:34 +02:00
case Qt : : MiddleButton :
ui - > mouseButton - > setCurrentIndex ( 2 ) ;
break ;
2016-09-22 17:04:51 +02:00
# endif
2016-04-25 07:26:34 +02:00
case Qt : : RightButton :
ui - > mouseButton - > setCurrentIndex ( 3 ) ;
break ;
default :
ui - > mouseButton - > setCurrentIndex ( 0 ) ;
break ;
}
2017-07-11 23:25:06 +02:00
Qt : : KeyboardModifiers Modifiers = options - > 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
}