Stellarium 0.15.0
SearchDialog.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2008 Guillaume Chereau
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18 */
19 
20 #ifndef _SEARCHDIALOG_HPP_
21 #define _SEARCHDIALOG_HPP_
22 
23 #include <QObject>
24 #include <QLabel>
25 #include <QMap>
26 #include <QHash>
27 #include "StelDialog.hpp"
28 #include "VecMath.hpp"
29 
30 // pre declaration of the ui class
31 class Ui_searchDialogForm;
32 
34 {
35  bool operator()(const QString &s1, const QString &s2) const
36  {
37  return s1.length() < s2.length();
38  }
39 };
40 
44 class CompletionLabel : public QLabel
45 {
46  Q_OBJECT
47 
48 public:
49  CompletionLabel(QWidget* parent=0);
50  ~CompletionLabel();
51 
52  QString getSelected(void);
53  void setValues(const QStringList&);
54  bool isEmpty() const {return values.isEmpty();}
55  void appendValues(const QStringList&);
56  void clearValues();
57 
58 public slots:
59  void selectNext();
60  void selectPrevious();
61  void selectFirst();
62 
63 private:
64  void updateText();
65  int selectedIdx;
66  QStringList values;
67 };
68 
69 QT_FORWARD_DECLARE_CLASS(QListWidgetItem)
70 
71 class SearchDialog : public StelDialog
74 {
75  Q_OBJECT
76  Q_ENUMS(CoordinateSystem)
77 
78 public:
81  {
82  equatorialJ2000,
83  equatorial,
84  horizontal,
85  galactic,
86  ecliptic,
87  eclipticJ2000
88  };
89 
90  SearchDialog(QObject* parent);
91  virtual ~SearchDialog();
93  void styleChanged();
94  bool eventFilter(QObject *object, QEvent *event);
95 
96 
99  static QString substituteGreek(const QString& keyString);
101  static QString getGreekLetterByName(const QString& potentialGreekLetterName);
103  static const char* DEF_SIMBAD_URL;
104 public slots:
105  void retranslate();
107  void setSimpleStyle();
108 
111  {
112  currentCoordinateSystem = cs;
113  }
116  {
117  return currentCoordinateSystem;
118  }
120  QString getCurrentCoordinateSystemKey(void) const;
122  void setCurrentCoordinateSystemKey(QString key);
123 
124  void setCoordinateSystem(int csID);
125  void populateCoordinateSystemsList();
126  void populateCoordinateAxis();
127 
128 protected:
129  Ui_searchDialogForm* ui;
131  virtual void createDialogContent();
132 
133 private slots:
134  void greekLetterClicked();
136  void onSimbadStatusChanged();
138  void onSearchTextChanged(const QString& text);
139 
140  void gotoObject();
141  void gotoObject(const QString& nameI18n);
142  // for going from list views
143  void gotoObject(QListWidgetItem* item);
144 
145  void searchListChanged(const QString& newText);
146 
148  void manualPositionChanged();
149 
151  void enableSimbadSearch(bool enable);
152 
154  void enableStartOfWordsAutofill(bool enable);
155 
157  void setHasSelectedFlag();
158 
160  void selectSimbadServer(int index);
161 
163  void updateListWidget(int index);
164 
165  // retranslate/recreate tab
166  void updateListTab();
167 
168  void showContextMenu(const QPoint &pt);
169 
170  void pasteAndGo();
171 
172 private:
173  class SearchDialogStaticData
174  {
175  public:
177  QHash<QString, QString> greekLetters;
178 
179  SearchDialogStaticData()
180  {
181  greekLetters.insert("alpha", QString(QChar(0x03B1)));
182  greekLetters.insert("beta", QString(QChar(0x03B2)));
183  greekLetters.insert("gamma", QString(QChar(0x03B3)));
184  greekLetters.insert("delta", QString(QChar(0x03B4)));
185  greekLetters.insert("epsilon", QString(QChar(0x03B5)));
186 
187  greekLetters.insert("zeta", QString(QChar(0x03B6)));
188  greekLetters.insert("eta", QString(QChar(0x03B7)));
189  greekLetters.insert("theta", QString(QChar(0x03B8)));
190  greekLetters.insert("iota", QString(QChar(0x03B9)));
191  greekLetters.insert("kappa", QString(QChar(0x03BA)));
192 
193  greekLetters.insert("lambda", QString(QChar(0x03BB)));
194  greekLetters.insert("mu", QString(QChar(0x03BC)));
195  greekLetters.insert("nu", QString(QChar(0x03BD)));
196  greekLetters.insert("xi", QString(QChar(0x03BE)));
197  greekLetters.insert("omicron", QString(QChar(0x03BF)));
198 
199  greekLetters.insert("pi", QString(QChar(0x03C0)));
200  greekLetters.insert("rho", QString(QChar(0x03C1)));
201  greekLetters.insert("sigma", QString(QChar(0x03C3))); // second lower-case sigma shouldn't affect anything
202  greekLetters.insert("tau", QString(QChar(0x03C4)));
203  greekLetters.insert("upsilon", QString(QChar(0x03C5)));
204 
205  greekLetters.insert("phi", QString(QChar(0x03C6)));
206  greekLetters.insert("chi", QString(QChar(0x03C7)));
207  greekLetters.insert("psi", QString(QChar(0x03C8)));
208  greekLetters.insert("omega", QString(QChar(0x03C9)));
209  }
210  };
211  static SearchDialogStaticData staticData;
212 
213  class SimbadSearcher* simbadSearcher;
214  class SimbadLookupReply* simbadReply;
215  QMap<QString, Vec3d> simbadResults;
216  class StelObjectMgr* objectMgr;
217  class QSettings* conf;
218 
220  bool flagHasSelectedText;
221 
222  bool useStartOfWords;
223  bool useSimbad;
225  QString simbadServerUrl;
226  void populateSimbadServerList();
227 
228  // The current coordinate system
229  CoordinateSystem currentCoordinateSystem;
230 
231 public:
232  static QString extSearchText;
233 
234 };
235 
236 #endif // _SEARCHDIALOG_HPP_
237 
void setCurrentCoordinateSystem(CoordinateSystem cs)
Set the current coordinate system.
static const char * DEF_SIMBAD_URL
URL of the default SIMBAD server (Strasbourg).
Base class for all the GUI windows in Stellarium.
Definition: StelDialog.hpp:67
Contains all the information about a current simbad lookup query.
Display a list of results matching the search string, and allow to tab through those selections...
Manage the selection and queries on one or more StelObjects.
CoordinateSystem getCurrentCoordinateSystem() const
Get the current coordinate system.
CoordinateSystem
Available coordinate systems.
The sky object search dialog.
Provides lookup features into the online Simbad service from CDS.