[TD]add preferences for Balloon drag modifiers

This commit is contained in:
wandererfan
2024-09-17 17:17:15 -04:00
parent 758674d40b
commit 5ecd2a0b7a
5 changed files with 332 additions and 8 deletions

View File

@@ -24,17 +24,21 @@
#include "PreCompiled.h"
#include <Mod/TechDraw/App/Preferences.h>
#include "DlgPrefsTechDrawAdvancedImp.h"
#include "ui_DlgPrefsTechDrawAdvanced.h"
using namespace TechDrawGui;
using namespace TechDraw;
DlgPrefsTechDrawAdvancedImp::DlgPrefsTechDrawAdvancedImp( QWidget* parent )
: PreferencePage( parent )
, ui(new Ui_DlgPrefsTechDrawAdvancedImp)
{
ui->setupUi(this);
makeBalloonBoxConnections();
}
DlgPrefsTechDrawAdvancedImp::~DlgPrefsTechDrawAdvancedImp()
@@ -58,8 +62,40 @@ void DlgPrefsTechDrawAdvancedImp::saveSettings()
ui->cbAutoCorrectRefs->onSave();
ui->cbNewFaceFinder->onSave();
ui->sbScrubCount->onSave();
saveBalloonOverride();
}
void DlgPrefsTechDrawAdvancedImp::saveBalloonOverride()
{
if (ui->cbBalloonDefault->isChecked()) {
Preferences::setBalloonDragModifiers(Qt::ControlModifier);
return;
}
Qt::KeyboardModifiers result{Qt::NoModifier};
if (ui->cbBalloonShift->isChecked()) {
result |= Qt::ShiftModifier;
}
if (ui->cbBalloonControl->isChecked()) {
result |= Qt::ControlModifier;
}
if (ui->cbBalloonAlt->isChecked()) {
result |= Qt::AltModifier;
}
if (ui->cbBalloonMeta->isChecked()) {
result |= Qt::MetaModifier;
}
Preferences::setBalloonDragModifiers(result);
}
void DlgPrefsTechDrawAdvancedImp::loadSettings()
{
ui->cbDetectFaces->onRestore();
@@ -76,18 +112,116 @@ void DlgPrefsTechDrawAdvancedImp::loadSettings()
ui->cbAutoCorrectRefs->onRestore();
ui->cbNewFaceFinder->onRestore();
ui->sbScrubCount->onRestore();
loadBalloonOverride();
}
void DlgPrefsTechDrawAdvancedImp::loadBalloonOverride()
{
uint prefOverride = Preferences::balloonDragModifiers();
if (prefOverride == Qt::ControlModifier) {
// default case
ui->cbBalloonDefault->setChecked(true);
clearBalloonOptions();
enableBalloonOptions(false);
return;
}
ui->cbBalloonDefault->setChecked(false);
enableBalloonOptions(true);
if (flagsContainValue(prefOverride, Qt::ShiftModifier)) {
ui->cbBalloonShift->setChecked(true);
}
if (flagsContainValue(prefOverride, Qt::ControlModifier)) {
ui->cbBalloonControl->setChecked(true);
}
if (flagsContainValue(prefOverride, Qt::AltModifier)) {
ui->cbBalloonAlt->setChecked(true);
}
if (flagsContainValue(prefOverride, Qt::MetaModifier)) {
ui->cbBalloonMeta->setChecked(true);
}
}
//! true if bit pattern of value is found in flags.
bool DlgPrefsTechDrawAdvancedImp::flagsContainValue(uint flags, uint value)
{
uint matchResult = flags & value;
if (matchResult == value) {
return true;
}
return false;
}
void DlgPrefsTechDrawAdvancedImp::clearBalloonOptions()
{
ui->cbBalloonShift->setChecked(false);
ui->cbBalloonControl->setChecked(false);
ui->cbBalloonAlt->setChecked(false);
ui->cbBalloonMeta->setChecked(false);
}
void DlgPrefsTechDrawAdvancedImp::enableBalloonOptions(bool newState)
{
ui->cbBalloonShift->setEnabled(newState);
ui->cbBalloonControl->setEnabled(newState);
ui->cbBalloonAlt->setEnabled(newState);
ui->cbBalloonMeta->setEnabled(newState);
}
void DlgPrefsTechDrawAdvancedImp::slotBalloonBoxChecked()
{
if (ui->cbBalloonDefault->isChecked()) {
clearBalloonOptions();
enableBalloonOptions(false);
} else {
enableBalloonOptions(true);
}
}
void DlgPrefsTechDrawAdvancedImp::makeBalloonBoxConnections()
{
connect(ui->cbBalloonDefault,
qOverload<int>(&QCheckBox::stateChanged),
this,
&DlgPrefsTechDrawAdvancedImp::slotBalloonBoxChecked);
connect(ui->cbBalloonShift,
qOverload<int>(&QCheckBox::stateChanged),
this,
&DlgPrefsTechDrawAdvancedImp::slotBalloonBoxChecked);
connect(ui->cbBalloonControl,
qOverload<int>(&QCheckBox::stateChanged),
this,
&DlgPrefsTechDrawAdvancedImp::slotBalloonBoxChecked);
connect(ui->cbBalloonAlt,
qOverload<int>(&QCheckBox::stateChanged),
this,
&DlgPrefsTechDrawAdvancedImp::slotBalloonBoxChecked);
connect(ui->cbBalloonMeta,
qOverload<int>(&QCheckBox::stateChanged),
this,
&DlgPrefsTechDrawAdvancedImp::slotBalloonBoxChecked);
}
/**
* Sets the strings of the subwidgets using the current language.
*/
void DlgPrefsTechDrawAdvancedImp::changeEvent(QEvent *e)
void DlgPrefsTechDrawAdvancedImp::changeEvent(QEvent *event)
{
if (e->type() == QEvent::LanguageChange) {
if (event->type() == QEvent::LanguageChange) {
ui->retranslateUi(this);
}
else {
QWidget::changeEvent(e);
QWidget::changeEvent(event);
}
}