3#include "ViewSplitter.h"
5#include <QLoggingCategory>
8#include "ViewSplitterContainer.h"
10static Q_LOGGING_CATEGORY(log,
"App.View.Splitter")
13 :
CView(pPara, parent)
19 qDebug(log) << Q_FUNC_INFO <<
this;
21 QVBoxLayout* p =
new QVBoxLayout(
this);
23 qCritical(log) <<
"new QVBoxLayout fail";
26 p->setContentsMargins(0, 0, 0, 0);
28 m_pMain =
new QSplitter(Qt::Vertical,
this);
30 m_pMain->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
31 qCritical(log) <<
"m_pMain is nullptr";
34 p->addWidget(m_pMain);
35 m_HandleWidth = m_pMain->handleWidth();
41CViewSplitter::~CViewSplitter()
43 qDebug(log) << Q_FUNC_INFO <<
this;
44 for(
int i = 0; i < m_nRow; i++)
47 for(
int j = 0; j < sp->count(); j++)
49 auto pw = sp->widget(j);
50 pw->setParent(
nullptr);
58 QSplitter* sp =
nullptr;
60 qCritical(log) <<
"The view is null";
68 if(m_nCount + 1 > m_nRow * m_nRow) {
69 QSplitter* p =
new QSplitter(Qt::Horizontal, m_pMain);
71 p->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
79 for(i = 0; i < m_nRow; i++) {
81 if(p->count() < m_nRow) {
93 m_nIdxCol = sp->count();
94 sp->addWidget(pContainer);
95 pContainer->SetVisibleTab(m_pParameterApp->GetTabBar());
97 m_Container.insert(pView, pContainer);
101 SIGNAL(customContextMenuRequested(
const QPoint&)),
102 this, SIGNAL(customContextMenuRequested(
const QPoint&)));
104 check = connect(pContainer, &CViewSplitterContainer::sigFouceIn,
105 this, [&](QWidget* pView){
106 SetCurrentView(pView);
110 check = connect(m_pParameterApp, SIGNAL(sigTabPositionChanged()),
111 pContainer, SLOT(slotTabPositionChanged()));
113 check = connect(pContainer, SIGNAL(
sigCloseView(
const QWidget*)),
123 qDebug(log) << Q_FUNC_INFO <<
"Row:" << m_nRow << m_pMain->count() <<
"Count:" << m_nCount
124 <<
"Current row:" << m_nIdxRow <<
"Current col:" << m_nIdxCol
125 <<
"Current count:" << sp->count();
126 emit sigCurrentChanged(pView);
139 nRet = GetIndex(pView, nRow, nCol);
145 if(pView == pCurView)
148 if(m_Row[nRow]->count() > nCol + 1)
149 pContainerNext = GetContainer(nRow, nCol + 1);
150 else if(m_Row[nRow]->count() - 1 == nCol && 0 != nCol)
151 pContainerNext = GetContainer(nRow, nCol -1);
152 else if(0 == nCol && nRow + 1 < m_nRow) {
153 for(
int i = nRow + 1; i < m_nRow; i++) {
154 if(m_Row[i]->count() > 0) {
155 pContainerNext = GetContainer(nRow + 1, 0);
160 if(!pContainerNext) {
161 for(
int i = nRow - 1; i >= 0; i--) {
162 if(m_Row[i]->count() > 0) {
163 pContainerNext = GetContainer(i, m_Row[i]->count() - 1);
171 pView->setParent(
nullptr);
172 auto pContainer = GetContainer(pView);
175 pContainer->setParent(
nullptr);
176 m_Container.remove(pView);
179 qDebug(log) <<
"Row:" << nRow <<
"remain:" << m_Row[nRow]->count();
182 qDebug(log) <<
"Row:" << m_nRow <<
"Count:" << m_nCount
183 <<
"Current row:" << m_nIdxRow <<
"Current col:" << m_nIdxCol;
186 pCurView = pContainerNext->GetView();
188 if(pContainerNext->isHidden())
189 pContainerNext->show();
192 pCurView->setFocus();
194 return SetCurrentView(pCurView);
199 auto p = GetContainer(m_nIdxRow, m_nIdxCol);
205int CViewSplitter::SetCurrentView(QWidget *pView)
212 nRet = GetIndex(pView, nRow, nCol);
213 if(nRet)
return nRet;
215 if(m_nIdxCol == nCol && m_nIdxRow == nRow)
222 emit sigCurrentChanged(pView);
227void CViewSplitter::SetWidowsTitle(
228 QWidget *pView,
const QString &szTitle,
229 const QIcon &icon,
const QString &szToolTip)
233 auto pContainer = GetContainer(pView);
236 pContainer->setWindowTitle(szTitle);
237 if(m_pParameterApp->GetEnableTabIcon())
238 pContainer->setWindowIcon(icon);
240 pContainer->setWindowIcon(QIcon());
241 if(m_pParameterApp->GetEnableTabToolTip())
242 pContainer->SetPrompt(szToolTip);
244 pContainer->SetPrompt(QString());
249int CViewSplitter::SetFullScreen(
bool bFull)
252 if(0 >= m_nCount)
return 0;
254 if(m_pParameterApp && m_pParameterApp->GetKeepSplitViewWhenFullScreen())
258 qDebug(log) <<
"CurrentView:" << p;
261 m_szStyleSheet = styleSheet();
263 setStyleSheet(
"QWidget::pane{top:0px;left:0px;border:none;}");
264 m_HandleWidth = m_pMain->handleWidth();
265 m_pMain->setHandleWidth(0);
266 for(
int i = 0; i < m_nRow; i++) {
269 qCritical(log) <<
"Row" << i <<
"is null";
272 sp->setHandleWidth(0);
273 for(
int j = 0; j < m_nRow; j++) {
274 if(m_nIdxRow == i && m_nIdxCol == j) {
276 SetVisibleTab(
false);
279 auto p = sp->widget(j);
283 qCritical(log) <<
"Widget: Row" << i <<
"Col" << j <<
"is null";
289 setStyleSheet(m_szStyleSheet);
290 m_pMain->setHandleWidth(m_HandleWidth);
291 for(
int i = 0; i < m_nRow; i++) {
293 sp->setHandleWidth(m_HandleWidth);
295 for(
int j = 0; j < m_nRow; j++) {
296 auto p = sp->widget(j);
298 SetVisibleTab(m_pParameterApp->GetTabBar());
300 if(m_nIdxRow == i && m_nIdxCol == j) {
312int CViewSplitter::SetVisibleTab(
bool bVisible)
314 foreach (
auto c, m_Container) {
316 c->SetVisibleTab(bVisible);
322int CViewSplitter::GetIndex(QWidget* pView,
int &nRow,
int &nCol)
329 auto pContainer = m_Container[pView];
330 for(nRow = 0; nRow < m_nRow; nRow++)
332 auto sp = m_Row[nRow];
334 nCol = sp->indexOf(pContainer);
344 QWidget* pContainer =
nullptr;
345 QSplitter* sp =
nullptr;
346 if(-1 < nRow && nRow < m_nRow)
348 if(sp && -1 < nCol && nCol < sp->count())
349 pContainer = sp->widget(nCol);
350 qDebug(log) <<
"Container" <<
"Row number:" << m_nRow << m_Row.size()
351 <<
"Count:" << m_nCount
352 <<
"row:" << m_nIdxRow <<
"col:" << m_nIdxCol;
353 return qobject_cast<CViewSplitterContainer*>(pContainer);
358 auto it = m_Container.find(pView);
359 if(m_Container.end() == it)
366 foreach (
auto c, m_Container) {
368 if(c->GetView() == pView &&
nullptr != pView) {
369 c->setFrameStyle(QFrame::Panel|QFrame::Raised);
371 c->setMidLineWidth(5);
373 c->setFrameStyle(QFrame::NoFrame);
375 c->setMidLineWidth(0);
381int CViewSplitter::SetSizes()
386 foreach(
auto sp, m_Row) {
387 for(
int i = 0; i < sp->count(); i++) {
388 auto pContainer = sp->widget(i);
389 w = qMax(w, pContainer->frameGeometry().width());
390 h = qMax(h, pContainer->frameGeometry().height());
394 qDebug(log) <<
"Width:" << w <<
"Height:" << h;
396 QList<int> wSizes, hSizes;
397 foreach(
auto sp, m_Row) {
399 for(
int i = 0; i < sp->count(); i++) {
402 sp->setSizes(wSizes);
403 qDebug(log) <<
"wSizes:" << wSizes << sp->sizes();
406 m_pMain->setSizes(hSizes);
407 qDebug(log) <<
"hSizes:" << hSizes << m_pMain->sizes();
virtual int RemoveView(QWidget *pView) override
int ActiveContainer(QWidget *pView)
突出当前视图
virtual QWidget * GetCurrentView() override
virtual int AddView(QWidget *pView) override
void sigCloseView(const QWidget *pView)