~ubuntu-branches/ubuntu/precise/kstars/precise-proposed

« back to all changes in this revision

Viewing changes to kstars/printing/detailstable.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-16 13:14:42 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111216131442-dfrjlt6pests9qu1
Tags: 4:4.7.90-0ubuntu1
New upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          detailstable.cpp  -  K Desktop Planetarium
 
3
                             -------------------
 
4
    begin                : Fri Jul 29 2011
 
5
    copyright            : (C) 2011 by Rafał Kułaga
 
6
    email                : rl.kulaga@gmail.com
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
 
 
18
#include "detailstable.h"
 
19
 
 
20
#include "QTextDocument"
 
21
#include "QTextTable"
 
22
#include "kstars.h"
 
23
#include "kstarsdata.h"
 
24
#include "ksplanetbase.h"
 
25
#include "starobject.h"
 
26
#include "skymapcomposite.h"
 
27
#include "constellationboundarylines.h"
 
28
#include "deepskyobject.h"
 
29
#include "customcatalogcomponent.h"
 
30
#include "ksmoon.h"
 
31
#include "ksplanetbase.h"
 
32
#include "ksasteroid.h"
 
33
#include "kscomet.h"
 
34
 
 
35
DetailsTable::DetailsTable()
 
36
{
 
37
    m_Document = new QTextDocument(KStars::Instance());
 
38
 
 
39
    setDefaultFormatting();
 
40
}
 
41
 
 
42
DetailsTable::~DetailsTable()
 
43
{
 
44
    if(m_Document)
 
45
    {
 
46
        delete m_Document;
 
47
    }
 
48
}
 
49
 
 
50
void DetailsTable::createGeneralTable(SkyObject *obj)
 
51
{
 
52
    clearContents();
 
53
 
 
54
    QTextCursor cursor = m_Document->rootFrame()->firstCursorPosition();
 
55
 
 
56
    //Fill in the data fields
 
57
    //Contents depend on type of object
 
58
    StarObject *s = 0;
 
59
    DeepSkyObject *dso = 0;
 
60
    KSPlanetBase *ps = 0;
 
61
    QString pname, oname;
 
62
 
 
63
    QString objNamesVal, objTypeVal, objDistVal, objSizeVal, objMagVal, objBvVal, objIllumVal;
 
64
    QString objSizeLabel, objMagLabel;
 
65
 
 
66
    switch(obj->type())
 
67
    {
 
68
    case SkyObject::STAR:
 
69
        {
 
70
            s = (StarObject *)obj;
 
71
 
 
72
            objNamesVal = s->longname();
 
73
 
 
74
            if(s->getHDIndex() != 0)
 
75
            {
 
76
                if(!s->longname().isEmpty())
 
77
                {
 
78
                    objNamesVal = s->longname() + QString(", HD%1").arg(QString::number(s->getHDIndex())) ;
 
79
                }
 
80
 
 
81
                else
 
82
                {
 
83
                    objNamesVal = QString(", HD%1").arg(QString::number(s->getHDIndex()));
 
84
                }
 
85
            }
 
86
 
 
87
            objTypeVal = s->sptype() + ' ' + i18n("star");
 
88
            objMagVal = i18nc("number in magnitudes", "%1 mag", KGlobal::locale()->formatNumber(s->mag(), 1)); //show to tenths place
 
89
 
 
90
            if(s->getBVIndex() < 30.0)
 
91
            {
 
92
                objBvVal = QString::number(s->getBVIndex(), 'g', 2);
 
93
            }
 
94
 
 
95
            //distance
 
96
            if(s->distance() > 2000. || s->distance() < 0.)  // parallax < 0.5 mas
 
97
            {
 
98
                objDistVal = i18nc("larger than 2000 parsecs", "> 2000 pc");
 
99
            }
 
100
 
 
101
            else if(s->distance() > 50.0) //show to nearest integer
 
102
            {
 
103
                objDistVal = i18nc("number in parsecs", "%1 pc", KGlobal::locale()->formatNumber(s->distance(), 0));
 
104
            }
 
105
 
 
106
            else if(s->distance() > 10.0) //show to tenths place
 
107
            {
 
108
                objDistVal = i18nc("number in parsecs", "%1 pc", KGlobal::locale()->formatNumber(s->distance(), 1));
 
109
            }
 
110
 
 
111
            else //show to hundredths place
 
112
            {
 
113
                objDistVal = i18nc("number in parsecs", "%1 pc", KGlobal::locale()->formatNumber(s->distance(), 2));
 
114
            }
 
115
 
 
116
            //Note multiplicity/variablility in angular size label
 
117
            if(s->isMultiple() && s->isVariable())
 
118
            {
 
119
                objSizeLabel = i18nc("the star is a multiple star", "multiple") + ',';
 
120
                objSizeVal = i18nc("the star is a variable star", "variable");
 
121
            }
 
122
 
 
123
            else if(s->isMultiple())
 
124
            {
 
125
                objSizeLabel = i18nc("the star is a multiple star", "multiple");
 
126
            }
 
127
 
 
128
            else if(s->isVariable())
 
129
            {
 
130
                objSizeLabel = i18nc("the star is a variable star", "variable");
 
131
            }
 
132
 
 
133
            objIllumVal = "--";
 
134
 
 
135
            break; //End of stars case
 
136
        }
 
137
 
 
138
    case SkyObject::ASTEROID:  //[fall through to planets]
 
139
 
 
140
    case SkyObject::COMET:     //[fall through to planets]
 
141
 
 
142
    case SkyObject::MOON:      //[fall through to planets]
 
143
 
 
144
    case SkyObject::PLANET:
 
145
        {
 
146
            ps = (KSPlanetBase *)obj;
 
147
 
 
148
            objNamesVal = ps->longname();
 
149
            //Type is "G5 star" for Sun
 
150
            if(ps->name() == "Sun")
 
151
            {
 
152
                objTypeVal = i18n("G5 star");
 
153
            }
 
154
 
 
155
            else if(ps->name() == "Moon")
 
156
            {
 
157
                objTypeVal = ps->translatedName();
 
158
            }
 
159
 
 
160
            else if(ps->name() == i18n("Pluto") || ps->name() == "Ceres" || ps->name() == "Eris") // TODO: Check if Ceres / Eris have translations and i18n() them
 
161
            {
 
162
                objTypeVal = i18n("Dwarf planet");
 
163
            }
 
164
 
 
165
            else
 
166
            {
 
167
                objTypeVal = ps->typeName();
 
168
            }
 
169
 
 
170
            //Magnitude: The moon displays illumination fraction instead
 
171
            if(obj->name() == "Moon")
 
172
            {
 
173
                objIllumVal = QString("%1 %").arg(KGlobal::locale()->formatNumber(((KSMoon *)obj)->illum()*100., 0));
 
174
            }
 
175
 
 
176
            objMagVal = i18nc("number in magnitudes", "%1 mag", KGlobal::locale()->formatNumber(ps->mag(), 1)); //show to tenths place
 
177
 
 
178
            //Distance from Earth.  The moon requires a unit conversion
 
179
            if(ps->name() == "Moon")
 
180
            {
 
181
                objDistVal = i18nc("distance in kilometers", "%1 km", KGlobal::locale()->formatNumber(ps->rearth() * AU_KM ));
 
182
            }
 
183
 
 
184
            else
 
185
            {
 
186
                objDistVal = i18nc("distance in Astronomical Units", "%1 AU", KGlobal::locale()->formatNumber(ps->rearth()));
 
187
            }
 
188
 
 
189
            //Angular size; moon and sun in arcmin, others in arcsec
 
190
            if(ps->angSize())
 
191
            {
 
192
                if(ps->name() == "Sun" || ps->name() == "Moon")
 
193
                {
 
194
                    // Needn't be a plural form because sun / moon will never contract to 1 arcminute
 
195
                    objSizeVal = i18nc("angular size in arcminutes", "%1 arcmin", KGlobal::locale()->formatNumber(ps->angSize()));
 
196
                }
 
197
 
 
198
                else
 
199
                {
 
200
                    objSizeVal = i18nc("angular size in arcseconds","%1 arcsec", KGlobal::locale()->formatNumber(ps->angSize() * 60.0));
 
201
                }
 
202
            }
 
203
 
 
204
            else
 
205
            {
 
206
                objSizeVal = "--";
 
207
            }
 
208
 
 
209
            break; //End of planets/comets/asteroids case
 
210
        }
 
211
 
 
212
    default: //Deep-sky objects
 
213
        {
 
214
            dso = (DeepSkyObject *)obj;
 
215
 
 
216
            //Show all names recorded for the object
 
217
            if(!dso->longname().isEmpty() && dso->longname() != dso->name())
 
218
            {
 
219
                pname = dso->translatedLongName();
 
220
                oname = dso->translatedName();
 
221
            }
 
222
 
 
223
            else
 
224
            {
 
225
                pname = dso->translatedName();
 
226
            }
 
227
 
 
228
            if(!dso->translatedName2().isEmpty())
 
229
            {
 
230
                if(oname.isEmpty())
 
231
                {
 
232
                    oname = dso->translatedName2();
 
233
                }
 
234
 
 
235
                else
 
236
                {
 
237
                    oname += ", " + dso->translatedName2();
 
238
                }
 
239
            }
 
240
 
 
241
            if(dso->ugc() != 0)
 
242
            {
 
243
                if(!oname.isEmpty())
 
244
                {
 
245
                    oname += ", ";
 
246
                }
 
247
 
 
248
                oname += "UGC " + QString::number(dso->ugc());
 
249
            }
 
250
            if(dso->pgc() != 0)
 
251
            {
 
252
                if(!oname.isEmpty())
 
253
                {
 
254
                    oname += ", ";
 
255
                }
 
256
 
 
257
                oname += "PGC " + QString::number(dso->pgc());
 
258
            }
 
259
 
 
260
            if(!oname.isEmpty())
 
261
            {
 
262
                pname += ", " + oname;
 
263
            }
 
264
 
 
265
            objNamesVal = pname;
 
266
 
 
267
            objTypeVal = dso->typeName();
 
268
 
 
269
            if(dso->type() == SkyObject::RADIO_SOURCE)
 
270
            {
 
271
                objMagLabel = i18nc("integrated flux at a frequency", "Flux(%1):", dso->customCatalog()->fluxFrequency());
 
272
                objMagVal = i18nc("integrated flux value", "%1 %2", KGlobal::locale()->formatNumber(dso->flux(), 1),
 
273
                                  dso->customCatalog()->fluxUnit()); //show to tenths place
 
274
            }
 
275
 
 
276
            else if(dso->mag() > 90.0)
 
277
            {
 
278
                objMagVal = "--";
 
279
            }
 
280
 
 
281
            else
 
282
            {
 
283
                objMagVal = i18nc("number in magnitudes", "%1 mag", KGlobal::locale()->formatNumber(dso->mag(), 1)); //show to tenths place
 
284
            }
 
285
 
 
286
            //No distances at this point...
 
287
            objDistVal = "--";
 
288
 
 
289
            //Only show decimal place for small angular sizes
 
290
            if(dso->a() > 10.0)
 
291
            {
 
292
                objSizeVal = i18nc("angular size in arcminutes", "%1 arcmin", KGlobal::locale()->formatNumber(dso->a(), 0));
 
293
            }
 
294
 
 
295
            else if(dso->a())
 
296
            {
 
297
                objSizeVal = i18nc("angular size in arcminutes", "%1 arcmin", KGlobal::locale()->formatNumber(dso->a(), 1));
 
298
            }
 
299
 
 
300
            else
 
301
            {
 
302
                objSizeVal = "--";
 
303
            }
 
304
 
 
305
            break; //End of deep-space objects case
 
306
        }
 
307
    }
 
308
 
 
309
    //Common to all types:
 
310
    if(obj->type() == SkyObject::CONSTELLATION )
 
311
    {
 
312
        objTypeVal = KStarsData::Instance()->skyComposite()->getConstellationBoundary()->constellationName(obj);
 
313
    }
 
314
 
 
315
    else
 
316
    {
 
317
        objTypeVal = i18nc("%1 type of sky object (planet, asteroid etc), %2 name of a constellation", "%1 in %2", objTypeVal,
 
318
                           KStarsData::Instance()->skyComposite()->getConstellationBoundary()->constellationName(obj));
 
319
    }
 
320
 
 
321
    QVector<QTextLength> constraints;
 
322
    constraints << QTextLength(QTextLength::PercentageLength, 25)
 
323
                << QTextLength(QTextLength::PercentageLength, 25)
 
324
                << QTextLength(QTextLength::PercentageLength, 25)
 
325
                << QTextLength(QTextLength::PercentageLength, 25);
 
326
    m_TableFormat.setColumnWidthConstraints(constraints);
 
327
 
 
328
    QTextTable *table = cursor.insertTable(5, 4, m_TableFormat);
 
329
    table->mergeCells(0, 0, 1, 4);
 
330
    QTextBlockFormat centered;
 
331
    centered.setAlignment(Qt::AlignCenter);
 
332
    table->cellAt(0, 0).firstCursorPosition().setBlockFormat(centered);
 
333
    table->cellAt(0, 0).firstCursorPosition().insertText(i18n("General"), m_TableTitleCharFormat);
 
334
 
 
335
    table->mergeCells(1, 1, 1, 3);
 
336
    table->cellAt(1, 0).firstCursorPosition().insertText(i18n("Names:"), m_ItemNameCharFormat);
 
337
    table->cellAt(1, 0).firstCursorPosition().setBlockFormat(centered);
 
338
    table->cellAt(1, 1).firstCursorPosition().insertText(objNamesVal, m_ItemValueCharFormat);
 
339
 
 
340
    table->cellAt(2, 0).firstCursorPosition().insertText(i18n("Type:"), m_ItemNameCharFormat);
 
341
    table->cellAt(2, 0).firstCursorPosition().setBlockFormat(centered);
 
342
    table->cellAt(2, 1).firstCursorPosition().insertText(objTypeVal, m_ItemValueCharFormat);
 
343
 
 
344
    table->cellAt(3, 0).firstCursorPosition().insertText(i18n("Distance:"), m_ItemNameCharFormat);
 
345
    table->cellAt(3, 0).firstCursorPosition().setBlockFormat(centered);
 
346
    table->cellAt(3, 1).firstCursorPosition().insertText(objDistVal, m_ItemValueCharFormat);
 
347
 
 
348
    table->cellAt(4, 0).firstCursorPosition().insertText(i18n("Size:"), m_ItemNameCharFormat);
 
349
    table->cellAt(4, 0).firstCursorPosition().setBlockFormat(centered);
 
350
    table->cellAt(4, 1).firstCursorPosition().insertText(objSizeVal, m_ItemValueCharFormat);
 
351
 
 
352
    table->cellAt(2, 2).firstCursorPosition().insertText(i18n("Magnitude:"), m_ItemNameCharFormat);
 
353
    table->cellAt(2, 2).firstCursorPosition().setBlockFormat(centered);
 
354
    table->cellAt(2, 3).firstCursorPosition().insertText(objMagVal, m_ItemValueCharFormat);
 
355
 
 
356
    table->cellAt(3, 2).firstCursorPosition().insertText(i18n("B-V index:"), m_ItemNameCharFormat);
 
357
    table->cellAt(3, 2).firstCursorPosition().setBlockFormat(centered);
 
358
    table->cellAt(3, 3).firstCursorPosition().insertText(objBvVal, m_ItemValueCharFormat);
 
359
 
 
360
    table->cellAt(4, 2).firstCursorPosition().insertText(i18n("Illumination:"), m_ItemNameCharFormat);
 
361
    table->cellAt(4, 2).firstCursorPosition().setBlockFormat(centered);
 
362
    table->cellAt(4, 3).firstCursorPosition().insertText(objIllumVal, m_ItemValueCharFormat);
 
363
}
 
364
 
 
365
void DetailsTable::createAsteroidCometTable(SkyObject *obj)
 
366
{
 
367
    clearContents();
 
368
 
 
369
    QTextCursor cursor = m_Document->rootFrame()->firstCursorPosition();
 
370
 
 
371
    QString perihelionVal, orbitIdVal, neoVal, diamVal, rotPeriodVal, moidVal;
 
372
    QString orbitClassVal, albedoVal, dimVal, periodVal;
 
373
 
 
374
    // Add specifics data
 
375
    switch(obj->type())
 
376
    {
 
377
    case SkyObject::ASTEROID:
 
378
        {
 
379
            KSAsteroid* ast = (KSAsteroid *)obj;
 
380
 
 
381
            // Perihelion
 
382
            perihelionVal = QString::number(ast->getPerihelion()) + " AU";
 
383
 
 
384
            // Earth MOID
 
385
            moidVal = ast->getEarthMOID() == 0 ? QString("--") : QString::number(ast->getEarthMOID()) + QString(" AU");
 
386
 
 
387
            // Orbit ID
 
388
            orbitIdVal = ast->getOrbitID();
 
389
 
 
390
            // Orbit Class
 
391
            orbitClassVal = ast->getOrbitClass();
 
392
 
 
393
            // NEO
 
394
            neoVal = ast->isNEO() ? i18n("Yes") : i18n("No");
 
395
 
 
396
            // Albedo
 
397
            albedoVal = ast->getAlbedo() == 0 ? QString("--") : QString::number(ast->getAlbedo());
 
398
 
 
399
            // Diameter
 
400
            diamVal = ast->getDiameter() == 0 ? QString("--") : QString::number(ast->getDiameter()) + QString(" km");
 
401
 
 
402
            // Dimensions
 
403
            dimVal = ast->getDimensions().isEmpty() ? QString("--") : ast->getDimensions() + QString(" km");
 
404
 
 
405
            // Rotation period
 
406
            rotPeriodVal = ast->getRotationPeriod() == 0 ? QString("--") : QString::number(ast->getRotationPeriod()) + QString(" h");
 
407
 
 
408
            // Period
 
409
            periodVal = ast->getPeriod() == 0 ? QString("--") : QString::number(ast->getPeriod()) + QString(" y");
 
410
 
 
411
            break;
 
412
        }
 
413
 
 
414
    case SkyObject::COMET:
 
415
        {
 
416
            KSComet* com = (KSComet *)obj;
 
417
 
 
418
            // Perihelion
 
419
            perihelionVal = QString::number(com->getPerihelion()) + " AU";
 
420
 
 
421
            // Earth MOID
 
422
            moidVal = com->getEarthMOID() == 0 ? QString("--") : QString::number(com->getEarthMOID()) + QString(" AU");
 
423
 
 
424
            // Orbit ID
 
425
            orbitIdVal = com->getOrbitID();
 
426
 
 
427
            // Orbit Class
 
428
            orbitClassVal = com->getOrbitClass();
 
429
 
 
430
            // NEO
 
431
            neoVal = com->isNEO() ? i18n("Yes") : i18n("No");
 
432
 
 
433
            // Albedo
 
434
            albedoVal = com->getAlbedo() == 0 ? QString("--") : QString::number(com->getAlbedo());
 
435
 
 
436
            // Diameter
 
437
            diamVal = com->getDiameter() == 0 ? QString("--") : QString::number(com->getDiameter()) + QString(" km");
 
438
 
 
439
            // Dimensions
 
440
            dimVal = com->getDimensions().isEmpty() ? QString("--") : com->getDimensions() + QString(" km");
 
441
 
 
442
            // Rotation period
 
443
            rotPeriodVal = com->getRotationPeriod() == 0 ? QString("--") : QString::number(com->getRotationPeriod()) + QString(" h");
 
444
 
 
445
            // Period
 
446
            periodVal = com->getPeriod() == 0 ? QString("--") : QString::number(com->getPeriod()) + QString(" y");
 
447
 
 
448
            break;
 
449
        }
 
450
 
 
451
    default:
 
452
        {
 
453
            return;
 
454
        }
 
455
    }
 
456
 
 
457
    // Set column width constraints
 
458
    QVector<QTextLength> constraints;
 
459
    constraints << QTextLength(QTextLength::PercentageLength, 25)
 
460
                << QTextLength(QTextLength::PercentageLength, 25)
 
461
                << QTextLength(QTextLength::PercentageLength, 25)
 
462
                << QTextLength(QTextLength::PercentageLength, 25);
 
463
    m_TableFormat.setColumnWidthConstraints(constraints);
 
464
 
 
465
    QTextTable *table = cursor.insertTable(6, 4, m_TableFormat);
 
466
    table->mergeCells(0, 0, 1, 4);
 
467
    QTextBlockFormat centered;
 
468
    centered.setAlignment(Qt::AlignCenter);
 
469
    table->cellAt(0, 0).firstCursorPosition().setBlockFormat(centered);
 
470
    table->cellAt(0, 0).firstCursorPosition().insertText(i18n("Asteroid/Comet details"), m_TableTitleCharFormat);
 
471
 
 
472
    table->cellAt(1, 0).firstCursorPosition().insertText(i18n("Perihelion:"), m_ItemNameCharFormat);
 
473
    table->cellAt(1, 0).firstCursorPosition().setBlockFormat(centered);
 
474
    table->cellAt(1, 1).firstCursorPosition().insertText(perihelionVal, m_ItemValueCharFormat);
 
475
 
 
476
    table->cellAt(2, 0).firstCursorPosition().insertText(i18n("Orbit ID:"), m_ItemNameCharFormat);
 
477
    table->cellAt(2, 0).firstCursorPosition().setBlockFormat(centered);
 
478
    table->cellAt(2, 1).firstCursorPosition().insertText(orbitIdVal, m_ItemValueCharFormat);
 
479
 
 
480
    table->cellAt(3, 0).firstCursorPosition().insertText(i18n("NEO:"), m_ItemNameCharFormat);
 
481
    table->cellAt(3, 0).firstCursorPosition().setBlockFormat(centered);
 
482
    table->cellAt(3, 1).firstCursorPosition().insertText(neoVal, m_ItemValueCharFormat);
 
483
 
 
484
    table->cellAt(4, 0).firstCursorPosition().insertText(i18n("Diameter:"), m_ItemNameCharFormat);
 
485
    table->cellAt(4, 0).firstCursorPosition().setBlockFormat(centered);
 
486
    table->cellAt(4, 1).firstCursorPosition().insertText(diamVal, m_ItemValueCharFormat);
 
487
 
 
488
    table->cellAt(5, 0).firstCursorPosition().insertText(i18n("Rotation period:"), m_ItemNameCharFormat);
 
489
    table->cellAt(5, 0).firstCursorPosition().setBlockFormat(centered);
 
490
    table->cellAt(5, 1).firstCursorPosition().insertText(rotPeriodVal, m_ItemValueCharFormat);
 
491
 
 
492
    table->cellAt(1, 2).firstCursorPosition().insertText(i18n("Earth MOID:"), m_ItemNameCharFormat);
 
493
    table->cellAt(1, 2).firstCursorPosition().setBlockFormat(centered);
 
494
    table->cellAt(1, 3).firstCursorPosition().insertText(moidVal, m_ItemValueCharFormat);
 
495
 
 
496
    table->cellAt(2, 2).firstCursorPosition().insertText(i18n("Orbit class:"), m_ItemNameCharFormat);
 
497
    table->cellAt(2, 2).firstCursorPosition().setBlockFormat(centered);
 
498
    table->cellAt(2, 3).firstCursorPosition().insertText(orbitClassVal, m_ItemValueCharFormat);
 
499
 
 
500
    table->cellAt(3, 2).firstCursorPosition().insertText(i18n("Albedo:"), m_ItemNameCharFormat);
 
501
    table->cellAt(3, 2).firstCursorPosition().setBlockFormat(centered);
 
502
    table->cellAt(3, 3).firstCursorPosition().insertText(albedoVal, m_ItemValueCharFormat);
 
503
 
 
504
    table->cellAt(4, 2).firstCursorPosition().insertText(i18n("Dimensions:"), m_ItemNameCharFormat);
 
505
    table->cellAt(4, 2).firstCursorPosition().setBlockFormat(centered);
 
506
    table->cellAt(4, 3).firstCursorPosition().insertText(dimVal, m_ItemValueCharFormat);
 
507
 
 
508
    table->cellAt(5, 2).firstCursorPosition().insertText(i18n("Period:"), m_ItemNameCharFormat);
 
509
    table->cellAt(5, 2).firstCursorPosition().setBlockFormat(centered);
 
510
    table->cellAt(5, 3).firstCursorPosition().insertText(periodVal, m_ItemValueCharFormat);
 
511
}
 
512
 
 
513
void DetailsTable::createCoordinatesTable(SkyObject *obj, const KStarsDateTime &ut, GeoLocation *geo)
 
514
{
 
515
    clearContents();
 
516
 
 
517
    QTextCursor cursor = m_Document->rootFrame()->firstCursorPosition();
 
518
 
 
519
    // Set column width constraints
 
520
    QVector<QTextLength> constraints;
 
521
    constraints << QTextLength(QTextLength::PercentageLength, 25)
 
522
                << QTextLength(QTextLength::PercentageLength, 25)
 
523
                << QTextLength(QTextLength::PercentageLength, 25)
 
524
                << QTextLength(QTextLength::PercentageLength, 25);
 
525
    m_TableFormat.setColumnWidthConstraints(constraints);
 
526
 
 
527
    // Insert table & row containing table name
 
528
    QTextTable *table = cursor.insertTable(4, 4, m_TableFormat);
 
529
    table->mergeCells(0, 0, 1, 4);
 
530
    QTextBlockFormat centered;
 
531
    centered.setAlignment(Qt::AlignCenter);
 
532
    table->cellAt(0, 0).firstCursorPosition().setBlockFormat(centered);
 
533
    table->cellAt(0, 0).firstCursorPosition().insertText(i18n("Coordinates"), m_TableTitleCharFormat);
 
534
 
 
535
    //Coordinates Section:
 
536
    //Don't use KLocale::formatNumber() for the epoch string,
 
537
    //because we don't want a thousands-place separator!
 
538
    QString sEpoch = QString::number(ut.epoch(), 'f', 1);
 
539
    //Replace the decimal point with localized decimal symbol
 
540
    sEpoch.replace('.', KGlobal::locale()->decimalSymbol());
 
541
 
 
542
    table->cellAt(1, 0).firstCursorPosition().insertText(i18n("RA (%1):", sEpoch), m_ItemNameCharFormat);
 
543
    table->cellAt(1, 0).firstCursorPosition().setBlockFormat(centered);
 
544
    table->cellAt(1, 1).firstCursorPosition().insertText(obj->ra().toHMSString(), m_ItemValueCharFormat);
 
545
 
 
546
    table->cellAt(2, 0).firstCursorPosition().insertText(i18n("Dec (%1):", sEpoch), m_ItemNameCharFormat);
 
547
    table->cellAt(2, 0).firstCursorPosition().setBlockFormat(centered);
 
548
    table->cellAt(2, 1).firstCursorPosition().insertText(obj->dec().toDMSString(), m_ItemValueCharFormat);
 
549
 
 
550
    table->cellAt(3, 0).firstCursorPosition().insertText(i18n("Hour angle:"), m_ItemNameCharFormat);
 
551
    table->cellAt(3, 0).firstCursorPosition().setBlockFormat(centered);
 
552
    //Hour Angle can be negative, but dms HMS expressions cannot.
 
553
    //Here's a kludgy workaround:
 
554
    dms lst = geo->GSTtoLST(ut.gst());
 
555
    dms ha(lst.Degrees() - obj->ra().Degrees());
 
556
    QChar sgn('+');
 
557
    if(ha.Hours() > 12.0)
 
558
    {
 
559
        ha.setH(24.0 - ha.Hours());
 
560
        sgn = '-';
 
561
    }
 
562
    table->cellAt(3, 1).firstCursorPosition().insertText(QString("%1%2").arg(sgn).arg(ha.toHMSString()), m_ItemValueCharFormat);
 
563
 
 
564
    table->cellAt(1, 2).firstCursorPosition().insertText(i18n("Azimuth:"), m_ItemNameCharFormat);
 
565
    table->cellAt(1, 2).firstCursorPosition().setBlockFormat(centered);
 
566
    table->cellAt(1, 3).firstCursorPosition().insertText(obj->az().toDMSString(), m_ItemValueCharFormat);
 
567
 
 
568
    table->cellAt(2, 2).firstCursorPosition().insertText(i18n("Altitude:"), m_ItemNameCharFormat);
 
569
    table->cellAt(2, 2).firstCursorPosition().setBlockFormat(centered);
 
570
    dms a;
 
571
    if(Options::useAltAz())
 
572
    {
 
573
        a = obj->alt();
 
574
    }
 
575
 
 
576
    else
 
577
    {
 
578
        a = obj->altRefracted();
 
579
    }
 
580
    table->cellAt(2, 3).firstCursorPosition().insertText(a.toDMSString(), m_ItemValueCharFormat);
 
581
 
 
582
    table->cellAt(3, 2).firstCursorPosition().insertText(i18n("Airmass:"), m_ItemNameCharFormat);
 
583
    table->cellAt(3, 2).firstCursorPosition().setBlockFormat(centered);
 
584
    //Airmass is approximated as the secant of the zenith distance,
 
585
    //equivalent to 1./sin(Alt).  Beware of Inf at Alt=0!
 
586
    QString aMassStr;
 
587
    if(obj->alt().Degrees() > 0.0)
 
588
    {
 
589
        aMassStr = KGlobal::locale()->formatNumber(1./sin(obj->alt().radians() ), 2);
 
590
    }
 
591
 
 
592
    else
 
593
    {
 
594
        aMassStr = "--";
 
595
    }
 
596
    table->cellAt(3, 3).firstCursorPosition().insertText(aMassStr, m_ItemValueCharFormat);
 
597
 
 
598
    // Restore the position and other time-dependent parameters
 
599
    obj->recomputeCoords(ut, geo);
 
600
}
 
601
 
 
602
void DetailsTable::createRSTTAble(SkyObject *obj, const KStarsDateTime &ut, GeoLocation *geo)
 
603
{
 
604
    clearContents();
 
605
 
 
606
    QTextCursor cursor = m_Document->rootFrame()->firstCursorPosition();
 
607
 
 
608
    QString rtValue, stValue; // Rise/Set time values
 
609
    QString azRValue, azSValue; // Rise/Set azimuth values
 
610
 
 
611
    //Prepare time/position variables
 
612
    QTime rt = obj->riseSetTime(ut, geo, true); //true = use rise time
 
613
    dms raz = obj->riseSetTimeAz(ut, geo, true); //true = use rise time
 
614
 
 
615
    //If transit time is before rise time, use transit time for tomorrow
 
616
    QTime tt = obj->transitTime(ut, geo);
 
617
    dms talt = obj->transitAltitude(ut, geo);
 
618
    if(tt < rt)
 
619
    {
 
620
        tt = obj->transitTime(ut.addDays(1), geo);
 
621
        talt = obj->transitAltitude(ut.addDays(1), geo);
 
622
    }
 
623
 
 
624
    //If set time is before rise time, use set time for tomorrow
 
625
    QTime st = obj->riseSetTime(ut, geo, false); //false = use set time
 
626
    dms saz = obj->riseSetTimeAz(ut, geo, false); //false = use set time
 
627
    if(st < rt)
 
628
    {
 
629
        st = obj->riseSetTime(ut.addDays(1), geo, false); //false = use set time
 
630
        saz = obj->riseSetTimeAz(ut.addDays( 1 ), geo, false); //false = use set time
 
631
    }
 
632
 
 
633
    if(rt.isValid())
 
634
    {
 
635
        rtValue = QString().sprintf("%02d:%02d", rt.hour(), rt.minute());
 
636
        stValue = QString().sprintf("%02d:%02d", st.hour(), st.minute());
 
637
        azRValue = raz.toDMSString();
 
638
        azSValue = saz.toDMSString();
 
639
    }
 
640
 
 
641
    else
 
642
    {
 
643
        if(obj->alt().Degrees() > 0.0)
 
644
        {
 
645
            rtValue = i18n("Circumpolar");
 
646
            stValue = i18n("Circumpolar");
 
647
        }
 
648
 
 
649
        else
 
650
        {
 
651
            rtValue = i18n("Never rises");
 
652
            stValue = i18n("Never rises");
 
653
        }
 
654
 
 
655
        azRValue = i18nc("Not Applicable", "N/A");
 
656
        azSValue = i18nc("Not Applicable", "N/A");
 
657
    }
 
658
 
 
659
    // Set column width constraints
 
660
    QVector<QTextLength> constraints;
 
661
    constraints << QTextLength(QTextLength::PercentageLength, 25)
 
662
                << QTextLength(QTextLength::PercentageLength, 25)
 
663
                << QTextLength(QTextLength::PercentageLength, 25)
 
664
                << QTextLength(QTextLength::PercentageLength, 25);
 
665
    m_TableFormat.setColumnWidthConstraints(constraints);
 
666
 
 
667
    // Insert table & row containing table name
 
668
    QTextTable *table = cursor.insertTable(4, 4, m_TableFormat);
 
669
    table->mergeCells(0, 0, 1, 4);
 
670
    QTextBlockFormat centered;
 
671
    centered.setAlignment(Qt::AlignCenter);
 
672
    table->cellAt(0, 0).firstCursorPosition().setBlockFormat(centered);
 
673
    table->cellAt(0, 0).firstCursorPosition().insertText(i18n("Rise/Set/Transit"), m_TableTitleCharFormat);
 
674
 
 
675
    // Insert cell names & values
 
676
    table->cellAt(1, 0).firstCursorPosition().insertText(i18n("Rise time:"), m_ItemNameCharFormat);
 
677
    table->cellAt(1, 0).firstCursorPosition().setBlockFormat(centered);
 
678
    table->cellAt(1, 1).firstCursorPosition().insertText(rtValue, m_ItemValueCharFormat);
 
679
 
 
680
    table->cellAt(2, 0).firstCursorPosition().insertText(i18n("Transit time:"), m_ItemNameCharFormat);
 
681
    table->cellAt(2, 0).firstCursorPosition().setBlockFormat(centered);
 
682
    table->cellAt(2, 1).firstCursorPosition().insertText(QString().sprintf("%02d:%02d", tt.hour(), tt.minute()), m_ItemValueCharFormat);
 
683
 
 
684
    table->cellAt(3, 0).firstCursorPosition().insertText(i18n("Set time:"), m_ItemNameCharFormat);
 
685
    table->cellAt(3, 0).firstCursorPosition().setBlockFormat(centered);
 
686
    table->cellAt(3, 1).firstCursorPosition().insertText(stValue, m_ItemValueCharFormat);
 
687
 
 
688
    table->cellAt(1, 2).firstCursorPosition().insertText(i18n("Azimuth at rise:"), m_ItemNameCharFormat);
 
689
    table->cellAt(1, 2).firstCursorPosition().setBlockFormat(centered);
 
690
    table->cellAt(1, 3).firstCursorPosition().insertText(azRValue, m_ItemValueCharFormat);
 
691
 
 
692
    table->cellAt(2, 2).firstCursorPosition().insertText(i18n("Altitude at transit:"), m_ItemNameCharFormat);
 
693
    table->cellAt(2, 2).firstCursorPosition().setBlockFormat(centered);
 
694
    table->cellAt(2, 3).firstCursorPosition().insertText(talt.toDMSString(), m_ItemValueCharFormat);
 
695
 
 
696
    table->cellAt(3, 2).firstCursorPosition().insertText(i18n("Azimuth at set:"), m_ItemNameCharFormat);
 
697
    table->cellAt(3, 2).firstCursorPosition().setBlockFormat(centered);
 
698
    table->cellAt(3, 3).firstCursorPosition().insertText(azSValue, m_ItemValueCharFormat);
 
699
 
 
700
    // Restore the position and other time-dependent parameters
 
701
    obj->recomputeCoords( ut, geo );
 
702
}
 
703
 
 
704
void DetailsTable::clearContents()
 
705
{
 
706
    m_Document->clear();
 
707
}
 
708
 
 
709
void DetailsTable::setDefaultFormatting()
 
710
{
 
711
    // Set default table format
 
712
    m_TableFormat.setAlignment(Qt::AlignCenter);
 
713
    m_TableFormat.setBorder(4);
 
714
    m_TableFormat.setCellPadding(2);
 
715
    m_TableFormat.setCellSpacing(2);
 
716
 
 
717
    // Set default table title character format
 
718
    m_TableTitleCharFormat.setFont(QFont("Times", 12, QFont::Bold));
 
719
    m_TableTitleCharFormat.setFontCapitalization(QFont::Capitalize);
 
720
 
 
721
    // Set default table item name character format
 
722
    m_ItemNameCharFormat.setFont(QFont("Times", 10, QFont::Bold));
 
723
 
 
724
    // Set default table item value character format
 
725
    m_ItemValueCharFormat.setFont(QFont("Times", 10));
 
726
}