Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nheko
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
nheko
Commits
c6ec20fa
Commit
c6ec20fa
authored
Aug 20, 2017
by
Konstantinos Sideris
Browse files
Options
Downloads
Patches
Plain Diff
Place the completion popup under the search widget
parent
2644e4ac
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/QuickSwitcher.h
+11
-0
11 additions, 0 deletions
include/QuickSwitcher.h
src/QuickSwitcher.cc
+63
-27
63 additions, 27 deletions
src/QuickSwitcher.cc
with
74 additions
and
27 deletions
include/QuickSwitcher.h
+
11
−
0
View file @
c6ec20fa
...
...
@@ -17,6 +17,7 @@
#pragma once
#include
<QAbstractItemView>
#include
<QFrame>
#include
<QKeyEvent>
#include
<QVBoxLayout>
...
...
@@ -29,8 +30,14 @@ class RoomSearchInput : public TextField
public:
explicit
RoomSearchInput
(
QWidget
*
parent
=
nullptr
);
signals:
void
selectNextCompletion
();
void
selectPreviousCompletion
();
void
hiding
();
protected:
void
keyPressEvent
(
QKeyEvent
*
event
)
override
;
void
hideEvent
(
QHideEvent
*
event
)
override
;
bool
focusNextPrevChild
(
bool
next
)
override
;
};
...
...
@@ -51,8 +58,12 @@ protected:
void
showEvent
(
QShowEvent
*
event
)
override
;
private:
// Current highlighted selection from the completer.
int
selection_
=
-
1
;
QVBoxLayout
*
topLayout_
;
RoomSearchInput
*
roomSearch_
;
QCompleter
*
completer_
;
QMap
<
QString
,
QString
>
rooms_
;
};
This diff is collapsed.
Click to expand it.
src/QuickSwitcher.cc
+
63
−
27
View file @
c6ec20fa
...
...
@@ -15,7 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include
<QAbstractItemView>
#include
<QCompleter>
#include
<QDebug>
#include
<QStringListModel>
...
...
@@ -39,17 +38,12 @@ RoomSearchInput::focusNextPrevChild(bool next)
void
RoomSearchInput
::
keyPressEvent
(
QKeyEvent
*
event
)
{
if
(
event
->
key
()
==
Qt
::
Key_Tab
)
{
auto
completer
=
this
->
completer
();
if
(
completer
)
{
// Enable the current item if its valid.
completer
->
popup
()
->
setCurrentIndex
(
completer
->
currentIndex
());
if
(
!
completer
->
setCurrentRow
(
completer
->
currentRow
()
+
1
))
completer
->
setCurrentRow
(
0
);
}
if
(
event
->
key
()
==
Qt
::
Key_Tab
||
event
->
key
()
==
Qt
::
Key_Down
)
{
emit
selectNextCompletion
();
event
->
accept
();
return
;
}
else
if
(
event
->
key
()
==
Qt
::
Key_Up
)
{
emit
selectPreviousCompletion
();
event
->
accept
();
return
;
}
...
...
@@ -57,11 +51,18 @@ RoomSearchInput::keyPressEvent(QKeyEvent *event)
TextField
::
keyPressEvent
(
event
);
}
void
RoomSearchInput
::
hideEvent
(
QHideEvent
*
event
)
{
emit
hiding
();
TextField
::
hideEvent
(
event
);
}
QuickSwitcher
::
QuickSwitcher
(
QWidget
*
parent
)
:
QFrame
(
parent
)
{
setMaximumWidth
(
4
0
0
);
setStyleSheet
(
"background-color:
#f9f9f9
"
);
setMaximumWidth
(
4
5
0
);
setStyleSheet
(
"background-color:
white
"
);
QFont
font
;
font
.
setPixelSize
(
20
);
...
...
@@ -70,17 +71,56 @@ QuickSwitcher::QuickSwitcher(QWidget *parent)
roomSearch_
->
setFont
(
font
);
roomSearch_
->
setPlaceholderText
(
tr
(
"Find a room..."
));
QStringList
wordList
;
QCompleter
*
completer
=
new
QCompleter
(
wordList
,
this
);
completer
->
setCaseSensitivity
(
Qt
::
CaseInsensitive
);
roomSearch_
->
setCompleter
(
completer
);
completer_
=
new
QCompleter
();
completer_
->
setCaseSensitivity
(
Qt
::
CaseInsensitive
);
completer_
->
setCompletionMode
(
QCompleter
::
PopupCompletion
);
completer_
->
setWidget
(
this
);
topLayout_
=
new
QVBoxLayout
(
this
);
topLayout_
->
setMargin
(
20
);
topLayout_
->
setSpacing
(
0
);
topLayout_
->
addWidget
(
roomSearch_
);
connect
(
completer_
,
SIGNAL
(
highlighted
(
QString
)),
roomSearch_
,
SLOT
(
setText
(
QString
)));
connect
(
roomSearch_
,
&
QLineEdit
::
textEdited
,
this
,
[
=
](
const
QString
&
prefix
)
{
if
(
prefix
.
isEmpty
())
{
completer_
->
popup
()
->
hide
();
selection_
=
-
1
;
return
;
}
if
(
prefix
!=
completer_
->
completionPrefix
())
{
completer_
->
setCompletionPrefix
(
prefix
);
selection_
=
-
1
;
}
completer_
->
popup
()
->
setWindowFlags
(
completer_
->
popup
()
->
windowFlags
()
|
Qt
::
ToolTip
|
Qt
::
NoDropShadowWindowHint
);
completer_
->
popup
()
->
setAttribute
(
Qt
::
WA_ShowWithoutActivating
);
completer_
->
complete
();
});
connect
(
roomSearch_
,
&
RoomSearchInput
::
selectNextCompletion
,
this
,
[
=
]()
{
selection_
+=
1
;
if
(
!
completer_
->
setCurrentRow
(
selection_
))
{
selection_
=
0
;
completer_
->
setCurrentRow
(
selection_
);
}
completer_
->
popup
()
->
setCurrentIndex
(
completer_
->
currentIndex
());
});
connect
(
roomSearch_
,
&
RoomSearchInput
::
selectPreviousCompletion
,
this
,
[
=
]()
{
selection_
-=
1
;
if
(
!
completer_
->
setCurrentRow
(
selection_
))
{
selection_
=
completer_
->
completionCount
()
-
1
;
completer_
->
setCurrentRow
(
selection_
);
}
completer_
->
popup
()
->
setCurrentIndex
(
completer_
->
currentIndex
());
});
connect
(
roomSearch_
,
&
RoomSearchInput
::
hiding
,
this
,
[
=
]()
{
completer_
->
popup
()
->
hide
();
});
connect
(
roomSearch_
,
&
QLineEdit
::
returnPressed
,
this
,
[
=
]()
{
emit
closing
();
emit
roomSelected
(
rooms_
[
this
->
roomSearch_
->
text
().
trimmed
()]);
...
...
@@ -93,13 +133,9 @@ void
QuickSwitcher
::
setRoomList
(
const
QMap
<
QString
,
QString
>
&
rooms
)
{
rooms_
=
rooms
;
QStringList
items
=
rooms
.
keys
();
QStringList
search_items
=
rooms
.
keys
();
if
(
!
roomSearch_
->
completer
())
return
;
roomSearch_
->
completer
()
->
setModel
(
new
QStringListModel
(
search_items
));
completer_
->
setModel
(
new
QStringListModel
(
items
));
}
void
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment