app/mode: place tabs in menu corner
Signed-off-by: Kiara Navarro <sophiekovalevsky@fedoraproject.org>
This commit is contained in:
parent
7a0e6da706
commit
cb9b03e418
@ -125,7 +125,6 @@ HEADERS += \
|
||||
json.hpp \
|
||||
modehandler.h \
|
||||
mode.h \
|
||||
modetabwidget.h \
|
||||
modewindow.h \
|
||||
preferences.h \
|
||||
savable.h \
|
||||
@ -247,7 +246,6 @@ SOURCES += \
|
||||
main.cpp \
|
||||
modehandler.cpp \
|
||||
mode.cpp \
|
||||
modetabwidget.cpp \
|
||||
modewindow.cpp \
|
||||
preferences.cpp \
|
||||
scpi.cpp \
|
||||
@ -312,7 +310,6 @@ FORMS += \
|
||||
VNA/s2pImportOptions.ui \
|
||||
aboutdialog.ui \
|
||||
main.ui \
|
||||
modewindow.ui \
|
||||
preferencesdialog.ui
|
||||
|
||||
DISTFILES +=
|
||||
|
@ -227,12 +227,15 @@ AppWindow::AppWindow(QWidget *parent)
|
||||
}
|
||||
|
||||
modeHandler = new ModeHandler(this);
|
||||
auto modeWindow = new ModeWindow(modeHandler, this);
|
||||
new ModeWindow(modeHandler, this);
|
||||
|
||||
setCentralWidget(modeWindow);
|
||||
modeHandler->createMode("Vector Network Analyzer", Mode::Type::VNA);
|
||||
central = new QStackedWidget;
|
||||
setCentralWidget(central);
|
||||
|
||||
auto vnaIndex = modeHandler->createMode("Vector Network Analyzer", Mode::Type::VNA);
|
||||
modeHandler->createMode("Spectrum Analyzer", Mode::Type::SA);
|
||||
modeHandler->createMode("Signal Generator", Mode::Type::SG);
|
||||
modeHandler->setCurrentIndex(vnaIndex);
|
||||
|
||||
auto setModeStatusbar = [=](const QString &msg) {
|
||||
lModeInfo.setText(msg);
|
||||
@ -1128,28 +1131,29 @@ void AppWindow::LoadSetup(nlohmann::json j)
|
||||
|
||||
modeHandler->closeModes();
|
||||
|
||||
// old style VNA/Generator/Spectrum Analyzer settings
|
||||
/* old style VNA/Generator/Spectrum Analyzer settings,
|
||||
* no more than one instance in each mode running */
|
||||
if(j.contains("VNA")) {
|
||||
modeHandler->createMode("Vector Network Analyzer", Mode::Type::VNA);
|
||||
auto * vna = static_cast<VNA*>(modeHandler->findFirstOfType(Mode::Type::VNA));
|
||||
auto vnaIndex = modeHandler->createMode("Vector Network Analyzer", Mode::Type::VNA);
|
||||
auto *vna = static_cast<VNA*>(modeHandler->getMode(vnaIndex));
|
||||
vna->fromJSON(j["VNA"]);
|
||||
}
|
||||
if(j.contains("Generator")) {
|
||||
modeHandler->createMode("Generator", Mode::Type::SG);
|
||||
auto * generator = static_cast<Generator*>(modeHandler->findFirstOfType(Mode::Type::SG));
|
||||
auto sgIndex = modeHandler->createMode("Generator", Mode::Type::SG);
|
||||
auto *generator = static_cast<Generator*>(modeHandler->getMode(sgIndex));
|
||||
generator->fromJSON(j["Generator"]);
|
||||
}
|
||||
if(j.contains("SpectrumAnalyzer")) {
|
||||
modeHandler->createMode("Spectrum Analyzer", Mode::Type::SA);
|
||||
auto * spectrumAnalyzer = static_cast<SpectrumAnalyzer*>(modeHandler->findFirstOfType(Mode::Type::SA));
|
||||
auto saIndex = modeHandler->createMode("Spectrum Analyzer", Mode::Type::SA);
|
||||
auto *spectrumAnalyzer = static_cast<SpectrumAnalyzer*>(modeHandler->getMode(saIndex));
|
||||
spectrumAnalyzer->fromJSON(j["SpectrumAnalyzer"]);
|
||||
}
|
||||
if(j.contains("Modes")) {
|
||||
for(auto jm : j["Modes"]) {
|
||||
auto type = Mode::TypeFromName(QString::fromStdString(jm.value("type", "Invalid")));
|
||||
if(type != Mode::Type::Last && jm.contains("settings")) {
|
||||
modeHandler->createMode(QString::fromStdString(jm.value("name", "")), type);
|
||||
auto m = modeHandler->getMode(modeHandler->getCurrentIndex());
|
||||
auto index = modeHandler->createMode(QString::fromStdString(jm.value("name", "")), type);
|
||||
auto m = modeHandler->getMode(index);
|
||||
m->fromJSON(jm["settings"]);
|
||||
}
|
||||
}
|
||||
@ -1159,7 +1163,8 @@ void AppWindow::LoadSetup(nlohmann::json j)
|
||||
QString modeName = QString::fromStdString(j.value("activeMode", ""));
|
||||
for(auto m : modeHandler->getModes()) {
|
||||
if(m->getName() == modeName) {
|
||||
m->activate();
|
||||
auto index = modeHandler->findIndex(m);
|
||||
modeHandler->setCurrentIndex(index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1174,6 +1179,11 @@ Device *&AppWindow::getDevice()
|
||||
return device;
|
||||
}
|
||||
|
||||
QStackedWidget *AppWindow::getCentral() const
|
||||
{
|
||||
return central;
|
||||
}
|
||||
|
||||
Ui::MainWindow *AppWindow::getUi() const
|
||||
{
|
||||
return ui;
|
||||
|
@ -41,6 +41,7 @@ public:
|
||||
~AppWindow();
|
||||
|
||||
Ui::MainWindow *getUi() const;
|
||||
QStackedWidget *getCentral() const;
|
||||
Device*&getDevice();
|
||||
|
||||
const QString& getAppVersion() const;
|
||||
|
@ -32,6 +32,8 @@ Mode::~Mode()
|
||||
if(activeMode == this) {
|
||||
deactivate();
|
||||
}
|
||||
window->getCentral()->removeWidget(central);
|
||||
delete central;
|
||||
for(auto d : docks) {
|
||||
delete d;
|
||||
}
|
||||
@ -64,7 +66,7 @@ void Mode::activate()
|
||||
}
|
||||
|
||||
QSettings settings;
|
||||
|
||||
window->getCentral()->setCurrentWidget(central);
|
||||
// restore dock and toolbar positions
|
||||
window->restoreState(settings.value("windowState_"+name).toByteArray());
|
||||
|
||||
@ -179,6 +181,7 @@ Mode *Mode::createNew(AppWindow *window, QString name, Mode::Type t)
|
||||
void Mode::finalize(QWidget *centralWidget)
|
||||
{
|
||||
central = centralWidget;
|
||||
window->getCentral()->addWidget(central);
|
||||
// Set ObjectName for toolbars and docks
|
||||
for(auto d : docks) {
|
||||
d->setObjectName(d->windowTitle()+name);
|
||||
@ -224,8 +227,3 @@ void Mode::updateGraphColors()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QWidget *Mode::getCentral() const
|
||||
{
|
||||
return central;
|
||||
}
|
||||
|
@ -45,8 +45,6 @@ public:
|
||||
|
||||
static Mode *createNew(AppWindow *window, QString name, Type t);
|
||||
|
||||
virtual QWidget *getCentral() const;
|
||||
|
||||
signals:
|
||||
void statusbarMessage(QString msg);
|
||||
protected:
|
||||
|
@ -18,19 +18,23 @@ void ModeHandler::shutdown()
|
||||
}
|
||||
}
|
||||
|
||||
void ModeHandler::createMode(QString name, Mode::Type t)
|
||||
int ModeHandler::createMode(QString name, Mode::Type t)
|
||||
{
|
||||
auto mode = Mode::createNew(aw, name, t);
|
||||
createMode(mode);
|
||||
return createMode(mode);
|
||||
}
|
||||
|
||||
void ModeHandler::createMode(Mode *mode)
|
||||
int ModeHandler::createMode(Mode *mode)
|
||||
{
|
||||
modes.push_back(mode);
|
||||
currentModeIndex = int(modes.size());
|
||||
currentModeIndex = int(modes.size()) - 1;
|
||||
connect(mode, &Mode::statusbarMessage, this, &ModeHandler::setStatusBarMessageChanged);
|
||||
emit ModeCreated(currentModeIndex - 1);
|
||||
|
||||
auto * m = getMode(currentModeIndex);
|
||||
m->activate();
|
||||
|
||||
emit ModeCreated(currentModeIndex);
|
||||
return (currentModeIndex);
|
||||
}
|
||||
|
||||
Mode* ModeHandler::getMode(int index)
|
||||
@ -45,10 +49,12 @@ std::vector<Mode*> ModeHandler::getModes()
|
||||
|
||||
void ModeHandler::setCurrentIndex(int index)
|
||||
{
|
||||
if ( (currentModeIndex != index) && (index >= 0)) {
|
||||
// if ( (getCurrentIndex() != index) && (index >= 0)) {
|
||||
if ( (getCurrentIndex() != index) && (index >= 0)) {
|
||||
currentModeIndex = index;
|
||||
auto * mode = modes.at(currentModeIndex);
|
||||
mode->activate();
|
||||
auto * m = getMode(getCurrentIndex());
|
||||
m->activate();
|
||||
emit CurrentModeChanged(getCurrentIndex());
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,10 +68,10 @@ void ModeHandler::closeMode(int index)
|
||||
disconnect(modes.at(index), &Mode::statusbarMessage, this, &ModeHandler::setStatusBarMessageChanged);
|
||||
delete modes.at(index);
|
||||
modes.erase(modes.begin() + index);
|
||||
if (currentModeIndex > int(modes.size()) ) {
|
||||
setCurrentIndex(currentModeIndex - 1); // Select bar before one deleted
|
||||
auto vna = modes.at(currentModeIndex);
|
||||
vna->activate();
|
||||
if (int(modes.size()) > 0) {
|
||||
if (getCurrentIndex() == index) {
|
||||
setCurrentIndex(getCurrentIndex()-1); // Select bar before one deleted
|
||||
}
|
||||
}
|
||||
emit ModeClosed(index);
|
||||
}
|
||||
@ -95,6 +101,12 @@ bool ModeHandler::nameAllowed(const QString &name)
|
||||
return true;
|
||||
}
|
||||
|
||||
int ModeHandler::findIndex(Mode *targetMode)
|
||||
{
|
||||
auto it = std::find(modes.begin(), modes.end(), targetMode);
|
||||
return it - modes.begin();
|
||||
}
|
||||
|
||||
Mode* ModeHandler::findFirstOfType(Mode::Type t)
|
||||
{
|
||||
for(auto m : modes) {
|
||||
|
@ -15,7 +15,7 @@ public:
|
||||
~ModeHandler() = default;
|
||||
|
||||
void shutdown();
|
||||
void createMode(QString name, Mode::Type t);
|
||||
int createMode(QString name, Mode::Type t);
|
||||
void closeMode(int index);
|
||||
void closeModes();
|
||||
int getCurrentIndex();
|
||||
@ -24,6 +24,7 @@ public:
|
||||
std::vector<Mode*> getModes();
|
||||
|
||||
bool nameAllowed(const QString &name);
|
||||
int findIndex(Mode *targetMode);
|
||||
Mode* findFirstOfType(Mode::Type t);
|
||||
|
||||
void setAveragingMode(Averaging::Mode m);
|
||||
@ -33,6 +34,7 @@ signals:
|
||||
|
||||
void ModeCreated(int modeIndex);
|
||||
void ModeClosed(int modeIndex);
|
||||
void CurrentModeChanged(int modeIndex);
|
||||
|
||||
public slots:
|
||||
void setCurrentIndex(int modeIndex);
|
||||
@ -40,7 +42,7 @@ public slots:
|
||||
private:
|
||||
std::vector<Mode*> modes;
|
||||
int currentModeIndex;
|
||||
void createMode(Mode *mode);
|
||||
int createMode(Mode *mode);
|
||||
AppWindow *aw;
|
||||
|
||||
private slots:
|
||||
|
@ -1,14 +0,0 @@
|
||||
#include "modetabwidget.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QPushButton>
|
||||
|
||||
ModeTabWidget::ModeTabWidget(QWidget* parent):
|
||||
QTabWidget(parent)
|
||||
{
|
||||
tabBar = new QTabBar;
|
||||
tabBar->setStyleSheet("QTabBar::tab { height: " + QString::number(parent->height()) + "px;}");
|
||||
this->setTabBar(tabBar);
|
||||
this->setTabsClosable(true);
|
||||
this->setMovable(true);
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
#ifndef MODETABWIDGET_H
|
||||
#define MODETABWIDGET_H
|
||||
|
||||
#include <QTabWidget>
|
||||
#include <QTabBar>
|
||||
|
||||
class ModeTabWidget: public QTabWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ModeTabWidget(QWidget* parent = nullptr);
|
||||
~ModeTabWidget() = default;
|
||||
|
||||
private:
|
||||
QTabBar * tabBar = nullptr;
|
||||
};
|
||||
|
||||
#endif // MODETABWIDGET_H
|
@ -1,7 +1,6 @@
|
||||
#include "modewindow.h"
|
||||
|
||||
#include "mode.h"
|
||||
#include "ui_modewindow.h"
|
||||
#include "appwindow.h"
|
||||
#include "CustomWidgets/informationbox.h"
|
||||
|
||||
@ -14,31 +13,34 @@ ModeWindow::ModeWindow(ModeHandler* handler, AppWindow* aw, QWidget* parent):
|
||||
handler(handler),
|
||||
aw(aw)
|
||||
{
|
||||
ui = new Ui::ModeWindow;
|
||||
ui->setupUi(this);
|
||||
|
||||
SetupUi();
|
||||
|
||||
connect(handler, &ModeHandler::ModeCreated, this, &ModeWindow::ModeCreated);
|
||||
connect(handler, &ModeHandler::ModeClosed, this, &ModeWindow::ModeClosed);
|
||||
connect(handler, &ModeHandler::CurrentModeChanged, this, &ModeWindow::CurrentModeChanged);
|
||||
|
||||
connect(ui->tabwidgetModes, &ModeTabWidget::currentChanged, handler, &ModeHandler::setCurrentIndex);
|
||||
connect(ui->tabwidgetModes, &ModeTabWidget::tabCloseRequested, handler, &ModeHandler::closeMode);
|
||||
|
||||
connect(tabBar, &QTabBar::currentChanged, handler, &ModeHandler::setCurrentIndex);
|
||||
connect(tabBar, &QTabBar::tabCloseRequested, handler, &ModeHandler::closeMode);
|
||||
}
|
||||
|
||||
ModeWindow::~ModeWindow()
|
||||
{
|
||||
delete ui;
|
||||
ui = nullptr;
|
||||
}
|
||||
|
||||
void ModeWindow::SetupUi()
|
||||
{
|
||||
ui->horizontalLayout->setSpacing(0);
|
||||
ui->horizontalLayout->setMargin(0);
|
||||
ui->horizontalLayout->setContentsMargins(0,0,0,0);
|
||||
ui->tabwidgetModes->setUsesScrollButtons(true);
|
||||
auto cornerWidget = new QWidget();
|
||||
cornerWidget->setLayout(new QHBoxLayout);
|
||||
cornerWidget->layout()->setSpacing(0);
|
||||
cornerWidget->layout()->setMargin(0);
|
||||
cornerWidget->layout()->setContentsMargins(0,0,0,0);
|
||||
cornerWidget->setMaximumHeight(aw->menuBar()->height());
|
||||
|
||||
tabBar = new QTabBar;
|
||||
tabBar->setStyleSheet("QTabBar::tab { height: " + QString::number(aw->menuBar()->height()) + "px;}");
|
||||
tabBar->setTabsClosable(true);
|
||||
cornerWidget->layout()->addWidget(tabBar);
|
||||
|
||||
auto bAdd = new QPushButton();
|
||||
QIcon icon;
|
||||
@ -50,7 +52,7 @@ void ModeWindow::SetupUi()
|
||||
icon.addFile(QString::fromUtf8(":/icons/add.png"), QSize(), QIcon::Normal, QIcon::Off);
|
||||
|
||||
bAdd->setIcon(icon);
|
||||
bAdd->setMaximumHeight(450);
|
||||
bAdd->setMaximumHeight(aw->menuBar()->height());
|
||||
bAdd->setMaximumWidth(40);
|
||||
|
||||
auto mAdd = new QMenu();
|
||||
@ -75,7 +77,10 @@ void ModeWindow::SetupUi()
|
||||
});
|
||||
}
|
||||
bAdd->setMenu(mAdd);
|
||||
aw->menuBar()->setCornerWidget(bAdd);
|
||||
|
||||
cornerWidget->layout()->addWidget(bAdd);
|
||||
|
||||
aw->menuBar()->setCornerWidget(cornerWidget);
|
||||
}
|
||||
|
||||
void ModeWindow::ModeCreated(int modeIndex)
|
||||
@ -85,15 +90,27 @@ void ModeWindow::ModeCreated(int modeIndex)
|
||||
if (mode)
|
||||
{
|
||||
const auto name = mode->getName();
|
||||
auto central = mode->getCentral();
|
||||
const auto tabIndex = ui->tabwidgetModes->insertTab(modeIndex, central, name);
|
||||
ui->tabwidgetModes->setCurrentIndex(tabIndex);
|
||||
|
||||
tabBar->blockSignals(true);
|
||||
tabBar->insertTab(modeIndex, name);
|
||||
tabBar->blockSignals(false);
|
||||
|
||||
tabBar->setCurrentIndex(modeIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void ModeWindow::ModeClosed(int modeIndex)
|
||||
{
|
||||
auto modeWidget = ui->tabwidgetModes->widget(modeIndex);
|
||||
ui->tabwidgetModes->removeTab(modeIndex);
|
||||
delete modeWidget;
|
||||
tabBar->blockSignals(true);
|
||||
tabBar->removeTab(modeIndex);
|
||||
tabBar->blockSignals(false);
|
||||
}
|
||||
|
||||
|
||||
void ModeWindow::CurrentModeChanged(int modeIndex)
|
||||
{
|
||||
if (modeIndex != tabBar->currentIndex())
|
||||
{
|
||||
tabBar->setCurrentIndex(modeIndex);
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,6 @@
|
||||
|
||||
#include "modehandler.h"
|
||||
|
||||
namespace Ui {
|
||||
class ModeWindow;
|
||||
}
|
||||
|
||||
class ModeWindow: public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -16,13 +12,14 @@ public:
|
||||
|
||||
private:
|
||||
ModeHandler* handler;
|
||||
Ui::ModeWindow *ui;
|
||||
void SetupUi();
|
||||
AppWindow* aw;
|
||||
QTabBar* tabBar;
|
||||
|
||||
private slots:
|
||||
void ModeCreated(int modeIndex);
|
||||
void ModeClosed(int modeIndex);
|
||||
void CurrentModeChanged(int modeIndex);
|
||||
};
|
||||
|
||||
#endif // MODEWINDOW_H
|
||||
|
@ -1,45 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ModeWindow</class>
|
||||
<widget class="QWidget" name="ModeWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>22</width>
|
||||
<height>29</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="ModeTabWidget" name="tabwidgetModes">
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>-1</number>
|
||||
</property>
|
||||
<property name="usesScrollButtons">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="tabsClosable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ModeTabWidget</class>
|
||||
<extends>QTabWidget</extends>
|
||||
<header>modetabwidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in New Issue
Block a user