Add copy unformatted ASCII menu items and add copy ASCII by default option (copy with operators and separators intact by default); Add caret as xor option; Refine use of quotation marks for function arguments; Do not replace *, -, / with Unicode operators if cursor is within quotation marks; Handle non-breaking spaces (now used in libqalculate)
This commit is contained in:
parent
960c3e640c
commit
365b776a19
@ -1370,6 +1370,7 @@ void ExpressionEdit::keyPressEvent(QKeyEvent *event) {
|
||||
emit calculateRPNRequest(OPERATION_MULTIPLY);
|
||||
return;
|
||||
}
|
||||
if(expressionInQuotes()) break;
|
||||
if(doChainMode(settings->multiplicationSign())) return;
|
||||
wrapSelection(settings->multiplicationSign());
|
||||
return;
|
||||
@ -1379,6 +1380,7 @@ void ExpressionEdit::keyPressEvent(QKeyEvent *event) {
|
||||
emit calculateRPNRequest(OPERATION_SUBTRACT);
|
||||
return;
|
||||
}
|
||||
if(expressionInQuotes()) break;
|
||||
if(doChainMode(settings->printops.use_unicode_signs ? SIGN_MINUS : "-")) return;
|
||||
wrapSelection(settings->printops.use_unicode_signs ? SIGN_MINUS : "-");
|
||||
return;
|
||||
@ -1388,6 +1390,7 @@ void ExpressionEdit::keyPressEvent(QKeyEvent *event) {
|
||||
emit calculateRPNRequest(settings->caret_as_xor ? OPERATION_BITWISE_XOR : OPERATION_RAISE);
|
||||
return;
|
||||
}
|
||||
if(expressionInQuotes()) break;
|
||||
if(doChainMode(settings->caret_as_xor ? " xor " : "^")) return;
|
||||
wrapSelection(settings->caret_as_xor ? " xor " : "^");
|
||||
return;
|
||||
@ -1401,6 +1404,7 @@ void ExpressionEdit::keyPressEvent(QKeyEvent *event) {
|
||||
emit calculateRPNRequest(settings->caret_as_xor ? OPERATION_BITWISE_XOR : OPERATION_RAISE);
|
||||
return;
|
||||
}
|
||||
if(expressionInQuotes()) break;
|
||||
if(doChainMode(settings->caret_as_xor ? " xor " : "^")) return;
|
||||
wrapSelection(settings->caret_as_xor ? " xor " : "^");
|
||||
return;
|
||||
@ -1410,6 +1414,7 @@ void ExpressionEdit::keyPressEvent(QKeyEvent *event) {
|
||||
emit calculateRPNRequest(OPERATION_ADD);
|
||||
return;
|
||||
}
|
||||
if(expressionInQuotes()) break;
|
||||
if(doChainMode("+")) return;
|
||||
wrapSelection("+");
|
||||
return;
|
||||
@ -1419,6 +1424,7 @@ void ExpressionEdit::keyPressEvent(QKeyEvent *event) {
|
||||
emit calculateRPNRequest(OPERATION_DIVIDE);
|
||||
return;
|
||||
}
|
||||
if(expressionInQuotes()) break;
|
||||
if(doChainMode(settings->divisionSign(false))) return;
|
||||
wrapSelection(settings->divisionSign(false));
|
||||
return;
|
||||
@ -1835,18 +1841,29 @@ void ExpressionEdit::blockUndo(bool b) {
|
||||
else block_add_to_undo--;
|
||||
}
|
||||
void remove_spaces(std::string &str) {
|
||||
size_t i = 0, i2;
|
||||
size_t i = 0;
|
||||
while(true) {
|
||||
i = str.find(' ', i);
|
||||
i2 = str.find(THIN_SPACE, i);
|
||||
if(i2 != std::string::npos && (i == std::string::npos || i2 < i)) {
|
||||
str.erase(i2, 3);
|
||||
i = i2;
|
||||
} else if(i != std::string::npos) {
|
||||
str.erase(i, 1);
|
||||
} else {
|
||||
break;
|
||||
if(i != std::string::npos) str.erase(i, 1);
|
||||
else break;
|
||||
}
|
||||
i = 0;
|
||||
while(true) {
|
||||
i = str.find(THIN_SPACE, i);
|
||||
if(i != std::string::npos) str.erase(i, strlen(THIN_SPACE));
|
||||
else break;
|
||||
}
|
||||
i = 0;
|
||||
while(true) {
|
||||
i = str.find(NNBSP, i);
|
||||
if(i != std::string::npos) str.erase(i, strlen(NNBSP));
|
||||
else break;
|
||||
}
|
||||
i = 0;
|
||||
while(true) {
|
||||
i = str.find(NBSP, i);
|
||||
if(i != std::string::npos) str.erase(i, strlen(NBSP));
|
||||
else break;
|
||||
}
|
||||
}
|
||||
void ExpressionEdit::showCurrentStatus() {
|
||||
@ -2699,6 +2716,20 @@ void ExpressionEdit::onCursorPositionChanged() {
|
||||
highlightParentheses();
|
||||
displayParseStatus();
|
||||
}
|
||||
bool ExpressionEdit::expressionInQuotes() {
|
||||
bool in_cit1 = false, in_cit2 = false;
|
||||
QString str = toPlainText();
|
||||
int pos = textCursor().selectionStart();
|
||||
for(int i = 0; i < pos; i++) {
|
||||
if(!in_cit2 && str[i] == '\"') {
|
||||
in_cit1 = !in_cit1;
|
||||
} else if(!in_cit1 && str[i] == '\'') {
|
||||
in_cit2 = !in_cit2;
|
||||
}
|
||||
}
|
||||
return in_cit1 || in_cit2;
|
||||
}
|
||||
|
||||
void ExpressionEdit::highlightParentheses() {
|
||||
if(document()->isEmpty()) return;
|
||||
if(parentheses_highlighted) {
|
||||
@ -3469,9 +3500,27 @@ void ExpressionEdit::insertFromMimeData(const QMimeData *source) {
|
||||
if(!source->objectName().startsWith("history_") && source->hasHtml()) str = unhtmlize(source->html()).trimmed();
|
||||
else if(source->hasText()) str = source->text();
|
||||
if(settings->printops.use_unicode_signs && str.length() > 1) {
|
||||
str.replace("-", SIGN_MINUS);
|
||||
str.replace("*", settings->multiplicationSign());
|
||||
str.replace("/", settings->divisionSign(false));
|
||||
bool in_cit1 = false, in_cit2 = false;
|
||||
QString text = toPlainText();
|
||||
int pos = textCursor().selectionStart();
|
||||
for(int i = 0; i < pos; i++) {
|
||||
if(!in_cit2 && text[i] == '\"') {
|
||||
in_cit1 = !in_cit1;
|
||||
} else if(!in_cit1 && text[i] == '\'') {
|
||||
in_cit2 = !in_cit2;
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < str.length(); i++) {
|
||||
if(!in_cit2 && str[i] == '\"') {
|
||||
in_cit1 = !in_cit1;
|
||||
} else if(!in_cit1 && str[i] == '\'') {
|
||||
in_cit2 = !in_cit2;
|
||||
} else if(!in_cit1 && !in_cit2) {
|
||||
if(str[i] == '*') str.replace(i, 1, settings->multiplicationSign());
|
||||
else if(str[i] == '/') str.replace(i, 1, settings->divisionSign(false));
|
||||
else if(str[i] == '-') str.replace(i, 1, SIGN_MINUS);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!str.isEmpty()) insertPlainText(str);
|
||||
}
|
||||
|
@ -96,6 +96,7 @@ class ExpressionEdit : public QPlainTextEdit {
|
||||
void keyReleaseEvent(QKeyEvent*) override;
|
||||
void contextMenuEvent(QContextMenuEvent *e) override;
|
||||
void insertFromMimeData(const QMimeData*) override;
|
||||
bool expressionInQuotes();
|
||||
|
||||
public:
|
||||
|
||||
|
@ -138,6 +138,8 @@ QString unhtmlize(QString str) {
|
||||
str.replace(">", ">");
|
||||
str.replace("<", "<");
|
||||
str.replace(" ", " ");
|
||||
str.replace(" ", THIN_SPACE);
|
||||
str.replace(" ", NNBSP);
|
||||
str.replace(""", "\"");
|
||||
return str;
|
||||
}
|
||||
@ -753,9 +755,12 @@ void HistoryView::contextMenuEvent(QContextMenuEvent *e) {
|
||||
cmenu = new QMenu(this);
|
||||
insertValueAction = cmenu->addAction(tr("Insert Value"), this, SLOT(editInsertValue()));
|
||||
insertTextAction = cmenu->addAction(tr("Insert Text"), this, SLOT(editInsertText()));
|
||||
copyAction = cmenu->addAction(tr("Copy"), this, SLOT(editCopy()));
|
||||
copyAction = new QAction(tr("Copy"));
|
||||
connect(copyAction, SIGNAL(triggered()), this, SLOT(editCopy()));
|
||||
copyAction->setShortcut(QKeySequence::Copy);
|
||||
copyAction->setShortcutContext(Qt::WidgetShortcut);
|
||||
copyFormattedAction = cmenu->addAction(tr("Copy"), this, SLOT(editCopyFormatted()));
|
||||
copyAsciiAction = cmenu->addAction(tr("Copy unformatted ASCII"), this, SLOT(editCopyAscii()));
|
||||
selectAllAction = cmenu->addAction(tr("Select All"), this, SLOT(selectAll()));
|
||||
selectAllAction->setShortcut(QKeySequence::SelectAll);
|
||||
selectAllAction->setShortcutContext(Qt::WidgetShortcut);
|
||||
@ -779,6 +784,8 @@ void HistoryView::contextMenuEvent(QContextMenuEvent *e) {
|
||||
insertValueAction->setEnabled(i3 >= 0);
|
||||
insertTextAction->setEnabled(true);
|
||||
copyAction->setEnabled(true);
|
||||
copyFormattedAction->setEnabled(true);
|
||||
copyAsciiAction->setEnabled(true);
|
||||
delAction->setEnabled(true);
|
||||
protectAction->setEnabled(true);
|
||||
bool b = false;
|
||||
@ -791,6 +798,8 @@ void HistoryView::contextMenuEvent(QContextMenuEvent *e) {
|
||||
movetotopAction->setEnabled(b);
|
||||
} else {
|
||||
copyAction->setEnabled(textCursor().hasSelection());
|
||||
copyFormattedAction->setEnabled(textCursor().hasSelection());
|
||||
copyAsciiAction->setEnabled(textCursor().hasSelection());
|
||||
delAction->setEnabled(false);
|
||||
protectAction->setEnabled(false);
|
||||
movetotopAction->setEnabled(false);
|
||||
@ -829,29 +838,67 @@ void HistoryView::editFind() {
|
||||
dialog->deleteLater();
|
||||
}
|
||||
|
||||
void remove_separator(std::string ©_text) {
|
||||
for(size_t i = ((CALCULATOR->local_digit_group_separator.empty() || CALCULATOR->local_digit_group_separator == " ") ? 1 : 0); i < 4; i++) {
|
||||
std::string str_sep;
|
||||
if(i == 0) str_sep = CALCULATOR->local_digit_group_separator;
|
||||
else if(i == 1) str_sep = THIN_SPACE;
|
||||
else if(i == 2) str_sep = NNBSP;
|
||||
else str_sep = " ";
|
||||
size_t index = copy_text.find(str_sep);
|
||||
while(index != std::string::npos) {
|
||||
if(index > 0 && index + str_sep.length() < copy_text.length() && copy_text[index - 1] >= '0' && copy_text[index - 1] <= '9' && copy_text[index + str_sep.length()] >= '0' && copy_text[index + str_sep.length()] <= '9') {
|
||||
copy_text.erase(index, str_sep.length());
|
||||
} else {
|
||||
index++;
|
||||
}
|
||||
index = copy_text.find(str_sep, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
QString replace_first_minus(const QString &qstr) {
|
||||
if(qstr.indexOf(SIGN_MINUS) == 0) {
|
||||
std::string str = qstr.toStdString();
|
||||
if(str.find_first_of(OPERATORS) == std::string::npos) {
|
||||
for(size_t i = strlen(SIGN_MINUS); i < str.length(); i++) {
|
||||
if((signed char) str[i] < 0) return qstr;
|
||||
}
|
||||
std::string str_new = str;
|
||||
str_new.replace(0, strlen(SIGN_MINUS), "-");
|
||||
return QString::fromStdString(str_new);
|
||||
}
|
||||
}
|
||||
return qstr;
|
||||
}
|
||||
|
||||
std::string replace_first_minus(const std::string &str) {
|
||||
if(str.find(SIGN_MINUS) == 0 && str.find_first_of(OPERATORS) == std::string::npos) {
|
||||
for(size_t i = strlen(SIGN_MINUS); i < str.length(); i++) {
|
||||
if((signed char) str[i] < 0) return str;
|
||||
}
|
||||
std::string str_new = str;
|
||||
str_new.replace(0, strlen(SIGN_MINUS), "-");
|
||||
return str_new;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string unformat(std::string str) {
|
||||
remove_separator(str);
|
||||
gsub(SIGN_MINUS, "-", str);
|
||||
gsub(SIGN_MULTIPLICATION, "*", str);
|
||||
gsub(SIGN_MULTIDOT, "*", str);
|
||||
gsub(SIGN_MIDDLEDOT, "*", str);
|
||||
gsub(THIN_SPACE, "", str);
|
||||
gsub(NNBSP, "", str);
|
||||
gsub(SIGN_DIVISION, "/", str);
|
||||
gsub(SIGN_DIVISION_SLASH, "/", str);
|
||||
gsub(SIGN_SQRT, "sqrt", str);
|
||||
gsub("Ω", "ohm", str);
|
||||
return str;
|
||||
}
|
||||
|
||||
QString unformat(QString str) {
|
||||
str.replace(SIGN_MINUS, "-");
|
||||
str.replace(SIGN_MULTIPLICATION, "*");
|
||||
str.replace(SIGN_MULTIDOT, "*");
|
||||
str.replace(SIGN_MIDDLEDOT, "*");
|
||||
str.replace(THIN_SPACE, "");
|
||||
str.replace(SIGN_DIVISION, "/");
|
||||
str.replace(SIGN_DIVISION_SLASH, "/");
|
||||
return str;
|
||||
}
|
||||
|
||||
void HistoryView::editCopy() {
|
||||
void HistoryView::editCopy(int ascii) {
|
||||
if(textCursor().hasSelection()) {
|
||||
QString str = textCursor().selection().toHtml();
|
||||
int i = str.indexOf("<!--StartFragment-->");
|
||||
@ -869,35 +916,54 @@ void HistoryView::editCopy() {
|
||||
} else {
|
||||
str = unhtmlize(textCursor().selectedText());
|
||||
}
|
||||
if(ascii > 0 || (ascii < 0 && settings->copy_ascii)) {
|
||||
QApplication::clipboard()->setText(QString::fromStdString(unformat(str.toStdString())));
|
||||
} else {
|
||||
QMimeData *qm = new QMimeData();
|
||||
qm->setHtml(textCursor().selection().toHtml());
|
||||
qm->setText(unformat(str));
|
||||
qm->setText(str);
|
||||
qm->setObjectName("history_selection");
|
||||
QApplication::clipboard()->setMimeData(qm);
|
||||
}
|
||||
} else {
|
||||
int i1 = -1, i2 = -1;
|
||||
indexAtPos(context_pos, &i1, &i2);
|
||||
if(i1 < 0) return;
|
||||
if(i2 < 0) {
|
||||
if(i1 >= 0 && (size_t) i1 < settings->v_expression.size()) {
|
||||
if(ascii > 0 || (ascii < 0 && settings->copy_ascii)) {
|
||||
if(!settings->v_expression[i1].empty()) QApplication::clipboard()->setText(QString::fromStdString(unformat(settings->v_expression[i1])));
|
||||
else QApplication::clipboard()->setText(QString::fromStdString(unformat(unhtmlize(settings->v_parse[i1]))));
|
||||
} else {
|
||||
QMimeData *qm = new QMimeData();
|
||||
qm->setHtml(QString::fromStdString(settings->v_parse[i1]));
|
||||
if(!settings->v_expression[i1].empty()) qm->setText(QString::fromStdString(unformat(settings->v_expression[i1])));
|
||||
else qm->setText(QString::fromStdString(unformat(unhtmlize(settings->v_parse[i1]))));
|
||||
if(!settings->v_expression[i1].empty()) qm->setText(QString::fromStdString(settings->v_expression[i1]));
|
||||
else qm->setText(QString::fromStdString(unhtmlize(settings->v_parse[i1])));
|
||||
qm->setObjectName("history_expression");
|
||||
QApplication::clipboard()->setMimeData(qm);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if((size_t) i1 < settings->v_result.size() && (size_t) i2 < settings->v_result[i1].size()) {
|
||||
if(ascii > 0 || (ascii < 0 && settings->copy_ascii)) {
|
||||
QApplication::clipboard()->setText(QString::fromStdString(unformat(unhtmlize((settings->v_result[i1][i2])))));
|
||||
} else {
|
||||
QMimeData *qm = new QMimeData();
|
||||
qm->setHtml(QString::fromStdString((settings->v_result[i1][i2])));
|
||||
qm->setText(QString::fromStdString(unformat(unhtmlize((settings->v_result[i1][i2])))));
|
||||
qm->setHtml(QString::fromStdString(settings->v_result[i1][i2]));
|
||||
qm->setText(QString::fromStdString(unhtmlize((settings->v_result[i1][i2]))));
|
||||
qm->setObjectName("history_result");
|
||||
QApplication::clipboard()->setMimeData(qm);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void HistoryView::editCopyAscii() {
|
||||
editCopy(1);
|
||||
}
|
||||
void HistoryView::editCopyFormatted() {
|
||||
editCopy(0);
|
||||
}
|
||||
void HistoryView::editInsertValue() {
|
||||
int i1 = -1, i2 = -1, i3 = -1;
|
||||
indexAtPos(context_pos, &i1, &i2, &i3);
|
||||
|
@ -43,7 +43,7 @@ class HistoryView : public QTextEdit {
|
||||
QString s_text;
|
||||
int i_pos;
|
||||
QMenu *cmenu;
|
||||
QAction *insertTextAction, *insertValueAction, *copyAction, *selectAllAction, *delAction, *clearAction, *findAction, *protectAction, *movetotopAction;
|
||||
QAction *insertTextAction, *insertValueAction, *copyAction, *copyFormattedAction, *copyAsciiAction, *selectAllAction, *delAction, *clearAction, *findAction, *protectAction, *movetotopAction;
|
||||
QColor prev_color;
|
||||
QPoint context_pos;
|
||||
QLineEdit *searchEdit;
|
||||
@ -66,7 +66,9 @@ class HistoryView : public QTextEdit {
|
||||
|
||||
void editInsertValue();
|
||||
void editInsertText();
|
||||
void editCopy();
|
||||
void editCopy(int = -1);
|
||||
void editCopyFormatted();
|
||||
void editCopyAscii();
|
||||
void editClear();
|
||||
void editRemove();
|
||||
void editProtect();
|
||||
|
@ -61,6 +61,8 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) : QDialog(parent) {
|
||||
BOX_G(tr("Ignore system language (requires restart)"), settings->ignore_locale, ignoreLocaleToggled(bool));
|
||||
BOX_G(tr("Allow multiple instances"), settings->allow_multiple_instances > 0, multipleInstancesToggled(bool));
|
||||
BOX_G(tr("Clear history on exit"), settings->clear_history_on_exit, clearHistoryToggled(bool));
|
||||
BOX_G(tr("Use keyboard keys for RPN"), settings->rpn_keys, rpnKeysToggled(bool));
|
||||
BOX_G(tr("Use caret for bitwise XOR"), settings->caret_as_xor, caretAsXorToggled(bool));
|
||||
BOX_G(tr("Keep above other windows"), settings->always_on_top, keepAboveToggled(bool));
|
||||
l2->addWidget(new QLabel(tr("Window title:"), this), r, 0);
|
||||
combo = new QComboBox(this);
|
||||
@ -128,7 +130,6 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) : QDialog(parent) {
|
||||
combo->setCurrentIndex(combo->findData(settings->replace_expression));
|
||||
connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(replaceExpressionChanged(int)));
|
||||
l2->addWidget(combo, r, 1); r++;
|
||||
BOX_G(tr("Use keyboard keys for RPN"), settings->rpn_keys, rpnKeysToggled(bool));
|
||||
l2->addWidget(new QLabel(tr("Parsing mode:"), this), r, 0);
|
||||
combo = new QComboBox(this);
|
||||
combo->addItem(tr("Adaptive"), PARSING_MODE_ADAPTIVE);
|
||||
@ -168,6 +169,7 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) : QDialog(parent) {
|
||||
BOX(tr("Indicate repeating decimals"), settings->printops.indicate_infinite_series, repeatingDecimalsToggled(bool));
|
||||
if(CALCULATOR->getDecimalPoint() == COMMA) ignoreCommaBox->hide();
|
||||
if(CALCULATOR->getDecimalPoint() == DOT) ignoreDotBox->hide();
|
||||
BOX(tr("Copy result as unformatted ASCII by default"), settings->copy_ascii, copyAsciiToggled(bool));
|
||||
l2 = new QGridLayout();
|
||||
r = 0;
|
||||
l2->addWidget(new QLabel(tr("Digit grouping:"), this), r, 0);
|
||||
@ -438,6 +440,12 @@ void PreferencesDialog::repeatingDecimalsToggled(bool b) {
|
||||
settings->printops.indicate_infinite_series = b;
|
||||
emit resultFormatUpdated();
|
||||
}
|
||||
void PreferencesDialog::copyAsciiToggled(bool b) {
|
||||
settings->copy_ascii = b;
|
||||
}
|
||||
void PreferencesDialog::caretAsXorToggled(bool b) {
|
||||
settings->caret_as_xor = b;
|
||||
}
|
||||
void PreferencesDialog::mixedUnitsToggled(bool b) {
|
||||
if(b) settings->evalops.mixed_units_conversion = MIXED_UNITS_CONVERSION_DEFAULT;
|
||||
else settings->evalops.mixed_units_conversion = MIXED_UNITS_CONVERSION_NONE;
|
||||
|
@ -88,6 +88,8 @@ class PreferencesDialog : public QDialog {
|
||||
void multipleInstancesToggled(bool);
|
||||
void clearHistoryToggled(bool);
|
||||
void historyExpressionChanged(int);
|
||||
void copyAsciiToggled(bool);
|
||||
void caretAsXorToggled(bool);
|
||||
|
||||
public:
|
||||
|
||||
|
@ -618,6 +618,8 @@ void QalculateQtSettings::readPreferenceValue(const std::string &svar, const std
|
||||
printops.spell_out_logical_operators = v;
|
||||
} else if(svar == "caret_as_xor") {
|
||||
caret_as_xor = v;
|
||||
} else if(svar == "copy_ascii") {
|
||||
copy_ascii = v;
|
||||
} else if(svar == "decimal_comma") {
|
||||
decimal_comma = v;
|
||||
if(v == 0) CALCULATOR->useDecimalPoint(evalops.parse_options.comma_as_separator);
|
||||
@ -738,6 +740,7 @@ void QalculateQtSettings::loadPreferences() {
|
||||
rpn_keys = true;
|
||||
rpn_shown = false;
|
||||
caret_as_xor = false;
|
||||
copy_ascii = false;
|
||||
do_imaginary_j = false;
|
||||
simplified_percentage = true;
|
||||
color = 1;
|
||||
@ -1202,6 +1205,7 @@ bool QalculateQtSettings::savePreferences(const char *filename, bool is_workspac
|
||||
if(default_signed >= 0) fprintf(file, "signed_integer=%i\n", default_signed);
|
||||
fprintf(file, "spell_out_logical_operators=%i\n", printops.spell_out_logical_operators);
|
||||
fprintf(file, "caret_as_xor=%i\n", caret_as_xor);
|
||||
fprintf(file, "copy_ascii=%i\n", copy_ascii);
|
||||
fprintf(file, "digit_grouping=%i\n", printops.digit_grouping);
|
||||
fprintf(file, "decimal_comma=%i\n", decimal_comma);
|
||||
fprintf(file, "dot_as_separator=%i\n", dot_question_asked ? evalops.parse_options.dot_as_separator : -1);
|
||||
|
@ -29,11 +29,13 @@ bool can_display_unicode_string_function(const char *str, void *w);
|
||||
#define LOAD_APP_ICON(x) QIcon(":/icons/apps/scalable/" x ".svg")
|
||||
#define LOAD_ICON(x) load_icon(x, this)
|
||||
|
||||
#define USE_QUOTES(arg, f) (arg && (arg->suggestsQuotes() || arg->type() == ARGUMENT_TYPE_TEXT) && f->id() != FUNCTION_ID_BASE && f->id() != FUNCTION_ID_BIN && f->id() != FUNCTION_ID_OCT && f->id() != FUNCTION_ID_DEC && f->id() != FUNCTION_ID_HEX)
|
||||
|
||||
std::string to_html_escaped(const std::string str);
|
||||
std::string unhtmlize(std::string str);
|
||||
QString unhtmlize(QString str);
|
||||
std::string unformat(std::string str);
|
||||
QString unformat(QString str);
|
||||
std::string replace_first_minus(const std::string &str);
|
||||
QIcon load_icon(const QString &str, QWidget*);
|
||||
bool last_is_operator(std::string str, bool allow_exp = false);
|
||||
bool string_is_less(std::string str1, std::string str2);
|
||||
@ -229,6 +231,7 @@ class QalculateQtSettings : QObject {
|
||||
bool rpn_shown;
|
||||
bool auto_calculate;
|
||||
int history_expression_type;
|
||||
bool copy_ascii;
|
||||
std::string custom_result_font, custom_expression_font, custom_keypad_font, custom_app_font;
|
||||
KnownVariable *vans[5], *v_memory;
|
||||
MathStructure *current_result;
|
||||
|
@ -232,6 +232,7 @@ std::string unhtmlize(std::string str) {
|
||||
gsub(" ", "", str);
|
||||
gsub(" ", " ", str);
|
||||
gsub(" ", THIN_SPACE, str);
|
||||
gsub(" ", NNBSP, str);
|
||||
return str;
|
||||
}
|
||||
|
||||
@ -1216,12 +1217,16 @@ void QalculateWindow::triggerShortcut(int type, const std::string &value) {
|
||||
}
|
||||
case SHORTCUT_TYPE_COPY_RESULT: {
|
||||
if(!settings->v_result.empty()) {
|
||||
if(settings->copy_ascii) {
|
||||
QApplication::clipboard()->setText(QString::fromStdString(unformat(unhtmlize(settings->v_result[settings->v_result.size() - 1][0]))));
|
||||
} else {
|
||||
QMimeData *qm = new QMimeData();
|
||||
qm->setHtml(QString::fromStdString(settings->v_result[settings->v_result.size() - 1][0]));
|
||||
qm->setText(QString::fromStdString(unformat(unhtmlize(settings->v_result[settings->v_result.size() - 1][0]))));
|
||||
qm->setText(QString::fromStdString(unhtmlize(settings->v_result[settings->v_result.size() - 1][0])));
|
||||
qm->setObjectName("history_result");
|
||||
QApplication::clipboard()->setMimeData(qm);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SHORTCUT_TYPE_INSERT_RESULT: {
|
||||
@ -1623,7 +1628,7 @@ void QalculateWindow::onFunctionClicked(MathFunction *f) {
|
||||
return;
|
||||
}
|
||||
QString sargs;
|
||||
bool b_text = (f->getArgumentDefinition(1) && f->getArgumentDefinition(1)->type() == ARGUMENT_TYPE_TEXT);
|
||||
bool b_text = USE_QUOTES(f->getArgumentDefinition(1), f);
|
||||
if(f->id() == FUNCTION_ID_CIRCULAR_SHIFT || f->id() == FUNCTION_ID_BIT_CMP) {
|
||||
Argument *arg_bits = f->getArgumentDefinition(f->id() == FUNCTION_ID_CIRCULAR_SHIFT ? 3 : 2);
|
||||
Argument *arg_steps = (f->id() == FUNCTION_ID_CIRCULAR_SHIFT ? f->getArgumentDefinition(2) : NULL);
|
||||
@ -4605,13 +4610,21 @@ void QalculateWindow::onExpressionChanged() {
|
||||
std::string ellipsize_result(const std::string &result_text, size_t length) {
|
||||
length /= 2;
|
||||
size_t index1 = result_text.find(SPACE, length);
|
||||
if(index1 == std::string::npos || index1 > length * 1.2) index1 = result_text.find(THIN_SPACE, length);
|
||||
if(index1 == std::string::npos || index1 > length * 1.2) {
|
||||
index1 = result_text.find(THIN_SPACE, length);
|
||||
size_t index1b = result_text.find(NNBSP, length);
|
||||
if(index1b != std::string::npos && (index1 == std::string::npos || index1b < index1)) index1 = index1b;
|
||||
}
|
||||
if(index1 == std::string::npos || index1 > length * 1.2) {
|
||||
index1 = length;
|
||||
while(index1 > 0 && (signed char) result_text[index1] < 0 && (unsigned char) result_text[index1 + 1] < 0xC0) index1--;
|
||||
}
|
||||
size_t index2 = result_text.find(SPACE, result_text.length() - length);
|
||||
if(index2 == std::string::npos || index2 > result_text.length() - length * 0.8) index2 = result_text.find(THIN_SPACE, result_text.length() - length);
|
||||
if(index2 == std::string::npos || index2 > result_text.length() - length * 0.8) {
|
||||
index2 = result_text.find(THIN_SPACE, result_text.length() - length);
|
||||
size_t index2b = result_text.find(NNBSP, result_text.length() - length);
|
||||
if(index2b != std::string::npos && (index2 == std::string::npos || index2b < index2)) index2 = index2b;
|
||||
}
|
||||
if(index2 == std::string::npos || index2 > result_text.length() - length * 0.8) {
|
||||
index2 = result_text.length() - length;
|
||||
while(index2 > index1 && (signed char) result_text[index2] < 0 && (unsigned char) result_text[index2 + 1] < 0xC0) index2--;
|
||||
@ -6574,7 +6587,7 @@ void QalculateWindow::insertFunction(MathFunction *f, QWidget *parent) {
|
||||
typestr = "";
|
||||
ParseOptions pa = settings->evalops.parse_options; pa.base = 10;
|
||||
defstr = QString::fromStdString(CALCULATOR->localizeExpression(f->getDefaultValue(i + 1), pa));
|
||||
if(arg && (arg->suggestsQuotes() || arg->type() == ARGUMENT_TYPE_TEXT) && defstr.length() >= 2 && defstr[0] == '\"' && defstr[defstr.length() - 1] == '\"') {
|
||||
if(USE_QUOTES(arg, f) && defstr.length() >= 2 && defstr[0] == '\"' && defstr[defstr.length() - 1] == '\"') {
|
||||
defstr = defstr.mid(1, defstr.length() - 2);
|
||||
}
|
||||
fd->label[i] = new QLabel(tr("%1:").arg(argstr));
|
||||
@ -6707,6 +6720,8 @@ void QalculateWindow::insertFunction(MathFunction *f, QWidget *parent) {
|
||||
combo->addItem("persian");
|
||||
fd->entry[i] = combo->lineEdit();
|
||||
entry = combo;
|
||||
} else if(USE_QUOTES(arg, f)) {
|
||||
fd->entry[i] = new QLineEdit();
|
||||
} else {
|
||||
fd->entry[i] = new MathLineEdit();
|
||||
}
|
||||
@ -6936,7 +6951,7 @@ void QalculateWindow::insertFunctionDo(FunctionDialog *fd) {
|
||||
str2 = ((QLineEdit*) fd->entry[argcount - 1])->text().toStdString();
|
||||
remove_blank_ends(str2);
|
||||
}
|
||||
if(!str2.empty() && f->getArgumentDefinition(argcount) && (f->getArgumentDefinition(argcount)->suggestsQuotes() || (f->getArgumentDefinition(argcount)->type() == ARGUMENT_TYPE_TEXT && str2.find(CALCULATOR->getComma()) == std::string::npos))) {
|
||||
if(!str2.empty() && USE_QUOTES(f->getArgumentDefinition(argcount), f) && str2.find(CALCULATOR->getComma()) == std::string::npos) {
|
||||
if(str2.length() < 1 || (str2[0] != '\"' && str[0] != '\'')) {
|
||||
str2.insert(0, "\"");
|
||||
str2 += "\"";
|
||||
@ -6975,7 +6990,7 @@ void QalculateWindow::insertFunctionDo(FunctionDialog *fd) {
|
||||
str2 = ((QLineEdit*) fd->entry[i])->text().toStdString();
|
||||
remove_blank_ends(str2);
|
||||
}
|
||||
if((i < f->minargs() || !str2.empty()) && f->getArgumentDefinition(i + 1) && (f->getArgumentDefinition(i + 1)->suggestsQuotes() || (f->getArgumentDefinition(i + 1)->type() == ARGUMENT_TYPE_TEXT && str2.find(CALCULATOR->getComma()) == std::string::npos))) {
|
||||
if((i < f->minargs() || !str2.empty()) && USE_QUOTES(f->getArgumentDefinition(i + 1), f) && str2.find(CALCULATOR->getComma()) == std::string::npos) {
|
||||
if(str2.length() < 1 || (str2[0] != '\"' && str[0] != '\'')) {
|
||||
str2.insert(0, "\"");
|
||||
str2 += "\"";
|
||||
|
Loading…
x
Reference in New Issue
Block a user