Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4137
Browse files Browse the repository at this point in the history
Yuri (1):
      fix(font): Made font changes in settings apply on screen instantly.
  • Loading branch information
sudden6 committed Feb 6, 2017
2 parents a6bc9db + 742583b commit d320b1f
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/chatlog/chatline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ void ChatLine::selectionFocusChanged(bool focusIn)
c->selectionFocusChanged(focusIn);
}

void ChatLine::fontChanged(const QFont& font)
{
for (ChatLineContent* c : content)
c->fontChanged(font);
}

int ChatLine::getColumnCount()
{
return content.size();
Expand Down
2 changes: 2 additions & 0 deletions src/chatlog/chatline.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ChatLog;
class ChatLineContent;
class QGraphicsScene;
class QStyleOptionGraphicsItem;
class QFont;

struct ColumnFormat
{
Expand Down Expand Up @@ -75,6 +76,7 @@ class ChatLine
void setVisible(bool visible);
void selectionCleared();
void selectionFocusChanged(bool focusIn);
void fontChanged(const QFont& font);

int getColumnCount();
int getRow() const;
Expand Down
4 changes: 4 additions & 0 deletions src/chatlog/chatlinecontent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ QString ChatLineContent::getSelectedText() const
return QString();
}

void ChatLineContent::fontChanged(const QFont& font)
{
}

qreal ChatLineContent::getAscent() const
{
return 0.0;
Expand Down
1 change: 1 addition & 0 deletions src/chatlog/chatlinecontent.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ChatLineContent : public QObject, public QGraphicsItem
virtual void selectionFocusChanged(bool focusIn);
virtual bool isOverSelection(QPointF scenePos) const;
virtual QString getSelectedText() const;
virtual void fontChanged(const QFont& font);

virtual QString getText() const;

Expand Down
8 changes: 8 additions & 0 deletions src/chatlog/chatlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,14 @@ void ChatLog::selectAll()
updateMultiSelectionRect();
}

void ChatLog::fontChanged(const QFont& font)
{
for (ChatLine::Ptr l : lines)
{
l->fontChanged(font);
}
}

void ChatLog::forceRelayout()
{
startResizeWorker();
Expand Down
1 change: 1 addition & 0 deletions src/chatlog/chatlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ChatLog : public QGraphicsView
void setTypingNotificationVisible(bool visible);
void scrollToLine(ChatLine::Ptr line);
void selectAll();
void fontChanged(const QFont& font);

QString getSelectedText() const;

Expand Down
5 changes: 5 additions & 0 deletions src/chatlog/content/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ QString Text::getSelectedText() const
return selectedText;
}

void Text::fontChanged(const QFont& font)
{
defFont = font;
}

QRectF Text::boundingRect() const
{
return QRectF(QPointF(0, 0), size);
Expand Down
1 change: 1 addition & 0 deletions src/chatlog/content/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Text : public ChatLineContent
virtual void selectionFocusChanged(bool focusIn) final;
virtual bool isOverSelection(QPointF scenePos) const final;
virtual QString getSelectedText() const final;
virtual void fontChanged(const QFont& font) final;

virtual QRectF boundingRect() const final;
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) final;
Expand Down
11 changes: 11 additions & 0 deletions src/widget/form/genericchatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ GenericChatForm::GenericChatForm(QWidget *parent)
const Settings& s = Settings::getInstance();
connect(&s, &Settings::emojiFontPointSizeChanged,
chatWidget, &ChatLog::forceRelayout);
connect(&s, &Settings::chatMessageFontChanged,
this, &GenericChatForm::onChatMessageFontChanged);

msgEdit = new ChatTextEdit();

Expand Down Expand Up @@ -479,6 +481,15 @@ void GenericChatForm::focusInput()
msgEdit->setFocus();
}

void GenericChatForm::onChatMessageFontChanged(const QFont& font) {
// chat log
chatWidget->fontChanged(font);
chatWidget->forceRelayout();
// message editor
msgEdit->setStyleSheet(Style::getStylesheet(":/ui/msgEdit/msgEdit.css")
+ fontToCss(font, "QTextEdit"));
}

void GenericChatForm::addSystemInfoMessage(const QString &message, ChatMessage::SystemMessageType type, const QDateTime &datetime)
{
previousId = ToxPk();
Expand Down
1 change: 1 addition & 0 deletions src/widget/form/genericchatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class GenericChatForm : public QWidget

public slots:
void focusInput();
void onChatMessageFontChanged(const QFont& font);

protected slots:
void onChatContextMenuRequested(QPoint pos);
Expand Down

0 comments on commit d320b1f

Please sign in to comment.