[kde-doc-english] KDE/kdeutils/kcalc

David Johnson david at usermode.org
Sun Feb 1 07:25:22 CET 2009


SVN commit 919487 by brandybuck:

GUI:
FEATURE:
Add configure option to display two's complement or not for non-decimal numbers.



 M  +64 -13    general.ui  
 M  +9 -0      kcalc.kcfg  
 M  +25 -8     kcalcdisplay.cpp  
 M  +2 -0      kcalcdisplay.h  


--- trunk/KDE/kdeutils/kcalc/general.ui #919486:919487
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>300</width>
-    <height>268</height>
+    <width>293</width>
+    <height>319</height>
    </rect>
   </property>
   <property name="windowTitle" >
@@ -35,10 +35,20 @@
          </widget>
         </item>
         <item row="0" column="1" >
-         <widget class="QSpinBox" name="kcfg_Precision" />
+         <widget class="QSpinBox" name="kcfg_Precision" >
+          <property name="toolTip" >
+           <string>Maximum number of digits displayed</string>
+          </property>
+          <property name="whatsThis" >
+           <string>KCalc can compute with many more digits than the number that fits on the display. This setting gives the maximum number of digits displayed, before KCalc starts using scientific notation, i.e. notation of the type 2.34e12.</string>
+          </property>
+         </widget>
         </item>
         <item row="1" column="0" >
          <widget class="QCheckBox" name="kcfg_Fixed" >
+          <property name="toolTip" >
+           <string>Whether to use fixed decimal places</string>
+          </property>
           <property name="text" >
            <string>Set &amp;decimal precision</string>
           </property>
@@ -49,6 +59,9 @@
           <property name="enabled" >
            <bool>false</bool>
           </property>
+          <property name="toolTip" >
+           <string>Number of fixed decimal digits</string>
+          </property>
          </widget>
         </item>
        </layout>
@@ -58,7 +71,7 @@
         <property name="orientation" >
          <enum>Qt::Horizontal</enum>
         </property>
-        <property name="sizeHint" >
+        <property name="sizeHint" stdset="0" >
          <size>
           <width>40</width>
           <height>20</height>
@@ -70,6 +83,44 @@
     </widget>
    </item>
    <item>
+    <widget class="QGroupBox" name="groupBox" >
+     <property name="title" >
+      <string>Numbers</string>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout" >
+      <item>
+       <widget class="QCheckBox" name="kcfg_GroupDigits" >
+        <property name="toolTip" >
+         <string>Whether to group digits</string>
+        </property>
+        <property name="text" >
+         <string>Group digits</string>
+        </property>
+        <property name="checked" >
+         <bool>true</bool>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QCheckBox" name="kcfg_TwosComplement" >
+        <property name="toolTip" >
+         <string>Whether to use Two's Complement for non-decimal numbers</string>
+        </property>
+        <property name="whatsThis" >
+         <string>Select to use Two's Complement notation for Binary, Octal and Hexidecimal numbers. This is a common notation to represent negative numbers for non-decimal numbers in computers.</string>
+        </property>
+        <property name="text" >
+         <string>Two's Complement</string>
+        </property>
+        <property name="checked" >
+         <bool>true</bool>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
     <widget class="QGroupBox" name="miscGroupBox" >
      <property name="title" >
       <string>Misc</string>
@@ -77,6 +128,9 @@
      <layout class="QVBoxLayout" >
       <item>
        <widget class="QCheckBox" name="kcfg_Beep" >
+        <property name="toolTip" >
+         <string>Whether to beep on error</string>
+        </property>
         <property name="text" >
          <string>&amp;Beep on error</string>
         </property>
@@ -87,18 +141,14 @@
       </item>
       <item>
        <widget class="QCheckBox" name="kcfg_CaptionResult" >
+        <property name="toolTip" >
+         <string>Whether to show the result in the window title</string>
+        </property>
         <property name="text" >
          <string>Show &amp;result in window title</string>
         </property>
        </widget>
       </item>
-      <item>
-       <widget class="QCheckBox" name="kcfg_GroupDigits" >
-        <property name="text" >
-         <string>Group digits</string>
-        </property>
-       </widget>
-      </item>
      </layout>
     </widget>
    </item>
@@ -110,7 +160,7 @@
      <property name="sizeType" >
       <enum>QSizePolicy::Expanding</enum>
      </property>
-     <property name="sizeHint" >
+     <property name="sizeHint" stdset="0" >
       <size>
        <width>282</width>
        <height>31</height>
@@ -126,9 +176,10 @@
   <tabstop>kcfg_Precision</tabstop>
   <tabstop>kcfg_Fixed</tabstop>
   <tabstop>kcfg_FixedPrecision</tabstop>
+  <tabstop>kcfg_GroupDigits</tabstop>
+  <tabstop>kcfg_TwosComplement</tabstop>
   <tabstop>kcfg_Beep</tabstop>
   <tabstop>kcfg_CaptionResult</tabstop>
-  <tabstop>kcfg_GroupDigits</tabstop>
  </tabstops>
  <resources/>
  <connections>
--- trunk/KDE/kdeutils/kcalc/kcalc.kcfg #919486:919487
@@ -91,6 +91,15 @@
       <label>Whether to group digits.</label>
       <default>true</default>
     </entry>
+    <entry name="TwosComplement" type="Bool" key="twoscomplement">
+      <label>Whether to use Two's Complement for non-decimal numbers.</label>
+      <whatsthis>
+        Select to use Two's Complement notation for Binary, Octal
+        and Hexidecimal numbers. This is a common notation to represent
+        negative numbers in computers.
+      </whatsthis>
+      <default>true</default>
+    </entry>
     <entry name="ShowBitset" type="Bool">
       <label>Whether to show the bit edit widget.</label>
       <default>false</default>
--- trunk/KDE/kdeutils/kcalc/kcalcdisplay.cpp #919486:919487
@@ -45,9 +45,10 @@
 #include "kcalcdisplay.moc"
 
 KCalcDisplay::KCalcDisplay(QWidget *parent)
-    :QFrame(parent), _beep(false), _groupdigits(false), _button(0),
-     _lit(false), _num_base(NB_DECIMAL), _precision(9), _fixed_precision(-1),
-     _display_amount(0), _history_index(0), _selection_timer(new QTimer)
+    :QFrame(parent), _beep(false), _groupdigits(true), _twoscomplement(true),
+     _button(0), _lit(false), _num_base(NB_DECIMAL), _precision(9),
+     _fixed_precision(-1), _display_amount(0), _history_index(0),
+     _selection_timer(new QTimer)
 {
     setFocusPolicy(Qt::StrongFocus);
 
@@ -91,9 +92,10 @@
 	else
 		setFixedPrecision(KCalcSettings::fixedPrecision());
 
-	setBeep(KCalcSettings::beep());
-	setGroupDigits(KCalcSettings::groupDigits());
-	updateDisplay();
+    setBeep(KCalcSettings::beep());
+    setGroupDigits(KCalcSettings::groupDigits());
+    setTwosComplement(KCalcSettings::twosComplement());
+    updateDisplay();
 }
 
 void KCalcDisplay::updateFromCore(CalcEngine const &core,
@@ -351,6 +353,11 @@
     _groupdigits = flag;
 }
 
+void KCalcDisplay::setTwosComplement(bool flag)
+{
+    _twoscomplement = flag;
+}
+
 KNumber const & KCalcDisplay::getAmount(void) const
 {
     return _display_amount;
@@ -369,8 +376,18 @@
     if ((_num_base != NB_DECIMAL) &&
         (new_amount.type() != KNumber::SpecialType)) {
         _display_amount = new_amount.integerPart();
-        quint64 tmp_workaround = static_cast<quint64>(_display_amount);
-        display_str = QString::number(tmp_workaround, _num_base).toUpper();
+        if (_twoscomplement) {
+            // treat number as 64-bit unsigned
+            quint64 tmp_workaround = static_cast<quint64>(_display_amount);
+            display_str = QString::number(tmp_workaround, _num_base).toUpper();
+        } else {
+            // QString::number treats non-decimal as unsigned
+            qint64 tmp_workaround = static_cast<qint64>(_display_amount);
+            bool neg = tmp_workaround < 0;
+            if (neg) tmp_workaround = qAbs(tmp_workaround);
+            display_str = QString::number(tmp_workaround, _num_base).toUpper();
+            if (neg) display_str.prepend(KGlobal::locale()->negativeSign());
+        }
     } else {
         // _num_base == NB_DECIMAL || new_amount.type() == KNumber::SpecialType
         _display_amount = new_amount;
--- trunk/KDE/kdeutils/kcalc/kcalcdisplay.h #919486:919487
@@ -86,6 +86,7 @@
 	int setBase(NumBase new_base);
 	void setBeep(bool flag);
 	void setGroupDigits(bool flag);
+	void setTwosComplement(bool flag);
 	void setFixedPrecision(int precision);
 	void setPrecision(int precision);
 	void setText(QString const &string);
@@ -128,6 +129,7 @@
 	QString _text;
     bool _beep;
 	bool _groupdigits;
+	bool _twoscomplement;
 	int  _button;
 	bool _lit;
 	NumBase _num_base;



More information about the kde-doc-english mailing list