Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
jlib
Commits
48fadc2a
Commit
48fadc2a
authored
Apr 13, 2020
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update and fix
parent
8a337d1c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
13 deletions
+36
-13
log2.h
jlib/log2.h
+1
-1
QtUtils.h
jlib/qt/QtUtils.h
+26
-3
monitor.h
jlib/qt/monitor.h
+7
-7
rect.h
jlib/win32/rect.h
+2
-2
No files found.
jlib/log2.h
View file @
48fadc2a
...
...
@@ -75,7 +75,7 @@ file_name)
file_name
,
23
,
59
));
auto
combined_logger
=
std
::
make_shared
<
spdlog
::
logger
>
(
g_logger_name
,
begin
(
sinks
),
end
(
sinks
));
combined_logger
->
set_pattern
(
"[%Y-%m-%d %H:%M:%S.%e] [
tid
%t] [%L] %v"
);
combined_logger
->
set_pattern
(
"[%Y-%m-%d %H:%M:%S.%e] [%t] [%L] %v"
);
spdlog
::
register_logger
(
combined_logger
);
combined_logger
->
flush_on
(
spdlog
::
level
::
trace
);
}
catch
(
const
spdlog
::
spdlog_ex
&
ex
)
{
...
...
jlib/qt/QtUtils.h
View file @
48fadc2a
...
...
@@ -13,21 +13,43 @@
#include <QProcess>
#include "QtDebug.h"
#include "QtPathHelper.h"
#include <thread>
#include <chrono>
JLIBQT_NAMESPACE_BEGIN
/**
* @brief 阻塞等待一段时间
* @param ms 等待的毫秒数
*/
static
inline
void
blocking_wait
(
int
ms
,
QString
log
=
""
)
{
if
(
!
log
.
isEmpty
())
{
MYQDEBUG
<<
log
<<
"in"
;
}
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
ms
));
if
(
!
log
.
isEmpty
())
{
MYQDEBUG
<<
log
<<
"out"
;
}
}
/**
* @brief 不阻塞UI响应的情况下,等待一段时间
* @param ms 等待的毫秒数
*/
static
inline
void
non_blocking_wait_in_ui_thread
(
int
ms
)
{
static
inline
void
non_blocking_wait_in_ui_thread
(
int
ms
,
QString
log
=
""
)
{
if
(
!
log
.
isEmpty
())
{
MYQDEBUG
<<
log
<<
"in"
;
}
QEventLoop
q
;
QTimer
t
;
t
.
setSingleShot
(
true
);
QObject
::
connect
(
&
t
,
&
QTimer
::
timeout
,
&
q
,
&
QEventLoop
::
quit
);
t
.
start
(
ms
);
q
.
exec
();
if
(
!
log
.
isEmpty
())
{
MYQDEBUG
<<
log
<<
"out"
;
}
}
/**
...
...
@@ -43,13 +65,13 @@ static inline void showInGraphicalShell(const QString &pathIn) {
QProcess
::
startDetached
(
command
);
}
static
inline
bool
warn_if_load_pixmap_failed
(
QPixmap
&
pixmap
,
QString
icon_path
,
QString
file_line
)
static
inline
bool
warn_if_load_pixmap_failed
(
QPixmap
&
pixmap
,
QString
icon_path
,
QString
file_line
,
bool
forceUseQss
=
true
)
{
/*if (!QDir().isAbsolutePath(icon_path)) {
icon_path = PathHelper::program() + "/" + icon_path;
}*/
if
(
!
icon_path
.
startsWith
(
":/"
))
{
if
(
forceUseQss
&&
!
icon_path
.
startsWith
(
":/"
))
{
icon_path
=
":/"
+
icon_path
;
}
...
...
@@ -62,6 +84,7 @@ static inline bool warn_if_load_pixmap_failed(QPixmap& pixmap, QString icon_path
}
#define LOAD_PIXMAP_EX(icon_path) JLIBQT_NAMESPACE warn_if_load_pixmap_failed(pixmap, icon_path, JLIBQT_QDEBUG_FILE_LINE_VALUE)
#define LOAD_PIXMAP_EX2(icon_path) JLIBQT_NAMESPACE warn_if_load_pixmap_failed(pixmap, icon_path, JLIBQT_QDEBUG_FILE_LINE_VALUE, false)
static
QIcon
icon_from_path
(
QString
path
,
QSize
icon_sz
)
{
QPixmap
pixmap
;
...
...
jlib/qt/monitor.h
View file @
48fadc2a
...
...
@@ -243,12 +243,12 @@ static void test_monitor()
static
void
setExtendMode
()
{
auto
ret
=
SetDisplayConfig
(
0
,
NULL
,
0
,
NULL
,
SDC_TOPOLOGY_EXTEND
|
SDC_APPLY
);
MYQDEBUG
<<
"SetDisplayConfig SDC_TOPOLOGY_EXTEND returns:"
<<
ret
;
MYQDEBUG
<<
"SetDisplayConfig SDC_TOPOLOGY_EXTEND returns:"
<<
(
ret
==
ERROR_SUCCESS
)
;
}
static
void
setCloneMode
()
{
auto
ret
=
SetDisplayConfig
(
0
,
NULL
,
0
,
NULL
,
SDC_TOPOLOGY_CLONE
|
SDC_APPLY
);
MYQDEBUG
<<
"SetDisplayConfig SDC_TOPOLOGY_CLONE returns:"
<<
ret
;
MYQDEBUG
<<
"SetDisplayConfig SDC_TOPOLOGY_CLONE returns:"
<<
(
ret
==
ERROR_SUCCESS
)
;
}
//void setOnlyDisplayInMainMonitor() {
...
...
@@ -263,7 +263,7 @@ static void setCloneMode() {
static
void
commitChange
()
{
auto
ret
=
ChangeDisplaySettingsExW
(
NULL
,
NULL
,
NULL
,
0
,
NULL
);
MYQDEBUG
<<
"commitChange ChangeDisplaySettingsExW returns:"
<<
ret
;
MYQDEBUG
<<
"commitChange ChangeDisplaySettingsExW returns:"
<<
(
ret
==
ERROR_SUCCESS
)
;
};
static
void
disableMonitor
(
const
MonitorInfo
&
m
)
{
...
...
@@ -275,7 +275,7 @@ static void disableMonitor(const MonitorInfo& m) {
DWORD
dwFlags
=
CDS_UPDATEREGISTRY
|
CDS_GLOBAL
|
CDS_NORESET
;
auto
ret
=
ChangeDisplaySettingsExW
(
m
.
deviceName
.
toStdWString
().
data
(),
&
dm
,
nullptr
,
dwFlags
,
nullptr
);
MYQDEBUG
<<
"disableMonitor ChangeDisplaySettingsExW returns:"
<<
ret
;
MYQDEBUG
<<
"disableMonitor ChangeDisplaySettingsExW returns:"
<<
(
ret
==
ERROR_SUCCESS
)
;
commitChange
();
}
...
...
@@ -290,7 +290,7 @@ static void setMainMonitor(const MonitorInfo& newMain, const MonitorInfo& oldMai
DWORD
dwFlags
=
CDS_UPDATEREGISTRY
|
CDS_GLOBAL
|
CDS_NORESET
;
auto
ret
=
ChangeDisplaySettingsExW
(
oldMain
.
deviceName
.
toStdWString
().
data
(),
&
dm
,
nullptr
,
dwFlags
,
nullptr
);
MYQDEBUG
<<
"moveOld ChangeDisplaySettingsExW returns:"
<<
ret
;
MYQDEBUG
<<
"moveOld ChangeDisplaySettingsExW returns:"
<<
(
ret
==
ERROR_SUCCESS
)
;
};
auto
moveNew
=
[](
const
MonitorInfo
&
newMain
)
{
...
...
@@ -302,7 +302,7 @@ static void setMainMonitor(const MonitorInfo& newMain, const MonitorInfo& oldMai
DWORD
dwFlags
=
CDS_UPDATEREGISTRY
|
CDS_GLOBAL
|
CDS_NORESET
|
CDS_SET_PRIMARY
;
auto
ret
=
ChangeDisplaySettingsExW
(
newMain
.
deviceName
.
toStdWString
().
data
(),
&
dm
,
nullptr
,
dwFlags
,
nullptr
);
MYQDEBUG
<<
"moveNew ChangeDisplaySettingsExW returns:"
<<
ret
;
MYQDEBUG
<<
"moveNew ChangeDisplaySettingsExW returns:"
<<
(
ret
==
ERROR_SUCCESS
)
;
};
moveOld
(
newMain
,
oldMain
);
...
...
@@ -320,7 +320,7 @@ static void changeResolution(const MonitorInfo& monitor, const MonitorInfo::Reso
DWORD
dwFlags
=
CDS_UPDATEREGISTRY
|
CDS_GLOBAL
;
auto
ret
=
ChangeDisplaySettingsExW
(
monitor
.
deviceName
.
toStdWString
().
data
(),
&
dm
,
nullptr
,
dwFlags
,
nullptr
);
MYQDEBUG
<<
"changeResolution ChangeDisplaySettingsExW returns:"
<<
ret
;
MYQDEBUG
<<
"changeResolution ChangeDisplaySettingsExW returns:"
<<
(
ret
==
ERROR_SUCCESS
)
;
commitChange
();
}
...
...
jlib/win32/rect.h
View file @
48fadc2a
...
...
@@ -43,8 +43,8 @@ inline std::vector<::RECT> splitRect(::LPCRECT rc, int n, int gap = 50) {
double
l
=
sqrt
(
n
);
int
line
=
int
(
l
);
int
col_step
=
(
int
)(
W
idth
(
rc
)
/
line
);
int
row_step
=
(
int
)(
H
eight
(
rc
)
/
line
);
int
col_step
=
(
int
)(
w
idth
(
rc
)
/
line
);
int
row_step
=
(
int
)(
h
eight
(
rc
)
/
line
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
v
[
i
].
left
=
rc
->
left
+
(
i
%
line
)
*
col_step
;
...
...
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