summaryrefslogtreecommitdiff
path: root/engineeringpage.cpp
diff options
context:
space:
mode:
authorJoshua Drake <joshua.drake@ditchwitch.com>2023-01-31 09:22:48 -0600
committerJoshua Drake <joshua.drake@ditchwitch.com>2023-01-31 09:22:48 -0600
commit29a63fc5f2f4f0ec5be6d9ff6a688550f48fe88e (patch)
tree8ed8f6b816c6f1bf901fea63bc131b2d7ccc6872 /engineeringpage.cpp
Initial Commit. :)HEADmaster
Diffstat (limited to 'engineeringpage.cpp')
-rw-r--r--engineeringpage.cpp200
1 files changed, 200 insertions, 0 deletions
diff --git a/engineeringpage.cpp b/engineeringpage.cpp
new file mode 100644
index 0000000..695c697
--- /dev/null
+++ b/engineeringpage.cpp
@@ -0,0 +1,200 @@
+/*
+ Class for making engineering pages
+ Created by Joshua Drake
+ 6/9/2022
+*/
+#include "engineeringpage.h"
+
+engineeringpage::engineeringpage(QWidget *parent) : QWidget(parent) ,
+ rows(0)
+{
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ title->setText("Null");
+ title->setFrameStyle(QFrame::NoFrame);
+ title->setAlignment(Qt::AlignCenter | Qt::AlignCenter );
+ title->setGeometry(0,0,SCREEN_WIDTH,20);
+
+ table->setAlternatingRowColors(true);
+ table->setFrameStyle(QFrame::NoFrame);
+ table->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ initializestylesheet();
+}
+engineeringpage::engineeringpage(QString titletext, QStringList message_names,QWidget *parent) : QWidget(parent) ,
+ rows(0)
+{
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ title->setText("Null");
+ title->setFrameStyle(QFrame::NoFrame);
+ title->setAlignment(Qt::AlignCenter | Qt::AlignCenter );
+ title->setGeometry(0,0,SCREEN_WIDTH,20);
+
+ table->setAlternatingRowColors(true);
+ table->setFrameStyle(QFrame::NoFrame);
+ table->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ initializestylesheet();
+ configure(titletext, message_names);
+}
+
+void engineeringpage::initializestylesheet()
+{
+ table->setStyleSheet(
+ "QTableView"
+ "{"
+ "padding: 0px 0px 0px 0px;"
+ "background-color: black;"
+ "alternate-background-color: white;"
+ "selection-background-color: white;"
+ "/*border: 1px solid white;*/"
+ "border-width: 1px;"
+ "border-radius: 5px;"
+ "border-color: white;"
+ "border-style: outset;"
+ "}"
+ "QTableView::item"
+ "{"
+ "color: white;"
+ "background-color: black;"
+ "alternate-background-color: white;"
+ "border-bottom: 1px dotted white;"
+ "}"
+
+ "QHeaderView::section"
+ " {"
+ "background-color: black;"
+ "border-right: 1px solid white;"
+ "border-bottom: 1px solid white;"
+ "text-align: center;"
+ "padding: 0px 0px;"
+ "}");
+}
+void engineeringpage::configure(QString titletext, QStringList message_names)
+{
+ rows = message_names.length();
+ title->setText(titletext);
+ title->setGeometry(0,0,SCREEN_WIDTH,SCREEN_HEIGHT*.10);
+
+ table->setColumnCount(1);
+ table->setRowCount(rows);
+ table->setFrameShape(QFrame::NoFrame);
+ table->setGeometry(0,(SCREEN_HEIGHT*.10),SCREEN_WIDTH,SCREEN_HEIGHT - (SCREEN_HEIGHT*.10));
+ table->setSelectionBehavior(QAbstractItemView::SelectRows);
+ verticalheader = table->verticalHeader();
+ verticalheader->setMinimumSectionSize(1);
+ verticalheader->setDefaultSectionSize((SCREEN_HEIGHT - (SCREEN_HEIGHT*.10))/rows);
+ verticalheader->setMaximumSectionSize(SCREEN_HEIGHT);
+
+ //verticalheader->setSectionResizeMode(QHeaderView::Fixed);
+ verticalheader->setAlternatingRowColors(true);
+ verticalheader->setFixedWidth(SCREEN_WIDTH * .40);
+
+ horizontalheader = table->horizontalHeader();
+ horizontalheader->setSectionResizeMode(QHeaderView::Stretch);
+ horizontalheader->setMaximumSectionSize(SCREEN_WIDTH);
+ horizontalheader->setVisible(false);
+
+
+
+ table->setVerticalHeaderLabels(message_names);
+ // table->verticalHeader()->font().setCapitalization(true);
+ QFont tableFont("System", verticalheader->height(), QFont::Bold, false);
+ tableFont.setCapitalization(QFont::MixedCase);
+ const int dataFontSize = table->verticalHeader()->rect().height();
+
+
+ verticalheader->setFont(tableFont);
+ for(int x = 0; x < rows; x++)
+ {
+ //qDebug() << message_names.at(x).length();
+ /*if(message_names.at(x).length() > 10)tableFont.setPointSizeF((verticalheader->width())/(message_names.at(x).length()));
+ else tableFont.setPixelSize((verticalheader->width())/(message_names.at(x).length())); //adjust font to be relative to header width and number of characters within the label
+ */
+ tableFont.setPointSizeF(table->verticalHeader()->rect().height());
+ table->verticalHeaderItem(x)->setFont(tableFont);
+ //table->verticalHeaderItem(x)->setTextAlignment(Qt::AlignCenter);
+
+
+ QTableWidgetItem *instance = new QTableWidgetItem();
+ QTableWidgetItem *v_instance = new QTableWidgetItem();
+ tableFont.setPixelSize(dataFontSize);
+
+ instance->setTextAlignment(Qt::AlignCenter);
+ instance->setFont(tableFont);
+ //instance->setText(message_names.at(x));
+ v_instance->setTextAlignment(Qt::AlignCenter);
+ v_instance->setFont(tableFont);
+ v_instance->setText(message_names.at(x));
+ tableHeader.push_back(v_instance);
+ tableData.push_back(instance);
+
+ if(textOverhang(tableHeader[x],message_names.at(x)))
+ {
+ v_instance->setTextAlignment(Qt::AlignLeft);
+ v_instance->setTextAlignment(Qt::AlignVCenter);
+
+ text_scrolling.insert(tableHeader[x],scrollText(message_names.at(x)));
+ }
+ table->setVerticalHeaderItem(x,tableHeader[x]);
+ table->setItem(x,0,tableData[x]);
+
+ //qDebug() << table->verticalHeaderItem(x) << " : " << table->item(x,0);
+ }
+ scroll_timer.setInterval(350);
+ connect(&scroll_timer, SIGNAL(timeout()), this, SLOT(check_scroll()));
+ scroll_timer.start();
+}
+
+void engineeringpage::update(int row, QString message_data)
+{
+ if(row >= rows) return;
+ tableData[row]->setText(message_data);
+}
+void engineeringpage::update(QStringList message_data)
+{
+ for(int x = 0; (x < tableData.size()) && (x < message_data.size()); x++) tableData[x]->setText(message_data.at(x));
+}
+void engineeringpage::update(QList<double> message_data)
+{
+ for(int x = 0; (x < tableData.size()) && (x < message_data.size()); x++) tableData[x]->setData(Qt::DisplayRole,message_data.at(x));
+ //qDebug() << message_data;
+}
+void engineeringpage::update(QByteArray message_data)
+{
+ for(int x = 0; x < (x < tableData.size()) && (x < message_data.size()); x++) tableData[x]->setData(Qt::DisplayRole,message_data.at(x));
+ //qDebug() << message_data;
+}
+bool engineeringpage::textOverhang(QTableWidgetItem *instance, QString text)
+{
+ QFontMetrics fm(instance->font());
+
+ if(fm.horizontalAdvance(text) > table->verticalHeader()->rect().width()) return true;
+ return false;
+}
+
+void engineeringpage :: check_scroll(void)
+{
+
+ QMap<QTableWidgetItem*, scrollText>::iterator i;
+ for (i = text_scrolling.begin(); i != text_scrolling.end(); ++i)
+ {
+ if(i.value().scrolled)
+ {
+ if(i.value().position > 0)
+ {
+ i.value().position--;
+ i.key()->setText(i.value().fullText.right(i.value().fullText.length() - i.value().position));
+ }
+ else i.value().scrolled = false;
+ }
+ else
+ {
+ if(textOverhang(i.key(),i.value().fullText.right(i.value().fullText.length() - i.value().position)))
+ {
+ i.value().position++;
+ i.key()->setText(i.value().fullText.right(i.value().fullText.length() - i.value().position));
+ }
+ else i.value().scrolled = true;
+ }
+ }
+}
+
+