玉兔远程控制 0.0.34
载入中...
搜索中...
未找到
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 << this;
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 << this;
58 if(m_pTab) {
59 m_pTab->clear();
60 delete m_pTab;
61 }
62}
63
64void CViewTable::slotCurrentChanged(int index)
65{
66 qDebug(log) << "CViewTable::slotCurrentChanged";
67 emit sigCurrentChanged(GetViewer(index));
68}
69
70void CViewTable::slotTabCloseRequested(int index)
71{
72 QWidget* pView = GetViewer(index);
73 if(!pView) return;
74 emit sigCloseView(pView);
75}
76
77void CViewTable::slotTabPositionChanged()
78{
79 MainWindow* p = dynamic_cast<MainWindow*>(parent());
80 if(!p || !m_pTab) return;
81 m_pTab->setTabPosition(p->m_Parameter.GetTabPosition());
82}
83
84void CViewTable::slotSystemCombination()
85{
86 QWidget* pView = GetCurrentView();
87 if(!pView) return;
88 CFrmViewer* pFrmViewer = qobject_cast<CFrmViewer*>(pView);
89 if(pFrmViewer)
90 pFrmViewer->slotSystemCombination();
91}
92
93int CViewTable::AddView(QWidget *pView)
94{
95 int nIndex = -1;
96 if(!pView)
97 {
98 qCritical(log) << "CViewTable::AddView: The pView is nullptr";
99 return -1;
100 }
101 //qDebug(log) << "CViewTable::AddView: Window title:" << pView->windowTitle();
102 nIndex = m_pTab->indexOf(pView);
103 if(-1 == nIndex)
104 nIndex = m_pTab->addTab(pView, pView->windowTitle());
105 m_pTab->setCurrentIndex(nIndex);
106
107 return 0;
108}
109
110int CViewTable::RemoveView(QWidget *pView)
111{
112 int nIndex = GetViewIndex(pView);
113 if(-1 == nIndex) return 0;
114 // Note: The following order cannot be changed
115 m_pTab->removeTab(nIndex);
116 return 0;
117}
118
119void CViewTable::SetWidowsTitle(QWidget* pView, const QString& szTitle,
120 const QIcon &icon, const QString &szToolTip)
121{
122 if(!pView) {
123 qCritical(log) << "CViewTable::SetWidowsTitle: The pView is nullptr";
124 return;
125 }
126 //qDebug(log) << "CViewTable::SetWidowsTitle: Window title:" << szTitle;
127 pView->setWindowTitle(szTitle);
128 int nIndex = GetViewIndex(pView);
129 m_pTab->setTabText(nIndex, szTitle);
130 if(m_pMainWindow->m_Parameter.GetEnableTabToolTip())
131 m_pTab->setTabToolTip(nIndex, szToolTip);
132 else
133 m_pTab->setTabToolTip(nIndex, "");
134 if(m_pMainWindow->m_Parameter.GetEnableTabIcon())
135 m_pTab->setTabIcon(nIndex, icon);
136 else
137 m_pTab->setTabIcon(nIndex, QIcon());
138}
139
140int CViewTable::SetFullScreen(bool bFull)
141{
142 if(!m_pTab) return -1;
143 ShowTabBar(!bFull);
144 if(bFull)
145 {
146 m_szStyleSheet = m_pTab->styleSheet();
147 //qDebug(log) << m_szStyleSheet;
148 m_pTab->setStyleSheet("QTabWidget::pane{top:0px;left:0px;border:none;}");
149 m_pTab->showFullScreen();
150 } else {
151 m_pTab->setStyleSheet(m_szStyleSheet);
152 m_pTab->showNormal();
153 }
154 return 0;
155}
156
157int CViewTable::ShowTabBar(bool bShow)
158{
159 m_pTab->tabBar()->setVisible(bShow);
160 return 0;
161}
162
163QWidget *CViewTable::GetViewer(int index)
164{
165 if(index < 0 || index >= m_pTab->count())
166 return nullptr;
167
168 return m_pTab->widget(index);
169}
170
171int CViewTable::GetViewIndex(QWidget *pView)
172{
173 for(int i = 0; i < m_pTab->count(); i++)
174 {
175 QWidget* p = GetViewer(i);
176 if(p == pView)
177 return i;
178 }
179 return -1;
180}
181
182// \note The return QWidget* must is same as CConnecter::GetViewer()
184{
185 QWidget* pView = m_pTab->currentWidget();
186 if(!pView) return pView;
187 return pView;
188}
189
190int CViewTable::SetCurrentView(QWidget* pView)
191{
192 int nIndex = m_pTab->indexOf(pView);
193 if(-1 != nIndex) {
194 m_pTab->setCurrentIndex(nIndex);
195 return 0;
196 }
197 return -1;
198}
199
200void CViewTable::resizeEvent(QResizeEvent *event)
201{
202 if(!m_pTab)
203 return;
204 m_pTab->move(0, 0);
205 m_pTab->resize(event->size());
206}
用于显示从 CConnectDesktop 输出的图像,和向 CConnectDesktop 发送键盘、鼠标事件。
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:93
The CView class
Definition View.h:24
void sigCloseView(const QWidget *pView)
The MainWindow class
Definition mainwindow.h:33