• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kstars

dmsbox.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           dmsbox.cpp  -  description
00003                              -------------------
00004     begin                : wed Dec 19 2001
00005     copyright            : (C) 2001-2002 by Pablo de Vicente
00006     email                : vicente@oan.es
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include <stdlib.h>
00019 
00020 #include "dmsbox.h"
00021 
00022 #include <kdebug.h>
00023 #include <klocale.h>
00024 #include <qregexp.h>
00025 #include <qstring.h>
00026 #include <qtooltip.h>
00027 #include <qwhatsthis.h>
00028 
00029 dmsBox::dmsBox(QWidget *parent, const char *name, bool dg) 
00030     : KLineEdit(parent,name), EmptyFlag(true) {
00031     setMaxLength(14);
00032     setMaximumWidth(160);
00033     setDegType( dg );
00034     
00035     
00036     connect( this, SIGNAL( textChanged( const QString & ) ), this, SLOT( slotTextChanged( const QString & ) ) );
00037 }
00038 
00039 void dmsBox::setEmptyText() {
00040     QPalette p = palette();
00041     QColor txc = p.color( QPalette::Active, QColorGroup::Text );
00042     QColor bgc = paletteBackgroundColor();
00043     int r( ( txc.red()   + bgc.red()   )/2 );
00044     int g( ( txc.green() + bgc.green() )/2 );
00045     int b( ( txc.blue()  + bgc.blue()  )/2 );
00046     
00047     p.setColor( QPalette::Active,   QColorGroup::Text, QColor( r, g, b ) );
00048     p.setColor( QPalette::Inactive, QColorGroup::Text, QColor( r, g, b ) );
00049     setPalette( p );
00050     
00051     if ( degType() ) 
00052         setText( "dd mm ss.s" );
00053     else 
00054         setText( "hh mm ss.s" );
00055         
00056     EmptyFlag = true;
00057 }
00058 
00059 void dmsBox::focusInEvent( QFocusEvent *e ) {
00060     KLineEdit::focusInEvent( e );
00061     
00062     if ( EmptyFlag ) {
00063         clear();
00064         unsetPalette();
00065         EmptyFlag = false;
00066     }
00067 }
00068 
00069 void dmsBox::focusOutEvent( QFocusEvent *e ) {
00070     KLineEdit::focusOutEvent( e );
00071     
00072     if ( text().isEmpty() ) {
00073         setEmptyText();
00074     }
00075 }
00076 
00077 void dmsBox::slotTextChanged( const QString &t ) {
00078     if ( ! hasFocus() ) {
00079         if ( EmptyFlag && ! t.isEmpty() ) {
00080             unsetPalette();
00081             EmptyFlag = false;
00082         }
00083         
00084         if ( ! EmptyFlag && t.isEmpty() ) {
00085             setEmptyText();
00086         }
00087     }
00088 }
00089 
00090 void dmsBox::setDegType( bool t ) {
00091     deg = t;
00092 
00093     if ( deg ) {
00094         QToolTip::add( this, i18n( "Angle value in degrees. You may enter a simple integer \nor a floating-point value, or space- or colon-delimited values \nspecifying degrees, arcminutes and arcseconds." ) );
00095         QWhatsThis::add( this, i18n( "Enter an angle value in degrees.  The angle can be expressed as a simple integer (\"45\") or floating-point (\"45.333\") value, or as space- or colon-delimited values specifying degrees, arcminutes and arcseconds (\"45:20\", \"45:20:00\", \"45:20\", \"45 20.0\", etc.)." ) ); 
00096     } else {
00097         QToolTip::add( this, i18n( "Angle value in hours. You may enter a simple integer \nor floating-point value, or space- or colon-delimited values \nspecifying hours, minutes and seconds." ) );
00098         QWhatsThis::add( this, i18n( "Enter an angle value in hours.  The angle can be expressed as a simple integer (\"12\") or floating-point (\"12.333\") value, or as space- or colon-delimited values specifying hours, minutes and seconds (\"12:20\", \"12:20:00\", \"12:20\", \"12 20.0\", etc.)." ) );
00099     }
00100 
00101     clear();
00102     unsetPalette();
00103     EmptyFlag = false;
00104     setEmptyText();
00105 }
00106 
00107 void dmsBox::showInDegrees (const dms *d) { showInDegrees( dms( *d ) ); }
00108 void dmsBox::showInDegrees (dms d)
00109 {
00110     double seconds = d.arcsec() + d.marcsec()/1000.;
00111     setDMS( QString().sprintf( "%02d %02d %05.2f", d.degree(), d.arcmin(), seconds ) );
00112 }
00113 
00114 void dmsBox::showInHours (const dms *d) { showInHours( dms( *d ) ); }
00115 void dmsBox::showInHours (dms d)
00116 {
00117     double seconds = d.second() + d.msecond()/1000.;
00118     setDMS( QString().sprintf( "%02d %02d %05.2f", d.hour(), d.minute(), seconds ) );
00119 }
00120 
00121 void dmsBox::show(const dms *d, bool deg) { show( dms( *d ),deg ); }
00122 void dmsBox::show(dms d, bool deg)
00123 {
00124     if (deg)
00125         showInDegrees(d);
00126     else
00127         showInHours(d);
00128 }
00129 
00130 dms dmsBox::createDms ( bool deg, bool *ok )
00131 {
00132     dms dmsAngle(0.0);
00133     bool check;
00134     check = dmsAngle.setFromString( text(), deg );
00135     if (ok) *ok = check; //ok might be a null pointer!
00136 
00137     return dmsAngle;
00138 }
00139 
00140 dmsBox::~dmsBox(){
00141 }
00142 
00143 #include "dmsbox.moc"

kstars

Skip menu "kstars"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • keduca
  • kstars
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal