Merge pull request #2619 from chelovechishko/chat_amusement

gui: chat: add auto shrink chattextedit
This commit is contained in:
csoler 2022-05-11 21:23:48 +02:00 committed by GitHub
commit 52dffddf64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 238 additions and 16 deletions

View File

@ -241,10 +241,6 @@ SharedFilesDialog::SharedFilesDialog(bool remote_mode, QWidget *parent)
/* Set Multi Selection */
ui.dirTreeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
QFontMetricsF fontMetrics(ui.dirTreeView->font());
int iconHeight = fontMetrics.height() * 1.5;
ui.dirTreeView->setIconSize(QSize(iconHeight, iconHeight));
/* Hide platform specific features */
copylinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Copy retroshare Links to Clipboard" ), this );
connect( copylinkAct , SIGNAL( triggered() ), this, SLOT( copyLink() ) );
@ -323,7 +319,7 @@ void SharedFilesDialog::hideEvent(QHideEvent *)
model->setVisible(false) ;
}
void SharedFilesDialog::showEvent(QShowEvent *)
void SharedFilesDialog::showEvent(QShowEvent *event)
{
if(model!=NULL)
{
@ -336,6 +332,10 @@ void SharedFilesDialog::showEvent(QShowEvent *)
restoreExpandedPathsAndSelection(expanded_indexes,hidden_indexes,selected_indexes);
}
if (!event->spontaneous()) {
updateFontSize();
}
}
RemoteSharedFilesDialog::~RemoteSharedFilesDialog()
{
@ -1686,3 +1686,16 @@ bool SharedFilesDialog::tree_FilterItem(const QModelIndex &index, const QString
return (visible || visibleChildCount);
}
#endif
void SharedFilesDialog::updateFontSize()
{
int customFontSize = Settings->valueFromGroup("File", "MinimumFontSize", 11).toInt();
QFont newFont = ui.dirTreeView->font();
if (newFont.pointSize() != customFontSize) {
newFont.setPointSize(customFontSize);
QFontMetricsF fontMetrics(newFont);
int iconHeight = fontMetrics.height();
ui.dirTreeView->setFont(newFont);
ui.dirTreeView->setIconSize(QSize(iconHeight, iconHeight));
}
}

View File

@ -117,6 +117,8 @@ protected:
QModelIndexList getSelected();
void updateFontSize();
/** Defines the actions for the context menu for QTreeWidget */
QAction* copylinkAct;
QAction* sendlinkAct;

View File

@ -356,11 +356,6 @@ border-image: url(:/images/closepressed.png)
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
</font>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>

View File

@ -27,8 +27,8 @@
#include "ChatDialog.h"
#include "PopupChatWindow.h"
Q_DECLARE_METATYPE(RsGxsId)
Q_DECLARE_METATYPE(QList<RsGxsId>)
// Q_DECLARE_METATYPE(RsGxsId)
// Q_DECLARE_METATYPE(QList<RsGxsId>)
class GxsIdChooser ;
class QToolButton;

View File

@ -474,6 +474,7 @@ void ChatWidget::processSettings(bool load)
// state of splitter
ui->chatVSplitter->restoreState(Settings->value("ChatSplitter").toByteArray());
} else {
shrinkChatTextEdit(false);
// save settings
// state of splitter
@ -643,6 +644,16 @@ bool ChatWidget::eventFilter(QObject *obj, QEvent *event)
}
} else if (obj == ui->chatTextEdit) {
if (chatType() == CHATTYPE_LOBBY) {
#define EVENT_IS(q_event) (event->type() == QEvent::q_event)
if (EVENT_IS(FocusIn)) {
if (was_shrinked) {
shrinkChatTextEdit(false);
}
}
#undef EVENT_IS
}
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
@ -905,11 +916,19 @@ void ChatWidget::showEvent(QShowEvent */*event*/)
QScrollBar *scrollbar = ui->textBrowser->verticalScrollBar();
bool is_scrollbar_at_end = scrollbar->value() == scrollbar->maximum();
bool is_chat_text_edit_empty = ui->chatTextEdit->toPlainText().isEmpty();
// show event will not be called on every change of focus
if (is_scrollbar_at_end || !is_chat_text_edit_empty) {
if (!firstShow) {
shrinkChatTextEdit(false);
}
focusDialog();
} else {
// otherwise focus will be get even not chat itself
// otherwise, focus will not even be gotten by chat itself
ui->textBrowser->setFocus();
if (!firstShow && !was_shrinked) {
shrinkChatTextEdit(true);
}
}
ChatUserNotify::clearWaitingChat(chatId);
@ -923,6 +942,11 @@ void ChatWidget::showEvent(QShowEvent */*event*/)
void ChatWidget::resizeEvent(QResizeEvent */*event*/)
{
// it's about resize all chat window, not about chattextedit
// just unshrink it and do not bother
if (was_shrinked) {
shrinkChatTextEdit(false);
}
// Workaround: now the scroll position is correct calculated
QScrollBar *scrollbar = ui->textBrowser->verticalScrollBar();
scrollbar->setValue(scrollbar->maximum());
@ -1967,3 +1991,50 @@ void ChatWidget::saveSticker()
filename = Emoticons::importedStickerPath() + "/" + filename + ".png";
ImageUtil::extractImage(window(), cursor, filename);
}
void ChatWidget::shrinkChatTextEdit(bool shrink_me)
{
// here and at eventfiltert check
if (chatType() != CHATTYPE_LOBBY)
return;
if (!Settings->getShrinkChatTextEdit()) {
if (was_shrinked) {
ui->chatVSplitter->setSizes(_chatvsplitter_saved_size);
}
_chatvsplitter_saved_size.clear();
was_shrinked = false;
}
if (Settings->getShrinkChatTextEdit()) {
if (shrink_me) {
if (!was_shrinked) {
_chatvsplitter_saved_size = ui->chatVSplitter->sizes();
QList<int> shrinked_v_splitter_size = _chatvsplitter_saved_size;
// #define TEXT_BROWSER ui->chatVSplitter->indexOf(ui->textBrowser)
#define TEXT_BROWSER 0
// when you will update the layout one more time change this appropriately
// #define BELOW_TEXT_BROWSER ui->chatVSplitter->indexOf(ui->chatVSplitter->widget(1))
#define BELOW_TEXT_BROWSER 1
int height_diff = shrinked_v_splitter_size[BELOW_TEXT_BROWSER] - ui->chatTextEdit->minimumHeight();
shrinked_v_splitter_size[BELOW_TEXT_BROWSER] = ui->chatTextEdit->minimumHeight();
shrinked_v_splitter_size[TEXT_BROWSER] += height_diff;
ui->chatVSplitter->setSizes( shrinked_v_splitter_size );
#undef TEXT_BROWSER
#undef BELOW_TEXT_BROWSER
was_shrinked = true;
}
} else { // (!shrink_me)
if (was_shrinked) {
// to not shrink/unshrink at every entry into chat
// when unshrinked state is enough to a browser be scrollable, but shrinked - not
QScrollBar *scrollbar = ui->textBrowser->verticalScrollBar();
bool is_scrollbar_at_end = scrollbar->value() == scrollbar->maximum();
ui->chatVSplitter->setSizes(_chatvsplitter_saved_size);
if (is_scrollbar_at_end)
scrollbar->setValue(scrollbar->maximum());
was_shrinked = false;
}
}
}
}

View File

@ -215,6 +215,8 @@ private:
void completeNickname(bool reverse);
QAbstractItemModel *modelFromPeers();
void shrinkChatTextEdit(bool shrink_me);
ChatId chatId;
QString title;
QString name;
@ -264,6 +266,9 @@ private:
QCompleter *completer;
ImHistoryBrowser* imBrowser;
QList<int> _chatvsplitter_saved_size;
bool was_shrinked = false;
QList<ChatWidgetHolder*> mChatWidgetHolder;
ChatLobbyUserNotify* notify;

View File

@ -661,7 +661,7 @@ border-image: url(:/images/closepressed.png)
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
<height>40</height>
</size>
</property>
<property name="placeholderText">

View File

@ -34,6 +34,7 @@
#include "util/misc.h"
#include "rshare.h"
#include <retroshare/rsidentity.h>
#include <retroshare/rsmsgs.h>
#include <retroshare/rsnotify.h>
@ -100,6 +101,17 @@ PopupChatWindow::PopupChatWindow(bool tabbed, QWidget *parent, Qt::WindowFlags f
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint)));
voteNegative = new QAction(FilesDefs::getIconFromQtResourcePath(":/icons/png/thumbs-down.png"),
tr("Ban this person (Sets negative opinion)"), this);
voteNeutral = new QAction(FilesDefs::getIconFromQtResourcePath(":/icons/png/thumbs-neutral.png"),
tr("Give neutral opinion"), this);
votePositive = new QAction(FilesDefs::getIconFromQtResourcePath(":/icons/png/thumbs-up.png"),
tr("Give positive opinion"), this);
connect(votePositive, SIGNAL(triggered()), this, SLOT(voteParticipant()));
connect(voteNeutral, SIGNAL(triggered()), this, SLOT(voteParticipant()));
connect(voteNegative, SIGNAL(triggered()), this, SLOT(voteParticipant()));
connect(ui.tabWidget, SIGNAL(tabChanged(ChatDialog*)), this, SLOT(tabChanged(ChatDialog*)));
connect(ui.tabWidget, SIGNAL(tabClosed(ChatDialog*)), this, SLOT(tabClosed(ChatDialog*)));
@ -116,6 +128,37 @@ void PopupChatWindow::showContextMenu(QPoint)
QMenu contextMnu(this);
contextMnu.addAction(FilesDefs::getIconFromQtResourcePath(":/images/highlight.png"),tr("Choose window color..."),this,SLOT(setStyle()));
ChatId ch_id = getCurrentDialog()->getChatId();
if (ch_id.isDistantChatId()) {
DistantChatPeerId dc_id = ch_id.toDistantChatId();
DistantChatPeerInfo dc_info;
if(rsMsgs->getDistantChatStatus(dc_id, dc_info)) {
RsGxsId gxs_id = dc_info.to_id;
if(!gxs_id.isNull() && !rsIdentity->isOwnId(gxs_id)) {
contextMnu.addAction(votePositive);
contextMnu.addAction(voteNeutral);
contextMnu.addAction(voteNegative);
votePositive->setEnabled(false);
voteNeutral ->setEnabled(false);
voteNegative->setEnabled(false);
RsOpinion rs_rep;
rsReputations->getOwnOpinion(gxs_id, rs_rep);
if (rsReputations->getOwnOpinion(gxs_id, rs_rep)) {
votePositive->setEnabled(rs_rep != RsOpinion::POSITIVE);
voteNeutral->setEnabled( ( rs_rep == RsOpinion::POSITIVE )
|| ( rs_rep == RsOpinion::NEGATIVE ) );
voteNegative->setEnabled(rs_rep != RsOpinion::NEGATIVE);
votePositive->setData(QVariant::fromValue(gxs_id));
voteNeutral ->setData(QVariant::fromValue(gxs_id));
voteNegative->setData(QVariant::fromValue(gxs_id));
}
}
}
}
if (Settings->getChatFlags() & RS_CHAT_TABBED_WINDOW)
{
if(tabbedWindow)
@ -457,3 +500,17 @@ void PopupChatWindow::blink(bool on)
setWindowIcon(on ? mBlinkIcon : *mEmptyIcon);
}
}
void PopupChatWindow::voteParticipant()
{
QAction *act = dynamic_cast<QAction*>(sender()) ;
if (!act) {
return ;
}
RsOpinion opinion = RsOpinion::NEUTRAL;
if (act == voteNeutral) opinion = RsOpinion::NEUTRAL;
if (act == votePositive) opinion = RsOpinion::POSITIVE;
if (act == voteNegative) opinion = RsOpinion::NEGATIVE;
rsReputations->setOwnOpinion(act->data().value<RsGxsId>(), opinion);
}

View File

@ -27,6 +27,8 @@
#include "ui_PopupChatWindow.h"
#include <retroshare/rstypes.h>
#include <retroshare/rsmsgs.h>
Q_DECLARE_METATYPE(RsGxsId)
Q_DECLARE_METATYPE(QList<RsGxsId>)
class ChatDialog;
@ -67,6 +69,7 @@ private slots:
void setOnTop();
void blink(bool on);
void showContextMenu(QPoint p);
void voteParticipant();
private:
bool tabbedWindow;
@ -75,6 +78,9 @@ private:
ChatDialog *chatDialog;
QIcon mBlinkIcon;
QIcon *mEmptyIcon;
QAction* votePositive;
QAction* voteNegative;
QAction* voteNeutral;
ChatDialog *getCurrentDialog();
void saveSettings();

View File

@ -135,6 +135,7 @@ void ChatPage::updateChatParams()
Settings->setChatSendAsPlainTextByDef(ui.sendAsPlainTextByDef->isChecked());
Settings->setChatLoadEmbeddedImages(ui.loadEmbeddedImages->isChecked());
Settings->setChatDoNotSendIsTyping(ui.DontSendTyping->isChecked());
Settings->setShrinkChatTextEdit(ui.shrinkChatTextEdit->isChecked());
}
void ChatPage::updateChatSearchParams()
@ -248,6 +249,7 @@ ChatPage::ChatPage(QWidget * parent, Qt::WindowFlags flags)
connect(ui.sendAsPlainTextByDef, SIGNAL(toggled(bool)), this, SLOT(updateChatParams()));
connect(ui.loadEmbeddedImages, SIGNAL(toggled(bool)), this, SLOT(updateChatParams()));
connect(ui.DontSendTyping, SIGNAL(toggled(bool)), this, SLOT(updateChatParams()));
connect(ui.shrinkChatTextEdit, SIGNAL(toggled(bool)), this, SLOT(updateChatParams()));
connect(ui.sbSearch_CharToStart, SIGNAL(valueChanged(int)), this, SLOT(updateChatSearchParams()));
connect(ui.cbSearch_CaseSensitively, SIGNAL(toggled(bool)), this, SLOT(updateChatSearchParams()));
@ -403,6 +405,7 @@ ChatPage::load()
whileBlocking(ui.sendAsPlainTextByDef)->setChecked(Settings->getChatSendAsPlainTextByDef());
whileBlocking(ui.loadEmbeddedImages)->setChecked(Settings->getChatLoadEmbeddedImages());
whileBlocking(ui.DontSendTyping)->setChecked(Settings->getChatDoNotSendIsTyping());
whileBlocking(ui.shrinkChatTextEdit)->setChecked(Settings->getShrinkChatTextEdit());
std::string advsetting;
if(rsConfig->getConfigurationOption(RS_CONFIG_ADVANCED, advsetting) && (advsetting == "YES"))

View File

@ -95,6 +95,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="shrinkChatTextEdit">
<property name="toolTip">
<string>When focus on text browser after showing chat room</string>
</property>
<property name="text">
<string>Shrink text edit field when not needed</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -53,6 +53,7 @@ TransferPage::TransferPage(QWidget * parent, Qt::WindowFlags flags)
QObject::connect(ui.partialButton, SIGNAL(clicked( bool ) ), this , SLOT( setPartialsDirectory() ) );
QObject::connect(ui.editShareButton, SIGNAL(clicked()), this, SLOT(editDirectories()));
QObject::connect(ui.autoCheckDirectories_CB, SIGNAL(clicked(bool)), this, SLOT(toggleAutoCheckDirectories(bool)));
QObject::connect(ui.minimumFontSize_SB, SIGNAL(valueChanged(int)), this, SLOT(updateFontSize())) ;
QObject::connect(ui.autoCheckDirectories_CB, SIGNAL(toggled(bool)), this,SLOT(updateAutoCheckDirectories())) ;
QObject::connect(ui.autoCheckDirectoriesDelay_SB,SIGNAL(valueChanged(int)),this,SLOT(updateAutoScanDirectoriesPeriod())) ;
@ -188,6 +189,10 @@ void TransferPage::load()
whileBlocking(ui.suffixesIgnoreList_CB)->setChecked( ignore_flags & RS_FILE_SHARE_FLAGS_IGNORE_SUFFIXES ) ;
whileBlocking(ui.prefixesIgnoreList_LE)->setText( ignore_prefixes_string );
whileBlocking(ui.suffixesIgnoreList_LE)->setText( ignore_suffixes_string );
Settings->beginGroup(QString("File"));
whileBlocking(ui.minimumFontSize_SB)->setValue( Settings->value("MinimumFontSize", 11 ).toInt());
Settings->endGroup();
}
void TransferPage::updateDefaultStrategy(int i)
@ -290,6 +295,13 @@ void TransferPage::editDirectories()
ShareManager::showYourself() ;
}
void TransferPage::updateFontSize()
{
Settings->beginGroup(QString("File"));
Settings->setValue("MinimumFontSize", ui.minimumFontSize_SB->value());
Settings->endGroup();
}
void TransferPage::updateAutoCheckDirectories() { rsFiles->setWatchEnabled(ui.autoCheckDirectories_CB->isChecked()) ; }
void TransferPage::updateAutoScanDirectoriesPeriod() { rsFiles->setWatchPeriod(ui.autoCheckDirectoriesDelay_SB->value()); }
void TransferPage::updateShareDownloadDirectory() { rsFiles->shareDownloadDirectory(ui.shareDownloadDirectoryCB->isChecked());}

View File

@ -58,6 +58,7 @@ class TransferPage: public ConfigPage
void updateAutoDLColl();
void setPartialsDirectory();
void toggleAutoCheckDirectories(bool);
void updateFontSize();
void updateAutoCheckDirectories() ;
void updateAutoScanDirectoriesPeriod() ;

View File

@ -299,6 +299,40 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item row="4" column="0">
<layout class="QHBoxLayout" name="minimumFontSizeHLayout">
<item>
<widget class="QLabel" name="minimumFontSizeLabel">
<property name="text">
<string>Minimum font size for Shared Files</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="minimumFontSize_SB">
<property name="minimum">
<number>11</number>
</property>
<property name="maximum">
<number>64</number>
</property>
</widget>
</item>
<item>
<spacer name="minimumFontSizeHSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="5" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>

View File

@ -537,6 +537,16 @@ void RshareSettings::setChatSendAsPlainTextByDef(bool bValue)
setValueToGroup("Chat", "SendAsPlainTextByDef", bValue);
}
bool RshareSettings::getShrinkChatTextEdit()
{
return valueFromGroup("Chat", "ShrinkChatTextEdit", false).toBool();
}
void RshareSettings::setShrinkChatTextEdit(bool bValue)
{
setValueToGroup("Chat", "ShrinkChatTextEdit", bValue);
}
bool RshareSettings::getChatSearchShowBarByDefault()
{
return valueFromGroup("Chat", "SearchShowBarByDefault", false).toBool();

View File

@ -217,6 +217,9 @@ public:
bool getChatSendAsPlainTextByDef();
void setChatSendAsPlainTextByDef(bool bValue);
bool getShrinkChatTextEdit();
void setShrinkChatTextEdit(bool bValue);
bool getChatSearchShowBarByDefault();
void setChatSearchShowBarByDefault(bool bValue);