Kstars

finderchart.cpp
1 /*
2  SPDX-FileCopyrightText: 2011 Rafał Kułaga <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "finderchart.h"
8 
9 #include "detailstable.h"
10 #include "geolocation.h"
11 #include "kstarsdatetime.h"
12 #include "loggingform.h"
13 
14 #include <QLocale>
15 #include <QTextDocument>
16 #include <QTextDocumentFragment>
17 #include <QTextDocumentWriter>
18 #include <QTextTable>
19 
21 {
22 }
23 
24 void FinderChart::insertTitleSubtitle(const QString &title, const QString &subtitle)
25 {
26  QTextCursor cursor(m_Document.get());
28 
29  QTextBlockFormat titleBlockFmt;
30  titleBlockFmt.setAlignment(Qt::AlignCenter);
31 
32  if (!title.isEmpty())
33  {
34  QTextCharFormat titleCharFmt;
35  QFont titleFont("Times", 20, QFont::Bold);
36  titleCharFmt.setFont(titleFont);
37 
38  cursor.insertBlock(titleBlockFmt, titleCharFmt);
39  cursor.insertText(title);
40  }
41 
42  if (!subtitle.isEmpty())
43  {
44  QTextCharFormat subtitleCharFmt;
45  QFont subtitleFont("Times", 14);
46  subtitleCharFmt.setFont(subtitleFont);
47 
48  cursor.insertBlock(titleBlockFmt, subtitleCharFmt);
49  cursor.insertText(subtitle);
50 
52  }
53 }
54 
55 void FinderChart::insertDescription(const QString &description)
56 {
57  QTextCursor cursor = m_Document->rootFrame()->lastCursorPosition();
58 
59  QTextBlockFormat descrBlockFmt;
60  descrBlockFmt.setAlignment(Qt::AlignJustify);
61  QTextCharFormat descrCharFmt;
62  QFont descrFont("Times", 10);
63  descrCharFmt.setFont(descrFont);
64 
65  cursor.insertBlock(descrBlockFmt, descrCharFmt);
66  cursor.insertText(description);
67 
69 }
70 
72 {
73  QTextCursor cursor = m_Document->rootFrame()->lastCursorPosition();
74 
75  QTextBlockFormat geoBlockFmt;
76  geoBlockFmt.setAlignment(Qt::AlignLeft);
77  QTextCharFormat geoCharFmt;
78  QFont geoFont("Times", 10, QFont::Bold);
79  geoCharFmt.setFont(geoFont);
80 
81  cursor.insertBlock(geoBlockFmt);
82  cursor.insertText(i18n("Date, time and location: "), geoCharFmt);
83 
84  QString geoStr = geo->translatedName();
85  if (!geo->translatedProvince().isEmpty())
86  {
87  if (!geoStr.isEmpty())
88  {
89  geoStr.append(", ");
90  }
91  geoStr.append(geo->translatedProvince());
92  }
93  if (!geo->translatedCountry().isEmpty())
94  {
95  if (!geoStr.isEmpty())
96  {
97  geoStr.append(", ");
98  }
99  geoStr.append(geo->translatedCountry());
100  }
101 
102  geoFont.setBold(false);
103  geoCharFmt.setFont(geoFont);
104  //cursor.insertText(QLocale().toString(ut.dateTime()) + ", " + geoStr, geoCharFmt);
105  cursor.insertText(QLocale().toString(ut) + ", " + geoStr, geoCharFmt);
106 
108 }
109 
111 {
112  QTextCursor cursor = m_Document->rootFrame()->lastCursorPosition();
114 
117 }
118 
119 void FinderChart::insertImage(const QImage &img, const QString &description, bool descriptionBelow)
120 {
121  QTextCursor cursor = m_Document->rootFrame()->lastCursorPosition();
122  QTextCharFormat textFmt;
123  QTextBlockFormat blockFmt;
124  blockFmt.setAlignment(Qt::AlignHCenter);
125 
126  if (descriptionBelow)
127  {
128  cursor.insertBlock(blockFmt, textFmt);
129  cursor.insertImage(img);
130  cursor.insertBlock(blockFmt, textFmt);
131  cursor.insertText(description);
132  }
133 
134  else
135  {
136  cursor.insertBlock(blockFmt, textFmt);
137  cursor.insertText(description);
138  cursor.insertBlock(blockFmt, textFmt);
139  cursor.insertImage(img);
140  }
141 
144 }
145 
147 {
148  QTextCursor cursor = m_Document->rootFrame()->lastCursorPosition();
150 
153 }
154 
156 {
157  QTextCursor cursor = m_Document->rootFrame()->lastCursorPosition();
158 
159  QTextBlockFormat titleBlockFmt;
160  titleBlockFmt.setAlignment(Qt::AlignLeft);
161  QTextCharFormat titleCharFmt;
162  QFont titleFont("Times", 16, QFont::Bold);
164  titleCharFmt.setFont(titleFont);
165 
166  cursor.insertBlock(titleBlockFmt, titleCharFmt);
167  cursor.insertText(title);
168 }
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
AlignCenter
void insertImage(const QImage &img, const QString &description, bool descriptionBelow=true)
Insert image to the finder chart.
QTextDocument * getDocument()
Get logging form internal QTextDocument.
Definition: loggingform.cpp:56
void setAlignment(Qt::Alignment alignment)
void insertImage(const QTextImageFormat &format, QTextFrameFormat::Position alignment)
void insertFragment(const QTextDocumentFragment &fragment)
void insertBlock()
FinderChart()
Constructor.
Definition: finderchart.cpp:20
QString i18n(const char *text, const TYPE &arg...)
Class that represents logging form. Currently, LoggingForm class is used to create logging forms for ...
Definition: loggingform.h:20
bool isEmpty() const const
void insertDetailsTable(DetailsTable *table)
Insert details table to the finder chart.
void setFont(const QFont &font, QTextCharFormat::FontPropertiesInheritanceBehavior behavior)
void insertDescription(const QString &description)
Insert description to the finder chart.
Definition: finderchart.cpp:55
Base class for KStars documents. KStarsDocument is a base class for all KStars documents: finder char...
Represents details tables that can be inserted to finder charts and logging forms....
Definition: detailstable.h:28
void insertGeoTimeInfo(const KStarsDateTime &ut, GeoLocation *geo)
Insert details about date&time and geographic location.
Definition: finderchart.cpp:71
void insertLoggingForm(LoggingForm *log)
Insert logging form to the finder chart.
void insertText(const QString &text)
void setCapitalization(QFont::Capitalization caps)
void insertSectionTitle(const QString &title)
Insert section title to the finder chart.
void insertTitleSubtitle(const QString &title, const QString &subtitle)
Insert title and subtitle to the finder chart.
Definition: finderchart.cpp:24
void setBold(bool enable)
bool movePosition(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode, int n)
QTextDocument * getDocument()
Get table document.
Definition: detailstable.h:126
QString & append(QChar ch)
Relevant data about an observing location on Earth.
Definition: geolocation.h:27
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Aug 9 2022 04:06:02 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.