Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Q
qglobalshortcut
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abby Cin
qglobalshortcut
Commits
9e12e2bc
Commit
9e12e2bc
authored
5 years ago
by
abbycin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add popup
parent
01a90d3c
master
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
172 additions
and
6 deletions
+172
-6
mainwindow.cpp
test/mainwindow.cpp
+16
-4
mainwindow.h
test/mainwindow.h
+4
-0
popup.cpp
test/popup.cpp
+108
-0
popup.h
test/popup.h
+40
-0
test.pro
test/test.pro
+4
-2
No files found.
test/mainwindow.cpp
View file @
9e12e2bc
...
@@ -12,9 +12,11 @@
...
@@ -12,9 +12,11 @@
#include <QApplication>
#include <QApplication>
#include <QPushButton>
#include <QPushButton>
#include <QMessageBox>
#include <QMessageBox>
#include <QTimer>
#include "popup.h"
MainWindow
::
MainWindow
(
QWidget
*
parent
)
MainWindow
::
MainWindow
(
QWidget
*
parent
)
:
QMainWindow
(
parent
),
mEdit
{},
mHide
{},
mFull
{}
:
QMainWindow
(
parent
),
mEdit
{},
mHide
{},
mFull
{}
,
mPopup
{}
{
{
auto
menu
=
this
->
menuBar
();
auto
menu
=
this
->
menuBar
();
auto
preference
=
menu
->
addAction
(
"Preference"
);
auto
preference
=
menu
->
addAction
(
"Preference"
);
...
@@ -42,6 +44,8 @@ void MainWindow::showEditor()
...
@@ -42,6 +44,8 @@ void MainWindow::showEditor()
void
MainWindow
::
initEditor
()
void
MainWindow
::
initEditor
()
{
{
mPopup
=
new
PopUp
{
this
};
mEdit
=
new
QWidget
{};
mEdit
=
new
QWidget
{};
QLabel
*
hide
=
new
QLabel
{};
QLabel
*
hide
=
new
QLabel
{};
hide
->
setText
(
"hide/show"
);
hide
->
setText
(
"hide/show"
);
...
@@ -89,7 +93,7 @@ void MainWindow::initEditor()
...
@@ -89,7 +93,7 @@ void MainWindow::initEditor()
}
}
});
});
connect
(
mHide
,
&
KeyEdit
::
error
,
[
this
](
QString
msg
)
{
connect
(
mHide
,
&
KeyEdit
::
error
,
[
this
](
QString
msg
)
{
QMessageBox
::
critical
(
this
,
"Error"
,
msg
);
this
->
showPopUp
(
msg
);
mHide
->
clear
();
mHide
->
clear
();
});
});
connect
(
mFull
,
&
KeyEdit
::
actived
,
[
this
]
{
connect
(
mFull
,
&
KeyEdit
::
actived
,
[
this
]
{
...
@@ -103,7 +107,7 @@ void MainWindow::initEditor()
...
@@ -103,7 +107,7 @@ void MainWindow::initEditor()
}
}
});
});
connect
(
mFull
,
&
KeyEdit
::
error
,
[
this
](
QString
msg
)
{
connect
(
mFull
,
&
KeyEdit
::
error
,
[
this
](
QString
msg
)
{
QMessageBox
::
critical
(
this
,
"Error"
,
msg
);
this
->
showPopUp
(
msg
);
});
});
mEdit
->
setLayout
(
g
);
mEdit
->
setLayout
(
g
);
...
@@ -111,13 +115,21 @@ void MainWindow::initEditor()
...
@@ -111,13 +115,21 @@ void MainWindow::initEditor()
mEdit
->
hide
();
mEdit
->
hide
();
#ifdef Q_OS_WIN
#ifdef Q_OS_WIN
// test conflit with QQ
// test conflit with QQ
mHide
->
setKey
(
QKeySequence
::
fromString
(
"Ctrl+Alt+A"
));
QTimer
::
singleShot
(
1000
,
[
this
]
{
mHide
->
setKey
(
QKeySequence
::
fromString
(
"Ctrl+Alt+A"
));
});
#else
#else
// test conflit with search
// test conflit with search
mHide
->
setKey
(
QKeySequence
::
fromString
(
"Alt+Space"
));
mHide
->
setKey
(
QKeySequence
::
fromString
(
"Alt+Space"
));
#endif
#endif
}
}
void
MainWindow
::
showPopUp
(
QString
msg
)
{
mPopup
->
setPopupText
(
msg
);
mPopup
->
show
();
}
KeyEdit
::
KeyEdit
(
QWidget
*
parent
)
KeyEdit
::
KeyEdit
(
QWidget
*
parent
)
:
QKeySequenceEdit
{
parent
}
:
QKeySequenceEdit
{
parent
}
{
{
...
...
This diff is collapsed.
Click to expand it.
test/mainwindow.h
View file @
9e12e2bc
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include <QKeySequenceEdit>
#include <QKeySequenceEdit>
class
QGlobalShortcut
;
class
QGlobalShortcut
;
class
PopUp
;
class
KeyEdit
:
public
QKeySequenceEdit
class
KeyEdit
:
public
QKeySequenceEdit
{
{
...
@@ -40,8 +41,11 @@ private:
...
@@ -40,8 +41,11 @@ private:
QWidget
*
mEdit
;
QWidget
*
mEdit
;
KeyEdit
*
mHide
;
KeyEdit
*
mHide
;
KeyEdit
*
mFull
;
KeyEdit
*
mFull
;
PopUp
*
mPopup
;
void
initEditor
();
void
initEditor
();
void
showPopUp
(
QString
msg
);
};
};
#endif // MAINWINDOW_H
#endif // MAINWINDOW_H
This diff is collapsed.
Click to expand it.
test/popup.cpp
0 → 100644
View file @
9e12e2bc
#include "popup.h"
#include <QLabel>
#include <QGridLayout>
#include <QPropertyAnimation>
#include <QTimer>
#include <QApplication>
#include <QDesktopWidget>
#include <QPainter>
#include <QRect>
PopUp
::
PopUp
(
QWidget
*
parent
)
:
QWidget
{
parent
}
{
mLabel
=
new
QLabel
{};
mLayout
=
new
QGridLayout
{
this
};
mAnimation
=
new
QPropertyAnimation
{
this
};
mTimer
=
new
QTimer
{
this
};
setWindowFlags
(
Qt
::
FramelessWindowHint
|
Qt
::
Tool
|
Qt
::
WindowStaysOnTopHint
);
setAttribute
(
Qt
::
WA_TranslucentBackground
);
setAttribute
(
Qt
::
WA_ShowWithoutActivating
);
mAnimation
->
setTargetObject
(
this
);
mAnimation
->
setPropertyName
(
"popUpOpacity"
);
connect
(
mAnimation
,
&
QAbstractAnimation
::
finished
,
this
,
&
PopUp
::
hide
);
mLabel
->
setAlignment
(
Qt
::
AlignHCenter
|
Qt
::
AlignVCenter
);
mLabel
->
setStyleSheet
(
"QLabel { color : white; "
"margin-top: 10px;"
"margin-bottom: 10px;"
"margin-left: 10px;"
"margin-right: 10px; }"
);
mLayout
->
addWidget
(
mLabel
,
0
,
0
);
setLayout
(
mLayout
);
connect
(
mTimer
,
&
QTimer
::
timeout
,
this
,
&
PopUp
::
hideAnimation
);
}
void
PopUp
::
setOpacity
(
float
opacity
)
{
mOpacity
=
opacity
;
setWindowOpacity
(
opacity
);
}
float
PopUp
::
opacity
()
const
{
return
mOpacity
;
}
void
PopUp
::
paintEvent
(
QPaintEvent
*
event
)
{
Q_UNUSED
(
event
)
QPainter
painter
(
this
);
painter
.
setRenderHint
(
QPainter
::
Antialiasing
);
QRect
roundedRect
;
roundedRect
.
setX
(
rect
().
x
()
+
5
);
roundedRect
.
setY
(
rect
().
y
()
+
5
);
roundedRect
.
setWidth
(
rect
().
width
()
-
10
);
roundedRect
.
setHeight
(
rect
().
height
()
-
10
);
painter
.
setBrush
(
QBrush
(
QColor
(
0
,
0
,
0
,
180
)));
painter
.
setPen
(
Qt
::
NoPen
);
painter
.
drawRoundedRect
(
roundedRect
,
10
,
10
);
}
void
PopUp
::
setPopupText
(
const
QString
&
text
)
{
mLabel
->
setText
(
text
);
this
->
adjustSize
();
}
void
PopUp
::
show
()
{
setWindowOpacity
(
0.0
);
mAnimation
->
setDuration
(
150
);
mAnimation
->
setStartValue
(
0.0
);
mAnimation
->
setEndValue
(
1.0
);
auto
geo
=
QApplication
::
desktop
()
->
availableGeometry
();
setGeometry
(
geo
.
width
()
-
30
-
width
()
+
geo
.
x
(),
geo
.
height
()
-
30
-
height
()
+
geo
.
y
(),
width
(),
height
());
QWidget
::
show
();
mAnimation
->
start
();
mTimer
->
start
(
3000
);
}
void
PopUp
::
hideAnimation
()
{
mTimer
->
stop
();
mAnimation
->
setDuration
(
1000
);
mAnimation
->
setStartValue
(
1.0
);
mAnimation
->
setEndValue
(
0.0
);
mAnimation
->
start
();
}
void
PopUp
::
hide
()
{
if
(
mOpacity
<
0.01
)
{
QWidget
::
hide
();
}
}
This diff is collapsed.
Click to expand it.
test/popup.h
0 → 100644
View file @
9e12e2bc
#ifndef POPUP_H
#define POPUP_H
#include <QWidget>
class
QLabel
;
class
QGridLayout
;
class
QPropertyAnimation
;
class
QTimer
;
class
PopUp
:
public
QWidget
{
Q_OBJECT
Q_PROPERTY
(
float
popUpOpacity
READ
opacity
WRITE
setOpacity
)
public
:
explicit
PopUp
(
QWidget
*
parent
=
0
);
void
setOpacity
(
float
opacity
);
float
opacity
()
const
;
protected
:
void
paintEvent
(
QPaintEvent
*
event
);
public
slots
:
void
setPopupText
(
const
QString
&
text
);
void
show
();
private
slots
:
void
hideAnimation
();
void
hide
();
private
:
QLabel
*
mLabel
{
nullptr
};
QGridLayout
*
mLayout
{
nullptr
};
QPropertyAnimation
*
mAnimation
{
nullptr
};
QTimer
*
mTimer
{
nullptr
};
float
mOpacity
{
0
.
5
};
};
#endif // POPUP_H
This diff is collapsed.
Click to expand it.
test/test.pro
View file @
9e12e2bc
...
@@ -16,8 +16,10 @@ DESTDIR = $$PWD/../dest
...
@@ -16,8 +16,10 @@ DESTDIR = $$PWD/../dest
INCLUDEPATH
+=
$$
PWD
/../
lib
INCLUDEPATH
+=
$$
PWD
/../
lib
SOURCES
+=
main
.
cpp
\
SOURCES
+=
main
.
cpp
\
mainwindow
.
cpp
mainwindow
.
cpp
\
popup
.
cpp
HEADERS
+=
mainwindow
.
h
HEADERS
+=
mainwindow
.
h
\
popup
.
h
LIBS
+=
-
L
$$
PWD
/../
dest
-
lghk
LIBS
+=
-
L
$$
PWD
/../
dest
-
lghk
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment