mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
cleanup, use qss instead of QPalette
This commit is contained in:
parent
a4cd2d34db
commit
214e428b7e
|
@ -19,7 +19,14 @@
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QVector>
|
|
||||||
|
// helper function
|
||||||
|
QFont appFont(int pixelSize, int weight) {
|
||||||
|
auto font = QFont();
|
||||||
|
font.setPixelSize(pixelSize);
|
||||||
|
font.setWeight(weight);
|
||||||
|
return font;
|
||||||
|
}
|
||||||
|
|
||||||
QString Style::getStylesheet(const QString &filename)
|
QString Style::getStylesheet(const QString &filename)
|
||||||
{
|
{
|
||||||
|
@ -51,13 +58,6 @@ QColor Style::getColor(Style::ColorPalette entry)
|
||||||
return palette[entry];
|
return palette[entry];
|
||||||
}
|
}
|
||||||
|
|
||||||
QFont appFont(int pixelSize, int weight) {
|
|
||||||
auto font = QFont();
|
|
||||||
font.setPixelSize(pixelSize);
|
|
||||||
font.setWeight(weight);
|
|
||||||
return font;
|
|
||||||
}
|
|
||||||
|
|
||||||
QFont Style::getFont(Style::Font font)
|
QFont Style::getFont(Style::Font font)
|
||||||
{
|
{
|
||||||
static QFont fonts[] = {
|
static QFont fonts[] = {
|
||||||
|
|
|
@ -35,22 +35,10 @@ FriendWidget::FriendWidget(int FriendId, QString id)
|
||||||
: friendId(FriendId)
|
: friendId(FriendId)
|
||||||
, isDefaultAvatar{true}
|
, isDefaultAvatar{true}
|
||||||
{
|
{
|
||||||
setMouseTracking(true);
|
|
||||||
setAutoFillBackground(true);
|
|
||||||
setFixedHeight(55);
|
|
||||||
setLayout(&layout);
|
|
||||||
layout.setSpacing(0);
|
|
||||||
layout.setMargin(0);
|
|
||||||
layout.setStretchFactor(this, 100);
|
|
||||||
textLayout.setSpacing(0);
|
|
||||||
textLayout.setMargin(0);
|
|
||||||
setLayoutDirection(Qt::LeftToRight); // parent might have set Qt::RightToLeft
|
|
||||||
|
|
||||||
avatar = new MaskablePixmapWidget(this, QSize(40,40), ":/img/avatar_mask.png");
|
avatar = new MaskablePixmapWidget(this, QSize(40,40), ":/img/avatar_mask.png");
|
||||||
avatar->setPixmap(QPixmap(":img/contact.png"), Qt::transparent);
|
avatar->setPixmap(QPixmap(":img/contact.png"), Qt::transparent);
|
||||||
|
|
||||||
name.setText(id);
|
name.setText(id);
|
||||||
//statusPic.setAlignment(Qt::AlignHCenter);
|
|
||||||
statusPic.setPixmap(QPixmap(":img/status/dot_away.png"));
|
statusPic.setPixmap(QPixmap(":img/status/dot_away.png"));
|
||||||
|
|
||||||
// status text
|
// status text
|
||||||
|
@ -65,11 +53,6 @@ FriendWidget::FriendWidget(int FriendId, QString id)
|
||||||
name.setPalette(pal2);
|
name.setPalette(pal2);
|
||||||
name.setFont(Style::getFont(Style::Big));
|
name.setFont(Style::getFont(Style::Big));
|
||||||
|
|
||||||
// background
|
|
||||||
QPalette pal3;
|
|
||||||
pal3.setColor(QPalette::Background, Style::getColor(Style::MediumGrey));
|
|
||||||
setPalette(pal3);
|
|
||||||
|
|
||||||
textLayout.addStretch();
|
textLayout.addStretch();
|
||||||
textLayout.addWidget(&name);
|
textLayout.addWidget(&name);
|
||||||
textLayout.addWidget(&statusMessage);
|
textLayout.addWidget(&statusMessage);
|
||||||
|
@ -82,11 +65,7 @@ FriendWidget::FriendWidget(int FriendId, QString id)
|
||||||
layout.addSpacing(10);
|
layout.addSpacing(10);
|
||||||
layout.addWidget(&statusPic);
|
layout.addWidget(&statusPic);
|
||||||
layout.addSpacing(10);
|
layout.addSpacing(10);
|
||||||
|
|
||||||
layout.invalidate();
|
|
||||||
layout.update();
|
|
||||||
layout.activate();
|
layout.activate();
|
||||||
updateGeometry();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||||
|
|
|
@ -22,49 +22,43 @@ GenericChatroomWidget::GenericChatroomWidget(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, isActiveWidget(false)
|
, isActiveWidget(false)
|
||||||
{
|
{
|
||||||
|
setMouseTracking(true);
|
||||||
|
setFixedHeight(55);
|
||||||
|
|
||||||
|
setLayout(&layout);
|
||||||
|
layout.setSpacing(0);
|
||||||
|
layout.setMargin(0);
|
||||||
|
textLayout.setSpacing(0);
|
||||||
|
textLayout.setMargin(0);
|
||||||
|
setLayoutDirection(Qt::LeftToRight); // parent might have set Qt::RightToLeft
|
||||||
|
|
||||||
|
setStyleSheet(QString("background-color: %1").arg(Style::getColor(Style::MediumGrey).name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GenericChatroomWidget::isActive()
|
bool GenericChatroomWidget::isActive()
|
||||||
{
|
{
|
||||||
return isActiveWidget;
|
return isActiveWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericChatroomWidget::setActive(bool active)
|
void GenericChatroomWidget::setActive(bool active)
|
||||||
{
|
{
|
||||||
isActiveWidget = active;
|
isActiveWidget = active;
|
||||||
|
|
||||||
if (active)
|
if (active)
|
||||||
{
|
setStyleSheet(QString("background-color: %1").arg(Style::getColor(Style::White).name()));
|
||||||
QPalette pal;
|
|
||||||
pal.setColor(QPalette::Background, Style::getColor(Style::White));
|
|
||||||
setPalette(pal);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
setStyleSheet(QString("background-color: %1").arg(Style::getColor(Style::MediumGrey).name()));
|
||||||
QPalette pal;
|
|
||||||
pal.setColor(QPalette::Background, Style::getColor(Style::MediumGrey));
|
|
||||||
setPalette(pal);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericChatroomWidget::leaveEvent(QEvent *)
|
void GenericChatroomWidget::leaveEvent(QEvent *)
|
||||||
{
|
{
|
||||||
if (!isActive())
|
if (!isActive())
|
||||||
{
|
setStyleSheet(QString("background-color: %1").arg(Style::getColor(Style::MediumGrey).name()));
|
||||||
QPalette pal;
|
|
||||||
pal.setColor(QPalette::Background, Style::getColor(Style::MediumGrey));
|
|
||||||
setPalette(pal);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericChatroomWidget::enterEvent(QEvent *)
|
void GenericChatroomWidget::enterEvent(QEvent *)
|
||||||
{
|
{
|
||||||
if (!isActive())
|
if (!isActive())
|
||||||
{
|
setStyleSheet(QString("background-color: %1").arg(Style::getColor(Style::MediumGrey).lighter(120).name()));
|
||||||
QPalette pal;
|
|
||||||
pal.setColor(QPalette::Background, Style::getColor(Style::MediumGrey).lighter(120));
|
|
||||||
setPalette(pal);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenericChatroomWidget::mouseReleaseEvent(QMouseEvent*)
|
void GenericChatroomWidget::mouseReleaseEvent(QMouseEvent*)
|
||||||
|
|
|
@ -30,16 +30,6 @@
|
||||||
GroupWidget::GroupWidget(int GroupId, QString Name)
|
GroupWidget::GroupWidget(int GroupId, QString Name)
|
||||||
: groupId{GroupId}
|
: groupId{GroupId}
|
||||||
{
|
{
|
||||||
setMouseTracking(true);
|
|
||||||
setAutoFillBackground(true);
|
|
||||||
setLayout(&layout);
|
|
||||||
setFixedHeight(55);
|
|
||||||
layout.setSpacing(0);
|
|
||||||
layout.setMargin(0);
|
|
||||||
textLayout.setSpacing(0);
|
|
||||||
textLayout.setMargin(0);
|
|
||||||
setLayoutDirection(Qt::LeftToRight); // parent might have set Qt::RightToLeft
|
|
||||||
|
|
||||||
avatar = new MaskablePixmapWidget(this, QSize(40,40), ":/img/avatar_mask.png");
|
avatar = new MaskablePixmapWidget(this, QSize(40,40), ":/img/avatar_mask.png");
|
||||||
avatar->setPixmap(QPixmap(":img/group.png"), Qt::transparent);
|
avatar->setPixmap(QPixmap(":img/group.png"), Qt::transparent);
|
||||||
|
|
||||||
|
@ -58,11 +48,6 @@ GroupWidget::GroupWidget(int GroupId, QString Name)
|
||||||
nusers.setPalette(pal);
|
nusers.setPalette(pal);
|
||||||
nusers.setFont(Style::getFont(Style::Medium));
|
nusers.setFont(Style::getFont(Style::Medium));
|
||||||
|
|
||||||
// background
|
|
||||||
QPalette pal3;
|
|
||||||
pal3.setColor(QPalette::Background, Style::getColor(Style::MediumGrey));
|
|
||||||
this->setPalette(pal3);
|
|
||||||
|
|
||||||
Group* g = GroupList::findGroup(groupId);
|
Group* g = GroupList::findGroup(groupId);
|
||||||
if (g)
|
if (g)
|
||||||
nusers.setText(GroupWidget::tr("%1 users in chat").arg(g->peers.size()));
|
nusers.setText(GroupWidget::tr("%1 users in chat").arg(g->peers.size()));
|
||||||
|
@ -82,6 +67,7 @@ GroupWidget::GroupWidget(int GroupId, QString Name)
|
||||||
layout.addSpacing(10);
|
layout.addSpacing(10);
|
||||||
layout.addWidget(&statusPic);
|
layout.addWidget(&statusPic);
|
||||||
layout.addSpacing(10);
|
layout.addSpacing(10);
|
||||||
|
layout.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupWidget::contextMenuEvent(QContextMenuEvent * event)
|
void GroupWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||||
|
@ -154,16 +140,20 @@ void GroupWidget::updateStatusLight()
|
||||||
{
|
{
|
||||||
statusPic.setPixmap(QPixmap(":img/status/dot_online.png"));
|
statusPic.setPixmap(QPixmap(":img/status/dot_online.png"));
|
||||||
} else {
|
} else {
|
||||||
if (g->userWasMentioned == 0) statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
|
if (g->userWasMentioned == 0)
|
||||||
else statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
|
statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
|
||||||
|
else
|
||||||
|
statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (g->hasNewMessages == 0)
|
if (g->hasNewMessages == 0)
|
||||||
{
|
{
|
||||||
statusPic.setPixmap(QPixmap(":img/status/dot_groupchat.png"));
|
statusPic.setPixmap(QPixmap(":img/status/dot_groupchat.png"));
|
||||||
} else {
|
} else {
|
||||||
if (g->userWasMentioned == 0) statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_newmessages.png"));
|
if (g->userWasMentioned == 0)
|
||||||
else statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_notification.png"));
|
statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_newmessages.png"));
|
||||||
|
else
|
||||||
|
statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_notification.png"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user