Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
cache: true
- name: Linux build dependencies
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y libgl1-mesa-dev libxkbcommon-dev
run: sudo apt-get update && sudo apt-get install -y libgl1-mesa-dev libxkbcommon-dev libxcb1-dev
- name: MSVC environment
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1
Expand Down
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,22 @@ if(EMBLINK_STUDIO_BUILD_TESTS)
find_package(Qt6 REQUIRED COMPONENTS Test)
endif()

# Qt Advanced Docking System (spec section 11, question 1): LGPL-2.1-or-later, so it is built
# as a shared library and linked dynamically (spec section 9). Pinned by version and SHA-256.
include(FetchContent)
set(QT_VERSION_MAJOR 6)
set(BUILD_STATIC OFF CACHE BOOL "Build Qt Advanced Docking System as a static library" FORCE)
set(BUILD_EXAMPLES OFF CACHE BOOL "Build Qt Advanced Docking System's examples" FORCE)
FetchContent_Declare(qtads
URL https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System/archive/refs/tags/v5.1.1.tar.gz
URL_HASH SHA256=9ce947acbb1984946f9145c976e42e6984f99b98fb414dd7354a290af6d4ff04
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
FetchContent_MakeAvailable(qtads)
# Next to the application and the tests, so Windows finds the DLL without a PATH change.
set_target_properties(qtadvanceddocking-qt6 PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/app"
LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/app"
)

add_subdirectory(app)
13 changes: 12 additions & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ target_compile_definitions(emblink_studio_corelink PUBLIC
EMBLINK_STUDIO_CORE_SRC_DIR="${PROJECT_SOURCE_DIR}/core/src"
)

# The dockable layout: every view a dock, layouts saved and restored (spec section 7).
qt_add_library(emblink_studio_workbench STATIC
src/workbench.cpp src/workbench.h
)
target_include_directories(emblink_studio_workbench PUBLIC src)
target_link_libraries(emblink_studio_workbench PUBLIC Qt6::Widgets ads::qtadvanceddocking-qt6)

# The notices list shown in the About box, generated from third_party/components.json.
set(notices "${CMAKE_CURRENT_BINARY_DIR}/NOTICES.md")
add_custom_command(
Expand All @@ -38,7 +45,7 @@ qt_add_executable(emblinkstudio WIN32 MACOSX_BUNDLE
src/main.cpp
src/mainwindow.cpp src/mainwindow.h
)
target_link_libraries(emblinkstudio PRIVATE emblink_studio_corelink Qt6::Widgets)
target_link_libraries(emblinkstudio PRIVATE emblink_studio_corelink emblink_studio_workbench Qt6::Widgets)
target_compile_definitions(emblinkstudio PRIVATE EMBLINK_STUDIO_VERSION="${PROJECT_VERSION}")
set_source_files_properties("${notices}" PROPERTIES QT_RESOURCE_ALIAS NOTICES.md)
qt_add_resources(emblinkstudio notices PREFIX "/" BASE "${CMAKE_CURRENT_BINARY_DIR}" FILES "${notices}")
Expand All @@ -57,4 +64,8 @@ if(EMBLINK_STUDIO_BUILD_TESTS)
endforeach()
target_compile_definitions(tst_coreclient PRIVATE
EMBLINK_STUDIO_FAKE_CORE="${CMAKE_CURRENT_SOURCE_DIR}/tests/fake_core.py")

qt_add_executable(tst_workbench tests/tst_workbench.cpp)
target_link_libraries(tst_workbench PRIVATE emblink_studio_workbench Qt6::Test)
add_test(NAME tst_workbench COMMAND tst_workbench)
endif()
82 changes: 66 additions & 16 deletions app/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
* @brief Implementation of MainWindow: layout, menus, About dialog, core lifecycle.
*
* @details
* Builds the status label, the restart button, the "Core log" dock (a QDockWidget
* until Qt Advanced Docking System lands, spec section 11 question 1) and the File,
* View and Help menus. The About dialog shows the third-party notices bundled as the
* Builds two Workbench views, "Core" (the status label and the restart button) and
* "Core log", and the File, View and Help menus. The View menu shows or hides each
* view, opens and saves named layouts, and resets the layout. The layout is saved to
* the user's settings when the window closes and restored when it opens (per project
* in .emblink-studio/ once projects exist, spec section 6). The About dialog shows the third-party
* notices bundled as the
* :/NOTICES.md resource. The core is started when the window is built and stopped
* when it closes.
*
Expand All @@ -21,17 +24,20 @@
*/

#include "mainwindow.h"
#include "workbench.h"

#include <QApplication>
#include <QCloseEvent>
#include <QDialog>
#include <QDialogButtonBox>
#include <QDockWidget>
#include <QFile>
#include <QInputDialog>
#include <QLabel>
#include <QLineEdit>
#include <QMenuBar>
#include <QPlainTextEdit>
#include <QPushButton>
#include <QSettings>
#include <QTextBrowser>
#include <QVBoxLayout>

Expand All @@ -43,31 +49,44 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
setWindowTitle(tr("EmbLink Studio"));
resize(960, 600);

auto *central = new QWidget(this);
auto *layout = new QVBoxLayout(central);
m_status = new QLabel(central);
m_workbench = new Workbench(this);

auto *coreView = new QWidget;
auto *layout = new QVBoxLayout(coreView);
m_status = new QLabel(coreView);
m_status->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
m_status->setWordWrap(true);
m_restart = new QPushButton(tr("&Restart the core"), central);
m_restart = new QPushButton(tr("&Restart the core"), coreView);
m_restart->setVisible(false);
layout->addWidget(m_status);
layout->addWidget(m_restart, 0, Qt::AlignLeft);
layout->addStretch();
setCentralWidget(central);

// QDockWidget until Qt Advanced Docking System lands (decided: spec section 11, question 1).
auto *dock = new QDockWidget(tr("Core log"), this);
dock->setObjectName(QStringLiteral("coreLog"));
m_log = new QPlainTextEdit(dock);
m_log = new QPlainTextEdit;
m_log->setReadOnly(true);
m_log->setMaximumBlockCount(5000);
dock->setWidget(m_log);
addDockWidget(Qt::BottomDockWidgetArea, dock);

// The ids name the views in saved layouts: keep them stable.
m_workbench->addView(QStringLiteral("core"), tr("Core"), coreView, ads::CenterDockWidgetArea);
m_workbench->addView(QStringLiteral("coreLog"), tr("Core log"), m_log,
ads::BottomDockWidgetArea);
m_workbench->captureDefaultLayout();
{
QSettings settings;
settings.beginGroup(QStringLiteral("layout"));
m_workbench->restore(settings);
}

QMenu *file = menuBar()->addMenu(tr("&File"));
file->addAction(tr("&Quit"), QKeySequence::Quit, this, &QWidget::close);
QMenu *view = menuBar()->addMenu(tr("&View"));
view->addAction(dock->toggleViewAction());
for (ads::CDockWidget *v : m_workbench->views())
view->addAction(v->toggleViewAction());
view->addSeparator();
m_layouts = view->addMenu(tr("&Layouts"));
connect(m_layouts, &QMenu::aboutToShow, this, &MainWindow::fillLayoutsMenu);
view->addAction(tr("&Save layout as..."), this, &MainWindow::saveLayoutAs);
view->addAction(tr("&Reset layout"), m_workbench, &Workbench::resetLayout);
QMenu *help = menuBar()->addMenu(tr("&Help"));
help->addAction(tr("&About EmbLink Studio"), this, &MainWindow::showAbout);

Expand Down Expand Up @@ -127,8 +146,39 @@ void MainWindow::showAbout()
dialog.exec();
}

void MainWindow::fillLayoutsMenu()
{
m_layouts->clear();
const QStringList names = m_workbench->namedLayouts();
if (names.isEmpty()) {
m_layouts->addAction(tr("No saved layouts"))->setEnabled(false);
return;
}
for (const QString &name : names)
m_layouts->addAction(name, this, [this, name] { m_workbench->openNamedLayout(name); });
m_layouts->addSeparator();
QMenu *remove = m_layouts->addMenu(tr("&Delete"));
for (const QString &name : names)
remove->addAction(name, this, [this, name] { m_workbench->removeNamedLayout(name); });
}

void MainWindow::saveLayoutAs()
{
bool ok = false;
const QString name = QInputDialog::getText(this, tr("Save layout"),
tr("Name of this layout, such as Debug:"),
QLineEdit::Normal, QString(), &ok)
.trimmed();
if (ok && !name.isEmpty())
m_workbench->saveNamedLayout(name);
}

void MainWindow::closeEvent(QCloseEvent *event)
{
QSettings settings;
settings.beginGroup(QStringLiteral("layout"));
m_workbench->save(settings);
settings.endGroup();
m_core.stop();
event->accept();
}
Expand Down
15 changes: 12 additions & 3 deletions app/src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
*
* @details
* Shows whether EmbLink Studio Core is connected, offers a restart when the core
* fails or stops unexpectedly, and shows the core's log in a dock. The window owns
* the CoreClient for the life of the application.
* fails or stops unexpectedly, and shows the core's log. Both are views of the
* Workbench, so they can be moved, split, floated and closed, and the layout is kept
* from one run to the next. The window owns the CoreClient for the life of the
* application.
*
* @see Spec section 4; coreclient.h
* @see Spec sections 4 and 7; coreclient.h, workbench.h
* @author Junior Deogracias
* @date 2026-11-11 (created)
*/
Expand All @@ -25,12 +27,15 @@
#include <QMainWindow>

class QLabel;
class QMenu;
class QPlainTextEdit;
class QPushButton;

namespace emblinkstudio
{

class Workbench;

// S0's window: the core's state, its log, and a restart if it stops (spec section 4).
class MainWindow : public QMainWindow
{
Expand All @@ -46,8 +51,12 @@ class MainWindow : public QMainWindow
void startCore();
void showAbout();
void setStatus(const QString &text, bool canRestart);
void fillLayoutsMenu();
void saveLayoutAs();

CoreClient m_core;
Workbench *m_workbench = nullptr;
QMenu *m_layouts = nullptr;
QLabel *m_status = nullptr;
QPushButton *m_restart = nullptr;
QPlainTextEdit *m_log = nullptr;
Expand Down
132 changes: 132 additions & 0 deletions app/src/workbench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2026 Junior Deogracias
//
// This file is part of EmbLink Studio, the IDE for EmbLinkRTOS.
// Licensed under the Apache License, Version 2.0; see the LICENSE file at the repository root.

/**
* @file workbench.cpp
* @brief Implementation of Workbench: placing views, layouts saved and restored.
*
* @details
* Layouts are Qt Advanced Docking System's own state, tagged with kLayoutVersion.
* Named layouts are its perspectives. In QSettings the current layout is the value
* "current" and the named ones the array "Perspectives", both under the caller's group.
*
* @see workbench.h
* @author Junior Deogracias
* @date 2026-11-11 (created)
*/

#include "workbench.h"

#include <DockAreaWidget.h>
#include <QMainWindow>
#include <QSettings>

namespace emblinkstudio
{

namespace
{

// Config flags are global to the process, so they are set once, before the first manager.
void configureDocking()
{
static bool done = false;
if (done)
return;
done = true;
using M = ads::CDockManager;
// Splitters resize live; every area has its close, undock and tabs-menu buttons.
M::setConfigFlags(M::DefaultOpaqueConfig);
M::setConfigFlag(M::FocusHighlighting, true);
}

} // namespace

Workbench::Workbench(QMainWindow *window) : QObject(window)
{
configureDocking();
m_manager = new ads::CDockManager(window);
}

ads::CDockWidget *Workbench::addView(const QString &id, const QString &title, QWidget *content,
ads::DockWidgetArea area, ads::CDockWidget *tabWith)
{
auto *view = new ads::CDockWidget(m_manager, title);
view->setObjectName(id);
view->setWidget(content);
// Every view can be moved, floated and closed: none is fixed in place.
view->setFeatures(ads::CDockWidget::DefaultDockWidgetFeatures);
if (tabWith && tabWith->dockAreaWidget())
m_manager->addDockWidgetTabToArea(view, tabWith->dockAreaWidget());
else
m_manager->addDockWidget(area, view);
m_views.append(view);
return view;
}

void Workbench::captureDefaultLayout()
{
m_default = saveLayout();
}

void Workbench::resetLayout()
{
if (m_default.isEmpty())
return;
for (ads::CDockWidget *view : std::as_const(m_views))
view->toggleView(true);
restoreLayout(m_default);
}

QByteArray Workbench::saveLayout() const
{
return m_manager->saveState(kLayoutVersion);
}

bool Workbench::restoreLayout(const QByteArray &state)
{
return !state.isEmpty() && m_manager->restoreState(state, kLayoutVersion);
}

void Workbench::saveNamedLayout(const QString &name)
{
m_manager->addPerspective(name);
emit namedLayoutsChanged();
}

bool Workbench::openNamedLayout(const QString &name)
{
if (!m_manager->perspectiveNames().contains(name))
return false;
m_manager->openPerspective(name);
return true;
}

void Workbench::removeNamedLayout(const QString &name)
{
m_manager->removePerspective(name);
emit namedLayoutsChanged();
}

QStringList Workbench::namedLayouts() const
{
return m_manager->perspectiveNames();
}

void Workbench::save(QSettings &settings) const
{
settings.setValue(QStringLiteral("current"), saveLayout());
m_manager->savePerspectives(settings);
}

void Workbench::restore(QSettings &settings)
{
m_manager->loadPerspectives(settings);
restoreLayout(settings.value(QStringLiteral("current")).toByteArray());
emit namedLayoutsChanged();
}

} // namespace emblinkstudio
Loading
Loading