fixed font handling for chat config page (Patch from HM)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7826 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2015-01-08 19:12:47 +00:00
parent 64c8048981
commit bef921f70c
5 changed files with 45 additions and 10 deletions

View File

@ -122,6 +122,7 @@ ChatWidget::ChatWidget(QWidget *parent) :
connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&, int)), this, SLOT(updateStatus(const QString&, int))); connect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(const QString&, int)), this, SLOT(updateStatus(const QString&, int)));
connect(NotifyQt::getInstance(), SIGNAL(peerHasNewCustomStateString(const QString&, const QString&)), this, SLOT(updatePeersCustomStateString(const QString&, const QString&))); connect(NotifyQt::getInstance(), SIGNAL(peerHasNewCustomStateString(const QString&, const QString&)), this, SLOT(updatePeersCustomStateString(const QString&, const QString&)));
connect(NotifyQt::getInstance(), SIGNAL(chatFontChanged()), this, SLOT(resetFonts()));
connect(ui->textBrowser, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuTextBrowser(QPoint))); connect(ui->textBrowser, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuTextBrowser(QPoint)));
@ -235,7 +236,7 @@ void ChatWidget::init(const ChatId &chat_id, const QString &title)
currentFont.fromString(PeerSettings->getPrivateChatFont(chatId)); currentFont.fromString(PeerSettings->getPrivateChatFont(chatId));
colorChanged(); colorChanged();
setColorAndFont(); setColorAndFont(true);
// load style // load style
PeerSettings->getStyle(chatId, "ChatWidget", style); PeerSettings->getStyle(chatId, "ChatWidget", style);
@ -780,7 +781,7 @@ void ChatWidget::pasteText(const QString& S)
{ {
//std::cerr << "In paste link" << std::endl; //std::cerr << "In paste link" << std::endl;
ui->chatTextEdit->insertHtml(S); ui->chatTextEdit->insertHtml(S);
setColorAndFont(); setColorAndFont(false);
} }
void ChatWidget::pasteCreateMsgLink() void ChatWidget::pasteCreateMsgLink()
@ -831,7 +832,7 @@ void ChatWidget::chatCharFormatChanged()
// Reset font and color before inserting a character if edit box is empty // Reset font and color before inserting a character if edit box is empty
// (color info disappears when the user deletes all text) // (color info disappears when the user deletes all text)
if (ui->chatTextEdit->toPlainText().isEmpty()) { if (ui->chatTextEdit->toPlainText().isEmpty()) {
setColorAndFont(); setColorAndFont(false);
} }
inChatCharFormatChanged = false; inChatCharFormatChanged = false;
@ -1136,7 +1137,7 @@ void ChatWidget::chooseColor()
currentColor = QColor(color); currentColor = QColor(color);
PeerSettings->setPrivateChatColor(chatId, currentColor.name()); PeerSettings->setPrivateChatColor(chatId, currentColor.name());
colorChanged(); colorChanged();
setColorAndFont(); setColorAndFont(false);
} }
} }
@ -1163,10 +1164,24 @@ void ChatWidget::resetFont()
setFont(); setFont();
} }
void ChatWidget::setColorAndFont() void ChatWidget::resetFonts()
{
currentFont.fromString(Settings->getChatScreenFont());
setColorAndFont(true);
PeerSettings->setPrivateChatFont(chatId, currentFont.toString());
}
void ChatWidget::setColorAndFont(bool both)
{ {
ui->chatTextEdit->setFont(currentFont); ui->chatTextEdit->setFont(currentFont);
QStringList fontdata=currentFont.toString().split(",");
QString stylesheet="font-family: '"+fontdata[0]+"'; font-size: "+fontdata[1]+"pt;";
if (currentFont.bold()) stylesheet+=" font-weight: bold;";
if (currentFont.italic()) stylesheet+=" font-style: italic;";
if (currentFont.underline()) stylesheet+=" text-decoration: underline;";
if (both) ui->textBrowser->setStyleSheet(stylesheet);
ui->chatTextEdit->setStyleSheet(stylesheet);
ui->chatTextEdit->setTextColor(currentColor); ui->chatTextEdit->setTextColor(currentColor);
ui->chatTextEdit->setFocus(); ui->chatTextEdit->setFocus();
@ -1174,7 +1189,7 @@ void ChatWidget::setColorAndFont()
void ChatWidget::setFont() void ChatWidget::setFont()
{ {
setColorAndFont(); setColorAndFont(false);
PeerSettings->setPrivateChatFont(chatId, currentFont.toString()); PeerSettings->setPrivateChatFont(chatId, currentFont.toString());
} }

View File

@ -160,6 +160,7 @@ private slots:
void chooseColor(); void chooseColor();
void chooseFont(); void chooseFont();
void resetFont(); void resetFont();
void resetFonts();
void setFont(); void setFont();
void updateLenOfChatTextEdit(); void updateLenOfChatTextEdit();
@ -178,7 +179,7 @@ private:
void setCurrentFileName(const QString &fileName); void setCurrentFileName(const QString &fileName);
void colorChanged(); void colorChanged();
void setColorAndFont(); void setColorAndFont(bool both);
void processSettings(bool load); void processSettings(bool load);
void completeNickname(bool reverse); void completeNickname(bool reverse);

View File

@ -1020,6 +1020,16 @@ void NotifyQt::testToaster(uint notifyFlags, /*RshareSettings::enumToasterPositi
} }
} }
void NotifyQt::notifyChatFontChanged()
{
{
QMutexLocker m(&_mutex) ;
if(!_enabled)
return ;
}
emit chatFontChanged();
}
void NotifyQt::notifyChatStyleChanged(int /*ChatStyle::enumStyleType*/ styleType) void NotifyQt::notifyChatStyleChanged(int /*ChatStyle::enumStyleType*/ styleType)
{ {
{ {

View File

@ -84,6 +84,7 @@ class NotifyQt: public QObject, public NotifyClient
virtual bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result) ; virtual bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result) ;
/* Notify from GUI */ /* Notify from GUI */
void notifyChatFontChanged();
void notifyChatStyleChanged(int /*ChatStyle::enumStyleType*/ styleType); void notifyChatStyleChanged(int /*ChatStyle::enumStyleType*/ styleType);
void testToaster(uint notifyFlags, /*RshareSettings::enumToasterPosition*/ int position, QPoint margin); void testToaster(uint notifyFlags, /*RshareSettings::enumToasterPosition*/ int position, QPoint margin);
@ -139,6 +140,7 @@ class NotifyQt: public QObject, public NotifyClient
void chatLobbyTimeShift(int time_shift) ; void chatLobbyTimeShift(int time_shift) ;
/* Notify from GUI */ /* Notify from GUI */
void chatFontChanged();
void chatStyleChanged(int /*ChatStyle::enumStyleType*/ styleType); void chatStyleChanged(int /*ChatStyle::enumStyleType*/ styleType);
void settingsChanged(); void settingsChanged();
void disableAllChanged(bool disableAll) const; void disableAllChanged(bool disableAll) const;

View File

@ -127,6 +127,7 @@ ChatPage::save(QString &/*errmsg*/)
Settings->endGroup(); Settings->endGroup();
Settings->setChatScreenFont(fontTempChat.toString()); Settings->setChatScreenFont(fontTempChat.toString());
NotifyQt::getInstance()->notifyChatFontChanged();
Settings->setChatSendMessageWithCtrlReturn(ui.sendMessageWithCtrlReturn->isChecked()); Settings->setChatSendMessageWithCtrlReturn(ui.sendMessageWithCtrlReturn->isChecked());
@ -245,8 +246,11 @@ ChatPage::load()
ui.publicChatSaveCount->setValue(rsHistory->getSaveCount(RS_HISTORY_TYPE_PUBLIC)); ui.publicChatSaveCount->setValue(rsHistory->getSaveCount(RS_HISTORY_TYPE_PUBLIC));
ui.privateChatSaveCount->setValue(rsHistory->getSaveCount(RS_HISTORY_TYPE_PRIVATE)); ui.privateChatSaveCount->setValue(rsHistory->getSaveCount(RS_HISTORY_TYPE_PRIVATE));
ui.lobbyChatSaveCount->setValue(rsHistory->getSaveCount(RS_HISTORY_TYPE_LOBBY)); ui.lobbyChatSaveCount->setValue(rsHistory->getSaveCount(RS_HISTORY_TYPE_LOBBY));
ui.labelChatFontPreview->setText(fontTempChat.rawName()); // using fontTempChat.rawname() does not always work!
// see http://doc.qt.digia.com/qt-maemo/qfont.html#rawName
QStringList fontname = fontTempChat.toString().split(",");
ui.labelChatFontPreview->setText(fontname[0]);
ui.labelChatFontPreview->setFont(fontTempChat); ui.labelChatFontPreview->setFont(fontTempChat);
ui.max_storage_period->setValue(rsHistory->getMaxStorageDuration()/86400) ; ui.max_storage_period->setValue(rsHistory->getMaxStorageDuration()/86400) ;
@ -298,7 +302,10 @@ void ChatPage::on_pushButtonChangeChatFont_clicked()
QFont font = QFontDialog::getFont(&ok, fontTempChat, this); QFont font = QFontDialog::getFont(&ok, fontTempChat, this);
if (ok) { if (ok) {
fontTempChat = font; fontTempChat = font;
ui.labelChatFontPreview->setText(fontTempChat.rawName()); // using fontTempChat.rawname() does not always work!
// see http://doc.qt.digia.com/qt-maemo/qfont.html#rawName
QStringList fontname = fontTempChat.toString().split(",");
ui.labelChatFontPreview->setText(fontname[0]);
ui.labelChatFontPreview->setFont(fontTempChat); ui.labelChatFontPreview->setFont(fontTempChat);
} }
} }