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

kig

  • sources
  • kde-4.12
  • kdeedu
  • kig
  • misc
kiginputdialog.cc
Go to the documentation of this file.
1 
21 #include "kiginputdialog.h"
22 #include "kiginputdialog.moc"
23 
24 #include "coordinate.h"
25 #include "coordinate_system.h"
26 #include "goniometry.h"
27 
28 #include "../kig/kig_document.h"
29 
30 #include <qevent.h>
31 #include <qlabel.h>
32 #include <qlayout.h>
33 #include <qvalidator.h>
34 
35 #include <kcombobox.h>
36 #include <klineedit.h>
37 #include <klocale.h>
38 #include <kpushbutton.h>
39 
40 class KigInputDialogPrivate
41 {
42 public:
43  KigInputDialogPrivate();
44 
45  QLabel* m_label;
46  KLineEdit* m_lineEditFirst;
47  KLineEdit* m_lineEditSecond;
48  KComboBox* m_comboBox;
49 
50  Coordinate m_coord1;
51  Coordinate m_coord2;
52  const KigDocument* m_doc;
53  QValidator* m_vtor;
54  Goniometry m_gonio;
55  bool m_gonioIsNum;
56 };
57 
58 KigInputDialogPrivate::KigInputDialogPrivate()
59  : m_label( 0L ), m_lineEditFirst( 0L ), m_lineEditSecond( 0L ), m_comboBox( 0L ),
60  m_doc( 0 )
61 {
62 }
63 
64 KigInputDialog::~KigInputDialog()
65 {
66  delete d;
67 }
68 
69 KigInputDialog::KigInputDialog( const QString& caption, const QString& label,
70  QWidget* parent, const KigDocument& doc, Coordinate* c1, Coordinate* c2 )
71  : KDialog( parent ),
72  d( new KigInputDialogPrivate() )
73 {
74  setCaption( caption );
75  setButtons( Ok | Cancel );
76 
77  d->m_coord1 = c1 ? Coordinate( *c1 ) : Coordinate::invalidCoord();
78  d->m_coord2 = c2 ? Coordinate( *c2 ) : Coordinate::invalidCoord();
79  d->m_doc = &doc;
80  d->m_vtor = d->m_doc->coordinateSystem().coordinateValidator();
81 
82  bool ok = false;
83 
84  QWidget* frame = new QWidget();
85  setMainWidget( frame );
86  QVBoxLayout* mainlay = new QVBoxLayout( frame );
87  mainlay->setMargin( 0 );
88  mainlay->setSpacing( spacingHint() );
89  mainlay->activate();
90 
91  d->m_label = new QLabel( frame );
92  d->m_label->setTextFormat( Qt::RichText );
93  d->m_label->setText( label );
94  mainlay->addWidget( d->m_label );
95 
96  d->m_lineEditFirst = new KLineEdit( frame );
97 // d->m_lineEditFirst->setValidator( d->m_vtor );
98  if ( d->m_coord1.valid() )
99  {
100  d->m_lineEditFirst->setText( d->m_doc->coordinateSystem().fromScreen( d->m_coord1, *d->m_doc ) );
101  ok = true;
102  }
103  mainlay->addWidget( d->m_lineEditFirst );
104 
105  connect( d->m_lineEditFirst, SIGNAL(textChanged(const QString&)),
106  this, SLOT(slotCoordsChanged(const QString&)) );
107 
108  if ( d->m_coord2.valid() )
109  {
110  d->m_lineEditSecond = new KLineEdit( frame );
111 // d->m_lineEditSecond->setValidator( d->m_vtor );
112  d->m_lineEditSecond->setText( d->m_doc->coordinateSystem().fromScreen( d->m_coord2, *d->m_doc ) );
113  mainlay->addWidget( d->m_lineEditSecond );
114 
115  connect( d->m_lineEditSecond, SIGNAL(textChanged(const QString&)),
116  this, SLOT(slotCoordsChanged(const QString&)) );
117  }
118 
119  resize( minimumSizeHint() );
120 
121  d->m_lineEditFirst->setFocus();
122 
123  enableButtonOk( ok );
124 }
125 
126 KigInputDialog::KigInputDialog( QWidget* parent, const Goniometry& g )
127  : KDialog( parent ),
128  d( new KigInputDialogPrivate() )
129 {
130  setCaption( i18n( "Set Angle Size" ) );
131  setButtons( Ok | Cancel );
132 
133  d->m_gonio = g;
134  d->m_gonioIsNum = true;
135 
136  QWidget* frame = new QWidget();
137  setMainWidget( frame );
138  QVBoxLayout* mainlay = new QVBoxLayout( frame );
139  mainlay->setMargin( 0 );
140  mainlay->setSpacing( spacingHint() );
141  mainlay->activate();
142 
143  d->m_label = new QLabel( frame );
144  d->m_label->setText( i18n( "Insert the new size of this angle:" ) );
145  mainlay->addWidget( d->m_label );
146 
147  QHBoxLayout* horlay = new QHBoxLayout( (QWidget*)0 );
148  horlay->setMargin( 0 );
149  horlay->setSpacing( spacingHint() );
150  horlay->activate();
151 
152  d->m_lineEditFirst = new KLineEdit( frame );
153  d->m_lineEditFirst->setText( QString::number( d->m_gonio.value() ) );
154  d->m_lineEditFirst->setWhatsThis(
155  i18n( "Use this edit field to modify the size of this angle." ) );
156  horlay->addWidget( d->m_lineEditFirst );
157 
158  d->m_comboBox = new KComboBox( frame );
159  d->m_comboBox->addItems( Goniometry::systemList() );
160  d->m_comboBox->setCurrentIndex( d->m_gonio.system() );
161  d->m_comboBox->setWhatsThis(
162  i18n( "Choose from this list the goniometric unit you want to use to "
163  "modify the size of this angle.<br />\n"
164  "If you switch to another unit, the value in the edit field on "
165  "the left will be converted to the new selected unit." ) );
166  horlay->addWidget( d->m_comboBox );
167 
168  mainlay->addLayout( horlay );
169 
170  connect( d->m_lineEditFirst, SIGNAL(textChanged(const QString&)),
171  this, SLOT(slotGonioTextChanged(const QString&)) );
172  connect( d->m_comboBox, SIGNAL(activated(int)),
173  this, SLOT(slotGonioSystemChanged(int)) );
174 
175  resize( 350, 100 );
176 
177  d->m_lineEditFirst->setFocus();
178 }
179 
180 void KigInputDialog::keyPressEvent( QKeyEvent* e )
181 {
182 #if 0
183  if ( ( e->key() == Qt::Key_Return ) && ( e->modifiers() == 0 ) )
184  {
185  if ( actionButton( Ok )->isEnabled() )
186  {
187  actionButton( Ok )->animateClick();
188  e->accept();
189  return;
190  }
191  }
192  else if ( ( e->key() == Qt::Key_Escape ) && ( e->modifiers() == 0 ) )
193  {
194  actionButton( Cancel )->animateClick();
195  e->accept();
196  return;
197  }
198 #endif
199  KDialog::keyPressEvent( e );
200 }
201 
202 void KigInputDialog::slotCoordsChanged( const QString& )
203 {
204  int p = 0;
205  QString t = d->m_lineEditFirst->text();
206  bool ok = d->m_vtor->validate( t, p ) == QValidator::Acceptable;
207  if ( ok )
208  d->m_coord1 = d->m_doc->coordinateSystem().toScreen( t, ok );
209  if ( d->m_lineEditSecond )
210  {
211  p = 0;
212  t = d->m_lineEditSecond->text();
213  ok &= d->m_vtor->validate( t, p ) == QValidator::Acceptable;
214  if ( ok )
215  d->m_coord2 = d->m_doc->coordinateSystem().toScreen( t, ok );
216  }
217 
218  enableButtonOk( ok );
219 }
220 
221 void KigInputDialog::slotGonioSystemChanged( int index )
222 {
223  if ( d->m_gonioIsNum )
224  {
225  Goniometry::System newsys = Goniometry::intToSystem( index );
226  d->m_gonio.convertTo( newsys );
227  d->m_lineEditFirst->setText( QString::number( d->m_gonio.value() ) );
228  }
229 }
230 
231 void KigInputDialog::slotGonioTextChanged( const QString& txt )
232 {
233  if ( txt.isNull() )
234  d->m_gonioIsNum = false;
235  else
236  {
237  double v = txt.toDouble( &(d->m_gonioIsNum) );
238  d->m_gonio.setValue( v );
239  }
240  enableButtonOk( d->m_gonioIsNum );
241 }
242 
243 
244 Coordinate KigInputDialog::coordinateFirst() const
245 {
246  return d->m_coord1;
247 }
248 
249 Coordinate KigInputDialog::coordinateSecond() const
250 {
251  return d->m_coord2;
252 }
253 
254 Goniometry KigInputDialog::goniometry() const
255 {
256  return d->m_gonio;
257 }
258 
259 void KigInputDialog::getCoordinate( const QString& caption, const QString& label,
260  QWidget* parent, bool* ok, const KigDocument& doc, Coordinate* cvalue )
261 {
262  getTwoCoordinates( caption, label, parent, ok, doc, cvalue, 0 );
263 }
264 
265 void KigInputDialog::getTwoCoordinates( const QString& caption, const QString& label,
266  QWidget* parent, bool* ok, const KigDocument& doc, Coordinate* cvalue,
267  Coordinate* cvalue2 )
268 {
269  KigInputDialog dlg( caption, label, parent, doc, cvalue, cvalue2 );
270 
271  *ok = ( dlg.exec() == Accepted );
272 
273  if ( *ok )
274  {
275  Coordinate a = dlg.coordinateFirst();
276  *cvalue = a;
277  if ( cvalue2 )
278  {
279  Coordinate b = dlg.coordinateSecond();
280  *cvalue2 = b;
281  }
282  }
283 
284 }
285 
286 Goniometry KigInputDialog::getAngle( QWidget* parent, bool* ok, const Goniometry& g )
287 {
288  KigInputDialog dlg( parent, g );
289 
290  *ok = ( dlg.exec() == Accepted );
291 
292  return dlg.goniometry();
293 }
CoordinateSystem::coordinateValidator
virtual QValidator * coordinateValidator() const =0
Goniometry
Manage an angle and convert it from/to other goniometric systems.
Definition: goniometry.h:28
Goniometry::System
System
Definition: goniometry.h:31
QWidget
Goniometry::intToSystem
static Goniometry::System intToSystem(const int index)
Definition: goniometry.cc:128
coordinate_system.h
KDialog
Coordinate
The Coordinate class is the basic class representing a 2D location by its x and y components...
Definition: coordinate.h:33
KigInputDialog::getTwoCoordinates
static void getTwoCoordinates(const QString &caption, const QString &label, QWidget *parent, bool *ok, const KigDocument &doc, Coordinate *cvalue, Coordinate *cvalue2)
Static convenience function to get two Coordinates at once from the user.
Definition: kiginputdialog.cc:265
Goniometry::systemList
static QStringList systemList()
Get a list of the supported goniometric systems.
Definition: goniometry.cc:119
goniometry.h
KigInputDialog::getCoordinate
static void getCoordinate(const QString &caption, const QString &label, QWidget *parent, bool *ok, const KigDocument &doc, Coordinate *cvalue)
Static convenience function to get a Coordinate from the user.
Definition: kiginputdialog.cc:259
kiginputdialog.h
KigInputDialog::getAngle
static Goniometry getAngle(QWidget *parent, bool *ok, const Goniometry &g)
Static convenience function to get an angle incapsulated in a Goniometry class.
Definition: kiginputdialog.cc:286
KigDocument
KigDocument is the class holding the real data in a Kig document.
Definition: kig_document.h:36
coordinate.h
KigDocument::coordinateSystem
const CoordinateSystem & coordinateSystem() const
Definition: kig_document.cc:40
KigInputDialog
The KigInputDialog class provides easy ways of interaction with the user.
Definition: kiginputdialog.h:40
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kig

Skip menu "kig"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

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