1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #362 from krepa098/style

Style
This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-10-01 19:18:00 +02:00
commit 193b4e8bee
29 changed files with 474 additions and 307 deletions

View File

@ -36,19 +36,17 @@ Friend::~Friend()
void Friend::setName(QString name)
{
widget->name.setText(name);
widget->name.setToolTip(name); // for overlength names
widget->setName(name);
chatForm->setName(name);
}
void Friend::setStatusMessage(QString message)
{
widget->statusMessage.setText(message);
widget->statusMessage.setToolTip(message); // for overlength messsages
widget->setStatusMsg(message);
chatForm->setStatusMessage(message);
}
QString Friend::getName()
{
return widget->name.text();
return widget->getName();
}

View File

@ -19,17 +19,129 @@
#include <QFile>
#include <QDebug>
#include <QMap>
#include <QRegularExpression>
#include <QWidget>
#include <QStyle>
QString Style::get(const QString &filename)
// helper functions
QFont appFont(int pixelSize, int weight)
{
QFont font;
font.setPixelSize(pixelSize);
font.setWeight(weight);
return font;
}
QString qssifyWeight(int weight)
{
QString weightStr = "normal";
if (weight == QFont::Bold)
weightStr = "bold";
if (weight == QFont::Light)
weightStr = "light";
return QString("%1").arg(weightStr);
}
QString qssifyFont(QFont font)
{
return QString("%1px %2 \"%3\"")
.arg(font.pixelSize())
.arg(qssifyWeight(font.weight()))
.arg(font.family());
}
QString Style::getStylesheet(const QString &filename)
{
if (!Settings::getInstance().getUseNativeStyle())
{
QFile file(filename);
if (file.open(QFile::ReadOnly | QFile::Text))
return file.readAll();
return resolve(file.readAll());
else
qWarning() << "Style " << filename << " not found";
qWarning() << "Style: Stylesheet " << filename << " not found";
}
return QString();
}
QColor Style::getColor(Style::ColorPalette entry)
{
static QColor palette[] = {
QColor("#6bc260"),
QColor("#cebf44"),
QColor("#c84e4e"),
QColor("#000000"),
QColor("#1c1c1c"),
QColor("#414141"),
QColor("#414141").lighter(120),
QColor("#d1d1d1"),
QColor("#ffffff"),
};
return palette[entry];
}
QFont Style::getFont(Style::Font font)
{
static QFont fonts[] = {
appFont(14, QFont::Bold),
appFont(12, QFont::Normal),
appFont(12, QFont::Bold),
appFont(11, QFont::Normal),
appFont(11, QFont::Bold),
appFont(10, QFont::Normal),
appFont(10, QFont::Light),
};
return fonts[font];
}
QString Style::resolve(QString qss)
{
static QMap<QString, QString> dict = {
// colors
{"@green", getColor(Green).name()},
{"@yellow", getColor(Yellow).name()},
{"@red", getColor(Red).name()},
{"@black", getColor(Black).name()},
{"@darkGrey", getColor(DarkGrey).name()},
{"@mediumGrey", getColor(MediumGrey).name()},
{"@mediumGreyLight", getColor(MediumGreyLight).name()},
{"@lightGrey", getColor(LightGrey).name()},
{"@white", getColor(White).name()},
// fonts
{"@extraBig", qssifyFont(getFont(ExtraBig))},
{"@big", qssifyFont(getFont(Big))},
{"@bigBold", qssifyFont(getFont(BigBold))},
{"@medium", qssifyFont(getFont(Medium))},
{"@mediumBold", qssifyFont(getFont(MediumBold))},
{"@small", qssifyFont(getFont(Small))},
{"@smallLight", qssifyFont(getFont(SmallLight))},
};
for (const QString& key : dict.keys())
{
qss.replace(QRegularExpression(QString("%1\\b").arg(key)), dict[key]);
}
return qss;
}
void Style::repolish(QWidget *w)
{
w->style()->unpolish(w);
w->style()->polish(w);
for (QObject* o : w->children())
{
QWidget* c = qobject_cast<QWidget*>(o);
if (c)
{
c->style()->unpolish(c);
c->style()->polish(c);
}
}
}

View File

@ -17,12 +17,45 @@
#ifndef STYLE_H
#define STYLE_H
#include <QColor>
#include <QFont>
class QString;
class QWidget;
class Style
{
public:
static QString get(const QString& filename);
enum ColorPalette
{
Green,
Yellow,
Red,
Black,
DarkGrey,
MediumGrey,
MediumGreyLight,
LightGrey,
White,
};
enum Font
{
ExtraBig, // 14px, bold
Big, // 12px
BigBold, // 12px, bold
Medium, // 11px
MediumBold, // 11px, bold
Small, // 10px
SmallLight // 10px, light
};
static QString getStylesheet(const QString& filename);
static QColor getColor(ColorPalette entry);
static QFont getFont(Font font);
static QString resolve(QString qss);
static void repolish(QWidget* w);
private:
Style();
};

View File

@ -145,5 +145,6 @@
<file>translations/uk.qm</file>
<file>img/avatar_mask.png</file>
<file>img/group_2x.png</file>
<file>ui/chatroomWidgets/genericChatroomWidget.css</file>
</qresource>
</RCC>

View File

@ -1,25 +1,31 @@
div.name_me {
color: #646464;
font-weight: bold;
padding-right: 3px;
}
div.name {
color: #000000;
font-weight: bold;
padding-right: 3px;
color: @black;
font: @big;
}
div.message {
color: #000000;
padding-right: 3px;
padding-left: 3px;
color: @black;
font: @big;
}
div.date {
color: #000000;
padding-left: 3px;
white-space: nowrap;
color: @black;
font: @big;
}
div.name_me {
color: @mediumGrey;
font: @big;
}
div.message_me {
color: @mediumGrey;
font: @big;
}
div.date_me {
color: @mediumGrey;
font: @big;
}
span.quote {
@ -31,9 +37,9 @@ div.green {
margin-bottom: 12px;
margin-left: 12px;
margin-right: 12px;
color: #ffffff;
background-color: #6bc260;
font-size: 10px;
color: @white;
background-color: @green;
font: @small;
}
div.silver {
@ -41,9 +47,9 @@ div.silver {
margin-bottom: 12px;
margin-left: 12px;
margin-right: 12px;
color: #000000;
background-color: #d1d1d1;
font-size: 10px;
color: @black;
background-color: @lightGrey;
font: @small;
}
div.red {
@ -51,14 +57,14 @@ div.red {
margin-bottom: 12px;
margin-left: 12px;
margin-right: 12px;
color: #ffffff;
background-color: rgb(200,78,78);
font-size: 10px;
color: @white;
background-color: @red;
font: @small;
}
div.button {
margin-top: 0px;
margin-bottom: 0px;
margin-left: 0px;
color: #ffffff;
color: @white;
}

View File

@ -0,0 +1,38 @@
GenericChatroomWidget
{
background-color: @mediumGrey;
}
GenericChatroomWidget[active="true"]
{
background-color: @white;
}
GenericChatroomWidget[active="false"]:hover
{
background-color: @mediumGreyLight;
}
GenericChatroomWidget[active="true"] > QLabel#status
{
font: @medium;
color: @mediumGrey;
}
GenericChatroomWidget[active="false"] > QLabel#status
{
font: @medium;
color: @lightGrey;
}
GenericChatroomWidget[active="true"] > QLabel#name
{
font: @big;
color: @darkGrey;
}
GenericChatroomWidget[active="false"] > QLabel#name
{
font: @big;
color: @white;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 233 B

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 263 B

After

Width:  |  Height:  |  Size: 234 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 237 B

After

Width:  |  Height:  |  Size: 233 B

View File

@ -35,6 +35,6 @@ QRadioButton::indicator::checked
QMenu
{
background-color: rgb(240,240,240); /* sets background of the menu */
border: 1px solid;
background-color: @mediumGrey; /* sets background of the menu */
border: 0px solid;
}

View File

@ -1,5 +1,5 @@
QTextEdit {
border-color: #c4c1bd;
border-color: @lightGrey;
border-style: solid;
border-width: 1px 0 1px 1px;
}

View File

@ -48,17 +48,3 @@ QSize AdjustingScrollArea::sizeHint() const
return QScrollArea::sizeHint();
}
bool AdjustingScrollArea::eventFilter(QObject *obj, QEvent *ev)
{
if (ev->type() == QEvent::Paint)
{
// workaround: sometimes a child widget gets drawn on top of the scrollbar
// so we trigger a repaint afterwards
// => Actually, we don't. This triggers an infinite loop of QEvent::UpdateRequest and burns 100% CPU !
//verticalScrollBar()->update();
//horizontalScrollBar()->update();
}
return QObject::eventFilter(obj, ev);
}

View File

@ -27,7 +27,6 @@ public:
virtual void resizeEvent(QResizeEvent *ev) override;
virtual QSize sizeHint() const override;
virtual bool eventFilter(QObject *obj, QEvent *ev) override;
};
#endif // ADJUSTINGSCROLLAREA_H

View File

@ -23,8 +23,9 @@
#include <QCoreApplication>
#include <QDebug>
ChatAreaWidget::ChatAreaWidget(QWidget *parent) :
QTextBrowser(parent)
ChatAreaWidget::ChatAreaWidget(QWidget *parent)
: QTextBrowser(parent)
, nameWidth(75)
{
setReadOnly(true);
viewport()->setCursor(Qt::ArrowCursor);
@ -36,19 +37,19 @@ ChatAreaWidget::ChatAreaWidget(QWidget *parent) :
setAcceptRichText(false);
setFrameStyle(QFrame::NoFrame);
chatTextTable = textCursor().insertTable(1,3);
QTextTableFormat tableFormat;
tableFormat.setCellSpacing(15);
tableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_None);
tableFormat.setCellSpacing(2);
tableFormat.setWidth(QTextLength(QTextLength::PercentageLength,100));
chatTextTable->setFormat(tableFormat);
setNameColWidth(100);
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::FixedLength,nameWidth),
QTextLength(QTextLength::PercentageLength,100),
QTextLength(QTextLength::VariableLength,0)});
// nameFormat.setAlignment(Qt::AlignRight);
// nameFormat.setNonBreakableLines(true);
// dateFormat.setAlignment(Qt::AlignLeft);
// dateFormat.setNonBreakableLines(true);
chatTextTable = textCursor().insertTable(1,3,tableFormat);
nameFormat.setAlignment(Qt::AlignRight);
nameFormat.setNonBreakableLines(true);
dateFormat.setAlignment(Qt::AlignLeft);
dateFormat.setNonBreakableLines(true);
connect(this, &ChatAreaWidget::anchorClicked, this, &ChatAreaWidget::onAnchorClicked);
connect(verticalScrollBar(), SIGNAL(rangeChanged(int,int)), this, SLOT(onSliderRangeChanged()));
@ -112,9 +113,11 @@ void ChatAreaWidget::insertMessage(ChatAction *msgAction)
cur.clearSelection();
cur.setKeepPositionOnInsert(true);
chatTextTable->appendRows(1);
chatTextTable->cellAt(row,0).firstCursorPosition().setBlockFormat(nameFormat);
chatTextTable->cellAt(row,0).firstCursorPosition().insertHtml(msgAction->getName());
chatTextTable->cellAt(row,1).firstCursorPosition().insertHtml(msgAction->getMessage());
chatTextTable->cellAt(row,2).firstCursorPosition().insertText(msgAction->getDate());
chatTextTable->cellAt(row,2).firstCursorPosition().setBlockFormat(dateFormat);
chatTextTable->cellAt(row,2).firstCursorPosition().insertHtml(msgAction->getDate());
msgAction->setup(cur, this);

View File

@ -27,7 +27,7 @@
EmoticonsWidget::EmoticonsWidget(QWidget *parent) :
QMenu(parent)
{
setStyleSheet(Style::get(":/ui/emoticonWidget/emoticonWidget.css"));
setStyleSheet(Style::getStylesheet(":/ui/emoticonWidget/emoticonWidget.css"));
setLayout(&layout);
layout.addWidget(&stack);

View File

@ -34,18 +34,26 @@
#include "core.h"
#include "widget/widget.h"
#include "widget/maskablepixmapwidget.h"
#include "widget/croppinglabel.h"
#include "misc/style.h"
ChatForm::ChatForm(Friend* chatFriend)
: f(chatFriend)
{
nameLabel->setText(f->getName());
avatar->setPixmap(QPixmap(":/img/contact_dark.png"));
avatar->setPixmap(QPixmap(":/img/contact_dark.png"), Qt::transparent);
statusMessageLabel = new CroppingLabel();
statusMessageLabel->setFont(Style::getFont(Style::Medium));
QPalette pal; pal.setColor(QPalette::WindowText, Style::getColor(Style::MediumGrey));
statusMessageLabel->setPalette(pal);
netcam = new NetCamView();
headTextLayout->addWidget(statusMessageLabel);
headTextLayout->addStretch();
headTextLayout->setSpacing(0);
connect(Core::getInstance(), &Core::fileSendStarted, this, &ChatForm::startFileSend);
connect(Core::getInstance(), &Core::videoFrameReceived, netcam, &NetCamView::updateDisplay);
@ -507,5 +515,5 @@ void ChatForm::onAvatarRemoved(int FriendId)
if (FriendId != f->friendId)
return;
avatar->setPixmap(QPixmap(":/img/contact_dark.png"));
avatar->setPixmap(QPixmap(":/img/contact_dark.png"), Qt::transparent);
}

View File

@ -36,6 +36,10 @@ GenericChatForm::GenericChatForm(QWidget *parent) :
headWidget = new QWidget();
nameLabel = new CroppingLabel();
nameLabel->setFont(Style::getFont(Style::MediumBold));
QPalette pal; pal.setColor(QPalette::WindowText, Style::getColor(Style::DarkGrey));
nameLabel->setPalette(pal);
avatar = new MaskablePixmapWidget(this, QSize(40,40), ":/img/avatar_mask.png");
QHBoxLayout *headLayout = new QHBoxLayout(), *mainFootLayout = new QHBoxLayout();
headTextLayout = new QVBoxLayout();
@ -43,8 +47,8 @@ GenericChatForm::GenericChatForm(QWidget *parent) :
QVBoxLayout *footButtonsSmall = new QVBoxLayout(), *volMicLayout = new QVBoxLayout();
chatWidget = new ChatAreaWidget();
chatWidget->document()->setDefaultStyleSheet(Style::get(":ui/chatArea/innerStyle.css"));
chatWidget->setStyleSheet(Style::get(":/ui/chatArea/chatArea.css"));
chatWidget->document()->setDefaultStyleSheet(Style::getStylesheet(":ui/chatArea/innerStyle.css"));
chatWidget->setStyleSheet(Style::getStylesheet(":/ui/chatArea/chatArea.css"));
msgEdit = new ChatTextEdit();
@ -63,25 +67,25 @@ GenericChatForm::GenericChatForm(QWidget *parent) :
footButtonsSmall->setSpacing(2);
msgEdit->setStyleSheet(Style::get(":/ui/msgEdit/msgEdit.css"));
msgEdit->setStyleSheet(Style::getStylesheet(":/ui/msgEdit/msgEdit.css"));
msgEdit->setFixedHeight(50);
msgEdit->setFrameStyle(QFrame::NoFrame);
sendButton->setStyleSheet(Style::get(":/ui/sendButton/sendButton.css"));
fileButton->setStyleSheet(Style::get(":/ui/fileButton/fileButton.css"));
emoteButton->setStyleSheet(Style::get(":/ui/emoteButton/emoteButton.css"));
sendButton->setStyleSheet(Style::getStylesheet(":/ui/sendButton/sendButton.css"));
fileButton->setStyleSheet(Style::getStylesheet(":/ui/fileButton/fileButton.css"));
emoteButton->setStyleSheet(Style::getStylesheet(":/ui/emoteButton/emoteButton.css"));
callButton->setObjectName("green");
callButton->setStyleSheet(Style::get(":/ui/callButton/callButton.css"));
callButton->setStyleSheet(Style::getStylesheet(":/ui/callButton/callButton.css"));
videoButton->setObjectName("green");
videoButton->setStyleSheet(Style::get(":/ui/videoButton/videoButton.css"));
videoButton->setStyleSheet(Style::getStylesheet(":/ui/videoButton/videoButton.css"));
QString volButtonStylesheet = Style::get(":/ui/volButton/volButton.css");
QString volButtonStylesheet = Style::getStylesheet(":/ui/volButton/volButton.css");
volButton->setObjectName("green");
volButton->setStyleSheet(volButtonStylesheet);
QString micButtonStylesheet = Style::get(":/ui/micButton/micButton.css");
QString micButtonStylesheet = Style::getStylesheet(":/ui/micButton/micButton.css");
micButton->setObjectName("green");
micButton->setStyleSheet(micButtonStylesheet);
@ -169,7 +173,9 @@ void GenericChatForm::addMessage(QString author, QString message, QDateTime date
if (previousName == author)
chatWidget->insertMessage(new MessageAction("", message, date, isMe));
else chatWidget->insertMessage(new MessageAction(getElidedName(author) , message, date, isMe));
else
chatWidget->insertMessage(new MessageAction(getElidedName(author) , message, date, isMe));
previousName = author;
}

View File

@ -21,6 +21,7 @@
#include "widget/croppinglabel.h"
#include "widget/maskablepixmapwidget.h"
#include "core.h"
#include "misc/style.h"
#include <QPushButton>
#include <QMimeData>
#include <QDragEnterEvent>
@ -40,10 +41,14 @@ GroupChatForm::GroupChatForm(Group* chatGroup)
QFont small;
small.setPixelSize(10);
nameLabel->setText(group->widget->name.text());
nusersLabel->setFont(small);
nameLabel->setText(group->widget->getName());
nusersLabel->setFont(Style::getFont(Style::Medium));
nusersLabel->setText(GroupChatForm::tr("%1 users in chat","Number of users in chat").arg(group->peers.size()));
avatar->setPixmap(QPixmap(":/img/group_dark.png"));
QPalette pal; pal.setColor(QPalette::WindowText, Style::getColor(Style::MediumGrey));
nusersLabel->setPalette(pal);
avatar->setPixmap(QPixmap(":/img/group_dark.png"), Qt::transparent);
QString names;
for (QString& s : group->peers)

View File

@ -23,6 +23,8 @@
#include "core.h"
#include "widget/form/chatform.h"
#include "widget/maskablepixmapwidget.h"
#include "widget/croppinglabel.h"
#include "misc/style.h"
#include <QContextMenuEvent>
#include <QMenu>
#include <QDrag>
@ -31,56 +33,12 @@
#include <QBitmap>
FriendWidget::FriendWidget(int FriendId, QString id)
: friendId(FriendId), isDefaultAvatar{true}
: 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_dark.png"));
name.setText(id);
//statusPic.setAlignment(Qt::AlignHCenter);
avatar->setPixmap(QPixmap(":img/contact.png"), Qt::transparent);
statusPic.setPixmap(QPixmap(":img/status/dot_away.png"));
QFont small;
small.setPixelSize(10);
statusMessage.setFont(small);
QPalette pal;
pal.setColor(QPalette::WindowText,Qt::gray);
statusMessage.setPalette(pal);
QPalette pal2;
pal2.setColor(QPalette::WindowText,Qt::white);
name.setPalette(pal2);
QPalette pal3;
pal3.setColor(QPalette::Background, QColor(65,65,65,255));
this->setPalette(pal3);
textLayout.addStretch();
textLayout.addWidget(&name);
textLayout.addWidget(&statusMessage);
textLayout.addStretch();
layout.addSpacing(20);
layout.addWidget(avatar);
layout.addSpacing(5);
layout.addLayout(&textLayout);
layout.addSpacing(5);
layout.addWidget(&statusPic);
layout.addSpacing(5);
isActiveWidget = 0;
layout.invalidate();
layout.update();
layout.activate();
updateGeometry();
nameLabel->setText(id);
}
void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
@ -92,7 +50,7 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
QMap<QAction*, Group*> groupActions;
for (Group* group : GroupList::groupList)
{
QAction* groupAction = inviteMenu->addAction(group->widget->name.text());
QAction* groupAction = inviteMenu->addAction(group->widget->getName());
groupActions[groupAction] = group;
}
if (groupActions.isEmpty())
@ -126,38 +84,18 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
void FriendWidget::setAsActiveChatroom()
{
isActiveWidget = 1;
setActive(true);
QFont small;
small.setPixelSize(10);
statusMessage.setFont(small);
QPalette pal;
pal.setColor(QPalette::WindowText,Qt::darkGray);
statusMessage.setPalette(pal);
QPalette pal2;
pal2.setColor(QPalette::WindowText,Qt::black);
name.setPalette(pal2);
QPalette pal3;
pal3.setColor(QPalette::Background, Qt::white);
this->setPalette(pal3);
if (isDefaultAvatar)
avatar->setPixmap(QPixmap(":img/contact_dark.png"), Qt::transparent);
}
void FriendWidget::setAsInactiveChatroom()
{
isActiveWidget = 0;
setActive(false);
QFont small;
small.setPixelSize(10);
statusMessage.setFont(small);
QPalette pal;
pal.setColor(QPalette::WindowText,Qt::gray);
statusMessage.setPalette(pal);
QPalette pal2;
pal2.setColor(QPalette::WindowText,Qt::white);
name.setPalette(pal2);
QPalette pal3;
pal3.setColor(QPalette::Background, QColor(65,65,65,255));
this->setPalette(pal3);
if (isDefaultAvatar)
avatar->setPixmap(QPixmap(":img/contact.png"), Qt::transparent);
}
void FriendWidget::updateStatusLight()
@ -202,6 +140,7 @@ void FriendWidget::onAvatarChange(int FriendId, const QPixmap& pic)
isDefaultAvatar = false;
avatar->setPixmap(pic);
avatar->autopickBackground();
}
void FriendWidget::onAvatarRemoved(int FriendId)
@ -210,7 +149,7 @@ void FriendWidget::onAvatarRemoved(int FriendId)
return;
isDefaultAvatar = true;
avatar->setPixmap(QPixmap(":img/contact_dark.png"));
avatar->setPixmap(QPixmap(":img/contact.png"), Qt::transparent);
}
void FriendWidget::mousePressEvent(QMouseEvent *ev)

View File

@ -20,7 +20,6 @@
#include <QLabel>
#include "genericchatroomwidget.h"
#include "croppinglabel.h"
class QPixmap;
class MaskablePixmapWidget;
@ -52,9 +51,6 @@ protected:
public:
int friendId;
MaskablePixmapWidget* avatar;
QLabel statusPic;
CroppingLabel name, statusMessage;
bool isDefaultAvatar;
QPoint dragStartPos;
};

View File

@ -15,56 +15,82 @@
*/
#include "genericchatroomwidget.h"
#include "misc/style.h"
#include "widget/maskablepixmapwidget.h"
#include "croppinglabel.h"
#include <QMouseEvent>
#include <QStyle>
GenericChatroomWidget::GenericChatroomWidget(QWidget *parent) :
QWidget(parent)
GenericChatroomWidget::GenericChatroomWidget(QWidget *parent)
: QFrame(parent)
{
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
// avatar
avatar = new MaskablePixmapWidget(this, QSize(40,40), ":/img/avatar_mask.png");
// status text
statusMessageLabel = new CroppingLabel(this);
statusMessageLabel->setObjectName("status");
// name text
nameLabel = new CroppingLabel(this);
nameLabel->setObjectName("name");
textLayout.addStretch();
textLayout.addWidget(nameLabel);
textLayout.addWidget(statusMessageLabel);
textLayout.addStretch();
layout.addSpacing(20);
layout.addWidget(avatar);
layout.addSpacing(10);
layout.addLayout(&textLayout);
layout.addSpacing(10);
layout.addWidget(&statusPic);
layout.addSpacing(10);
layout.activate();
setProperty("active", false);
setStyleSheet(Style::getStylesheet(":/ui/chatroomWidgets/genericChatroomWidget.css"));
}
int GenericChatroomWidget::isActive()
bool GenericChatroomWidget::isActive()
{
return isActiveWidget;
return property("active").toBool();
}
void GenericChatroomWidget::mousePressEvent(QMouseEvent *event)
void GenericChatroomWidget::setActive(bool active)
{
if ((event->buttons() & Qt::LeftButton) == Qt::LeftButton)
{
if (isActive())
{
QPalette pal;
pal.setColor(QPalette::Background, QColor(250,250,250,255));
this->setPalette(pal);
}
else
{
QPalette pal;
pal.setColor(QPalette::Background, QColor(85,85,85,255));
this->setPalette(pal);
}
}
setProperty("active", active);
Style::repolish(this);
}
void GenericChatroomWidget::leaveEvent(QEvent *)
void GenericChatroomWidget::setName(const QString &name)
{
if (isActive() != 1)
{
QPalette pal;
pal.setColor(QPalette::Background, lastColor);
this->setPalette(pal);
}
nameLabel->setText(name);
}
void GenericChatroomWidget::enterEvent(QEvent *)
void GenericChatroomWidget::setStatusMsg(const QString &status)
{
if (isActive() != 1)
{
QPalette pal;
pal.setColor(QPalette::Background, QColor(75,75,75,255));
lastColor = this->palette().background().color();
this->setPalette(pal);
}
statusMessageLabel->setText(status);
}
QString GenericChatroomWidget::getName() const
{
return nameLabel->text();
}
QString GenericChatroomWidget::getStatusMsg() const
{
return statusMessageLabel->text();
}
void GenericChatroomWidget::mouseReleaseEvent(QMouseEvent*)

View File

@ -17,23 +17,24 @@
#ifndef GENERICCHATROOMWIDGET_H
#define GENERICCHATROOMWIDGET_H
#include <QWidget>
#include <QFrame>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
class CroppingLabel;
class MaskablePixmapWidget;
namespace Ui {
class MainWindow;
}
class GenericChatroomWidget : public QWidget
class GenericChatroomWidget : public QFrame
{
Q_OBJECT
public:
GenericChatroomWidget(QWidget *parent = 0);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent (QMouseEvent* event);
void leaveEvent(QEvent *);
void enterEvent(QEvent *);
virtual void setAsActiveChatroom(){;}
virtual void setAsInactiveChatroom(){;}
@ -41,7 +42,14 @@ public:
virtual void setChatForm(Ui::MainWindow &){;}
virtual void resetEventFlags(){;}
int isActive();
bool isActive();
void setActive(bool active);
void setName(const QString& name);
void setStatusMsg(const QString& status);
QString getName() const;
QString getStatusMsg() const;
signals:
void chatroomWidgetClicked(GenericChatroomWidget* widget);
@ -49,10 +57,12 @@ signals:
public slots:
protected:
int isActiveWidget;
QColor lastColor;
QHBoxLayout layout;
QVBoxLayout textLayout;
MaskablePixmapWidget* avatar;
QLabel statusPic;
CroppingLabel *nameLabel, *statusMessageLabel;
};
#endif // GENERICCHATROOMWIDGET_H

View File

@ -20,6 +20,7 @@
#include "misc/settings.h"
#include "widget/form/groupchatform.h"
#include "widget/maskablepixmapwidget.h"
#include "misc/style.h"
#include <QPalette>
#include <QMenu>
#include <QContextMenuEvent>
@ -29,53 +30,15 @@
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), QString(), Qt::transparent);
avatar->setPixmap(QPixmap(":img/group.png"));
avatar->setPixmap(QPixmap(":img/group.png"), Qt::transparent);
statusPic.setPixmap(QPixmap(":img/status/dot_online.png"));
name.setText(Name);
QFont small;
small.setPixelSize(10);
nusers.setFont(small);
QPalette pal;
pal.setColor(QPalette::WindowText,Qt::gray);
nusers.setPalette(pal);
QPalette pal2;
pal2.setColor(QPalette::WindowText,Qt::white);
name.setPalette(pal2);
QPalette pal3;
pal3.setColor(QPalette::Background, QColor(65,65,65,255));
this->setPalette(pal3);
nameLabel->setText(Name);
Group* g = GroupList::findGroup(groupId);
if (g)
nusers.setText(GroupWidget::tr("%1 users in chat").arg(g->peers.size()));
statusMessageLabel->setText(GroupWidget::tr("%1 users in chat").arg(g->peers.size()));
else
nusers.setText(GroupWidget::tr("0 users in chat"));
textLayout.addStretch();
textLayout.addWidget(&name);
textLayout.addWidget(&nusers);
textLayout.addStretch();
layout.addSpacing(20);
layout.addWidget(avatar);
layout.addSpacing(5);
layout.addLayout(&textLayout);
layout.addStretch();
layout.addSpacing(5);
layout.addWidget(&statusPic);
layout.addSpacing(5);
isActiveWidget = 0;
statusMessageLabel->setText(GroupWidget::tr("0 users in chat"));
}
void GroupWidget::contextMenuEvent(QContextMenuEvent * event)
@ -86,60 +49,28 @@ void GroupWidget::contextMenuEvent(QContextMenuEvent * event)
QAction* selectedItem = menu.exec(pos);
if (selectedItem == quitGroup)
{
hide();
show(); //Toggle visibility to work around bug of repaintEvent() not being fired on parent widget when this is hidden
hide();
emit removeGroup(groupId);
return;
}
}
void GroupWidget::onUserListChanged()
{
Group* g = GroupList::findGroup(groupId);
if (g)
nusers.setText(tr("%1 users in chat").arg(g->nPeers));
statusMessageLabel->setText(tr("%1 users in chat").arg(g->nPeers));
else
nusers.setText(tr("0 users in chat"));
statusMessageLabel->setText(tr("0 users in chat"));
}
void GroupWidget::setAsActiveChatroom()
{
isActiveWidget = 1;
QFont small;
small.setPixelSize(10);
nusers.setFont(small);
QPalette pal;
pal.setColor(QPalette::WindowText,Qt::darkGray);
nusers.setPalette(pal);
QPalette pal2;
pal2.setColor(QPalette::WindowText,Qt::black);
name.setPalette(pal2);
QPalette pal3;
pal3.setColor(QPalette::Background, Qt::white);
this->setPalette(pal3);
avatar->setPixmap(QPixmap(":img/group_dark.png"));
setActive(true);
avatar->setPixmap(QPixmap(":img/group_dark.png"), Qt::transparent);
}
void GroupWidget::setAsInactiveChatroom()
{
isActiveWidget = 0;
QFont small;
small.setPixelSize(10);
nusers.setFont(small);
QPalette pal;
pal.setColor(QPalette::WindowText,Qt::gray);
nusers.setPalette(pal);
QPalette pal2;
pal2.setColor(QPalette::WindowText,Qt::white);
name.setPalette(pal2);
QPalette pal3;
pal3.setColor(QPalette::Background, QColor(65,65,65,255));
this->setPalette(pal3);
avatar->setPixmap(QPixmap(":img/group.png"));
setActive(false);
avatar->setPixmap(QPixmap(":img/group.png"), Qt::transparent);
}
void GroupWidget::updateStatusLight()
@ -152,16 +83,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"));
}
}
}

View File

@ -20,8 +20,6 @@
#include <QLabel>
#include "genericchatroomwidget.h"
class MaskablePixmapWidget;
class GroupWidget : public GenericChatroomWidget
{
Q_OBJECT
@ -41,8 +39,6 @@ signals:
public:
int groupId;
QLabel name, nusers, statusPic;
MaskablePixmapWidget* avatar;
};
#endif // GROUPWIDGET_H

View File

@ -17,9 +17,9 @@
#include "maskablepixmapwidget.h"
#include <QPainter>
MaskablePixmapWidget::MaskablePixmapWidget(QWidget *parent, QSize size, QString maskName, QColor background)
MaskablePixmapWidget::MaskablePixmapWidget(QWidget *parent, QSize size, QString maskName)
: QWidget(parent)
, backgroundColor(background)
, backgroundColor(Qt::white)
, clickable(false)
{
setFixedSize(size);
@ -30,6 +30,48 @@ MaskablePixmapWidget::MaskablePixmapWidget(QWidget *parent, QSize size, QString
mask = QPixmap(maskName).scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
}
void MaskablePixmapWidget::autopickBackground()
{
QImage pic = pixmap.toImage();
if (pic.isNull())
return;
int r = 0;
int g = 0;
int b = 0;
int weight = 0;
for (int x=0;x<pic.width();++x)
{
for (int y=0;y<pic.height();++y)
{
QRgb color = pic.pixel(x,y);
r += qRed(color);
g += qGreen(color);
b += qBlue(color);
weight += qAlpha(color);
}
}
weight = qMax(1, weight / 255);
r /= weight;
g /= weight;
b /= weight;
QColor color = QColor::fromRgb(r,g,b);
backgroundColor = QColor::fromRgb(0xFFFFFF ^ color.rgb());
update();
}
void MaskablePixmapWidget::setBackground(QColor color)
{
backgroundColor = color;
update();
}
void MaskablePixmapWidget::setClickable(bool clickable)
{
this->clickable = clickable;
@ -40,10 +82,26 @@ void MaskablePixmapWidget::setClickable(bool clickable)
unsetCursor();
}
void MaskablePixmapWidget::setPixmap(const QPixmap &pmap, QColor background)
{
if (!pmap.isNull())
{
pixmap = pmap.scaled(width(), height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
backgroundColor = background;
update();
}
}
void MaskablePixmapWidget::setPixmap(const QPixmap &pmap)
{
pixmap = pmap.scaled(width(), height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
update();
if (!pmap.isNull())
{
pixmap = pmap.scaled(width(), height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
autopickBackground();
update();
}
}
QPixmap MaskablePixmapWidget::getPixmap() const

View File

@ -23,9 +23,12 @@ class MaskablePixmapWidget : public QWidget
{
Q_OBJECT
public:
MaskablePixmapWidget(QWidget *parent, QSize size, QString maskName, QColor background = Qt::white);
MaskablePixmapWidget(QWidget *parent, QSize size, QString maskName = QString());
void autopickBackground();
void setBackground(QColor color);
void setClickable(bool clickable);
void setPixmap(const QPixmap &pmap, QColor background);
void setPixmap(const QPixmap &pmap);
QPixmap getPixmap() const;

View File

@ -41,13 +41,15 @@ QString ChatAction::QImage2base64(const QImage &img)
QString ChatAction::getName()
{
if (isMe)
return QString("<div class=name_me>" + toHtmlChars(name) + "</div>");
return QString("<div class=%1>%2</div>").arg("name_me").arg(toHtmlChars(name));
else
return QString("<div class=name>" + toHtmlChars(name) + "</div>");
return QString("<div class=%1>%2</div>").arg("name").arg(toHtmlChars(name));
}
QString ChatAction::getDate()
{
QString res = date;
return res;
if (isMe)
return QString("<div class=date_me>" + toHtmlChars(date) + "</div>");
else
return QString("<div class=date>" + toHtmlChars(date) + "</div>");
}

View File

@ -71,5 +71,8 @@ QString MessageAction::getMessage()
}
message_ = message_.left(message_.length()-4);
return QString("<div class=message>" + message_ + "</div>");
if (isMe)
return QString("<div class=message_me>" + message_ + "</div>");
else
return QString("<div class=message>" + message_ + "</div>");
}

View File

@ -68,17 +68,17 @@ Widget::Widget(QWidget *parent)
this->layout()->setContentsMargins(0, 0, 0, 0);
ui->friendList->setObjectName("friendList");
ui->friendList->setStyleSheet(Style::get(":ui/friendList/friendList.css"));
ui->friendList->setStyleSheet(Style::getStylesheet(":ui/friendList/friendList.css"));
}
else
{
this->setObjectName("activeWindow");
this->setStyleSheet(Style::get(":ui/window/window.css"));
this->setStyleSheet(Style::getStylesheet(":ui/window/window.css"));
ui->statusPanel->setStyleSheet(QString(""));
ui->friendList->setStyleSheet(QString(""));
ui->friendList->setObjectName("friendList");
ui->friendList->setStyleSheet(Style::get(":ui/friendList/friendList.css"));
ui->friendList->setStyleSheet(Style::getStylesheet(":ui/friendList/friendList.css"));
ui->tbMenu->setIcon(QIcon(":ui/window/applicationIcon.png"));
ui->pbMin->setObjectName("minimizeButton");
@ -116,6 +116,7 @@ Widget::Widget(QWidget *parent)
profilePicture->setPixmap(QPixmap(":/img/contact_dark.png"));
profilePicture->setClickable(true);
ui->horizontalLayout_3->insertWidget(0,profilePicture);
ui->horizontalLayout_3->insertSpacing(1, 7);
ui->mainContent->setLayout(new QVBoxLayout());
ui->mainHead->setLayout(new QVBoxLayout());
@ -129,13 +130,16 @@ Widget::Widget(QWidget *parent)
ui->nameLabel->setEditable(true);
ui->statusLabel->setEditable(true);
ui->statusLabel->setFont(Style::getFont(Style::Medium));
ui->nameLabel->setFont(Style::getFont(Style::ExtraBig));
// delay setting username and message until Core inits
//ui->nameLabel->setText(core->getUsername());
ui->nameLabel->setStyleSheet("QLabel { color : white; font-size: 11pt; font-weight:bold;}");
//ui->statusLabel->setText(core->getStatusMessage());
ui->statusLabel->setStyleSheet("QLabel { color : white; font-size: 8pt;}");
ui->statusButton->setStyleSheet(Style::get(":/ui/statusButton/statusButton.css"));
ui->statusButton->setStyleSheet(Style::getStylesheet(":/ui/statusButton/statusButton.css"));
QMenu *statusButtonMenu = new QMenu(ui->statusButton);
QAction* setStatusOnline = statusButtonMenu->addAction(Widget::tr("Online","Button to set your status to 'Online'"));