Option to use regular slash character instead of Unicode division slash (issue #11)

This commit is contained in:
Hanna K 2021-09-01 07:56:05 +02:00
parent 4886f8983e
commit f2966eafff
7 changed files with 32 additions and 6 deletions

View File

@ -227,13 +227,13 @@ bool last_is_operator(std::string str, bool allow_exp) {
} else {
if(str.length() >= 3 && str[str.length() - 2] < 0) {
str = str.substr(str.length() - 3);
if(str == "" || str == "" || str == "" || str == "" || str == "" || str == "" || str == "" || str == settings->multiplicationSign() || str == SIGN_DIVISION_SLASH || str == SIGN_MINUS) {
if(str == "" || str == "" || str == "" || str == "" || str == "" || str == "" || str == "" || str == settings->multiplicationSign() || str == settings->divisionSign() || str == SIGN_MINUS) {
return true;
}
}
if(str.length() >= 2) {
str = str.substr(str.length() - 2);
if(str == "¬" || str == settings->multiplicationSign() || str == SIGN_DIVISION_SLASH || str == SIGN_MINUS) return true;
if(str == "¬" || str == settings->multiplicationSign() || str == settings->divisionSign() || str == SIGN_MINUS) return true;
}
}
return false;
@ -1398,8 +1398,8 @@ void ExpressionEdit::keyPressEvent(QKeyEvent *event) {
emit calculateRPNRequest(OPERATION_DIVIDE);
return;
}
if(doChainMode("/")) return;
wrapSelection("/");
if(doChainMode(settings->divisionSign(false))) return;
wrapSelection(settings->divisionSign(false));
return;
}
case Qt::Key_ParenRight: {

View File

@ -44,6 +44,10 @@ class MathTextEdit : public QPlainTextEdit {
insertPlainText(settings->multiplicationSign());
return;
}
case Qt::Key_Slash: {
insertPlainText(settings->divisionSign(false));
return;
}
case Qt::Key_Minus: {
insertPlainText(SIGN_MINUS);
return;
@ -130,6 +134,7 @@ UserFunction *FunctionEditDialog::createFunction(MathFunction **replaced_item) {
gsub("z", "\\z", str);
}
gsub(settings->multiplicationSign(), "*", str);
gsub(settings->divisionSign(), "/", str);
gsub(SIGN_MINUS, "-", str);
f = new UserFunction("", nameEdit->text().trimmed().toStdString(), str);
CALCULATOR->addFunction(f);
@ -158,6 +163,7 @@ bool FunctionEditDialog::modifyFunction(MathFunction *f, MathFunction **replaced
gsub("z", "\\z", str);
}
gsub(settings->multiplicationSign(), "*", str);
gsub(settings->divisionSign(), "/", str);
gsub(SIGN_MINUS, "-", str);
((UserFunction*) f)->setFormula(str);
}
@ -170,6 +176,7 @@ void FunctionEditDialog::setFunction(MathFunction *f) {
expressionEdit->setEnabled(true);
std::string str = CALCULATOR->localizeExpression(((UserFunction*) f)->formula(), settings->evalops.parse_options);
gsub("*", settings->multiplicationSign(), str);
gsub("/", settings->divisionSign(false), str);
gsub("-", SIGN_MINUS, str);
expressionEdit->setPlainText(QString::fromStdString(str));
} else {

View File

@ -319,8 +319,8 @@ KeypadWidget::KeypadWidget(QWidget *parent) : QWidget(parent) {
OPERATOR_SYMBOL_BUTTON(SIGN_MINUS, SIGN_MINUS, 2, c);
button->setToolTip(tr("Subtraction"), tr("Minus"));
}
OPERATOR_BUTTON3(SIGN_DIVISION_SLASH, "|", "~", 1, c);
button->setProperty(BUTTON_DATA, "/");
OPERATOR_BUTTON3(settings->divisionSign(), "|", "~", 1, c);
button->setProperty(BUTTON_DATA, settings->divisionSign());
button->setToolTip(tr("Division"), tr("Bitwise OR"), tr("Bitwise NOT"));
acButton = new KeypadButton(LOAD_ICON("edit-clear"), this);
acButton->setToolTip(tr("Clear expression"));
@ -360,6 +360,8 @@ KeypadWidget::~KeypadWidget() {}
void KeypadWidget::updateSymbols() {
multiplicationButton->setText(settings->multiplicationSign());
multiplicationButton->setProperty(BUTTON_DATA, settings->multiplicationSign());
multiplicationButton->setText(settings->divisionSign());
multiplicationButton->setProperty(BUTTON_DATA, settings->divisionSign());
commaButton->setText(QString::fromStdString(CALCULATOR->getComma()));
commaButton->setProperty(BUTTON_DATA, QString::fromStdString(CALCULATOR->getComma()));
dotButton->setText(QString::fromStdString(CALCULATOR->getDecimalPoint()));

View File

@ -145,6 +145,7 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) : QDialog(parent) {
BOX(tr("Hexadecimal two's complement representation"), settings->printops.hexadecimal_twos_complement, hexTwosToggled(bool));
BOX(tr("Use lower case letters in non-decimal numbers"), settings->printops.lower_case_numbers, lowerCaseToggled(bool));
BOX(tr("Use dot as multiplication sign"), settings->printops.multiplication_sign != MULTIPLICATION_SIGN_X, multiplicationDotToggled(bool));
BOX(tr("Use Unicode division slash in output"), settings->printops.division_sign == DIVISION_SIGN_DIVISION_SLASH, divisionSlashToggled(bool));
BOX(tr("Spell out logical operators"), settings->printops.spell_out_logical_operators, spellOutToggled(bool));
BOX(tr("Use E-notation instead of 10^n"), settings->printops.lower_case_e, eToggled(bool));
BOX(tr("Use 'j' as imaginary unit"), CALCULATOR->getVariableById(VARIABLE_ID_I)->hasName("j") > 0, imaginaryJToggled(bool));
@ -292,6 +293,12 @@ void PreferencesDialog::multiplicationDotToggled(bool b) {
emit resultDisplayUpdated();
emit symbolsUpdated();
}
void PreferencesDialog::divisionSlashToggled(bool b) {
if(b) settings->printops.division_sign = DIVISION_SIGN_DIVISION_SLASH;
else settings->printops.division_sign = DIVISION_SIGN_SLASH;
emit resultDisplayUpdated();
emit symbolsUpdated();
}
void PreferencesDialog::spellOutToggled(bool b) {
settings->printops.spell_out_logical_operators = b;
emit resultDisplayUpdated();

View File

@ -42,6 +42,7 @@ class PreferencesDialog : public QDialog {
void hexTwosToggled(bool);
void lowerCaseToggled(bool);
void multiplicationDotToggled(bool);
void divisionSlashToggled(bool);
void spellOutToggled(bool);
void eToggled(bool);
void imaginaryJToggled(bool);

View File

@ -393,6 +393,8 @@ void QalculateQtSettings::loadPreferences() {
if(v >= MULTIPLICATION_SIGN_ASTERISK && v <= MULTIPLICATION_SIGN_ALTDOT) {
printops.multiplication_sign = (MultiplicationSign) v;
}
} else if(svar == "division_sign") {
if(v >= DIVISION_SIGN_SLASH && v <= DIVISION_SIGN_DIVISION) printops.division_sign = (DivisionSign) v;
} else if(svar == "plot_legend_placement") {
if(v >= PLOT_LEGEND_NONE && v <= PLOT_LEGEND_OUTSIDE) default_plot_legend_placement = (PlotLegendPlacement) v;
} else if(svar == "plot_style") {
@ -821,6 +823,7 @@ void QalculateQtSettings::savePreferences(bool) {
if(use_custom_keypad_font || save_custom_keypad_font) fprintf(file, "custom_keypad_font=%s\n", custom_keypad_font.c_str());
if(use_custom_app_font || save_custom_app_font) fprintf(file, "custom_application_font=%s\n", custom_app_font.c_str());
if(printops.multiplication_sign != MULTIPLICATION_SIGN_X) fprintf(file, "multiplication_sign=%i\n", printops.multiplication_sign);
if(printops.division_sign != DIVISION_SIGN_DIVISION_SLASH) fprintf(file, "division_sign=%i\n", printops.division_sign);
if(implicit_question_asked) fprintf(file, "implicit_question_asked=%i\n", implicit_question_asked);
fprintf(file, "replace_expression=%i\n", replace_expression);
fprintf(file, "rpn_keys=%i\n", rpn_keys);
@ -981,6 +984,11 @@ const char *QalculateQtSettings::multiplicationSign() {
default: {return "*";}
}
}
const char *QalculateQtSettings::divisionSign(bool output) {
if(printops.division_sign == DIVISION_SIGN_DIVISION && printops.use_unicode_signs) return SIGN_DIVISION;
else if(output && printops.division_sign == DIVISION_SIGN_DIVISION_SLASH && printops.use_unicode_signs) return SIGN_DIVISION_SLASH;
return "/";
}
void QalculateQtSettings::updateMessagePrintOptions() {
PrintOptions message_printoptions = printops;

View File

@ -74,6 +74,7 @@ class QalculateQtSettings : QObject {
void checkVersion(bool force, QWidget *parent);
void autoUpdate(std::string new_version, QWidget *parent);
const char *multiplicationSign();
const char *divisionSign(bool output = true);
EvaluationOptions evalops;
PrintOptions printops;