diff --git a/src/SeerMainWindow.cpp b/src/SeerMainWindow.cpp index 9f417d2..b498412 100644 --- a/src/SeerMainWindow.cpp +++ b/src/SeerMainWindow.cpp @@ -36,7 +36,7 @@ SeerMainWindow::SeerMainWindow(QWidget* parent) : QMainWindow(parent) { // Add status bar indicator. SeerRunStatusIndicator* runStatus = new SeerRunStatusIndicator(this); - statusBar()->addPermanentWidget(runStatus->indicatorBox()); + statusBar()->addPermanentWidget(runStatus); // Add progress spin widget. QWidget* spacerWidget = new QWidget(this); diff --git a/src/SeerPlainTextEdit.cpp b/src/SeerPlainTextEdit.cpp index 9fb2462..e0999e2 100644 --- a/src/SeerPlainTextEdit.cpp +++ b/src/SeerPlainTextEdit.cpp @@ -12,6 +12,9 @@ SeerPlainTextEdit::SeerPlainTextEdit(const QString& text, QWidget* parent) : QPlainTextEdit(text, parent) { + // Turn off the widget's cursor. We'll do our own in the paintEvent. + setCursorWidth(0); + _cursorVisible = true; _cursorTimer = new QTimer(this); @@ -23,6 +26,9 @@ SeerPlainTextEdit::SeerPlainTextEdit(const QString& text, QWidget* parent) : QPl SeerPlainTextEdit::SeerPlainTextEdit(QWidget* parent) : QPlainTextEdit(parent) { + // Turn off the widget's cursor. We'll do our own in the paintEvent. + setCursorWidth(0); + _cursorVisible = true; _cursorTimer = new QTimer(this); @@ -52,22 +58,19 @@ void SeerPlainTextEdit::paintEvent(QPaintEvent* event) { // First, let the standard QPlainTextEdit handle its painting. QPlainTextEdit::paintEvent(event); - // If the widget does not have focus, draw the cursor manually. + // Get our painter. + QPainter painter(viewport()); + + // Draw the cursor manually. if (_cursorVisible) { - setCursorWidth(CURSOR_WIDTH); QRect r = cursorRect(); - QPainter p(viewport()); - p.fillRect(r, palette().text().color()); - } - else - { - setCursorWidth(0); + r.setWidth(CURSOR_WIDTH); + painter.fillRect(r, palette().text().color()); } // Add margin highlight for current line - QPainter painter(viewport()); QTextCursor cursor = textCursor(); - QTextBlock block = cursor.block(); + QTextBlock block = cursor.block(); // Get the rectangle of the current line (block) QRectF rect = blockBoundingGeometry(block).translated(contentOffset()); diff --git a/src/SeerRunStatusIndicator.cpp b/src/SeerRunStatusIndicator.cpp index 0505a71..0eb8658 100644 --- a/src/SeerRunStatusIndicator.cpp +++ b/src/SeerRunStatusIndicator.cpp @@ -3,64 +3,48 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "SeerRunStatusIndicator.h" +#include #include #include -#include -#include SeerRunStatusIndicator::SeerRunStatusIndicator(QWidget* parent) : QLabel(parent) { - // Create group box - _groupBox = new QGroupBox(); - _groupBox->setTitle(""); - _groupBox->setFlat(true); - _groupBox->setStyleSheet("QGroupBox { border: none; }"); - _statusLabel = new QLabel("Status"); - _statusLabel->setAlignment(Qt::AlignCenter); - _statusLabel->setFixedSize(150, 25); - _statusLabel->setStyleSheet("background-color: lightgray; color: black; font-weight: bold;"); + QSize size = fontMetrics().size(Qt::TextSingleLine, "XXXXXXXXXXXXXXXXXX"); - // Layout - auto *layout = new QHBoxLayout(); - layout->setContentsMargins(0, 0, 0, 0); - layout->setSpacing(0); - layout->addWidget(_statusLabel); - _groupBox->setLayout(layout); + setAlignment(Qt::AlignCenter); + setFixedWidth(size.width()); + setText("Status"); + setStyleSheet("background-color: lightgray; color: black; font-weight: bold;"); } SeerRunStatusIndicator::~SeerRunStatusIndicator() { } void SeerRunStatusIndicator::setRunStatus (SeerRunStatusIndicator::RunStatus status) { + if (status == RunStatus::Idle) { - _statusLabel->setText("Session Terminated"); - _statusLabel->setStyleSheet("background-color: lightgray; color: black; font-weight: bold;"); + setText("Session Terminated"); + setStyleSheet("background-color: lightgray; color: black; font-weight: bold;"); }else if (status == RunStatus::Stopped) { - _statusLabel->setText("Stopped"); - _statusLabel->setStyleSheet("background-color: red; color: black; font-weight: bold;"); + setText("Stopped"); + setStyleSheet("background-color: red; color: black; font-weight: bold;"); - } - else if (status == RunStatus::Stop_By_Breakpoint) { - _statusLabel->setText("Stop by breakpoint"); - _statusLabel->setStyleSheet("background-color: yellow; color: black; font-weight: bold;"); - } - else if (status == RunStatus::Running) { - _statusLabel->setText("Running"); - _statusLabel->setStyleSheet("background-color: green; color: black; font-weight: bold;"); + }else if (status == RunStatus::Stop_By_Breakpoint) { + setText("Stop by breakpoint"); + setStyleSheet("background-color: yellow; color: black; font-weight: bold;"); - } - else { - _statusLabel->setText("Unknown"); + }else if (status == RunStatus::Running) { + setText("Running"); + setStyleSheet("background-color: green; color: black; font-weight: bold;"); + + }else{ + setText("Unknown"); } emit statusChanged(status); } -QGroupBox* SeerRunStatusIndicator::indicatorBox() { - return _groupBox; -} - void SeerRunStatusIndicator::handleText (const QString& text) { if (text.startsWith("*running,thread-id=\"")) { @@ -99,8 +83,11 @@ void SeerRunStatusIndicator::handleText (const QString& text) { // handle when program stop/ killed void SeerRunStatusIndicator::handleSessionTerminated() { - _statusLabel->setText("Session Terminated"); - _statusLabel->setStyleSheet("background-color: lightgray; color: black; font-weight: bold;"); + + setText("Session Terminated"); + setStyleSheet("background-color: lightgray; color: black; font-weight: bold;"); + // also tell SeerProgressIndicator to stop spinning setRunStatus(SeerRunStatusIndicator::Idle); -} \ No newline at end of file +} + diff --git a/src/SeerRunStatusIndicator.h b/src/SeerRunStatusIndicator.h index da7adde..f35dc9a 100644 --- a/src/SeerRunStatusIndicator.h +++ b/src/SeerRunStatusIndicator.h @@ -6,8 +6,6 @@ #include #include -#include -#include #include class SeerRunStatusIndicator : public QLabel { @@ -27,7 +25,6 @@ class SeerRunStatusIndicator : public QLabel { void setRunStatus (SeerRunStatusIndicator::RunStatus status); SeerRunStatusIndicator::RunStatus runStatus () const; - QGroupBox* indicatorBox (); signals: void statusChanged (SeerRunStatusIndicator::RunStatus status); @@ -39,8 +36,5 @@ class SeerRunStatusIndicator : public QLabel { protected: private: - QGroupBox* _groupBox; - QLabel* _statusLabel; - QHBoxLayout* _layout; };