Allow each tab to provide tab actions in toolbar
MODIFY
src/mainwindow.cpp
src/mainwindow.cpp
@@ -46,30 +46,32 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), m_ui(new Ui::Main
m_stackedTabs = new QStackedWidget(this);
m_ui->centrallayout->addWidget(m_stackedTabs);
- auto* tb = addToolBar("Edit");
- tb->setVisible(false);
- m_editTab = new EditTab(tb, this);
+ m_controlToolbar = addToolBar("Simulator control");
+ m_controlToolbar->setVisible(true); // Always visible
+
+ m_editToolbar = addToolBar("Edit");
+ m_editToolbar->setVisible(false);
+ m_editTab = new EditTab(m_editToolbar, this);
m_stackedTabs->insertWidget(0, m_editTab);
- tb = addToolBar("Processor");
- tb->setVisible(true);
- m_processorTab = new ProcessorTab(tb, this);
+ m_processorToolbar = addToolBar("Processor");
+ m_processorToolbar->setVisible(false);
+ m_processorTab = new ProcessorTab(m_controlToolbar, m_processorToolbar, this);
m_stackedTabs->insertWidget(1, m_processorTab);
- tb = addToolBar("Processor");
- tb->setVisible(false);
- m_memoryTab = new MemoryTab(tb, this);
+ m_memoryToolbar = addToolBar("Memory");
+ m_memoryToolbar->setVisible(false);
+ m_memoryTab = new MemoryTab(m_memoryToolbar, this);
m_stackedTabs->insertWidget(2, m_memoryTab);
// Setup tab bar
m_ui->tabbar->addFancyTab(QIcon(":/icons/binary-code.svg"), "Editor");
m_ui->tabbar->addFancyTab(QIcon(":/icons/cpu.svg"), "Processor");
m_ui->tabbar->addFancyTab(QIcon(":/icons/ram-memory.svg"), "Memory");
+ connect(m_stackedTabs, &QStackedWidget::currentChanged, this, &MainWindow::tabChanged);
connect(m_ui->tabbar, &FancyTabBar::activeIndexChanged, m_stackedTabs, &QStackedWidget::setCurrentIndex);
connect(m_ui->tabbar, &FancyTabBar::activeIndexChanged, m_editTab, &EditTab::updateProgramViewerHighlighting);
- m_ui->tabbar->setActiveIndex(1);
-
setupMenus();
// setup and connect widgets
@@ -93,6 +95,15 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), m_ui(new Ui::Main
connect(m_ui->actionOpen_wiki, &QAction::triggered, this, &MainWindow::wiki);
connect(m_ui->actionVersion, &QAction::triggered, this, &MainWindow::version);
connect(m_ui->actionSettings, &QAction::triggered, this, &MainWindow::settingsTriggered);
+
+ m_ui->tabbar->setActiveIndex(1);
+ m_processorToolbar->setVisible(true);
+}
+
+void MainWindow::tabChanged() {
+ m_editToolbar->setVisible(m_editTab->isVisible());
+ m_memoryToolbar->setVisible(m_memoryTab->isVisible());
+ m_processorToolbar->setVisible(m_processorTab->isVisible());
}
void MainWindow::fitToView() {

MODIFY
src/mainwindow.h
src/mainwindow.h
@@ -40,6 +40,7 @@ private slots:
void saveFilesAsTriggered();
void newProgramTriggered();
void settingsTriggered();
+ void tabChanged();
void processorUpdated() { emit updateMemoryTab(); }
@@ -61,8 +62,14 @@ private:
// Tabs
QStackedWidget* m_stackedTabs = nullptr;
+
ProcessorTab* m_processorTab = nullptr;
EditTab* m_editTab = nullptr;
MemoryTab* m_memoryTab = nullptr;
+
+ QToolBar* m_controlToolbar = nullptr;
+ QToolBar* m_processorToolbar = nullptr;
+ QToolBar* m_editToolbar = nullptr;
+ QToolBar* m_memoryToolbar = nullptr;
};
} // namespace Ripes

MODIFY
src/processortab.cpp
src/processortab.cpp
namespace Ripes {
-ProcessorTab::ProcessorTab(QToolBar* toolbar, QWidget* parent) : RipesTab(toolbar, parent), m_ui(new Ui::ProcessorTab) {
+ProcessorTab::ProcessorTab(QToolBar* controlToolbar, QToolBar* additionalToolbar, QWidget* parent)
+ : RipesTab(additionalToolbar, parent), m_ui(new Ui::ProcessorTab) {
m_ui->setupUi(this);
m_vsrtlWidget = m_ui->vsrtlWidget;
@@ -43,7 +44,7 @@ ProcessorTab::ProcessorTab(QToolBar* toolbar, QWidget* parent) : RipesTab(toolba
connect(this, &ProcessorTab::update, this, &ProcessorTab::updateStatistics);
connect(this, &ProcessorTab::update, this, &ProcessorTab::updateInstructionLabels);
- setupSimulatorActions();
+ setupSimulatorActions(controlToolbar);
// Setup statistics update timer
m_statUpdateTimer = new QTimer(this);
@@ -107,33 +108,33 @@ void ProcessorTab::loadLayout(const Layout& layout) {
}
}
-void ProcessorTab::setupSimulatorActions() {
+void ProcessorTab::setupSimulatorActions(QToolBar* controlToolbar) {
const QIcon processorIcon = QIcon(":/icons/cpu.svg");
m_selectProcessorAction = new QAction(processorIcon, "Select processor", this);
connect(m_selectProcessorAction, &QAction::triggered, this, &ProcessorTab::processorSelection);
- m_toolbar->addAction(m_selectProcessorAction);
- m_toolbar->addSeparator();
+ controlToolbar->addAction(m_selectProcessorAction);
+ controlToolbar->addSeparator();
const QIcon resetIcon = QIcon(":/icons/reset.svg");
m_resetAction = new QAction(resetIcon, "Reset (F3)", this);
connect(m_resetAction, &QAction::triggered, this, &ProcessorTab::reset);
m_resetAction->setShortcut(QKeySequence("F3"));
m_resetAction->setToolTip("Reset the simulator (F3)");
- m_toolbar->addAction(m_resetAction);
+ controlToolbar->addAction(m_resetAction);
const QIcon reverseIcon = QIcon(":/icons/reverse.svg");
m_reverseAction = new QAction(reverseIcon, "Reverse (F4)", this);
connect(m_reverseAction, &QAction::triggered, this, &ProcessorTab::reverse);
m_reverseAction->setShortcut(QKeySequence("F4"));
m_reverseAction->setToolTip("Undo a clock cycle (F4)");
- m_toolbar->addAction(m_reverseAction);
+ controlToolbar->addAction(m_reverseAction);
const QIcon clockIcon = QIcon(":/icons/step.svg");
m_clockAction = new QAction(clockIcon, "Clock (F5)", this);
connect(m_clockAction, &QAction::triggered, this, &ProcessorTab::clock);
m_clockAction->setShortcut(QKeySequence("F5"));
m_clockAction->setToolTip("Clock the circuit (F5)");
- m_toolbar->addAction(m_clockAction);
+ controlToolbar->addAction(m_clockAction);
QTimer* timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &ProcessorTab::clock);
@@ -154,7 +155,7 @@ void ProcessorTab::setupSimulatorActions() {
}
});
m_autoClockAction->setChecked(false);
- m_toolbar->addAction(m_autoClockAction);
+ controlToolbar->addAction(m_autoClockAction);
m_autoClockInterval = new QSpinBox(this);
m_autoClockInterval->setRange(1, 10000);
@@ -163,7 +164,7 @@ void ProcessorTab::setupSimulatorActions() {
connect(m_autoClockInterval, qOverload<int>(&QSpinBox::valueChanged),
[timer](int msec) { timer->setInterval(msec); });
m_autoClockInterval->setValue(100);
- m_toolbar->addWidget(m_autoClockInterval);
+ controlToolbar->addWidget(m_autoClockInterval);
const QIcon runIcon = QIcon(":/icons/run.svg");
m_runAction = new QAction(runIcon, "Run (F8)", this);
@@ -174,9 +175,9 @@ void ProcessorTab::setupSimulatorActions() {
"Execute simulator without updating UI (fast execution) (F8).\n Running will stop once the program exits or a "
"breakpoint is hit.");
connect(m_runAction, &QAction::toggled, this, &ProcessorTab::run);
- m_toolbar->addAction(m_runAction);
- m_toolbar->addSeparator();
+ controlToolbar->addAction(m_runAction);
+ // Setup processor-tab only actions
const QIcon tagIcon = QIcon(":/icons/tag.svg");
m_displayValuesAction = new QAction(tagIcon, "Display signal values", this);
m_displayValuesAction->setCheckable(true);

MODIFY
src/processortab.h
src/processortab.h
@@ -30,7 +30,7 @@ class ProcessorTab : public RipesTab {
Q_OBJECT
public:
- ProcessorTab(QToolBar* toolbar, QWidget* parent = nullptr);
+ ProcessorTab(QToolBar* controlToolbar, QToolBar* additionalToolbar, QWidget* parent = nullptr);
~ProcessorTab() override;
void initRegWidget();
@@ -60,7 +60,7 @@ private slots:
void showStageTable();
private:
- void setupSimulatorActions();
+ void setupSimulatorActions(QToolBar* controlToolbar);
void enableSimulatorControls();
void updateInstructionModel();
void updateRegisterModel();

Allow each tab to provide tab actions in toolbar