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

Merge pull request #36 from F1ynn/master

Disabled custom window borders, fixed minimized window alerts, re-added dark groupchat icon
This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-07-01 10:54:23 +02:00
commit c0564783fd
23 changed files with 3620 additions and 2684 deletions

BIN
img/group_dark.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 671 B

16
res.qrc
View File

@ -81,5 +81,21 @@
<file>ui/videoButton/videoButtonYellow.png</file>
<file>ui/videoButton/videoButtonYellowHover.png</file>
<file>ui/videoButton/videoButtonYellowPressed.png</file>
<file>img/group_dark.png</file>
<file>ui/window/applicationIcon.png</file>
<file>ui/window/closeButton.png</file>
<file>ui/window/closeButtonHover.png</file>
<file>ui/window/closeButtonPressed.png</file>
<file>ui/window/maximizeButton.png</file>
<file>ui/window/maximizeButtonHover.png</file>
<file>ui/window/maximizeButtonPressed.png</file>
<file>ui/window/minimizeButton.png</file>
<file>ui/window/minimizeButtonHover.png</file>
<file>ui/window/minimizeButtonPressed.png</file>
<file>ui/window/restoreButton.png</file>
<file>ui/window/restoreButtonHover.png</file>
<file>ui/window/restoreButtonPressed.png</file>
<file>ui/friendList/friendList.css</file>
<file>ui/window/window.css</file>
</qresource>
</RCC>

View File

@ -1,21 +1,24 @@
QScrollArea {
background: transparent;
border: 0 0 0 0;
background: white;
border: 0 0 0 0 ;
}
QScrollArea > QWidget > QWidget {
background: transparent;
background: white;
}
QScrollBar:vertical {
background: white;
width: 10px;
margin: 12px 0 12px 0;
background: transparent;
width: 12px;
margin-top: 2px;
margin-bottom: 2px;
}
QScrollBar::handle:vertical {
background: #d1d1d1;
min-height: 20px;
border-radius: 3px;
margin-left: 2px;
}
QScrollBar::handle:vertical:hover {
@ -27,36 +30,19 @@ QScrollBar::handle:vertical:pressed {
}
QScrollBar::add-line:vertical {
background: url(":/ui/chatArea/scrollBarDownArrow.png") center;
height: 10px;
background: url(":ui/chatArea/scrollBarDownArrow.png") center;
height: 0px;
subcontrol-position: bottom;
subcontrol-origin: margin;
}
QScrollBar::add-line:vertical:hover {
background: url(":/ui/chatArea/scrollBarDownArrowHover.png") center;
}
QScrollBar::add-line:vertical:pressed {
background: url(":/ui/chatArea/scrollBarDownArrowPressed.png") center;
}
QScrollBar::sub-line:vertical {
background: url(":/ui/chatArea/scrollBarUpArrow.png") center;
height: 10px;
background: url(":ui/chatArea/scrollBarUpArrow.png") center;
height: 0px;
subcontrol-position: top;
subcontrol-origin: margin;
}
QScrollBar::sub-line:vertical:hover {
background: url(":/ui/chatArea/scrollBarUpArrowHover.png") center;
}
QScrollBar::sub-line:vertical:pressed {
background: url(":/ui/chatArea/scrollBarUpArrowPressed.png") center;
}
QScrollBar:QScrollBar::down-arrow:vertical {
width: 10;
height: 10px;
@ -77,12 +63,13 @@ QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
QScrollBar:horizontal {
background: white;
height: 10px;
margin: 0 12px 0 12px;
margin: 0 2px 0 2px;
}
QScrollBar::handle:horizontal {
background: #d1d1d1;
min-width: 20px;
border-radius: 2px;
}
QScrollBar::handle:horizontal:hover {
@ -94,36 +81,19 @@ QScrollBar::handle:horizontal:pressed {
}
QScrollBar::add-line:horizontal {
background: url(":/ui/chatArea/scrollBarRightArrow.png") center;
width: 10px;
background: url(":ui/chatArea/scrollBarRightArrow.png") center;
width: 0px;
subcontrol-position: right;
subcontrol-origin: margin;
}
QScrollBar::add-line:horizontal:hover {
background: url(":/ui/chatArea/scrollBarRightArrowHover.png") center;
}
QScrollBar::add-line:horizontal:pressed {
background: url(":/ui/chatArea/scrollBarRightArrowPressed.png") center;
}
QScrollBar::sub-line:horizontal {
background: url(":/ui/chatArea/scrollBarLeftArrow.png") center;
width: 10px;
background: url(":ui/chatArea/scrollBarLeftArrow.png") center;
width: 0px;
subcontrol-position: left;
subcontrol-origin: margin;
}
QScrollBar::sub-line:horizontal:hover {
background: url(":/ui/chatArea/scrollBarLeftArrowHover.png") center;
}
QScrollBar::sub-line:horizontal:pressed {
background: url(":/ui/chatArea/scrollBarLeftArrowPressed.png") center;
}
QScrollBar:QScrollBar::down-arrow:horizontal {
width: 10;
height: 10px;

View File

@ -0,0 +1,34 @@
QScrollArea {
background: #414141!important;
}
QScrollBar:vertical {
background: #414141!important;
width: 14px!important;
margin-top: 2px!important;
margin-bottom: 2px!important;
}
QScrollBar:handle:vertical {
background: #1c1c1c!important;
min-height: 20px!important;
border-radius: 3px!important;
margin-left: 3px!important;
margin-right: 1px!important;
}
QScrollBar:handle:vertical:hover {
background: #2d2d2d!important;
}
QScrollBar:handle:vertical:pressed {
background: #171717!important;
}
QScrollBar:add-line:vertical {height: 0px!important;subcontrol-position: bottom!important;subcontrol-origin: margin!important;}
QScrollBar:sub-line:vertical {height: 0px!important;subcontrol-position: top!important;subcontrol-origin: margin!important;}
QScrollBar:add-page:vertical, QScrollBar::sub-page:vertical {
background: none!important;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
ui/window/closeButton.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 385 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 401 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 401 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 402 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 B

BIN
ui/window/restoreButton.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 401 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 401 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 402 B

68
ui/window/window.css Normal file
View File

@ -0,0 +1,68 @@
Widget#activeWindow
{
background-color: #DFDFDF;
border: 2px solid #ABABAB;
}
Widget#inactiveWindow
{
background-color: #f4f4f4;
border: 2px solid #ABABAB;
}
/*
Widget#titleBar
{
border: 10px solid #ABABAB;
border-top: 0px solid transparent;
background-color: #DFDFDF;
}
Widget#titleBarInactive
{
border: 5px solid #ABABAB;
border-top: 0px solid transparent;
background-color: #F1F1F1;
}*/
QToolButton#tbMenu
{
border: 0px solid transparent;
background-color: transparent;
}
QPushButton#minimizeButton
{
border: 0px solid transparent;
background-color: transparent;
image: url(":ui/window/minimizeButton.png");}
QPushButton#minimizeButton:hover {image: url(":ui/window/minimizeButtonHover.png");}
QPushButton#minimizeButton:pressed {image: url(":ui/window/minimizeButtonPressed.png");}
QPushButton#minimizeButton:focus {outline: none;}
QPushButton#maximizeButton
{
border: 0px solid transparent;
background-color: transparent;
image: url(":ui/window/maximizeButton.png");}
QPushButton#maximizeButton:hover {image: url(":ui/window/maximizeButtonHover.png");}
QPushButton#maximizeButton:pressed {image: url(":ui/window/maximizeButtonPressed.png");}
QPushButton#maximizeButton:focus {outline: none;}
QPushButton#closeButton
{
border: 0px solid transparent;
background-color: transparent;
image: url(":ui/window/closeButton.png");}
QPushButton#closeButton:hover {image: url(":ui/window/closeButtonHover.png");}
QPushButton#closeButton:pressed {image: url(":ui/window/closeButtonPressed.png");}
QPushButton#closeButton:focus {outline: none;}
QPushButton#restoreButton
{
border: 0px solid transparent;
background-color: transparent;
image: url(":ui/window/restoreButton.png");}
QPushButton#restoreButton:hover {image: url(":ui/window/restoreButtonHover.png");}
QPushButton#restoreButton:pressed {image: url(":ui/window/restoreButtonPressed.png");}
QPushButton#restoreButton:focus {outline: none;}

5493
widget.ui

File diff suppressed because it is too large Load Diff

View File

@ -9,6 +9,7 @@
FriendWidget::FriendWidget(int FriendId, QString id)
: friendId(FriendId)
{
this->setMouseTracking(true);
this->setAutoFillBackground(true);
this->setLayout(&layout);
this->setFixedWidth(225);
@ -18,16 +19,22 @@ FriendWidget::FriendWidget(int FriendId, QString id)
textLayout.setSpacing(0);
textLayout.setMargin(0);
avatar.setPixmap(QPixmap(":/img/contact.png"));
avatar.setPixmap(QPixmap(":img/contact.png"));
name.setText(id);
//statusPic.setAlignment(Qt::AlignHCenter);
statusPic.setPixmap(QPixmap(":/img/status/dot_away.png"));
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);
@ -140,7 +147,7 @@ void FriendWidget::setAsActiveChatroom()
QPalette pal3;
pal3.setColor(QPalette::Background, Qt::white);
this->setPalette(pal3);
avatar.setPixmap(QPixmap(":/img/contact_dark.png"));
avatar.setPixmap(QPixmap(":img/contact_dark.png"));
}
void FriendWidget::setAsInactiveChatroom()
@ -159,5 +166,5 @@ void FriendWidget::setAsInactiveChatroom()
QPalette pal3;
pal3.setColor(QPalette::Background, QColor(65,65,65,255));
this->setPalette(pal3);
avatar.setPixmap(QPixmap(":/img/contact.png"));
avatar.setPixmap(QPixmap(":img/contact.png"));
}

View File

@ -8,6 +8,7 @@
GroupWidget::GroupWidget(int GroupId, QString Name)
: groupId{GroupId}
{
this->setMouseTracking(true);
this->setAutoFillBackground(true);
this->setLayout(&layout);
this->setFixedWidth(225);
@ -17,8 +18,8 @@ GroupWidget::GroupWidget(int GroupId, QString Name)
textLayout.setSpacing(0);
textLayout.setMargin(0);
avatar.setPixmap(QPixmap(":/img/group.png"));
statusPic.setPixmap(QPixmap(":/img/status/dot_groupchat.png"));
avatar.setPixmap(QPixmap(":img/group.png"));
statusPic.setPixmap(QPixmap(":img/status/dot_groupchat.png"));
name.setText(Name);
QFont small;
small.setPixelSize(10);
@ -26,6 +27,12 @@ GroupWidget::GroupWidget(int GroupId, QString Name)
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);
Group* g = GroupList::findGroup(groupId);
if (g)
nusers.setText(QString("%1 users in chat").arg(g->peers.size()));
@ -137,7 +144,7 @@ void GroupWidget::setAsActiveChatroom()
QPalette pal3;
pal3.setColor(QPalette::Background, Qt::white);
this->setPalette(pal3);
avatar.setPixmap(QPixmap(":/img/group_dark.png"));
avatar.setPixmap(QPixmap(":img/group_dark.png"));
}
void GroupWidget::setAsInactiveChatroom()
@ -156,5 +163,5 @@ void GroupWidget::setAsInactiveChatroom()
QPalette pal3;
pal3.setColor(QPalette::Background, QColor(65,65,65,255));
this->setPalette(pal3);
avatar.setPixmap(QPixmap(":/img/group.png"));
avatar.setPixmap(QPixmap("img/group.png"));
}

View File

@ -12,6 +12,14 @@
#include <QMessageBox>
#include <QDebug>
#include <QSound>
#include <QTextStream>
#include <QFile>
#include <QString>
#include <QPainter>
#include <QMouseEvent>
#include <QDesktopWidget>
#include <QCursor>
#include <QSettings>
Widget *Widget::instance{nullptr};
@ -19,6 +27,115 @@ Widget::Widget(QWidget *parent) :
QWidget(parent), ui(new Ui::Widget), activeFriendWidget{nullptr}, activeGroupWidget{nullptr}
{
ui->setupUi(this);
QSettings settings(Settings::getInstance().getSettingsDirPath() + '/' + "windowSettings.ini", QSettings::IniFormat);
if (!settings.contains("useNativeTheme"))
useNativeTheme = 1;
else
useNativeTheme = settings.value("useNativeTheme").toInt();
if (useNativeTheme)
{
ui->titleBar->hide();
//setWindowFlags(windowFlags() & ~Qt::FramelessWindowHint);
this->layout()->setContentsMargins(0, 0, 0, 0);
QString friendListStylesheet = "";
try
{
QFile f(":ui/friendList/friendList.css");
f.open(QFile::ReadOnly | QFile::Text);
QTextStream friendListStylesheetStream(&f);
friendListStylesheet = friendListStylesheetStream.readAll();
}
catch (int e) {}
ui->friendList->setObjectName("friendList");
ui->friendList->setStyleSheet(friendListStylesheet);
}
else
{
QString windowStylesheet = "";
try
{
QFile f(":ui/window/window.css");
f.open(QFile::ReadOnly | QFile::Text);
QTextStream windowStylesheetStream(&f);
windowStylesheet = windowStylesheetStream.readAll();
}
catch (int e) {}
this->setObjectName("activeWindow");
this->setStyleSheet(windowStylesheet);
ui->statusPanel->setStyleSheet(QString(""));
ui->friendList->setStyleSheet(QString(""));
QString friendListStylesheet = "";
try
{
QFile f(":ui/friendList/friendList.css");
f.open(QFile::ReadOnly | QFile::Text);
QTextStream friendListStylesheetStream(&f);
friendListStylesheet = friendListStylesheetStream.readAll();
}
catch (int e) {}
ui->friendList->setObjectName("friendList");
ui->friendList->setStyleSheet(friendListStylesheet);
ui->tbMenu->setIcon(QIcon(":ui/window/applicationIcon.png"));
ui->pbMin->setObjectName("minimizeButton");
ui->pbMax->setObjectName("maximizeButton");
ui->pbClose->setObjectName("closeButton");
setWindowFlags(Qt::CustomizeWindowHint);
setWindowFlags(Qt::FramelessWindowHint);
setAttribute(Qt::WA_DeleteOnClose);
setMouseTracking(true);
ui->titleBar->setMouseTracking(true);
ui->LTitle->setMouseTracking(true);
ui->tbMenu->setMouseTracking(true);
ui->pbMin->setMouseTracking(true);
ui->pbMax->setMouseTracking(true);
ui->pbClose->setMouseTracking(true);
addAction(ui->actionClose);
connect(ui->pbMin, SIGNAL(clicked()), this, SLOT(minimizeBtnClicked()));
connect(ui->pbMax, SIGNAL(clicked()), this, SLOT(maximizeBtnClicked()));
connect(ui->pbClose, SIGNAL(clicked()), this, SLOT(close()));
m_titleMode = FullTitle;
moveWidget = false;
inResizeZone = false;
allowToResize = false;
resizeVerSup = false;
resizeHorEsq = false;
resizeDiagSupEsq = false;
resizeDiagSupDer = false;
QSettings settings(Settings::getInstance().getSettingsDirPath() + '/' + "windowSettings.ini", QSettings::IniFormat);
QRect geo = settings.value("geometry").toRect();
if (geo.height() > 0 and geo.x() < QApplication::desktop()->width() and geo.width() > 0 and geo.y() < QApplication::desktop()->height())
setGeometry(geo);
if (settings.value("maximized").toBool())
{
showMaximized();
ui->pbMax->setObjectName("restoreButton");
}
QList<QWidget*> widgets = this->findChildren<QWidget*>();
foreach (QWidget *widget, widgets)
{
widget->setMouseTracking(true);
}
}
isWindowMinimized = 0;
centralLayout = new QHBoxLayout(ui->centralWidget);
ui->mainContent->setLayout(new QVBoxLayout());
ui->mainHead->setLayout(new QVBoxLayout());
ui->mainHead->layout()->setMargin(0);
@ -31,7 +148,9 @@ Widget::Widget(QWidget *parent) :
ui->friendList->setWidget(friendListWidget);
ui->nameLabel->setText(Settings::getInstance().getUsername());
ui->nameLabel->label->setStyleSheet("QLabel { color : white; font-size: 11pt; font-weight:bold;}");
ui->statusLabel->setText(Settings::getInstance().getStatusMessage());
ui->statusLabel->label->setStyleSheet("QLabel { color : white; font-size: 8pt;}");
ui->friendList->widget()->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
camera = new Camera;
@ -107,8 +226,12 @@ Widget::~Widget()
for (Group* g : GroupList::groupList)
delete g;
GroupList::groupList.clear();
QSettings settings(Settings::getInstance().getSettingsDirPath() + '/' + "windowSettings.ini", QSettings::IniFormat);
settings.setValue("geometry", geometry());
settings.setValue("maximized", isMaximized());
settings.setValue("useNativeTheme", useNativeTheme);
delete ui;
delete centralLayout;
}
Widget* Widget::getInstance()
@ -118,6 +241,7 @@ Widget* Widget::getInstance()
return instance;
}
QString Widget::getUsername()
{
return ui->nameLabel->text();
@ -150,11 +274,11 @@ void Widget::onFailedToStartCore()
void Widget::onStatusSet(Status status)
{
if (status == Status::Online)
ui->statImg->setPixmap(QPixmap(":/img/status/dot_online_2x.png"));
ui->statImg->setPixmap(QPixmap(":img/status/dot_online_2x.png"));
else if (status == Status::Busy || status == Status::Away)
ui->statImg->setPixmap(QPixmap(":/img/status/dot_idle_2x.png"));
ui->statImg->setPixmap(QPixmap(":img/status/dot_idle_2x.png"));
else if (status == Status::Offline)
ui->statImg->setPixmap(QPixmap(":/img/status/dot_away_2x.png"));
ui->statImg->setPixmap(QPixmap(":img/status/dot_away_2x.png"));
}
void Widget::onAddClicked()
@ -358,7 +482,7 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message)
if (activeFriendWidget != nullptr)
{
Friend* f2 = FriendList::findFriend(activeFriendWidget->friendId);
if ((f->friendId != f2->friendId) || isFriendWidgetActive == 0)
if (((f->friendId != f2->friendId) || isFriendWidgetActive == 0) || isWindowMinimized)
{
f->hasNewMessages = 1;
newMessageAlert();
@ -378,23 +502,23 @@ void Widget::updateFriendStatusLights(int friendId)
Friend* f = FriendList::findFriend(friendId);
Status status = f->friendStatus;
if (status == Status::Online && f->hasNewMessages == 0)
f->widget->statusPic.setPixmap(QPixmap(":/img/status/dot_online.png"));
f->widget->statusPic.setPixmap(QPixmap(":img/status/dot_online.png"));
else if (status == Status::Online && f->hasNewMessages == 1)
f->widget->statusPic.setPixmap(QPixmap(":/img/status/dot_online_notification.png"));
f->widget->statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
else if ((status == Status::Busy || status == Status::Away) && f->hasNewMessages == 0)
f->widget->statusPic.setPixmap(QPixmap(":/img/status/dot_idle.png"));
f->widget->statusPic.setPixmap(QPixmap(":img/status/dot_idle.png"));
else if ((status == Status::Busy || status == Status::Away) && f->hasNewMessages == 1)
f->widget->statusPic.setPixmap(QPixmap(":/img/status/dot_idle_notification.png"));
f->widget->statusPic.setPixmap(QPixmap(":img/status/dot_idle_notification.png"));
else if (status == Status::Offline && f->hasNewMessages == 0)
f->widget->statusPic.setPixmap(QPixmap(":/img/status/dot_away.png"));
f->widget->statusPic.setPixmap(QPixmap(":img/status/dot_away.png"));
else if (status == Status::Offline && f->hasNewMessages == 1)
f->widget->statusPic.setPixmap(QPixmap(":/img/status/dot_away_notification.png"));
f->widget->statusPic.setPixmap(QPixmap(":img/status/dot_away_notification.png"));
}
void Widget::newMessageAlert()
{
QApplication::alert(this, 1000);
QSound::play(":/audio/notification.wav");
QApplication::alert(this);
QSound::play(":audio/notification.wav");
}
void Widget::onFriendRequestReceived(const QString& userId, const QString& message)
@ -435,20 +559,20 @@ void Widget::onGroupMessageReceived(int groupnumber, int friendgroupnumber, cons
g->chatForm->addGroupMessage(message, friendgroupnumber);
if (isGroupWidgetActive != 1 || (g->groupId != activeGroupWidget->groupId))
if ((isGroupWidgetActive != 1 || (g->groupId != activeGroupWidget->groupId)) || isWindowMinimized)
{
if (message.contains(Settings::getInstance().getUsername(), Qt::CaseInsensitive))
{
newMessageAlert();
g->hasNewMessages = 1;
g->userWasMentioned = 1;
g->widget->statusPic.setPixmap(QPixmap(":/img/status/dot_groupchat_notification.png"));
g->widget->statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_notification.png"));
}
else
if (g->hasNewMessages == 0)
{
g->hasNewMessages = 1;
g->widget->statusPic.setPixmap(QPixmap(":/img/status/dot_groupchat_newmessages.png"));
g->widget->statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_newmessages.png"));
}
}
}
@ -492,7 +616,7 @@ void Widget::onGroupWidgetClicked(GroupWidget* widget)
{
g->hasNewMessages = 0;
g->userWasMentioned = 0;
g->widget->statusPic.setPixmap(QPixmap(":/img/status/dot_groupchat.png"));
g->widget->statusPic.setPixmap(QPixmap(":img/status/dot_groupchat.png"));
}
}
@ -557,3 +681,408 @@ bool Widget::isFriendWidgetCurActiveWidget(Friend* f)
return false;
return true;
}
void Widget::mouseMoveEvent(QMouseEvent *e)
{
if (!useNativeTheme)
{
int xMouse = e->pos().x();
int yMouse = e->pos().y();
int wWidth = this->geometry().width();
int wHeight = this->geometry().height();
if (moveWidget)
{
inResizeZone = false;
moveWindow(e);
}
else if (allowToResize)
resizeWindow(e);
//right
else if (xMouse >= wWidth - PIXELS_TO_ACT or allowToResize)
{
inResizeZone = true;
if (yMouse >= wHeight - PIXELS_TO_ACT)
setCursor(Qt::SizeFDiagCursor);
else if (yMouse <= PIXELS_TO_ACT)
setCursor(Qt::SizeBDiagCursor);
else
setCursor(Qt::SizeHorCursor);
resizeWindow(e);
}
//left
else if (xMouse <= PIXELS_TO_ACT or allowToResize)
{
inResizeZone = true;
if (yMouse >= wHeight - PIXELS_TO_ACT)
setCursor(Qt::SizeBDiagCursor);
else if (yMouse <= PIXELS_TO_ACT)
setCursor(Qt::SizeFDiagCursor);
else
setCursor(Qt::SizeHorCursor);
resizeWindow(e);
}
//bottom edge
else if ((yMouse >= wHeight - PIXELS_TO_ACT) or allowToResize)
{
inResizeZone = true;
setCursor(Qt::SizeVerCursor);
resizeWindow(e);
}
//Cursor part top
else if (yMouse <= PIXELS_TO_ACT or allowToResize)
{
inResizeZone = true;
setCursor(Qt::SizeVerCursor);
resizeWindow(e);
}
else
{
inResizeZone = false;
setCursor(Qt::ArrowCursor);
}
e->accept();
}
}
bool Widget::event(QEvent * e)
{
if (e->type() == QEvent::WindowStateChange)
{
if(windowState().testFlag(Qt::WindowMinimized) == true)
{
isWindowMinimized = 1;
}
}
else if (e->type() == QEvent::WindowActivate)
{
if (!useNativeTheme)
{
this->setObjectName("activeWindow");
this->style()->polish(this);
}
isWindowMinimized = 0;
if (isFriendWidgetActive && activeFriendWidget != nullptr)
{
Friend* f = FriendList::findFriend(activeFriendWidget->friendId);
f->hasNewMessages = 0;
updateFriendStatusLights(f->friendId);
}
else if (isGroupWidgetActive && activeGroupWidget != nullptr)
{
Group* g = GroupList::findGroup(activeGroupWidget->groupId);
g->hasNewMessages = 0;
g->userWasMentioned = 0;
g->widget->statusPic.setPixmap(QPixmap("img/status/dot_groupchat.png"));
}
}
else if (e->type() == QEvent::WindowDeactivate && !useNativeTheme)
{
this->setObjectName("inactiveWindow");
this->style()->polish(this);
}
return QWidget::event(e);
}
void Widget::mousePressEvent(QMouseEvent *e)
{
if (!useNativeTheme)
{
if (e->button() == Qt::LeftButton)
{
if (inResizeZone)
{
allowToResize = true;
if (e->pos().y() <= PIXELS_TO_ACT)
{
if (e->pos().x() <= PIXELS_TO_ACT)
resizeDiagSupEsq = true;
else if (e->pos().x() >= geometry().width() - PIXELS_TO_ACT)
resizeDiagSupDer = true;
else
resizeVerSup = true;
}
else if (e->pos().x() <= PIXELS_TO_ACT)
resizeHorEsq = true;
}
else if (e->pos().x() >= PIXELS_TO_ACT and e->pos().x() < ui->titleBar->geometry().width()
and e->pos().y() >= PIXELS_TO_ACT and e->pos().y() < ui->titleBar->geometry().height())
{
moveWidget = true;
dragPosition = e->globalPos() - frameGeometry().topLeft();
}
}
e->accept();
}
}
void Widget::mouseReleaseEvent(QMouseEvent *e)
{
if (!useNativeTheme)
{
moveWidget = false;
allowToResize = false;
resizeVerSup = false;
resizeHorEsq = false;
resizeDiagSupEsq = false;
resizeDiagSupDer = false;
e->accept();
}
}
void Widget::mouseDoubleClickEvent(QMouseEvent *e)
{
if (!useNativeTheme)
{
if (e->pos().x() < ui->tbMenu->geometry().right() and e->pos().y() < ui->tbMenu->geometry().bottom()
and e->pos().x() >= ui->tbMenu->geometry().x() and e->pos().y() >= ui->tbMenu->geometry().y()
and ui->tbMenu->isVisible())
close();
else if (e->pos().x() < ui->titleBar->geometry().width()
and e->pos().y() < ui->titleBar->geometry().height()
and m_titleMode != FullScreenMode)
maximizeBtnClicked();
e->accept();
}
}
void Widget::paintEvent (QPaintEvent *)
{
QStyleOption opt;
opt.init (this);
QPainter p(this);
style()->drawPrimitive (QStyle::PE_Widget, &opt, &p, this);
}
void Widget::moveWindow(QMouseEvent *e)
{
if (!useNativeTheme)
{
if (e->buttons() & Qt::LeftButton)
{
move(e->globalPos() - dragPosition);
e->accept();
}
}
}
void Widget::resizeWindow(QMouseEvent *e)
{
if (!useNativeTheme)
{
if (allowToResize)
{
int xMouse = e->pos().x();
int yMouse = e->pos().y();
int wWidth = geometry().width();
int wHeight = geometry().height();
if (cursor().shape() == Qt::SizeVerCursor)
{
if (resizeVerSup)
{
int newY = geometry().y() + yMouse;
int newHeight = wHeight - yMouse;
if (newHeight > minimumSizeHint().height())
{
resize(wWidth, newHeight);
move(geometry().x(), newY);
}
}
else
resize(wWidth, yMouse+1);
}
else if (cursor().shape() == Qt::SizeHorCursor)
{
if (resizeHorEsq)
{
int newX = geometry().x() + xMouse;
int newWidth = wWidth - xMouse;
if (newWidth > minimumSizeHint().width())
{
resize(newWidth, wHeight);
move(newX, geometry().y());
}
}
else
resize(xMouse, wHeight);
}
else if (cursor().shape() == Qt::SizeBDiagCursor)
{
int newX = 0;
int newWidth = 0;
int newY = 0;
int newHeight = 0;
if (resizeDiagSupDer)
{
newX = geometry().x();
newWidth = xMouse;
newY = geometry().y() + yMouse;
newHeight = wHeight - yMouse;
}
else
{
newX = geometry().x() + xMouse;
newWidth = wWidth - xMouse;
newY = geometry().y();
newHeight = yMouse;
}
if (newWidth >= minimumSizeHint().width() and newHeight >= minimumSizeHint().height())
{
resize(newWidth, newHeight);
move(newX, newY);
}
else if (newWidth >= minimumSizeHint().width())
{
resize(newWidth, wHeight);
move(newX, geometry().y());
}
else if (newHeight >= minimumSizeHint().height())
{
resize(wWidth, newHeight);
move(geometry().x(), newY);
}
}
else if (cursor().shape() == Qt::SizeFDiagCursor)
{
if (resizeDiagSupEsq)
{
int newX = geometry().x() + xMouse;
int newWidth = wWidth - xMouse;
int newY = geometry().y() + yMouse;
int newHeight = wHeight - yMouse;
if (newWidth >= minimumSizeHint().width() and newHeight >= minimumSizeHint().height())
{
resize(newWidth, newHeight);
move(newX, newY);
}
else if (newWidth >= minimumSizeHint().width())
{
resize(newWidth, wHeight);
move(newX, geometry().y());
}
else if (newHeight >= minimumSizeHint().height())
{
resize(wWidth, newHeight);
move(geometry().x(), newY);
}
}
else
resize(xMouse+1, yMouse+1);
}
e->accept();
}
}
}
void Widget::setCentralWidget(QWidget *widget, const QString &widgetName)
{
connect(widget, SIGNAL(cancelled()), this, SLOT(close()));
centralLayout->addWidget(widget);
ui->centralWidget->setLayout(centralLayout);
ui->LTitle->setText(widgetName);
}
void Widget::setTitlebarMode(const TitleMode &flag)
{
m_titleMode = flag;
switch (m_titleMode)
{
case CleanTitle:
ui->tbMenu->setHidden(true);
ui->pbMin->setHidden(true);
ui->pbMax->setHidden(true);
ui->pbClose->setHidden(true);
break;
case OnlyCloseButton:
ui->tbMenu->setHidden(true);
ui->pbMin->setHidden(true);
ui->pbMax->setHidden(true);
break;
case MenuOff:
ui->tbMenu->setHidden(true);
break;
case MaxMinOff:
ui->pbMin->setHidden(true);
ui->pbMax->setHidden(true);
break;
case FullScreenMode:
ui->pbMax->setHidden(true);
showMaximized();
break;
case MaximizeModeOff:
ui->pbMax->setHidden(true);
break;
case MinimizeModeOff:
ui->pbMin->setHidden(true);
break;
case FullTitle:
ui->tbMenu->setVisible(true);
ui->pbMin->setVisible(true);
ui->pbMax->setVisible(true);
ui->pbClose->setVisible(true);
break;
break;
default:
ui->tbMenu->setVisible(true);
ui->pbMin->setVisible(true);
ui->pbMax->setVisible(true);
ui->pbClose->setVisible(true);
break;
}
ui->LTitle->setVisible(true);
}
void Widget::setTitlebarMenu(QMenu *menu, const QString &icon)
{
ui->tbMenu->setMenu(menu);
ui->tbMenu->setIcon(QIcon(icon));
}
void Widget::maximizeBtnClicked()
{
if (isFullScreen() or isMaximized())
{
ui->pbMax->setIcon(QIcon(":/ui/images/app_max.png"));
setWindowState(windowState() & ~Qt::WindowFullScreen & ~Qt::WindowMaximized);
}
else
{
ui->pbMax->setIcon(QIcon(":/ui/images/app_rest.png"));
setWindowState(windowState() | Qt::WindowFullScreen | Qt::WindowMaximized);
}
}
void Widget::minimizeBtnClicked()
{
if (isMinimized())
{
setWindowState(windowState() & ~Qt::WindowMinimized);
}
else
{
setWindowState(windowState() | Qt::WindowMinimized);
}
}

View File

@ -4,11 +4,15 @@
#include <QThread>
#include <QWidget>
#include <QString>
#include <QHBoxLayout>
#include <QMenu>
#include "core.h"
#include "widget/form/addfriendform.h"
#include "widget/form/settingsform.h"
#include "camera.h"
#define PIXELS_TO_ACT 5
namespace Ui {
class Widget;
}
@ -26,6 +30,10 @@ class Widget : public QWidget
public:
explicit Widget(QWidget *parent = 0);
enum TitleMode { CleanTitle = 0, OnlyCloseButton, MenuOff, MaxMinOff, FullScreenMode, MaximizeModeOff, MinimizeModeOff, FullTitle };
void setTitlebarMode(const TitleMode &flag);
void setTitlebarMenu(QMenu *menu, const QString &icon = "");
void setCentralWidget(QWidget *widget, const QString &widgetName);
QString getUsername();
Core* getCore();
Camera* getCamera();
@ -34,6 +42,7 @@ public:
void newMessageAlert();
bool isFriendWidgetCurActiveWidget(Friend* f);
void updateFriendStatusLights(int friendId);
int useNativeTheme;
~Widget();
signals:
@ -45,6 +54,8 @@ signals:
void statusMessageChanged(const QString& statusMessage);
private slots:
void maximizeBtnClicked();
void minimizeBtnClicked();
void onConnected();
void onDisconnected();
void onStatusSet(Status status);
@ -77,12 +88,33 @@ private slots:
void removeFriend(int friendId);
void removeGroup(int groupId);
protected slots:
void moveWindow(QMouseEvent *e);
private:
void hideMainForms();
Group* createGroup(int groupId);
private:
Ui::Widget *ui;
QHBoxLayout *centralLayout;
QPoint dragPosition;
TitleMode m_titleMode;
bool moveWidget;
bool inResizeZone;
bool allowToResize;
bool resizeVerSup;
bool resizeHorEsq;
bool resizeDiagSupEsq;
bool resizeDiagSupDer;
void mouseMoveEvent(QMouseEvent *e);
void mousePressEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
void mouseDoubleClickEvent(QMouseEvent *e);
void paintEvent (QPaintEvent *);
void resizeWindow(QMouseEvent *e);
bool event(QEvent *event);
int isWindowMinimized;
Core* core;
QThread* coreThread;
AddFriendForm friendForm;