玉兔远程控制 0.1.0-bate11
载入中...
搜索中...
未找到
FrmFullScreenToolBar.cpp
1// Author: Kang Lin <kl222@126.com>
2
3#include <QStyleOption>
4#include <QVBoxLayout>
5#include <QSettings>
6#include <QScreen>
7#include <QApplication>
8#include <QLoggingCategory>
9#include <QPalette>
10
11#include "RabbitCommonDir.h"
12#include "RabbitCommonTools.h"
13#include "FrmFullScreenToolBar.h"
14#include "ui_FrmFullScreenToolBar.h"
15#include "ui_mainwindow.h"
16
17static Q_LOGGING_CATEGORY(log, "App.MainWindow.FullScreen")
18
20 QWidget(parent),
22 m_ToolBar(this),
23 m_pOperateMenu(nullptr),
24 m_pNail(nullptr),
25 m_pMain(qobject_cast<MainWindow*>(parent)),
26 m_TimeOut(3000),
27 m_isHide(false)
28{
29 bool check = false;
30 Q_ASSERT(m_pMain);
31
32 setAttribute(Qt::WA_DeleteOnClose);
33 setAttribute(Qt::WA_ShowWithoutActivating);
34 setAutoFillBackground(true);
35 setAttribute(Qt::WA_TranslucentBackground, false);
36
37 Qt::WindowFlags flags;
38 flags = Qt::WindowStaysOnTopHint
39#ifndef WIN32
40 | Qt::X11BypassWindowManagerHint //这个标志是在x11下有用,查看帮助QWidget::showFullScreen(),符合ICCCM协
41#endif
42 | Qt::FramelessWindowHint
43 | Qt::CustomizeWindowHint;
44 if(-1 == QGuiApplication::platformName().indexOf(QRegularExpression("wayland.*"))) {
45 flags |= Qt::Tool;
46 }
47 setWindowFlags(flags);
48
49 ui->setupUi(this);
50
51 QSettings set(RabbitCommon::CDir::Instance()->GetFileUserConfigure());
52 m_ToolBar.addSeparator();
53 m_pNail = m_ToolBar.addAction(QIcon::fromTheme("nail"), tr("Nail"),
54 this, SLOT(slotNail()));
55 m_pNail->setCheckable(true);
56 m_pNail->setChecked(set.value("FullScreen/Nail", true).toBool());
57 m_pNail->setToolTip(tr("Nail"));
58 m_pNail->setStatusTip(tr("Nail"));
59 m_ToolBar.addSeparator();
60 m_ToolBar.addAction(m_pMain->ui->actionFull_screen_F);
61
62 m_ToolBar.addSeparator();
63 if(m_pMain->m_pActionOperateMenu) {
64 m_pOperateMenu = m_pMain->m_pActionOperateMenu;
65 m_ToolBar.addAction(m_pOperateMenu);
66 }
67
68 m_ToolBar.addAction(m_pMain->ui->actionStop);
69 m_ToolBar.addSeparator();
70 m_ToolBar.addAction(m_pMain->ui->actionExit_E);
71
72 m_ToolBar.show();
73
74 check = connect(&m_Timer, SIGNAL(timeout()),
75 this, SLOT(slotTimeOut()));
76 Q_ASSERT(check);
77
78 m_Timer.start(m_TimeOut);
79 ReToolBarSize();
80}
81
82CFrmFullScreenToolBar::~CFrmFullScreenToolBar()
83{
84 qDebug(log) << "CFrmFullScreenToolBar::~CFrmFullScreenToolBar()";
85
86 m_Timer.stop();
87 delete ui;
88}
89
90void CFrmFullScreenToolBar::mouseMoveEvent(QMouseEvent *event)
91{
92 if(Qt::LeftButton != event->buttons())
93 return;
94
95 QPointF p = event->pos();
96 move(x() + (p.x() - m_Pos.x()), y() + (p.y() - m_Pos.y()));
97}
98
99void CFrmFullScreenToolBar::mousePressEvent(QMouseEvent *event)
100{
101 m_Pos = event->pos();
102}
103
104int CFrmFullScreenToolBar::ReToolBarSize()
105{
106 QPalette palette = this->palette();
107 palette.setColor(QPalette::Window,
108 m_pMain->palette().color(QPalette::Window));
109 this->setPalette(palette);
110
111 int marginW = style()->pixelMetric(
112 QStyle::PM_FocusFrameHMargin) << 1;
113 int marginH = style()->pixelMetric(
114 QStyle::PM_FocusFrameVMargin) << 1;
115 QMargins cm = contentsMargins();
116
117 QSize size = m_ToolBar.frameSize();
118
119 resize(marginW + cm.left() + cm.right() + size.width(),
120 marginH + cm.top() + cm.bottom() + size.height());
121
122 if(frameGeometry().top() > m_pMain->frameGeometry().height() >> 1)
123 move(frameGeometry().left(),
124 m_pMain->frameGeometry().height() - frameGeometry().height());
125
126 this->raise();
127 qDebug(log) << Q_FUNC_INFO << "frameGeometry:" << frameGeometry()
128 << "main window frameGeometry:" << m_pMain->frameGeometry();
129
130 return 0;
131}
132
133void CFrmFullScreenToolBar::slotTimeOut()
134{
135 int area = 5;
136 if(m_isHide) return;
137
138 if(m_pNail->isChecked()) return;
139
140 QPalette palette = this->palette();
141 palette.setColor(QPalette::Window,
142 RabbitCommon::CTools::InvertColor(palette.color(QPalette::Window)));
143 this->setPalette(palette);
144
145 m_isHide = true;
146 m_Timer.stop();
147 m_ToolBar.hide();
148 resize(width(), area);
149
150 int h = m_pMain->frameGeometry().height() >> 1;
151 if(frameGeometry().top() < h)
152 move(frameGeometry().left(), 0);
153 else
154 move(frameGeometry().left(), m_pMain->frameGeometry().height() - area);
155
156 this->raise();
157 qDebug(log) << Q_FUNC_INFO << "frameGeometry:" << frameGeometry()
158 << "main window frameGeometry:" << m_pMain->frameGeometry();
159}
160
161#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
162void CFrmFullScreenToolBar::enterEvent(QEnterEvent *event)
163#else
164void CFrmFullScreenToolBar::enterEvent(QEvent *event)
165#endif
166{
167 Q_UNUSED(event);
168 m_Timer.stop();
169 if(m_isHide)
170 {
171 m_ToolBar.show();
172 ReToolBarSize();
173 m_isHide = false;
174 }
175}
176
177void CFrmFullScreenToolBar::leaveEvent(QEvent *event)
178{
179 Q_UNUSED(event);
180 if(m_pNail->isChecked()) return;
181 m_Timer.stop();
182 m_Timer.start(m_TimeOut);
183}
184
185void CFrmFullScreenToolBar::slotNail()
186{
187 QSettings set(RabbitCommon::CDir::Instance()->GetFileUserConfigure());
188 set.setValue("FullScreen/Nail", m_pNail->isChecked());
189}
190
191void CFrmFullScreenToolBar::slotOperateMenuChanged(QAction* pAction)
192{
193 if(m_pOperateMenu) {
194 m_ToolBar.removeAction(m_pOperateMenu);
195 m_pOperateMenu = pAction;
196 m_ToolBar.insertAction(m_pMain->ui->actionStop, m_pOperateMenu);
197 }
198}
The MainWindow class