[Kstars-devel] kdeedu/kstars/kstars

Jason Harris kstars at 30doradus.org
Sat Oct 2 22:08:04 CEST 2004


CVS commit by harris: 

Experimental usability improvement for dmsBox:

When the dmsBox is empty, it displays in grey text 
"dd mm ss.s" or "hh mm ss.s" (depending on whether it 
expects degrees or hours).  These letters disappear 
when the dmsBox gets input focus.  They reappear if 
the dmsBox loses input focus and the box is empty.

The intention is to provide the user with some hint 
that this isn't just a normal edit box, that angle
values can be accepted by typing values for degrees,
arcminutes and arcseconds (or hours, minutes, seconds).
It also provides visual feedback on whether degrees 
or hours are expected.

Drawbacks: it may be confusing to some users who 
are not familiar with expressing angles in this 
way.  It also does not make clear that other formats 
are also acceptable.

Please let me know your opinions on this feature.
You will need to run "make -f Makefile.cvs" and 
configure, because dmsBox now needs a MOC file.

CCMAIL: kstars-devel at kde.org


  M +59 -1     dmsbox.cpp   1.27
  M +13 -3     dmsbox.h   1.14


--- kdeedu/kstars/kstars/dmsbox.cpp  #1.26:1.27
@@ -26,8 +26,64 @@
 #include <qwhatsthis.h>
 
-dmsBox::dmsBox(QWidget *parent, const char *name, bool dg) : KLineEdit(parent,name) {
+dmsBox::dmsBox(QWidget *parent, const char *name, bool dg) 
+        : KLineEdit(parent,name), EmptyFlag(true) {
         setMaxLength(14);
         setMaximumWidth(160);
         setDegType( dg );
+        
+        setEmptyText();
+        
+        connect( this, SIGNAL( textChanged( const QString & ) ), this, SLOT( slotTextChanged( const QString & ) ) );
+}
+
+void dmsBox::setEmptyText() {
+        QPalette p = palette();
+        QColor txc = p.color( QPalette::Active, QColorGroup::Text );
+        QColor bgc = paletteBackgroundColor();
+        int r( ( txc.red()   + bgc.red()   )/2 );
+        int g( ( txc.green() + bgc.green() )/2 );
+        int b( ( txc.blue()  + bgc.blue()  )/2 );
+        
+        p.setColor( QPalette::Active,   QColorGroup::Text, QColor( r, g, b ) );
+        p.setColor( QPalette::Inactive, QColorGroup::Text, QColor( r, g, b ) );
+        setPalette( p );
+        
+        if ( degType() ) 
+                setText( "dd mm ss.s" );
+        else 
+                setText( "hh mm ss.s" );
+                
+        EmptyFlag = true;
+}
+
+void dmsBox::focusInEvent( QFocusEvent *e ) {
+        KLineEdit::focusInEvent( e );
+        
+        if ( EmptyFlag ) {
+                clear();
+                unsetPalette();
+                EmptyFlag = false;
+        }
+}
+
+void dmsBox::focusOutEvent( QFocusEvent *e ) {
+        KLineEdit::focusOutEvent( e );
+        
+        if ( text().isEmpty() ) {
+                setEmptyText();
+        }
+}
+
+void dmsBox::slotTextChanged( const QString &t ) {
+        if ( ! hasFocus() ) {
+                if ( EmptyFlag && ! t.isEmpty() ) {
+                        unsetPalette();
+                        EmptyFlag = false;
+                }
+                
+                if ( ! EmptyFlag && t.isEmpty() ) {
+                        setEmptyText();
+                }
+        }
 }
 
@@ -76,2 +132,4 @@ dms dmsBox::createDms ( bool deg, bool *
 dmsBox::~dmsBox(){
 }
+
+#include "dmsbox.moc"

--- kdeedu/kstars/kstars/dmsbox.h  #1.13:1.14
@@ -42,4 +42,6 @@
 
 class dmsBox : public KLineEdit  {
+Q_OBJECT
+
 public:
         /**Constructor for the dmsBox object.
@@ -109,6 +111,6 @@ public:
         dms createDms(bool deg=TRUE, bool *ok=0);
 
-        /*@return a boolean indicating if object contains degrees or hours
-                **/
+        /**@return a boolean indicating if object contains degrees or hours
+                */
         bool degType(void) const {return deg;}
 
@@ -123,10 +125,18 @@ public:
         void clearFields (void) { setDMS(""); }
 
+protected:
+        void focusInEvent( QFocusEvent *e );
+        void focusOutEvent( QFocusEvent *e );
+
+private slots:
+        void slotTextChanged( const QString &t );
+
 private:
+        void setEmptyText();
 
         int degree, minute, hour;
         double second;
         int second_int, msecond;
-        bool deg;
+        bool deg, EmptyFlag;
         dms degValue;
 };




More information about the Kstars-devel mailing list