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
8a337d1c
Commit
8a337d1c
authored
Mar 10, 2020
by
captainwong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jlibqt/TextMenu
parent
d850d100
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
190 additions
and
0 deletions
+190
-0
TextMenu.cpp
jlib/qt/View/TextMenu.cpp
+141
-0
TextMenu.h
jlib/qt/View/TextMenu.h
+41
-0
qt.vcxproj
jlib/qt/qt.vcxproj
+2
-0
qt.vcxproj.filters
jlib/qt/qt.vcxproj.filters
+6
-0
No files found.
jlib/qt/View/TextMenu.cpp
0 → 100644
View file @
8a337d1c
#include "TextMenu.h"
#include "CheckBtn.h"
#include "../QtUtils.h"
#include "../QtStyleSheet.h"
using
namespace
jlib
::
qt
;
TextMenu
::
TextMenu
(
QWidget
*
parent
,
int
font_sz
)
:
BaseScrollView
(
parent
)
,
font_sz_
(
font_sz
)
{
}
TextMenu
::~
TextMenu
()
{
}
void
TextMenu
::
add_menu
(
int
tag
,
QString
text
)
{
auto
chk
=
new
CheckBtn
(
root
(),
tag
);
chk
->
setText
(
text
);
chk
->
set_font_size
(
font_sz_
);
chk
->
refresh
();
menu_items_
.
push_back
(
chk
);
connect
(
chk
,
SIGNAL
(
sig_check
(
int
,
bool
)),
this
,
SLOT
(
slot_check
(
int
,
bool
)));
}
void
TextMenu
::
refresh
(
QPoint
pt
)
{
if
(
menu_items_
.
empty
())
return
;
int
gap
=
2
;
auto
sample_chk
=
menu_items_
.
front
();
int
max_width
=
sample_chk
->
width
();
int
max_y
=
parentWidget
()
->
rect
().
bottom
();
int
y
=
0
;
for
(
auto
&
chk
:
menu_items_
)
{
chk
->
move
(
0
,
y
);
y
+=
chk
->
height
()
+
gap
;
if
(
height
()
<
y
&&
pt
.
y
()
+
y
<
max_y
)
{
setFixedHeight
(
y
);
}
if
(
root
()
->
height
()
<
y
)
{
root
()
->
setFixedHeight
(
y
);
}
if
(
max_width
<
chk
->
width
())
{
max_width
=
chk
->
width
();
root
()
->
setFixedWidth
(
max_width
);
}
MYQDEBUG
<<
"max_width"
<<
max_width
;
}
setFixedWidth
(
max_width
+
10
);
move
(
pt
.
x
(),
pt
.
y
());
adjustSize
();
setFocus
();
}
bool
TextMenu
::
focus_down
()
{
if
(
!
menu_items_
.
empty
())
{
if
(
++
focus_
==
menu_items_
.
size
())
{
focus_
--
;
}
MYQDEBUG
<<
"focus_="
<<
focus_
;
auto
iter
=
menu_items_
.
begin
();
for
(
int
i
=
0
;
i
<
focus_
;
i
++
)
{
iter
++
;
}
auto
item
=
*
iter
;
ensureWidgetVisible
(
item
);
auto
pt
=
item
->
mapToGlobal
(
item
->
rect
().
center
());
SetCursorPos
(
pt
.
x
(),
pt
.
y
());
return
true
;
}
return
false
;
}
bool
TextMenu
::
focus_up
()
{
if
(
!
menu_items_
.
empty
())
{
if
(
--
focus_
<
0
)
{
focus_
=
0
;
}
MYQDEBUG
<<
"focus_="
<<
focus_
;
auto
iter
=
menu_items_
.
begin
();
for
(
int
i
=
0
;
i
<
focus_
;
i
++
)
{
iter
++
;
}
auto
item
=
*
iter
;
ensureWidgetVisible
(
item
);
auto
pt
=
item
->
mapToGlobal
(
item
->
rect
().
center
());
SetCursorPos
(
pt
.
x
(),
pt
.
y
());
return
true
;
}
return
false
;
}
void
TextMenu
::
click_focus
()
{
auto
iter
=
menu_items_
.
begin
();
for
(
int
i
=
0
;
i
<
focus_
&&
iter
!=
menu_items_
.
end
();
i
++
)
{
iter
++
;
}
if
(
iter
!=
menu_items_
.
end
())
{
auto
item
=
*
iter
;
slot_check
(
item
->
tag
(),
true
);
}
}
void
TextMenu
::
focusOutEvent
(
QFocusEvent
*
e
)
{
auto
top
=
topLevelWidget
();
if
(
isAncestorOf
(
top
))
{
return
;
}
hide
();
emit
sig_menu_dead
();
deleteLater
();
}
void
TextMenu
::
slot_check
(
int
tag
,
bool
is_check
)
{
if
(
!
is_check
)
return
;
MYQDEBUG
<<
tag
<<
is_check
;
emit
sig_menu_check
(
tag
);
parentWidget
()
->
setFocus
();
}
jlib/qt/View/TextMenu.h
0 → 100644
View file @
8a337d1c
#pragma once
#include <QtWidgets>
#include <vector>
#include "BaseScrollView.h"
class
CheckBtn
;
class
TextMenu
:
public
BaseScrollView
{
Q_OBJECT
public
:
TextMenu
(
QWidget
*
parent
,
int
font_sz
);
~
TextMenu
();
void
add_menu
(
int
tag
,
QString
text
);
void
refresh
(
QPoint
pt
);
// return true for success, false for back
bool
focus_down
();
// return true for success, false for back
bool
focus_up
();
void
click_focus
();
protected
:
virtual
void
focusOutEvent
(
QFocusEvent
*
e
)
override
;
signals
:
void
sig_menu_check
(
int
tag
);
void
sig_menu_dead
();
private
slots
:
void
slot_check
(
int
tag
,
bool
is_check
);
private
:
int
sel_
=
-
1
;
int
focus_
=
-
1
;
std
::
vector
<
CheckBtn
*>
menu_items_
=
{};
int
font_sz_
=
18
;
};
jlib/qt/qt.vcxproj
View file @
8a337d1c
...
...
@@ -97,12 +97,14 @@
<ClCompile
Include=
"View\BgColorBtn.cpp"
/>
<ClCompile
Include=
"View\CheckBtn.cpp"
/>
<ClCompile
Include=
"View\IconBtn.cpp"
/>
<ClCompile
Include=
"View\TextMenu.cpp"
/>
<ClCompile
Include=
"View\TitleBar.cpp"
/>
<ClCompile
Include=
"View\PageView.cpp"
/>
<ClCompile
Include=
"View\RndButton.cpp"
/>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"resource.h"
/>
<QtMoc
Include=
"View\TextMenu.h"
/>
<QtMoc
Include=
"View\PageView.h"
/>
<QtMoc
Include=
"View\CheckBtn.h"
/>
<QtMoc
Include=
"View\BaseScrollView.h"
/>
...
...
jlib/qt/qt.vcxproj.filters
View file @
8a337d1c
...
...
@@ -54,6 +54,9 @@
<ClCompile
Include=
"View\TitleBar.cpp"
>
<Filter>
View
</Filter>
</ClCompile>
<ClCompile
Include=
"View\TextMenu.cpp"
>
<Filter>
View
</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"qt.h"
>
...
...
@@ -114,5 +117,8 @@
<QtMoc
Include=
"View\TitleBar.h"
>
<Filter>
View
</Filter>
</QtMoc>
<QtMoc
Include=
"View\TextMenu.h"
>
<Filter>
View
</Filter>
</QtMoc>
</ItemGroup>
</Project>
\ No newline at end of file
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