27 #include <kmessagebox.h>
29 #include <QSortFilterProxyModel>
30 #include <QStringListModel>
36 FilterType->addItem( i18n (
"Any") );
37 FilterType->addItem( i18n (
"Stars") );
38 FilterType->addItem( i18n (
"Solar System") );
39 FilterType->addItem( i18n (
"Open Clusters") );
40 FilterType->addItem( i18n (
"Globular Clusters") );
41 FilterType->addItem( i18n (
"Gaseous Nebulae") );
42 FilterType->addItem( i18n (
"Planetary Nebulae") );
43 FilterType->addItem( i18n (
"Galaxies") );
44 FilterType->addItem( i18n (
"Comets") );
45 FilterType->addItem( i18n (
"Asteroids") );
46 FilterType->addItem( i18n (
"Constellations") );
47 FilterType->addItem( i18n (
"Supernovae") );
49 SearchList->setMinimumWidth( 256 );
50 SearchList->setMinimumHeight( 320 );
59 setCaption( i18n(
"Find Object" ) );
60 setButtons( KDialog::Ok|KDialog::User1|KDialog::Cancel );
61 ui->FilterType->setCurrentIndex(0);
63 fModel =
new QStringListModel(
this );
65 sortModel->setFilterCaseSensitivity( Qt::CaseInsensitive );
66 ui->SearchList->setModel( sortModel );
67 sortModel->setSourceModel( fModel );
68 ui->SearchList->setModel( sortModel );
69 setButtonText(KDialog::User1, i18n(
"Details..."));
72 connect(
this, SIGNAL( okClicked() ),
this, SLOT(
slotOk() ) );
73 connect(
this, SIGNAL( cancelClicked() ),
this, SLOT( reject() ) );
74 connect(
this, SIGNAL(user1Clicked()),
this, SLOT(slotDetails()));
75 connect( ui->SearchBox, SIGNAL( textChanged(
const QString & ) ), SLOT( enqueueSearch() ) );
76 connect( ui->SearchBox, SIGNAL( returnPressed() ), SLOT(
slotOk() ) );
77 connect( ui->FilterType, SIGNAL( activated(
int ) ),
this, SLOT( enqueueSearch() ) );
78 connect( ui->SearchList, SIGNAL( doubleClicked(
const QModelIndex & ) ), SLOT(
slotOk() ) );
81 ui->SearchBox->setFocus();
84 QTimer::singleShot(0,
this, SLOT( init() ));
91 void FindDialog::init() {
92 ui->SearchBox->clear();
98 void FindDialog::initSelection() {
99 if ( sortModel->rowCount() <= 0 ) {
100 button( Ok )->setEnabled(
false );
104 if ( ui->SearchBox->text().isEmpty() ) {
106 QModelIndex selectItem = sortModel->index( 0, sortModel->filterKeyColumn(), QModelIndex() );
107 switch ( ui->FilterType->currentIndex() ) {
110 QModelIndex qmi = fModel->index( fModel->stringList().indexOf( i18n(
"Andromeda Galaxy") ) );
111 selectItem = sortModel->mapFromSource( qmi );
116 QModelIndex qmi = fModel->index( fModel->stringList().indexOf( i18n(
"Aldebaran") ) );
117 selectItem = sortModel->mapFromSource( qmi );
123 QModelIndex qmi = fModel->index( fModel->stringList().indexOf( i18n(
"Aaltje") ) );
124 selectItem = sortModel->mapFromSource( qmi );
129 QModelIndex qmi = fModel->index( fModel->stringList().indexOf( i18n(
"Aarseth-Brewington (1989 W1)") ) );
130 selectItem = sortModel->mapFromSource( qmi );
136 if ( selectItem.isValid() ) {
137 ui->SearchList->selectionModel()->select( selectItem, QItemSelectionModel::ClearAndSelect );
138 ui->SearchList->scrollTo( selectItem );
139 ui->SearchList->setCurrentIndex( selectItem );
140 button( Ok )->setEnabled(
true );
147 void FindDialog::filterByType() {
150 switch ( ui->FilterType->currentIndex() ) {
153 QStringList allObjects;
156 fModel->setStringList( allObjects );
161 QStringList starObjects;
164 fModel->setStringList( starObjects );
169 QStringList ssObjects;
174 ssObjects += i18n(
"Sun");
175 fModel->setStringList( ssObjects );
210 SearchText = processSearchText();
211 sortModel->setFilterFixedString( SearchText );
216 if ( !SearchText.isEmpty() ) {
217 QStringList mItems = fModel->stringList().filter( QRegExp(
'^'+SearchText, Qt::CaseInsensitive ) );
220 if ( mItems.size() ) {
221 QModelIndex qmi = fModel->index( fModel->stringList().indexOf( mItems[0] ) );
222 QModelIndex selectItem = sortModel->mapFromSource( qmi );
224 if ( selectItem.isValid() ) {
225 ui->SearchList->selectionModel()->select( selectItem, QItemSelectionModel::ClearAndSelect );
226 ui->SearchList->scrollTo( selectItem );
227 ui->SearchList->setCurrentIndex( selectItem );
228 button( Ok )->setEnabled(
true );
237 QModelIndex i = ui->SearchList->currentIndex();
240 QString ObjName = i.data().toString();
244 QString stext = ui->SearchBox->text();
245 if( stext.startsWith( QLatin1String(
"HD" ) ) ) {
246 stext.remove(
"HD" );
248 int HD = stext.toInt( &ok );
258 void FindDialog::enqueueSearch() {
259 listFiltered =
false;
263 timer =
new QTimer(
this );
264 timer->setSingleShot(
true );
265 connect( timer, SIGNAL( timeout() ),
this, SLOT( filterList() ) );
271 QString FindDialog::processSearchText() {
273 QString searchtext = ui->SearchBox->text();
275 re.setCaseSensitivity( Qt::CaseInsensitive );
278 re.setPattern(
"^(m|ngc|ic)\\s*\\d*$");
279 if(ui->SearchBox->text().contains(re)) {
280 re.setPattern(
"\\s*(\\d+)");
281 searchtext.replace( re,
" \\1" );
282 re.setPattern(
"\\s*$");
283 searchtext.remove( re );
284 re.setPattern(
"^\\s*");
285 searchtext.remove( re );
301 selObj = selectedObject();
303 QString message = i18n(
"No object named %1 found.", ui->SearchBox->text() );
304 KMessageBox::sorry( 0, message, i18n(
"Bad object name" ) );
312 case Qt::Key_Escape :
317 int currentRow = ui->SearchList->currentIndex().row();
318 if ( currentRow > 0 ) {
319 QModelIndex selectItem = sortModel->index( currentRow-1, sortModel->filterKeyColumn(), QModelIndex() );
320 ui->SearchList->selectionModel()->setCurrentIndex( selectItem, QItemSelectionModel::SelectCurrent );
326 int currentRow = ui->SearchList->currentIndex().row();
327 if ( currentRow < sortModel->rowCount()-1 ) {
328 QModelIndex selectItem = sortModel->index( currentRow+1, sortModel->filterKeyColumn(), QModelIndex() );
329 ui->SearchList->selectionModel()->setCurrentIndex( selectItem, QItemSelectionModel::SelectCurrent );
336 void FindDialog::slotDetails()
338 if ( selectedObject() ) {
346 #include "finddialog.moc"
window showing detailed information for a selected object.
KStarsData is the backbone of KStars.
FindDialog(QWidget *parent=0)
Constructor.
static KStarsData * Instance()
static KStars * Instance()
static StarComponent * Instance()
virtual ~FindDialog()
Destructor.
SkyObject * selectedObject() const
SkyMapComposite * skyComposite()
void filterList()
When Text is entered in the QLineEdit, filter the List of objects so that only objects which start wi...
SkyObject * findByHDIndex(int HDnum)
Find stars by HD catalog index.
virtual SkyObject * findByName(const QString &name)
Search the children of this SkyMapComposite for a SkyObject whose name matches the argument...
void slotOk()
Overloading the Standard KDialogBase slotOk() to show a "sorry" message box if no object is selected ...
QHash< int, QStringList > & objectNames()
Provides all necessary information about an object in the sky: its coordinates, name(s), type, magnitude, and QStringLists of URLs for images and webpages regarding the object.
void keyPressEvent(QKeyEvent *e)
Process Keystrokes.
FindDialogUI(QWidget *parent=0)