玉兔远程控制 0.0.31
载入中...
搜索中...
未找到
FrmScroll.cpp
1// Author: Kang Lin <kl222@126.com>
2
3#include <QScrollBar>
4#include <QLoggingCategory>
5
6#include "FrmScroll.h"
7
8static Q_LOGGING_CATEGORY(log, "Client.FrmScroll")
9CFrmScroll::CFrmScroll(CFrmViewer *pView, QWidget *parent) : QScrollArea(parent)
10{
11 qDebug(log) << Q_FUNC_INFO;
12 setFocusPolicy(Qt::NoFocus);
13 if(pView)
14 {
15 setWidget(pView);
16 pView->show();
17 bool check = connect(pView,
18 SIGNAL(sigMouseMoveEvent(QMouseEvent*)),
19 this,
20 SLOT(slotMouseMoveEvent(QMouseEvent*)));
21 Q_ASSERT(check);
22 }
23 setAlignment(Qt::AlignCenter);
24 //setBackgroundRole(QPalette::Dark);
25 setWidgetResizable(false);
26 slotSetAdaptWindows(GetViewer()->GetAdaptWindows());
27}
28
29CFrmScroll::~CFrmScroll()
30{
31 qDebug(log) << Q_FUNC_INFO;
32}
33
34void CFrmScroll::slotSetAdaptWindows(CFrmViewer::ADAPT_WINDOWS aw)
35{
36 CFrmViewer* pView = qobject_cast<CFrmViewer*>(widget());
37 if(!pView) return;
39 {
40 if(widgetResizable())
41 setWidgetResizable(false);
42 } else {
43 if(!widgetResizable())
44 setWidgetResizable(true);
45 }
46 pView->slotSetAdaptWindows(aw);
47 return;
48}
49
50CFrmViewer::ADAPT_WINDOWS CFrmScroll::AdaptWindows()
51{
52 CFrmViewer* pView = qobject_cast<CFrmViewer*>(widget());
53 if(pView)
54 return pView->GetAdaptWindows();
55 return CFrmViewer::ADAPT_WINDOWS::Auto;
56}
57
58CFrmViewer* CFrmScroll::GetViewer()
59{
60 return qobject_cast<CFrmViewer*>(widget());
61}
62
63void CFrmScroll::slotMouseMoveEvent(QMouseEvent *event)
64{
65 int area = 10;
66 CFrmViewer* pFrmView = qobject_cast<CFrmViewer*>(sender());
67 QScrollBar* pHBar = horizontalScrollBar();
68 QScrollBar* pVBar = verticalScrollBar();
69 if(pHBar->isHidden() && pVBar->isHidden())
70 return;
71
72 int nVWidth = 0;
73 if(!pVBar->isHidden()) nVWidth = pVBar->geometry().width();
74 QPoint pos = pFrmView->mapToParent(event->pos());
75 if(pos.x() < area && pHBar->value() > pHBar->minimum())
76 pHBar->setValue(pHBar->value() - pHBar->singleStep());
77 else if(pos.x() > width() - area - nVWidth
78 && pHBar->value() < pHBar->maximum())
79 pHBar->setValue(pHBar->value() + pHBar->singleStep());
80
81 int nHHeight = 0;
82 if(!pHBar->isHidden()) nHHeight = pHBar->geometry().height();
83 if(pos.y() < area && pVBar->value() > pVBar->minimum())
84 pVBar->setValue(pVBar->value() - pVBar->singleStep());
85 else if(pos.y() > height() - area - nHHeight
86 && pVBar->value() < pVBar->maximum())
87 pVBar->setValue(pVBar->value() + pVBar->singleStep());
88}
The scroll form class
Definition FrmScroll.h:17
用于显示从 CConnectDesktop 输出的图像,和向 CConnectDesktop 发送键盘、鼠标事件。
Definition FrmViewer.h:49
ADAPT_WINDOWS
窗口适配枚举常量
Definition FrmViewer.h:61
@ Original
原始桌面大小,桌面的左上点与窗口的左上点对齐
@ Zoom
缩放窗口大小等于桌面大小 * 系数