Stellarium 0.15.2
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  supergalactic,
87  ecliptic,
88  eclipticJ2000
89  };
90 
91  SearchDialog(QObject* parent);
92  virtual ~SearchDialog();
94  void styleChanged();
95  bool eventFilter(QObject *object, QEvent *event);
96 
97 
100  static QString substituteGreek(const QString& keyString);
102  static QString getGreekLetterByName(const QString& potentialGreekLetterName);
104  static const char* DEF_SIMBAD_URL;
105 public slots:
106  void retranslate();
108  void setSimpleStyle();
109 
112  {
113  currentCoordinateSystem = cs;
114  }
117  {
118  return currentCoordinateSystem;
119  }
121  QString getCurrentCoordinateSystemKey(void) const;
123  void setCurrentCoordinateSystemKey(QString key);
124 
125  void setCoordinateSystem(int csID);
126  void populateCoordinateSystemsList();
127  void populateCoordinateAxis();
128 
129 protected:
130  Ui_searchDialogForm* ui;
132  virtual void createDialogContent();
133 
134 private slots:
135  void greekLetterClicked();
137  void onSimbadStatusChanged();
139  void onSearchTextChanged(const QString& text);
140 
141  void gotoObject();
142  void gotoObject(const QString& nameI18n);
143  // for going from list views
144  void gotoObject(QListWidgetItem* item);
145 
146  void searchListChanged(const QString& newText);
147 
149  void manualPositionChanged();
150 
152  void enableSimbadSearch(bool enable);
153 
155  void enableStartOfWordsAutofill(bool enable);
156 
158  void enableLockPosition(bool enable);
159 
161  void setHasSelectedFlag();
162 
164  void selectSimbadServer(int index);
165 
167  void updateListWidget(int index);
168 
169  // retranslate/recreate tab
170  void updateListTab();
171 
172  void showContextMenu(const QPoint &pt);
173 
174  void pasteAndGo();
175 
176 private:
177  class SearchDialogStaticData
178  {
179  public:
181  QHash<QString, QString> greekLetters;
182 
183  SearchDialogStaticData()
184  {
185  greekLetters.insert("alpha", QString(QChar(0x03B1)));
186  greekLetters.insert("beta", QString(QChar(0x03B2)));
187  greekLetters.insert("gamma", QString(QChar(0x03B3)));
188  greekLetters.insert("delta", QString(QChar(0x03B4)));
189  greekLetters.insert("epsilon", QString(QChar(0x03B5)));
190 
191  greekLetters.insert("zeta", QString(QChar(0x03B6)));
192  greekLetters.insert("eta", QString(QChar(0x03B7)));
193  greekLetters.insert("theta", QString(QChar(0x03B8)));
194  greekLetters.insert("iota", QString(QChar(0x03B9)));
195  greekLetters.insert("kappa", QString(QChar(0x03BA)));
196 
197  greekLetters.insert("lambda", QString(QChar(0x03BB)));
198  greekLetters.insert("mu", QString(QChar(0x03BC)));
199  greekLetters.insert("nu", QString(QChar(0x03BD)));
200  greekLetters.insert("xi", QString(QChar(0x03BE)));
201  greekLetters.insert("omicron", QString(QChar(0x03BF)));
202 
203  greekLetters.insert("pi", QString(QChar(0x03C0)));
204  greekLetters.insert("rho", QString(QChar(0x03C1)));
205  greekLetters.insert("sigma", QString(QChar(0x03C3))); // second lower-case sigma shouldn't affect anything
206  greekLetters.insert("tau", QString(QChar(0x03C4)));
207  greekLetters.insert("upsilon", QString(QChar(0x03C5)));
208 
209  greekLetters.insert("phi", QString(QChar(0x03C6)));
210  greekLetters.insert("chi", QString(QChar(0x03C7)));
211  greekLetters.insert("psi", QString(QChar(0x03C8)));
212  greekLetters.insert("omega", QString(QChar(0x03C9)));
213  }
214  };
215  static SearchDialogStaticData staticData;
216 
217  class SimbadSearcher* simbadSearcher;
218  class SimbadLookupReply* simbadReply;
219  QMap<QString, Vec3d> simbadResults;
220  class StelObjectMgr* objectMgr;
221  class QSettings* conf;
222 
224  bool flagHasSelectedText;
225 
226  bool useStartOfWords;
227  bool useLockPosition;
228  bool useSimbad;
230  QString simbadServerUrl;
231  void populateSimbadServerList();
232 
233  // The current coordinate system
234  CoordinateSystem currentCoordinateSystem;
235 
236 public:
237  static QString extSearchText;
238 
239 };
240 
241 #endif // _SEARCHDIALOG_HPP_
242 
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:72
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.