[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kstars-devel
Subject:    Re: [Kstars-devel]
From:       Khudyakov Alexey <alexey.skladnoy () gmail ! com>
Date:       2009-03-06 16:08:10
Message-ID: 200903061908.10978.alexey.skladnoy () gmail ! com
[Download RAW message or body]

On Thursday 05 March 2009 21:28:28 Akarsh Simha wrote:
> > Yes it would. Will make it easier I believe. AFAIK `m' superscript is
> > international designation.
> >
> > Also it's possible to put string "%1 <sup>m</sup>"  into
> > internationalization machinery with comment like: "You generally need not
> > to translate this string unless you have reasons to do so".
>
> Great! Go ahead and make the replacement whenever / wherever you
> can. Just for beginners who use our software, it might be a good idea
> to add a tooltip that says that the <sup>m</sup> indicates a
> magnitude.
>
Patchset updated

* helper_functions.patch 

Add helper function to convert magnitude to string representation suitable for 
QLabel. It takes care for special cases. 

It was put in separate source file. It is meant to hold various small utility 
functions. Probably there is more suitable place for it but couldn't find it.

* details_m_superscript.patch 

Change how does magnitude displayed in details dialog. Use "m" superscript 
instead of "mag."

["helper_functions.patch" (text/x-diff)]

Index: kshelpers.cpp
===================================================================
--- kshelpers.cpp	(revision 0)
+++ kshelpers.cpp	(revision 0)
@@ -0,0 +1,15 @@
+
+#include "kshelpers.h"
+#include <kglobal.h>
+#include <klocale.h>
+
+#include <math.h>
+
+QString magnitudeToStr(float m, int n)
+{
+    // It's not expected for anything to be that bright of dim.
+    // This values are arbitrary though
+    if( isnan(m) || m > 60 || m < -30 )
+        return QString("--");
+    return i18n("%1<sup> m</sup>", KGlobal::locale()->formatNumber(m,n));
+}
Index: kshelpers.h
===================================================================
--- kshelpers.h	(revision 0)
+++ kshelpers.h	(revision 0)
@@ -0,0 +1,25 @@
+#ifndef KSTARSHELPERS_H_
+#define KSTARSHELPERS_H_
+
+/***************************************************************************
+ *                                                                         *
+ *   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.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#import <QString>
+
+/** @file Small helper functions which could be used anywhere. */
+
+/** Convert magnitude to string representation for QLabel. It returns
+    string in like "1.22<sup> m</sup>". QLabel makes 'm' superscript.
+
+    @param m - magnitude to convert
+    @param n - number of signs after decimal point
+*/
+QString magnitudeToStr(float m, int n = 2);
+
+#endif /* KSTARSHELPERS_H_ */
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 935863)
+++ CMakeLists.txt	(working copy)
@@ -300,7 +300,7 @@
 	ksfilereader.cpp ksnumbers.cpp
 	kspopupmenu.cpp kstars.cpp 
 	kstarsactions.cpp kstarsdata.cpp kstarsdatetime.cpp kstarsdcop.cpp kstarsinit.cpp 
-	kstarssplash.cpp ksutils.cpp kswizard.cpp main.cpp 
+	kstarssplash.cpp ksutils.cpp kshelpers.cpp kswizard.cpp main.cpp 
 	simclock.cpp skymap.cpp skymapdraw.cpp skymapevents.cpp
 	timezonerule.cpp 
 	thumbnailpicker.cpp thumbnaileditor.cpp quaternion.cpp binfilehelper.cpp
Index: kspopupmenu.cpp
===================================================================
--- kspopupmenu.cpp	(revision 935863)
+++ kspopupmenu.cpp	(working copy)
@@ -28,6 +28,8 @@
 #include "skyobjects/trailobject.h"
 #include "skymap.h"
 
+#include "kshelpers.h"
+
 #include <config-kstars.h>
 
 #ifdef HAVE_INDI_H
@@ -42,10 +44,6 @@
 
 #include <kactioncollection.h>
 
-// Convert magnitude to string representation for QLabel
-static QString magToStr(double m) {
-	return QString("%1<sup>m</sup>").arg(m, 0, 'f', 2);
-}
 
 // Helper function to return object name
 static QString getObjectName(SkyObject *obj) {
@@ -123,21 +121,21 @@
 }
  
 void KSPopupMenu::createDeepSkyObjectMenu( SkyObject *obj ) {
-	QString name = getObjectName(obj);
+    QString name = getObjectName(obj);
     QString typeName = ks->data()->typeName( obj->type() );
-	// FIXME: information about angular sizes should be added.
-	// Requires downcast. Not sure whether it safe.
-	QString info = magToStr( obj->mag() );
-	
-	initPopupMenu( obj, name, typeName, info );
+    // FIXME: information about angular sizes should be added.
+    // Requires downcast. Not sure whether it safe.
+    QString info = magnitudeToStr( obj->mag() );
+
+    initPopupMenu( obj, name, typeName, info );
     addLinksToMenu( obj );
 }
 
 void KSPopupMenu::createCustomObjectMenu( SkyObject *obj ) {
-	QString name = getObjectName(obj); 
+    QString name = getObjectName(obj); 
     QString typeName = ks->data()->typeName( obj->type() );
-	QString info = magToStr( obj->mag() );
-	
+    QString info = magnitudeToStr( obj->mag() );
+
     initPopupMenu( obj, name, typeName, info );
 
     addLinksToMenu( obj, true );
@@ -146,14 +144,14 @@
 void KSPopupMenu::createPlanetMenu( SkyObject *p ) {
     bool addTrail( ! ((TrailObject*)p)->hasTrail() );
     QString info;
-	QString type;
+    QString type;
     if ( p->name() == "Moon" ) {
         info = QString("%1<sup>m</sup>, %2").arg(p->mag(), 0, 'f', 2).arg(((KSMoon *)p)->phaseName());
     } else {
-		// FIXME: angular size is required.
-		info = magToStr( p->mag() );
-		type = i18n("Solar system object");
-	}
+        // FIXME: angular size is required.
+        info = magnitudeToStr( p->mag() );
+        type = i18n("Solar system object");
+    }
     initPopupMenu( p, p->translatedName(), type, info, true, true, true, true, addTrail );
     addLinksToMenu( p, false ); //don't offer DSS images for planets
 }

["details_m_superscript.patch" (text/x-diff)]

diff -r 89d7e2d8c515 kstars/dialogs/detaildialog.cpp
--- a/kstars/dialogs/detaildialog.cpp	Fri Mar 06 19:06:26 2009 +0300
+++ b/kstars/dialogs/detaildialog.cpp	Fri Mar 06 19:06:32 2009 +0300
@@ -46,6 +46,7 @@
 #include "skyobjects/ksmoon.h"
 #include "thumbnailpicker.h"
 #include "Options.h"
+#include "kshelpers.h"
 
 #include <config-kstars.h>
 
@@ -134,8 +135,7 @@
                 Data->Names->setText( QString( ", HD%1" ).arg( QString::number( \
s->getHDIndex() ) ) );  }
         Data->Type->setText( s->sptype() + ' ' + i18n("star") );
-        Data->Magnitude->setText( i18nc( "number in magnitudes", "%1 mag" ,
-                                         KGlobal::locale()->formatNumber( s->mag(), 1 ) ) );  \
//show to tenths place +        Data->Magnitude->setText( magnitudeToStr(s->mag()) );
 
         //The thumbnail image is empty, and isn't clickable for stars
         //Also, don't show the border around the Image QFrame.
@@ -192,8 +192,7 @@
             Data->Illumination->setText( QString("%1 %").arg( KGlobal::locale()->formatNumber( \
((KSMoon *)selectedObject)->illum()*100., 0 ) ) );  }
 
-        Data->Magnitude->setText( i18nc( "number in magnitudes", "%1 mag" ,
-                                         KGlobal::locale()->formatNumber( ps->mag(), 1 ) ) );  \
//show to tenths place +        Data->Magnitude->setText( magnitudeToStr(ps->mag()) );
         //Distance from Earth.  The moon requires a unit conversion
         if ( ps->name() == "Moon" ) {
             Data->Distance->setText( i18nc("distance in kilometers", "%1 km",
@@ -247,11 +246,8 @@
 
         Data->Type->setText( dso->typeName() );
 
-        if ( dso->mag() > 90.0 )
-            Data->Magnitude->setText( "--" );
-        else
-            Data->Magnitude->setText( i18nc( "number in magnitudes", "%1 mag" ,
-                                             KGlobal::locale()->formatNumber( dso->mag(), 1 ) \
) );  //show to tenths place +        Data->Magnitude->setText( magnitudeToStr(dso->mag()) );
+
 
         //No distances at this point...
         Data->Distance->setText( "--" );



_______________________________________________
Kstars-devel mailing list
Kstars-devel@kde.org
https://mail.kde.org/mailman/listinfo/kstars-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic