refactor: Move Style global shared state into class

reviewable/pr6564/r1
Anthony Bilinski 2022-03-12 04:20:22 -08:00
parent d7b67081e5
commit b067aae207
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
72 changed files with 462 additions and 325 deletions

View File

@ -41,9 +41,11 @@
#define TIME_COL_WIDTH 90.0
ChatMessage::ChatMessage(DocumentCache& documentCache_, Settings& settings_)
ChatMessage::ChatMessage(DocumentCache& documentCache_, Settings& settings_,
Style& style_)
: documentCache{documentCache_}
, settings{settings_}
, style{style_}
{
}
@ -53,9 +55,9 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt
MessageType type, bool isMe, MessageState state,
const QDateTime& date, DocumentCache& documentCache,
SmileyPack& smileyPack, Settings& settings,
bool colorizeName)
Style& style, bool colorizeName)
{
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache, settings));
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache, settings, style));
QString text = rawMessage.toHtmlEscaped();
QString senderText = sender;
@ -97,7 +99,7 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt
if (isMe)
authorFont.setBold(true);
QColor color = Style::getColor(Style::ColorPalette::MainText);
QColor color = style.getColor(Style::ColorPalette::MainText);
if (colorizeName) {
QByteArray hash = QCryptographicHash::hash((sender.toUtf8()), QCryptographicHash::Sha256);
auto lightness = color.lightnessF();
@ -112,9 +114,9 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt
}
}
msg->addColumn(new Text(documentCache, settings, senderText, authorFont, true, sender, textType, color),
msg->addColumn(new Text(documentCache, settings, style, color, senderText, authorFont, true, sender, textType),
ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
msg->addColumn(new Text(documentCache, settings, text, baseFont, false, ((type == ACTION) && isMe)
msg->addColumn(new Text(documentCache, settings, style, text, baseFont, false, ((type == ACTION) && isMe)
? QString("%1 %2").arg(sender, rawMessage)
: rawMessage),
ColumnFormat(1.0, ColumnFormat::VariableSize));
@ -122,15 +124,15 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt
switch (state) {
case MessageState::complete:
msg->addColumn(new Timestamp(date, settings.getTimestampFormat(),
baseFont, documentCache, settings),
baseFont, documentCache, settings, style),
ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
break;
case MessageState::pending:
msg->addColumn(new Spinner(Style::getImagePath("chatArea/spinner.svg", settings), QSize(16, 16), 360.0 / 1.6),
msg->addColumn(new Spinner(style.getImagePath("chatArea/spinner.svg", settings), QSize(16, 16), 360.0 / 1.6),
ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
break;
case MessageState::broken:
msg->addColumn(new Broken(Style::getImagePath("chatArea/error.svg", settings), QSize(16, 16)),
msg->addColumn(new Broken(style.getImagePath("chatArea/error.svg", settings), QSize(16, 16)),
ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
break;
}
@ -139,21 +141,22 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt
ChatMessage::Ptr ChatMessage::createChatInfoMessage(const QString& rawMessage,
SystemMessageType type, const QDateTime& date,
DocumentCache& documentCache, Settings& settings)
DocumentCache& documentCache, Settings& settings,
Style& style)
{
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache, settings));
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache, settings, style));
QString text = rawMessage.toHtmlEscaped();
QString img;
switch (type) {
case INFO:
img = Style::getImagePath("chatArea/info.svg", settings);
img = style.getImagePath("chatArea/info.svg", settings);
break;
case ERROR:
img = Style::getImagePath("chatArea/error.svg", settings);
img = style.getImagePath("chatArea/error.svg", settings);
break;
case TYPING:
img = Style::getImagePath("chatArea/typing.svg", settings);
img = style.getImagePath("chatArea/typing.svg", settings);
break;
}
@ -161,10 +164,10 @@ ChatMessage::Ptr ChatMessage::createChatInfoMessage(const QString& rawMessage,
msg->addColumn(new Image(QSize(18, 18), img),
ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
msg->addColumn(new Text(documentCache, settings, "<b>" + text + "</b>", baseFont, false, text),
msg->addColumn(new Text(documentCache, settings, style, "<b>" + text + "</b>", baseFont, false, text),
ColumnFormat(1.0, ColumnFormat::VariableSize, ColumnFormat::Left));
msg->addColumn(new Timestamp(date, settings.getTimestampFormat(),
baseFont, documentCache, settings),
baseFont, documentCache, settings, style),
ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
return msg;
@ -173,9 +176,9 @@ ChatMessage::Ptr ChatMessage::createChatInfoMessage(const QString& rawMessage,
ChatMessage::Ptr ChatMessage::createFileTransferMessage(const QString& sender, CoreFile& coreFile,
ToxFile file, bool isMe, const QDateTime& date,
DocumentCache& documentCache,
Settings& settings)
Settings& settings, Style& style)
{
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache, settings));
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache, settings, style));
QFont baseFont = settings.getChatMessageFont();
QFont authorFont = baseFont;
@ -183,21 +186,22 @@ ChatMessage::Ptr ChatMessage::createFileTransferMessage(const QString& sender, C
authorFont.setBold(true);
}
msg->addColumn(new Text(documentCache, settings, sender, authorFont, true),
msg->addColumn(new Text(documentCache, settings, style, sender, authorFont, true),
ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
msg->addColumn(new ChatLineContentProxy(new FileTransferWidget(nullptr, coreFile, file, settings), 320, 0.6f),
msg->addColumn(new ChatLineContentProxy(new FileTransferWidget(
nullptr, coreFile, file, settings, style), 320, 0.6f),
ColumnFormat(1.0, ColumnFormat::VariableSize));
msg->addColumn(new Timestamp(date, settings.getTimestampFormat(), baseFont,
documentCache, settings),
documentCache, settings, style),
ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
return msg;
}
ChatMessage::Ptr ChatMessage::createTypingNotification(DocumentCache& documentCache,
Settings& settings)
Settings& settings, Style& style)
{
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache, settings));
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache, settings, style));
QFont baseFont = settings.getChatMessageFont();
@ -208,9 +212,9 @@ ChatMessage::Ptr ChatMessage::createTypingNotification(DocumentCache& documentCa
// user received typing notifications constantly since contact came online.
// This causes "[user]..." to be displayed in place of user nick, as long
// as user will keep typing. Issue #1280
msg->addColumn(new NotificationIcon(settings, QSize(18, 18)),
msg->addColumn(new NotificationIcon(settings, style, QSize(18, 18)),
ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
msg->addColumn(new Text(documentCache, settings, "[user]...", baseFont, false, ""),
msg->addColumn(new Text(documentCache, settings, style, "[user]...", baseFont, false, ""),
ColumnFormat(1.0, ColumnFormat::VariableSize, ColumnFormat::Left));
return msg;
@ -225,14 +229,14 @@ ChatMessage::Ptr ChatMessage::createTypingNotification(DocumentCache& documentCa
* @return created message
*/
ChatMessage::Ptr ChatMessage::createBusyNotification(DocumentCache& documentCache,
Settings& settings)
Settings& settings, Style& style)
{
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache, settings));
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache, settings, style));
QFont baseFont = settings.getChatMessageFont();
baseFont.setPixelSize(baseFont.pixelSize() + 2);
baseFont.setBold(true);
msg->addColumn(new Text(documentCache, settings, QObject::tr("Reformatting text...", "Waiting for text to be reformatted"), baseFont, false, ""),
msg->addColumn(new Text(documentCache, settings, style, QObject::tr("Reformatting text...", "Waiting for text to be reformatted"), baseFont, false, ""),
ColumnFormat(1.0, ColumnFormat::VariableSize, ColumnFormat::Center));
return msg;
@ -244,12 +248,12 @@ void ChatMessage::markAsDelivered(const QDateTime& time)
// remove the spinner and replace it by $time
replaceContent(2, new Timestamp(time, settings.getTimestampFormat(),
baseFont, documentCache, settings));
baseFont, documentCache, settings, style));
}
void ChatMessage::markAsBroken()
{
replaceContent(2, new Broken(Style::getImagePath("chatArea/error.svg", settings), QSize(16, 16)));
replaceContent(2, new Broken(style.getImagePath("chatArea/error.svg", settings), QSize(16, 16)));
}
QString ChatMessage::toString() const

View File

@ -30,6 +30,7 @@ class QGraphicsScene;
class DocumentCache;
class SmileyPack;
class Settings;
class Style;
class ChatMessage : public ChatLine
{
@ -50,7 +51,7 @@ public:
ALERT,
};
ChatMessage(DocumentCache& documentCache, Settings& settings);
ChatMessage(DocumentCache& documentCache, Settings& settings, Style& style);
~ChatMessage();
ChatMessage(const ChatMessage&) = default;
ChatMessage(ChatMessage&&) = default;
@ -58,14 +59,15 @@ public:
static ChatMessage::Ptr createChatMessage(const QString& sender, const QString& rawMessage,
MessageType type, bool isMe, MessageState state,
const QDateTime& date, DocumentCache& documentCache,
SmileyPack& smileyPack, Settings& settings, bool colorizeName = false);
SmileyPack& smileyPack, Settings& settings, Style& style, bool colorizeName = false);
static ChatMessage::Ptr createChatInfoMessage(const QString& rawMessage, SystemMessageType type,
const QDateTime& date, DocumentCache& documentCache, Settings& settings);
const QDateTime& date, DocumentCache& documentCache, Settings& settings,
Style& style);
static ChatMessage::Ptr createFileTransferMessage(const QString& sender, CoreFile& coreFile,
ToxFile file, bool isMe, const QDateTime& date,
DocumentCache& documentCache, Settings& settings);
static ChatMessage::Ptr createTypingNotification(DocumentCache& documentCache, Settings& settings);
static ChatMessage::Ptr createBusyNotification(DocumentCache& documentCache, Settings& settings);
DocumentCache& documentCache, Settings& settings, Style& style);
static ChatMessage::Ptr createTypingNotification(DocumentCache& documentCache, Settings& settings, Style& style);
static ChatMessage::Ptr createBusyNotification(DocumentCache& documentCache, Settings& settings, Style& style);
void markAsDelivered(const QDateTime& time);
void markAsBroken();
@ -83,4 +85,5 @@ private:
bool action = false;
DocumentCache& documentCache;
Settings& settings;
Style& style;
};

View File

@ -62,16 +62,18 @@ T clamp(T x, T min, T max)
return x;
}
ChatMessage::Ptr createDateMessage(QDateTime timestamp, DocumentCache& documentCache, Settings& settings)
ChatMessage::Ptr createDateMessage(QDateTime timestamp, DocumentCache& documentCache,
Settings& settings, Style& style)
{
const auto date = timestamp.date();
auto dateText = date.toString(settings.getDateFormat());
return ChatMessage::createChatInfoMessage(dateText, ChatMessage::INFO, QDateTime(), documentCache, settings);
return ChatMessage::createChatInfoMessage(dateText, ChatMessage::INFO, QDateTime(),
documentCache, settings, style);
}
ChatMessage::Ptr createMessage(const QString& displayName, bool isSelf, bool colorizeNames,
const ChatLogMessage& chatLogMessage, DocumentCache& documentCache,
SmileyPack& smileyPack, Settings& settings)
SmileyPack& smileyPack, Settings& settings, Style& style)
{
auto messageType = chatLogMessage.message.isAction ? ChatMessage::MessageType::ACTION
: ChatMessage::MessageType::NORMAL;
@ -87,14 +89,15 @@ ChatMessage::Ptr createMessage(const QString& displayName, bool isSelf, bool col
}
const auto timestamp = chatLogMessage.message.timestamp;
return ChatMessage::createChatMessage(displayName, chatLogMessage.message.content, messageType,
return ChatMessage::createChatMessage(displayName, chatLogMessage.message.content,messageType,
isSelf, chatLogMessage.state, timestamp, documentCache,
smileyPack, settings, colorizeNames);
smileyPack, settings, style, colorizeNames);
}
void renderMessageRaw(const QString& displayName, bool isSelf, bool colorizeNames,
const ChatLogMessage& chatLogMessage, ChatLine::Ptr& chatLine,
DocumentCache& documentCache, SmileyPack& smileyPack, Settings& settings)
DocumentCache& documentCache, SmileyPack& smileyPack,
Settings& settings, Style& style)
{
// HACK: This is kind of gross, but there's not an easy way to fit this into
// the existing architecture. This shouldn't ever fail since we should only
@ -111,7 +114,7 @@ void renderMessageRaw(const QString& displayName, bool isSelf, bool colorizeName
}
} else {
chatLine = createMessage(displayName, isSelf, colorizeNames, chatLogMessage,
documentCache, smileyPack, settings);
documentCache, smileyPack, settings, style);
}
}
@ -208,14 +211,16 @@ ChatLogIdx clampedAdd(ChatLogIdx idx, int val, IChatLog& chatLog)
ChatWidget::ChatWidget(IChatLog& chatLog_, const Core& core_, DocumentCache& documentCache_,
SmileyPack& smileyPack_, Settings& settings_, QWidget* parent)
SmileyPack& smileyPack_, Settings& settings_, Style& style_, QWidget* parent)
: QGraphicsView(parent)
, selectionRectColor{style_.getColor(Style::ColorPalette::SelectText)}
, chatLog(chatLog_)
, core(core_)
, chatLineStorage(new ChatLineStorage())
, documentCache(documentCache_)
, smileyPack{smileyPack_}
, settings(settings_)
, style{style_}
{
// Create the scene
busyScene = new QGraphicsScene(this);
@ -223,7 +228,7 @@ ChatWidget::ChatWidget(IChatLog& chatLog_, const Core& core_, DocumentCache& doc
scene->setItemIndexMethod(QGraphicsScene::BspTreeIndex);
setScene(scene);
busyNotification = ChatMessage::createBusyNotification(documentCache, settings);
busyNotification = ChatMessage::createBusyNotification(documentCache, settings, style);
busyNotification->addToScene(busyScene);
busyNotification->visibilityChanged(true);
@ -235,7 +240,7 @@ ChatWidget::ChatWidget(IChatLog& chatLog_, const Core& core_, DocumentCache& doc
setDragMode(QGraphicsView::NoDrag);
setViewportUpdateMode(MinimalViewportUpdate);
setContextMenuPolicy(Qt::CustomContextMenu);
setBackgroundBrush(QBrush(Style::getColor(Style::ColorPalette::GroundBase), Qt::SolidPattern));
setBackgroundBrush(QBrush(style.getColor(Style::ColorPalette::GroundBase), Qt::SolidPattern));
// The selection rect for multi-line selection
selGraphItem = scene->addRect(0, 0, 0, 0, selectionRectColor.darker(120), selectionRectColor);
@ -548,7 +553,7 @@ void ChatWidget::insertChatlines(std::map<ChatLogIdx, ChatLine::Ptr> chatLines)
if (!chatLineStorage->contains(date)) {
// If there is no dateline for the given date we need to insert it
// above the line we'd like to insert.
auto dateLine = createDateMessage(date, documentCache, settings);
auto dateLine = createDateMessage(date, documentCache, settings, style);
chatLineStorage->insertDateLine(date, dateLine);
dateLine->addToScene(scene);
dateLine->visibilityChanged(false);
@ -797,9 +802,9 @@ void ChatWidget::fontChanged(const QFont& font)
void ChatWidget::reloadTheme()
{
setStyleSheet(Style::getStylesheet("chatArea/chatArea.css", settings));
setBackgroundBrush(QBrush(Style::getColor(Style::ColorPalette::GroundBase), Qt::SolidPattern));
selectionRectColor = Style::getColor(Style::ColorPalette::SelectText);
setStyleSheet(style.getStylesheet("chatArea/chatArea.css", settings));
setBackgroundBrush(QBrush(style.getColor(Style::ColorPalette::GroundBase), Qt::SolidPattern));
selectionRectColor = style.getColor(Style::ColorPalette::SelectText);
selGraphItem->setBrush(QBrush(selectionRectColor));
selGraphItem->setPen(QPen(selectionRectColor.darker(120)));
setTypingNotification();
@ -1401,7 +1406,7 @@ bool ChatWidget::isActiveFileTransfer(ChatLine::Ptr l)
void ChatWidget::setTypingNotification()
{
typingNotification = ChatMessage::createTypingNotification(documentCache, settings);
typingNotification = ChatMessage::createTypingNotification(documentCache, settings, style);
typingNotification->visibilityChanged(true);
typingNotification->setVisible(false);
typingNotification->addToScene(scene);
@ -1420,7 +1425,7 @@ void ChatWidget::renderItem(const ChatLogItem& item, bool hideName, bool coloriz
const auto& chatLogMessage = item.getContentAsMessage();
renderMessageRaw(item.getDisplayName(), isSelf, colorizeNames_, chatLogMessage,
chatMessage, documentCache, smileyPack, settings);
chatMessage, documentCache, smileyPack, settings, style);
break;
}
@ -1434,7 +1439,8 @@ void ChatWidget::renderItem(const ChatLogItem& item, bool hideName, bool coloriz
auto chatMessageType = getChatMessageType(systemMessage);
chatMessage = ChatMessage::createChatInfoMessage(systemMessage.toString(),
chatMessageType, QDateTime::currentDateTime(), documentCache, settings);
chatMessageType, QDateTime::currentDateTime(), documentCache, settings,
style);
// Ignore caller's decision to hide the name. We show the icon in the
// slot of the sender's name so we always want it visible
hideName = false;
@ -1454,7 +1460,7 @@ void ChatWidget::renderFile(QString displayName, ToxFile file, bool isSelf, QDat
CoreFile* coreFile = core.getCoreFile();
assert(coreFile);
chatMessage = ChatMessage::createFileTransferMessage(displayName, *coreFile,
file, isSelf, timestamp, documentCache, settings);
file, isSelf, timestamp, documentCache, settings, style);
} else {
auto proxy = static_cast<ChatLineContentProxy*>(chatMessage->getContent(1));
assert(proxy->getWidgetType() == ChatLineContentProxy::FileTransferWidgetType);

View File

@ -25,7 +25,6 @@
#include "chatline.h"
#include "chatmessage.h"
#include "src/widget/style.h"
#include "src/model/ichatlog.h"
class QGraphicsScene;
@ -36,7 +35,7 @@ class ChatLineContent;
struct ToxFile;
class SmileyPack;
class Settings;
class Style;
class ChatLineStorage;
static const size_t DEF_NUM_MSG_TO_LOAD = 100;
@ -45,7 +44,7 @@ class ChatWidget : public QGraphicsView
Q_OBJECT
public:
ChatWidget(IChatLog& chatLog_, const Core& core_, DocumentCache& documentCache,
SmileyPack& smileyPack, Settings& settings, QWidget* parent = nullptr);
SmileyPack& smileyPack, Settings& settings, Style& style, QWidget* parent = nullptr);
virtual ~ChatWidget();
void insertChatlines(std::map<ChatLogIdx, ChatLine::Ptr> chatLines);
@ -187,7 +186,7 @@ private:
int selClickedCol = -1;
ChatLine::Ptr selFirstRow;
ChatLine::Ptr selLastRow;
QColor selectionRectColor = Style::getColor(Style::ColorPalette::SelectText);
QColor selectionRectColor;
SelectionMode selectionMode = SelectionMode::None;
QPointF clickPos;
QGraphicsRectItem* selGraphItem = nullptr;
@ -220,4 +219,5 @@ private:
DocumentCache& documentCache;
SmileyPack& smileyPack;
Settings& settings;
Style& style;
};

View File

@ -49,16 +49,17 @@
// downloaded to.
FileTransferWidget::FileTransferWidget(QWidget* parent, CoreFile& _coreFile,
ToxFile file, Settings& settings_)
ToxFile file, Settings& settings_, Style& style_)
: QWidget(parent)
, coreFile{_coreFile}
, ui(new Ui::FileTransferWidget)
, fileInfo(file)
, backgroundColor(Style::getColor(Style::ColorPalette::TransferMiddle))
, buttonColor(Style::getColor(Style::ColorPalette::TransferWait))
, buttonBackgroundColor(Style::getColor(Style::ColorPalette::GroundBase))
, backgroundColor(style_.getColor(Style::ColorPalette::TransferMiddle))
, buttonColor(style_.getColor(Style::ColorPalette::TransferWait))
, buttonBackgroundColor(style_.getColor(Style::ColorPalette::GroundBase))
, active(true)
, settings(settings_)
, style{style_}
{
ui->setupUi(this);
@ -160,7 +161,7 @@ void FileTransferWidget::setBackgroundColor(const QColor& c, bool whiteFont)
setProperty("fontColor", whiteFont ? "white" : "black");
setStyleSheet(Style::getStylesheet("fileTransferInstance/filetransferWidget.css", settings));
setStyleSheet(style.getStylesheet("fileTransferInstance/filetransferWidget.css", settings));
Style::repolish(this);
update();
@ -380,46 +381,46 @@ void FileTransferWidget::setupButtons(ToxFile const& file)
switch (file.status) {
case ToxFile::TRANSMITTING:
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/pause.svg", settings)));
ui->leftButton->setIcon(QIcon(style.getImagePath("fileTransferInstance/pause.svg", settings)));
ui->leftButton->setObjectName("pause");
ui->leftButton->setToolTip(tr("Pause transfer"));
ui->rightButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/no.svg", settings)));
ui->rightButton->setIcon(QIcon(style.getImagePath("fileTransferInstance/no.svg", settings)));
ui->rightButton->setObjectName("cancel");
ui->rightButton->setToolTip(tr("Cancel transfer"));
setButtonColor(Style::getColor(Style::ColorPalette::TransferGood));
setButtonColor(style.getColor(Style::ColorPalette::TransferGood));
break;
case ToxFile::PAUSED:
if (file.pauseStatus.localPaused()) {
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/arrow_white.svg", settings)));
ui->leftButton->setIcon(QIcon(style.getImagePath("fileTransferInstance/arrow_white.svg", settings)));
ui->leftButton->setObjectName("resume");
ui->leftButton->setToolTip(tr("Resume transfer"));
} else {
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/pause.svg", settings)));
ui->leftButton->setIcon(QIcon(style.getImagePath("fileTransferInstance/pause.svg", settings)));
ui->leftButton->setObjectName("pause");
ui->leftButton->setToolTip(tr("Pause transfer"));
}
ui->rightButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/no.svg", settings)));
ui->rightButton->setIcon(QIcon(style.getImagePath("fileTransferInstance/no.svg", settings)));
ui->rightButton->setObjectName("cancel");
ui->rightButton->setToolTip(tr("Cancel transfer"));
setButtonColor(Style::getColor(Style::ColorPalette::TransferMiddle));
setButtonColor(style.getColor(Style::ColorPalette::TransferMiddle));
break;
case ToxFile::INITIALIZING:
ui->rightButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/no.svg", settings)));
ui->rightButton->setIcon(QIcon(style.getImagePath("fileTransferInstance/no.svg", settings)));
ui->rightButton->setObjectName("cancel");
ui->rightButton->setToolTip(tr("Cancel transfer"));
if (file.direction == ToxFile::SENDING) {
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/pause.svg", settings)));
ui->leftButton->setIcon(QIcon(style.getImagePath("fileTransferInstance/pause.svg", settings)));
ui->leftButton->setObjectName("pause");
ui->leftButton->setToolTip(tr("Pause transfer"));
} else {
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/yes.svg", settings)));
ui->leftButton->setIcon(QIcon(style.getImagePath("fileTransferInstance/yes.svg", settings)));
ui->leftButton->setObjectName("accept");
ui->leftButton->setToolTip(tr("Accept transfer"));
}
@ -430,12 +431,12 @@ void FileTransferWidget::setupButtons(ToxFile const& file)
ui->rightButton->hide();
break;
case ToxFile::FINISHED:
ui->leftButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/yes.svg", settings)));
ui->leftButton->setIcon(QIcon(style.getImagePath("fileTransferInstance/yes.svg", settings)));
ui->leftButton->setObjectName("ok");
ui->leftButton->setToolTip(tr("Open file"));
ui->leftButton->show();
ui->rightButton->setIcon(QIcon(Style::getImagePath("fileTransferInstance/dir.svg", settings)));
ui->rightButton->setIcon(QIcon(style.getImagePath("fileTransferInstance/dir.svg", settings)));
ui->rightButton->setObjectName("dir");
ui->rightButton->setToolTip(tr("Open file directory"));
ui->rightButton->show();
@ -535,14 +536,14 @@ void FileTransferWidget::updateBackgroundColor(const ToxFile::FileStatus status)
case ToxFile::INITIALIZING:
case ToxFile::PAUSED:
case ToxFile::TRANSMITTING:
setBackgroundColor(Style::getColor(Style::ColorPalette::TransferMiddle), false);
setBackgroundColor(style.getColor(Style::ColorPalette::TransferMiddle), false);
break;
case ToxFile::BROKEN:
case ToxFile::CANCELED:
setBackgroundColor(Style::getColor(Style::ColorPalette::TransferBad), true);
setBackgroundColor(style.getColor(Style::ColorPalette::TransferBad), true);
break;
case ToxFile::FINISHED:
setBackgroundColor(Style::getColor(Style::ColorPalette::TransferGood), true);
setBackgroundColor(style.getColor(Style::ColorPalette::TransferGood), true);
break;
default:
qCritical() << "Invalid file status";

View File

@ -34,13 +34,15 @@ class FileTransferWidget;
class QVariantAnimation;
class QPushButton;
class Settings;
class Style;
class FileTransferWidget : public QWidget
{
Q_OBJECT
public:
FileTransferWidget(QWidget* parent, CoreFile& _coreFile, ToxFile file, Settings& settings);
FileTransferWidget(QWidget* parent, CoreFile& _coreFile, ToxFile file,
Settings& settings, Style& style);
virtual ~FileTransferWidget();
bool isActive() const;
void onFileTransferUpdate(ToxFile file);
@ -90,5 +92,5 @@ private:
QTime lastTransmissionUpdate;
ToxFile::FileStatus lastStatus = ToxFile::INITIALIZING;
Settings& settings;
Style& style;
};

View File

@ -25,10 +25,10 @@
#include <QPainter>
#include <QTimer>
NotificationIcon::NotificationIcon(Settings& settings, QSize Size)
NotificationIcon::NotificationIcon(Settings& settings, Style& style, QSize Size)
: size(Size)
{
pmap = PixmapCache::getInstance().get(Style::getImagePath("chatArea/typing.svg", settings), size);
pmap = PixmapCache::getInstance().get(style.getImagePath("chatArea/typing.svg", settings), size);
// Timer for the animation, if the Widget is not redrawn, no paint events will
// arrive and the timer will not be restarted, so this stops automatically

View File

@ -26,12 +26,13 @@
#include <QTimer>
class Settings;
class Style;
class NotificationIcon : public ChatLineContent
{
Q_OBJECT
public:
explicit NotificationIcon(Settings& settings, QSize size);
NotificationIcon(Settings& settings, Style& style, QSize size);
QRectF boundingRect() const override;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,

View File

@ -31,17 +31,18 @@
#include <QTextBlock>
#include <QTextFragment>
Text::Text(DocumentCache& documentCache_, Settings& settings_, const QString& txt,
const QFont& font, bool enableElide, const QString& rawText_, const TextType& type,
const QColor& custom)
Text::Text(DocumentCache& documentCache_, Settings& settings_, Style& style_,
const QColor& custom, const QString& txt, const QFont& font, bool enableElide,
const QString& rawText_, const TextType& type)
: rawText(rawText_)
, elide(enableElide)
, defFont(font)
, defStyleSheet(Style::getStylesheet(QStringLiteral("chatArea/innerStyle.css"), settings_, font))
, textType(type)
, customColor(custom)
, documentCache(documentCache_)
, settings{settings_}
, defStyleSheet(style_.getStylesheet(QStringLiteral("chatArea/innerStyle.css"), settings_, font))
, style{style_}
{
color = textColor();
setText(txt);
@ -49,6 +50,14 @@ Text::Text(DocumentCache& documentCache_, Settings& settings_, const QString& tx
setAcceptHoverEvents(true);
}
Text::Text(DocumentCache& documentCache_, Settings& settings_, Style& style_,
const QString& txt, const QFont& font, bool enableElide, const QString& rawText_,
const TextType& type)
: Text(documentCache_, settings_, style_, style_.getColor(Style::ColorPalette::MainText),
txt, font, enableElide, rawText_, type)
{
}
Text::~Text()
{
if (doc)
@ -231,7 +240,7 @@ void Text::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWid
sel.cursor.setPosition(getSelectionEnd(), QTextCursor::KeepAnchor);
}
const QColor selectionColor = Style::getColor(Style::ColorPalette::SelectText);
const QColor selectionColor = style.getColor(Style::ColorPalette::SelectText);
sel.format.setBackground(selectionColor.lighter(selectionHasFocus ? 100 : 160));
sel.format.setForeground(selectionHasFocus ? Qt::white : Qt::black);
@ -252,7 +261,7 @@ void Text::visibilityChanged(bool visible)
void Text::reloadTheme()
{
defStyleSheet = Style::getStylesheet(QStringLiteral("chatArea/innerStyle.css"), settings, defFont);
defStyleSheet = style.getStylesheet(QStringLiteral("chatArea/innerStyle.css"), settings, defFont);
color = textColor();
dirty = true;
regenerate();
@ -463,7 +472,7 @@ void Text::selectText(QTextCursor& cursor, const std::pair<int, int>& point)
cursor.endEditBlock();
QTextCharFormat format;
format.setBackground(QBrush(Style::getColor(Style::ColorPalette::SearchHighlighted)));
format.setBackground(QBrush(style.getColor(Style::ColorPalette::SearchHighlighted)));
cursor.mergeCharFormat(format);
regenerate();
@ -473,9 +482,9 @@ void Text::selectText(QTextCursor& cursor, const std::pair<int, int>& point)
QColor Text::textColor() const
{
QColor c = Style::getColor(Style::ColorPalette::MainText);
QColor c = style.getColor(Style::ColorPalette::MainText);
if (textType == ACTION) {
c = Style::getColor(Style::ColorPalette::Action);
c = style.getColor(Style::ColorPalette::Action);
} else if (textType == CUSTOM) {
c = customColor;
}

View File

@ -40,10 +40,13 @@ public:
CUSTOM
};
Text(DocumentCache& documentCache, Settings& settings, const QString& txt = "",
const QFont& font = QFont(), bool enableElide = false,
const QString& rawText = QString(), const TextType& type = NORMAL,
const QColor& custom = Style::getColor(Style::ColorPalette::MainText));
Text(DocumentCache& documentCache, Settings& settings, Style& style, const QColor& custom,
const QString& txt = "", const QFont& font = QFont(),
bool enableElide = false, const QString& rawText = QString(),
const TextType& type = NORMAL);
Text(DocumentCache& documentCache, Settings& settings, Style& style, const QString& txt = "", const QFont& font = QFont(),
bool enableElide = false, const QString& rawText = QString(),
const TextType& type = NORMAL);
virtual ~Text();
void setText(const QString& txt);
@ -109,10 +112,11 @@ private:
int selectionAnchor = -1;
qreal ascent = 0.0;
QFont defFont;
QString defStyleSheet;
TextType textType;
QColor color;
QColor customColor;
DocumentCache& documentCache;
Settings& settings;
QString defStyleSheet;
Style& style;
};

View File

@ -20,8 +20,9 @@
#include "timestamp.h"
Timestamp::Timestamp(const QDateTime& time_, const QString& format,
const QFont& font, DocumentCache& documentCache_, Settings& settings_)
: Text(documentCache_, settings_, time_.toString(format), font, false,
const QFont& font, DocumentCache& documentCache_, Settings& settings_,
Style& style_)
: Text(documentCache_, settings_, style_, time_.toString(format), font, false,
time_.toString(format))
{
time = time_;

View File

@ -26,13 +26,14 @@
class QTextDocument;
class DocumentCache;
class Settings;
class Style;
class Timestamp : public Text
{
Q_OBJECT
public:
Timestamp(const QDateTime& time_, const QString& format, const QFont& font,
DocumentCache& documentCache, Settings& settings);
DocumentCache& documentCache, Settings& settings, Style& style);
QDateTime getTime();
protected:

View File

@ -26,18 +26,22 @@
#include "src/model/status.h"
#include "src/persistence/profile.h"
#include "src/widget/widget.h"
#include "src/widget/style.h"
#include "video/camerasource.h"
#include "widget/gui.h"
#include "widget/loginscreen.h"
#include "audio/audio.h"
#include <QApplication>
#include <QCommandLineParser>
#include <QDebug>
#include <QDesktopWidget>
#include <QThread>
#include <cassert>
#include "audio/audio.h"
#include <vpx/vpx_image.h>
#include <cassert>
#ifdef Q_OS_MAC
#include <QActionGroup>
#include <QMenuBar>
@ -63,6 +67,7 @@ Nexus::Nexus(QObject* parent)
: QObject(parent)
, profile{nullptr}
, widget{nullptr}
, style{new Style()}
{
}
@ -161,7 +166,7 @@ int Nexus::showLogin(const QString& profileName)
delete profile;
profile = nullptr;
LoginScreen loginScreen{*settings, profileName};
LoginScreen loginScreen{*settings, *style, profileName};
connectLoginScreen(loginScreen);
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
@ -230,7 +235,7 @@ void Nexus::showMainGUI()
assert(profile);
// Create GUI
widget = new Widget(*profile, *audioControl, *cameraSource, *settings);
widget = new Widget(*profile, *audioControl, *cameraSource, *settings, *style);
// Start GUI
widget->init();

View File

@ -33,6 +33,7 @@ class LoginScreen;
class Core;
class QCommandLineParser;
class CameraSource;
class Style;
#ifdef Q_OS_MAC
class QMenuBar;
@ -109,4 +110,5 @@ private:
std::unique_ptr<IAudioControl> audioControl;
QCommandLineParser* parser = nullptr;
std::unique_ptr<CameraSource> cameraSource;
std::unique_ptr<Style> style;
};

View File

@ -48,13 +48,14 @@ const auto BTN_STYLE_SHEET_PATH = QStringLiteral("chatForm/fullScreenButtons.css
}
NetCamView::NetCamView(ToxPk friendPk_, CameraSource& cameraSource_,
Settings& settings_, QWidget* parent)
Settings& settings_, Style& style_, QWidget* parent)
: QWidget(parent)
, selfFrame{nullptr}
, friendPk{friendPk_}
, e(false)
, cameraSource{cameraSource_}
, settings{settings_}
, style{style_}
{
verLayout = new QVBoxLayout(this);
setWindowTitle(tr("Tox video"));
@ -79,7 +80,7 @@ NetCamView::NetCamView(ToxPk friendPk_, CameraSource& cameraSource_,
setStyleSheet("NetCamView { background-color: #c1c1c1; }");
buttonPanel = new QFrame(this);
buttonPanel->setStyleSheet(Style::getStylesheet(BTN_STYLE_SHEET_PATH, settings));
buttonPanel->setStyleSheet(style.getStylesheet(BTN_STYLE_SHEET_PATH, settings));
buttonPanel->setGeometry(0, 0, BTN_PANEL_WIDTH, BTN_PANEL_HEIGHT);
QHBoxLayout* buttonPanelLayout = new QHBoxLayout(buttonPanel);
@ -241,7 +242,7 @@ void NetCamView::setShowMessages(bool show, bool notify)
toggleMessagesButton->setText(tr("Show messages"));
if (notify) {
toggleMessagesButton->setIcon(QIcon(Style::getImagePath("chatArea/info.svg", settings)));
toggleMessagesButton->setIcon(QIcon(style.getImagePath("chatArea/info.svg", settings)));
}
}
@ -303,7 +304,7 @@ QPushButton* NetCamView::createButton(const QString& name, const QString& state)
btn->setAttribute(Qt::WA_LayoutUsesWidgetRect);
btn->setObjectName(name);
btn->setProperty("state", QVariant(state));
btn->setStyleSheet(Style::getStylesheet(BTN_STYLE_SHEET_PATH, settings));
btn->setStyleSheet(style.getStylesheet(BTN_STYLE_SHEET_PATH, settings));
return btn;
}
@ -326,7 +327,7 @@ void NetCamView::toggleButtonState(QPushButton* btn)
btn->setProperty("state", BTN_STATE_RED);
}
btn->setStyleSheet(Style::getStylesheet(BTN_STYLE_SHEET_PATH, settings));
btn->setStyleSheet(style.getStylesheet(BTN_STYLE_SHEET_PATH, settings));
}
void NetCamView::updateButtonState(QPushButton* btn, bool active)
@ -337,7 +338,7 @@ void NetCamView::updateButtonState(QPushButton* btn, bool active)
btn->setProperty("state", BTN_STATE_RED);
}
btn->setStyleSheet(Style::getStylesheet(BTN_STYLE_SHEET_PATH, settings));
btn->setStyleSheet(style.getStylesheet(BTN_STYLE_SHEET_PATH, settings));
}
void NetCamView::keyPressEvent(QKeyEvent *event)

View File

@ -36,13 +36,15 @@ class QCloseEvent;
class QShowEvent;
class CameraSource;
class Settings;
class Style;
class NetCamView : public QWidget
{
Q_OBJECT
public:
NetCamView(ToxPk friendPk_, CameraSource& cameraSource, Settings& settings, QWidget* parent = nullptr);
NetCamView(ToxPk friendPk_, CameraSource& cameraSource, Settings& settings,
Style& style, QWidget* parent = nullptr);
~NetCamView();
virtual void show(VideoSource* source, const QString& title);
@ -99,4 +101,5 @@ private:
QPushButton* exitFullScreenButton = nullptr;
CameraSource& cameraSource;
Settings& settings;
Style& style;
};

View File

@ -36,11 +36,13 @@ QString getAutoAcceptDir(const QString& dir)
} // namespace
AboutFriendForm::AboutFriendForm(std::unique_ptr<IAboutFriend> about_, Settings& settings_, QWidget* parent)
AboutFriendForm::AboutFriendForm(std::unique_ptr<IAboutFriend> about_,
Settings& settings_, Style& style_, QWidget* parent)
: QDialog(parent)
, ui(new Ui::AboutFriendForm)
, about{std::move(about_)}
, settings{settings_}
, style{style_}
{
ui->setupUi(this);
ui->label_4->hide();
@ -98,7 +100,7 @@ void AboutFriendForm::onAutoAcceptDirClicked()
void AboutFriendForm::reloadTheme()
{
setStyleSheet(Style::getStylesheet("window/general.css", settings));
setStyleSheet(style.getStylesheet("window/general.css", settings));
}
void AboutFriendForm::onAutoAcceptDirChanged(const QString& path)

View File

@ -31,19 +31,22 @@ class AboutFriendForm;
}
class Settings;
class Style;
class AboutFriendForm : public QDialog
{
Q_OBJECT
public:
AboutFriendForm(std::unique_ptr<IAboutFriend> about, Settings& settings, QWidget* parent = nullptr);
AboutFriendForm(std::unique_ptr<IAboutFriend> about, Settings& settings,
Style& style, QWidget* parent = nullptr);
~AboutFriendForm();
private:
Ui::AboutFriendForm* ui;
const std::unique_ptr<IAboutFriend> about;
Settings& settings;
Style& style;
signals:
void histroyRemoved();

View File

@ -38,9 +38,11 @@ void CategoryWidget::emitChatroomWidget(QLayout* layout, int index)
}
}
CategoryWidget::CategoryWidget(bool compact_, Settings& settings_, QWidget* parent)
CategoryWidget::CategoryWidget(bool compact_, Settings& settings_, Style& style_,
QWidget* parent)
: GenericChatItemWidget(compact_, parent)
, settings{settings_}
, style{style_}
{
container = new QWidget(this);
container->setObjectName("circleWidgetContainer");
@ -50,7 +52,7 @@ CategoryWidget::CategoryWidget(bool compact_, Settings& settings_, QWidget* pare
statusLabel->setObjectName("status");
statusLabel->setTextFormat(Qt::PlainText);
statusPic.setPixmap(QPixmap(Style::getImagePath("chatArea/scrollBarRightArrow.svg", settings)));
statusPic.setPixmap(QPixmap(style.getImagePath("chatArea/scrollBarRightArrow.svg", settings)));
fullLayout = new QVBoxLayout(this);
fullLayout->setSpacing(0);
@ -97,9 +99,9 @@ void CategoryWidget::setExpanded(bool isExpanded, bool save)
QString pixmapPath;
if (isExpanded)
pixmapPath = Style::getImagePath("chatArea/scrollBarDownArrow.svg", settings);
pixmapPath = style.getImagePath("chatArea/scrollBarDownArrow.svg", settings);
else
pixmapPath = Style::getImagePath("chatArea/scrollBarRightArrow.svg", settings);
pixmapPath = style.getImagePath("chatArea/scrollBarRightArrow.svg", settings);
statusPic.setPixmap(QPixmap(pixmapPath));
if (save)

View File

@ -29,12 +29,13 @@ class FriendWidget;
class QVBoxLayout;
class QHBoxLayout;
class Settings;
class Style;
class CategoryWidget : public GenericChatItemWidget
{
Q_OBJECT
public:
explicit CategoryWidget(bool compact_, Settings& settings, QWidget* parent = nullptr);
CategoryWidget(bool compact_, Settings& settings, Style& style, QWidget* parent = nullptr);
bool isExpanded() const;
void setExpanded(bool isExpanded, bool save = true);
@ -86,4 +87,5 @@ private:
QFrame* lineFrame;
bool expanded = false;
Settings& settings;
Style& style;
};

View File

@ -81,12 +81,13 @@ const QString MIC_TOOL_TIP[] = {
};
template <class T, class Fun>
QPushButton* createButton(const QString& name, T* self, Fun onClickSlot, Settings& settings)
QPushButton* createButton(const QString& name, T* self, Fun onClickSlot,
Settings& settings, Style& style)
{
QPushButton* btn = new QPushButton();
btn->setAttribute(Qt::WA_LayoutUsesWidgetRect);
btn->setObjectName(name);
btn->setStyleSheet(Style::getStylesheet(STYLE_PATH, settings));
btn->setStyleSheet(style.getStylesheet(STYLE_PATH, settings));
QObject::connect(btn, &QPushButton::clicked, self, onClickSlot);
return btn;
}
@ -108,7 +109,7 @@ void setStateName(QAbstractButton* btn, State state)
}
ChatFormHeader::ChatFormHeader(Settings& settings_, QWidget* parent)
ChatFormHeader::ChatFormHeader(Settings& settings_, Style& style_, QWidget* parent)
: QWidget(parent)
, mode{Mode::AV}
, callState{CallButtonState::Disabled}
@ -116,6 +117,7 @@ ChatFormHeader::ChatFormHeader(Settings& settings_, QWidget* parent)
, volState{ToolButtonState::Disabled}
, micState{ToolButtonState::Disabled}
, settings{settings_}
, style{style_}
{
QHBoxLayout* headLayout = new QHBoxLayout();
avatar = new MaskablePixmapWidget(this, AVATAR_SIZE, ":/img/avatar_mask.svg");
@ -141,10 +143,10 @@ ChatFormHeader::ChatFormHeader(Settings& settings_, QWidget* parent)
headTextLayout->addLayout(nameLine);
headTextLayout->addStretch();
micButton = createButton("micButton", this, &ChatFormHeader::micMuteToggle, settings);
volButton = createButton("volButton", this, &ChatFormHeader::volMuteToggle, settings);
callButton = createButton("callButton", this, &ChatFormHeader::callTriggered, settings);
videoButton = createButton("videoButton", this, &ChatFormHeader::videoCallTriggered, settings);
micButton = createButton("micButton", this, &ChatFormHeader::micMuteToggle, settings, style);
volButton = createButton("volButton", this, &ChatFormHeader::volMuteToggle, settings, style);
callButton = createButton("callButton", this, &ChatFormHeader::callTriggered, settings, style);
videoButton = createButton("videoButton", this, &ChatFormHeader::videoCallTriggered, settings, style);
QVBoxLayout* micButtonsLayout = new QVBoxLayout();
micButtonsLayout->setSpacing(MIC_BUTTONS_LAYOUT_SPACING);
@ -219,7 +221,7 @@ void ChatFormHeader::showOutgoingCall(bool video)
void ChatFormHeader::createCallConfirm(bool video)
{
QWidget* btn = video ? videoButton : callButton;
callConfirm = std::unique_ptr<CallConfirmWidget>(new CallConfirmWidget(settings, btn));
callConfirm = std::unique_ptr<CallConfirmWidget>(new CallConfirmWidget(settings, style, btn));
connect(callConfirm.get(), &CallConfirmWidget::accepted, this, &ChatFormHeader::callAccepted);
connect(callConfirm.get(), &CallConfirmWidget::rejected, this, &ChatFormHeader::callRejected);
}
@ -303,11 +305,11 @@ QSize ChatFormHeader::getAvatarSize() const
void ChatFormHeader::reloadTheme()
{
setStyleSheet(Style::getStylesheet("chatArea/chatHead.css", settings));
callButton->setStyleSheet(Style::getStylesheet(STYLE_PATH, settings));
videoButton->setStyleSheet(Style::getStylesheet(STYLE_PATH, settings));
volButton->setStyleSheet(Style::getStylesheet(STYLE_PATH, settings));
micButton->setStyleSheet(Style::getStylesheet(STYLE_PATH, settings));
setStyleSheet(style.getStylesheet("chatArea/chatHead.css", settings));
callButton->setStyleSheet(style.getStylesheet(STYLE_PATH, settings));
videoButton->setStyleSheet(style.getStylesheet(STYLE_PATH, settings));
volButton->setStyleSheet(style.getStylesheet(STYLE_PATH, settings));
micButton->setStyleSheet(style.getStylesheet(STYLE_PATH, settings));
}
void ChatFormHeader::addWidget(QWidget* widget, int stretch, Qt::Alignment alignment)

View File

@ -35,6 +35,7 @@ class CallConfirmWidget;
class QLabel;
class ExtensionStatus;
class Settings;
class Style;
class ChatFormHeader : public QWidget
{
@ -59,7 +60,7 @@ public:
AV = Audio | Video
};
ChatFormHeader(Settings& settings, QWidget* parent = nullptr);
ChatFormHeader(Settings& settings, Style& style, QWidget* parent = nullptr);
~ChatFormHeader();
void setName(const QString& newName);
@ -121,4 +122,5 @@ private:
std::unique_ptr<CallConfirmWidget> callConfirm;
Settings& settings;
Style& style;
};

View File

@ -41,11 +41,12 @@
QHash<int, CircleWidget*> CircleWidget::circleList;
CircleWidget::CircleWidget(const Core &core_, FriendListWidget* parent, int id_,
Settings& settings_)
: CategoryWidget(isCompact(), settings_, parent)
Settings& settings_, Style& style_)
: CategoryWidget(isCompact(), settings_, style_, parent)
, id(id_)
, core{core_}
, settings{settings_}
, style{style_}
{
setName(settings.getCircleName(id), false);
circleList[id] = this;
@ -116,7 +117,7 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event)
circleList.remove(replacedCircle);
} else if (selectedItem == openAction) {
ContentDialog* dialog = new ContentDialog(core, settings);
ContentDialog* dialog = new ContentDialog(core, settings, style);
emit newContentDialog(*dialog);
for (int i = 0; i < friendOnlineLayout()->count(); ++i) {
QWidget* const widget = friendOnlineLayout()->itemAt(i)->widget();

View File

@ -24,12 +24,14 @@
class ContentDialog;
class Core;
class Settings;
class Style;
class CircleWidget final : public CategoryWidget
{
Q_OBJECT
public:
CircleWidget(const Core& core_, FriendListWidget* parent, int id_, Settings& settings);
CircleWidget(const Core& core_, FriendListWidget* parent, int id_, Settings& settings,
Style& style);
~CircleWidget();
void editName();
@ -56,4 +58,5 @@ private:
const Core& core;
Settings& settings;
Style& style;
};

View File

@ -53,7 +53,8 @@ const QSize minSize(minHeight, minWidget);
const QSize defaultSize(720, 400);
} // namespace
ContentDialog::ContentDialog(const Core &core, Settings& settings_, QWidget* parent)
ContentDialog::ContentDialog(const Core &core, Settings& settings_,
Style& style_, QWidget* parent)
: ActivateDialog(parent, Qt::Window)
, splitter{new QSplitter(this)}
, friendLayout{new FriendListLayout(this)}
@ -61,6 +62,7 @@ ContentDialog::ContentDialog(const Core &core, Settings& settings_, QWidget* par
, videoSurfaceSize(QSize())
, videoCount(0)
, settings{settings_}
, style{style_}
{
friendLayout->setMargin(0);
friendLayout->setSpacing(0);
@ -94,7 +96,7 @@ ContentDialog::ContentDialog(const Core &core, Settings& settings_, QWidget* par
QWidget* contentWidget = new QWidget(this);
contentWidget->setAutoFillBackground(true);
contentLayout = new ContentLayout(settings, contentWidget);
contentLayout = new ContentLayout(settings, style, contentWidget);
contentLayout->setMargin(0);
contentLayout->setSpacing(0);
@ -157,7 +159,7 @@ FriendWidget* ContentDialog::addFriend(std::shared_ptr<FriendChatroom> chatroom,
const auto compact = settings.getCompactLayout();
auto frnd = chatroom->getFriend();
const auto& friendPk = frnd->getPublicKey();
auto friendWidget = new FriendWidget(chatroom, compact, settings);
auto friendWidget = new FriendWidget(chatroom, compact, settings, style);
emit connectFriendWidget(*friendWidget);
chatWidgets[friendPk] = friendWidget;
friendLayout->addFriendWidget(friendWidget, frnd->getStatus());
@ -179,7 +181,7 @@ GroupWidget* ContentDialog::addGroup(std::shared_ptr<GroupChatroom> chatroom, Ge
const auto g = chatroom->getGroup();
const auto& groupId = g->getPersistentId();
const auto compact = settings.getCompactLayout();
auto groupWidget = new GroupWidget(chatroom, compact, settings);
auto groupWidget = new GroupWidget(chatroom, compact, settings, style);
chatWidgets[groupId] = groupWidget;
groupLayout.addSortedWidget(groupWidget);
chatForms[groupId] = form;
@ -438,8 +440,8 @@ void ContentDialog::setUsername(const QString& newName)
void ContentDialog::reloadTheme()
{
setStyleSheet(Style::getStylesheet("contentDialog/contentDialog.css", settings));
friendScroll->setStyleSheet(Style::getStylesheet("friendList/friendList.css", settings));
setStyleSheet(style.getStylesheet("contentDialog/contentDialog.css", settings));
friendScroll->setStyleSheet(style.getStylesheet("friendList/friendList.css", settings));
}
bool ContentDialog::event(QEvent* event)

View File

@ -46,12 +46,13 @@ class QCloseEvent;
class QSplitter;
class QScrollArea;
class Settings;
class Style;
class ContentDialog : public ActivateDialog, public IDialogs
{
Q_OBJECT
public:
ContentDialog(const Core& core, Settings& settings, QWidget* parent = nullptr);
ContentDialog(const Core& core, Settings& settings, Style& style, QWidget* parent = nullptr);
~ContentDialog() override;
FriendWidget* addFriend(std::shared_ptr<FriendChatroom> chatroom, GenericChatForm* form);
@ -137,4 +138,5 @@ private:
QString username;
Settings& settings;
Style& style;
};

View File

@ -24,16 +24,18 @@
#include <QFrame>
#include <QStyleFactory>
ContentLayout::ContentLayout(Settings& settings_)
ContentLayout::ContentLayout(Settings& settings_, Style& style_)
: QVBoxLayout()
, settings{settings_}
, style{style_}
{
init();
}
ContentLayout::ContentLayout(Settings& settings_, QWidget* parent)
ContentLayout::ContentLayout(Settings& settings_, Style& style_, QWidget* parent)
: QVBoxLayout(parent)
, settings{settings_}
, style{style_}
{
init();
@ -72,8 +74,8 @@ ContentLayout::~ContentLayout()
void ContentLayout::reloadTheme()
{
#ifndef Q_OS_MAC
mainHead->setStyleSheet(Style::getStylesheet("settings/mainHead.css", settings));
mainContent->setStyleSheet(Style::getStylesheet("window/general.css", settings));
mainHead->setStyleSheet(style.getStylesheet("settings/mainHead.css", settings));
mainContent->setStyleSheet(style.getStylesheet("window/general.css", settings));
#endif
}

View File

@ -23,12 +23,13 @@
#include <QFrame>
class Settings;
class Style;
class ContentLayout : public QVBoxLayout
{
public:
ContentLayout(Settings& settings);
explicit ContentLayout(Settings& settings, QWidget* parent);
ContentLayout(Settings& settings, Style& style);
explicit ContentLayout(Settings& settings, Style& style, QWidget* parent);
~ContentLayout();
void clear();
@ -38,6 +39,7 @@ public:
QWidget* mainContent;
QWidget* mainHead;
Settings& settings;
Style& style;
public slots:
void reloadTheme();

View File

@ -32,10 +32,10 @@
#include <math.h>
EmoticonsWidget::EmoticonsWidget(SmileyPack& smileyPack, Settings& settings,
QWidget* parent)
Style& style, QWidget* parent)
: QMenu(parent)
{
setStyleSheet(Style::getStylesheet("emoticonWidget/emoticonWidget.css", settings));
setStyleSheet(style.getStylesheet("emoticonWidget/emoticonWidget.css", settings));
setLayout(&layout);
layout.addWidget(&stack);

View File

@ -29,12 +29,14 @@
class QIcon;
class SmileyPack;
class Settings;
class Style;
class EmoticonsWidget : public QMenu
{
Q_OBJECT
public:
EmoticonsWidget(SmileyPack& smileyPack, Settings& settings, QWidget* parent = nullptr);
EmoticonsWidget(SmileyPack& smileyPack, Settings& settings, Style& style,
QWidget* parent = nullptr);
signals:
void insertEmoticon(QString str);

View File

@ -61,9 +61,10 @@ namespace
* @brief Cached username so we can retranslate the invite message
*/
AddFriendForm::AddFriendForm(ToxId ownId_, Settings& settings_)
AddFriendForm::AddFriendForm(ToxId ownId_, Settings& settings_, Style& style_)
: ownId{ownId_}
, settings{settings_}
, style{style_}
{
tabWidget = new QTabWidget();
main = new QWidget(tabWidget);
@ -293,7 +294,7 @@ void AddFriendForm::onIdChanged(const QString& id)
isValidId ? QStringLiteral("%1 (%2)") : QStringLiteral("%1 <font color='red'>(%2)</font>");
toxIdLabel.setText(labelText.arg(toxIdText, toxIdComment));
toxId.setStyleSheet(isValidOrEmpty ? QStringLiteral("")
: Style::getStylesheet("addFriendForm/toxId.css", settings));
: style.getStylesheet("addFriendForm/toxId.css", settings));
toxId.setToolTip(isValidOrEmpty ? QStringLiteral("") : tr("Invalid Tox ID format"));
sendButton.setEnabled(isValidId);

View File

@ -34,6 +34,7 @@ class QTabWidget;
class ContentLayout;
class Settings;
class Style;
class AddFriendForm : public QObject
{
@ -46,7 +47,7 @@ public:
FriendRequest = 2
};
AddFriendForm(ToxId ownId_, Settings& settings);
AddFriendForm(ToxId ownId_, Settings& settings, Style& style);
AddFriendForm(const AddFriendForm&) = delete;
AddFriendForm& operator=(const AddFriendForm&) = delete;
~AddFriendForm();
@ -115,4 +116,5 @@ private:
ToxId ownId;
Settings& settings;
Style& style;
};

View File

@ -108,15 +108,17 @@ QString secondsToDHMS(quint32 duration)
ChatForm::ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog_,
IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache_,
SmileyPack& smileyPack_, CameraSource& cameraSource_, Settings& settings_)
SmileyPack& smileyPack_, CameraSource& cameraSource_, Settings& settings_,
Style& style_)
: GenericChatForm(profile.getCore(), chatFriend, chatLog_, messageDispatcher_,
documentCache_, smileyPack_, settings_)
documentCache_, smileyPack_, settings_, style_)
, core{profile.getCore()}
, f(chatFriend)
, isTyping{false}
, lastCallIsVideo{false}
, cameraSource{cameraSource_}
, settings{settings_}
, style{style_}
{
setName(f->getDisplayedName());
@ -147,7 +149,7 @@ ChatForm::ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog_,
imagePreview->setStyleSheet("QPushButton { border: 0px }");
imagePreview->hide();
auto cancelIcon = QIcon(Style::getImagePath("rejectCall/rejectCall.svg", settings));
auto cancelIcon = QIcon(style.getImagePath("rejectCall/rejectCall.svg", settings));
QPushButton* cancelButton = new QPushButton(imagePreview);
cancelButton->setFixedSize(20, 20);
cancelButton->move(QPoint(80, 0));
@ -513,7 +515,7 @@ std::unique_ptr<NetCamView> ChatForm::createNetcam()
qDebug() << "creating netcam";
uint32_t friendId = f->getId();
std::unique_ptr<NetCamView> view = std::unique_ptr<NetCamView>(
new NetCamView(f->getPublicKey(), cameraSource, settings, this));
new NetCamView(f->getPublicKey(), cameraSource, settings, style, this));
CoreAV* av = core.getAv();
VideoSource* source = av->getVideoSourceFromCall(friendId);
view->show(source, f->getDisplayedName());

View File

@ -45,6 +45,7 @@ class ImagePreviewButton;
class DocumentCache;
class SmileyPack;
class Settings;
class Style;
class ChatForm : public GenericChatForm
{
@ -52,7 +53,7 @@ class ChatForm : public GenericChatForm
public:
ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog_,
IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache, SmileyPack& smileyPack,
CameraSource& cameraSource, Settings& settings);
CameraSource& cameraSource, Settings& settings, Style& style);
~ChatForm() override;
void setStatusMessage(const QString& newMessage);
@ -145,4 +146,5 @@ private:
std::unique_ptr<NetCamView> netcam;
CameraSource& cameraSource;
Settings& settings;
Style& style;
};

View File

@ -324,9 +324,10 @@ namespace FileTransferList
return true;
}
Delegate::Delegate(Settings& settings_, QWidget* parent)
Delegate::Delegate(Settings& settings_, Style& style_, QWidget* parent)
: QStyledItemDelegate(parent)
, settings{settings_}
, style{style_}
{}
void Delegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
@ -359,11 +360,11 @@ namespace FileTransferList
}
const auto localPaused = data.toBool();
QPixmap pausePixmap = localPaused
? QPixmap(Style::getImagePath("fileTransferInstance/arrow_black.svg", settings))
: QPixmap(Style::getImagePath("fileTransferInstance/pause_dark.svg", settings));
? QPixmap(style.getImagePath("fileTransferInstance/arrow_black.svg", settings))
: QPixmap(style.getImagePath("fileTransferInstance/pause_dark.svg", settings));
QApplication::style()->drawItemPixmap(painter, pauseRect(option), Qt::AlignCenter, pausePixmap);
QPixmap stopPixmap(Style::getImagePath("fileTransferInstance/no_dark.svg", settings));
QPixmap stopPixmap(style.getImagePath("fileTransferInstance/no_dark.svg", settings));
QApplication::style()->drawItemPixmap(painter, stopRect(option), Qt::AlignCenter, stopPixmap);
return;
}
@ -402,7 +403,8 @@ namespace FileTransferList
}
View::View(QAbstractItemModel* model, Settings& settings, QWidget* parent)
View::View(QAbstractItemModel* model, Settings& settings, Style& style,
QWidget* parent)
: QTableView(parent)
{
setModel(model);
@ -417,14 +419,14 @@ namespace FileTransferList
setShowGrid(false);
setSelectionBehavior(QAbstractItemView::SelectRows);
setSelectionMode(QAbstractItemView::SingleSelection);
setItemDelegate(new Delegate(settings, this));
setItemDelegate(new Delegate(settings, style, this));
}
View::~View() = default;
} // namespace FileTransferList
FilesForm::FilesForm(CoreFile& coreFile, Settings& settings)
FilesForm::FilesForm(CoreFile& coreFile, Settings& settings, Style& style)
: QObject()
{
head = new QWidget();
@ -454,8 +456,8 @@ FilesForm::FilesForm(CoreFile& coreFile, Settings& settings)
connect(sentModel, &FileTransferList::Model::togglePause, pauseFile);
connect(sentModel, &FileTransferList::Model::cancel, cancelFileSend);
recvd = new FileTransferList::View(recvdModel, settings);
sent = new FileTransferList::View(sentModel, settings);
recvd = new FileTransferList::View(recvdModel, settings, style);
sent = new FileTransferList::View(sentModel, settings, style);
main.addTab(recvd, QString());
main.addTab(sent, QString());

View File

@ -35,6 +35,7 @@
class ContentLayout;
class QTableView;
class Settings;
class Style;
namespace FileTransferList
{
@ -89,18 +90,20 @@ namespace FileTransferList
class Delegate : public QStyledItemDelegate
{
public:
Delegate(Settings& settings, QWidget* parent = nullptr);
Delegate(Settings& settings, Style& style, QWidget* parent = nullptr);
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) override;
private:
Settings& settings;
Style& style;
};
class View : public QTableView
{
public:
View(QAbstractItemModel* model, Settings& settings, QWidget* parent = nullptr);
View(QAbstractItemModel* model, Settings& settings, Style& style,
QWidget* parent = nullptr);
~View();
};
@ -111,7 +114,7 @@ class FilesForm : public QObject
Q_OBJECT
public:
FilesForm(CoreFile& coreFile, Settings& settings);
FilesForm(CoreFile& coreFile, Settings& settings, Style& style);
~FilesForm();
bool isShown() const;

View File

@ -121,7 +121,8 @@ namespace
{
template <class T, class Fun>
QPushButton* createButton(const QString& name, T* self, Fun onClickSlot, Settings& settings)
QPushButton* createButton(const QString& name, T* self, Fun onClickSlot,
Settings& settings, Style& style)
{
QPushButton* btn = new QPushButton();
// Fix for incorrect layouts on OS X as per
@ -129,7 +130,7 @@ QPushButton* createButton(const QString& name, T* self, Fun onClickSlot, Setting
btn->setAttribute(Qt::WA_LayoutUsesWidgetRect);
btn->setObjectName(name);
btn->setProperty("state", "green");
btn->setStyleSheet(Style::getStylesheet(STYLE_PATH, settings));
btn->setStyleSheet(style.getStylesheet(STYLE_PATH, settings));
QObject::connect(btn, &QPushButton::clicked, self, onClickSlot);
return btn;
}
@ -138,7 +139,8 @@ QPushButton* createButton(const QString& name, T* self, Fun onClickSlot, Setting
GenericChatForm::GenericChatForm(const Core& core_, const Chat* chat, IChatLog& chatLog_,
IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache,
SmileyPack& smileyPack_, Settings& settings_, QWidget* parent_)
SmileyPack& smileyPack_, Settings& settings_, Style& style_,
QWidget* parent_)
: QWidget(parent_, Qt::Window)
, core{core_}
, audioInputFlag(false)
@ -147,13 +149,14 @@ GenericChatForm::GenericChatForm(const Core& core_, const Chat* chat, IChatLog&
, messageDispatcher(messageDispatcher_)
, smileyPack{smileyPack_}
, settings{settings_}
, style{style_}
{
curRow = 0;
headWidget = new ChatFormHeader(settings);
searchForm = new SearchForm(settings);
headWidget = new ChatFormHeader(settings, style);
searchForm = new SearchForm(settings, style);
dateInfo = new QLabel(this);
chatWidget = new ChatWidget(chatLog_, core, documentCache, smileyPack,
settings, this);
settings, style, this);
searchForm->hide();
dateInfo->setAlignment(Qt::AlignHCenter);
dateInfo->setVisible(false);
@ -169,11 +172,11 @@ GenericChatForm::GenericChatForm(const Core& core_, const Chat* chat, IChatLog&
}
#endif
sendButton = createButton("sendButton", this, &GenericChatForm::onSendTriggered, settings);
emoteButton = createButton("emoteButton", this, &GenericChatForm::onEmoteButtonClicked, settings);
sendButton = createButton("sendButton", this, &GenericChatForm::onSendTriggered, settings, style);
emoteButton = createButton("emoteButton", this, &GenericChatForm::onEmoteButtonClicked, settings, style);
fileButton = createButton("fileButton", this, &GenericChatForm::onAttachClicked, settings);
screenshotButton = createButton("screenshotButton", this, &GenericChatForm::onScreenshotClicked, settings);
fileButton = createButton("fileButton", this, &GenericChatForm::onAttachClicked, settings, style);
screenshotButton = createButton("screenshotButton", this, &GenericChatForm::onScreenshotClicked, settings, style);
// TODO: Make updateCallButtons (see ChatForm) abstract
// and call here to set tooltips.
@ -352,14 +355,14 @@ QDateTime GenericChatForm::getLatestTime() const
void GenericChatForm::reloadTheme()
{
setStyleSheet(Style::getStylesheet("genericChatForm/genericChatForm.css", settings));
msgEdit->setStyleSheet(Style::getStylesheet("msgEdit/msgEdit.css", settings)
setStyleSheet(style.getStylesheet("genericChatForm/genericChatForm.css", settings));
msgEdit->setStyleSheet(style.getStylesheet("msgEdit/msgEdit.css", settings)
+ fontToCss(settings.getChatMessageFont(), "QTextEdit"));
emoteButton->setStyleSheet(Style::getStylesheet(STYLE_PATH, settings));
fileButton->setStyleSheet(Style::getStylesheet(STYLE_PATH, settings));
screenshotButton->setStyleSheet(Style::getStylesheet(STYLE_PATH, settings));
sendButton->setStyleSheet(Style::getStylesheet(STYLE_PATH, settings));
emoteButton->setStyleSheet(style.getStylesheet(STYLE_PATH, settings));
fileButton->setStyleSheet(style.getStylesheet(STYLE_PATH, settings));
screenshotButton->setStyleSheet(style.getStylesheet(STYLE_PATH, settings));
sendButton->setStyleSheet(style.getStylesheet(STYLE_PATH, settings));
}
void GenericChatForm::setName(const QString& newName)
@ -457,7 +460,7 @@ void GenericChatForm::onEmoteButtonClicked()
if (smileyPack.getEmoticons().empty())
return;
EmoticonsWidget widget(smileyPack, settings);
EmoticonsWidget widget(smileyPack, settings, style);
connect(&widget, SIGNAL(insertEmoticon(QString)), this, SLOT(onEmoteInsertRequested(QString)));
widget.installEventFilter(this);
@ -495,7 +498,7 @@ void GenericChatForm::onChatMessageFontChanged(const QFont& font)
chatWidget->fontChanged(font);
chatWidget->forceRelayout();
// message editor
msgEdit->setStyleSheet(Style::getStylesheet("msgEdit/msgEdit.css", settings)
msgEdit->setStyleSheet(style.getStylesheet("msgEdit/msgEdit.css", settings)
+ fontToCss(font, "QTextEdit"));
}

View File

@ -56,6 +56,7 @@ struct Message;
class DocumentCache;
class SmileyPack;
class Settings;
class Style;
namespace Ui {
class MainWindow;
@ -73,7 +74,8 @@ class GenericChatForm : public QWidget
public:
GenericChatForm(const Core& core_, const Chat* chat, IChatLog& chatLog_,
IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache,
SmileyPack& smileyPack, Settings& settings, QWidget* parent_ = nullptr);
SmileyPack& smileyPack, Settings& settings, Style& style,
QWidget* parent_ = nullptr);
~GenericChatForm() override;
void setName(const QString& newName);
@ -171,4 +173,5 @@ protected:
IMessageDispatcher& messageDispatcher;
SmileyPack& smileyPack;
Settings& settings;
Style& style;
};

View File

@ -85,12 +85,14 @@ QString editName(const QString& name)
GroupChatForm::GroupChatForm(Core& core_, Group* chatGroup, IChatLog& chatLog_,
IMessageDispatcher& messageDispatcher_, Settings& settings_, DocumentCache& documentCache_,
SmileyPack& smileyPack_)
: GenericChatForm(core_, chatGroup, chatLog_, messageDispatcher_, documentCache_, smileyPack_, settings_)
SmileyPack& smileyPack_, Style& style_)
: GenericChatForm(core_, chatGroup, chatLog_, messageDispatcher_,
documentCache_, smileyPack_, settings_, style_)
, core{core_}
, group(chatGroup)
, inCall(false)
, settings(settings_)
, style{style_}
{
nusersLabel = new QLabel();
@ -217,7 +219,7 @@ void GroupChatForm::updateUserNames()
label->setProperty("peerType", LABEL_PEER_TYPE_MUTED);
}
label->setStyleSheet(Style::getStylesheet(PEER_LABEL_STYLE_SHEET_PATH, settings));
label->setStyleSheet(style.getStylesheet(PEER_LABEL_STYLE_SHEET_PATH, settings));
peerLabels.insert(peerPk, label);
}
@ -286,7 +288,7 @@ void GroupChatForm::peerAudioPlaying(ToxPk peerPk)
});
}
peerLabels[peerPk]->setStyleSheet(Style::getStylesheet(PEER_LABEL_STYLE_SHEET_PATH, settings));
peerLabels[peerPk]->setStyleSheet(style.getStylesheet(PEER_LABEL_STYLE_SHEET_PATH, settings));
peerAudioTimers[peerPk]->start(500);
}
@ -434,7 +436,7 @@ void GroupChatForm::onLabelContextMenuRequested(const QPoint& localPos)
} else {
toggleMuteAction = contextMenu->addAction(muteString);
}
contextMenu->setStyleSheet(Style::getStylesheet(PEER_LABEL_STYLE_SHEET_PATH, settings));
contextMenu->setStyleSheet(style.getStylesheet(PEER_LABEL_STYLE_SHEET_PATH, settings));
const QAction* selectedItem = contextMenu->exec(pos);
if (selectedItem == toggleMuteAction) {

View File

@ -37,6 +37,7 @@ struct Message;
class Settings;
class DocumentCache;
class SmileyPack;
class Style;
class GroupChatForm : public GenericChatForm
{
@ -44,7 +45,7 @@ class GroupChatForm : public GenericChatForm
public:
GroupChatForm(Core& core_, Group* chatGroup, IChatLog& chatLog_,
IMessageDispatcher& messageDispatcher_, Settings& settings_,
DocumentCache& documentCache, SmileyPack& smileyPack);
DocumentCache& documentCache, SmileyPack& smileyPack, Style& style);
~GroupChatForm();
void peerAudioPlaying(ToxPk peerPk);
@ -85,4 +86,5 @@ private:
TabCompleter* tabber;
bool inCall;
Settings& settings;
Style& style;
};

View File

@ -100,7 +100,7 @@ const QPair<QString, QString> CAN_NOT_CHANGE_PASSWORD = {
} // namespace
ProfileForm::ProfileForm(IProfileInfo* profileInfo_, Settings& settings_,
QWidget* parent)
Style& style, QWidget* parent)
: QWidget{parent}
, qr{nullptr}
, profileInfo{profileInfo_}
@ -133,7 +133,7 @@ ProfileForm::ProfileForm(IProfileInfo* profileInfo_, Settings& settings_,
profilePicture->installEventFilter(this);
profilePicture->setAccessibleName("Profile avatar");
profilePicture->setAccessibleDescription("Set a profile avatar shown to all contacts");
profilePicture->setStyleSheet(Style::getStylesheet("window/profile.css", settings));
profilePicture->setStyleSheet(style.getStylesheet("window/profile.css", settings));
connect(profilePicture, &MaskablePixmapWidget::clicked, this, &ProfileForm::onAvatarClicked);
connect(profilePicture, &MaskablePixmapWidget::customContextMenuRequested,
this, &ProfileForm::showProfilePictureContextMenu);

View File

@ -30,6 +30,7 @@ class CroppingLabel;
class IProfileInfo;
class MaskablePixmapWidget;
class Settings;
class Style;
namespace Ui {
class IdentitySettings;
@ -54,7 +55,8 @@ class ProfileForm : public QWidget
{
Q_OBJECT
public:
ProfileForm(IProfileInfo* profileInfo_, Settings& settings, QWidget* parent = nullptr);
ProfileForm(IProfileInfo* profileInfo_, Settings& settings, Style& style,
QWidget* parent = nullptr);
~ProfileForm();
void show(ContentLayout* contentLayout);
bool isShown() const;

View File

@ -23,10 +23,11 @@
#include "src/widget/style.h"
#include "src/widget/form/loadhistorydialog.h"
SearchSettingsForm::SearchSettingsForm(Settings& settings_, QWidget *parent)
SearchSettingsForm::SearchSettingsForm(Settings& settings_, Style& style_, QWidget *parent)
: QWidget(parent)
, ui(new Ui::SearchSettingsForm)
, settings{settings_}
, style{style_}
{
ui->setupUi(this);
@ -100,8 +101,8 @@ ParameterSearch SearchSettingsForm::getParameterSearch()
void SearchSettingsForm::reloadTheme()
{
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
ui->startDateLabel->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/labels.css"), settings));
ui->choiceDateButton->setStyleSheet(style.getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
ui->startDateLabel->setStyleSheet(style.getStylesheet(QStringLiteral("chatForm/labels.css"), settings));
}
void SearchSettingsForm::updateStartDateLabel()
@ -122,7 +123,7 @@ void SearchSettingsForm::onStartSearchSelected(const int index)
ui->startDateLabel->setEnabled(true);
ui->choiceDateButton->setProperty("state", QStringLiteral("green"));
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
ui->choiceDateButton->setStyleSheet(style.getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
if (startDate.isNull()) {
startDate = QDate::currentDate();
@ -134,7 +135,7 @@ void SearchSettingsForm::onStartSearchSelected(const int index)
ui->startDateLabel->setEnabled(false);
ui->choiceDateButton->setProperty("state", QString());
ui->choiceDateButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
ui->choiceDateButton->setStyleSheet(style.getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
}
setUpdate(true);

View File

@ -26,13 +26,14 @@ namespace Ui {
class SearchSettingsForm;
}
class Settings;
class Style;
class SearchSettingsForm : public QWidget
{
Q_OBJECT
public:
explicit SearchSettingsForm(Settings& settings, QWidget *parent = nullptr);
SearchSettingsForm(Settings& settings, Style& style, QWidget *parent = nullptr);
~SearchSettingsForm();
ParameterSearch getParameterSearch();
@ -43,6 +44,7 @@ private:
QDate startDate;
bool isUpdate{false};
Settings& settings;
Style& style;
void updateStartDateLabel();
void setUpdate(const bool isUpdate_);

View File

@ -54,11 +54,12 @@ enum class updateIndex
/**
* @brief Constructor of AboutForm.
*/
AboutForm::AboutForm(UpdateCheck* updateCheck_)
AboutForm::AboutForm(UpdateCheck* updateCheck_, Style& style_)
: GenericForm(QPixmap(":/img/settings/general.png"))
, bodyUI(new Ui::AboutSettings)
, progressTimer(new QTimer(this))
, updateCheck(updateCheck_)
, style{style_}
{
bodyUI->setupUi(this);
@ -212,7 +213,7 @@ QString AboutForm::createLink(QString path, QString text) const
{
return QString::fromUtf8(
"<a href=\"%1\" style=\"text-decoration: underline; color:%2;\">%3</a>")
.arg(path, Style::getColor(Style::ColorPalette::Link).name(), text);
.arg(path, style.getColor(Style::ColorPalette::Link).name(), text);
}
AboutForm::~AboutForm()

View File

@ -27,6 +27,7 @@ class QTimer;
class QString;
class UpdateCheck;
class QLayoutItem;
class Style;
namespace Ui {
class AboutSettings;
@ -36,7 +37,7 @@ class AboutForm : public GenericForm
{
Q_OBJECT
public:
AboutForm(UpdateCheck* updateCheck_);
AboutForm(UpdateCheck* updateCheck_, Style& style_);
~AboutForm();
QString getFormName() final
{
@ -60,4 +61,5 @@ private:
QTimer* progressTimer;
UpdateCheck* updateCheck;
QMetaObject::Connection linkConnection;
Style& style;
};

View File

@ -55,10 +55,11 @@
* Restores all controls from the settings.
*/
UserInterfaceForm::UserInterfaceForm(SmileyPack& smileyPack_, Settings& settings_,
SettingsWidget* myParent)
Style& style_, SettingsWidget* myParent)
: GenericForm(QPixmap(":/img/settings/general.png"))
, smileyPack{smileyPack_}
, settings{settings_}
, style{style_}
{
parent = myParent;
@ -114,13 +115,13 @@ UserInterfaceForm::UserInterfaceForm(SmileyPack& smileyPack_, Settings& settings
bodyUI->styleBrowser->addItem(tr("None"));
bodyUI->styleBrowser->addItems(QStyleFactory::keys());
QString style;
QString textStyle;
if (QStyleFactory::keys().contains(settings.getStyle()))
style = settings.getStyle();
textStyle = settings.getStyle();
else
style = tr("None");
textStyle = tr("None");
bodyUI->styleBrowser->setCurrentText(style);
bodyUI->styleBrowser->setCurrentText(textStyle);
for (QString color : Style::getThemeColorNames())
bodyUI->themeColorCBox->addItem(color);
@ -178,15 +179,15 @@ UserInterfaceForm::~UserInterfaceForm()
delete bodyUI;
}
void UserInterfaceForm::on_styleBrowser_currentIndexChanged(QString style)
void UserInterfaceForm::on_styleBrowser_currentIndexChanged(QString textStyle)
{
if (bodyUI->styleBrowser->currentIndex() == 0)
settings.setStyle("None");
else
settings.setStyle(style);
settings.setStyle(textStyle);
setStyle(QStyleFactory::create(style));
parent->setBodyHeadStyle(style);
setStyle(QStyleFactory::create(textStyle));
parent->setBodyHeadStyle(textStyle);
}
void UserInterfaceForm::on_emoticonSize_editingFinished()
@ -340,7 +341,7 @@ void UserInterfaceForm::on_cbShowIdenticons_stateChanged()
void UserInterfaceForm::on_themeColorCBox_currentIndexChanged(int index)
{
settings.setThemeColor(index);
Style::setThemeColor(settings, index);
style.setThemeColor(settings, index);
Style::applyTheme();
}

View File

@ -28,14 +28,15 @@ namespace Ui {
class UserInterfaceSettings;
}
class Settings;
class SmileyPack;
class Style;
class UserInterfaceForm : public GenericForm
{
Q_OBJECT
public:
UserInterfaceForm(SmileyPack& smileyPack, Settings& settings, SettingsWidget* myParent);
UserInterfaceForm(SmileyPack& smileyPack, Settings& settings, Style& style,
SettingsWidget* myParent);
~UserInterfaceForm();
QString getFormName() final
{
@ -45,7 +46,7 @@ public:
private slots:
void on_smileyPackBrowser_currentIndexChanged(int index);
void on_emoticonSize_editingFinished();
void on_styleBrowser_currentIndexChanged(QString style);
void on_styleBrowser_currentIndexChanged(QString textStyle);
void on_timestamp_editTextChanged(const QString& format);
void on_dateFormats_editTextChanged(const QString& format);
void on_textStyleComboBox_currentTextChanged();
@ -79,4 +80,5 @@ private:
const int MAX_FORMAT_LENGTH = 128;
SmileyPack& smileyPack;
Settings& settings;
Style& style;
};

View File

@ -43,7 +43,7 @@
SettingsWidget::SettingsWidget(UpdateCheck* updateCheck, IAudioControl& audio,
Core* core, SmileyPack& smileyPack, CameraSource& cameraSource,
Settings& settings, Widget* parent)
Settings& settings, Style& style, Widget* parent)
: QWidget(parent, Qt::Window)
{
CoreAV* coreAV = core->getAv();
@ -61,14 +61,14 @@ SettingsWidget::SettingsWidget(UpdateCheck* updateCheck, IAudioControl& audio,
std::unique_ptr<GeneralForm> gfrm(new GeneralForm(this, settings));
connect(gfrm.get(), &GeneralForm::updateIcons, parent, &Widget::updateIcons);
std::unique_ptr<UserInterfaceForm> uifrm(new UserInterfaceForm(smileyPack, settings, this));
std::unique_ptr<UserInterfaceForm> uifrm(new UserInterfaceForm(smileyPack, settings, style, this));
std::unique_ptr<PrivacyForm> pfrm(new PrivacyForm(core, settings));
connect(pfrm.get(), &PrivacyForm::clearAllReceipts, parent, &Widget::clearAllReceipts);
AVForm* rawAvfrm = new AVForm(audio, coreAV, cameraSource, audioSettings, videoSettings);
std::unique_ptr<AVForm> avfrm(rawAvfrm);
std::unique_ptr<AdvancedForm> expfrm(new AdvancedForm(settings));
std::unique_ptr<AboutForm> abtfrm(new AboutForm(updateCheck));
std::unique_ptr<AboutForm> abtfrm(new AboutForm(updateCheck, style));
#if UPDATE_CHECK_ENABLED
if (updateCheck != nullptr) {

View File

@ -41,13 +41,15 @@ class Widget;
class SmileyPack;
class CameraSource;
class Settings;
class Style;
class SettingsWidget : public QWidget
{
Q_OBJECT
public:
SettingsWidget(UpdateCheck* updateCheck, IAudioControl& audio, Core *core,
SmileyPack& smileyPack, CameraSource& cameraSource, Settings& settings, Widget* parent = nullptr);
SmileyPack& smileyPack, CameraSource& cameraSource, Settings& settings,
Style& style, Widget* parent = nullptr);
~SettingsWidget();
bool isShown() const;

View File

@ -100,10 +100,11 @@ qint64 timeUntilTomorrow()
} // namespace
FriendListWidget::FriendListWidget(const Core &core_, Widget* parent,
Settings& settings_, bool groupsOnTop)
Settings& settings_, Style& style_, bool groupsOnTop)
: QWidget(parent)
, core{core_}
, settings{settings_}
, style{style_}
{
int countContacts = core.getFriendList().size();
manager = new FriendListManager(countContacts, this);
@ -246,7 +247,7 @@ void FriendListWidget::sortByMode()
activityLayout = new QVBoxLayout();
bool compact = settings.getCompactLayout();
for (Time t : names.keys()) {
CategoryWidget* category = new CategoryWidget(compact, settings, this);
CategoryWidget* category = new CategoryWidget(compact, settings, style, this);
category->setName(names[t]);
activityLayout->addWidget(category);
}
@ -615,7 +616,7 @@ CircleWidget* FriendListWidget::createCircleWidget(int id)
return CircleWidget::getFromID(id);
}
CircleWidget* circleWidget = new CircleWidget(core, this, id, settings);
CircleWidget* circleWidget = new CircleWidget(core, this, id, settings, style);
emit connectCircleWidget(*circleWidget);
connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged);
connect(circleWidget, &CircleWidget::renameRequested, this, &FriendListWidget::renameCircleWidget);

View File

@ -39,13 +39,14 @@ class CategoryWidget;
class Friend;
class IFriendListItem;
class Settings;
class Style;
class FriendListWidget : public QWidget
{
Q_OBJECT
public:
using SortingMode = Settings::FriendListSortingMode;
FriendListWidget(const Core& core, Widget* parent, Settings& settings, bool groupsOnTop = true);
FriendListWidget(const Core& core, Widget* parent, Settings& settings, Style& style, bool groupsOnTop = true);
~FriendListWidget();
void setMode(SortingMode mode);
SortingMode getMode() const;
@ -99,4 +100,5 @@ private:
const Core& core;
Settings& settings;
Style& style;
};

View File

@ -56,11 +56,13 @@
* For example, used on friend list.
* When you click should open the chat with friend. Widget has a context menu.
*/
FriendWidget::FriendWidget(std::shared_ptr<FriendChatroom> chatroom_, bool compact_, Settings& settings_)
: GenericChatroomWidget(compact_, settings_)
FriendWidget::FriendWidget(std::shared_ptr<FriendChatroom> chatroom_, bool compact_,
Settings& settings_, Style& style_)
: GenericChatroomWidget(compact_, settings_, style_)
, chatroom{chatroom_}
, isDefaultAvatar{true}
, settings{settings_}
, style{style_}
{
avatar->setPixmap(QPixmap(":/img/contact.svg"));
statusPic.setPixmap(QPixmap(Status::getIconPath(Status::Status::Offline)));
@ -283,7 +285,7 @@ void FriendWidget::showDetails()
const auto frnd = chatroom->getFriend();
const auto iabout = new AboutFriend(frnd, &settings);
std::unique_ptr<IAboutFriend> about = std::unique_ptr<IAboutFriend>(iabout);
const auto aboutUser = new AboutFriendForm(std::move(about), settings, this);
const auto aboutUser = new AboutFriendForm(std::move(about), settings, style, this);
connect(aboutUser, &AboutFriendForm::histroyRemoved, this, &FriendWidget::friendHistoryRemoved);
aboutUser->show();
}

View File

@ -30,12 +30,14 @@ class QPixmap;
class MaskablePixmapWidget;
class CircleWidget;
class Settings;
class Style;
class FriendWidget : public GenericChatroomWidget, public IFriendListItem
{
Q_OBJECT
public:
FriendWidget(std::shared_ptr<FriendChatroom> chatroom_, bool compact_, Settings& settings);
FriendWidget(std::shared_ptr<FriendChatroom> chatroom_, bool compact_,
Settings& settings, Style& style);
void contextMenuEvent(QContextMenuEvent* event) final;
void setAsActiveChatroom() final;
@ -87,4 +89,5 @@ public:
std::shared_ptr<FriendChatroom> chatroom;
bool isDefaultAvatar;
Settings& settings;
Style& style;
};

View File

@ -25,10 +25,12 @@
#include <QBoxLayout>
#include <QMouseEvent>
GenericChatroomWidget::GenericChatroomWidget(bool compact_, Settings& settings_, QWidget* parent)
GenericChatroomWidget::GenericChatroomWidget(bool compact_, Settings& settings_,
Style& style_, QWidget* parent)
: GenericChatItemWidget(compact_, parent)
, active{false}
, settings{settings_}
, style{style_}
{
// avatar
QSize size;
@ -160,7 +162,7 @@ QString GenericChatroomWidget::getTitle() const
void GenericChatroomWidget::reloadTheme()
{
setStyleSheet(Style::getStylesheet("genericChatRoomWidget/genericChatRoomWidget.css", settings));
setStyleSheet(style.getStylesheet("genericChatRoomWidget/genericChatRoomWidget.css", settings));
}
void GenericChatroomWidget::activate()

View File

@ -28,15 +28,16 @@ class QHBoxLayout;
class ContentLayout;
class Friend;
class Group;
class Contact;
class Settings;
class Chat;
class Style;
class GenericChatroomWidget : public GenericChatItemWidget
{
Q_OBJECT
public:
explicit GenericChatroomWidget(bool compact, Settings& settings, QWidget* parent = nullptr);
GenericChatroomWidget(bool compact, Settings& settings, Style& style,
QWidget* parent = nullptr);
public slots:
virtual void setAsActiveChatroom() = 0;
@ -87,4 +88,5 @@ protected:
CroppingLabel* statusMessageLabel;
bool active;
Settings& settings;
Style& style;
};

View File

@ -41,8 +41,9 @@
#include "src/widget/widget.h"
#include "tool/croppinglabel.h"
GroupWidget::GroupWidget(std::shared_ptr<GroupChatroom> chatroom_, bool compact_, Settings& settings_)
: GenericChatroomWidget(compact_, settings_)
GroupWidget::GroupWidget(std::shared_ptr<GroupChatroom> chatroom_, bool compact_,
Settings& settings_, Style& style_)
: GenericChatroomWidget(compact_, settings_, style_)
, groupId{chatroom_->getGroup()->getPersistentId()}
, chatroom{chatroom_}
{

View File

@ -28,12 +28,14 @@
#include <memory>
class Settings;
class Style;
class GroupWidget final : public GenericChatroomWidget, public IFriendListItem
{
Q_OBJECT
public:
GroupWidget(std::shared_ptr<GroupChatroom> chatroom_, bool compact, Settings& settings);
GroupWidget(std::shared_ptr<GroupChatroom> chatroom_, bool compact, Settings& settings,
Style& style);
~GroupWidget();
void setAsInactiveChatroom() final;
void setAsActiveChatroom() final;

View File

@ -33,8 +33,8 @@
#include <QMessageBox>
#include <QToolButton>
LoginScreen::LoginScreen(Settings& settings_, const QString& initialProfileName,
QWidget* parent)
LoginScreen::LoginScreen(Settings& settings_, Style& style,
const QString& initialProfileName, QWidget* parent)
: QDialog(parent)
, ui(new Ui::LoginScreen)
, quitShortcut{QKeySequence(Qt::CTRL + Qt::Key_Q), this}
@ -63,7 +63,7 @@ LoginScreen::LoginScreen(Settings& settings_, const QString& initialProfileName,
connect(ui->importButton, &QPushButton::clicked, this, &LoginScreen::onImportProfile);
reset(initialProfileName);
setStyleSheet(Style::getStylesheet("loginScreen/loginScreen.css", settings));
setStyleSheet(style.getStylesheet("loginScreen/loginScreen.css", settings));
retranslateUi();
Translator::registerHandler(std::bind(&LoginScreen::retranslateUi, this), this);

View File

@ -26,6 +26,7 @@
class Profile;
class Settings;
class Style;
namespace Ui {
class LoginScreen;
@ -36,7 +37,8 @@ class LoginScreen : public QDialog
Q_OBJECT
public:
LoginScreen(Settings& settings, const QString& initialProfileName = QString(), QWidget* parent = nullptr);
LoginScreen(Settings& settings, Style& style, const QString& initialProfileName = QString(),
QWidget* parent = nullptr);
~LoginScreen();
bool event(QEvent* event) final;

View File

@ -25,11 +25,12 @@
#include <QDebug>
NotificationEdgeWidget::NotificationEdgeWidget(Position position, Settings& settings, QWidget* parent)
NotificationEdgeWidget::NotificationEdgeWidget(Position position, Settings& settings,
Style& style, QWidget* parent)
: QWidget(parent)
{
setAttribute(Qt::WA_StyledBackground); // Show background.
setStyleSheet(Style::getStylesheet("notificationEdge/notificationEdge.css", settings));
setStyleSheet(style.getStylesheet("notificationEdge/notificationEdge.css", settings));
QHBoxLayout* layout = new QHBoxLayout(this);
layout->addStretch();
@ -40,9 +41,9 @@ NotificationEdgeWidget::NotificationEdgeWidget(Position position, Settings& sett
QLabel* arrowLabel = new QLabel(this);
if (position == Top)
arrowLabel->setPixmap(QPixmap(Style::getImagePath("chatArea/scrollBarUpArrow.svg", settings)));
arrowLabel->setPixmap(QPixmap(style.getImagePath("chatArea/scrollBarUpArrow.svg", settings)));
else
arrowLabel->setPixmap(QPixmap(Style::getImagePath("chatArea/scrollBarDownArrow.svg", settings)));
arrowLabel->setPixmap(QPixmap(style.getImagePath("chatArea/scrollBarDownArrow.svg", settings)));
layout->addWidget(arrowLabel);
layout->addStretch();

View File

@ -23,6 +23,7 @@
class QLabel;
class Settings;
class Style;
class NotificationEdgeWidget final : public QWidget
{
@ -34,7 +35,8 @@ public:
Bottom
};
NotificationEdgeWidget(Position position, Settings& settings, QWidget* parent = nullptr);
NotificationEdgeWidget(Position position, Settings& settings, Style& style,
QWidget* parent = nullptr);
void updateNotificationCount(int count);
signals:

View File

@ -31,7 +31,8 @@ NotificationScrollArea::NotificationScrollArea(QWidget* parent)
&NotificationScrollArea::updateVisualTracking);
}
void NotificationScrollArea::trackWidget(Settings& settings, GenericChatroomWidget* widget)
void NotificationScrollArea::trackWidget(Settings& settings, Style& style,
GenericChatroomWidget* widget)
{
if (trackedWidgets.find(widget) != trackedWidgets.end())
return;
@ -41,7 +42,8 @@ void NotificationScrollArea::trackWidget(Settings& settings, GenericChatroomWidg
if (visibility == Above) {
if (referencesAbove++ == 0) {
assert(topEdge == nullptr);
topEdge = new NotificationEdgeWidget(NotificationEdgeWidget::Top, settings, this);
topEdge = new NotificationEdgeWidget(NotificationEdgeWidget::Top,
settings, style, this);
connect(topEdge, &NotificationEdgeWidget::clicked, this,
&NotificationScrollArea::findPreviousWidget);
recalculateTopEdge();
@ -51,7 +53,8 @@ void NotificationScrollArea::trackWidget(Settings& settings, GenericChatroomWidg
} else {
if (referencesBelow++ == 0) {
assert(bottomEdge == nullptr);
bottomEdge = new NotificationEdgeWidget(NotificationEdgeWidget::Bottom, settings, this);
bottomEdge = new NotificationEdgeWidget(NotificationEdgeWidget::Bottom,
settings, style, this);
connect(bottomEdge, &NotificationEdgeWidget::clicked, this,
&NotificationScrollArea::findNextWidget);
recalculateBottomEdge();

View File

@ -25,6 +25,7 @@
class GenericChatroomWidget;
class NotificationEdgeWidget;
class Settings;
class Style;
class NotificationScrollArea final : public AdjustingScrollArea
{
@ -32,7 +33,7 @@ public:
explicit NotificationScrollArea(QWidget* parent = nullptr);
public slots:
void trackWidget(Settings& settings, GenericChatroomWidget* widget);
void trackWidget(Settings& settings, Style& style, GenericChatroomWidget* widget);
void updateVisualTracking();
void updateTracking(GenericChatroomWidget* widget);

View File

@ -36,9 +36,10 @@ static std::array<QString, 3> STATE_NAME = {
QStringLiteral("red"),
};
SearchForm::SearchForm(Settings& settings_, QWidget* parent)
SearchForm::SearchForm(Settings& settings_, Style& style_, QWidget* parent)
: QWidget(parent)
, settings{settings_}
, style{style_}
{
QVBoxLayout* layout = new QVBoxLayout();
QHBoxLayout* layoutNavigation = new QHBoxLayout();
@ -46,12 +47,12 @@ SearchForm::SearchForm(Settings& settings_, QWidget* parent)
QSpacerItem *lSpacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Ignored);
QSpacerItem *rSpacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Ignored);
searchLine = new LineEdit();
searchSettingsForm = new SearchSettingsForm(settings);
searchSettingsForm = new SearchSettingsForm(settings, style);
messageLabel = new QLabel();
searchSettingsForm->setVisible(false);
messageLabel->setProperty("state", QStringLiteral("red"));
messageLabel->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/labels.css"),settings));
messageLabel->setStyleSheet(style.getStylesheet(QStringLiteral("chatForm/labels.css"),settings));
messageLabel->setText(tr("The text could not be found."));
messageLabel->setVisible(false);
@ -125,11 +126,11 @@ void SearchForm::insertEditor(const QString &text)
void SearchForm::reloadTheme()
{
settingsButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
upButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
downButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
hideButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
startButton->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
settingsButton->setStyleSheet(style.getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
upButton->setStyleSheet(style.getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
downButton->setStyleSheet(style.getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
hideButton->setStyleSheet(style.getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
startButton->setStyleSheet(style.getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
searchSettingsForm->reloadTheme();
}
@ -146,7 +147,7 @@ QPushButton *SearchForm::createButton(const QString& name, const QString& state)
btn->setAttribute(Qt::WA_LayoutUsesWidgetRect);
btn->setObjectName(name);
btn->setProperty("state", state);
btn->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
btn->setStyleSheet(style.getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
return btn;
}
@ -172,7 +173,7 @@ void SearchForm::setStateName(QPushButton *btn, ToolButtonState state)
{
const auto index = static_cast<unsigned long>(state);
btn->setProperty("state", STATE_NAME[index]);
btn->setStyleSheet(Style::getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
btn->setStyleSheet(style.getStylesheet(QStringLiteral("chatForm/buttons.css"), settings));
btn->setEnabled(index != 0);
}

View File

@ -28,6 +28,7 @@ class QLabel;
class LineEdit;
class SearchSettingsForm;
class Settings;
class Style;
class SearchForm final : public QWidget
{
@ -39,7 +40,7 @@ public:
Active = 2, // Red
};
explicit SearchForm(Settings& settings, QWidget* parent = nullptr);
SearchForm(Settings& settings, Style& style, QWidget* parent = nullptr);
void removeSearchPhrase();
QString getSearchPhrase() const;
ParameterSearch getParameterSearch();
@ -73,6 +74,7 @@ private:
bool isSearchInBegin{true};
bool isPrevSearch{false};
Settings& settings;
Style& style;
private slots:
void changedSearchPhrase(const QString& text);

View File

@ -82,14 +82,13 @@ QString qssifyFont(QFont font)
return QString("%1 %2px \"%3\"").arg(font.weight() * 8).arg(font.pixelSize()).arg(font.family());
}
using ColorPalette = Style::ColorPalette;
QMap<ColorPalette, QColor> palette;
QMap<QString, QString> dictColor;
QMap<QString, QString> dictFont;
QMap<QString, QString> dictTheme;
using MainTheme = Style::MainTheme;
const QList<Style::ThemeNameColor> themeNameColors = {
struct ThemeNameColor {
MainTheme type;
QString name;
QColor color;
};
const QList<ThemeNameColor> themeNameColors = {
{MainTheme::Light, QObject::tr("Default"), QColor()},
{MainTheme::Light, QObject::tr("Blue"), QColor("#004aa4")},
{MainTheme::Light, QObject::tr("Olive"), QColor("#97ba00")},
@ -102,6 +101,7 @@ const QList<Style::ThemeNameColor> themeNameColors = {
{MainTheme::Dark, QObject::tr("Dark violet"), QColor("#280d6c")}
};
using ColorPalette = Style::ColorPalette;
const QMap<ColorPalette, QString> aliasColors = {
{ColorPalette::TransferGood, "transferGood"},
{ColorPalette::TransferWait, "transferWait"},
@ -123,12 +123,6 @@ const QMap<ColorPalette, QString> aliasColors = {
{ColorPalette::SearchHighlighted, "searchHighlighted"},
{ColorPalette::SelectText, "selectText"},
};
// stylesheet filename, font -> stylesheet
// QString implicit sharing deduplicates stylesheets rather than constructing a new one each time
std::map<std::pair<const QString, const QFont>, const QString> stylesheetsCache;
QStringList existingImagesCache;
} // namespace
QStringList Style::getThemeColorNames()
@ -217,7 +211,7 @@ QFont Style::getFont(Font font)
// fonts as defined in
// https://github.com/ItsDuke/Tox-UI/blob/master/UI%20GUIDELINES.md
static int defSize = QFontInfo(QFont()).pixelSize();
static const int defSize = QFontInfo(QFont()).pixelSize();
static const std::map<Font, QFont> fonts = {
{Font::ExtraBig, appFont(defSize + 3, QFont::Bold)},

View File

@ -21,6 +21,7 @@
#include <QColor>
#include <QFont>
#include <QMap>
class QString;
class QWidget;
@ -69,32 +70,35 @@ public:
Dark
};
struct ThemeNameColor {
MainTheme type;
QString name;
QColor color;
};
static QStringList getThemeColorNames();
static const QString getStylesheet(const QString& filename, Settings& settings, const QFont& baseFont = QFont());
static const QString getImagePath(const QString& filename, Settings& settings);
static QString getThemeFolder(Settings& settings);
static QString getThemeName();
static QColor getColor(ColorPalette entry);
static QFont getFont(Font font);
static const QString resolve(const QString& filename, Settings& settings, const QFont& baseFont = QFont());
static void repolish(QWidget* w);
static void setThemeColor(Settings& settings, int color);
static void setThemeColor(const QColor& color);
static void applyTheme();
static QPixmap scaleSvgImage(const QString& path, uint32_t width, uint32_t height);
static void initPalette(Settings& settings);
static void initDictColor();
Style() = default;
const QString getStylesheet(const QString& filename, Settings& settings, const QFont& baseFont = QFont());
const QString getImagePath(const QString& filename, Settings& settings);
QColor getColor(ColorPalette entry);
const QString resolve(const QString& filename, Settings& settings, const QFont& baseFont = QFont());
void setThemeColor(Settings& settings, int color);
void setThemeColor(const QColor& color);
void initPalette(Settings& settings);
void initDictColor();
static QString getThemePath(Settings& settings);
signals:
void themeChanged();
private:
Style();
QMap<ColorPalette, QColor> palette;
QMap<QString, QString> dictColor;
QMap<QString, QString> dictFont;
QMap<QString, QString> dictTheme;
// stylesheet filename, font -> stylesheet
// QString implicit sharing deduplicates stylesheets rather than constructing a new one each time
std::map<std::pair<const QString, const QFont>, const QString> stylesheetsCache;
QStringList existingImagesCache;
};

View File

@ -50,7 +50,8 @@
* @brief Used to correct the rounding factors on non-square rects
*/
CallConfirmWidget::CallConfirmWidget(Settings& settings, const QWidget* anchor_)
CallConfirmWidget::CallConfirmWidget(Settings& settings, Style& style,
const QWidget* anchor_)
: QWidget()
, anchor(anchor_)
, rectW{120}
@ -90,8 +91,8 @@ CallConfirmWidget::CallConfirmWidget(Settings& settings, const QWidget* anchor_)
reject->setFlat(true);
accept->setStyleSheet("QPushButton{border:none;}");
reject->setStyleSheet("QPushButton{border:none;}");
accept->setIcon(QIcon(Style::getImagePath("acceptCall/acceptCall.svg", settings)));
reject->setIcon(QIcon(Style::getImagePath("rejectCall/rejectCall.svg", settings)));
accept->setIcon(QIcon(style.getImagePath("acceptCall/acceptCall.svg", settings)));
reject->setIcon(QIcon(style.getImagePath("rejectCall/rejectCall.svg", settings)));
accept->setIconSize(accept->size());
reject->setIconSize(reject->size());

View File

@ -28,12 +28,13 @@
class QPaintEvent;
class QShowEvent;
class Settings;
class Style;
class CallConfirmWidget final : public QWidget
{
Q_OBJECT
public:
explicit CallConfirmWidget(Settings& settings, const QWidget* anchor_);
CallConfirmWidget(Settings& settings, Style& style, const QWidget* anchor_);
signals:
void accepted();

View File

@ -142,7 +142,7 @@ void Widget::acceptFileTransfer(const ToxFile& file, const QString& path)
Widget* Widget::instance{nullptr};
Widget::Widget(Profile &profile_, IAudioControl& audio_, CameraSource& cameraSource_,
Settings& settings_, QWidget* parent)
Settings& settings_, Style& style_, QWidget* parent)
: QMainWindow(parent)
, profile{profile_}
, trayMenu{nullptr}
@ -158,6 +158,7 @@ Widget::Widget(Profile &profile_, IAudioControl& audio_, CameraSource& cameraSou
, smileyPack(new SmileyPack(settings))
, documentCache(new DocumentCache(*smileyPack, settings))
, cameraSource{cameraSource_}
, style{style_}
{
installEventFilter(this);
QString locale = settings.getTranslation();
@ -204,7 +205,7 @@ void Widget::init()
#endif
actionQuit->setIcon(
prepareIcon(Style::getImagePath("rejectCall/rejectCall.svg", settings), icon_size, icon_size));
prepareIcon(style.getImagePath("rejectCall/rejectCall.svg", settings), icon_size, icon_size));
connect(actionQuit, &QAction::triggered, qApp, &QApplication::quit);
layout()->setContentsMargins(0, 0, 0, 0);
@ -263,7 +264,7 @@ void Widget::init()
sharedMessageProcessorParams.reset(new MessageProcessor::SharedParams(core->getMaxMessageSize(), coreExt->getMaxExtendedMessageSize()));
chatListWidget = new FriendListWidget(*core, this, settings, settings.getGroupchatPosition());
chatListWidget = new FriendListWidget(*core, this, settings, style, settings.getGroupchatPosition());
connect(chatListWidget, &FriendListWidget::searchCircle, this, &Widget::searchCircle);
connect(chatListWidget, &FriendListWidget::connectCircleWidget, this,
&Widget::connectCircleWidget);
@ -288,11 +289,11 @@ void Widget::init()
// Disable some widgets until we're connected to the DHT
ui->statusButton->setEnabled(false);
Style::setThemeColor(settings, settings.getThemeColor());
style.setThemeColor(settings, settings.getThemeColor());
CoreFile* coreFile = core->getCoreFile();
filesForm = new FilesForm(*coreFile, settings);
addFriendForm = new AddFriendForm(core->getSelfId(), settings);
filesForm = new FilesForm(*coreFile, settings, style);
addFriendForm = new AddFriendForm(core->getSelfId(), settings, style);
groupInviteForm = new GroupInviteForm(settings);
#if UPDATE_CHECK_ENABLED
@ -300,13 +301,13 @@ void Widget::init()
connect(updateCheck.get(), &UpdateCheck::updateAvailable, this, &Widget::onUpdateAvailable);
#endif
settingsWidget = new SettingsWidget(updateCheck.get(), audio, core, *smileyPack,
cameraSource, settings, this);
cameraSource, settings, style, this);
#if UPDATE_CHECK_ENABLED
updateCheck->checkForUpdate();
#endif
profileInfo = new ProfileInfo(core, &profile, settings);
profileForm = new ProfileForm(profileInfo, settings);
profileForm = new ProfileForm(profileInfo, settings, style);
#if DESKTOP_NOTIFICATIONS
notificationGenerator.reset(new NotificationGenerator(settings, &profile));
@ -805,7 +806,7 @@ void Widget::onSeparateWindowChanged(bool separate, bool clicked)
QWidget* contentWidget = new QWidget(this);
contentWidget->setObjectName("contentWidget");
contentLayout = new ContentLayout(settings, contentWidget);
contentLayout = new ContentLayout(settings, style, contentWidget);
ui->mainSplitter->addWidget(contentWidget);
setMinimumWidth(775);
@ -1185,7 +1186,7 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
auto rawChatroom = new FriendChatroom(newfriend, dialogManager, *core, settings);
std::shared_ptr<FriendChatroom> chatroom(rawChatroom);
const auto compact = settings.getCompactLayout();
auto widget = new FriendWidget(chatroom, compact, settings);
auto widget = new FriendWidget(chatroom, compact, settings, style);
connectFriendWidget(*widget);
auto history = profile.getHistory();
@ -1200,7 +1201,7 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
*friendMessageDispatcher);
auto friendForm = new ChatForm(profile, newfriend, *chatHistory,
*friendMessageDispatcher, *documentCache, *smileyPack, cameraSource,
settings);
settings, style);
connect(friendForm, &ChatForm::updateFriendActivity, this, &Widget::updateFriendActivity);
friendMessageDispatchers[friendPk] = friendMessageDispatcher;
@ -1614,7 +1615,7 @@ bool Widget::newFriendMessageAlert(const ToxPk& friendId, const QString& text, b
FriendWidget* widget = friendWidgets[friendId];
f->setEventFlag(true);
widget->updateStatusLight();
ui->friendList->trackWidget(settings, widget);
ui->friendList->trackWidget(settings, style, widget);
#if DESKTOP_NOTIFICATIONS
auto notificationData = filename.isEmpty() ? notificationGenerator->friendMessageNotification(f, text)
: notificationGenerator->fileTransferNotification(f, filename, filesize);
@ -1864,7 +1865,7 @@ void Widget::onUpdateAvailable()
ContentDialog* Widget::createContentDialog() const
{
ContentDialog* contentDialog = new ContentDialog(*core, settings);
ContentDialog* contentDialog = new ContentDialog(*core, settings, style);
registerContentDialog(*contentDialog);
return contentDialog;
@ -1896,11 +1897,12 @@ ContentLayout* Widget::createContentDialog(DialogType type) const
class Dialog : public ActivateDialog
{
public:
explicit Dialog(DialogType type_, Settings& settings_, Core* core_)
explicit Dialog(DialogType type_, Settings& settings_, Core* core_, Style& style_)
: ActivateDialog(nullptr, Qt::Window)
, type(type_)
, settings(settings_)
, core{core_}
, style{style_}
{
restoreGeometry(settings.getDialogSettingsGeometry());
Translator::registerHandler(std::bind(&Dialog::retranslateUi, this), this);
@ -1925,7 +1927,7 @@ ContentLayout* Widget::createContentDialog(DialogType type) const
void reloadTheme() final
{
setStyleSheet(Style::getStylesheet("window/general.css", settings));
setStyleSheet(style.getStylesheet("window/general.css", settings));
}
protected:
@ -1945,11 +1947,12 @@ ContentLayout* Widget::createContentDialog(DialogType type) const
DialogType type;
Settings& settings;
Core* core;
Style& style;
};
Dialog* dialog = new Dialog(type, settings, core);
Dialog* dialog = new Dialog(type, settings, core, style);
dialog->setAttribute(Qt::WA_DeleteOnClose);
ContentLayout* contentLayoutDialog = new ContentLayout(settings, dialog);
ContentLayout* contentLayoutDialog = new ContentLayout(settings, style, dialog);
dialog->setObjectName("detached");
dialog->setLayout(contentLayoutDialog);
@ -2155,7 +2158,7 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId)
std::shared_ptr<GroupChatroom> chatroom(rawChatroom);
const auto compact = settings.getCompactLayout();
auto widget = new GroupWidget(chatroom, compact, settings);
auto widget = new GroupWidget(chatroom, compact, settings, style);
auto messageProcessor = MessageProcessor(*sharedMessageProcessorParams);
auto messageDispatcher =
std::make_shared<GroupMessageDispatcher>(*newgroup, std::move(messageProcessor), *core,
@ -2185,7 +2188,7 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId)
groupAlertConnections.insert(groupId, notifyReceivedConnection);
auto form = new GroupChatForm(*core, newgroup, *groupChatLog, *messageDispatcher,
settings, *documentCache, *smileyPack);
settings, *documentCache, *smileyPack, style);
connect(&settings, &Settings::nameColorsChanged, form, &GenericChatForm::setColorizedNames);
form->setColorizedNames(settings.getEnableGroupChatsColor());
groupMessageDispatchers[groupId] = messageDispatcher;
@ -2483,15 +2486,15 @@ void Widget::reloadTheme()
x->setStyleSheet("");
}
setStyleSheet(Style::getStylesheet("window/general.css", settings));
QString statusPanelStyle = Style::getStylesheet("window/statusPanel.css", settings);
ui->tooliconsZone->setStyleSheet(Style::getStylesheet("tooliconsZone/tooliconsZone.css", settings));
setStyleSheet(style.getStylesheet("window/general.css", settings));
QString statusPanelStyle = style.getStylesheet("window/statusPanel.css", settings);
ui->tooliconsZone->setStyleSheet(style.getStylesheet("tooliconsZone/tooliconsZone.css", settings));
ui->statusPanel->setStyleSheet(statusPanelStyle);
ui->statusHead->setStyleSheet(statusPanelStyle);
ui->friendList->setStyleSheet(Style::getStylesheet("friendList/friendList.css", settings));
ui->statusButton->setStyleSheet(Style::getStylesheet("statusButton/statusButton.css", settings));
ui->friendList->setStyleSheet(style.getStylesheet("friendList/friendList.css", settings));
ui->statusButton->setStyleSheet(style.getStylesheet("statusButton/statusButton.css", settings));
profilePicture->setStyleSheet(Style::getStylesheet("window/profile.css", settings));
profilePicture->setStyleSheet(style.getStylesheet("window/profile.css", settings));
}
void Widget::nextChat()

View File

@ -85,6 +85,7 @@ class IChatLog;
class ChatHistory;
class SmileyPack;
class CameraSource;
class Style;
class Widget final : public QMainWindow
{
Q_OBJECT
@ -119,7 +120,7 @@ private:
public:
Widget(Profile& profile_, IAudioControl& audio_, CameraSource& cameraSource, Settings& settings,
QWidget* parent = nullptr);
Style& style, QWidget* parent = nullptr);
~Widget() override;
void init();
void setCentralWidget(QWidget* widget, const QString& widgetName);
@ -386,6 +387,7 @@ private:
std::unique_ptr<SmileyPack> smileyPack;
std::unique_ptr<DocumentCache> documentCache;
CameraSource& cameraSource;
Style& style;
};
bool toxActivateEventHandler(const QByteArray& data, void* userData);