File indexing completed on 2024-04-28 07:32:11
0001 /* 0002 SPDX-FileCopyrightText: 2011 Rafał Kułaga <rl.kulaga@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "finderchart.h" 0008 0009 #include "detailstable.h" 0010 #include "geolocation.h" 0011 #include "kstarsdatetime.h" 0012 #include "loggingform.h" 0013 0014 #include <QLocale> 0015 #include <QTextDocument> 0016 #include <QTextDocumentFragment> 0017 #include <QTextDocumentWriter> 0018 #include <QTextTable> 0019 0020 FinderChart::FinderChart() : KStarsDocument() 0021 { 0022 } 0023 0024 void FinderChart::insertTitleSubtitle(const QString &title, const QString &subtitle) 0025 { 0026 QTextCursor cursor(m_Document.get()); 0027 cursor.movePosition(QTextCursor::Start); 0028 0029 QTextBlockFormat titleBlockFmt; 0030 titleBlockFmt.setAlignment(Qt::AlignCenter); 0031 0032 if (!title.isEmpty()) 0033 { 0034 QTextCharFormat titleCharFmt; 0035 QFont titleFont("Times", 20, QFont::Bold); 0036 titleCharFmt.setFont(titleFont); 0037 0038 cursor.insertBlock(titleBlockFmt, titleCharFmt); 0039 cursor.insertText(title); 0040 } 0041 0042 if (!subtitle.isEmpty()) 0043 { 0044 QTextCharFormat subtitleCharFmt; 0045 QFont subtitleFont("Times", 14); 0046 subtitleCharFmt.setFont(subtitleFont); 0047 0048 cursor.insertBlock(titleBlockFmt, subtitleCharFmt); 0049 cursor.insertText(subtitle); 0050 0051 cursor.insertBlock(QTextBlockFormat(), QTextCharFormat()); 0052 } 0053 } 0054 0055 void FinderChart::insertDescription(const QString &description) 0056 { 0057 QTextCursor cursor = m_Document->rootFrame()->lastCursorPosition(); 0058 0059 QTextBlockFormat descrBlockFmt; 0060 descrBlockFmt.setAlignment(Qt::AlignJustify); 0061 QTextCharFormat descrCharFmt; 0062 QFont descrFont("Times", 10); 0063 descrCharFmt.setFont(descrFont); 0064 0065 cursor.insertBlock(descrBlockFmt, descrCharFmt); 0066 cursor.insertText(description); 0067 0068 cursor.insertBlock(QTextBlockFormat(), QTextCharFormat()); 0069 } 0070 0071 void FinderChart::insertGeoTimeInfo(const KStarsDateTime &ut, GeoLocation *geo) 0072 { 0073 QTextCursor cursor = m_Document->rootFrame()->lastCursorPosition(); 0074 0075 QTextBlockFormat geoBlockFmt; 0076 geoBlockFmt.setAlignment(Qt::AlignLeft); 0077 QTextCharFormat geoCharFmt; 0078 QFont geoFont("Times", 10, QFont::Bold); 0079 geoCharFmt.setFont(geoFont); 0080 0081 cursor.insertBlock(geoBlockFmt); 0082 cursor.insertText(i18n("Date, time and location: "), geoCharFmt); 0083 0084 QString geoStr = geo->translatedName(); 0085 if (!geo->translatedProvince().isEmpty()) 0086 { 0087 if (!geoStr.isEmpty()) 0088 { 0089 geoStr.append(", "); 0090 } 0091 geoStr.append(geo->translatedProvince()); 0092 } 0093 if (!geo->translatedCountry().isEmpty()) 0094 { 0095 if (!geoStr.isEmpty()) 0096 { 0097 geoStr.append(", "); 0098 } 0099 geoStr.append(geo->translatedCountry()); 0100 } 0101 0102 geoFont.setBold(false); 0103 geoCharFmt.setFont(geoFont); 0104 //cursor.insertText(QLocale().toString(ut.dateTime()) + ", " + geoStr, geoCharFmt); 0105 cursor.insertText(QLocale().toString(ut) + ", " + geoStr, geoCharFmt); 0106 0107 cursor.insertBlock(QTextBlockFormat(), QTextCharFormat()); 0108 } 0109 0110 void FinderChart::insertLoggingForm(LoggingForm *log) 0111 { 0112 QTextCursor cursor = m_Document->rootFrame()->lastCursorPosition(); 0113 cursor.insertFragment(QTextDocumentFragment(log->getDocument())); 0114 0115 cursor.insertBlock(QTextBlockFormat(), QTextCharFormat()); 0116 cursor.insertBlock(QTextBlockFormat(), QTextCharFormat()); 0117 } 0118 0119 void FinderChart::insertImage(const QImage &img, const QString &description, bool descriptionBelow) 0120 { 0121 QTextCursor cursor = m_Document->rootFrame()->lastCursorPosition(); 0122 QTextCharFormat textFmt; 0123 QTextBlockFormat blockFmt; 0124 blockFmt.setAlignment(Qt::AlignHCenter); 0125 0126 if (descriptionBelow) 0127 { 0128 cursor.insertBlock(blockFmt, textFmt); 0129 cursor.insertImage(img); 0130 cursor.insertBlock(blockFmt, textFmt); 0131 cursor.insertText(description); 0132 } 0133 0134 else 0135 { 0136 cursor.insertBlock(blockFmt, textFmt); 0137 cursor.insertText(description); 0138 cursor.insertBlock(blockFmt, textFmt); 0139 cursor.insertImage(img); 0140 } 0141 0142 cursor.insertBlock(QTextBlockFormat(), QTextCharFormat()); 0143 cursor.insertBlock(QTextBlockFormat(), QTextCharFormat()); 0144 } 0145 0146 void FinderChart::insertDetailsTable(DetailsTable *table) 0147 { 0148 QTextCursor cursor = m_Document->rootFrame()->lastCursorPosition(); 0149 cursor.insertFragment(QTextDocumentFragment(table->getDocument())); 0150 0151 cursor.insertBlock(QTextBlockFormat(), QTextCharFormat()); 0152 cursor.insertBlock(QTextBlockFormat(), QTextCharFormat()); 0153 } 0154 0155 void FinderChart::insertSectionTitle(const QString &title) 0156 { 0157 QTextCursor cursor = m_Document->rootFrame()->lastCursorPosition(); 0158 0159 QTextBlockFormat titleBlockFmt; 0160 titleBlockFmt.setAlignment(Qt::AlignLeft); 0161 QTextCharFormat titleCharFmt; 0162 QFont titleFont("Times", 16, QFont::Bold); 0163 titleFont.setCapitalization(QFont::AllUppercase); 0164 titleCharFmt.setFont(titleFont); 0165 0166 cursor.insertBlock(titleBlockFmt, titleCharFmt); 0167 cursor.insertText(title); 0168 }