10#include <QLoggingCategory>
11#include "mainwindow.h"
14static Q_LOGGING_CATEGORY(log,
"App.View.Table")
15static Q_LOGGING_CATEGORY(logRecord, "App.View.Table.Record")
18 :
CView(pPara, parent),
21 qDebug(log) << Q_FUNC_INFO <<
this;
25 m_pTab =
new QTabWidget(
this);
26 m_pTab->setTabsClosable(
true);
27 m_pTab->setUsesScrollButtons(
true);
28 m_pTab->setMovable(
true);
33 if(m_pParameterApp->GetTabElided())
34 m_pTab->setElideMode(Qt::ElideLeft);
35 m_pTab->setTabPosition(m_pParameterApp->GetTabPosition());
36 check = connect(m_pParameterApp, SIGNAL(sigTabPositionChanged()),
37 this, SLOT(slotTabPositionChanged()));
39 check = connect(m_pParameterApp, &CParameterApp::sigTabElided,
41 if(m_pParameterApp->GetTabElided())
42 m_pTab->setElideMode(Qt::ElideLeft);
44 m_pTab->setElideMode(Qt::ElideNone);
48 check = connect(m_pTab, SIGNAL(tabCloseRequested(
int)),
49 this, SLOT(slotTabCloseRequested(
int)));
51 check = connect(m_pTab, SIGNAL(currentChanged(
int)),
52 this, SLOT(slotCurrentChanged(
int)));
55 m_pTab->tabBar()->setContextMenuPolicy(Qt::CustomContextMenu);
56 check = connect(m_pTab->tabBar(), &QTabBar::customContextMenuRequested,
57 this, [&](
const QPoint& pos){
59 p = m_pTab->tabBar()->mapToGlobal(pos);
60 emit customContextMenuRequested(p);
66CViewTable::~CViewTable()
68 qDebug(log) << Q_FUNC_INFO <<
this;
75void CViewTable::slotCurrentChanged(
int index)
77 qDebug(log) <<
"CViewTable::slotCurrentChanged";
78 emit sigCurrentChanged(GetViewer(index));
81void CViewTable::slotTabCloseRequested(
int index)
83 QWidget* pView = GetViewer(index);
88void CViewTable::slotTabPositionChanged()
92 m_pTab->setTabPosition(m_pParameterApp->GetTabPosition());
100 qCritical(log) <<
"CViewTable::AddView: The pView is nullptr";
104 nIndex = m_pTab->indexOf(pView);
106 nIndex = m_pTab->addTab(pView, pView->windowTitle());
108 m_pTab->setCurrentIndex(nIndex);
115 int nIndex = GetViewIndex(pView);
116 if(-1 == nIndex)
return 0;
118 m_pTab->removeTab(nIndex);
122void CViewTable::SetWidowsTitle(QWidget* pView,
const QString& szTitle,
123 const QIcon &icon,
const QString &szToolTip)
126 qCritical(log) <<
"CViewTable::SetWidowsTitle: The pView is nullptr";
130 pView->setWindowTitle(szTitle);
131 int nIndex = GetViewIndex(pView);
132 m_pTab->setTabText(nIndex, szTitle);
133 if(m_pParameterApp->GetEnableTabToolTip())
134 m_pTab->setTabToolTip(nIndex, szToolTip);
136 m_pTab->setTabToolTip(nIndex,
"");
137 if(m_pParameterApp->GetEnableTabIcon())
138 m_pTab->setTabIcon(nIndex, icon);
140 m_pTab->setTabIcon(nIndex, QIcon());
143int CViewTable::SetFullScreen(
bool bFull)
145 if(!m_pTab)
return -1;
148 m_szStyleSheet = m_pTab->styleSheet();
149 SetVisibleTab(
false);
151 m_pTab->setStyleSheet(
"QTabWidget::pane{top:0px;left:0px;border:none;}");
152 m_pTab->showFullScreen();
154 SetVisibleTab(m_pParameterApp->GetTabBar());
155 m_pTab->setStyleSheet(m_szStyleSheet);
156 m_pTab->showNormal();
161int CViewTable::SetVisibleTab(
bool bVisible)
163 m_pTab->tabBar()->setVisible(bVisible);
167QWidget *CViewTable::GetViewer(
int index)
169 if(index < 0 || index >= m_pTab->count())
172 return m_pTab->widget(index);
175int CViewTable::GetViewIndex(QWidget *pView)
177 for(
int i = 0; i < m_pTab->count(); i++)
179 QWidget* p = GetViewer(i);
189 QWidget* pView = m_pTab->currentWidget();
190 if(!pView)
return pView;
194int CViewTable::SetCurrentView(QWidget* pView)
196 int nIndex = m_pTab->indexOf(pView);
198 m_pTab->setCurrentIndex(nIndex);
204void CViewTable::resizeEvent(QResizeEvent *event)
209 m_pTab->resize(event->size());
virtual int RemoveView(QWidget *pView) override
virtual QWidget * GetCurrentView() override
virtual int AddView(QWidget *pView) override
void sigCloseView(const QWidget *pView)