runners/calculator: Improve output base handling
Reimplement krunner base conversion through libqalculate
PrintOptions.base instead of parsing decimal output and converting it to hex.
This approach allows for correct display of multiple solutions
converted to different base, for example:
hex= x * x = 4
will output x = 0x2 || x = -0x2
.
Also, this makes it possible to easily implement more bases like
bin, oct, time, roman, etc.
To detect required base findPrefix function was implemented in QalculateEngine,
this function checks are there any common bases like hex, oct, bin,
roman, time, pi and if there is it sets PrintOptions.base to corresponding base,
this common base mappings were taken from libqalculate/src/qalc.cc
set_option function (lines from 747 to 776, libqalcualate commit d767c71).
To handle non-common bases prefix base was implemented, examples:
base 42=64
results to 1M
, base 2**16=123456789
results to \1883\52501
.
When findPrefix function encounters base keyword in prefix,
it sets base to BASE_CUSTOM, then at QalculateEngine::evaluate
if base is set to BASE_CUSTOM everything in prefix after base keyword
is calculated and set as custom base for main calculation via
CALCULATOR->setCustomOutputBase.