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

David Johnson david at usermode.org
Thu Jan 29 22:41:19 CET 2009


SVN commit 918364 by brandybuck:

GUI:
FEATURE:
BUG: 123983
Make button font configurable. User can now set button and display fonts in the
Font page of the Configure dialog.


 M  +63 -6     fonts.ui  
 M  +59 -29    kcalc.cpp  
 M  +18 -18    kcalc.h  
 M  +5 -1      kcalc.kcfg  
 M  +8 -0      kcalc_button.cpp  
 M  +1 -0      kcalc_button.h  
 M  +2 -1      kcalcdisplay.cpp  
 M  +4 -0      kcalcrc.upd  


--- trunk/KDE/kdeutils/kcalc/fonts.ui #918363:918364
@@ -5,24 +5,81 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>469</width>
-    <height>365</height>
+    <width>288</width>
+    <height>74</height>
    </rect>
   </property>
   <property name="windowTitle" >
    <string>Fonts</string>
   </property>
-  <layout class="QHBoxLayout" name="horizontalLayout" >
+  <layout class="QVBoxLayout" name="verticalLayout" >
    <item>
-    <widget class="KFontChooser" name="kcfg_Font" />
+    <layout class="QFormLayout" name="formLayout" >
+     <property name="fieldGrowthPolicy" >
+      <enum>QFormLayout::ExpandingFieldsGrow</enum>
+     </property>
+     <item row="0" column="0" >
+      <widget class="QLabel" name="buttonlabel" >
+       <property name="text" >
+        <string>&amp;Button font</string>
+       </property>
+       <property name="buddy" >
+        <cstring>kcfg_ButtonFont</cstring>
+       </property>
+      </widget>
+     </item>
+     <item row="0" column="1" >
+      <widget class="KFontRequester" name="kcfg_ButtonFont" >
+       <property name="focusPolicy" >
+        <enum>Qt::WheelFocus</enum>
+       </property>
+       <property name="toolTip" >
+        <string>The font to use for the buttons</string>
+       </property>
+      </widget>
+     </item>
+     <item row="1" column="0" >
+      <widget class="QLabel" name="displaylabel" >
+       <property name="text" >
+        <string>&amp;Display font</string>
+       </property>
+       <property name="buddy" >
+        <cstring>kcfg_DisplayFont</cstring>
+       </property>
+      </widget>
+     </item>
+     <item row="1" column="1" >
+      <widget class="KFontRequester" name="kcfg_DisplayFont" >
+       <property name="focusPolicy" >
+        <enum>Qt::WheelFocus</enum>
+       </property>
+       <property name="toolTip" >
+        <string>The font to use in the display</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
    </item>
+   <item>
+    <spacer name="verticalSpacer" >
+     <property name="orientation" >
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0" >
+      <size>
+       <width>20</width>
+       <height>0</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
   </layout>
  </widget>
  <customwidgets>
   <customwidget>
-   <class>KFontChooser</class>
+   <class>KFontRequester</class>
    <extends>QWidget</extends>
-   <header>kfontdialog.h</header>
+   <header>kfontrequester.h</header>
   </customwidget>
  </customwidgets>
  <resources/>
--- trunk/KDE/kdeutils/kcalc/kcalc.cpp #918363:918364
@@ -1,4 +1,4 @@
-// -*- indent-tabs-mode: t -*-
+// -*- indent-tabs-mode: nil -*-
 /*
     kCalculator, a simple scientific calculator for KDE
 
@@ -124,14 +124,15 @@
 
 	// misc setup
 
-	set_colors();
+	setColors();
+	setFonts();
 
 	// Show the result in the app's caption in taskbar (wishlist - bug #52858)
 	if (KCalcSettings::captionResult() == true)
 		connect(calc_display, SIGNAL(changedText(const QString &)),
 				SLOT(setCaption(const QString &)));
 	calc_display->changeSettings();
-	set_precision();
+	setPrecision();
 
 	resetBase(); // switch to decimal
 
@@ -161,7 +162,9 @@
 	// connections
 
 	connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()),
-			SLOT(set_colors()));
+			SLOT(setColors()));
+	connect(KGlobalSettings::self(), SIGNAL(kdisplayFontChanged()),
+			SLOT(setFonts()));
 
 	calc_display->setFocus();
 }
@@ -733,39 +736,41 @@
 
 void KCalculator::updateGeometry(void)
 {
-    QWidget *widget;
+    KCalcButton *button;
     QSize em = pbAND->fontMetrics().size(0, "M");
     int margin =
-		QApplication::style()->pixelMetric(QStyle::PM_ButtonMargin, 0, 0);
+        QApplication::style()->pixelMetric(QStyle::PM_ButtonMargin, 0, 0);
     margin = qMax(qMin(margin/2, 3), 3);
 
-	// left pad
+    // left pad
 
-	foreach (QObject *obj, leftPad->children()) {
-        if ( obj->isWidgetType() ) {
-            widget = static_cast<QWidget*>(obj);
-            widget->setFixedWidth(em.width()*4 + margin*2);
-            widget->installEventFilter( this );
+    foreach (QObject *obj, leftPad->children()) {
+        button = qobject_cast<KCalcButton*>(obj);
+        if ( button ) {
+            button->setFixedWidth(em.width()*4 + margin*2);
+            button->installEventFilter( this );
         }
     }
 
-	// right pad
+    // right pad
 
-	foreach (QObject *obj, rightPad->children()) {
-        if (obj->isWidgetType()) {
-            widget = static_cast<QWidget*>(obj);
-            widget->setFixedWidth(em.width()*3 + margin*2);
-            widget->installEventFilter(this);
+    foreach (QObject *obj, rightPad->children()) {
+        button = qobject_cast<KCalcButton*>(obj);
+        if ( button ) {
+            button->setFixedWidth(em.width()*3 + margin*2);
+            button->installEventFilter(this);
         }
     }
 
-	foreach (QObject *obj, numericPad->children()) {
-        if (obj->isWidgetType()) {
-            widget = static_cast<QWidget *>(obj);
-			if (widget != pb0) { // let pb0 expand freely
-				widget->setFixedWidth(em.width()*3 + margin*2);
-			}
-            widget->installEventFilter(this);
+    // numeric pad
+
+    foreach (QObject *obj, numericPad->children()) {
+        button = qobject_cast<KCalcButton*>(obj);
+        if ( button ) {
+	    if (button != pb0) { // let pb0 expand freely
+		button->setFixedWidth(em.width()*3 + margin*2);
+	    }
+            button->installEventFilter(this);
         }
     }
 }
@@ -1739,8 +1744,9 @@
 void KCalculator::updateSettings()
 {
 	changeButtonNames();
-	set_colors();
-	set_precision();
+	setColors();
+	setFonts();
+	setPrecision();
 	// Show the result in the app's caption in taskbar (wishlist - bug #52858)
 	disconnect(calc_display, SIGNAL(changedText(const QString &)),
 		   this, 0);
@@ -1775,7 +1781,7 @@
 
 }
 
-void KCalculator::set_colors()
+void KCalculator::setColors()
 {
 	calc_display->changeSettings();
 
@@ -1818,8 +1824,32 @@
 	}
 }
 
-void KCalculator::set_precision()
+void KCalculator::setFonts()
 {
+    KCalcButton *button;
+    foreach (QObject *obj, leftPad->children()) {
+	button = qobject_cast<KCalcButton*>(obj);
+        if (button) {
+            button->setFont(KCalcSettings::buttonFont());
+        }
+    }
+    foreach (QObject *obj, numericPad->children()) {
+	button = qobject_cast<KCalcButton*>(obj);
+        if (button) {
+            button->setFont(KCalcSettings::buttonFont());
+        }
+    }
+    foreach (QObject *obj, rightPad->children()) {
+	button = qobject_cast<KCalcButton*>(obj);
+        if (button) {
+            button->setFont(KCalcSettings::buttonFont());
+        }
+    }
+    updateGeometry();
+}
+
+void KCalculator::setPrecision()
+{
 	KNumber:: setDefaultFloatPrecision(KCalcSettings::precision());
 	updateDisplay(false);
 }
--- trunk/KDE/kdeutils/kcalc/kcalc.h #918363:918364
@@ -100,33 +100,33 @@
     Q_OBJECT
 
 public:
-	KCalculator(QWidget *parent = 0);
-	~KCalculator();
+    KCalculator(QWidget *parent = 0);
+    ~KCalculator();
 
 signals:
-	void switchInverse(bool);
-	void switchMode(ButtonModeFlags,bool);
-	void switchShowAccels(bool);
+    void switchInverse(bool);
+    void switchMode(ButtonModeFlags,bool);
+    void switchShowAccels(bool);
 
 private:
-	virtual bool eventFilter( QObject *o, QEvent *e );
-	void updateGeometry();
-	void setupMainActions(void);
-	void setupStatusbar(void);
-	void setupKeys();
-	void keyPressEvent(QKeyEvent *e);
-	void keyReleaseEvent(QKeyEvent *e);
-	void set_precision();
-	void set_style();
-	void resetBase(void) { decRadio->animateClick(); }
+    virtual bool eventFilter( QObject *o, QEvent *e );
+    void updateGeometry();
+    void setupMainActions(void);
+    void setupStatusbar(void);
+    void setupKeys();
+    void keyPressEvent(QKeyEvent *e);
+    void keyReleaseEvent(QKeyEvent *e);
+    void setPrecision();
+    void resetBase(void) { decRadio->animateClick(); }
 
-	void updateDisplay(bool get_amount_from_core = false,
-			   bool store_result_in_history = false);
+    void updateDisplay(bool get_amount_from_core = false,
+                       bool store_result_in_history = false);
 
 protected slots:
     void changeButtonNames();
     void updateSettings();
-    void set_colors();
+    void setColors();
+    void setFonts();
     void EnterEqual();
     void showSettings();
     void slotStatshow(bool toggled);
--- trunk/KDE/kdeutils/kcalc/kcalc.kcfg #918363:918364
@@ -47,7 +47,11 @@
     </entry>
   </group>
   <group name="Font">
-    <entry name="Font" type="Font">
+    <entry name="ButtonFont" type="Font">
+      <label>The font to use for the buttons.</label>
+      <default code="true">KGlobalSettings::generalFont()</default>
+    </entry>
+    <entry name="DisplayFont" type="Font">
       <label>The font to use in the display.</label>
       <default code="true">QFont(KGlobalSettings::generalFont().family(), 14, QFont::Bold)</default>
     </entry>
--- trunk/KDE/kdeutils/kcalc/kcalc_button.cpp #918363:918364
@@ -135,6 +135,7 @@
 	QTextDocument doc;
 	QAbstractTextDocumentLayout::PaintContext context;
 	doc.setHtml("<center>" + text() + "</center>");
+	doc.setDefaultFont(font());
 	context.palette = palette();
         context.palette.setColor(QPalette::Text, context.palette.buttonText().color());
 
@@ -178,6 +179,13 @@
 	_size = _size.expandedTo(QApplication::globalStrut());
 }
 
+void KCalcButton::setFont(const QFont &fnt)
+{
+    KPushButton::setFont(fnt);
+
+    calcSizeHint();
+}
+
 void KCalcButton::setText(const QString &text)
 {
 	KPushButton::setText(text);
--- trunk/KDE/kdeutils/kcalc/kcalc_button.h #918363:918364
@@ -67,6 +67,7 @@
 
  virtual QSize sizeHint() const; // reimp
 
+ void setFont(const QFont &fnt);
  void setText(const QString &text); // reimp
  void setToolTip(const QString &tip); // reimp
 
--- trunk/KDE/kdeutils/kcalc/kcalcdisplay.cpp #918363:918364
@@ -82,7 +82,7 @@
 
 	setPalette(pal);
 
-	setFont(KCalcSettings::font());
+	setFont(KCalcSettings::displayFont());
 
 	setPrecision(KCalcSettings::precision());
 
@@ -465,6 +465,7 @@
     }
 
     switch(_num_base) {
+        // TODO: use QString:::toULongLong() instead of STRTOUL
       case NB_BINARY:
           Q_ASSERT(_period == false  && _eestate == false);
           setText(tmp_string);
--- trunk/KDE/kdeutils/kcalc/kcalcrc.upd #918363:918364
@@ -2,3 +2,7 @@
 File=kcalcrc
 Group=General
 Key=style,Statistical
+Id=KDE_4_3_0
+File=kcalcrc
+Group=Font
+Key=Font,DisplayFont



More information about the kde-doc-english mailing list