-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShuttleHelper.cpp
208 lines (188 loc) · 4.6 KB
/
ShuttleHelper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include "ShuttleHelper.h"
#include "ShuttleBase.h"
#include <QDebug>
#define ToShuttle(x) dynamic_cast<ShuttleBase*>(x)
ShuttleHelper *ShuttleHelper::s_instance = nullptr;
ShuttleHelper& ShuttleHelper::Instance()
{
if(nullptr == s_instance)
{
s_instance = new ShuttleHelper(nullptr);
}
return *s_instance;
}
void ShuttleHelper::Construct(QObject *parent)
{
if(nullptr == s_instance)
{
s_instance = new ShuttleHelper(parent);
}
}
void ShuttleHelper::Destruct()
{
if(nullptr != s_instance)
{
delete s_instance;
s_instance = nullptr;
}
}
ShuttleHelper::ShuttleHelper(QObject *parent)
: QObject(parent)
, m_adjustFlag(false)
, m_clickFlag(false) // 默认不显示焦点
{
m_shuttleQueue.push_back(ShuttleDate());
}
ShuttleHelper::~ShuttleHelper()
{
}
void ShuttleHelper::onLeft() // <-
{
QVector<QWidget*> &vec = m_shuttleQueue.last().shuttleVec;
QVector<QWidget*>::const_iterator &iter = m_shuttleQueue.last().shuttleIter;
if(!m_clickFlag)
{
m_clickFlag = true;
(*iter)->setFocus();
}
else if(m_adjustFlag) // 调节
{
ToShuttle(*iter)->ShuttleReduce();
}
else // 光标移动
{
if(vec.constBegin() == iter)
{
iter = vec.constEnd()-1;
}
else
{
iter--;
}
(*iter)->setFocus();
}
}
void ShuttleHelper::onRight() // ->
{
QVector<QWidget*> &vec = m_shuttleQueue.last().shuttleVec;
QVector<QWidget*>::const_iterator &iter = m_shuttleQueue.last().shuttleIter;
if(!m_clickFlag)
{
m_clickFlag = true;
(*iter)->setFocus();
}
else if(m_adjustFlag) // 调节
{
ToShuttle(*iter)->ShuttleAdd();
}
else // 光标移动
{
if(vec.constEnd() - 1 == iter)
{
iter = vec.constBegin();
}
else
{
iter++;
}
(*iter)->setFocus();
}
}
void ShuttleHelper::onEnter()
{
QVector<QWidget*>::const_iterator &iter = m_shuttleQueue.last().shuttleIter;
if(!m_clickFlag)
{
m_clickFlag = true;
(*iter)->setFocus();
}
else
{
ToShuttle(*iter)->ShuttleClicked();
}
}
void ShuttleHelper::PopTopWindow()
{
m_shuttleQueue.pop_back();
SetAdjustFlag(false);
(*m_shuttleQueue.last().shuttleIter)->setFocus();
if(!m_clickFlag)
{
(*m_shuttleQueue.last().shuttleIter)->clearFocus();
}
}
void ShuttleHelper::RegeisterNewWindow(QVector<QWidget*> vec, QWidget* widget)
{
QVector<QWidget*>::const_iterator iter = vec.constBegin();
if(-1 != vec.indexOf(widget))
{
iter = vec.constBegin() + vec.indexOf(widget);
}
m_shuttleQueue.push_back(ShuttleDate{ vec, iter });
(*iter)->setFocus();
if(!m_clickFlag)
{
(*iter)->clearFocus();
}
}
void ShuttleHelper::RegeisterVoidTop() // 某些特殊情况 先创建出一个top的数据结构 使用前用Update去填充
{
QVector<QWidget*> vec;
QVector<QWidget*>::const_iterator iter = vec.constBegin();
m_shuttleQueue.push_back(ShuttleDate{ vec, iter });
}
void ShuttleHelper::UpdateTopWindow(QVector<QWidget*> vec, QWidget* widget)
{
QVector<QWidget*>::const_iterator iter = vec.constBegin();
if(-1 != vec.indexOf(widget))
{
iter = vec.constBegin() + vec.indexOf(widget);
}
m_shuttleQueue.last().shuttleVec = vec;
m_shuttleQueue.last().shuttleIter = iter;
(*iter)->setFocus();
if(!m_clickFlag)
{
(*iter)->clearFocus();
}
}
void ShuttleHelper::UpdateMainWindow(QVector<QWidget*> vec, QWidget* widget)
{
QVector<QWidget*>::const_iterator iter = vec.constBegin();
if(-1 != vec.indexOf(widget))
{
iter = vec.constBegin() + vec.indexOf(widget);
}
m_shuttleQueue.first().shuttleVec = vec;
m_shuttleQueue.first().shuttleIter = iter;
(*iter)->setFocus();
if(!m_clickFlag)
{
(*iter)->clearFocus();
}
}
void ShuttleHelper::UpdateTopWinIter(QWidget *ptr)
{
QQueue<ShuttleDate>::iterator iter = m_shuttleQueue.end()-1;
int index = iter->shuttleVec.indexOf(ptr);
if(-1 != index)
{
iter->shuttleIter = iter->shuttleVec.constBegin() + index;
}
if(m_shuttleQueue.begin() == iter)
{
m_clickFlag = false;
}
(*iter->shuttleIter)->setFocus();
(*iter->shuttleIter)->clearFocus();
}
void ShuttleHelper::SetAdjustFlag(bool flag)
{
m_adjustFlag = flag;
}
void ShuttleHelper::SetClickFlag()
{
m_clickFlag = false;
(*m_shuttleQueue.last().shuttleIter)->setFocus();
(*m_shuttleQueue.last().shuttleIter)->clearFocus();
}