Tidied structure of all classes within the entire code base

Also some other small bits of tidying
This commit is contained in:
Nav
2021-10-06 21:12:31 +01:00
parent 1aef5bba79
commit 6edfb7376a
179 changed files with 3446 additions and 3493 deletions

View File

@@ -1,11 +1,10 @@
#include "AboutWindow.hpp"
#include <QtUiTools>
#include "AboutWindow.hpp"
#include "Widgets/TargetWidgets/DIP/DualInlinePackageWidget.hpp"
#include "src/Logger/Logger.hpp"
#include "src/Exceptions/Exception.hpp"
#include "src/Application.hpp"
#include "src/Helpers/Paths.hpp"
#include "src/Application.hpp"
using namespace Bloom;
using namespace Exceptions;

View File

@@ -9,9 +9,7 @@ namespace Bloom
{
class AboutWindow: public QObject
{
Q_OBJECT
private:
QWidget* windowWidget = nullptr;
Q_OBJECT
public:
explicit AboutWindow(QWidget* parent);
@@ -24,5 +22,8 @@ namespace Bloom
this->windowWidget->show();
}
}
private:
QWidget* windowWidget = nullptr;
};
}

View File

@@ -143,15 +143,109 @@ void InsightWindow::init(TargetDescriptor targetDescriptor) {
this->activate();
}
void InsightWindow::toggleUi(bool disable) {
this->uiDisabled = disable;
if (this->refreshIoInspectionButton != nullptr) {
this->refreshIoInspectionButton->setDisabled(disable);
this->refreshIoInspectionButton->repaint();
void InsightWindow::onTargetControllerSuspended() {
if (this->activated) {
this->deactivate();
}
}
void InsightWindow::onTargetControllerResumed(const TargetDescriptor& targetDescriptor) {
if (!this->activated) {
this->targetDescriptor = targetDescriptor;
this->activate();
}
}
void InsightWindow::onTargetStateUpdate(TargetState newState) {
this->targetState = newState;
if (newState == TargetState::RUNNING) {
this->targetStatusLabel->setText("Running");
this->programCounterValueLabel->setText("-");
} else if (newState == TargetState::STOPPED) {
this->targetStatusLabel->setText("Stopped");
this->toggleUi(false);
} else {
this->targetStatusLabel->setText("Unknown");
}
}
void InsightWindow::onTargetProgramCounterUpdate(quint32 programCounter) {
this->programCounterValueLabel->setText(
"0x" + QString::number(programCounter, 16).toUpper() + " (" + QString::number(programCounter) + ")"
);
}
void InsightWindow::openReportIssuesUrl() {
auto url = QUrl("https://bloom.oscillate.io/report-issue");
/*
* The https://bloom.oscillate.io/report-issue URL just redirects to the Bloom GitHub issue page.
*
* We can use query parameters in the URL to pre-fill the body of the issue. We use this to include some
* target information.
*/
auto urlQuery = QUrlQuery();
auto issueBody = QString("Issue reported via Bloom Insight.\nTarget name: "
+ QString::fromStdString(this->targetDescriptor.name) + "\n"
+ "Target ID: " + QString::fromStdString(this->targetDescriptor.id) + "\n"
);
if (this->selectedVariant != nullptr) {
issueBody += "Target variant: " + QString::fromStdString(this->selectedVariant->name) + "\n";
}
issueBody += "\nPlease describe your issue below. Include as much detail as possible.";
urlQuery.addQueryItem("body", issueBody);
url.setQuery(urlQuery);
QDesktopServices::openUrl(url);
}
void InsightWindow::openGettingStartedUrl() {
QDesktopServices::openUrl(QUrl("https://bloom.oscillate.io/docs/getting-started"));
}
void InsightWindow::openAboutWindow() {
if (this->aboutWindowWidget == nullptr) {
this->aboutWindowWidget = new AboutWindow(this->windowContainer);
}
this->aboutWindowWidget->show();
}
void InsightWindow::toggleTargetRegistersPane() {
if (this->targetRegistersSidePane->activated) {
this->targetRegistersSidePane->deactivate();
this->targetRegistersButton->setChecked(false);
/*
* Given that the target registers side pane is currently the only pane in the left panel, the panel will be
* empty so no need to leave it visible.
*/
this->leftPanel->setVisible(false);
} else {
this->targetRegistersSidePane->activate();
this->targetRegistersButton->setChecked(true);
this->leftPanel->setVisible(true);
}
}
void InsightWindow::resizeEvent(QResizeEvent* event) {
const auto windowSize = this->size();
this->windowContainer->setFixedSize(windowSize);
this->layoutContainer->setFixedSize(windowSize);
this->adjustPanels();
}
void InsightWindow::showEvent(QShowEvent* event) {
this->adjustPanels();
}
bool InsightWindow::isVariantSupported(const TargetVariant& variant) {
/*
* Because the size of the pin body widget is fixed, for all of our target package widgets, we run out of screen
@@ -243,6 +337,15 @@ void InsightWindow::selectVariant(const TargetVariant* variant) {
}
}
void InsightWindow::toggleUi(bool disable) {
this->uiDisabled = disable;
if (this->refreshIoInspectionButton != nullptr) {
this->refreshIoInspectionButton->setDisabled(disable);
this->refreshIoInspectionButton->repaint();
}
}
void InsightWindow::activate() {
auto targetNameLabel = this->footer->findChild<QLabel*>("target-name");
auto targetIdLabel = this->footer->findChild<QLabel*>("target-id");
@@ -432,106 +535,3 @@ void InsightWindow::adjustPanels() {
)
);
}
void InsightWindow::resizeEvent(QResizeEvent* event) {
const auto windowSize = this->size();
this->windowContainer->setFixedSize(windowSize);
this->layoutContainer->setFixedSize(windowSize);
this->adjustPanels();
}
void InsightWindow::showEvent(QShowEvent* event) {
this->adjustPanels();
}
void InsightWindow::onTargetControllerSuspended() {
if (this->activated) {
this->deactivate();
}
}
void InsightWindow::onTargetControllerResumed(const TargetDescriptor& targetDescriptor) {
if (!this->activated) {
this->targetDescriptor = targetDescriptor;
this->activate();
}
}
void InsightWindow::openReportIssuesUrl() {
auto url = QUrl("https://bloom.oscillate.io/report-issue");
/*
* The https://bloom.oscillate.io/report-issue URL just redirects to the Bloom GitHub issue page.
*
* We can use query parameters in the URL to pre-fill the body of the issue. We use this to include some
* target information.
*/
auto urlQuery = QUrlQuery();
auto issueBody = QString("Issue reported via Bloom Insight.\nTarget name: "
+ QString::fromStdString(this->targetDescriptor.name) + "\n"
+ "Target ID: " + QString::fromStdString(this->targetDescriptor.id) + "\n"
);
if (this->selectedVariant != nullptr) {
issueBody += "Target variant: " + QString::fromStdString(this->selectedVariant->name) + "\n";
}
issueBody += "\nPlease describe your issue below. Include as much detail as possible.";
urlQuery.addQueryItem("body", issueBody);
url.setQuery(urlQuery);
QDesktopServices::openUrl(url);
}
void InsightWindow::openGettingStartedUrl() {
QDesktopServices::openUrl(QUrl("https://bloom.oscillate.io/docs/getting-started"));
}
void InsightWindow::openAboutWindow() {
if (this->aboutWindowWidget == nullptr) {
this->aboutWindowWidget = new AboutWindow(this->windowContainer);
}
this->aboutWindowWidget->show();
}
void InsightWindow::onTargetStateUpdate(TargetState newState) {
this->targetState = newState;
if (newState == TargetState::RUNNING) {
this->targetStatusLabel->setText("Running");
this->programCounterValueLabel->setText("-");
} else if (newState == TargetState::STOPPED) {
this->targetStatusLabel->setText("Stopped");
this->toggleUi(false);
} else {
this->targetStatusLabel->setText("Unknown");
}
}
void InsightWindow::onTargetProgramCounterUpdate(quint32 programCounter) {
this->programCounterValueLabel->setText(
"0x" + QString::number(programCounter, 16).toUpper() + " (" + QString::number(programCounter) + ")"
);
}
void InsightWindow::toggleTargetRegistersPane() {
if (this->targetRegistersSidePane->activated) {
this->targetRegistersSidePane->deactivate();
this->targetRegistersButton->setChecked(false);
/*
* Given that the target registers side pane is currently the only pane in the left panel, the panel will be
* empty so no need to leave it visible.
*/
this->leftPanel->setVisible(false);
} else {
this->targetRegistersSidePane->activate();
this->targetRegistersButton->setChecked(true);
this->leftPanel->setVisible(true);
}
}

View File

@@ -24,7 +24,39 @@ namespace Bloom
{
class InsightWindow: public QMainWindow
{
Q_OBJECT
Q_OBJECT
public:
InsightWindow(InsightWorker& insightWorker);
void setEnvironmentConfig(const EnvironmentConfig& environmentConfig) {
this->environmentConfig = environmentConfig;
this->targetConfig = environmentConfig.targetConfig;
}
void setInsightConfig(const InsightConfig& insightConfig) {
this->insightConfig = insightConfig;
}
void init(Targets::TargetDescriptor targetDescriptor);
public slots:
void onTargetControllerSuspended();
void onTargetControllerResumed(const Bloom::Targets::TargetDescriptor& targetDescriptor);
void onTargetStateUpdate(Targets::TargetState newState);
void onTargetProgramCounterUpdate(quint32 programCounter);
void openReportIssuesUrl();
void openGettingStartedUrl();
void openAboutWindow();
void toggleTargetRegistersPane();
signals:
void refreshTargetPinStates(int variantId);
protected:
void resizeEvent(QResizeEvent* event) override;
void showEvent(QShowEvent* event) override;
private:
InsightConfig insightConfig;
EnvironmentConfig environmentConfig;
@@ -76,36 +108,5 @@ namespace Bloom
void deactivate();
void adjustPanels();
protected:
void resizeEvent(QResizeEvent* event) override;
void showEvent(QShowEvent* event) override;
public:
InsightWindow(InsightWorker& insightWorker);
void setEnvironmentConfig(const EnvironmentConfig& environmentConfig) {
this->environmentConfig = environmentConfig;
this->targetConfig = environmentConfig.targetConfig;
}
void setInsightConfig(const InsightConfig& insightConfig) {
this->insightConfig = insightConfig;
}
void init(Targets::TargetDescriptor targetDescriptor);
public slots:
void onTargetControllerSuspended();
void onTargetControllerResumed(const Bloom::Targets::TargetDescriptor& targetDescriptor);
void onTargetStateUpdate(Targets::TargetState newState);
void onTargetProgramCounterUpdate(quint32 programCounter);
void openReportIssuesUrl();
void openGettingStartedUrl();
void openAboutWindow();
void toggleTargetRegistersPane();
signals:
void refreshTargetPinStates(int variantId);
};
}

View File

@@ -2,6 +2,7 @@
#include <QtUiTools>
// Custom widgets
#include "Widgets/PanelWidget.hpp"
#include "Widgets/RotatableLabel.hpp"
#include "Widgets/SvgWidget.hpp"
@@ -9,8 +10,6 @@
#include "Widgets/ExpandingHeightScrollAreaWidget.hpp"
#include "Widgets/TargetWidgets/TargetPackageWidgetContainer.hpp"
#include "src/Logger/Logger.hpp"
using namespace Bloom;
using namespace Bloom::Widgets;

View File

@@ -7,13 +7,17 @@ namespace Bloom
{
class UiLoader: public QUiLoader
{
Q_OBJECT
private:
std::map<QString, std::function<QWidget*(QWidget* parent, const QString& name)>> customWidgetConstructorsByWidgetName = {};
Q_OBJECT
public:
explicit UiLoader(QObject* parent);
QWidget* createWidget(const QString& className, QWidget* parent, const QString& name) override;
private:
std::map<
QString,
std::function<QWidget*(QWidget* parent, const QString& name)>
> customWidgetConstructorsByWidgetName = {};
};
}

View File

@@ -8,10 +8,7 @@ namespace Bloom::Widgets
{
class Q_WIDGETS_EXPORT ClickableWidget: public QFrame
{
Q_OBJECT
protected:
void mouseReleaseEvent(QMouseEvent* event) override;
void mouseDoubleClickEvent(QMouseEvent* event) override;
Q_OBJECT
public:
explicit ClickableWidget(QWidget* parent): QFrame(parent) {};
@@ -21,5 +18,8 @@ namespace Bloom::Widgets
void clicked();
void doubleClicked();
protected:
void mouseReleaseEvent(QMouseEvent* event) override;
void mouseDoubleClickEvent(QMouseEvent* event) override;
};
}

View File

@@ -3,8 +3,8 @@
#include <QHBoxLayout>
#include <QFile>
#include "src/Helpers/Paths.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/UiLoader.hpp"
#include "src/Helpers/Paths.hpp"
#include "src/Exceptions/Exception.hpp"
using namespace Bloom::Widgets;

View File

@@ -8,12 +8,14 @@ namespace Bloom::Widgets
{
class Q_WIDGETS_EXPORT ErrorDialogue: public QDialog
{
Q_OBJECT
QWidget* container = nullptr;
QLabel* errorMessageLabel = nullptr;
QPushButton* okButton = nullptr;
Q_OBJECT
public:
ErrorDialogue(const QString& windowTitle, const QString& errorMessage, QWidget* parent);
private:
QWidget* container = nullptr;
QLabel* errorMessageLabel = nullptr;
QPushButton* okButton = nullptr;
};
}

View File

@@ -8,7 +8,11 @@ namespace Bloom::Widgets
{
class Q_WIDGETS_EXPORT ExpandingHeightScrollAreaWidget: public QScrollArea
{
Q_OBJECT
Q_OBJECT
public:
explicit ExpandingHeightScrollAreaWidget(QWidget* parent): QScrollArea(parent) {};
protected:
[[nodiscard]] QSize scrollAreaSize() const {
auto parentWidget = this->parentWidget();
@@ -34,9 +38,5 @@ namespace Bloom::Widgets
[[nodiscard]] QSize minimumSizeHint() const override {
return this->scrollAreaSize();
};
public:
explicit ExpandingHeightScrollAreaWidget(QWidget* parent): QScrollArea(parent) {};
};
}

View File

@@ -35,6 +35,20 @@ void PanelWidget::setMaximumResize(int maximumResize) {
}
}
bool PanelWidget::event(QEvent* event) {
if (event->type() == QEvent::Type::HoverMove) {
auto hoverEvent = static_cast<QHoverEvent*>(event);
if (this->resizingActive || this->isPositionWithinHandleArea(hoverEvent->position().toPoint())) {
this->setCursor(this->resizeCursor);
} else {
this->setCursor(Qt::ArrowCursor);
}
}
return QFrame::event(event);
}
void PanelWidget::mousePressEvent(QMouseEvent* event) {
const auto position = event->pos();
@@ -61,20 +75,6 @@ void PanelWidget::mouseReleaseEvent(QMouseEvent* event) {
}
}
bool PanelWidget::event(QEvent* event) {
if (event->type() == QEvent::Type::HoverMove) {
auto hoverEvent = static_cast<QHoverEvent*>(event);
if (this->resizingActive || this->isPositionWithinHandleArea(hoverEvent->position().toPoint())) {
this->setCursor(this->resizeCursor);
} else {
this->setCursor(Qt::ArrowCursor);
}
}
return QFrame::event(event);
}
void PanelWidget::mouseMoveEvent(QMouseEvent* event) {
const auto position = event->pos();

View File

@@ -19,29 +19,11 @@ namespace Bloom::Widgets
class Q_WIDGETS_EXPORT PanelWidget: public QFrame
{
Q_OBJECT
Q_OBJECT
Q_PROPERTY(int handleSize READ getHandleSize WRITE setHandleSize DESIGNABLE true)
Q_PROPERTY(int minimumResize READ getMinimumResize WRITE setMinimumResize DESIGNABLE true)
Q_PROPERTY(Bloom::Widgets::PanelWidgetType panelType READ getPanelType WRITE setPanelType DESIGNABLE true)
protected:
int handleSize = 10;
int minimumResize = 10;
int maximumResize = 500;
PanelWidgetType panelType = PanelWidgetType::LEFT;
QCursor resizeCursor = Qt::SplitHCursor;
bool resizingActive = false;
int resizingOffset = 0;
void mousePressEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
bool event(QEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;
std::pair<QPoint, QPoint> getHandleArea() const;
bool isPositionWithinHandleArea(const QPoint& position) const;
public:
explicit PanelWidget(QWidget* parent);
@@ -73,5 +55,23 @@ namespace Bloom::Widgets
PanelWidgetType getPanelType() {
return this->panelType;
}
protected:
int handleSize = 10;
int minimumResize = 10;
int maximumResize = 500;
PanelWidgetType panelType = PanelWidgetType::LEFT;
QCursor resizeCursor = Qt::SplitHCursor;
bool resizingActive = false;
int resizingOffset = 0;
bool event(QEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;
std::pair<QPoint, QPoint> getHandleArea() const;
bool isPositionWithinHandleArea(const QPoint& position) const;
};
}

View File

@@ -7,11 +7,16 @@ namespace Bloom::Widgets
{
class RotatableLabel: public QLabel
{
Q_OBJECT
private:
int angle = 90;
Q_OBJECT
[[nodiscard]] QSize getContainerSize() const;
public:
RotatableLabel(const QString& text, QWidget* parent): QLabel(text, parent) {};
RotatableLabel(int angleDegrees, const QString& text, QWidget* parent)
: QLabel(text, parent), angle(angleDegrees) {};
void setAngle(int angleDegrees) {
this->angle = angleDegrees;
}
protected:
void paintEvent(QPaintEvent* event) override;
@@ -24,14 +29,9 @@ namespace Bloom::Widgets
return this->getContainerSize();
};
public:
RotatableLabel(const QString& text, QWidget* parent): QLabel(text, parent) {};
RotatableLabel(int angleDegrees, const QString& text, QWidget* parent): QLabel(text, parent) {
this->setAngle(angleDegrees);
};
private:
int angle = 90;
void setAngle(int angleDegrees) {
this->angle = angleDegrees;
}
[[nodiscard]] QSize getContainerSize() const;
};
}

View File

@@ -9,19 +9,13 @@ namespace Bloom::Widgets
{
class SvgToolButton: public QToolButton
{
Q_OBJECT
Q_OBJECT
Q_PROPERTY(QString svgFilePath READ getSvgFilePath WRITE setSvgFilePath DESIGNABLE true)
Q_PROPERTY(QString disabledSvgFilePath READ getDisabledSvgFilePath WRITE setDisabledSvgFilePath DESIGNABLE true)
Q_PROPERTY(int buttonWidth READ getButtonWidth WRITE setButtonWidth DESIGNABLE true)
Q_PROPERTY(int buttonHeight READ getButtonHeight WRITE setButtonHeight DESIGNABLE true)
private:
SvgWidget* svgWidget = new SvgWidget(this);
SvgWidget* disabledSvgWidget = nullptr;
int buttonWidth = 0;
int buttonHeight = 0;
public:
explicit SvgToolButton(QWidget* parent): QToolButton(parent) {
this->setButtonWidth(10);
@@ -63,5 +57,10 @@ namespace Bloom::Widgets
[[nodiscard]] int getButtonHeight() const {
return this->buttonHeight;
}
private:
SvgWidget* svgWidget = new SvgWidget(this);
int buttonWidth = 0;
int buttonHeight = 0;
};
}

View File

@@ -10,25 +10,13 @@ namespace Bloom::Widgets
{
class SvgWidget: public QFrame
{
Q_OBJECT
Q_OBJECT
Q_PROPERTY(QString svgFilePath READ getSvgFilePath WRITE setSvgFilePath DESIGNABLE true)
Q_PROPERTY(QString disabledSvgFilePath READ getDisabledSvgFilePath WRITE setDisabledSvgFilePath DESIGNABLE true)
Q_PROPERTY(int containerWidth READ getContainerWidth WRITE setContainerWidth DESIGNABLE true)
Q_PROPERTY(int containerHeight READ getContainerHeight WRITE setContainerHeight DESIGNABLE true)
Q_PROPERTY(int angle READ getAngle WRITE setAngle DESIGNABLE true)
private:
QSvgRenderer renderer = new QSvgRenderer(this);
QString svgFilePath;
QString disabledSvgFilePath;
int containerWidth = 0;
int containerHeight = 0;
int angle = 0;
protected:
void paintEvent(QPaintEvent* paintEvent) override;
void changeEvent(QEvent* event) override;
public:
explicit SvgWidget(QWidget* parent);
@@ -73,5 +61,16 @@ namespace Bloom::Widgets
return this->angle;
}
protected:
void paintEvent(QPaintEvent* paintEvent) override;
void changeEvent(QEvent* event) override;
private:
QSvgRenderer renderer = new QSvgRenderer(this);
QString svgFilePath;
QString disabledSvgFilePath;
int containerWidth = 0;
int containerHeight = 0;
int angle = 0;
};
}

View File

@@ -16,17 +16,6 @@ BitBodyWidget::BitBodyWidget(
this->setContentsMargins(0, 0, 0, 0);
}
void BitBodyWidget::mouseReleaseEvent(QMouseEvent* event) {
if (this->isEnabled()) {
if (!this->readOnly && event->button() == Qt::MouseButton::LeftButton) {
this->bit = !this->bit;
this->update();
}
ClickableWidget::mouseReleaseEvent(event);
}
}
bool BitBodyWidget::event(QEvent* event) {
if (this->isEnabled() && !this->readOnly) {
switch (event->type()) {
@@ -49,6 +38,17 @@ bool BitBodyWidget::event(QEvent* event) {
return QWidget::event(event);
}
void BitBodyWidget::mouseReleaseEvent(QMouseEvent* event) {
if (this->isEnabled()) {
if (!this->readOnly && event->button() == Qt::MouseButton::LeftButton) {
this->bit = !this->bit;
this->update();
}
ClickableWidget::mouseReleaseEvent(event);
}
}
void BitBodyWidget::paintEvent(QPaintEvent* event) {
auto painter = QPainter(this);
this->drawWidget(painter);

View File

@@ -15,18 +15,7 @@ namespace Bloom::Widgets
{
class BitBodyWidget: public ClickableWidget
{
Q_OBJECT
private:
int bitIndex = 0;
std::bitset<std::numeric_limits<unsigned char>::digits>::reference bit;
bool readOnly = true;
bool hoverActive = false;
protected:
bool event(QEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
void paintEvent(QPaintEvent* event) override;
void drawWidget(QPainter& painter);
Q_OBJECT
public:
constexpr static int WIDTH = 23;
@@ -38,5 +27,17 @@ namespace Bloom::Widgets
bool readOnly,
QWidget* parent
);
protected:
bool event(QEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
void paintEvent(QPaintEvent* event) override;
void drawWidget(QPainter& painter);
private:
int bitIndex = 0;
std::bitset<std::numeric_limits<unsigned char>::digits>::reference bit;
bool readOnly = true;
bool hoverActive = false;
};
}

View File

@@ -3,7 +3,6 @@
#include <QVBoxLayout>
#include <QScrollArea>
#include <QMargins>
#include <set>
#include "BitBodyWidget.hpp"

View File

@@ -17,20 +17,11 @@ namespace Bloom::Widgets
{
class BitWidget: public QWidget
{
Q_OBJECT
Q_OBJECT
private:
const static int VERTICAL_SPACING = 3;
int bitIndex = 0;
int bitNumber = 0;
std::bitset<std::numeric_limits<unsigned char>::digits>& bitset;
bool readOnly = true;
BitBodyWidget* body = nullptr;
QLabel* bitLabel = nullptr;
QLabel* bitNumberLabel = nullptr;
public:
constexpr static int LABEL_HEIGHT = 14;
constexpr static int LABEL_COUNT = 2;
@@ -49,5 +40,16 @@ namespace Bloom::Widgets
signals:
void bitChanged();
private:
int bitIndex = 0;
int bitNumber = 0;
std::bitset<std::numeric_limits<unsigned char>::digits>& bitset;
bool readOnly = true;
BitBodyWidget* body = nullptr;
QLabel* bitLabel = nullptr;
QLabel* bitNumberLabel = nullptr;
};
}

View File

@@ -45,6 +45,11 @@ QWidget(parent), byteNumber(byteNumber), byte(byte), readOnly(readOnly) {
}
}
void BitsetWidget::updateValue() {
this->bitset = {this->byte};
this->update();
}
void BitsetWidget::paintEvent(QPaintEvent* event) {
QWidget::paintEvent(event);
auto painter = QPainter(this);
@@ -101,8 +106,3 @@ void BitsetWidget::drawWidget(QPainter& painter) {
byteHex
);
}
void BitsetWidget::updateValue() {
this->bitset = {this->byte};
this->update();
}

View File

@@ -13,18 +13,7 @@ namespace Bloom::Widgets
{
class BitsetWidget: public QWidget
{
Q_OBJECT
private:
int byteNumber = 0;
unsigned char& byte;
std::bitset<std::numeric_limits<unsigned char>::digits> bitset = {byte};
bool readOnly = true;
QWidget* container = nullptr;
protected:
void paintEvent(QPaintEvent* event) override;
void drawWidget(QPainter& painter);
Q_OBJECT
public:
constexpr static int VALUE_GRAPHIC_HEIGHT = 20;
@@ -37,5 +26,17 @@ namespace Bloom::Widgets
signals:
void byteChanged();
protected:
void paintEvent(QPaintEvent* event) override;
void drawWidget(QPainter& painter);
private:
int byteNumber = 0;
unsigned char& byte;
std::bitset<std::numeric_limits<unsigned char>::digits> bitset = {byte};
bool readOnly = true;
QWidget* container = nullptr;
};
}

View File

@@ -13,14 +13,16 @@ namespace Bloom::Widgets
{
class CurrentItem: public Item
{
Q_OBJECT
QHBoxLayout* layout = new QHBoxLayout(this);
QLabel* titleLabel = new QLabel(this);
Q_OBJECT
public:
CurrentItem(
const Targets::TargetMemoryBuffer& registerValue,
QWidget *parent
);
private:
QHBoxLayout* layout = new QHBoxLayout(this);
QLabel* titleLabel = new QLabel(this);
};
}

View File

@@ -8,7 +8,7 @@ namespace Bloom::Widgets
{
class Item: public ClickableWidget
{
Q_OBJECT
Q_OBJECT
public:
Targets::TargetMemoryBuffer registerValue;
Item(const Targets::TargetMemoryBuffer& registerValue, QWidget *parent);

View File

@@ -10,11 +10,7 @@ namespace Bloom::Widgets
{
class RegisterHistoryItem: public Item
{
Q_OBJECT
QVBoxLayout* layout = new QVBoxLayout(this);
QLabel* dateLabel = new QLabel(this);
QLabel* valueLabel = new QLabel(this);
QLabel* descriptionLayout = new QLabel(this);
Q_OBJECT
public:
RegisterHistoryItem(
@@ -22,5 +18,11 @@ namespace Bloom::Widgets
const QDateTime& changeDate,
QWidget *parent
);
private:
QVBoxLayout* layout = new QVBoxLayout(this);
QLabel* dateLabel = new QLabel(this);
QLabel* valueLabel = new QLabel(this);
QLabel* descriptionLayout = new QLabel(this);
};
}

View File

@@ -6,7 +6,7 @@
#include <QScrollBar>
#include <set>
#include "../../../UiLoader.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/UiLoader.hpp"
#include "src/Helpers/Paths.hpp"
#include "src/Helpers/DateTime.hpp"

View File

@@ -23,26 +23,7 @@ namespace Bloom::Widgets
{
class RegisterHistoryWidget: public QWidget
{
Q_OBJECT
private:
Targets::TargetRegisterDescriptor registerDescriptor;
InsightWorker& insightWorker;
QWidget* container = nullptr;
QWidget* itemContainer = nullptr;
QVBoxLayout* itemContainerLayout = nullptr;
Targets::TargetState targetState = Targets::TargetState::UNKNOWN;
CurrentItem* currentItem = nullptr;
Item* selectedItemWidget = nullptr;
private slots:
void onTargetStateChanged(Targets::TargetState newState);
void onItemSelectionChange(Item* newlySelectedWidget);
void onRegistersWritten(Targets::TargetRegisters targetRegisters, const QDateTime& changeDate);
protected:
void resizeEvent(QResizeEvent* event) override;
Q_OBJECT
public:
RegisterHistoryWidget(
@@ -64,5 +45,25 @@ namespace Bloom::Widgets
signals:
void historyItemSelected(const Targets::TargetMemoryBuffer& registerValue);
protected:
void resizeEvent(QResizeEvent* event) override;
private:
Targets::TargetRegisterDescriptor registerDescriptor;
InsightWorker& insightWorker;
QWidget* container = nullptr;
QWidget* itemContainer = nullptr;
QVBoxLayout* itemContainerLayout = nullptr;
Targets::TargetState targetState = Targets::TargetState::UNKNOWN;
CurrentItem* currentItem = nullptr;
Item* selectedItemWidget = nullptr;
private slots:
void onTargetStateChanged(Targets::TargetState newState);
void onItemSelectionChange(Item* newlySelectedWidget);
void onRegistersWritten(Targets::TargetRegisters targetRegisters, const QDateTime& changeDate);
};
}

View File

@@ -2,9 +2,6 @@
#include <QVBoxLayout>
#include <QMargins>
#include <QTableWidget>
#include <QScrollBar>
#include <set>
#include <QDesktopServices>
#include "src/Insight/UserInterfaces/InsightWindow/UiLoader.hpp"

View File

@@ -22,7 +22,21 @@ namespace Bloom::Widgets
{
class TargetRegisterInspectorWindow: public QWidget
{
Q_OBJECT
Q_OBJECT
public:
TargetRegisterInspectorWindow(
const Targets::TargetRegisterDescriptor& registerDescriptor,
InsightWorker& insightWorker,
Targets::TargetState currentTargetState,
std::optional<Targets::TargetMemoryBuffer> registerValue = std::nullopt,
QWidget* parent = nullptr
);
static bool registerSupported(const Targets::TargetRegisterDescriptor& descriptor);
void setValue(const Targets::TargetMemoryBuffer& registerValue);
private:
Targets::TargetRegisterDescriptor registerDescriptor;
Targets::TargetMemoryBuffer registerValue;
@@ -57,18 +71,5 @@ namespace Bloom::Widgets
void refreshRegisterValue();
void applyChanges();
void openHelpPage();
public:
TargetRegisterInspectorWindow(
const Targets::TargetRegisterDescriptor& registerDescriptor,
InsightWorker& insightWorker,
Targets::TargetState currentTargetState,
std::optional<Targets::TargetMemoryBuffer> registerValue = std::nullopt,
QWidget* parent = nullptr
);
static bool registerSupported(const Targets::TargetRegisterDescriptor& descriptor);
void setValue(const Targets::TargetMemoryBuffer& registerValue);
};
}

View File

@@ -6,9 +6,7 @@ namespace Bloom::Widgets
{
class ItemWidget: public ClickableWidget
{
Q_OBJECT
protected:
virtual void postSetSelected(bool selected) {};
Q_OBJECT
public:
ItemWidget(QWidget *parent);
@@ -18,5 +16,8 @@ namespace Bloom::Widgets
signals:
void selected(ItemWidget*);
protected:
virtual void postSetSelected(bool selected) {};
};
}

View File

@@ -20,14 +20,7 @@ namespace Bloom::Widgets
class RegisterWidget;
class RegisterGroupWidget: public ItemWidget
{
Q_OBJECT
private:
QVBoxLayout* layout = new QVBoxLayout(this);
ItemWidget* headerWidget = new ItemWidget(this);
SvgWidget* arrowIcon = new SvgWidget(this->headerWidget);
SvgWidget* registerGroupIcon = new SvgWidget(this->headerWidget);
QLabel* label = new QLabel(this->headerWidget);
QWidget* bodyWidget = new QWidget(this);
Q_OBJECT
public:
QString name;
@@ -48,5 +41,13 @@ namespace Bloom::Widgets
void setAllRegistersVisible(bool visible);
void filterRegisters(const std::string& keyword);
private:
QVBoxLayout* layout = new QVBoxLayout(this);
ItemWidget* headerWidget = new ItemWidget(this);
SvgWidget* arrowIcon = new SvgWidget(this->headerWidget);
SvgWidget* registerGroupIcon = new SvgWidget(this->headerWidget);
QLabel* label = new QLabel(this->headerWidget);
QWidget* bodyWidget = new QWidget(this);
};
}

View File

@@ -92,6 +92,35 @@ void RegisterWidget::clearInlineValue() {
this->valueLabel->clear();
}
void RegisterWidget::contextMenuEvent(QContextMenuEvent* event) {
this->setSelected(true);
auto menu = new QMenu(this);
menu->addAction(this->openInspectionWindowAction);
menu->addAction(this->refreshValueAction);
menu->addSeparator();
auto copyMenu = new QMenu("Copy", this);
copyMenu->addAction(this->copyValueNameAction);
copyMenu->addSeparator();
copyMenu->addAction(this->copyValueDecimalAction);
copyMenu->addAction(this->copyValueHexAction);
copyMenu->addAction(this->copyValueBinaryAction);
menu->addMenu(copyMenu);
this->openInspectionWindowAction->setEnabled(TargetRegisterInspectorWindow::registerSupported(this->descriptor));
const auto targetStopped = this->targetState == Targets::TargetState::STOPPED;
const auto targetStoppedAndValuePresent = targetStopped && this->currentRegister.has_value();
this->refreshValueAction->setEnabled(targetStopped);
this->copyValueDecimalAction->setEnabled(targetStoppedAndValuePresent);
this->copyValueHexAction->setEnabled(targetStoppedAndValuePresent);
this->copyValueBinaryAction->setEnabled(targetStoppedAndValuePresent);
menu->exec(event->globalPos());
}
void RegisterWidget::openInspectionWindow() {
if (!TargetRegisterInspectorWindow::registerSupported(this->descriptor)) {
return;
@@ -183,35 +212,6 @@ void RegisterWidget::copyValueBinary() {
}
}
void RegisterWidget::contextMenuEvent(QContextMenuEvent* event) {
this->setSelected(true);
auto menu = new QMenu(this);
menu->addAction(this->openInspectionWindowAction);
menu->addAction(this->refreshValueAction);
menu->addSeparator();
auto copyMenu = new QMenu("Copy", this);
copyMenu->addAction(this->copyValueNameAction);
copyMenu->addSeparator();
copyMenu->addAction(this->copyValueDecimalAction);
copyMenu->addAction(this->copyValueHexAction);
copyMenu->addAction(this->copyValueBinaryAction);
menu->addMenu(copyMenu);
this->openInspectionWindowAction->setEnabled(TargetRegisterInspectorWindow::registerSupported(this->descriptor));
const auto targetStopped = this->targetState == Targets::TargetState::STOPPED;
const auto targetStoppedAndValuePresent = targetStopped && this->currentRegister.has_value();
this->refreshValueAction->setEnabled(targetStopped);
this->copyValueDecimalAction->setEnabled(targetStoppedAndValuePresent);
this->copyValueHexAction->setEnabled(targetStoppedAndValuePresent);
this->copyValueBinaryAction->setEnabled(targetStoppedAndValuePresent);
menu->exec(event->globalPos());
}
void RegisterWidget::postSetSelected(bool selected) {
auto valueLabelStyle = this->valueLabel->style();
valueLabelStyle->unpolish(this->valueLabel);

View File

@@ -19,30 +19,7 @@ namespace Bloom::Widgets
{
class RegisterWidget: public ItemWidget
{
Q_OBJECT
private:
InsightWorker& insightWorker;
QHBoxLayout* layout = new QHBoxLayout(this);
SvgWidget* registerIcon = new SvgWidget(this);
QLabel* nameLabel = new QLabel(this);
QLabel* valueLabel = new QLabel(this);
// Context-menu actions
QAction* openInspectionWindowAction = new QAction("Inspect", this);
QAction* refreshValueAction = new QAction("Refresh Value", this);
QAction* copyValueNameAction = new QAction("Copy Register Name", this);
QAction* copyValueHexAction = new QAction("Copy Hexadecimal Value", this);
QAction* copyValueDecimalAction = new QAction("Copy Decimal Value", this);
QAction* copyValueBinaryAction = new QAction("Copy Binary Value", this);
TargetRegisterInspectorWindow* inspectWindow = nullptr;
void postSetSelected(bool selected) override;
Targets::TargetState targetState = Targets::TargetState::UNKNOWN;
private slots:
void onTargetStateChange(Targets::TargetState newState);
Q_OBJECT
public:
Targets::TargetRegisterDescriptor descriptor;
@@ -71,5 +48,29 @@ namespace Bloom::Widgets
void copyValueHex();
void copyValueDecimal();
void copyValueBinary();
private:
InsightWorker& insightWorker;
QHBoxLayout* layout = new QHBoxLayout(this);
SvgWidget* registerIcon = new SvgWidget(this);
QLabel* nameLabel = new QLabel(this);
QLabel* valueLabel = new QLabel(this);
// Context-menu actions
QAction* openInspectionWindowAction = new QAction("Inspect", this);
QAction* refreshValueAction = new QAction("Refresh Value", this);
QAction* copyValueNameAction = new QAction("Copy Register Name", this);
QAction* copyValueHexAction = new QAction("Copy Hexadecimal Value", this);
QAction* copyValueDecimalAction = new QAction("Copy Decimal Value", this);
QAction* copyValueBinaryAction = new QAction("Copy Binary Value", this);
TargetRegisterInspectorWindow* inspectWindow = nullptr;
void postSetSelected(bool selected) override;
Targets::TargetState targetState = Targets::TargetState::UNKNOWN;
private slots:
void onTargetStateChange(Targets::TargetState newState);
};
}

View File

@@ -3,7 +3,7 @@
#include <QVBoxLayout>
#include <set>
#include "../../UiLoader.hpp"
#include "src/Insight/UserInterfaces/InsightWindow/UiLoader.hpp"
#include "RegisterGroupWidget.hpp"
#include "RegisterWidget.hpp"
@@ -123,54 +123,6 @@ TargetRegistersPaneWidget::TargetRegistersPaneWidget(
);
}
void TargetRegistersPaneWidget::resizeEvent(QResizeEvent* event) {
const auto parentSize = this->parent->size();
const auto width = parentSize.width() - 1;
this->container->setFixedSize(width, parentSize.height());
this->searchInput->setFixedWidth(width - 20);
/*
* In order to avoid the panel resize handle overlapping the scroll bar handle, we reduce the size of
* the scroll area.
*/
this->itemScrollArea->setFixedSize(
width - this->parent->getHandleSize(),
parentSize.height() - this->toolBar->height() - this->searchInput->height() - 5
);
}
void TargetRegistersPaneWidget::postActivate() {
if (this->targetState == Targets::TargetState::STOPPED) {
this->refreshRegisterValues();
}
}
void TargetRegistersPaneWidget::postDeactivate() {
}
void TargetRegistersPaneWidget::onTargetStateChanged(Targets::TargetState newState) {
using Targets::TargetState;
this->targetState = newState;
if (newState == TargetState::STOPPED && this->activated) {
this->refreshRegisterValues();
}
}
void TargetRegistersPaneWidget::onRegistersRead(const Targets::TargetRegisters& registers) {
for (const auto& targetRegister : registers) {
auto& descriptor = targetRegister.descriptor;
for (const auto& registerGroupWidget : this->registerGroupWidgets) {
if (registerGroupWidget->registerWidgetsMappedByDescriptor.contains(descriptor)) {
registerGroupWidget->registerWidgetsMappedByDescriptor.at(descriptor)->setRegisterValue(targetRegister);
break;
}
}
}
}
void TargetRegistersPaneWidget::filterRegisters(const QString& keyword) {
auto stdKeyword = keyword.toLower().toStdString();
@@ -254,3 +206,51 @@ void TargetRegistersPaneWidget::onItemSelectionChange(ItemWidget* newlySelectedW
this->selectedItemWidget = newlySelectedWidget;
}
}
void TargetRegistersPaneWidget::resizeEvent(QResizeEvent* event) {
const auto parentSize = this->parent->size();
const auto width = parentSize.width() - 1;
this->container->setFixedSize(width, parentSize.height());
this->searchInput->setFixedWidth(width - 20);
/*
* In order to avoid the panel resize handle overlapping the scroll bar handle, we reduce the size of
* the scroll area.
*/
this->itemScrollArea->setFixedSize(
width - this->parent->getHandleSize(),
parentSize.height() - this->toolBar->height() - this->searchInput->height() - 5
);
}
void TargetRegistersPaneWidget::postActivate() {
if (this->targetState == Targets::TargetState::STOPPED) {
this->refreshRegisterValues();
}
}
void TargetRegistersPaneWidget::postDeactivate() {
}
void TargetRegistersPaneWidget::onTargetStateChanged(Targets::TargetState newState) {
using Targets::TargetState;
this->targetState = newState;
if (newState == TargetState::STOPPED && this->activated) {
this->refreshRegisterValues();
}
}
void TargetRegistersPaneWidget::onRegistersRead(const Targets::TargetRegisters& registers) {
for (const auto& targetRegister : registers) {
auto& descriptor = targetRegister.descriptor;
for (const auto& registerGroupWidget : this->registerGroupWidgets) {
if (registerGroupWidget->registerWidgetsMappedByDescriptor.contains(descriptor)) {
registerGroupWidget->registerWidgetsMappedByDescriptor.at(descriptor)->setRegisterValue(targetRegister);
break;
}
}
}
}

View File

@@ -19,10 +19,37 @@
namespace Bloom::Widgets
{
class RegisterGroupWidget;
class TargetRegistersPaneWidget: public QWidget
{
Q_OBJECT
Q_OBJECT
public:
bool activated = false;
TargetRegistersPaneWidget(
const Targets::TargetDescriptor& targetDescriptor,
InsightWorker& insightWorker,
PanelWidget *parent
);
void filterRegisters(const QString& keyword);
void collapseAllRegisterGroups();
void expandAllRegisterGroups();
void refreshRegisterValues(std::optional<std::function<void(void)>> callback = std::nullopt);
void activate();
void deactivate();
public slots:
void onItemSelectionChange(ItemWidget* newlySelectedWidget);
protected:
void resizeEvent(QResizeEvent* event) override;
virtual void postActivate();
virtual void postDeactivate();
private:
const Targets::TargetDescriptor& targetDescriptor;
InsightWorker& insightWorker;
@@ -48,32 +75,5 @@ namespace Bloom::Widgets
private slots:
void onTargetStateChanged(Targets::TargetState newState);
void onRegistersRead(const Targets::TargetRegisters& registers);
protected:
void resizeEvent(QResizeEvent* event) override;
virtual void postActivate();
virtual void postDeactivate();
public:
bool activated = false;
TargetRegistersPaneWidget(
const Targets::TargetDescriptor& targetDescriptor,
InsightWorker& insightWorker,
PanelWidget *parent
);
void filterRegisters(const QString& keyword);
void collapseAllRegisterGroups();
void expandAllRegisterGroups();
void refreshRegisterValues(std::optional<std::function<void(void)>> callback = std::nullopt);
void activate();
void deactivate();
public slots:
void onItemSelectionChange(ItemWidget* newlySelectedWidget);
};
}

View File

@@ -1,7 +1,7 @@
#include "BodyWidget.hpp"
#include <QPainter>
#include "BodyWidget.hpp"
#include "src/Logger/Logger.hpp"
#include "src/Exceptions/Exception.hpp"
using namespace Bloom::Widgets::InsightTargetWidgets::Dip;

View File

@@ -6,18 +6,9 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
{
class BodyWidget: public QWidget
{
Q_OBJECT
Q_PROPERTY(QColor bodyColor READ getBodyColor WRITE setBodyColor DESIGNABLE true)
Q_PROPERTY(int disableAlphaLevel READ getDisableAlphaLevel WRITE setDisableAlphaLevel DESIGNABLE true)
private:
// These properties can be modified via Qt style sheets (see Stylesheets/DualInlinePackage.qss)
QColor bodyColor = QColor("#8E8B83");
int disableAlphaLevel = 100;
protected:
void paintEvent(QPaintEvent* event) override;
void drawWidget(QPainter& painter);
Q_OBJECT
Q_PROPERTY(QColor bodyColor READ getBodyColor WRITE setBodyColor DESIGNABLE true)
Q_PROPERTY(int disableAlphaLevel READ getDisableAlphaLevel WRITE setDisableAlphaLevel DESIGNABLE true)
public:
explicit BodyWidget(QWidget* parent): QWidget(parent) {
@@ -39,5 +30,14 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
void setDisableAlphaLevel(int level) {
this->disableAlphaLevel = level;
}
protected:
void paintEvent(QPaintEvent* event) override;
void drawWidget(QPainter& painter);
private:
// These properties can be modified via Qt style sheets (see Stylesheets/DualInlinePackage.qss)
QColor bodyColor = QColor("#8E8B83");
int disableAlphaLevel = 100;
};
}

View File

@@ -6,10 +6,7 @@
#include <QEvent>
#include <QFile>
#include "../../../InsightWindow.hpp"
#include "src/Helpers/Paths.hpp"
#include "PinWidget.hpp"
#include "BodyWidget.hpp"
using namespace Bloom::Widgets::InsightTargetWidgets::Dip;
using namespace Bloom::Exceptions;

View File

@@ -6,6 +6,7 @@
#include <QVBoxLayout>
#include "../TargetPackageWidget.hpp"
#include "PinWidget.hpp"
#include "BodyWidget.hpp"
#include "src/Targets/TargetVariant.hpp"
@@ -17,12 +18,7 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
*/
class DualInlinePackageWidget: public TargetPackageWidget
{
Q_OBJECT
private:
QVBoxLayout* layout = nullptr;
QHBoxLayout* topPinLayout = nullptr;
QHBoxLayout* bottomPinLayout = nullptr;
BodyWidget* bodyWidget = nullptr;
Q_OBJECT
public:
DualInlinePackageWidget(
@@ -30,5 +26,11 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
InsightWorker& insightWorker,
QWidget* parent
);
private:
QVBoxLayout* layout = nullptr;
QHBoxLayout* topPinLayout = nullptr;
QHBoxLayout* bottomPinLayout = nullptr;
BodyWidget* bodyWidget = nullptr;
};
}

View File

@@ -1,10 +1,7 @@
#include <QPainter>
#include <QLayout>
#include <QEvent>
#include <QMenu>
#include <QContextMenuEvent>
#include "PinBodyWidget.hpp"
#include <QPainter>
#include "src/Logger/Logger.hpp"
using namespace Bloom::Widgets::InsightTargetWidgets::Dip;

View File

@@ -1,19 +1,17 @@
#pragma once
#include <QWidget>
#include <QMouseEvent>
#include <utility>
#include <QEvent>
#include "../TargetPinBodyWidget.hpp"
#include "src/Targets/TargetPinDescriptor.hpp"
namespace Bloom::Widgets::InsightTargetWidgets::Dip
{
class PinBodyWidget: public TargetPinBodyWidget
{
protected:
void paintEvent(QPaintEvent* event) override;
void drawWidget(QPainter& painter);
Q_OBJECT
public:
static const int WIDTH = 30;
@@ -26,5 +24,9 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
this->setFixedSize(PinBodyWidget::WIDTH, PinBodyWidget::HEIGHT);
this->setObjectName("target-pin-body");
}
protected:
void paintEvent(QPaintEvent* event) override;
void drawWidget(QPainter& painter);
};
}

View File

@@ -1,12 +1,4 @@
#include <QWidget>
#include <QPainter>
#include <QLayout>
#include <cmath>
#include <QEvent>
#include "PinWidget.hpp"
#include "PinBodyWidget.hpp"
#include "src/Logger/Logger.hpp"
using namespace Bloom::Widgets::InsightTargetWidgets::Dip;
using namespace Bloom::Targets;

View File

@@ -1,9 +1,11 @@
#pragma once
#include <QWidget>
#include <QVBoxLayout>
#include <QLabel>
#include "../TargetPinWidget.hpp"
#include "PinBodyWidget.hpp"
#include "src/Targets/TargetVariant.hpp"
@@ -11,20 +13,7 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
{
class PinWidget: public TargetPinWidget
{
Q_OBJECT
private:
QVBoxLayout* layout = nullptr;
QLabel* pinNumberLabel = nullptr;
QLabel* pinNameLabel = nullptr;
QLabel* pinDirectionLabel = nullptr;
PinBodyWidget* bodyWidget = nullptr;
void setLabelColor(const QString& hexColor) {
auto style = QString("QLabel { color: " + hexColor + "; }");
if (this->pinNameLabel != nullptr) {
this->pinNameLabel->setStyleSheet(style);
}
}
Q_OBJECT
public:
static const int MINIMUM_WIDTH = 30;
@@ -59,5 +48,19 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
this->setLabelColor(this->pinStateChanged ? "#4d7bba" : "#a6a7aa");
}
private:
QVBoxLayout* layout = nullptr;
QLabel* pinNumberLabel = nullptr;
QLabel* pinNameLabel = nullptr;
QLabel* pinDirectionLabel = nullptr;
PinBodyWidget* bodyWidget = nullptr;
void setLabelColor(const QString& hexColor) {
auto style = QString("QLabel { color: " + hexColor + "; }");
if (this->pinNameLabel != nullptr) {
this->pinNameLabel->setStyleSheet(style);
}
}
};
}

View File

@@ -1,7 +1,6 @@
#include <QPainter>
#include "BodyWidget.hpp"
#include "src/Logger/Logger.hpp"
#include <QPainter>
using namespace Bloom::Widgets::InsightTargetWidgets::Qfp;

View File

@@ -6,18 +6,9 @@ namespace Bloom::Widgets::InsightTargetWidgets::Qfp
{
class BodyWidget: public QWidget
{
Q_OBJECT
Q_PROPERTY(QColor bodyColor READ getBodyColor WRITE setBodyColor DESIGNABLE true)
Q_PROPERTY(int disableAlphaLevel READ getDisableAlphaLevel WRITE setDisableAlphaLevel DESIGNABLE true)
private:
// These properties can be modified via Qt style sheets (see Stylesheets/QuadFlatPackage.qss)
QColor bodyColor = QColor("#8E8B83");
int disableAlphaLevel = 100;
protected:
void paintEvent(QPaintEvent* event) override;
void drawWidget(QPainter& painter);
Q_OBJECT
Q_PROPERTY(QColor bodyColor READ getBodyColor WRITE setBodyColor DESIGNABLE true)
Q_PROPERTY(int disableAlphaLevel READ getDisableAlphaLevel WRITE setDisableAlphaLevel DESIGNABLE true)
public:
explicit BodyWidget(QWidget* parent): QWidget(parent) {
@@ -39,5 +30,14 @@ namespace Bloom::Widgets::InsightTargetWidgets::Qfp
void setDisableAlphaLevel(int level) {
this->disableAlphaLevel = level;
}
protected:
void paintEvent(QPaintEvent* event) override;
void drawWidget(QPainter& painter);
private:
// These properties can be modified via Qt style sheets (see Stylesheets/QuadFlatPackage.qss)
QColor bodyColor = QColor("#8E8B83");
int disableAlphaLevel = 100;
};
}

View File

@@ -1,8 +1,8 @@
#include "PinBodyWidget.hpp"
#include <QPainter>
#include <QEvent>
#include "PinBodyWidget.hpp"
using namespace Bloom::Widgets::InsightTargetWidgets::Qfp;
using namespace Bloom::Targets;

View File

@@ -5,18 +5,14 @@
#include <utility>
#include "../TargetPinBodyWidget.hpp"
#include "src/Targets/TargetPinDescriptor.hpp"
namespace Bloom::Widgets::InsightTargetWidgets::Qfp
{
class PinBodyWidget: public TargetPinBodyWidget
{
private:
bool isVertical = false;
protected:
void paintEvent(QPaintEvent* event) override;
void drawWidget(QPainter& painter);
Q_OBJECT
public:
static const int WIDTH = 30;
@@ -33,5 +29,12 @@ namespace Bloom::Widgets::InsightTargetWidgets::Qfp
this->setFixedSize(PinBodyWidget::HEIGHT, PinBodyWidget::WIDTH);
}
}
protected:
void paintEvent(QPaintEvent* event) override;
void drawWidget(QPainter& painter);
private:
bool isVertical = false;
};
}

View File

@@ -6,7 +6,6 @@
#include "PinWidget.hpp"
#include "PinBodyWidget.hpp"
#include "src/Logger/Logger.hpp"
using namespace Bloom::Widgets::InsightTargetWidgets::Qfp;
using namespace Bloom::Targets;

View File

@@ -12,20 +12,7 @@ namespace Bloom::Widgets::InsightTargetWidgets::Qfp
{
class PinWidget: public TargetPinWidget
{
Q_OBJECT
private:
QBoxLayout* layout = nullptr;
QLabel* pinNumberLabel = nullptr;
QLabel* pinNameLabel = nullptr;
QLabel* pinDirectionLabel = nullptr;
PinBodyWidget* bodyWidget = nullptr;
bool isLeftLayout = false;
bool isBottomLayout = false;
bool isRightLayout = false;
bool isTopLayout = false;
void setLabelColor(const QString& hexColor);
Q_OBJECT
public:
static const int PIN_WIDGET_LAYOUT_PADDING = 46;
@@ -49,5 +36,19 @@ namespace Bloom::Widgets::InsightTargetWidgets::Qfp
);
void updatePinState(const Targets::TargetPinState& pinState) override;
private:
QBoxLayout* layout = nullptr;
QLabel* pinNumberLabel = nullptr;
QLabel* pinNameLabel = nullptr;
QLabel* pinDirectionLabel = nullptr;
PinBodyWidget* bodyWidget = nullptr;
bool isLeftLayout = false;
bool isBottomLayout = false;
bool isRightLayout = false;
bool isTopLayout = false;
void setLabelColor(const QString& hexColor);
};
}

View File

@@ -7,7 +7,6 @@
#include <QEvent>
#include <QFile>
#include "../../../InsightWindow.hpp"
#include "src/Helpers/Paths.hpp"
#include "PinWidget.hpp"
#include "BodyWidget.hpp"

View File

@@ -17,7 +17,15 @@ namespace Bloom::Widgets::InsightTargetWidgets::Qfp
*/
class QuadFlatPackageWidget: public TargetPackageWidget
{
Q_OBJECT
Q_OBJECT
public:
QuadFlatPackageWidget(
const Targets::TargetVariant& targetVariant,
InsightWorker& insightWorker,
QWidget* parent
);
private:
QVBoxLayout* layout = nullptr;
QHBoxLayout* horizontalLayout = nullptr;
@@ -26,12 +34,5 @@ namespace Bloom::Widgets::InsightTargetWidgets::Qfp
QHBoxLayout* bottomPinLayout = nullptr;
QVBoxLayout* leftPinLayout = nullptr;
BodyWidget* bodyWidget = nullptr;
public:
QuadFlatPackageWidget(
const Targets::TargetVariant& targetVariant,
InsightWorker& insightWorker,
QWidget* parent
);
};
}

View File

@@ -18,18 +18,7 @@ namespace Bloom::Widgets::InsightTargetWidgets
*/
class TargetPackageWidget: public QWidget
{
Q_OBJECT
protected:
Targets::TargetVariant targetVariant;
InsightWorker& insightWorker;
std::vector<TargetPinWidget*> pinWidgets;
Targets::TargetState targetState = Targets::TargetState::UNKNOWN;
protected slots:
virtual void updatePinStates(const Targets::TargetPinStateMappingType& pinStatesByNumber);
void onTargetStateChanged(Targets::TargetState newState);
void onRegistersWritten(Targets::TargetRegisters targetRegisters);
Q_OBJECT
public:
TargetPackageWidget(Targets::TargetVariant targetVariant, InsightWorker& insightWorker, QWidget* parent);
@@ -46,5 +35,17 @@ namespace Bloom::Widgets::InsightTargetWidgets
QSize minimumSizeHint() const override {
return this->sizeHint();
}
protected:
Targets::TargetVariant targetVariant;
InsightWorker& insightWorker;
std::vector<TargetPinWidget*> pinWidgets;
Targets::TargetState targetState = Targets::TargetState::UNKNOWN;
protected slots:
virtual void updatePinStates(const Targets::TargetPinStateMappingType& pinStatesByNumber);
void onTargetStateChanged(Targets::TargetState newState);
void onRegistersWritten(Targets::TargetRegisters targetRegisters);
};
}

View File

@@ -7,6 +7,14 @@ using namespace Bloom::Widgets::InsightTargetWidgets;
TargetPackageWidgetContainer::TargetPackageWidgetContainer(QWidget* parent): QWidget(parent) {}
void TargetPackageWidgetContainer::setPackageWidget(TargetPackageWidget* packageWidget) {
this->packageWidget = packageWidget;
if (packageWidget != nullptr) {
this->layout()->addWidget(packageWidget);
}
}
void TargetPackageWidgetContainer::resizeEvent(QResizeEvent* event) {
if (this->packageWidget == nullptr) {
return;
@@ -20,11 +28,3 @@ void TargetPackageWidgetContainer::resizeEvent(QResizeEvent* event) {
packageSize.height()
);
}
void TargetPackageWidgetContainer::setPackageWidget(TargetPackageWidget* packageWidget) {
this->packageWidget = packageWidget;
if (packageWidget != nullptr) {
this->layout()->addWidget(packageWidget);
}
}

View File

@@ -9,16 +9,17 @@ namespace Bloom::Widgets::InsightTargetWidgets
{
class TargetPackageWidgetContainer: public QWidget
{
Q_OBJECT
private:
TargetPackageWidget* packageWidget = nullptr;
protected:
void resizeEvent(QResizeEvent* event) override;
Q_OBJECT
public:
TargetPackageWidgetContainer(QWidget* parent);
void setPackageWidget(TargetPackageWidget* packageWidget);
protected:
void resizeEvent(QResizeEvent* event) override;
private:
TargetPackageWidget* packageWidget = nullptr;
};
}

View File

@@ -5,28 +5,6 @@
using namespace Bloom::Widgets::InsightTargetWidgets;
using namespace Bloom::Targets;
bool TargetPinBodyWidget::event(QEvent* event) {
if (this->pinState.has_value() && this->pinState->ioDirection == TargetPinState::IoDirection::OUTPUT) {
switch (event->type()) {
case QEvent::Enter: {
this->hoverActive = true;
this->repaint();
break;
}
case QEvent::Leave: {
this->hoverActive = false;
this->repaint();
break;
}
default: {
break;
}
}
}
return QWidget::event(event);
}
QColor TargetPinBodyWidget::getBodyColor() {
auto pinColor = this->defaultBodyColor;
@@ -65,3 +43,25 @@ QColor TargetPinBodyWidget::getBodyColor() {
return pinColor;
}
bool TargetPinBodyWidget::event(QEvent* event) {
if (this->pinState.has_value() && this->pinState->ioDirection == TargetPinState::IoDirection::OUTPUT) {
switch (event->type()) {
case QEvent::Enter: {
this->hoverActive = true;
this->repaint();
break;
}
case QEvent::Leave: {
this->hoverActive = false;
this->repaint();
break;
}
default: {
break;
}
}
}
return QWidget::event(event);
}

View File

@@ -11,7 +11,7 @@ namespace Bloom::Widgets::InsightTargetWidgets
{
class TargetPinBodyWidget: public QWidget
{
Q_OBJECT
Q_OBJECT
/*
* Pin body colors can be set in QSS files.
*/
@@ -23,38 +23,12 @@ namespace Bloom::Widgets::InsightTargetWidgets
Q_PROPERTY(int disableAlphaLevel READ getDisableAlphaLevel WRITE setDisableAlphaLevel DESIGNABLE true)
protected:
Targets::TargetPinDescriptor pinDescriptor;
std::optional<Targets::TargetPinState> pinState;
bool hoverActive = false;
QColor defaultBodyColor = QColor("#908D85");
QColor vccBodyColor = QColor("#70383A");
QColor gndBodyColor = QColor("#484A4B");
QColor outputHighBodyColor = QColor("#3C5E62");
QColor inputHighBodyColor = QColor("#7B5E38");
int disableAlphaLevel = 100;
bool event(QEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override {
if (event->button() == Qt::MouseButton::LeftButton) {
emit this->clicked();
}
QWidget::mouseReleaseEvent(event);
}
public:
TargetPinBodyWidget(QWidget* parent, Targets::TargetPinDescriptor pinDescriptor):
QWidget(parent), pinDescriptor(std::move(pinDescriptor)) {
this->setObjectName("target-pin-body");
}
QColor getBodyColor();
void setPinState(const Targets::TargetPinState& pinState) {
this->pinState = pinState;
}
@@ -109,5 +83,31 @@ namespace Bloom::Widgets::InsightTargetWidgets
signals:
void clicked();
protected:
Targets::TargetPinDescriptor pinDescriptor;
std::optional<Targets::TargetPinState> pinState;
bool hoverActive = false;
QColor defaultBodyColor = QColor("#908D85");
QColor vccBodyColor = QColor("#70383A");
QColor gndBodyColor = QColor("#484A4B");
QColor outputHighBodyColor = QColor("#3C5E62");
QColor inputHighBodyColor = QColor("#7B5E38");
int disableAlphaLevel = 100;
QColor getBodyColor();
bool event(QEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override {
if (event->button() == Qt::MouseButton::LeftButton) {
emit this->clicked();
}
QWidget::mouseReleaseEvent(event);
}
};
}

View File

@@ -11,14 +11,7 @@ namespace Bloom::Widgets::InsightTargetWidgets
{
class TargetPinWidget: public QWidget
{
Q_OBJECT
protected:
InsightWorker& insightWorker;
Targets::TargetVariant targetVariant;
Targets::TargetPinDescriptor pinDescriptor;
std::optional<Targets::TargetPinState> pinState;
bool pinStateChanged = false;
Q_OBJECT
public:
TargetPinWidget(
@@ -42,5 +35,13 @@ namespace Bloom::Widgets::InsightTargetWidgets
public slots:
virtual void onWidgetBodyClicked();
protected:
InsightWorker& insightWorker;
Targets::TargetVariant targetVariant;
Targets::TargetPinDescriptor pinDescriptor;
std::optional<Targets::TargetPinState> pinState;
bool pinStateChanged = false;
};
}