Skip to content

Commit

Permalink
gui/docking: Add initial docking infrastructure
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei-Fabian-Pop <[email protected]>
  • Loading branch information
Andrei-Fabian-Pop committed Nov 28, 2024
1 parent af4fe93 commit ee190c5
Show file tree
Hide file tree
Showing 16 changed files with 667 additions and 4 deletions.
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ include(GNUInstallDirs)

find_package(QT NAMES Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets LinguistTools)
find_package(KDDockWidgets)

if(KDDockWidgets_FOUND)
add_compile_definitions(USE_KDDOCKWIDGETS)
endif()

if(Qt5Widgets_VERSION VERSION_LESS 5.15.2)
message(FATAL_ERROR "Minimum supported Qt 5.15.2")
Expand Down Expand Up @@ -208,7 +213,14 @@ add_definitions(-DQT_NO_KEYWORDS)

set(CMAKE_VERBOSE_MAKEFILE ON)
target_include_directories(${PROJECT_NAME} PUBLIC scopy-gui scopy-core)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ${SCOPY_DEPENDENCIES} scopy-core scopy-gui)
target_link_libraries(
${PROJECT_NAME}
PRIVATE Qt${QT_VERSION_MAJOR}::Widgets
${SCOPY_DEPENDENCIES}
scopy-core
scopy-gui
KDAB::kddockwidgets
)

# Compiler options
target_compile_options(${PROJECT_NAME} PUBLIC -Wall)
Expand Down
4 changes: 4 additions & 0 deletions gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ file(
SRC_LIST
src/*.cpp
src/widgets/*.cpp
src/docking/*.cpp
src/*.cc
src/binding/*.cpp
src/prop/*.cpp
Expand All @@ -54,6 +55,7 @@ file(
include/${SCOPY_MODULE}/*.h
include/${SCOPY_MODULE}/*.hpp
include/${SCOPY_MODULE}/widgets/*.h
include/${SCOPY_MODULE}/docking/*.h
include/${SCOPY_MODULE}/binding/*.hpp
include/${SCOPY_MODULE}/prop/*.hpp
)
Expand Down Expand Up @@ -106,6 +108,7 @@ endif()
set(PROJECT_SOURCES ${SRC_LIST} ${HEADER_LIST} ${UI_LIST})

find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Xml Svg REQUIRED)
find_package(KDDockWidgets REQUIRED)

add_definitions(-DBOOST_ALL_DYN_LINK)
find_package(Boost COMPONENTS system filesystem thread chrono REQUIRED)
Expand Down Expand Up @@ -145,6 +148,7 @@ target_link_libraries(
${Boost_LIBRARIES}
scopy-common
scopy-pluginbase
KDAB::kddockwidgets
)

install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${SCOPY_DLL_INSTALL_PATH} COMPONENT ${SCOPY_PDK}
Expand Down
36 changes: 36 additions & 0 deletions gui/include/gui/docking/dockablearea.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2024 Analog Devices Inc.
*
* This file is part of Scopy
* (see https://www.github.com/analogdevicesinc/scopy).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef DOCKABLEAREA_H
#define DOCKABLEAREA_H

#ifdef USE_KDDOCKWIDGETS
#include "docking/dockableareakdab.h"
namespace scopy {
using DockableArea = kdab::DockableArea;
}
#else
#include "docking/dockableareaclassic.h"
namespace scopy {
using DockableArea = classic::DockableArea;
}
#endif

#endif // DOCKABLEAREA_H
45 changes: 45 additions & 0 deletions gui/include/gui/docking/dockableareaclassic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2024 Analog Devices Inc.
*
* This file is part of Scopy
* (see https://www.github.com/analogdevicesinc/scopy).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef DOCKABLEAREACLASSIC_H
#define DOCKABLEAREACLASSIC_H

#include "scopy-gui_export.h"
#include <QWidget>
#include "docking/dockableareainterface.h"

namespace scopy::classic {
class SCOPY_GUI_EXPORT DockableArea : public QWidget, public DockableAreaInterface
{
Q_OBJECT
Q_INTERFACES(scopy::DockableAreaInterface)
public:
explicit DockableArea(QWidget *parent = nullptr);
~DockableArea() override = default;

void addDockWrapper(DockWrapperInterface *wrapper) override;
void setAllDockWrappers(const QList<DockWrapperInterface *> &wrappers) override;

private:
void init();
};
} // namespace scopy::classic

#endif // DOCKABLEAREACLASSIC_H
39 changes: 39 additions & 0 deletions gui/include/gui/docking/dockableareainterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2024 Analog Devices Inc.
*
* This file is part of Scopy
* (see https://www.github.com/analogdevicesinc/scopy).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef DOCKABLEAREAINTERFACE_H
#define DOCKABLEAREAINTERFACE_H

#include "docking/dockwrapperinterface.h"
#include "scopy-gui_export.h"
#include <QObject>

namespace scopy {
class SCOPY_GUI_EXPORT DockableAreaInterface
{
public:
virtual ~DockableAreaInterface() = default;
virtual void addDockWrapper(DockWrapperInterface *wrapper) = 0;
virtual void setAllDockWrappers(const QList<DockWrapperInterface *> &wrappers) = 0;
};
} // namespace scopy

Q_DECLARE_INTERFACE(scopy::DockableAreaInterface, "scopy::DockableAreaInterface")
#endif // DOCKABLEAREAINTERFACE_H
49 changes: 49 additions & 0 deletions gui/include/gui/docking/dockableareakdab.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2024 Analog Devices Inc.
*
* This file is part of Scopy
* (see https://www.github.com/analogdevicesinc/scopy).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef DOCKABLEAREAKDAB_H
#define DOCKABLEAREAKDAB_H

#include "scopy-gui_export.h"
#include <QWidget>
#include <QList>
#include "docking/dockableareainterface.h"
#include "docking/dockwrapperinterface.h"
#include <kddockwidgets/qtwidgets/views/MainWindow.h>

namespace scopy::kdab {
class SCOPY_GUI_EXPORT DockableArea : public KDDockWidgets::QtWidgets::MainWindow, public DockableAreaInterface
{
Q_OBJECT
public:
explicit DockableArea(QWidget *parent = nullptr);
~DockableArea() override = default;

// Does not set affinities
void addDockWrapper(DockWrapperInterface *wrapper) override;

// Preffered as it also sets affinities
void setAllDockWrappers(const QList<DockWrapperInterface *> &wrappers) override;

private:
static int s_dockableAreaId;
};
} // namespace scopy::kdab
#endif // DOCKABLEAREAKDAB_H
80 changes: 80 additions & 0 deletions gui/include/gui/docking/docksettings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2024 Analog Devices Inc.
*
* This file is part of Scopy
* (see https://www.github.com/analogdevicesinc/scopy).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef DOCKSETTINGS_H
#define DOCKSETTINGS_H

#ifndef USE_KDDOCKWIDGETS
namespace scopy {
static void initDockWidgets() {}
} // namespace scopy
#else
#include "scopy-gui_export.h"
#include "style.h"
#include "style_attributes.h"

#include <kddockwidgets/Config.h>
#include <kddockwidgets/core/TitleBar.h>
#include <kddockwidgets/qtwidgets/TitleBar.h>
#include <kddockwidgets/qtwidgets/ViewFactory.h>

namespace scopy {
// All of this just to hide a button
class SCOPY_GUI_EXPORT NoCloseTitleBar : public KDDockWidgets::QtWidgets::TitleBar
{
public:
explicit NoCloseTitleBar(KDDockWidgets::Core::TitleBar *controller, KDDockWidgets::Core::View *parent = nullptr)
: KDDockWidgets::QtWidgets::TitleBar(controller, parent)
, m_controller(controller)
{
Style::setBackgroundColor(this, json::theme::background_subtle, true);
}

void init() override
{
m_controller->setHideDisabledButtons(KDDockWidgets::TitleBarButtonType::Close);
KDDockWidgets::QtWidgets::TitleBar::init();
}

private:
KDDockWidgets::Core::TitleBar *const m_controller;
};

class SCOPY_GUI_EXPORT TitleBarFactory : public KDDockWidgets::QtWidgets::ViewFactory
{
Q_OBJECT
public:
KDDockWidgets::Core::View *createTitleBar(KDDockWidgets::Core::TitleBar *controller,
KDDockWidgets::Core::View *parent) const override
{
return new NoCloseTitleBar(controller, parent);
}
};

// Mark as static or inline to avoid ODR violation, this should only be used once in main.cpp anyway
static void initDockWidgets()
{
KDDockWidgets::initFrontend(KDDockWidgets::FrontendType::QtWidgets);
KDDockWidgets::Config::self().setViewFactory(new TitleBarFactory());
}
} // namespace scopy

#endif // USE_KDDOCKWIDGETS
#endif // DOCKSETTINGS_H
31 changes: 31 additions & 0 deletions gui/include/gui/docking/dockwrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2024 Analog Devices Inc.
*
* This file is part of Scopy
* (see https://www.github.com/analogdevicesinc/scopy).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef DOCKWRAPPER_H
#define DOCKWRAPPER_H

#ifdef USE_KDDOCKWIDGETS
#include "docking/dockwrapperkdab.h"
using DockWrapper = scopy::kdab::DockWrapper;
#else
#include "docking/dockwrapperclassic.h"
using DockWrapper = scopy::classic::DockWrapper;
#endif // USE_KDDOCKWIDGETS
#endif // DOCKWRAPPER_H
47 changes: 47 additions & 0 deletions gui/include/gui/docking/dockwrapperclassic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2024 Analog Devices Inc.
*
* This file is part of Scopy
* (see https://www.github.com/analogdevicesinc/scopy).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef DOCKWRAPPERCLASSIC_H
#define DOCKWRAPPERCLASSIC_H

#include "scopy-gui_export.h"
#include <QWidget>
#include "docking/dockwrapperinterface.h"

namespace scopy::classic {
class SCOPY_GUI_EXPORT DockWrapper : public QWidget, public DockWrapperInterface
{
Q_OBJECT
Q_INTERFACES(scopy::DockWrapperInterface)
public:
explicit DockWrapper(QString name, QWidget *parent = nullptr);

void setInnerWidget(QWidget *innerWidget) override;
QWidget *innerWidget() const override;

void setActivated(bool isActivated) override;

private:
void init();
QWidget *m_innerWidget;
};
} // namespace scopy::classic

#endif // DOCKWRAPPERCLASSIC_H
Loading

0 comments on commit ee190c5

Please sign in to comment.