Skip to content

Commit

Permalink
feature(gischat): add emoji picker
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Jul 24, 2024
1 parent 095c15d commit 5302dfc
Show file tree
Hide file tree
Showing 3 changed files with 2,179 additions and 17 deletions.
25 changes: 23 additions & 2 deletions qtribu/gui/dck_qchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from qgis.PyQt.QtGui import QBrush, QColor, QIcon
from qgis.PyQt.QtWidgets import QMessageBox, QTreeWidgetItem, QWidget

# plugin
from qtribu.__about__ import __title__
from qtribu.constants import (
ADMIN_MESSAGES_COLOR,
Expand All @@ -28,10 +29,9 @@
QCHAT_NICKNAME_MINLENGTH,
USER_MESSAGES_COLOR,
)
from qtribu.gui.dlg_emoji_picker import QEmojiPicker
from qtribu.logic.qchat_client import QChatApiClient
from qtribu.tasks.dizzy import DizzyTask

# plugin
from qtribu.toolbelt import PlgLogger, PlgOptionsManager
from qtribu.toolbelt.commons import open_url_in_webviewer, play_resource_sound
from qtribu.toolbelt.preferences import PlgSettingsStructure
Expand All @@ -58,6 +58,14 @@ def __init__(self, iface: QgisInterface, parent: QWidget = None):
self.task_manager = QgsApplication.taskManager()
self.log = PlgLogger().log
self.plg_settings = PlgOptionsManager()
self.emoji_picker = QEmojiPicker(
parent=self,
# this option can say how many emojis are in a row
items_per_row=8,
# with this enabled, the emoji search will be faster but less accurate
performance_search=True,
)

uic.loadUi(Path(__file__).parent / f"{Path(__file__).stem}.ui", self)

# rules and status signal listener
Expand Down Expand Up @@ -109,6 +117,8 @@ def __init__(self, iface: QgisInterface, parent: QWidget = None):
self.btn_send.setIcon(
QIcon(QgsApplication.iconPath("mActionDoubleArrowRight.svg"))
)
# connect emojis picker
self.btn_emojis_picker.pressed.connect(self.on_emoji_picker_pressed)

@property
def settings(self) -> PlgSettingsStructure:
Expand Down Expand Up @@ -505,6 +515,17 @@ def check_cheatcode(self, message: dict[str, str]) -> bool:
return True
return False

def on_emoji_picker_pressed(self) -> Optional[str]:
"""Display the emoji picker and insert the selected one at the end of message line edit.
:return: selected emoji
:rtype: str
"""
selected_emoji = self.emoji_picker.select()
self.lne_message.insert(selected_emoji)

return selected_emoji

def on_renew_clicked(self) -> None:
msg_box = QMessageBox()
msg_box.setWindowTitle(self.tr("QGIS"))
Expand Down
56 changes: 41 additions & 15 deletions qtribu/gui/dck_qchat.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>441</width>
<height>887</height>
<width>341</width>
<height>672</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -266,19 +266,6 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lne_message"/>
</item>
<item row="4" column="1">
<widget class="QPushButton" name="btn_send">
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>Send message</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="lbl_nickname">
<property name="cursor">
Expand All @@ -292,6 +279,45 @@
</property>
</widget>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="lne_message"/>
</item>
<item>
<widget class="QPushButton" name="btn_emojis_picker">
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="toolTip">
<string>Pick an emoji. Not sure it'll be properly rendered for every users, still it's a bit of un.</string>
</property>
<property name="locale">
<locale language="English" country="UnitedStates"/>
</property>
<property name="text">
<string>😀</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="1">
<widget class="QPushButton" name="btn_send">
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>Send message</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
Loading

0 comments on commit 5302dfc

Please sign in to comment.