51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
#include "session_window.h"
|
|
|
|
#include "session_tab.h"
|
|
|
|
#include <QTabWidget>
|
|
|
|
SessionWindow::SessionWindow(const Profile& profile, QWidget* parent)
|
|
: QMainWindow(parent), m_tabs(new QTabWidget(this))
|
|
{
|
|
setWindowTitle(QStringLiteral("OrbitHub Session - %1").arg(profile.name));
|
|
resize(1080, 760);
|
|
|
|
m_tabs->setTabsClosable(true);
|
|
connect(m_tabs,
|
|
&QTabWidget::tabCloseRequested,
|
|
this,
|
|
[this](int index) {
|
|
QWidget* tab = m_tabs->widget(index);
|
|
m_tabs->removeTab(index);
|
|
delete tab;
|
|
if (m_tabs->count() == 0) {
|
|
close();
|
|
}
|
|
});
|
|
|
|
setCentralWidget(m_tabs);
|
|
addSessionTab(profile);
|
|
}
|
|
|
|
void SessionWindow::addSessionTab(const Profile& profile)
|
|
{
|
|
auto* tab = new SessionTab(profile, this);
|
|
const int index = m_tabs->addTab(tab, tab->tabTitle());
|
|
m_tabs->setCurrentIndex(index);
|
|
|
|
connect(tab,
|
|
&SessionTab::tabTitleChanged,
|
|
this,
|
|
[this, tab](const QString& title) { updateTabTitle(tab, title); });
|
|
}
|
|
|
|
void SessionWindow::updateTabTitle(SessionTab* tab, const QString& title)
|
|
{
|
|
for (int i = 0; i < m_tabs->count(); ++i) {
|
|
if (m_tabs->widget(i) == tab) {
|
|
m_tabs->setTabText(i, title);
|
|
return;
|
|
}
|
|
}
|
|
}
|