Commit a8767daa authored by Robert Lancaster's avatar Robert Lancaster Committed by Jasem Mutlaq

Further improvements to WIT tool

parent 925f6ebc
......@@ -575,7 +575,7 @@ void KStars::slotShowWIView(int status)
m_wiDock->setAllowedAreas(Qt::RightDockWidgetArea);
QWidget * container = QWidget::createWindowContainer(m_WIView->getWIBaseView());
m_wiDock->setWidget(container);
m_wiDock->setMinimumWidth(container->width());
m_wiDock->setMinimumWidth(300);
addDockWidget(Qt::RightDockWidgetArea, m_wiDock);
m_wiDock->setVisible(true);
}
......
......@@ -371,6 +371,26 @@ Rectangle {
width: parent.width
height: (dispSummary.height >= 130) ? dispSummary.height + 20 : 160
Rectangle{
id: summaryBackground
color: "transparent"
width: parent.width
height: parent.height
Text {
id: dispSummary
objectName: dispObjSummary
text: dispObjSummary
x: image.width + 5
width: parent.width - image.width - 30
color: "#187988"
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
font{
family: "Cantarell"
pixelSize: 13
}
}
}
Image {
id: image
width: 150
......@@ -378,7 +398,6 @@ Rectangle {
source: imageSource
}
Text {
id: dispText
objectName: dispName
......@@ -386,11 +405,20 @@ Rectangle {
color: "white"
font.bold: true
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: dispText.color = "yellow"
onExited: dispText.color = "white"
onEntered:{
dispText.color = "yellow"
dispSummary.color = "yellow"
summaryBackground.color = "#030723"
}
onExited: {
dispText.color = "white"
dispSummary.color = "#187988"
summaryBackground.color ="transparent"
}
onClicked: {
soListView.currentIndex = index
soListView.soListItemClicked(
......@@ -400,21 +428,6 @@ Rectangle {
}
}
}
Text {
id: dispSummary
objectName: dispObjSummary
text: dispObjSummary
x: image.width + 5
width: parent.width - image.width - 30
color: "#187988"
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
font{
family: "Cantarell"
pixelSize: 13
}
}
}
model: soListModel
}
......@@ -449,11 +462,26 @@ Rectangle {
color: "#000000"
}
Image {
id: detailImg
height: 300
width:parent.width - 200
anchors{
right: parent.right
}
objectName: "detailImage"
property string refreshableSource
fillMode: Image.PreserveAspectFit
source: refreshableSource
}
Text {
id: soname
objectName: "sonameObj"
y: 8
width: 273
width: parent.width
height: 22
color: "#ffffff"
text: xi18n("text")
......@@ -468,18 +496,6 @@ Rectangle {
verticalAlignment: Text.AlignVCenter
}
Image {
id: detailImg
anchors{
right: parent.right
}
objectName: "detailImage"
property string refreshableSource
height: 300
fillMode: Image.PreserveAspectFit
source: refreshableSource
}
Text {
id: posText
objectName: "posTextObj"
......@@ -488,7 +504,7 @@ Rectangle {
right: parent.right
rightMargin: 10
}
width: 320
width: parent.width
height: 16
color: "#f7f7ac"
text: xi18n("text")
......@@ -504,7 +520,7 @@ Rectangle {
Rectangle {
id: descTextBox
y: 347
height: 175
height: 200
color: "#010a14"
radius: 10
border.width: 0
......@@ -723,28 +739,17 @@ Rectangle {
Column {
id: detailItemsCol
x: 0
y: 75
width: 200
y: 100
width: parent.width
height: 93
spacing: 14
DetailsItem {
id: sbText
objectName: "sbTextObj"
text: xi18n("Surface Brightness:")
}
id: detailsText
objectName: "detailsTextObj"
DetailsItem {
id: magText
objectName: "magTextObj"
text: xi18n("Magnitude: ")
}
DetailsItem {
id: sizeText
objectName: "sizeTextObj"
text: xi18n("Size: ")
}
}
Column {
......
......@@ -75,7 +75,7 @@ QVariant SkyObjItem::data(int role)
case DispImageRole:
return getImageURL();
case DispSummaryRole:
return getDesc();
return getSummary();
case CategoryRole:
return getType();
case CategoryNameRole:
......@@ -117,16 +117,21 @@ QString SkyObjItem::getImageURL() const
return "";
}
QString fname = KSPaths::locate(QStandardPaths::GenericDataLocation, "thumb-" + m_So->name().toLower().remove( ' ' ) + ".png" ) ;
QString fname = KSPaths::locate(QStandardPaths::GenericDataLocation, "image_" + m_So->name().toLower().remove( ' ' ) + ".png" ) ;
if(fname=="")
fname = KSPaths::locate(QStandardPaths::GenericDataLocation, "thumb-" + m_So->name().toLower().remove( ' ' ) + ".png" ) ;
if(fname=="" && m_Type==Planet){
fname=KSPaths::locate(QStandardPaths::GenericDataLocation, "xplanet/" + getLongName() + ".png" );
fname=KSPaths::locate(QStandardPaths::GenericDataLocation, "xplanet/" + m_So->name() + ".png" );
}
return fname;
}
QString SkyObjItem::getSummary() const
{
return m_So->typeName()+"\n"+getRADE()+"\n"+getAltAz()+"\n";
}
QString SkyObjItem::getDesc() const
{
......@@ -160,7 +165,7 @@ QString SkyObjItem::getDesc() const
if(m_Type == Star)
return xi18n("Bright Star");
return getTypeName();
return m_So->typeName();
}
......@@ -197,7 +202,7 @@ QString SkyObjItem::getSurfaceBrightness() const
{
case Galaxy:
case Nebula:
return QLocale().toString(SB, 2) + " mag/arcmin^2";
return QLocale().toString(SB,'f', 2) + "\n (mag/arcmin^2)";
default:
return QString(" --"); // Not applicable for other sky-objects
}
......@@ -210,9 +215,9 @@ QString SkyObjItem::getSize() const
case Galaxy:
case Cluster:
case Nebula:
return QLocale().toString(((DeepSkyObject *)m_So)->a(), 2) + " arcminutes";
return QLocale().toString(((DeepSkyObject *)m_So)->a(),'f', 2) + "\"";
case Planet:
return QLocale().toString(((KSPlanetBase *)m_So)->angSize(), 2) + " arcseconds";
return QLocale().toString(((KSPlanetBase *)m_So)->angSize(),'f', 2) + "\"";
default:
return QString(" --");
}
......
......@@ -75,7 +75,10 @@ class SkyObjItem
*/
inline QString getLongName() const
{
if(m_LongName==m_Name)
return m_LongName;
else
return m_LongName + "\n (" + m_Name + ")";
}
/**
......@@ -105,6 +108,24 @@ class SkyObjItem
return m_Position;
}
/**
* \brief Get current RA/DE of sky-object associated with the SkyObjItem.
* \return Current RA/DE of sky-object associated with the SkyObjItem.
*/
inline QString getRADE() const
{
return "RA: "+ m_So->ra().toHMSString() + "\nDE: " + m_So->ra().toDMSString();
}
/**
* \brief Get current Altitute and Azimuth of sky-object associated with the SkyObjItem.
* \return Current Altitute and Azimuth of sky-object associated with the SkyObjItem.
*/
inline QString getAltAz() const
{
return "Alt: "+ QString::number(m_So->alt().Degrees(),'f', 2) + ", Az: " + QString::number(m_So->az().Degrees(),'f', 2);
}
/**
* \brief Get sky-object associated with the SkyObjItem.
* \return Pointer to SkyObject associated with the SkyObjItem.
......@@ -117,6 +138,13 @@ class SkyObjItem
QString getImageURL() const;
/**
* \brief Get Summary Description for the SkyObjItem.
* \return Summary Description for the SkyObjItem as a QString.
*/
QString getSummary() const;
/**
* \brief Get description for the SkyObjItem.
* \return Description for the SkyObjItem as a QString.
......
......@@ -25,6 +25,8 @@
#include "dialogs/detaildialog.h"
#include <klocalizedcontext.h>
#include "kspaths.h"
#include "starobject.h"
#ifdef HAVE_INDI
#include <basedevice.h>
......@@ -261,26 +263,77 @@ void WIView::loadDetailsView(SkyObjItem * soitem, int index)
QObject * detailImage = m_DetailsViewObj->findChild<QObject *>("detailImage");
QObject * descTextObj = m_DetailsViewObj->findChild<QObject *>("descTextObj");
QObject * descSrcTextObj = m_DetailsViewObj->findChild<QObject *>("descSrcTextObj");
QObject * magTextObj = m_DetailsViewObj->findChild<QObject *>("magTextObj");
QObject * sbTextObj = m_DetailsViewObj->findChild<QObject *>("sbTextObj");
QObject * sizeTextObj = m_DetailsViewObj->findChild<QObject *>("sizeTextObj");
QObject * detailsTextObj = m_DetailsViewObj->findChild<QObject *>("detailsTextObj");
sonameObj->setProperty("text", soitem->getLongName());
posTextObj->setProperty("text", soitem->getPosition());
detailImage->setProperty("refreshableSource", soitem->getImageURL());
descTextObj->setProperty("text", soitem->getDesc());
if(soitem->getType() != SkyObjItem::Planet)
tryToLoadFromWikipedia(descTextObj, descSrcTextObj, soitem);
descSrcTextObj->setProperty("text", soitem->getDescSource());
QString summary=soitem->getSummary();
QString magText;
if (soitem->getType() == SkyObjItem::Constellation)
magText = xi18n("Magnitude: --");
else
magText = xi18n("Magnitude: %1 mag", QLocale().toString(soitem->getMagnitude(), 2));
magTextObj->setProperty("text", magText);
magText = xi18n("Magnitude: %1", QLocale().toString(soitem->getMagnitude(),'f', 2));
QString sbText = xi18n("Surface Brightness: %1", soitem->getSurfaceBrightness());
sbTextObj->setProperty("text", sbText);
QString sizeText = xi18n("Size: %1", soitem->getSize());
sizeTextObj->setProperty("text", sizeText);
QString details = summary + "\n" + sbText + "\n" + magText + "\n" + sizeText;
detailsTextObj->setProperty("text", details);
}
void WIView::tryToLoadFromWikipedia(QObject * descTextObj, QObject * descSrcTextObj, SkyObjItem * soitem)
{
QString name;
if(soitem->getName().startsWith("M "))
name = soitem->getName().replace("M ","messier_").toLower().remove( ' ' );
else if(soitem->getType() == SkyObjItem::Constellation)
name = soitem->getName().toLower().remove( ' ' ) + "_constellation";
else if(soitem->getType() == SkyObjItem::Star){
StarObject *star=dynamic_cast<StarObject*>(soitem->getSkyObject());
if(star)
name = star->gname().toLower().remove( ' ' ); //the greek name seems to give the most consistent search results.
else
name = soitem->getName().toLower().remove( ' ' );
}else
name = soitem->getName().toLower().remove( ' ' );
QUrl url("https://en.wikipedia.org/w/api.php?action=opensearch&search=" + name + "&format=xml");
QNetworkAccessManager * manager = new QNetworkAccessManager();
QNetworkReply * response = manager->get(QNetworkRequest(url));
connect(manager, &QNetworkAccessManager::finished, this, [descTextObj, descSrcTextObj, manager, response]{
response->deleteLater();
manager->deleteLater();
if (response->error() != QNetworkReply::NoError) return;
QString contentType =
response->header(QNetworkRequest::ContentTypeHeader).toString();
if (!contentType.contains("charset=utf-8")) {
qWarning() << "Content charsets other than utf-8 are not implemented yet.";
return;
}
QString result = QString::fromUtf8(response->readAll());
int leftPos=result.indexOf("<Description")+34;
if(leftPos<34)
return;
int rightPos=result.indexOf("</Description>")-leftPos;
int leftURL=result.indexOf("<Url xml:space=\"preserve\">")+26;
int rightURL=result.indexOf("</Url>")-leftURL;
QString html="<HTML>" + result.mid(leftPos,rightPos) + "</HTML>";
QString srchtml="<HTML>Source: Wikipedia (<a href='" + result.mid(leftURL,rightURL) + "'>" + result.mid(leftURL,rightURL) + "</a>)</HTML>";
descTextObj->setProperty("text", html);
descSrcTextObj->setProperty("text", srchtml);
});
}
......@@ -120,6 +120,9 @@ class WIView : public QWidget
*/
void onReloadIconClicked();
void tryToLoadFromWikipedia(QObject * descTextObj, QObject *descSrcTextObj, SkyObjItem * soitem);
private:
QQuickItem * m_BaseObj, *m_ViewsRowObj, *m_SoListObj, *m_DetailsViewObj,
*m_NextObj, *m_PrevObj, *m_SlewButtonObj, *m_SlewTelescopeButtonObj, *m_DetailsButtonObj;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment