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

Commit

Permalink
feat: edit reload themes
Browse files Browse the repository at this point in the history
  • Loading branch information
TriKriSta committed Feb 21, 2019
1 parent 5bc27b0 commit e146c11
Show file tree
Hide file tree
Showing 22 changed files with 224 additions and 83 deletions.
7 changes: 7 additions & 0 deletions src/chatlog/chatline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ void ChatLine::fontChanged(const QFont& font)
c->fontChanged(font);
}

void ChatLine::reloadTheme()
{
for (ChatLineContent* c : content) {
c->reloadTheme();
}
}

int ChatLine::getColumnCount()
{
return content.size();
Expand Down
1 change: 1 addition & 0 deletions src/chatlog/chatline.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class ChatLine
void selectionCleared();
void selectionFocusChanged(bool focusIn);
void fontChanged(const QFont& font);
void reloadTheme();

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 @@ -88,6 +88,10 @@ void ChatLineContent::visibilityChanged(bool)
{
}

void ChatLineContent::reloadTheme()
{
}

QString ChatLineContent::getText() const
{
return QString();
Expand Down
1 change: 1 addition & 0 deletions src/chatlog/chatlinecontent.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ChatLineContent : public QObject, public QGraphicsItem
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) = 0;

virtual void visibilityChanged(bool visible);
virtual void reloadTheme();

private:
friend class ChatLine;
Expand Down
9 changes: 9 additions & 0 deletions src/chatlog/chatlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,15 @@ void ChatLog::fontChanged(const QFont& font)
}
}

void ChatLog::reloadTheme()
{
setBackgroundBrush(QBrush(Style::getColor(Style::White), Qt::SolidPattern));

for (ChatLine::Ptr l : lines) {
l->reloadTheme();
}
}

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 @@ -53,6 +53,7 @@ class ChatLog : public QGraphicsView
void scrollToLine(ChatLine::Ptr line);
void selectAll();
void fontChanged(const QFont& font);
void reloadTheme();

QString getSelectedText() const;

Expand Down
19 changes: 7 additions & 12 deletions src/chatlog/chatmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt
QString text = rawMessage.toHtmlEscaped();
QString senderText = sender;

const QColor actionColor = Style::getColor(Style::Action);

auto textType = Text::NORMAL;
// smileys
if (Settings::getInstance().getUseEmoticons())
text = SmileyPack::getInstance().smileyfied(text);
Expand All @@ -72,6 +71,7 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt
text = wrapDiv(text, "msg");
break;
case ACTION:
textType = Text::ACTION;
senderText = "*";
text = wrapDiv(QString("%1 %2").arg(sender.toHtmlEscaped(), text), "action");
msg->setAsAction();
Expand All @@ -88,23 +88,18 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt
authorFont.setBold(true);

QColor color = Style::getColor(Style::Black);
QColor authorColor;

if (colorizeName && Settings::getInstance().getEnableGroupChatsColor())
{
if (colorizeName && Settings::getInstance().getEnableGroupChatsColor()) {
QByteArray hash = QCryptographicHash::hash((sender.toUtf8()), QCryptographicHash::Sha256);
quint8 *data = (quint8*)hash.data();

authorColor.setHsv(data[0], 255, 196);
color.setHsv(data[0], 255, 196);

if (!isMe)
{
color = authorColor;
if (!isMe && textType == Text::NORMAL) {
textType = Text::CUSTOM;
}
}

msg->addColumn(new Text(senderText, authorFont, true, sender,
type == ACTION ? actionColor : color),
msg->addColumn(new Text(senderText, authorFont, true, sender, textType, color),
ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
msg->addColumn(new Text(text, baseFont, false, ((type == ACTION) && isMe)
? QString("%1 %2").arg(sender, rawMessage)
Expand Down
28 changes: 25 additions & 3 deletions src/chatlog/content/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@
static const QString COLOR_HIGHLIGHT = QStringLiteral("#ff7626");

Text::Text(const QString& txt, const QFont& font, bool enableElide, const QString& rwText,
const QColor c)
const TextType& type, const QColor& custom)
: rawText(rwText)
, elide(enableElide)
, defFont(font)
, defStyleSheet(Style::getStylesheet(QStringLiteral("chatArea/innerStyle.css"), font))
, color(c)
, textType(type)
, customColor(custom)
{
QString ct = c.name();
color = textColor();
setText(txt);
setAcceptedMouseButtons(Qt::LeftButton);
setAcceptHoverEvents(true);
Expand Down Expand Up @@ -247,6 +248,15 @@ void Text::visibilityChanged(bool visible)
update();
}

void Text::reloadTheme()
{
defStyleSheet = Style::getStylesheet(QStringLiteral("chatArea/innerStyle.css"), defFont);
color = textColor();
dirty = true;
regenerate();
update();
}

qreal Text::getAscent() const
{
return ascent;
Expand Down Expand Up @@ -458,3 +468,15 @@ void Text::selectText(QTextCursor& cursor, const std::pair<int, int>& point)
update();
}
}

QColor Text::textColor() const
{
QColor c = Style::getColor(Style::Black);
if (textType == ACTION) {
c = Style::getColor(Style::Action);
} else if (textType == CUSTOM) {
c = customColor;
}

return c;
}
15 changes: 13 additions & 2 deletions src/chatlog/content/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ class Text : public ChatLineContent
Q_OBJECT

public:
enum TextType
{
NORMAL,
ACTION,
CUSTOM
};

Text(const QString& txt = "", const QFont& font = QFont(), bool enableElide = false,
const QString& rawText = QString(), const QColor c = Style::getColor(Style::Black));
const QString& rawText = QString(), const TextType& type = NORMAL, const QColor& custom = Style::getColor(Style::Black));
virtual ~Text();

void setText(const QString& txt);
Expand All @@ -57,11 +64,12 @@ class Text : public ChatLineContent
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) final;

virtual void visibilityChanged(bool keepInMemory) final;
virtual void reloadTheme() final override;

virtual qreal getAscent() const final;
virtual void mousePressEvent(QGraphicsSceneMouseEvent* event) final override;
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) final override;
void hoverMoveEvent(QGraphicsSceneHoverEvent* event) final override;
void hoverMoveEvent(QGraphicsSceneHoverEvent* event) final override;

virtual QString getText() const final;
QString getLinkAt(QPointF scenePos) const;
Expand All @@ -85,6 +93,7 @@ class Text : public ChatLineContent

private:
void selectText(QTextCursor& cursor, const std::pair<int, int>& point);
QColor textColor() const;

QString text;
QString rawText;
Expand All @@ -98,7 +107,9 @@ class Text : public ChatLineContent
qreal ascent = 0.0;
QFont defFont;
QString defStyleSheet;
TextType textType;
QColor color;
QColor customColor;
};

#endif // TEXT_H
8 changes: 8 additions & 0 deletions src/widget/chatformheader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@ QSize ChatFormHeader::getAvatarSize() const
return QSize{avatar->width(), avatar->height()};
}

void ChatFormHeader::reloadTheme()
{
callButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));
videoButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));
volButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));
micButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));
}

void ChatFormHeader::addWidget(QWidget* widget, int stretch, Qt::Alignment alignment)
{
headTextLayout->addWidget(widget, stretch, alignment);
Expand Down
2 changes: 2 additions & 0 deletions src/widget/chatformheader.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class ChatFormHeader : public QWidget
void setAvatar(const QPixmap& img);
QSize getAvatarSize() const;

void reloadTheme();

// TODO: Remove
void addWidget(QWidget* widget, int stretch = 0, Qt::Alignment alignment = Qt::Alignment());
void addLayout(QLayout* layout);
Expand Down
13 changes: 9 additions & 4 deletions src/widget/contentlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ ContentLayout::~ContentLayout()
mainContent->deleteLater();
}

void ContentLayout::reloadTheme()
{
#ifndef Q_OS_MAC
mainHead->setStyleSheet(Style::getStylesheet("settings/mainHead.css"));
mainContent->setStyleSheet(Style::getStylesheet("settings/mainContent.css"));
#endif
}

void ContentLayout::clear()
{
QLayoutItem* item;
Expand Down Expand Up @@ -110,10 +118,7 @@ void ContentLayout::init()
mainContent->setStyle(QStyleFactory::create(Settings::getInstance().getStyle()));
}

#ifndef Q_OS_MAC
mainHead->setStyleSheet(Style::getStylesheet("settings/mainHead.css"));
mainContent->setStyleSheet(Style::getStylesheet("settings/mainContent.css"));
#endif
reloadTheme();

mainHLineLayout.addWidget(&mainHLine);
mainHLineLayout.addSpacing(5);
Expand Down
1 change: 1 addition & 0 deletions src/widget/contentlayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ContentLayout : public QVBoxLayout
explicit ContentLayout(QWidget* parent);
~ContentLayout();

void reloadTheme();
void clear();

QFrame mainHLine;
Expand Down
27 changes: 21 additions & 6 deletions src/widget/form/genericchatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,6 @@ GenericChatForm::GenericChatForm(const Contact* contact, QWidget* parent)
fileLayout->setSpacing(0);
fileLayout->setMargin(0);

setStyleSheet(Style::getStylesheet("genericChatForm/genericChatForm.css"));

msgEdit->setStyleSheet(Style::getStylesheet("msgEdit/msgEdit.css")
+ fontToCss(s.getChatMessageFont(), "QTextEdit"));
msgEdit->setFixedHeight(MESSAGE_EDIT_HEIGHT);
msgEdit->setFrameStyle(QFrame::NoFrame);

Expand Down Expand Up @@ -240,8 +236,7 @@ GenericChatForm::GenericChatForm(const Contact* contact, QWidget* parent)

connect(chatWidget, &ChatLog::workerTimeoutFinished, this, &GenericChatForm::onContinueSearch);

chatWidget->setStyleSheet(Style::getStylesheet("chatArea/chatArea.css"));
headWidget->setStyleSheet(Style::getStylesheet("chatArea/chatHead.css"));
reloadTheme();

fileFlyout->setFixedSize(FILE_FLYOUT_SIZE);
fileFlyout->setParent(this);
Expand Down Expand Up @@ -295,6 +290,26 @@ QDate GenericChatForm::getFirstDate() const
return getDate(chatWidget->getFirstLine());
}

void GenericChatForm::reloadTheme()
{
const Settings& s = Settings::getInstance();
setStyleSheet(Style::getStylesheet("genericChatForm/genericChatForm.css"));

msgEdit->setStyleSheet(Style::getStylesheet("msgEdit/msgEdit.css")
+ fontToCss(s.getChatMessageFont(), "QTextEdit"));

chatWidget->setStyleSheet(Style::getStylesheet("chatArea/chatArea.css"));
headWidget->setStyleSheet(Style::getStylesheet("chatArea/chatHead.css"));
chatWidget->reloadTheme();
headWidget->reloadTheme();
searchForm->reloadTheme();

emoteButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));
fileButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));
screenshotButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));
sendButton->setStyleSheet(Style::getStylesheet(STYLE_PATH));
}

void GenericChatForm::setName(const QString& newName)
{
headWidget->setName(newName);
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
static QString resolveToxPk(const ToxPk& pk);
QDate getLatestDate() const;
QDate getFirstDate() const;
void reloadTheme();

signals:
void sendMessage(uint32_t, QString);
Expand Down
9 changes: 7 additions & 2 deletions src/widget/form/searchsettingsform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ SearchSettingsForm::SearchSettingsForm(QWidget *parent) :

ui->choiceDateButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
ui->choiceDateButton->setObjectName(QStringLiteral("choiceDateButton"));
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css")));

ui->startDateLabel->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/labels.css")));
reloadTheme();

connect(ui->startSearchComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &SearchSettingsForm::onStartSearchSelected);
Expand Down Expand Up @@ -75,6 +74,12 @@ ParameterSearch SearchSettingsForm::getParameterSearch()
return ps;
}

void SearchSettingsForm::reloadTheme()
{
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css")));
ui->startDateLabel->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/labels.css")));
}

void SearchSettingsForm::updateStartDateLabel()
{
ui->startDateLabel->setText(startDate.toString(Settings::getInstance().getDateFormat()));
Expand Down
1 change: 1 addition & 0 deletions src/widget/form/searchsettingsform.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SearchSettingsForm : public QWidget
~SearchSettingsForm();

ParameterSearch getParameterSearch();
void reloadTheme();

private:
Ui::SearchSettingsForm *ui;
Expand Down
11 changes: 11 additions & 0 deletions src/widget/searchform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ void SearchForm::insertEditor(const QString &text)
searchLine->insert(text);
}

void SearchForm::reloadTheme()
{
settingsButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css")));
upButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css")));
downButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css")));
hideButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css")));
startButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css")));

settings->reloadTheme();
}

void SearchForm::showEvent(QShowEvent* event)
{
QWidget::showEvent(event);
Expand Down
1 change: 1 addition & 0 deletions src/widget/searchform.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class SearchForm final : public QWidget
ParameterSearch getParameterSearch();
void setFocusEditor();
void insertEditor(const QString &text);
void reloadTheme();

protected:
virtual void showEvent(QShowEvent* event) final override;
Expand Down

0 comments on commit e146c11

Please sign in to comment.