mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-24 06:59:27 -05:00
gui: chat: add auto shrink chattextedit
To shrink text edit form when it is convenient for browsing text browser. It just shrink/unshrink the edit here and there when switching between chat rooms. P.S. user should not resize chattextedit when it's shrinked P.P.S. okey, there is no "unshrink" maybe, but hope it's not big deal
This commit is contained in:
parent
56b6196fb2
commit
c6c6e11bec
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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">
|
||||
|
@ -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"))
|
||||
|
@ -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>
|
||||
|
@ -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();
|
||||
|
@ -217,6 +217,9 @@ public:
|
||||
bool getChatSendAsPlainTextByDef();
|
||||
void setChatSendAsPlainTextByDef(bool bValue);
|
||||
|
||||
bool getShrinkChatTextEdit();
|
||||
void setShrinkChatTextEdit(bool bValue);
|
||||
|
||||
bool getChatSearchShowBarByDefault();
|
||||
void setChatSearchShowBarByDefault(bool bValue);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user