• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • widgets
dmsbox.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  dmsbox.cpp - description
3  -------------------
4  begin : wed Dec 19 2001
5  copyright : (C) 2001-2002 by Pablo de Vicente
6  email : vicente@oan.es
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "dmsbox.h"
19 
20 #include <cstdlib>
21 
22 #include <kdebug.h>
23 #include <klocale.h>
24 
25 #include <QRegExp>
26 #include <QFocusEvent>
27 #include <QApplication>
28 
29 dmsBox::dmsBox(QWidget *parent, bool dg)
30  : KLineEdit(parent), EmptyFlag(true) {
31  setMaxLength(14);
32  setMaximumWidth(160);
33  setDegType( dg );
34 
35  connect( this, SIGNAL( textChanged( const QString & ) ), this, SLOT( slotTextChanged( const QString & ) ) );
36 }
37 
38 void dmsBox::setEmptyText() {
39  //Set the text color to the average between
40  //QColorGroup::Text and QColorGroup::Base
41  QPalette p=QApplication::palette();
42  QColor txc = p.color( QPalette::Active, QPalette::Text );
43  QColor bgc = p.color( QPalette::Active, QPalette::Base );
44  int r( ( txc.red() + bgc.red() )/2 );
45  int g( ( txc.green() + bgc.green() )/2 );
46  int b( ( txc.blue() + bgc.blue() )/2 );
47 
48  p.setColor( QPalette::Active, QPalette::Text, QColor( r, g, b ) );
49  p.setColor( QPalette::Inactive, QPalette::Text, QColor( r, g, b ) );
50  setPalette( p );
51 
52  if ( degType() )
53  setText( "dd mm ss.s" );
54  else
55  setText( "hh mm ss.s" );
56 
57  EmptyFlag = true;
58 }
59 
60 void dmsBox::focusInEvent( QFocusEvent *e ) {
61  KLineEdit::focusInEvent( e );
62 
63  if ( EmptyFlag ) {
64  clear();
65  setPalette( QApplication::palette() );
66  EmptyFlag = false;
67  }
68 }
69 
70 void dmsBox::focusOutEvent( QFocusEvent *e ) {
71  KLineEdit::focusOutEvent( e );
72 
73  if ( text().isEmpty() ) {
74  setEmptyText();
75  }
76 }
77 
78 void dmsBox::slotTextChanged( const QString &t ) {
79  if ( ! hasFocus() ) {
80  if ( EmptyFlag && ! t.isEmpty() ) {
81  EmptyFlag = false;
82  }
83 
84  if ( ! EmptyFlag && t.isEmpty() ) {
85  setEmptyText();
86  }
87  }
88 }
89 
90 void dmsBox::setDegType( bool t ) {
91  deg = t;
92 
93  QString sTip = ( t ? i18n( "Angle value in degrees." ) : i18n( "Angle value in hours." ) );
94  QString sWhatsThis;
95 
96  if ( isReadOnly() ) {
97  if( t ) {
98  sWhatsThis = i18n( "This box displays an angle in degrees. "
99  "The three numbers displayed are the angle's "
100  "degrees, arcminutes, and arcseconds." );
101  }
102  else {
103  sWhatsThis = i18n( "This box displays an angle in hours. "
104  "The three numbers displayed are the angle's "
105  "hours, minutes, and seconds." );
106  }
107  } else {
108  if( t ) {
109  sTip += i18n( " You may enter a simple integer, or a floating-point value, "
110  "or space- or colon-delimited values specifying "
111  "degrees, arcminutes and arcseconds" );
112 
113  sWhatsThis = i18n( "Enter an angle value in degrees. The angle can be expressed "
114  "as a simple integer (\"12\"), a floating-point value "
115  "(\"12.33\"), or as space- or colon-delimited "
116  "values specifying degrees, arcminutes and arcseconds (\"12:20\", \"12:20:00\", "
117  "\"12 20\", \"12 20 00.0\", etc.)." );
118  }
119  else {
120  sTip += i18n( " You may enter a simple integer, or a floating-point value, "
121  "or space- or colon-delimited values specifying "
122  "hours, minutes and seconds" );
123 
124  sWhatsThis = i18n( "Enter an angle value in hours. The angle can be expressed "
125  "as a simple integer (\"12\"), a floating-point value "
126  "(\"12.33\"), or as space- or colon-delimited "
127  "values specifying hours, minutes and seconds (\"12:20\", \"12:20:00\", "
128  "\"12 20\", \"12 20 00.0\", etc.)." );
129  }
130  }
131 
132  setToolTip( sTip );
133  setWhatsThis( sWhatsThis );
134 
135  clear();
136  EmptyFlag = false;
137  setEmptyText();
138 }
139 
140 void dmsBox::showInDegrees (const dms *d) { showInDegrees( dms( *d ) ); }
141 void dmsBox::showInDegrees (dms d)
142 {
143  double seconds = d.arcsec() + d.marcsec()/1000.;
144  setDMS( QString().sprintf( "%02d %02d %05.2f", d.degree(), d.arcmin(), seconds ) );
145 }
146 
147 void dmsBox::showInHours (const dms *d) { showInHours( dms( *d ) ); }
148 void dmsBox::showInHours (dms d)
149 {
150  double seconds = d.second() + d.msecond()/1000.;
151  setDMS( QString().sprintf( "%02d %02d %05.2f", d.hour(), d.minute(), seconds ) );
152 }
153 
154 void dmsBox::show(const dms *d, bool deg) { show( dms( *d ),deg ); }
155 void dmsBox::show(dms d, bool deg)
156 {
157  if (deg)
158  showInDegrees(d);
159  else
160  showInHours(d);
161 }
162 
163 dms dmsBox::createDms ( bool deg, bool *ok )
164 {
165  dms dmsAngle(0.0); // FIXME: Should we change this to NaN?
166  bool check;
167  check = dmsAngle.setFromString( text(), deg );
168  if (ok) *ok = check; //ok might be a null pointer!
169 
170  return dmsAngle;
171 }
172 
173 dmsBox::~dmsBox(){
174 }
175 
176 #include "dmsbox.moc"
dms::hour
int hour() const
Definition: dms.h:104
dmsBox::degType
bool degType(void) const
Definition: dmsbox.h:118
dmsBox::focusOutEvent
void focusOutEvent(QFocusEvent *e)
Definition: dmsbox.cpp:70
dmsBox::focusInEvent
void focusInEvent(QFocusEvent *e)
Definition: dmsbox.cpp:60
dmsBox::setDMS
void setDMS(const QString &s)
Simply display a string.
Definition: dmsbox.h:102
dms::minute
int minute() const
Definition: dms.cpp:174
QWidget
dms::degree
int degree() const
Definition: dms.h:79
dms::second
int second() const
Definition: dms.cpp:182
dmsBox::createDms
dms createDms(bool deg=true, bool *ok=0)
Parse the text in the dmsBox as an angle.
Definition: dmsbox.cpp:163
dmsBox::dmsBox
dmsBox(QWidget *parent, bool deg=true)
Constructor for the dmsBox object.
Definition: dmsbox.cpp:29
dmsBox::showInDegrees
void showInDegrees(dms t)
Display an angle using Deg/Arcmin/Arcsec.
Definition: dmsbox.cpp:141
dmsBox::showInHours
void showInHours(dms t)
Display an angle using Hours/Min/Sec.
Definition: dmsbox.cpp:148
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
KLineEdit
dms::marcsec
int marcsec() const
Definition: dms.cpp:165
NaN::d
const double d
Definition: nan.h:35
dmsBox::isEmpty
bool isEmpty()
Definition: dmsbox.h:130
dmsBox::show
void show(dms t, bool deg=true)
Display an angle.
Definition: dmsbox.cpp:155
dms::msecond
int msecond() const
Definition: dms.cpp:190
dms::arcsec
int arcsec() const
Definition: dms.cpp:156
dmsbox.h
dmsBox::setDegType
void setDegType(bool t)
set the dmsBox to Degrees or Hours
Definition: dmsbox.cpp:90
dmsBox::~dmsBox
~dmsBox()
Destructor (empty)
Definition: dmsbox.cpp:173
dms::arcmin
int arcmin() const
Definition: dms.cpp:148
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal