Rabbit Remote Control 0.0.30
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 //m_ToolBar.addAction(m_pMain->ui->actionTabBar_B);
58 m_pShowTabBar = m_ToolBar.addAction(QIcon::fromTheme("tabbar"), tr("TabBar"),
59 this, SLOT(slotShowTabBar()));
60 m_pShowTabBar->setCheckable(true);
61 m_pShowTabBar->setStatusTip(tr("Tab bar"));
62 m_pShowTabBar->setToolTip(tr("Tab bar"));
63
64 m_ToolBar.addAction(m_pMain->ui->actionDisconnect_D);
65 m_ToolBar.addSeparator();
66 m_ToolBar.addAction(m_pMain->ui->actionExit_E);
67
68 m_ToolBar.show();
69
70 check = connect(&m_Timer, SIGNAL(timeout()),
71 this, SLOT(slotTimeOut()));
72 Q_ASSERT(check);
73
74 m_Timer.start(m_TimeOut);
75
76 ReToolBarSize();
77}
78
79CFrmFullScreenToolBar::~CFrmFullScreenToolBar()
80{
81 qDebug(log) << "CFrmFullScreenToolBar::~CFrmFullScreenToolBar()";
82
83 m_Timer.stop();
84 delete ui;
85}
86
87void CFrmFullScreenToolBar::mouseMoveEvent(QMouseEvent *event)
88{
89 if(Qt::LeftButton != event->buttons())
90 return;
91
92 QPointF p = event->pos();
93 move(x() + (p.x() - m_Pos.x()), y() + (p.y() - m_Pos.y()));
94}
95
96void CFrmFullScreenToolBar::mousePressEvent(QMouseEvent *event)
97{
98 m_Pos = event->pos();
99}
100
101int CFrmFullScreenToolBar::ReToolBarSize()
102{
103 int marginW = style()->pixelMetric(
104 QStyle::PM_FocusFrameHMargin) << 1;
105 int marginH = style()->pixelMetric(
106 QStyle::PM_FocusFrameVMargin) << 1;
107 QMargins cm = contentsMargins();
108
109 QSize size = m_ToolBar.frameSize();
110
111 resize(marginW + cm.left() + cm.right() + size.width(),
112 marginH + cm.top() + cm.bottom() + size.height());
113
114 if(frameGeometry().top() > m_pMain->frameGeometry().height() >> 1)
115 move(frameGeometry().left(),
116 m_pMain->frameGeometry().height() - frameGeometry().height());
117 return 0;
118}
119
120void CFrmFullScreenToolBar::slotTimeOut()
121{
122 int area = 5;
123 if(m_isHide) return;
124
125 if(m_pNail->isChecked()) return;
126
127 m_isHide = true;
128 m_Timer.stop();
129 m_ToolBar.hide();
130 resize(width(), area);
131
132 int h = m_pMain->frameGeometry().height() >> 1;
133 if(frameGeometry().top() < h)
134 move(frameGeometry().left(), 0);
135 else
136 move(frameGeometry().left(), m_pMain->frameGeometry().height() - area);
137}
138
139#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
140void CFrmFullScreenToolBar::enterEvent(QEnterEvent *event)
141#else
142void CFrmFullScreenToolBar::enterEvent(QEvent *event)
143#endif
144{
145 Q_UNUSED(event);
146 m_Timer.stop();
147 if(m_isHide)
148 {
149 m_ToolBar.show();
150 ReToolBarSize();
151 m_isHide = false;
152 }
153}
154
155void CFrmFullScreenToolBar::leaveEvent(QEvent *event)
156{
157 Q_UNUSED(event);
158 if(m_pNail->isChecked()) return;
159 m_Timer.stop();
160 m_Timer.start(m_TimeOut);
161}
162
163void CFrmFullScreenToolBar::slotShowTabBar()
164{
165 emit sigShowTabBar(m_pShowTabBar->isChecked());
166}
167
168void CFrmFullScreenToolBar::slotNail()
169{
170 QSettings set(RabbitCommon::CDir::Instance()->GetFileUserConfigure());
171 set.setValue("FullScreen/Nail", m_pNail->isChecked());
172}
173
174void CFrmFullScreenToolBar::slotConnecterMenuChanged(QAction* pAction)
175{
176 if(m_pConnecterMenu) {
177 m_ToolBar.removeAction(m_pConnecterMenu);
178 m_pConnecterMenu = pAction;
179 m_ToolBar.insertAction(m_pShowTabBar, m_pConnecterMenu);
180 }
181}
The MainWindow class.
Definition mainwindow.h:32