54 lines
1.7 KiB
C++
Executable File
54 lines
1.7 KiB
C++
Executable File
/*****************************************************************
|
||
* @file FocusWindow.h
|
||
* @brief 让qt窗体焦点能够上下左右移动的类,内部实现全部来自android源码焦点移动部分。
|
||
* 在使用的时候需要继承这个类即可并重写getAllFocusabelWidget方法。
|
||
* @author luoxiang
|
||
* @date May 23 2024
|
||
****************************************************************/
|
||
#include <qwidget.h>
|
||
#ifndef FOCUS_WINDOW_H
|
||
#define FOCUS_WINDOW_H
|
||
|
||
namespace FW
|
||
{
|
||
class FocusWindow
|
||
{
|
||
public:
|
||
// 焦点移动方向
|
||
enum Direction
|
||
{
|
||
Up,
|
||
Down,
|
||
Left,
|
||
Right
|
||
};
|
||
void focusNext(Direction direction);
|
||
|
||
protected:
|
||
// 纯虚函数,让子类重写以获取当前窗体的所有可以获得焦点的控件。
|
||
virtual QList<QWidget*> getAllFocusabelWidget() = 0;
|
||
|
||
private:
|
||
QList<QWidget*> focusableList;
|
||
|
||
private:
|
||
// 与焦点移动相关的函数
|
||
QWidget* getNextFocusWidget(Direction direction);
|
||
bool isCandidate(QRect focused, QRect focusable, Direction direction);
|
||
bool isBetterCandidate(Direction direction, QRect focused, QRect focusable, QRect curCandidate);
|
||
bool beamBeats(Direction dircetion, QRect source, QRect rect1, QRect rect2);
|
||
bool beamsOverlap(Direction direction, QRect rect1, QRect rect2);
|
||
bool isToDirectionOf(Direction direction, QRect source, QRect dest);
|
||
int majorAxisDistance(Direction direction, QRect source, QRect dest);
|
||
int majorAxisDistanceRaw(Direction direction, QRect source, QRect dest);
|
||
int minorAxisDistance(Direction direction, QRect source, QRect dest);
|
||
int getWeightDistanceFor(int majorAxisDistance, int minorAxisDistance);
|
||
int majorAxisDistanceToFarEdge(Direction dircetion, QRect source, QRect dest);
|
||
int majorAxisDistanceToFarEdgeRaw(Direction dircetion, QRect source, QRect dest);
|
||
};
|
||
}
|
||
|
||
#endif // !FOCUS_WINDOW_H
|
||
|
||
|