Skip to content

Commit

Permalink
feat: set message colors in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
gounux committed Jul 25, 2024
1 parent ed3f4a4 commit c37b094
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 14 deletions.
3 changes: 0 additions & 3 deletions qtribu/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,7 @@ def local_path(self, base_path: Path = Path().home() / ".geotribu/cdn/") -> Path
# QChat
QCHAT_NICKNAME_MINLENGTH = 3
ADMIN_MESSAGES_NICKNAME = "admin"
ADMIN_MESSAGES_COLOR = "#ffa500"
ADMIN_MESSAGES_AVATAR = "mIconWarning.svg"
MENTION_MESSAGES_COLOR = "#4169e1"
USER_MESSAGES_COLOR = "#00cc00"
ERROR_MESSAGES_COLOR = "#ff0000"
INTERNAL_MESSAGE_AUTHOR = "internal"

Expand Down
9 changes: 3 additions & 6 deletions qtribu/gui/dck_qchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@
from qtribu.__about__ import __title__
from qtribu.constants import (
ADMIN_MESSAGES_AVATAR,
ADMIN_MESSAGES_COLOR,
ADMIN_MESSAGES_NICKNAME,
CHEATCODE_10OCLOCK,
CHEATCODE_DIZZY,
CHEATCODE_DONTCRYBABY,
CHEATCODE_IAMAROBOT,
CHEATCODE_QGIS_PRO_LICENSE,
INTERNAL_MESSAGE_AUTHOR,
MENTION_MESSAGES_COLOR,
QCHAT_NICKNAME_MINLENGTH,
USER_MESSAGES_COLOR,
)
from qtribu.logic.qchat_client import QChatApiClient
from qtribu.tasks.dizzy import DizzyTask
Expand Down Expand Up @@ -345,7 +342,7 @@ def on_ws_message_received(self, message: str) -> None:
message["author"],
message["avatar"],
message["message"],
foreground_color=MENTION_MESSAGES_COLOR,
foreground_color=self.settings.qchat_color_mention,
)
self.log(
message=self.tr("You were mentionned by {sender}: {message}").format(
Expand All @@ -362,7 +359,7 @@ def on_ws_message_received(self, message: str) -> None:
message["author"],
message["avatar"],
message["message"],
foreground_color=USER_MESSAGES_COLOR,
foreground_color=self.settings.qchat_color_self,
)
else:
item = self.create_message_item(
Expand Down Expand Up @@ -523,7 +520,7 @@ def add_admin_message(self, room: str, message: str) -> None:
ADMIN_MESSAGES_NICKNAME,
ADMIN_MESSAGES_AVATAR,
message,
foreground_color=ADMIN_MESSAGES_COLOR,
foreground_color=self.settings.qchat_color_admin,
)
self.twg_chat.insertTopLevelItem(0, item)

Expand Down
8 changes: 7 additions & 1 deletion qtribu/gui/dlg_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from qgis.gui import QgsOptionsPageWidget, QgsOptionsWidgetFactory
from qgis.PyQt import uic
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtGui import QColor, QIcon
from qgis.PyQt.QtWidgets import QButtonGroup, QMessageBox

# project
Expand Down Expand Up @@ -114,6 +114,9 @@ def apply(self):
settings.qchat_play_sounds = self.ckb_play_sounds.isChecked()
settings.qchat_sound_volume = self.hsl_sound_volume.value()
settings.qchat_ring_tone = self.cbb_ring_tone.currentText()
settings.qchat_color_mention = self.cbt_color_mention.color().name()
settings.qchat_color_self = self.cbt_color_self.color().name()
settings.qchat_color_admin = self.cbt_color_admin.color().name()

# misc
settings.debug_mode = self.opt_debug.isChecked()
Expand Down Expand Up @@ -162,6 +165,9 @@ def load_settings(self) -> None:
)
if beep_index >= 0:
self.cbb_ring_tone.setCurrentIndex(beep_index)
self.cbt_color_mention.setColor(QColor(settings.qchat_color_mention))
self.cbt_color_self.setColor(QColor(settings.qchat_color_self))
self.cbt_color_admin.setColor(QColor(settings.qchat_color_admin))

# misc
self.opt_debug.setChecked(settings.debug_mode)
Expand Down
111 changes: 107 additions & 4 deletions qtribu/gui/dlg_settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,9 @@
<item>
<layout class="QHBoxLayout" name="hly_misc">
<item>
<widget class="QCheckBox" name="ckb_cheatcodes">
<widget class="QCheckBox" name="ckb_show_avatars">
<property name="text">
<string>Activate cheatcodes</string>
<string>Show avatars</string>
</property>
</widget>
</item>
Expand All @@ -367,9 +367,9 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="ckb_show_avatars">
<widget class="QCheckBox" name="ckb_cheatcodes">
<property name="text">
<string>Show avatars</string>
<string>Activate cheatcodes</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -475,6 +475,79 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="hly_colors">
<item>
<widget class="QLabel" name="lbl_color_mention">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Mention message color:</string>
</property>
</widget>
</item>
<item>
<widget class="QgsColorButton" name="cbt_color_mention">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lbl_color_self">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Self message color:</string>
</property>
</widget>
</item>
<item>
<widget class="QgsColorButton" name="cbt_color_self">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lbl_color_admin">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Admin message color:</string>
</property>
</widget>
</item>
<item>
<widget class="QgsColorButton" name="cbt_color_admin">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -676,6 +749,11 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsColorButton</class>
<extends>QToolButton</extends>
<header>qgscolorbutton.h</header>
</customwidget>
<customwidget>
<class>QgsSymbolButton</class>
<extends>QToolButton</extends>
Expand All @@ -688,6 +766,31 @@
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>opt_browser_qt</tabstop>
<tabstop>opt_browser_os</tabstop>
<tabstop>opt_notif_push_msg</tabstop>
<tabstop>sbx_notif_duration</tabstop>
<tabstop>btn_reset_read_history</tabstop>
<tabstop>chb_integration_news_feed</tabstop>
<tabstop>chb_license_global_accept</tabstop>
<tabstop>mSymbolButton</tabstop>
<tabstop>cbb_qchat_instance_uri</tabstop>
<tabstop>btn_rules</tabstop>
<tabstop>ckb_show_avatars</tabstop>
<tabstop>ckb_display_admin_messages</tabstop>
<tabstop>ckb_cheatcodes</tabstop>
<tabstop>ckb_play_sounds</tabstop>
<tabstop>hsl_sound_volume</tabstop>
<tabstop>cbb_ring_tone</tabstop>
<tabstop>cbt_color_mention</tabstop>
<tabstop>cbt_color_self</tabstop>
<tabstop>cbt_color_admin</tabstop>
<tabstop>btn_help</tabstop>
<tabstop>btn_report</tabstop>
<tabstop>opt_debug</tabstop>
<tabstop>btn_reset</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>
3 changes: 3 additions & 0 deletions qtribu/toolbelt/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class PlgSettingsStructure:
qchat_play_sounds: bool = True
qchat_sound_volume: int = 33
qchat_ring_tone: str = "beep_1"
qchat_color_mention: str = "#4169e1"
qchat_color_self: str = "#00cc00"
qchat_color_admin: str = "#ffa500"

# usage
browser: int = 1
Expand Down

0 comments on commit c37b094

Please sign in to comment.