From 0e063f9a1b61eeb10a106ed6d7b740ecb2562a21 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Fri, 8 Oct 2010 00:07:44 +0000 Subject: [PATCH] Fixed font handling in PeersDialog. Fixed Qt bug in PeersDialog and PopupChatDialog with a workaround. - QTextEdit::clear() does not reset the CharFormat if document contains hyperlinks that have been accessed. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3652 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/PeersDialog.cpp | 76 ++++++++++--------- retroshare-gui/src/gui/PeersDialog.h | 7 +- .../src/gui/chat/PopupChatDialog.cpp | 4 + 3 files changed, 50 insertions(+), 37 deletions(-) diff --git a/retroshare-gui/src/gui/PeersDialog.cpp b/retroshare-gui/src/gui/PeersDialog.cpp index fa2faa1fb..228b80b25 100644 --- a/retroshare-gui/src/gui/PeersDialog.cpp +++ b/retroshare-gui/src/gui/PeersDialog.cpp @@ -174,14 +174,11 @@ PeersDialog::PeersDialog(QWidget *parent) ui.fontsButton->setIcon(QIcon(QString(":/images/fonts.png"))); - _currentColor = Qt::black; - - QPixmap pxm(16,16); - pxm.fill(_currentColor); - ui.colorChatButton->setIcon(pxm); - + mCurrentColor = Qt::black; mCurrentFont.fromString(Settings->getChatScreenFont()); - ui.lineEdit->setFont(mCurrentFont); + + colorChanged(mCurrentColor); + fontChanged(mCurrentFont); style.setStyleFromSettings(ChatStyle::TYPE_PUBLIC); @@ -203,8 +200,6 @@ PeersDialog::PeersDialog(QWidget *parent) grpchatmenu->addAction(ui.actionMessageHistory); ui.menuButton->setMenu(grpchatmenu); - _underline = false; - QMenu *menu = new QMenu(); menu->addAction(ui.actionAdd_Friend); menu->addAction(ui.actionAdd_Group); @@ -339,7 +334,7 @@ void PeersDialog::showEvent(QShowEvent *event) void PeersDialog::pasteLink() { - ui.lineEdit->insertHtml(RSLinkClipboard::toHtml()) ; + ui.lineEdit->insertHtml(RSLinkClipboard::toHtml()) ; } void PeersDialog::contextMenu( QPoint point ) @@ -1499,6 +1494,10 @@ void PeersDialog::sendMsg() rsMsgs->sendPublicChat(message); ui.lineEdit->clear(); + // workaround for Qt bug - http://bugreports.qt.nokia.com/browse/QTBUG-2533 + // QTextEdit::clear() does not reset the CharFormat if document contains hyperlinks that have been accessed. + ui.lineEdit->setCurrentCharFormat(QTextCharFormat ()); + setFont(); /* redraw send list */ @@ -1598,45 +1597,54 @@ void PeersDialog::insertSendList() void PeersDialog::setColor() { + bool ok; + QRgb color = QColorDialog::getRgba(ui.lineEdit->textColor().rgba(), &ok, this); + if (ok) { + mCurrentColor = QColor(color); + colorChanged(mCurrentColor); + } + setFont(); +} - bool ok; - QRgb color = QColorDialog::getRgba(ui.lineEdit->textColor().rgba(), &ok, this); - if (ok) { - _currentColor = QColor(color); - QPixmap pxm(16,16); - pxm.fill(_currentColor); - ui.colorChatButton->setIcon(pxm); - } - setFont(); +void PeersDialog::colorChanged(const QColor &c) +{ + QPixmap pxm(16,16); + pxm.fill(mCurrentColor); + ui.colorChatButton->setIcon(pxm); } void PeersDialog::getFont() { bool ok; mCurrentFont = QFontDialog::getFont(&ok, mCurrentFont, this); + if (ok) { + fontChanged(mCurrentFont); + } +} + +void PeersDialog::fontChanged(const QFont &font) +{ + mCurrentFont = font; + + ui.textboldChatButton->setChecked(mCurrentFont.bold()); + ui.textunderlineChatButton->setChecked(mCurrentFont.underline()); + ui.textitalicChatButton->setChecked(mCurrentFont.italic()); + setFont(); } void PeersDialog::setFont() { - mCurrentFont.setBold(ui.textboldChatButton->isChecked()); - mCurrentFont.setUnderline(ui.textunderlineChatButton->isChecked()); - mCurrentFont.setItalic(ui.textitalicChatButton->isChecked()); - ui.lineEdit->setFont(mCurrentFont); - ui.lineEdit->setTextColor(_currentColor); - Settings->setChatScreenFont(mCurrentFont.toString()); - - ui.lineEdit->setFocus(); + mCurrentFont.setBold(ui.textboldChatButton->isChecked()); + mCurrentFont.setUnderline(ui.textunderlineChatButton->isChecked()); + mCurrentFont.setItalic(ui.textitalicChatButton->isChecked()); + ui.lineEdit->setFont(mCurrentFont); + ui.lineEdit->setTextColor(mCurrentColor); + Settings->setChatScreenFont(mCurrentFont.toString()); + ui.lineEdit->setFocus(); } -void PeersDialog::underline() -{ - _underline = !_underline; - ui.lineEdit->setFontUnderline(_underline); -} - - // Update Chat Info information void PeersDialog::setChatInfo(QString info, QColor color) { diff --git a/retroshare-gui/src/gui/PeersDialog.h b/retroshare-gui/src/gui/PeersDialog.h index 3cb02e571..9342bf01c 100644 --- a/retroshare-gui/src/gui/PeersDialog.h +++ b/retroshare-gui/src/gui/PeersDialog.h @@ -144,7 +144,6 @@ private slots: void setFont(); void getFont(); - void underline(); void changeAvatarClicked(); void getAvatar(); @@ -175,6 +174,9 @@ private: void processSettings(bool bLoad); void addChatMsg(bool incoming, bool history, QString &name, QDateTime &recvTime, QString &message); + void colorChanged(const QColor &c); + void fontChanged(const QFont &font); + class QLabel *iconLabel, *textLabel; class QWidget *widget; class QWidgetAction *widgetAction; @@ -201,8 +203,7 @@ private: IMHistoryKeeper historyKeeper; ChatStyle style; - QColor _currentColor; - bool _underline; + QColor mCurrentColor; time_t last_status_send_time ; QFont mCurrentFont; /* how the text will come out */ diff --git a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp index b89a5e65e..9011126cb 100644 --- a/retroshare-gui/src/gui/chat/PopupChatDialog.cpp +++ b/retroshare-gui/src/gui/chat/PopupChatDialog.cpp @@ -761,6 +761,10 @@ void PopupChatDialog::sendChat() } chatWidget->clear(); + // workaround for Qt bug - http://bugreports.qt.nokia.com/browse/QTBUG-2533 + // QTextEdit::clear() does not reset the CharFormat if document contains hyperlinks that have been accessed. + chatWidget->setCurrentCharFormat(QTextCharFormat ()); + setFont(); /* redraw send list */