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
Aug 21, 2019
by
abbycin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add popup
parent
01a90d3c
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 @@
#include <QApplication>
#include <QPushButton>
#include <QMessageBox>
#include <QTimer>
#include "popup.h"
MainWindow
::
MainWindow
(
QWidget
*
parent
)
:
QMainWindow
(
parent
),
mEdit
{},
mHide
{},
mFull
{}
:
QMainWindow
(
parent
),
mEdit
{},
mHide
{},
mFull
{}
,
mPopup
{}
{
auto
menu
=
this
->
menuBar
();
auto
preference
=
menu
->
addAction
(
"Preference"
);
...
...
@@ -42,6 +44,8 @@ void MainWindow::showEditor()
void
MainWindow
::
initEditor
()
{
mPopup
=
new
PopUp
{
this
};
mEdit
=
new
QWidget
{};
QLabel
*
hide
=
new
QLabel
{};
hide
->
setText
(
"hide/show"
);
...
...
@@ -89,7 +93,7 @@ void MainWindow::initEditor()
}
});
connect
(
mHide
,
&
KeyEdit
::
error
,
[
this
](
QString
msg
)
{
QMessageBox
::
critical
(
this
,
"Error"
,
msg
);
this
->
showPopUp
(
msg
);
mHide
->
clear
();
});
connect
(
mFull
,
&
KeyEdit
::
actived
,
[
this
]
{
...
...
@@ -103,7 +107,7 @@ void MainWindow::initEditor()
}
});
connect
(
mFull
,
&
KeyEdit
::
error
,
[
this
](
QString
msg
)
{
QMessageBox
::
critical
(
this
,
"Error"
,
msg
);
this
->
showPopUp
(
msg
);
});
mEdit
->
setLayout
(
g
);
...
...
@@ -111,13 +115,21 @@ void MainWindow::initEditor()
mEdit
->
hide
();
#ifdef Q_OS_WIN
// test conflit with QQ
mHide
->
setKey
(
QKeySequence
::
fromString
(
"Ctrl+Alt+A"
));
QTimer
::
singleShot
(
1000
,
[
this
]
{
mHide
->
setKey
(
QKeySequence
::
fromString
(
"Ctrl+Alt+A"
));
});
#else
// test conflit with search
mHide
->
setKey
(
QKeySequence
::
fromString
(
"Alt+Space"
));
#endif
}
void
MainWindow
::
showPopUp
(
QString
msg
)
{
mPopup
->
setPopupText
(
msg
);
mPopup
->
show
();
}
KeyEdit
::
KeyEdit
(
QWidget
*
parent
)
:
QKeySequenceEdit
{
parent
}
{
...
...
test/mainwindow.h
View file @
9e12e2bc
...
...
@@ -5,6 +5,7 @@
#include <QKeySequenceEdit>
class
QGlobalShortcut
;
class
PopUp
;
class
KeyEdit
:
public
QKeySequenceEdit
{
...
...
@@ -40,8 +41,11 @@ private:
QWidget
*
mEdit
;
KeyEdit
*
mHide
;
KeyEdit
*
mFull
;
PopUp
*
mPopup
;
void
initEditor
();
void
showPopUp
(
QString
msg
);
};
#endif // MAINWINDOW_H
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
();
}
}
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
test/test.pro
View file @
9e12e2bc
...
...
@@ -16,8 +16,10 @@ DESTDIR = $$PWD/../dest
INCLUDEPATH
+=
$$
PWD
/../
lib
SOURCES
+=
main
.
cpp
\
mainwindow
.
cpp
mainwindow
.
cpp
\
popup
.
cpp
HEADERS
+=
mainwindow
.
h
HEADERS
+=
mainwindow
.
h
\
popup
.
h
LIBS
+=
-
L
$$
PWD
/../
dest
-
lghk
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