1
0
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:
krepa098 2014-09-30 23:45:33 +02:00
parent a4cd2d34db
commit 214e428b7e
4 changed files with 32 additions and 69 deletions

View File

@ -19,7 +19,14 @@
#include <QFile>
#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)
{
@ -51,13 +58,6 @@ QColor Style::getColor(Style::ColorPalette 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)
{
static QFont fonts[] = {

View File

@ -35,22 +35,10 @@ FriendWidget::FriendWidget(int FriendId, QString id)
: friendId(FriendId)
, 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->setPixmap(QPixmap(":img/contact.png"), Qt::transparent);
name.setText(id);
//statusPic.setAlignment(Qt::AlignHCenter);
statusPic.setPixmap(QPixmap(":img/status/dot_away.png"));
// status text
@ -65,11 +53,6 @@ FriendWidget::FriendWidget(int FriendId, QString id)
name.setPalette(pal2);
name.setFont(Style::getFont(Style::Big));
// background
QPalette pal3;
pal3.setColor(QPalette::Background, Style::getColor(Style::MediumGrey));
setPalette(pal3);
textLayout.addStretch();
textLayout.addWidget(&name);
textLayout.addWidget(&statusMessage);
@ -82,11 +65,7 @@ FriendWidget::FriendWidget(int FriendId, QString id)
layout.addSpacing(10);
layout.addWidget(&statusPic);
layout.addSpacing(10);
layout.invalidate();
layout.update();
layout.activate();
updateGeometry();
}
void FriendWidget::contextMenuEvent(QContextMenuEvent * event)

View File

@ -22,49 +22,43 @@ GenericChatroomWidget::GenericChatroomWidget(QWidget *parent)
: QWidget(parent)
, 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()
{
return isActiveWidget;
}
void GenericChatroomWidget::setActive(bool active)
{
isActiveWidget = active;
if (active)
{
QPalette pal;
pal.setColor(QPalette::Background, Style::getColor(Style::White));
setPalette(pal);
}
setStyleSheet(QString("background-color: %1").arg(Style::getColor(Style::White).name()));
else
{
QPalette pal;
pal.setColor(QPalette::Background, Style::getColor(Style::MediumGrey));
setPalette(pal);
}
setStyleSheet(QString("background-color: %1").arg(Style::getColor(Style::MediumGrey).name()));
}
void GenericChatroomWidget::leaveEvent(QEvent *)
{
if (!isActive())
{
QPalette pal;
pal.setColor(QPalette::Background, Style::getColor(Style::MediumGrey));
setPalette(pal);
}
setStyleSheet(QString("background-color: %1").arg(Style::getColor(Style::MediumGrey).name()));
}
void GenericChatroomWidget::enterEvent(QEvent *)
{
if (!isActive())
{
QPalette pal;
pal.setColor(QPalette::Background, Style::getColor(Style::MediumGrey).lighter(120));
setPalette(pal);
}
setStyleSheet(QString("background-color: %1").arg(Style::getColor(Style::MediumGrey).lighter(120).name()));
}
void GenericChatroomWidget::mouseReleaseEvent(QMouseEvent*)

View File

@ -30,16 +30,6 @@
GroupWidget::GroupWidget(int GroupId, QString Name)
: 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->setPixmap(QPixmap(":img/group.png"), Qt::transparent);
@ -58,11 +48,6 @@ GroupWidget::GroupWidget(int GroupId, QString Name)
nusers.setPalette(pal);
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);
if (g)
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.addWidget(&statusPic);
layout.addSpacing(10);
layout.activate();
}
void GroupWidget::contextMenuEvent(QContextMenuEvent * event)
@ -154,16 +140,20 @@ void GroupWidget::updateStatusLight()
{
statusPic.setPixmap(QPixmap(":img/status/dot_online.png"));
} else {
if (g->userWasMentioned == 0) statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
else statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
if (g->userWasMentioned == 0)
statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
else
statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
}
} else {
if (g->hasNewMessages == 0)
{
statusPic.setPixmap(QPixmap(":img/status/dot_groupchat.png"));
} else {
if (g->userWasMentioned == 0) statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_newmessages.png"));
else statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_notification.png"));
if (g->userWasMentioned == 0)
statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_newmessages.png"));
else
statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_notification.png"));
}
}
}