Commit 6ede51d1 authored by Antonio Prcela's avatar Antonio Prcela 🏞 Committed by Christoph Cullmann
Browse files

Add a display where the history of the calculations is stored

parent 5087035b
......@@ -96,7 +96,9 @@ target_sources(kcalc PRIVATE
kcalc_statusbar.cpp
stats.cpp
kcalc.qrc
)
kcalchistory.cpp
stats.cpp
kcalc.qrc )
ki18n_wrap_ui(kcalc
......
......@@ -94,6 +94,15 @@ buttons</link> and allows changing the numeral system.</action>
</para></listitem>
</varlistentry>
<varlistentry>
<term><menuchoice>
<guimenu>Settings</guimenu>
<guimenuitem>Show History</guimenuitem>
</menuchoice></term>
<listitem><para><action>Display the history.</action>
</para></listitem>
</varlistentry>
<varlistentry>
<term><menuchoice>
<guimenu>Settings</guimenu>
......
......@@ -178,6 +178,16 @@ the second layout of the buttons visible.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>History</term>
<listitem>
<para>The history area shows all the calculations done in &kcalc; for the active session of &kcalc;.
Click on <guibutton>AC</guibutton> or press the shortcut <keycap>Del</keycap> to clear the content of the history.
To activate or deactivate it, use the item <guilabel>Show History</guilabel> in the menu <guimenu>Settings</guimenu> of the
menu bar, or press <keycombo action="simul">&Ctrl;<keycap>H</keycap></keycombo>.</para>
</listitem>
</varlistentry>
</variablelist>
</sect1>
......
......@@ -55,6 +55,26 @@
</property>
</widget>
</item>
<item row="2" column="0" >
<widget class="QLabel" name="historylabel" >
<property name="text" >
<string>&amp;History font:</string>
</property>
<property name="buddy" >
<cstring>kcfg_HistoryFont</cstring>
</property>
</widget>
</item>
<item row="2" column="1" >
<widget class="KFontRequester" name="kcfg_HistoryFont" >
<property name="focusPolicy" >
<enum>Qt::WheelFocus</enum>
</property>
<property name="toolTip" >
<string>The font to use in the history</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
......
This diff is collapsed.
......@@ -141,6 +141,7 @@ private:
void setBase();
void updateDisplay(UpdateFlags flags);
void updateHistoryWithFunction(CalcEngine::Operation);
KCalcStatusBar *statusBar();
// button sets
......@@ -165,6 +166,7 @@ protected Q_SLOTS:
void slotSetStatisticMode();
void slotSetNumeralMode();
void slotHistoryshow(bool toggled);
void slotConstantsShow(bool toggled);
void slotBitsetshow(bool toggled);
void slotAngleSelected(QAbstractButton *button);
......@@ -240,6 +242,7 @@ private:
private:
bool shift_mode_ = false;
bool hyp_mode_ = false;
bool update_history_window_ = false;
KNumber memory_num_;
int angle_mode_; // angle modes for trigonometric values
......@@ -260,6 +263,7 @@ private:
std::array<QLabel *, 4> base_conversion_labels_;
KToggleAction *action_history_show_ = nullptr;
KToggleAction *action_bitset_show_ = nullptr;
KToggleAction *action_constants_show_ = nullptr;
......
......@@ -92,6 +92,10 @@
defaultDisplayFont.setPointSizeF(defaultDisplayFont.pointSizeF() * 1.4);</code>
<default code="true">defaultDisplayFont</default>
</entry>
<entry name="HistoryFont" type="Font">
<label>The font to use in the history.</label>
<default code="true">QFontDatabase::systemFont(QFontDatabase::GeneralFont)</default>
</entry>
</group>
<group name="Precision">
<entry name="Precision" type="UInt" key="precision">
......@@ -169,6 +173,10 @@
<label>Whether to show constant buttons.</label>
<default>false</default>
</entry>
<entry name="ShowHistory" type="Bool">
<label>Whether to show the history window.</label>
<default>false</default>
</entry>
<entry name="AngleMode" type="UInt">
<label>Degrees, radians or grads</label>
<default>0</default>
......
......@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>1084</width>
<width>1100</width>
<height>350</height>
</rect>
</property>
......@@ -112,7 +112,7 @@
</widget>
</item>
<item>
<widget class="KSqueezedTextLabel" name="hexDisplay" native="true">
<widget class="KSqueezedTextLabel" name="hexDisplay">
<property name="minimumSize">
<size>
<width>65</width>
......@@ -125,8 +125,8 @@
<height>16777215</height>
</size>
</property>
<property name="text" stdset="0">
<string>0</string>
<property name="text">
<string>KSq…bel</string>
</property>
</widget>
</item>
......@@ -148,7 +148,7 @@
</widget>
</item>
<item>
<widget class="KSqueezedTextLabel" name="decDisplay" native="true">
<widget class="KSqueezedTextLabel" name="decDisplay">
<property name="minimumSize">
<size>
<width>65</width>
......@@ -161,8 +161,8 @@
<height>16777215</height>
</size>
</property>
<property name="text" stdset="0">
<string>0</string>
<property name="text">
<string>KSq…bel</string>
</property>
</widget>
</item>
......@@ -184,7 +184,7 @@
</widget>
</item>
<item>
<widget class="KSqueezedTextLabel" name="octDisplay" native="true">
<widget class="KSqueezedTextLabel" name="octDisplay">
<property name="minimumSize">
<size>
<width>65</width>
......@@ -197,8 +197,8 @@
<height>16777215</height>
</size>
</property>
<property name="text" stdset="0">
<string>0</string>
<property name="text">
<string>KSq…bel</string>
</property>
</widget>
</item>
......@@ -220,7 +220,7 @@
</widget>
</item>
<item>
<widget class="KSqueezedTextLabel" name="binDisplay" native="true">
<widget class="KSqueezedTextLabel" name="binDisplay">
<property name="minimumSize">
<size>
<width>65</width>
......@@ -233,8 +233,8 @@
<height>16777215</height>
</size>
</property>
<property name="text" stdset="0">
<string>0</string>
<property name="text">
<string>KSq…bel</string>
</property>
</widget>
</item>
......@@ -1111,9 +1111,39 @@
</item>
</layout>
</item>
<item>
<widget class="KCalcHistory" name="calc_history">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::WheelFocus</enum>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KSqueezedTextLabel</class>
<extends>QLabel</extends>
<header>ksqueezedtextlabel.h</header>
</customwidget>
<customwidget>
<class>KCalcButton</class>
<extends>QPushButton</extends>
......@@ -1136,11 +1166,6 @@
<extends>QPushButton</extends>
<header>kcalc_const_button.h</header>
</customwidget>
<customwidget>
<class>KSqueezedTextLabel</class>
<extends>QWidget</extends>
<header>ksqueezedtextlabel.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>pb0</tabstop>
......@@ -1210,6 +1235,7 @@
<tabstop>radRadio</tabstop>
<tabstop>gradRadio</tabstop>
<tabstop>calc_display</tabstop>
<tabstop>calc_history</tabstop>
</tabstops>
<resources/>
<connections/>
......
......@@ -26,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "kcalc_core.h"
#include "kcalc_settings.h"
#include "kcalchistory.h"
#include <QDebug>
......
/*
* Copyright (c) 2021 Antonio Prcela <antonio.prcela@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kcalchistory.h"
#include "kcalc_settings.h"
//------------------------------------------------------------------------------
// Name: KCalcHistory
// Desc: constructor
//------------------------------------------------------------------------------
KCalcHistory::KCalcHistory(QWidget *parent) : QTextEdit(parent) {
setReadOnly(true);
setAlignment(Qt::AlignRight);
setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
}
//------------------------------------------------------------------------------
// Name: KCalcHistory
// Desc: destructor
//------------------------------------------------------------------------------
KCalcHistory::~KCalcHistory() {
}
//------------------------------------------------------------------------------
// Name: addToHistory
// Desc: Adds the latest calculations to the history window
//------------------------------------------------------------------------------
void KCalcHistory::addToHistory(const QString &str, bool new_lines_) {
setAlignment(Qt::AlignRight);
insertHtml(str);
if (new_lines_) {
insertHtml(QStringLiteral("<br>"));
}
ensureCursorVisible();
}
//------------------------------------------------------------------------------
// Name: addResultToHistory
// Desc: Used mostly for functions that are not in CalcEngine::Operation
// adds "=" and the result with newline endings
//------------------------------------------------------------------------------
void KCalcHistory::addResultToHistory(const QString &display_content) {
addToHistory(QStringLiteral(" = ") + display_content, true);
}
//------------------------------------------------------------------------------
// Name: addFuncToHistory
// Desc: Adds the current function symbol, taken via CalcEngine::Operation
// to the history window
//------------------------------------------------------------------------------
void KCalcHistory::addFuncToHistory(const CalcEngine::Operation FUNC) {
QString textToHistroy;
if (FUNC == CalcEngine::FUNC_PERCENT) {
textToHistroy = QStringLiteral(" % ");
} else if (FUNC == CalcEngine::FUNC_OR) {
textToHistroy = QStringLiteral(" OR ");
} else if (FUNC == CalcEngine::FUNC_XOR) {
textToHistroy = QStringLiteral(" XOR ");
} else if (FUNC == CalcEngine::FUNC_AND) {
textToHistroy = QStringLiteral(" AND ");
} else if (FUNC == CalcEngine::FUNC_LSH) {
textToHistroy = QStringLiteral(" Lsh ");
} else if (FUNC == CalcEngine::FUNC_RSH) {
textToHistroy = QStringLiteral(" Rsh ");
} else if (FUNC == CalcEngine::FUNC_ADD) {
textToHistroy = QStringLiteral(" + ");
} else if (FUNC == CalcEngine::FUNC_SUBTRACT) {
textToHistroy = QStringLiteral(" - ");
} else if (FUNC == CalcEngine::FUNC_MULTIPLY) {
textToHistroy = QStringLiteral(" × ");
} else if (FUNC == CalcEngine::FUNC_DIVIDE) {
textToHistroy = QStringLiteral(" ÷ ");
} else if (FUNC == CalcEngine::FUNC_MOD) {
textToHistroy = QStringLiteral(" Mod ");
} else if (FUNC == CalcEngine::FUNC_INTDIV) {
textToHistroy = QStringLiteral(" IntDiv ");
} else if (FUNC == CalcEngine::FUNC_BINOM) {
textToHistroy = QStringLiteral(" Binom ");
}
addToHistory(textToHistroy, false);
}
//------------------------------------------------------------------------------
// Name: addFuncToHistory
// Desc: Adds the current function symbol the history window
//------------------------------------------------------------------------------
void KCalcHistory::addFuncToHistory(const QString &func) {
addToHistory(func, false);
}
//------------------------------------------------------------------------------
// Name: clearHistory
// Desc: Clears the content of the history window
//------------------------------------------------------------------------------
void KCalcHistory::clearHistory() {
clear();
// somehow the alignment gets also reset, so we set it again
setAlignment(Qt::AlignRight);
}
void KCalcHistory::changeSettings() {
QPalette pal = palette();
pal.setColor(QPalette::Text, KCalcSettings::foreColor());
pal.setColor(QPalette::Base, KCalcSettings::backColor());
setPalette(pal);
setFont(KCalcSettings::historyFont());
}
/*
* Copyright (c) 2021 Antonio Prcela <antonio.prcela@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KCALC_HISTORY_H_
#define KCALC_HISTORY_H_
#include <QTextEdit>
#include "kcalc_core.h"
/*
This class provides a history display.
*/
class KCalcHistory : public QTextEdit {
Q_OBJECT
public:
explicit KCalcHistory(QWidget *parent = nullptr);
~KCalcHistory() override;
void addToHistory(const QString &, bool);
void addResultToHistory(const QString &);
void addFuncToHistory(const CalcEngine::Operation);
void addFuncToHistory(const QString &);
void changeSettings();
public Q_SLOTS:
void clearHistory();
};
#endif
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
<gui name="kcalc" version="20">
<gui name="kcalc" version="21">
<MenuBar>
<Menu name="settings" noMerge="1"><text>&amp;Settings</text>
<Action name="mode_simple"/>
......@@ -7,6 +7,7 @@
<Action name="mode_statistics"/>
<Action name="mode_numeral"/>
<Separator/>
<Action name="show_history"/>
<Action name="show_constants"/>
<Action name="show_bitset"/>
<Separator/>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment