mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Added MaskablePixmapWidget, improved avatar rendering
This commit is contained in:
parent
dfc40aa8e8
commit
5662aa933f
BIN
img/avatar_mask.png
Normal file
BIN
img/avatar_mask.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.6 KiB |
BIN
img/avatar_mask_circle.png
Normal file
BIN
img/avatar_mask_circle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.1 KiB |
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>716</width>
|
||||
<height>543</height>
|
||||
<width>714</width>
|
||||
<height>541</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
|
@ -1452,32 +1452,20 @@ QSplitter:handle{
|
|||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="ClickableLabel" name="profilePicture">
|
||||
<property name="minimumSize">
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Maximum</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>40</height>
|
||||
<width>5</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="res.qrc">:/img/contact.png</pixmap>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,1">
|
||||
|
@ -2095,8 +2083,8 @@ QSplitter:handle{
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>263</width>
|
||||
<height>378</height>
|
||||
<width>262</width>
|
||||
<height>375</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5"/>
|
||||
|
@ -3230,8 +3218,8 @@ QSplitter:handle{
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>716</width>
|
||||
<height>19</height>
|
||||
<width>714</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
|
@ -3257,11 +3245,6 @@ QSplitter:handle{
|
|||
<extends>QLabel</extends>
|
||||
<header>widget/croppinglabel.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>ClickableLabel</class>
|
||||
<extends>QLabel</extends>
|
||||
<header>widget/tool/clickablelabel.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="res.qrc"/>
|
||||
|
|
5
qtox.pro
5
qtox.pro
|
@ -117,7 +117,7 @@ HEADERS += widget/form/addfriendform.h \
|
|||
widget/tool/chatactions/messageaction.h \
|
||||
widget/tool/chatactions/filetransferaction.h \
|
||||
widget/tool/chatactions/systemmessageaction.h \
|
||||
widget/tool/clickablelabel.h
|
||||
widget/maskablepixmapwidget.h
|
||||
|
||||
SOURCES += \
|
||||
widget/form/addfriendform.cpp \
|
||||
|
@ -157,4 +157,5 @@ SOURCES += \
|
|||
widget/settingsdialog.cpp \
|
||||
widget/tool/chatactions/messageaction.cpp \
|
||||
widget/tool/chatactions/filetransferaction.cpp \
|
||||
widget/tool/chatactions/systemmessageaction.cpp
|
||||
widget/tool/chatactions/systemmessageaction.cpp \
|
||||
widget/maskablepixmapwidget.cpp
|
||||
|
|
2
res.qrc
2
res.qrc
|
@ -142,5 +142,7 @@
|
|||
<file>translations/pl.qm</file>
|
||||
<file>translations/fi.qm</file>
|
||||
<file>translations/mannol.qm</file>
|
||||
<file>img/avatar_mask.png</file>
|
||||
<file>img/avatar_mask_circle.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <QMimeData>
|
||||
#include <QFileInfo>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QBitmap>
|
||||
#include "chatform.h"
|
||||
#include "friend.h"
|
||||
#include "widget/friendwidget.h"
|
||||
|
@ -32,12 +33,13 @@
|
|||
#include "widget/tool/chattextedit.h"
|
||||
#include "core.h"
|
||||
#include "widget/widget.h"
|
||||
#include "widget/maskablepixmapwidget.h"
|
||||
|
||||
ChatForm::ChatForm(Friend* chatFriend)
|
||||
: f(chatFriend)
|
||||
{
|
||||
nameLabel->setText(f->getName());
|
||||
avatarLabel->setPixmap(QPixmap(":/img/contact_dark.png"));
|
||||
avatar->setPixmap(QPixmap(":/img/contact_dark.png"));
|
||||
|
||||
statusMessageLabel = new CroppingLabel();
|
||||
netcam = new NetCamView();
|
||||
|
@ -475,8 +477,7 @@ void ChatForm::onAvatarChange(int FriendId, const QPixmap &pic)
|
|||
if (FriendId != f->friendId)
|
||||
return;
|
||||
|
||||
QPixmap scaled = pic.scaled(40,40,Qt::KeepAspectRatio,Qt::SmoothTransformation);
|
||||
avatarLabel->setPixmap(scaled);
|
||||
avatar->setPixmap(pic);
|
||||
}
|
||||
|
||||
void ChatForm::dragEnterEvent(QDragEnterEvent *ev)
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "widget/tool/chatactions/systemmessageaction.h"
|
||||
#include "widget/chatareawidget.h"
|
||||
#include "widget/tool/chattextedit.h"
|
||||
#include "widget/maskablepixmapwidget.h"
|
||||
|
||||
GenericChatForm::GenericChatForm(QWidget *parent) :
|
||||
QWidget(parent)
|
||||
|
@ -35,7 +36,7 @@ GenericChatForm::GenericChatForm(QWidget *parent) :
|
|||
headWidget = new QWidget();
|
||||
|
||||
nameLabel = new CroppingLabel();
|
||||
avatarLabel = new QLabel();
|
||||
avatar = new MaskablePixmapWidget(this, QSize(40,40), ":/img/avatar_mask_circle.png");
|
||||
QHBoxLayout *headLayout = new QHBoxLayout(), *mainFootLayout = new QHBoxLayout();
|
||||
headTextLayout = new QVBoxLayout();
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout();
|
||||
|
@ -99,7 +100,7 @@ GenericChatForm::GenericChatForm(QWidget *parent) :
|
|||
mainFootLayout->setSpacing(0);
|
||||
|
||||
headWidget->setLayout(headLayout);
|
||||
headLayout->addWidget(avatarLabel);
|
||||
headLayout->addWidget(avatar);
|
||||
headLayout->addLayout(headTextLayout);
|
||||
headLayout->addLayout(volMicLayout);
|
||||
headLayout->addWidget(callButton);
|
||||
|
|
|
@ -30,6 +30,7 @@ class QPushButton;
|
|||
class CroppingLabel;
|
||||
class ChatTextEdit;
|
||||
class ChatAreaWidget;
|
||||
class MaskablePixmapWidget;
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
|
@ -60,7 +61,7 @@ protected slots:
|
|||
|
||||
protected:
|
||||
CroppingLabel *nameLabel;
|
||||
QLabel *avatarLabel;
|
||||
MaskablePixmapWidget *avatar;
|
||||
QWidget *headWidget;
|
||||
QPushButton *fileButton, *emoteButton, *callButton, *videoButton, *volButton, *micButton;
|
||||
QVBoxLayout *headTextLayout;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "widget/groupwidget.h"
|
||||
#include "widget/tool/chattextedit.h"
|
||||
#include "widget/croppinglabel.h"
|
||||
#include "widget/maskablepixmapwidget.h"
|
||||
#include "core.h"
|
||||
#include <QPushButton>
|
||||
#include <QMimeData>
|
||||
|
@ -42,7 +43,7 @@ GroupChatForm::GroupChatForm(Group* chatGroup)
|
|||
nameLabel->setText(group->widget->name.text());
|
||||
nusersLabel->setFont(small);
|
||||
nusersLabel->setText(GroupChatForm::tr("%1 users in chat","Number of users in chat").arg(group->peers.size()));
|
||||
avatarLabel->setPixmap(QPixmap(":/img/group_dark.png"));
|
||||
avatar->setPixmap(QPixmap(":/img/group_dark.png"));
|
||||
|
||||
QString names;
|
||||
for (QString& s : group->peers)
|
||||
|
|
|
@ -22,11 +22,13 @@
|
|||
#include "friend.h"
|
||||
#include "core.h"
|
||||
#include "widget/form/chatform.h"
|
||||
#include "widget/maskablepixmapwidget.h"
|
||||
#include <QContextMenuEvent>
|
||||
#include <QMenu>
|
||||
#include <QDrag>
|
||||
#include <QMimeData>
|
||||
#include <QApplication>
|
||||
#include <QBitmap>
|
||||
|
||||
FriendWidget::FriendWidget(int FriendId, QString id)
|
||||
: friendId(FriendId), isDefaultAvatar{true}
|
||||
|
@ -42,7 +44,8 @@ FriendWidget::FriendWidget(int FriendId, QString id)
|
|||
textLayout.setMargin(0);
|
||||
setLayoutDirection(Qt::LeftToRight); // parent might have set Qt::RightToLeft
|
||||
|
||||
avatar.setPixmap(QPixmap(":img/contact.png"));
|
||||
avatar = new MaskablePixmapWidget(this, QSize(40,40), ":/img/avatar_mask.png");
|
||||
avatar->setPixmap(QPixmap(":img/contact.png"));
|
||||
name.setText(id);
|
||||
//statusPic.setAlignment(Qt::AlignHCenter);
|
||||
statusPic.setPixmap(QPixmap(":img/status/dot_away.png"));
|
||||
|
@ -65,7 +68,7 @@ FriendWidget::FriendWidget(int FriendId, QString id)
|
|||
textLayout.addStretch();
|
||||
|
||||
layout.addSpacing(20);
|
||||
layout.addWidget(&avatar);
|
||||
layout.addWidget(avatar);
|
||||
layout.addSpacing(5);
|
||||
layout.addLayout(&textLayout);
|
||||
layout.addSpacing(5);
|
||||
|
@ -138,7 +141,7 @@ void FriendWidget::setAsActiveChatroom()
|
|||
pal3.setColor(QPalette::Background, Qt::white);
|
||||
this->setPalette(pal3);
|
||||
if (isDefaultAvatar)
|
||||
avatar.setPixmap(QPixmap(":img/contact_dark.png"));
|
||||
avatar->setPixmap(QPixmap(":img/contact_dark.png"));
|
||||
}
|
||||
|
||||
void FriendWidget::setAsInactiveChatroom()
|
||||
|
@ -159,7 +162,7 @@ void FriendWidget::setAsInactiveChatroom()
|
|||
this->setPalette(pal3);
|
||||
|
||||
if (isDefaultAvatar)
|
||||
avatar.setPixmap(QPixmap(":img/contact.png"));
|
||||
avatar->setPixmap(QPixmap(":img/contact.png"));
|
||||
}
|
||||
|
||||
void FriendWidget::updateStatusLight()
|
||||
|
@ -203,8 +206,7 @@ void FriendWidget::onAvatarChange(int FriendId, const QPixmap& pic)
|
|||
return;
|
||||
|
||||
isDefaultAvatar = false;
|
||||
QPixmap scaled = pic.scaled(40,40,Qt::KeepAspectRatio,Qt::SmoothTransformation);
|
||||
avatar.setPixmap(scaled);
|
||||
avatar->setPixmap(pic);
|
||||
}
|
||||
|
||||
void FriendWidget::mousePressEvent(QMouseEvent *ev)
|
||||
|
@ -225,8 +227,7 @@ void FriendWidget::mouseMoveEvent(QMouseEvent *ev)
|
|||
mdata->setData("friend", QString::number(friendId).toLatin1());
|
||||
|
||||
drag->setMimeData(mdata);
|
||||
if (avatar.pixmap())
|
||||
drag->setPixmap(*avatar.pixmap());
|
||||
drag->setPixmap(avatar->getPixmap());
|
||||
|
||||
drag->exec(Qt::CopyAction | Qt::MoveAction);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "croppinglabel.h"
|
||||
|
||||
class QPixmap;
|
||||
class MaskablePixmapWidget;
|
||||
|
||||
struct FriendWidget : public GenericChatroomWidget
|
||||
{
|
||||
|
@ -50,7 +51,8 @@ protected:
|
|||
|
||||
public:
|
||||
int friendId;
|
||||
QLabel avatar, statusPic;
|
||||
MaskablePixmapWidget* avatar;
|
||||
QLabel statusPic;
|
||||
CroppingLabel name, statusMessage;
|
||||
bool isDefaultAvatar;
|
||||
QPoint dragStartPos;
|
||||
|
|
61
widget/maskablepixmapwidget.cpp
Normal file
61
widget/maskablepixmapwidget.cpp
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
This program is libre software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "maskablepixmapwidget.h"
|
||||
#include <QPainter>
|
||||
#include <QPaintEvent>
|
||||
|
||||
MaskablePixmapWidget::MaskablePixmapWidget(QWidget *parent, QSize size, QString maskName)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setMinimumSize(size);
|
||||
setMaximumSize(size);
|
||||
|
||||
mask = QPixmap(maskName).scaled(maximumSize(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
|
||||
void MaskablePixmapWidget::setPixmap(const QPixmap &pmap)
|
||||
{
|
||||
pixmap = pmap.scaled(maximumSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
|
||||
QPixmap MaskablePixmapWidget::getPixmap() const
|
||||
{
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
void MaskablePixmapWidget::paintEvent(QPaintEvent *ev)
|
||||
{
|
||||
QPixmap tmp(ev->rect().size());
|
||||
tmp.fill(Qt::transparent);
|
||||
|
||||
QPoint offset((ev->rect().size().width()-pixmap.size().width())/2,(ev->rect().size().height()-pixmap.size().height())/2);
|
||||
|
||||
QPainter painter(&tmp);
|
||||
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
painter.drawPixmap(offset,pixmap);
|
||||
painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
||||
painter.drawPixmap(0,0,mask);
|
||||
|
||||
painter.end();
|
||||
painter.begin(this);
|
||||
painter.drawPixmap(0,0,tmp);
|
||||
}
|
||||
|
||||
void MaskablePixmapWidget::mousePressEvent(QMouseEvent*)
|
||||
{
|
||||
emit clicked();
|
||||
}
|
45
widget/maskablepixmapwidget.h
Normal file
45
widget/maskablepixmapwidget.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
This program is libre software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef MASKABLEPIXMAPWIDGET_H
|
||||
#define MASKABLEPIXMAPWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class MaskablePixmapWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MaskablePixmapWidget(QWidget *parent, QSize size, QString maskName);
|
||||
|
||||
void setPixmap(const QPixmap &pmap);
|
||||
QPixmap getPixmap() const;
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent *ev);
|
||||
virtual void mousePressEvent(QMouseEvent *);
|
||||
|
||||
private:
|
||||
QPixmap pixmap;
|
||||
QPixmap mask;
|
||||
QSize size;
|
||||
QString maskName;
|
||||
};
|
||||
|
||||
#endif // MASKABLEPIXMAPWIDGET_H
|
|
@ -1,22 +0,0 @@
|
|||
#ifndef CLICKABLELABEL_H
|
||||
#define CLICKABLELABEL_H
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
class QMouseEvent;
|
||||
class QWidget;
|
||||
|
||||
class ClickableLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ClickableLabel(QWidget* parent = 0) : QLabel(parent) {}
|
||||
signals:
|
||||
void clicked();
|
||||
protected:
|
||||
void mousePressEvent (QMouseEvent*) {emit clicked();}
|
||||
};
|
||||
|
||||
|
||||
#endif // CLICKABLELABEL_H
|
|
@ -32,6 +32,7 @@
|
|||
#include "camera.h"
|
||||
#include "widget/form/chatform.h"
|
||||
#include "widget/settingsdialog.h"
|
||||
#include "widget/maskablepixmapwidget.h"
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
#include <QFile>
|
||||
|
@ -111,6 +112,10 @@ Widget::Widget(QWidget *parent)
|
|||
|
||||
isWindowMinimized = 0;
|
||||
|
||||
profilePicture = new MaskablePixmapWidget(this, QSize(40,40), ":/img/avatar_mask.png");
|
||||
profilePicture->setPixmap(QPixmap(":/img/avatar.png"));
|
||||
ui->horizontalLayout_3->insertWidget(0,profilePicture);
|
||||
|
||||
ui->mainContent->setLayout(new QVBoxLayout());
|
||||
ui->mainHead->setLayout(new QVBoxLayout());
|
||||
ui->mainHead->layout()->setMargin(0);
|
||||
|
@ -214,7 +219,7 @@ Widget::Widget(QWidget *parent)
|
|||
connect(ui->settingsButton, SIGNAL(clicked()), this, SLOT(onSettingsClicked()));
|
||||
connect(ui->nameLabel, SIGNAL(textChanged(QString,QString)), this, SLOT(onUsernameChanged(QString,QString)));
|
||||
connect(ui->statusLabel, SIGNAL(textChanged(QString,QString)), this, SLOT(onStatusMessageChanged(QString,QString)));
|
||||
connect(ui->profilePicture, SIGNAL(clicked()), this, SLOT(onAvatarClicked()));
|
||||
connect(profilePicture, SIGNAL(clicked()), this, SLOT(onAvatarClicked()));
|
||||
connect(setStatusOnline, SIGNAL(triggered()), this, SLOT(setStatusOnline()));
|
||||
connect(setStatusAway, SIGNAL(triggered()), this, SLOT(setStatusAway()));
|
||||
connect(setStatusBusy, SIGNAL(triggered()), this, SLOT(setStatusBusy()));
|
||||
|
@ -322,8 +327,7 @@ void Widget::onAvatarClicked()
|
|||
|
||||
void Widget::onSelfAvatarLoaded(const QPixmap& pic)
|
||||
{
|
||||
QPixmap scaled = pic.scaled(40,40, Qt::KeepAspectRatio,Qt::SmoothTransformation);
|
||||
ui->profilePicture->setPixmap(scaled);
|
||||
profilePicture->setPixmap(pic);
|
||||
}
|
||||
|
||||
void Widget::onConnected()
|
||||
|
|
|
@ -38,6 +38,7 @@ class Core;
|
|||
class Camera;
|
||||
class FriendListWidget;
|
||||
class SettingsDialog;
|
||||
class MaskablePixmapWidget;
|
||||
|
||||
class Widget : public QMainWindow
|
||||
{
|
||||
|
@ -144,6 +145,7 @@ private:
|
|||
GenericChatroomWidget* activeChatroomWidget;
|
||||
FriendListWidget* contactListWidget;
|
||||
Camera* camera;
|
||||
MaskablePixmapWidget* profilePicture;
|
||||
bool notify(QObject *receiver, QEvent *event);
|
||||
bool eventFilter(QObject *, QEvent *event);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user