Skip to content

Commit

Permalink
WIP: Detach to a floating window
Browse files Browse the repository at this point in the history
  • Loading branch information
BatchDrake committed Mar 15, 2023
1 parent 1e45cc1 commit 90e3ad9
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 23 deletions.
3 changes: 3 additions & 0 deletions SigDigger.pro
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ SOURCES += \
UIComponent/ToolWidgetFactory.cpp \
UIComponent/UIComponentFactory.cpp \
UIComponent/UIListenerFactory.cpp \
UIMediator/FloatingTabWindow.cpp \
UIMediator/InspectorMediator.cpp \
UIMediator/PanoramicDialogMediator.cpp \
UIMediator/SpectrumMediator.cpp \
Expand Down Expand Up @@ -315,6 +316,7 @@ HEADERS += \
include/DeviceTweaks.h \
include/DopplerCalculator.h \
include/DopplerDialog.h \
include/FloatingTabWindow.h \
include/FrequencyCorrectionDialog.h \
include/GenericAudioPlayer.h \
include/GenericDataSaverUI.h \
Expand Down Expand Up @@ -388,6 +390,7 @@ FORMS += \
ui/DeviceTweaks.ui \
ui/DopplerDialog.ui \
ui/EqualizerControl.ui \
ui/FloatingTabWindow.ui \
ui/FrequencyCorrectionDialog.ui \
ui/GainControl.ui \
ui/GainSlider.ui \
Expand Down
18 changes: 18 additions & 0 deletions UIComponent/TabWidgetFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,33 @@ TabWidget::TabWidget(
void
TabWidget::addAction(QAction *action)
{
m_customActions.push_back(action);
m_menu->insertAction(m_renameTab, action);
}

void
TabWidget::addSeparator()
{
m_customActions.push_back(nullptr);
m_menu->insertSeparator(m_renameTab);
}

bool
TabWidget::hasCustomActions() const
{
return m_customActions.size() > 0;
}

void
TabWidget::addCustomActionsToMenu(QMenu *menu)
{
for (auto action : m_customActions) {
if (action == nullptr)
menu->addSeparator();
else
menu->addAction(action);
}
}

TabWidget::~TabWidget()
{
Expand Down
111 changes: 111 additions & 0 deletions UIMediator/FloatingTabWindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
//
// FloatingTabWindow.cpp: description
// Copyright (C) 2023 Gonzalo José Carracedo Carballal
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program. If not, see
// <http://www.gnu.org/licenses/>
//
#include "FloatingTabWindow.h"
#include "ui_FloatingTabWindow.h"

using namespace SigDigger;

FloatingTabWindow::FloatingTabWindow(TabWidget *widget, QWidget *parent) :
QMainWindow(parent),
m_tabWidget(widget),
ui(new Ui::FloatingTabWindow)
{
ui->setupUi(this);

//m_layout = new QVBoxLayout;

//setLayout(m_layout);

//m_layout->addWidget(m_tabWidget);
//m_tabWidget->setParent(this);

setCentralWidget(m_tabWidget);

if (m_tabWidget->hasCustomActions()) {
m_customMenu = new QMenu;
ui->menubar->addMenu(m_customMenu);
m_tabWidget->addCustomActionsToMenu(m_customMenu);
}

setWindowTitle(
"SigDigger - "
+ QString::fromStdString(m_tabWidget->getLabel()));

connectAll();
}

TabWidget *
FloatingTabWindow::getTabWidget() const
{
return m_tabWidget;
}

TabWidget *
FloatingTabWindow::takeTabWidget()
{
TabWidget *widget = m_tabWidget;

if (widget == nullptr)
return nullptr;

m_layout->removeWidget(widget);

m_tabWidget = nullptr;

return widget;
}

void
FloatingTabWindow::closeEvent(QCloseEvent *event)
{
event->ignore();

hide();

emit finished();
}

void
FloatingTabWindow::connectAll()
{
connect(
ui->action_Rename,
SIGNAL(triggered(bool)),
m_tabWidget,
SLOT(onRename()));

connect(
m_tabWidget,
SIGNAL(nameChanged(QString)),
this,
SLOT(onRename(QString)));
}

FloatingTabWindow::~FloatingTabWindow()
{
delete ui;
}

void
FloatingTabWindow::onRename(QString name)
{
setWindowTitle(
"SigDigger - "
+ name);
}
32 changes: 10 additions & 22 deletions UIMediator/UIMediator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <QMessageBox>
#include <QScreen>
#include <QTimeSlider.h>
#include <FloatingTabWindow.h>

#include <fstream>

Expand Down Expand Up @@ -266,14 +267,12 @@ UIMediator::closeTabWidget(TabWidget *tabWidget)
} else {
auto p = m_floatingTabs.find(tabWidget);
if (p != m_floatingTabs.end()) {
QDialog *d = p.value();
FloatingTabWindow *d = p.value();

m_floatingTabs.erase(p);

tabWidget->setParent(nullptr);

d->setProperty("tab-ptr", QVariant::fromValue<TabWidget *>(nullptr));

d->close();
d->deleteLater();
}
Expand All @@ -296,36 +295,25 @@ UIMediator::floatTabWidget(TabWidget *tabWidget)
if (p != m_floatingTabs.end())
return true;

QDialog *dialog = new QDialog(this->owner);
QVBoxLayout *layout = new QVBoxLayout;

tabWidget->floatStart();
this->closeTabWidget(tabWidget);

dialog->setProperty(
"tab-ptr",
QVariant::fromValue<TabWidget *>(tabWidget));
dialog->setLayout(layout);
dialog->setWindowFlags(Qt::Window);
FloatingTabWindow *window = new FloatingTabWindow(tabWidget, this->owner);

connect(
dialog,
SIGNAL(finished(int)),
window,
SIGNAL(finished()),
this,
SLOT(onCloseTabWindow()));

layout->addWidget(tabWidget);

tabWidget->floatEnd();
tabWidget->show();

dialog->move(this->owner->pos());
dialog->setWindowTitle(
"SigDigger - " + QString::fromStdString(tabWidget->getLabel()));
window->move(this->owner->pos());

m_floatingTabs[tabWidget] = dialog;
m_floatingTabs[tabWidget] = window;

dialog->show();
window->show();

return true;
}
Expand Down Expand Up @@ -1444,10 +1432,10 @@ UIMediator::onJumpToBookmark(BookmarkInfo info)
void
UIMediator::onCloseTabWindow()
{
QDialog *sender = qobject_cast<QDialog *>(QObject::sender());
FloatingTabWindow *sender = qobject_cast<FloatingTabWindow *>(QObject::sender());
TabWidget *tabWidget;

tabWidget = sender->property("tab-ptr").value<TabWidget *>();
tabWidget = sender->getTabWidget();

// We simply tell the tab widget that someone requested its closure
tabWidget->closeRequested();
Expand Down
66 changes: 66 additions & 0 deletions include/FloatingTabWindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// FloatingTabWindow.h: description
// Copyright (C) 2023 Gonzalo José Carracedo Carballal
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program. If not, see
// <http://www.gnu.org/licenses/>
//
#ifndef FLOATINGTABWINDOW_H
#define FLOATINGTABWINDOW_H

#include <QMainWindow>
#include <TabWidgetFactory.h>
#include <QCloseEvent>
#include <QVBoxLayout>

class QMenu;

namespace Ui {
class FloatingTabWindow;
}

namespace SigDigger {
class FloatingTabWindow : public QMainWindow
{
Q_OBJECT

TabWidget *m_tabWidget = nullptr;
QVBoxLayout *m_layout = nullptr;
QMenu *m_customMenu = nullptr;

void connectAll();

public:
void closeEvent(QCloseEvent *) override;

TabWidget *getTabWidget() const;
TabWidget *takeTabWidget();

explicit FloatingTabWindow(TabWidget *widget, QWidget *parent = nullptr);

~FloatingTabWindow();

signals:
void finished();

public slots:
void onRename(QString);

private:
Ui::FloatingTabWindow *ui;
};

}

#endif // FLOATINGTABWINDOW_H
5 changes: 5 additions & 0 deletions include/TabWidgetFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define TABWIDGETFACTORY_H

#include <UIComponentFactory.h>
#include <QList>

class QMenu;

Expand All @@ -36,6 +37,8 @@ namespace SigDigger {
QAction *m_renameTab = nullptr;
QAction *m_floatTab = nullptr;

QList<QAction *> m_customActions;

bool m_labelChanged = false;
QString m_cachedLabel;

Expand All @@ -51,6 +54,8 @@ namespace SigDigger {
virtual void floatEnd();
virtual void closeRequested();

bool hasCustomActions() const;
void addCustomActionsToMenu(QMenu *);
void popupMenu();

~TabWidget() override;
Expand Down
3 changes: 2 additions & 1 deletion include/UIMediator.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace SigDigger {
class TabWidget;
class InspectionWidget;
class UIListener;
class FloatingTabWindow;

class UIMediator : public PersistentWidget {
Q_OBJECT
Expand Down Expand Up @@ -112,7 +113,7 @@ namespace SigDigger {
Suscan::Analyzer *m_analyzer = nullptr;
QList<UIComponent *> m_components;
QList<TabWidget *> m_tabWidgets;
QMap<TabWidget *, QDialog *> m_floatingTabs;
QMap<TabWidget *, FloatingTabWindow *> m_floatingTabs;
struct timeval m_lastTimeStamp;
Suscan::Object m_hollowConfig;

Expand Down
Loading

0 comments on commit 90e3ad9

Please sign in to comment.