SearchDialog.cpp   SearchDialog.cpp 
skipping to change at line 27 skipping to change at line 27
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#include "Dialog.hpp" #include "Dialog.hpp"
#include "SearchDialog.hpp" #include "SearchDialog.hpp"
#include "ui_searchDialogGui.h" #include "ui_searchDialogGui.h"
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "MovementMgr.hpp" #include "StelMovementMgr.hpp"
#include "StelNavigator.hpp"
#include "StelUtils.hpp"
#include <QTextEdit> #include <QTextEdit>
#include <QLabel> #include <QLabel>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QDebug> #include <QDebug>
#include <QFrame> #include <QFrame>
#include "StelMainGraphicsView.hpp" #include "StelMainGraphicsView.hpp"
#include "SimbadSearcher.hpp"
// Start of members for class CompletionLabel // Start of members for class CompletionLabel
CompletionLabel::CompletionLabel(QWidget* parent) CompletionLabel::CompletionLabel(QWidget* parent) : QLabel(parent), selecte
: QLabel(parent), dIdx(0)
selectedIdx(0)
{ {
} }
CompletionLabel::~CompletionLabel() CompletionLabel::~CompletionLabel()
{ {
} }
QString CompletionLabel::getSelected(void) void CompletionLabel::setValues(const QStringList& v)
{ {
QString item = text().split(",").at(selectedIdx); values=v;
item.replace(QRegExp(" *</?b> *"), ""); updateText();
return item;
} }
void CompletionLabel::selectNext(void) void CompletionLabel::appendValues(const QStringList& v)
{ {
selectedIdx++; values+=v;
if (selectedIdx > text().count(",")) selectedIdx = 0; // wrap if nec updateText();
essary
updateSelected();
} }
void CompletionLabel::selectPrevious(void) void CompletionLabel::clearValues()
{ {
selectedIdx--; values.clear();
if (selectedIdx < 0) selectedIdx = text().count(","); // wrap if nec selectedIdx=0;
essary updateText();
updateSelected();
} }
void CompletionLabel::selectFirst(void) QString CompletionLabel::getSelected()
{ {
selectedIdx=0; if (values.isEmpty())
updateSelected(); return QString();
return values.at(selectedIdx);
} }
void CompletionLabel::updateSelected(void) void CompletionLabel::selectNext()
{ {
QStringList items = text().split(","); ++selectedIdx;
QString newText(""); if (selectedIdx>=values.size())
selectedIdx=0;
updateText();
}
// and pre-selected items, stripping bold tags if found void CompletionLabel::selectPrevious()
for(int i=0; i<selectedIdx; i++) {
{ --selectedIdx;
QString item(items.at(i)); if (selectedIdx<0)
item.replace(QRegExp("</?b>"), ""); selectedIdx = values.size()-1;
newText += item.trimmed() + ", "; updateText();
} }
// add selected item in bold void CompletionLabel::selectFirst()
if (items.at(selectedIdx) != "") newText += "<b>" + items.at(selecte {
dIdx).trimmed() + "</b>, "; selectedIdx=0;
updateText();
}
// and post-selected items, stripping bold tags if found void CompletionLabel::updateText()
for(int i=selectedIdx+1; i<items.size(); i++) {
QString newText;
// Regenerate the list with the selected item in bold
for (int i=0;i<values.size();++i)
{ {
QString item(items.at(i)); if (i==selectedIdx)
item.replace(QRegExp("</?b>"), ""); newText+="<b>"+values[i]+"</b>";
newText += item.trimmed() + ", "; else
newText+=values[i];
if (i!=values.size()-1)
newText += ", ";
} }
// remove final comma
newText.replace(QRegExp(", *$"), "");
setText(newText); setText(newText);
} }
// Start of members for class SearchDialog // Start of members for class SearchDialog
SearchDialog::SearchDialog() SearchDialog::SearchDialog() : simbadReply(NULL)
{ {
ui = new Ui_searchDialogForm; ui = new Ui_searchDialogForm;
simbadSearcher = new SimbadSearcher(this);
} }
SearchDialog::~SearchDialog() SearchDialog::~SearchDialog()
{ {
delete ui; delete ui;
if (simbadReply)
{
simbadReply->deleteLater();
simbadReply = NULL;
}
} }
void SearchDialog::languageChanged() void SearchDialog::languageChanged()
{ {
if (dialog) if (dialog)
{ {
QString text(ui->lineEditSearchSkyObject->text()); QString text(ui->lineEditSearchSkyObject->text());
ui->retranslateUi(dialog); ui->retranslateUi(dialog);
ui->lineEditSearchSkyObject->setText(text); ui->lineEditSearchSkyObject->setText(text);
} }
skipping to change at line 136 skipping to change at line 151
void SearchDialog::styleChanged() void SearchDialog::styleChanged()
{ {
// Nothing for now // Nothing for now
} }
// Initialize the dialog widgets and connect the signals/slots // Initialize the dialog widgets and connect the signals/slots
void SearchDialog::createDialogContent() void SearchDialog::createDialogContent()
{ {
ui->setupUi(dialog); ui->setupUi(dialog);
setSimpleStyle(true);
connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close())) ; connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(close())) ;
connect(ui->lineEditSearchSkyObject, SIGNAL(textChanged(const QStrin g&)), this, SLOT(onTextChanged(const QString&))); connect(ui->lineEditSearchSkyObject, SIGNAL(textChanged(const QStrin g&)), this, SLOT(onTextChanged(const QString&)));
connect(ui->pushButtonGotoSearchSkyObject, SIGNAL(clicked()), this, SLOT(gotoObject())); connect(ui->pushButtonGotoSearchSkyObject, SIGNAL(clicked()), this, SLOT(gotoObject()));
onTextChanged(ui->lineEditSearchSkyObject->text()); onTextChanged(ui->lineEditSearchSkyObject->text());
connect(ui->lineEditSearchSkyObject, SIGNAL(returnPressed()), this, SLOT(gotoObject())); connect(ui->lineEditSearchSkyObject, SIGNAL(returnPressed()), this, SLOT(gotoObject()));
ui->lineEditSearchSkyObject->installEventFilter(this); dialog->installEventFilter(this);
ui->RAAngleSpinBox->setDisplayFormat(AngleSpinBox::HMSLetters);
ui->DEAngleSpinBox->setDisplayFormat(AngleSpinBox::DMSSymbols);
ui->DEAngleSpinBox->setPrefixType(AngleSpinBox::NormalPlus);
// This simply doesn't work. Probably a Qt bug
ui->RAAngleSpinBox->setFocusPolicy(Qt::NoFocus);
ui->DEAngleSpinBox->setFocusPolicy(Qt::NoFocus);
connect(ui->RAAngleSpinBox, SIGNAL(valueChanged()), this, SLOT(manua
lPositionChanged()));
connect(ui->DEAngleSpinBox, SIGNAL(valueChanged()), this, SLOT(manua
lPositionChanged()));
} }
void SearchDialog::setVisible(bool v) void SearchDialog::setVisible(bool v)
{ {
StelDialog::setVisible(v); StelDialog::setVisible(v);
// Set the focus directly on the line edit // Set the focus directly on the line edit
if (ui->lineEditSearchSkyObject->isVisible()) if (ui->lineEditSearchSkyObject->isVisible())
ui->lineEditSearchSkyObject->setFocus(); ui->lineEditSearchSkyObject->setFocus();
} }
void SearchDialog::setSimpleStyle(bool b)
{
ui->RAAngleSpinBox->setVisible(!b);
ui->DEAngleSpinBox->setVisible(!b);
ui->simbadStatusLabel->setVisible(!b);
ui->raDecLabel->setVisible(!b);
}
void SearchDialog::manualPositionChanged()
{
ui->completionLabel->clearValues();
StelMovementMgr* mvmgr = (StelMovementMgr*)GETSTELMODULE("StelMoveme
ntMgr");
Vec3d pos;
StelUtils::spheToRect(ui->RAAngleSpinBox->valueRadians(), ui->DEAngl
eSpinBox->valueRadians(), pos);
mvmgr->moveTo(pos, 0.05);
}
void SearchDialog::onTextChanged(const QString& text) void SearchDialog::onTextChanged(const QString& text)
{ {
if (text=="") if (text.isEmpty())
{ {
ui->completionLabel->setText(""); ui->completionLabel->setText("");
ui->completionLabel->selectFirst(); ui->completionLabel->selectFirst();
ui->simbadStatusLabel->setText("");
} }
else else
{ {
if (simbadReply)
{
disconnect(simbadReply, SIGNAL(statusChanged()), thi
s, SLOT(onSimbadStatusChanged()));
delete simbadReply;
}
simbadResults.clear();
simbadReply = simbadSearcher->lookup(text, 3);
onSimbadStatusChanged();
connect(simbadReply, SIGNAL(statusChanged()), this, SLOT(onS
imbadStatusChanged()));
QStringList matches = StelApp::getInstance().getStelObjectMg r().listMatchingObjectsI18n(text, 5); QStringList matches = StelApp::getInstance().getStelObjectMg r().listMatchingObjectsI18n(text, 5);
ui->completionLabel->setText(matches.join(", ")); ui->completionLabel->setValues(matches);
ui->completionLabel->selectFirst(); ui->completionLabel->selectFirst();
} }
} }
// Called when the current simbad query status changes
void SearchDialog::onSimbadStatusChanged()
{
Q_ASSERT(simbadReply);
if (simbadReply->getCurrentStatus()==SimbadLookupReply::SimbadLookup
ErrorOccured)
ui->simbadStatusLabel->setText(QString("Simbad Lookup Error:
")+simbadReply->getErrorString());
else
ui->simbadStatusLabel->setText(QString("Simbad Lookup: ")+si
mbadReply->getCurrentStatusString());
if (simbadReply->getCurrentStatus()==SimbadLookupReply::SimbadLookup
Finished)
{
simbadResults = simbadReply->getResults();
ui->completionLabel->appendValues(simbadResults.keys());
}
if (simbadReply->getCurrentStatus()!=SimbadLookupReply::SimbadLookup
Querying)
{
disconnect(simbadReply, SIGNAL(statusChanged()), this, SLOT(
onSimbadStatusChanged()));
delete simbadReply;
simbadReply=NULL;
}
}
void SearchDialog::gotoObject() void SearchDialog::gotoObject()
{ {
QString name = ui->completionLabel->getSelected(); QString name = ui->completionLabel->getSelected();
if (name=="") return; if (name.isEmpty())
return;
StelMovementMgr* mvmgr = (StelMovementMgr*)GETSTELMODULE("StelMoveme
ntMgr");
if (simbadResults.contains(name))
{
close();
Vec3d pos = simbadResults[name];
StelApp::getInstance().getStelObjectMgr().unSelect();
pos = StelApp::getInstance().getCore()->getNavigator()->j200
0ToEquinoxEqu(pos);
mvmgr->moveTo(pos, mvmgr->getAutoMoveDuration());
ui->lineEditSearchSkyObject->clear();
ui->completionLabel->clearValues();
}
else if (StelApp::getInstance().getStelObjectMgr().findAndSelectI18n (name)) else if (StelApp::getInstance().getStelObjectMgr().findAndSelectI18n (name))
{ {
MovementMgr* mvmgr = (MovementMgr*)GETSTELMODULE("MovementMg r");
const QList<StelObjectP> newSelected = StelApp::getInstance( ).getStelObjectMgr().getSelectedObject(); const QList<StelObjectP> newSelected = StelApp::getInstance( ).getStelObjectMgr().getSelectedObject();
if (!newSelected.empty()) if (!newSelected.empty())
{ {
close();
ui->lineEditSearchSkyObject->clear(); ui->lineEditSearchSkyObject->clear();
ui->completionLabel->setText(""); ui->completionLabel->clearValues();
ui->completionLabel->selectFirst(); mvmgr->moveTo(newSelected[0]->getEquinoxEquatorialPo
mvmgr->moveTo(newSelected[0]->getObsEquatorialPos(St s(StelApp::getInstance().getCore()->getNavigator()),mvmgr->getAutoMoveDurat
elApp::getInstance().getCore()->getNavigation()),mvmgr->getAutoMoveDuration ion());
());
mvmgr->setFlagTracking(true); mvmgr->setFlagTracking(true);
close();
} }
} }
simbadResults.clear();
} }
bool SearchDialog::eventFilter(QObject *object, QEvent *event) bool SearchDialog::eventFilter(QObject *object, QEvent *event)
{ {
if (object == ui->lineEditSearchSkyObject && event->type() == QEvent ::KeyRelease) if (event->type() == QEvent::KeyRelease)
{ {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if (keyEvent->key() == Qt::Key_Tab || keyEvent->key() == Qt: :Key_Down) if (keyEvent->key() == Qt::Key_Tab || keyEvent->key() == Qt: :Key_Down)
{ {
ui->completionLabel->selectNext(); ui->completionLabel->selectNext();
event->accept();
return true; return true;
} }
if (keyEvent->key() == Qt::Key_Up) if (keyEvent->key() == Qt::Key_Up)
{ {
ui->completionLabel->selectPrevious(); ui->completionLabel->selectPrevious();
event->accept();
return true; return true;
} }
else
return false;
} }
return false; return false;
} }
 End of changes. 39 change blocks. 
58 lines changed or deleted 158 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/