| 
									
										
										
										
											2015-04-22 17:48:03 +00:00
										 |  |  | #include "messageaveraging.h"
 | 
					
						
							| 
									
										
										
										
											2016-06-10 15:54:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-09 14:30:23 +00:00
										 |  |  | #include <QSettings>
 | 
					
						
							| 
									
										
										
										
											2015-11-18 01:28:12 +00:00
										 |  |  | #include <QApplication>
 | 
					
						
							| 
									
										
										
										
											2016-05-18 23:22:24 +00:00
										 |  |  | #include <QTextCharFormat>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "SettingsGroup.hpp"
 | 
					
						
							|  |  |  | #include "qt_helpers.hpp"
 | 
					
						
							| 
									
										
										
										
											2015-04-22 17:48:03 +00:00
										 |  |  | #include "ui_messageaveraging.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-06 12:56:25 +01:00
										 |  |  | #include "moc_messageaveraging.cpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-18 23:22:24 +00:00
										 |  |  | MessageAveraging::MessageAveraging(QSettings * settings, QFont const& font, QWidget *parent) : | 
					
						
							| 
									
										
										
										
											2015-04-22 17:48:03 +00:00
										 |  |  |   QWidget(parent), | 
					
						
							|  |  |  |   settings_ {settings}, | 
					
						
							|  |  |  |   ui(new Ui::MessageAveraging) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   ui->setupUi(this); | 
					
						
							| 
									
										
										
										
											2018-11-12 22:03:39 +00:00
										 |  |  |   setWindowTitle (QApplication::applicationName () + " - " + tr ("Message Averaging")); | 
					
						
							| 
									
										
										
										
											2016-05-18 23:22:24 +00:00
										 |  |  |   ui->msgAvgPlainTextEdit->setReadOnly (true); | 
					
						
							|  |  |  |   changeFont (font); | 
					
						
							| 
									
										
										
										
											2015-04-22 17:48:03 +00:00
										 |  |  |   read_settings (); | 
					
						
							| 
									
										
										
										
											2018-11-12 22:03:39 +00:00
										 |  |  |   ui->header_label->setText("   UTC  Sync    DT  Freq   "); | 
					
						
							| 
									
										
										
										
											2015-04-22 17:48:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MessageAveraging::~MessageAveraging() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-12 22:03:39 +00:00
										 |  |  |   write_settings (); | 
					
						
							| 
									
										
										
										
											2015-04-22 17:48:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-18 23:22:24 +00:00
										 |  |  | void MessageAveraging::changeFont (QFont const& font) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   ui->header_label->setStyleSheet (font_as_stylesheet (font)); | 
					
						
							|  |  |  |   ui->msgAvgPlainTextEdit->setStyleSheet (font_as_stylesheet (font)); | 
					
						
							|  |  |  |   setContentFont (font); | 
					
						
							|  |  |  |   updateGeometry (); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MessageAveraging::setContentFont(QFont const& font) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   ui->msgAvgPlainTextEdit->setFont (font); | 
					
						
							|  |  |  |   QTextCharFormat charFormat; | 
					
						
							|  |  |  |   charFormat.setFont (font); | 
					
						
							|  |  |  |   ui->msgAvgPlainTextEdit->selectAll (); | 
					
						
							|  |  |  |   auto cursor = ui->msgAvgPlainTextEdit->textCursor (); | 
					
						
							|  |  |  |   cursor.mergeCharFormat (charFormat); | 
					
						
							|  |  |  |   cursor.clearSelection (); | 
					
						
							|  |  |  |   cursor.movePosition (QTextCursor::End); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // position so viewport scrolled to left
 | 
					
						
							|  |  |  |   cursor.movePosition (QTextCursor::Up); | 
					
						
							|  |  |  |   cursor.movePosition (QTextCursor::StartOfLine); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ui->msgAvgPlainTextEdit->setTextCursor (cursor); | 
					
						
							|  |  |  |   ui->msgAvgPlainTextEdit->ensureCursorVisible (); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-22 17:48:03 +00:00
										 |  |  | void MessageAveraging::read_settings () | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-18 23:22:24 +00:00
										 |  |  |   SettingsGroup group {settings_, "MessageAveraging"}; | 
					
						
							| 
									
										
										
										
											2015-12-10 14:15:43 +00:00
										 |  |  |   restoreGeometry (settings_->value ("window/geometry").toByteArray ()); | 
					
						
							| 
									
										
										
										
											2015-04-22 17:48:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MessageAveraging::write_settings () | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-18 23:22:24 +00:00
										 |  |  |   SettingsGroup group {settings_, "MessageAveraging"}; | 
					
						
							| 
									
										
										
										
											2015-12-10 14:15:43 +00:00
										 |  |  |   settings_->setValue ("window/geometry", saveGeometry ()); | 
					
						
							| 
									
										
										
										
											2015-04-22 17:48:03 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-18 23:22:24 +00:00
										 |  |  | void MessageAveraging::displayAvg(QString const& t) | 
					
						
							| 
									
										
										
										
											2015-04-22 17:48:03 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-18 23:22:24 +00:00
										 |  |  |   ui->msgAvgPlainTextEdit->setPlainText(t); | 
					
						
							| 
									
										
										
										
											2015-04-22 17:48:03 +00:00
										 |  |  | } |