leocad/qt/lc_qpreferencesdialog.cpp

1292 lines
43 KiB
C++
Raw Normal View History

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"
#include "lc_library.h"
#include "lc_application.h"
#include "lc_qutils.h"
#include "lc_glextensions.h"
2013-08-09 06:57:18 +02:00
#include "pieceinf.h"
2019-11-28 22:52:06 +01:00
static const char* gLanguageLocales[] =
{
"", "cs_CZ", "de_DE", "en_US", "fr_FR", "pt_PT", "es_ES"
2019-11-28 22:52:06 +01:00
};
lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogOptions* Options)
: QDialog(Parent), mOptions(Options), ui(new Ui::lcQPreferencesDialog)
2013-08-09 06:57:18 +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
connect(ui->BackgroundSolidColorButton, SIGNAL(clicked()), this, SLOT(ColorButtonClicked()));
connect(ui->BackgroundGradient1ColorButton, SIGNAL(clicked()), this, SLOT(ColorButtonClicked()));
connect(ui->BackgroundGradient2ColorButton, SIGNAL(clicked()), this, SLOT(ColorButtonClicked()));
connect(ui->AxesColorButton, SIGNAL(clicked()), this, SLOT(ColorButtonClicked()));
2020-12-30 22:44:08 +01:00
connect(ui->TextColorButton, SIGNAL(clicked()), this, SLOT(ColorButtonClicked()));
connect(ui->OverlayColorButton, SIGNAL(clicked()), this, SLOT(ColorButtonClicked()));
2020-04-25 21:16:37 +02:00
connect(ui->FadeStepsColor, SIGNAL(clicked()), this, SLOT(ColorButtonClicked()));
connect(ui->HighlightNewPartsColor, SIGNAL(clicked()), this, SLOT(ColorButtonClicked()));
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
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;
}
}
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);
ui->antiAliasing->setChecked(mOptions->AASamples != 1);
if (mOptions->AASamples == 8)
2013-08-09 06:57:18 +02:00
ui->antiAliasingSamples->setCurrentIndex(2);
else if (mOptions->AASamples == 4)
2013-08-09 06:57:18 +02:00
ui->antiAliasingSamples->setCurrentIndex(1);
else
ui->antiAliasingSamples->setCurrentIndex(0);
ui->edgeLines->setChecked(mOptions->Preferences.mDrawEdgeLines);
2020-06-06 20:16:01 +02:00
2020-12-27 22:05:55 +01:00
#ifdef LC_USE_QOPENGLWIDGET
if (QSurfaceFormat::defaultFormat().samples() > 1)
{
glGetFloatv(GL_SMOOTH_LINE_WIDTH_RANGE, mLineWidthRange);
glGetFloatv(GL_SMOOTH_LINE_WIDTH_GRANULARITY, &mLineWidthGranularity);
}
else
#elif !defined(LC_OPENGLES)
2020-06-06 20:16:01 +02:00
if (QGLFormat::defaultFormat().sampleBuffers() && QGLFormat::defaultFormat().samples() > 1)
{
glGetFloatv(GL_SMOOTH_LINE_WIDTH_RANGE, mLineWidthRange);
glGetFloatv(GL_SMOOTH_LINE_WIDTH_GRANULARITY, &mLineWidthGranularity);
}
else
2020-11-07 04:01:21 +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);
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);
ui->HighlightNewParts->setChecked(mOptions->Preferences.mHighlightNewParts);
ui->gridStuds->setChecked(mOptions->Preferences.mDrawGridStuds);
ui->gridLines->setChecked(mOptions->Preferences.mDrawGridLines);
ui->gridLineSpacing->setText(QString::number(mOptions->Preferences.mGridLineSpacing));
ui->AxisIconCheckBox->setChecked(mOptions->Preferences.mDrawAxes);
2019-01-20 20:59:18 +01:00
if (!mOptions->Preferences.mBackgroundGradient)
ui->BackgroundSolidRadio->setChecked(true);
else
ui->BackgroundGradientRadio->setChecked(true);
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
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);
if (!lcGetPiecesLibrary()->SupportsStudLogo())
{
ui->studLogo->setEnabled(false);
ui->studLogoCombo->setEnabled(false);
}
ui->studLogo->setChecked(mOptions->StudLogo);
if (ui->studLogo->isChecked())
ui->studLogoCombo->setCurrentIndex(mOptions->StudLogo - 1);
else
ui->studLogoCombo->setCurrentIndex(mOptions->StudLogo);
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
QPixmap pix(12, 12);
pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mBackgroundSolidColor), LC_RGBA_GREEN(mOptions->Preferences.mBackgroundSolidColor), LC_RGBA_BLUE(mOptions->Preferences.mBackgroundSolidColor)));
ui->BackgroundSolidColorButton->setIcon(pix);
pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mBackgroundGradientColorTop), LC_RGBA_GREEN(mOptions->Preferences.mBackgroundGradientColorTop), LC_RGBA_BLUE(mOptions->Preferences.mBackgroundGradientColorTop)));
ui->BackgroundGradient1ColorButton->setIcon(pix);
pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mBackgroundGradientColorBottom), LC_RGBA_GREEN(mOptions->Preferences.mBackgroundGradientColorBottom), LC_RGBA_BLUE(mOptions->Preferences.mBackgroundGradientColorBottom)));
ui->BackgroundGradient2ColorButton->setIcon(pix);
pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mAxesColor), LC_RGBA_GREEN(mOptions->Preferences.mAxesColor), LC_RGBA_BLUE(mOptions->Preferences.mAxesColor)));
ui->AxesColorButton->setIcon(pix);
2020-12-30 22:44:08 +01:00
pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mTextColor), LC_RGBA_GREEN(mOptions->Preferences.mTextColor), LC_RGBA_BLUE(mOptions->Preferences.mTextColor)));
ui->TextColorButton->setIcon(pix);
pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mOverlayColor), LC_RGBA_GREEN(mOptions->Preferences.mOverlayColor), LC_RGBA_BLUE(mOptions->Preferences.mOverlayColor)));
ui->OverlayColorButton->setIcon(pix);
2020-07-25 22:21:22 +02:00
pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mActiveViewColor), LC_RGBA_GREEN(mOptions->Preferences.mActiveViewColor), LC_RGBA_BLUE(mOptions->Preferences.mActiveViewColor)));
ui->ActiveViewColorButton->setIcon(pix);
2020-12-12 03:37:16 +01:00
pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mInactiveViewColor), LC_RGBA_GREEN(mOptions->Preferences.mInactiveViewColor), LC_RGBA_BLUE(mOptions->Preferences.mInactiveViewColor)));
ui->InactiveViewColorButton->setIcon(pix);
2020-04-25 21:16:37 +02:00
pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mFadeStepsColor), LC_RGBA_GREEN(mOptions->Preferences.mFadeStepsColor), LC_RGBA_BLUE(mOptions->Preferences.mFadeStepsColor)));
ui->FadeStepsColor->setIcon(pix);
pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mHighlightNewPartsColor), LC_RGBA_GREEN(mOptions->Preferences.mHighlightNewPartsColor), LC_RGBA_BLUE(mOptions->Preferences.mHighlightNewPartsColor)));
ui->HighlightNewPartsColor->setIcon(pix);
pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mGridStudColor), LC_RGBA_GREEN(mOptions->Preferences.mGridStudColor), LC_RGBA_BLUE(mOptions->Preferences.mGridStudColor)));
ui->gridStudColor->setIcon(pix);
pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mGridLineColor), LC_RGBA_GREEN(mOptions->Preferences.mGridLineColor), LC_RGBA_BLUE(mOptions->Preferences.mGridLineColor)));
ui->gridLineColor->setIcon(pix);
pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mViewSphereColor), LC_RGBA_GREEN(mOptions->Preferences.mViewSphereColor), LC_RGBA_BLUE(mOptions->Preferences.mViewSphereColor)));
2019-01-20 20:59:18 +01:00
ui->ViewSphereColorButton->setIcon(pix);
pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mViewSphereTextColor), LC_RGBA_GREEN(mOptions->Preferences.mViewSphereTextColor), LC_RGBA_BLUE(mOptions->Preferences.mViewSphereTextColor)));
2019-01-20 20:59:18 +01:00
ui->ViewSphereTextColorButton->setIcon(pix);
pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mViewSphereHighlightColor), LC_RGBA_GREEN(mOptions->Preferences.mViewSphereHighlightColor), LC_RGBA_BLUE(mOptions->Preferences.mViewSphereHighlightColor)));
2019-01-20 20:59:18 +01:00
ui->ViewSphereHighlightColorButton->setIcon(pix);
on_studLogo_toggled();
2013-08-09 06:57:18 +02:00
on_antiAliasing_toggled();
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();
on_HighlightNewParts_toggled();
on_gridStuds_toggled();
on_gridLines_toggled();
on_ViewSphereSizeCombo_currentIndexChanged(ui->ViewSphereSizeCombo->currentIndex());
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);
commandChanged(nullptr);
2016-04-25 07:26:34 +02:00
UpdateMouseTree();
#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
MouseTreeItemChanged(nullptr);
2013-08-09 06:57:18 +02:00
}
lcQPreferencesDialog::~lcQPreferencesDialog()
{
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;
}
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());
2019-11-28 22:52:06 +01:00
int Language = ui->Language->currentIndex();
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];
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())
mOptions->AASamples = 1;
2013-08-09 06:57:18 +02:00
else if (ui->antiAliasingSamples->currentIndex() == 2)
mOptions->AASamples = 8;
2013-08-09 06:57:18 +02:00
else if (ui->antiAliasingSamples->currentIndex() == 1)
mOptions->AASamples = 4;
2013-08-09 06:57:18 +02:00
else
mOptions->AASamples = 2;
2013-08-09 06:57:18 +02:00
mOptions->Preferences.mDrawEdgeLines = ui->edgeLines->isChecked();
2020-06-06 20:16:01 +02:00
mOptions->Preferences.mLineWidth = mLineWidthRange[0] + static_cast<float>(ui->LineWidthSlider->value()) * mLineWidthGranularity;
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();
mOptions->Preferences.mHighlightNewParts = ui->HighlightNewParts->isChecked();
2013-08-09 06:57:18 +02:00
mOptions->Preferences.mDrawGridStuds = ui->gridStuds->isChecked();
mOptions->Preferences.mDrawGridLines = ui->gridLines->isChecked();
mOptions->Preferences.mGridLineSpacing = gridLineSpacing;
2013-08-09 06:57:18 +02:00
mOptions->Preferences.mBackgroundGradient = ui->BackgroundGradientRadio->isChecked();
mOptions->Preferences.mDrawAxes = ui->AxisIconCheckBox->isChecked();
2020-12-30 22:44:08 +01:00
mOptions->Preferences.mViewSphereEnabled = ui->ViewSphereSizeCombo->currentIndex() > 0;
mOptions->Preferences.mViewSphereLocation = (lcViewSphereLocation)ui->ViewSphereLocationCombo->currentIndex();
2019-01-20 20:59:18 +01:00
switch (ui->ViewSphereSizeCombo->currentIndex())
{
case 3:
mOptions->Preferences.mViewSphereSize = 200;
2019-01-20 20:59:18 +01:00
break;
case 2:
mOptions->Preferences.mViewSphereSize = 100;
2019-01-20 20:59:18 +01:00
break;
case 1:
mOptions->Preferences.mViewSphereSize = 50;
2019-01-20 20:59:18 +01:00
break;
}
mOptions->Preferences.mShadingMode = (lcShadingMode)ui->ShadingMode->currentIndex();
2013-08-09 06:57:18 +02:00
if (ui->studLogoCombo->isEnabled())
mOptions->StudLogo = ui->studLogoCombo->currentIndex() + 1;
else
mOptions->StudLogo = 0;
mOptions->Preferences.mDrawPreviewAxis = ui->PreviewAxisIconCheckBox->isChecked();
2020-12-30 22:44:08 +01:00
mOptions->Preferences.mPreviewViewSphereEnabled = ui->PreviewViewSphereSizeCombo->currentIndex() > 0;
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());
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));
}
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()
{
#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("Select 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()
{
2018-03-10 20:41:23 +01:00
QString result = QFileDialog::getExistingDirectory(this, tr("Open LGEO Folder"), ui->lgeoPath->text());
if (!result.isEmpty())
2018-03-10 20:41:23 +01:00
ui->lgeoPath->setText(QDir::toNativeSeparators(result));
}
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()
{
QObject* Button = sender();
QString Title;
quint32* Color = nullptr;
QColorDialog::ColorDialogOptions DialogOptions;
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)
{
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");
}
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");
}
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)
{
Color = &mOptions->Preferences.mHighlightNewPartsColor;
Title = tr("Select Highlight Color");
DialogOptions = QColorDialog::ShowAlphaChannel;
}
else if (Button == ui->gridStudColor)
{
Color = &mOptions->Preferences.mGridStudColor;
Title = tr("Select Grid Stud Color");
DialogOptions = QColorDialog::ShowAlphaChannel;
}
else if (Button == ui->gridLineColor)
{
Color = &mOptions->Preferences.mGridLineColor;
Title = tr("Select Grid Line Color");
}
else if (Button == ui->ViewSphereColorButton)
2019-01-20 20:59:18 +01:00
{
Color = &mOptions->Preferences.mViewSphereColor;
Title = tr("Select View Sphere Color");
2019-01-20 20:59:18 +01:00
}
else if (Button == ui->ViewSphereTextColorButton)
2019-01-20 20:59:18 +01:00
{
Color = &mOptions->Preferences.mViewSphereTextColor;
Title = tr("Select View Sphere Text Color");
2019-01-20 20:59:18 +01:00
}
else if (Button == ui->ViewSphereHighlightColorButton)
2019-01-20 20:59:18 +01:00
{
Color = &mOptions->Preferences.mViewSphereHighlightColor;
Title = tr("Select View Sphere Highlight Color");
2019-01-20 20:59:18 +01:00
}
2017-02-13 03:05:20 +01:00
else
return;
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);
}
void lcQPreferencesDialog::on_studLogo_toggled()
{
if (lcGetPiecesLibrary()->SupportsStudLogo())
ui->studLogoCombo->setEnabled(ui->studLogo->isChecked());
}
2013-08-09 06:57:18 +02:00
void lcQPreferencesDialog::on_antiAliasing_toggled()
{
ui->antiAliasingSamples->setEnabled(ui->antiAliasing->isChecked());
}
void lcQPreferencesDialog::on_edgeLines_toggled()
{
2020-06-06 20:16:01 +02:00
ui->LineWidthSlider->setEnabled(ui->edgeLines->isChecked());
ui->LineWidthLabel->setEnabled(ui->edgeLines->isChecked());
}
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());
}
void lcQPreferencesDialog::on_HighlightNewParts_toggled()
{
ui->HighlightNewPartsColor->setEnabled(ui->HighlightNewParts->isChecked());
}
void lcQPreferencesDialog::on_gridStuds_toggled()
{
ui->gridStudColor->setEnabled(ui->gridStuds->isChecked());
}
void lcQPreferencesDialog::on_gridLines_toggled()
2013-08-09 06:57:18 +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_PreviewViewSphereSizeCombo_currentIndexChanged(int Index)
{
ui->PreviewViewSphereLocationCombo->setEnabled(Index != 0);
}
2019-01-20 20:59:18 +01:00
void lcQPreferencesDialog::on_ViewSphereSizeCombo_currentIndexChanged(int Index)
{
ui->ViewSphereLocationCombo->setEnabled(Index != 0);
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
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);
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
{
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);
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;
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;
lcQCategoryDialog dialog(this, &mOptions->Categories[categoryIndex]);
2013-08-09 06:57:18 +02:00
if (dialog.exec() != QDialog::Accepted)
return;
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;
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;
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()
{
QString FileName = QFileDialog::getOpenFileName(this, tr("Import Categories"), "", tr("Text Files (*.txt);;All Files (*.*)"));
2013-08-09 06:57:18 +02: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;
if (!lcLoadCategories(FileName, Categories))
2013-08-09 06:57:18 +02:00
{
QMessageBox::warning(this, "LeoCAD", tr("Error loading categories file."));
return;
}
mOptions->Categories = Categories;
mOptions->CategoriesModified = true;
mOptions->CategoriesDefault = false;
2013-08-09 06:57:18 +02:00
}
void lcQPreferencesDialog::on_exportCategories_clicked()
{
QString FileName = QFileDialog::getSaveFileName(this, tr("Export Categories"), "", tr("Text Files (*.txt);;All Files (*.*)"));
2013-08-09 06:57:18 +02:00
if (FileName.isEmpty())
2013-08-09 06:57:18 +02:00
return;
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;
lcResetCategories(mOptions->Categories);
2013-08-09 06:57:18 +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();
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;
}
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 (unsigned int actionIdx = 0; actionIdx < LC_NUM_COMMANDS; actionIdx++)
2013-08-09 06:57:18 +02: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;
QKeySequence sequence(mOptions->KeyboardShortcuts.mShortcuts[actionIdx]);
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
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));
QKeySequence key(mOptions->KeyboardShortcuts.mShortcuts[shortcutIndex]);
2013-08-09 06:57:18 +02:00
ui->shortcutEdit->setText(key.toString(QKeySequence::NativeText));
}
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);
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* CurrentItem = ui->commandList->currentItem();
2013-08-09 06:57:18 +02:00
if (!CurrentItem || !CurrentItem->data(0, Qt::UserRole).isValid())
2013-08-09 06:57:18 +02:00
return;
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++)
{
if (NewShortcut == Shortcuts[ExistingIndex] && ExistingIndex != ShortcutIndex)
{
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);
if (QMessageBox::question(this, tr("Override Shortcut"), QuestionText, QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
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
mOptions->KeyboardShortcuts.mShortcuts[ShortcutIndex] = NewShortcut;
CurrentItem->setText(1, NewShortcut);
2013-08-09 06:57:18 +02:00
setShortcutModified(CurrentItem, mOptions->KeyboardShortcuts.mShortcuts[ShortcutIndex] != gCommands[ShortcutIndex].DefaultShortcut);
2013-08-09 06:57:18 +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()
{
QString FileName = QFileDialog::getOpenFileName(this, tr("Import shortcuts"), "", tr("Text Files (*.txt);;All Files (*.*)"));
2013-08-09 06:57:18 +02:00
if (FileName.isEmpty())
2013-08-09 06:57:18 +02:00
return;
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;
}
mOptions->KeyboardShortcuts = Shortcuts;
2013-08-09 06:57:18 +02:00
mOptions->KeyboardShortcutsModified = true;
mOptions->KeyboardShortcutsDefault = false;
2013-08-09 06:57:18 +02:00
}
void lcQPreferencesDialog::on_shortcutsExport_clicked()
{
QString FileName = QFileDialog::getSaveFileName(this, tr("Export shortcuts"), "", tr("Text Files (*.txt);;All Files (*.*)"));
2013-08-09 06:57:18 +02:00
if (FileName.isEmpty())
2013-08-09 06:57:18 +02:00
return;
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;
mOptions->KeyboardShortcuts.Reset();
2013-08-09 06:57:18 +02:00
updateCommandList();
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
{
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))
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
case Qt::RightButton:
Shortcut += tr("Right Button");
break;
2016-04-25 07:26:34 +02:00
default:
Shortcut.clear();
}
return Shortcut;
};
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)
{
Item->setText(1, Shortcut1);
Item->setText(2, Shortcut2);
}
2016-04-25 07:26:34 +02:00
else
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;
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
{
if (ToolIdx == ButtonIndex)
continue;
if (mOptions->MouseShortcuts.mShortcuts[ToolIdx].Button2 == Button && mOptions->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;
mOptions->MouseShortcuts.mShortcuts[ToolIdx].Button2 = Qt::NoButton;
mOptions->MouseShortcuts.mShortcuts[ToolIdx].Modifiers2 = Qt::NoModifier;
}
if (mOptions->MouseShortcuts.mShortcuts[ToolIdx].Button1 == Button && mOptions->MouseShortcuts.mShortcuts[ToolIdx].Modifiers1 == Modifiers)
{
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)
return;
2016-04-30 22:07:32 +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;
UpdateMouseTreeItem(ToolIdx);
}
2016-04-30 22:07:32 +02:00
}
}
2016-04-25 07:26:34 +02:00
int ItemIndex = ui->mouseTree->indexOfTopLevelItem(Current);
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
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);
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
mOptions->MouseShortcutsModified = true;
mOptions->MouseShortcutsDefault = false;
2016-04-25 07:26:34 +02:00
UpdateMouseTreeItem(ItemIndex);
MouseTreeItemChanged(Current);
2016-04-25 07:26:34 +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;
mOptions->MouseShortcuts.Reset();
2016-04-25 07:26:34 +02:00
UpdateMouseTree();
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);
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;
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;
}
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
}