Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
ViewTable.cpp
1// Author: Kang Lin <kl222@126.com>
2
3#include <QResizeEvent>
4#include <QTabBar>
5#include <QStyleOption>
6#include <QDebug>
7#include <QScrollBar>
8#include <QFileInfo>
9#include <QDir>
10#include <QLoggingCategory>
11#include "mainwindow.h"
12#include "ViewTable.h"
13
14static Q_LOGGING_CATEGORY(log, "App.View.Table")
15static Q_LOGGING_CATEGORY(logRecord, "App.View.Table.Record")
16
17CViewTable::CViewTable(QWidget *parent) : CView(parent),
18 m_pTab(nullptr)
19{
20 qDebug(log) << Q_FUNC_INFO;
21 bool check = false;
22 setFocusPolicy(Qt::NoFocus);
23
24 m_pTab = new QTabWidget(this);
25 m_pTab->setTabsClosable(true);
26 m_pTab->setUsesScrollButtons(true);
27 m_pTab->setMovable(true);
28 m_pTab->setFocusPolicy(Qt::NoFocus);
29 m_pTab->tabBar()->setContextMenuPolicy(Qt::CustomContextMenu);
30 if(this->parent())
31 {
32 MainWindow* p = dynamic_cast<MainWindow*>(this->parent());
33 if(p)
34 {
35 m_pMainWindow = p;
36 m_pTab->setTabPosition(p->m_Parameter.GetTabPosition());
37 check = connect(&p->m_Parameter, SIGNAL(sigTabPositionChanged()),
38 this, SLOT(slotTabPositionChanged()));
39 Q_ASSERT(check);
40 }
41 }
42
43 check = connect(m_pTab, SIGNAL(tabCloseRequested(int)),
44 this, SLOT(slotTabCloseRequested(int)));
45 Q_ASSERT(check);
46 check = connect(m_pTab, SIGNAL(currentChanged(int)),
47 this, SLOT(slotCurrentChanged(int)));
48 Q_ASSERT(check);
49 check = connect(m_pTab->tabBar(),
50 SIGNAL(customContextMenuRequested(const QPoint&)),
51 this, SIGNAL(customContextMenuRequested(const QPoint&)));
52 Q_ASSERT(check);
53}
54
55CViewTable::~CViewTable()
56{
57 qDebug(log) << Q_FUNC_INFO;
58 if(m_pTab)
59 delete m_pTab;
60}
61
62void CViewTable::slotCurrentChanged(int index)
63{
64 qDebug(log) << "CViewTable::slotCurrentChanged";
65 emit sigCurrentChanged(GetViewer(index));
66}
67
68void CViewTable::slotTabCloseRequested(int index)
69{
70 QWidget* pView = GetViewer(index);
71 if(!pView) return;
72 emit sigCloseView(pView);
73}
74
75void CViewTable::slotTabPositionChanged()
76{
77 MainWindow* p = dynamic_cast<MainWindow*>(parent());
78 if(!p || !m_pTab) return;
79 m_pTab->setTabPosition(p->m_Parameter.GetTabPosition());
80}
81
82void CViewTable::slotSystemCombination()
83{
84 QWidget* pView = GetCurrentView();
85 if(!pView) return;
86 CFrmViewer* pFrmViewer = qobject_cast<CFrmViewer*>(pView);
87 if(pFrmViewer)
88 pFrmViewer->slotSystemCombination();
89}
90
91int CViewTable::AddView(QWidget *pView)
92{
93 int nIndex = -1;
94 if(!pView)
95 {
96 qCritical(log) << "CViewTable::AddView: The pView is nullptr";
97 return -1;
98 }
99 //qDebug(log) << "CViewTable::AddView: Window title:" << pView->windowTitle();
100 nIndex = m_pTab->addTab(pView, pView->windowTitle());
101 m_pTab->setCurrentIndex(nIndex);
102
103 return 0;
104}
105
106int CViewTable::RemoveView(QWidget *pView)
107{
108 int nIndex = GetViewIndex(pView);
109 if(-1 == nIndex) return 0;
110 // Note: The following order cannot be changed
111 m_pTab->removeTab(nIndex);
112 return 0;
113}
114
115void CViewTable::SetWidowsTitle(QWidget* pView, const QString& szTitle,
116 const QIcon &icon, const QString &szToolTip)
117{
118 if(!pView) {
119 qCritical(log) << "CViewTable::SetWidowsTitle: The pView is nullptr";
120 return;
121 }
122 //qDebug(log) << "CViewTable::SetWidowsTitle: Window title:" << szTitle;
123 pView->setWindowTitle(szTitle);
124 int nIndex = GetViewIndex(pView);
125 m_pTab->setTabText(nIndex, szTitle);
126 if(m_pMainWindow->m_Parameter.GetEnableTabToolTip())
127 m_pTab->setTabToolTip(nIndex, szToolTip);
128 else
129 m_pTab->setTabToolTip(nIndex, "");
130 if(m_pMainWindow->m_Parameter.GetEnableTabIcon())
131 m_pTab->setTabIcon(nIndex, icon);
132 else
133 m_pTab->setTabIcon(nIndex, QIcon());
134}
135
136int CViewTable::SetFullScreen(bool bFull)
137{
138 if(!m_pTab) return -1;
139 ShowTabBar(!bFull);
140 if(bFull)
141 {
142 m_szStyleSheet = m_pTab->styleSheet();
143 //qDebug(log) << m_szStyleSheet;
144 m_pTab->setStyleSheet("QTabWidget::pane{top:0px;left:0px;border:none;}");
145 m_pTab->showFullScreen();
146 } else {
147 m_pTab->setStyleSheet(m_szStyleSheet);
148 m_pTab->showNormal();
149 }
150 return 0;
151}
152
153int CViewTable::ShowTabBar(bool bShow)
154{
155 m_pTab->tabBar()->setVisible(bShow);
156 return 0;
157}
158
159QWidget *CViewTable::GetViewer(int index)
160{
161 if(index < 0 || index >= m_pTab->count())
162 return nullptr;
163
164 return m_pTab->widget(index);
165}
166
167int CViewTable::GetViewIndex(QWidget *pView)
168{
169 for(int i = 0; i < m_pTab->count(); i++)
170 {
171 QWidget* p = GetViewer(i);
172 if(p == pView)
173 return i;
174 }
175 return -1;
176}
177
178// \note The return QWidget* must is same as CConnecter::GetViewer()
180{
181 QWidget* pView = m_pTab->currentWidget();
182 if(!pView) return pView;
183 return pView;
184}
185
186void CViewTable::resizeEvent(QResizeEvent *event)
187{
188 if(!m_pTab)
189 return;
190 m_pTab->move(0, 0);
191 m_pTab->resize(event->size());
192}
193
194QSize CViewTable::GetDesktopSize()
195{
196 return frameSize();
197}
A widget which displays output image from a CConnectDesktop and sends input keypresses and mouse acti...
Definition FrmViewer.h:49
The CViewTable class.
Definition ViewTable.h:16
virtual int RemoveView(QWidget *pView) override
virtual QWidget * GetCurrentView() override
virtual int AddView(QWidget *pView) override
Definition ViewTable.cpp:91
The CView class.
Definition View.h:25
void sigCloseView(const QWidget *pView)
The MainWindow class.
Definition mainwindow.h:32