Rabbit Remote Control 0.0.35
Loading...
Searching...
No Matches
FrmFullScreenToolBar.cpp
1// Author: Kang Lin <kl222@126.com>
2
3#include "FrmFullScreenToolBar.h"
4#include "ui_FrmFullScreenToolBar.h"
5#include "ui_mainwindow.h"
6#include "RabbitCommonDir.h"
7#include <QStyleOption>
8#include <QVBoxLayout>
9#include <QSettings>
10#include <QScreen>
11#include <QApplication>
12#include <QLoggingCategory>
13
14static Q_LOGGING_CATEGORY(log, "App.MainWindow.FullScreen")
15static Q_LOGGING_CATEGORY(logRecord, "App.MainWindow.FullScreen.Record")
16
18 QWidget(parent,
19 Qt::FramelessWindowHint
20 #ifndef WIN32
21 | Qt::X11BypassWindowManagerHint //这个标志是在x11下有用,查看帮>助QWidget::showFullScreen(),符合ICCCM协议的不需要这个
22 #endif
23 | Qt::Tool
24 | Qt::WindowStaysOnTopHint
25 | Qt::CustomizeWindowHint
26 ),
27 ui(new Ui::CFrmFullScreenToolBar),
28 m_ToolBar(this),
29 m_pConnecterMenu(nullptr),
30 m_pNail(nullptr),
31 m_pMain(pMain),
32 m_TimeOut(3000),
33 m_isHide(false)
34{
35 bool check = false;
36 setAttribute(Qt::WA_DeleteOnClose);
37 ui->setupUi(this);
38
39 setFocusPolicy(Qt::NoFocus);
40
41 QSettings set(RabbitCommon::CDir::Instance()->GetFileUserConfigure());
42 m_ToolBar.addSeparator();
43 m_pNail = m_ToolBar.addAction(QIcon::fromTheme("nail"), tr("Nail"),
44 this, SLOT(slotNail()));
45 m_pNail->setCheckable(true);
46 m_pNail->setChecked(set.value("FullScreen/Nail", true).toBool());
47 m_pNail->setToolTip(tr("Nail"));
48 m_pNail->setStatusTip(tr("Nail"));
49 m_ToolBar.addSeparator();
50 m_ToolBar.addAction(m_pMain->ui->actionFull_screen_F);
51
52 m_ToolBar.addSeparator();
53 if(m_pMain->m_pActionConnecterMenu) {
54 m_pConnecterMenu = m_pMain->m_pActionConnecterMenu;
55 m_ToolBar.addAction(m_pConnecterMenu);
56 }
57
58 m_ToolBar.addAction(m_pMain->ui->actionDisconnect_D);
59 m_ToolBar.addSeparator();
60 m_ToolBar.addAction(m_pMain->ui->actionExit_E);
61
62 m_ToolBar.show();
63
64 check = connect(&m_Timer, SIGNAL(timeout()),
65 this, SLOT(slotTimeOut()));
66 Q_ASSERT(check);
67
68 m_Timer.start(m_TimeOut);
69
70 ReToolBarSize();
71}
72
73CFrmFullScreenToolBar::~CFrmFullScreenToolBar()
74{
75 qDebug(log) << "CFrmFullScreenToolBar::~CFrmFullScreenToolBar()";
76
77 m_Timer.stop();
78 delete ui;
79}
80
81void CFrmFullScreenToolBar::mouseMoveEvent(QMouseEvent *event)
82{
83 if(Qt::LeftButton != event->buttons())
84 return;
85
86 QPointF p = event->pos();
87 move(x() + (p.x() - m_Pos.x()), y() + (p.y() - m_Pos.y()));
88}
89
90void CFrmFullScreenToolBar::mousePressEvent(QMouseEvent *event)
91{
92 m_Pos = event->pos();
93}
94
95int CFrmFullScreenToolBar::ReToolBarSize()
96{
97 int marginW = style()->pixelMetric(
98 QStyle::PM_FocusFrameHMargin) << 1;
99 int marginH = style()->pixelMetric(
100 QStyle::PM_FocusFrameVMargin) << 1;
101 QMargins cm = contentsMargins();
102
103 QSize size = m_ToolBar.frameSize();
104
105 resize(marginW + cm.left() + cm.right() + size.width(),
106 marginH + cm.top() + cm.bottom() + size.height());
107
108 if(frameGeometry().top() > m_pMain->frameGeometry().height() >> 1)
109 move(frameGeometry().left(),
110 m_pMain->frameGeometry().height() - frameGeometry().height());
111 return 0;
112}
113
114void CFrmFullScreenToolBar::slotTimeOut()
115{
116 int area = 5;
117 if(m_isHide) return;
118
119 if(m_pNail->isChecked()) return;
120
121 m_isHide = true;
122 m_Timer.stop();
123 m_ToolBar.hide();
124 resize(width(), area);
125
126 int h = m_pMain->frameGeometry().height() >> 1;
127 if(frameGeometry().top() < h)
128 move(frameGeometry().left(), 0);
129 else
130 move(frameGeometry().left(), m_pMain->frameGeometry().height() - area);
131}
132
133#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
134void CFrmFullScreenToolBar::enterEvent(QEnterEvent *event)
135#else
136void CFrmFullScreenToolBar::enterEvent(QEvent *event)
137#endif
138{
139 Q_UNUSED(event);
140 m_Timer.stop();
141 if(m_isHide)
142 {
143 m_ToolBar.show();
144 ReToolBarSize();
145 m_isHide = false;
146 }
147}
148
149void CFrmFullScreenToolBar::leaveEvent(QEvent *event)
150{
151 Q_UNUSED(event);
152 if(m_pNail->isChecked()) return;
153 m_Timer.stop();
154 m_Timer.start(m_TimeOut);
155}
156
157void CFrmFullScreenToolBar::slotNail()
158{
159 QSettings set(RabbitCommon::CDir::Instance()->GetFileUserConfigure());
160 set.setValue("FullScreen/Nail", m_pNail->isChecked());
161}
162
163void CFrmFullScreenToolBar::slotConnecterMenuChanged(QAction* pAction)
164{
165 if(m_pConnecterMenu) {
166 m_ToolBar.removeAction(m_pConnecterMenu);
167 m_pConnecterMenu = pAction;
168 m_ToolBar.insertAction(m_pMain->ui->actionDisconnect_D, m_pConnecterMenu);
169 }
170}
The MainWindow class.
Definition mainwindow.h:33