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

Merge pull request #380 from krepa098/master

More visual tweaks and fixes
This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-10-05 18:14:36 +02:00
commit 525552a6ac
29 changed files with 171 additions and 2048 deletions

View File

@ -16,6 +16,7 @@
#include "filetransferinstance.h"
#include "core.h"
#include "misc/style.h"
#include <math.h>
#include <QFileDialog>
#include <QMessageBox>
@ -38,9 +39,10 @@ FileTransferInstance::FileTransferInstance(ToxFile File)
lastUpdateTime = QDateTime::currentDateTime();
filename = File.fileName;
QFont font;
font.setPixelSize(10);
QFontMetrics fm(font);
// update this whenever you change the font in innerStyle.css
QFontMetrics fm(Style::getFont(Style::Small));
filenameElided = fm.elidedText(filename, Qt::ElideRight, CONTENT_WIDTH);
size = getHumanReadableSize(File.filesize);
@ -391,10 +393,33 @@ QString FileTransferInstance::draw2ButtonsForm(const QString &type, const QImage
QString FileTransferInstance::wrapIntoForm(const QString& content, const QString &type, const QString &imgAstr, const QString &imgBstr)
{
QString res;
QString w = QString::number(QImage(":/ui/fileTransferInstance/emptyLRedFileButton.png").size().width());
QString imgLeftA, imgLeftB;
if (type == "green")
{
imgLeftA = "<img src=\"data:placeholder/png;base64," + QImage2base64(QImage(":/ui/fileTransferInstance/emptyLGreenFileButton.png").mirrored(true,false)) + "\">";
imgLeftB = "<img src=\"data:placeholder/png;base64," + QImage2base64(QImage(":/ui/fileTransferInstance/emptyLGreenFileButton.png").mirrored(true,true)) + "\">";
}
if (type == "silver")
{
imgLeftA = "<img src=\"data:placeholder/png;base64," + QImage2base64(QImage(":/ui/fileTransferInstance/sliverRTEdge.png").mirrored(true,false)) + "\">";
imgLeftB = "<img src=\"data:placeholder/png;base64," + QImage2base64(QImage(":/ui/fileTransferInstance/sliverRTEdge.png").mirrored(true,true)) + "\">";
}
if (type == "red")
{
imgLeftA = "<img src=\"data:placeholder/png;base64," + QImage2base64(QImage(":/ui/fileTransferInstance/emptyLRedFileButton.png").mirrored(true,false)) + "\">";
imgLeftB = "<img src=\"data:placeholder/png;base64," + QImage2base64(QImage(":/ui/fileTransferInstance/emptyLRedFileButton.png").mirrored(true,true)) + "\">";
}
QString res;
res = "<table cellspacing=\"0\">\n";
res += "<tr valign=middle>\n";
res += "<td width=" + w + ">\n";
res += "<div class=button>" + imgLeftA + "<br>" + imgLeftB + "</div>\n";
res += "</td>\n";
res += insertMiniature(type);
res += "<td width=" + QString::number(CONTENT_WIDTH + 30) + ">\n";
res += "<div class=" + type + ">";
@ -402,7 +427,7 @@ QString FileTransferInstance::wrapIntoForm(const QString& content, const QString
res += "</div>\n";
res += "</td>\n";
res += "<td>\n";
res += "<div class=button>" + imgAstr + "<br>" + imgBstr+ "</div>\n";
res += "<div class=button>" + imgAstr + "<br>" + imgBstr + "</div>\n";
res += "</td>\n";
res += "</tr>\n";
res += "</table>\n";

File diff suppressed because it is too large Load Diff

View File

@ -130,7 +130,6 @@ void Settings::load()
timestampFormat = s.value("timestampFormat", "hh:mm").toString();
minimizeOnClose = s.value("minimizeOnClose", false).toBool();
useNativeStyle = s.value("nativeStyle", false).toBool();
useNativeDecoration = s.value("nativeDecoration", true).toBool();
s.endGroup();
s.beginGroup("State");
@ -230,7 +229,6 @@ void Settings::save(QString path)
s.setValue("timestampFormat", timestampFormat);
s.setValue("minimizeOnClose", minimizeOnClose);
s.setValue("nativeStyle", useNativeStyle);
s.setValue("nativeDecoration", useNativeDecoration);
s.endGroup();
s.beginGroup("State");
@ -478,16 +476,6 @@ void Settings::setUseNativeStyle(bool value)
useNativeStyle = value;
}
bool Settings::getUseNativeDecoration() const
{
return useNativeDecoration;
}
void Settings::setUseNativeDecoration(bool value)
{
useNativeDecoration = value;
}
QByteArray Settings::getWindowGeometry() const
{
return windowGeometry;

View File

@ -121,9 +121,6 @@ public:
bool getUseNativeStyle() const;
void setUseNativeStyle(bool value);
bool getUseNativeDecoration() const;
void setUseNativeDecoration(bool value);
QByteArray getWindowGeometry() const;
void setWindowGeometry(const QByteArray &value);
@ -170,7 +167,6 @@ private:
int emojiFontPointSize;
bool minimizeOnClose;
bool useNativeStyle;
bool useNativeDecoration;
QByteArray windowGeometry;
QByteArray windowState;
QByteArray splitterState;

View File

@ -33,22 +33,11 @@ QFont appFont(int pixelSize, int 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("%1 %2 \"%3\"")
return QString("%1 %2px \"%3\"")
.arg(font.weight()*8)
.arg(font.pixelSize())
.arg(qssifyWeight(font.weight()))
.arg(font.family());
}
@ -68,6 +57,8 @@ QString Style::getStylesheet(const QString &filename)
QColor Style::getColor(Style::ColorPalette entry)
{
// colors as defined in
// https://github.com/ItsDuke/Tox-UI/blob/master/UI%20GUIDELINES.md
static QColor palette[] = {
QColor("#6bc260"),
QColor("#cebf44"),
@ -85,14 +76,16 @@ QColor Style::getColor(Style::ColorPalette entry)
QFont Style::getFont(Style::Font font)
{
// fonts as defined in
// https://github.com/ItsDuke/Tox-UI/blob/master/UI%20GUIDELINES.md
static QFont fonts[] = {
appFont(16, QFont::Bold),
appFont(14, QFont::Normal),
appFont(14, QFont::Bold),
appFont(13, QFont::Normal),
appFont(13, 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),
appFont(12, QFont::Light),
};
return fonts[font];

14
res.qrc
View File

@ -84,18 +84,6 @@
<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>
<file>img/status/dot_busy.png</file>
@ -146,5 +134,7 @@
<file>img/avatar_mask.png</file>
<file>img/group_2x.png</file>
<file>ui/chatroomWidgets/genericChatroomWidget.css</file>
<file>ui/fileTransferInstance/sliverRTEdge.png</file>
<file>ui/window/statusPanel.css</file>
</qresource>
</RCC>

View File

@ -1,7 +1,6 @@
div.name {
color: @black;
font: @bigBold;
font-weight: bold; /* @bigBold doesn't actually work */
}
div.message {
@ -41,7 +40,7 @@ span.quote {
div.green {
margin-top: 12px;
margin-bottom: 12px;
margin-left: 12px;
margin-left: 0px;
margin-right: 12px;
color: @white;
background-color: @green;
@ -51,7 +50,7 @@ div.green {
div.silver {
margin-top: 12px;
margin-bottom: 12px;
margin-left: 12px;
margin-left: 0px;
margin-right: 12px;
color: @black;
background-color: @lightGrey;
@ -61,7 +60,7 @@ div.silver {
div.red {
margin-top: 12px;
margin-bottom: 12px;
margin-left: 12px;
margin-left: 0px;
margin-right: 12px;
color: @white;
background-color: @red;

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 385 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 370 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 402 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 402 B

70
ui/window/statusPanel.css Normal file
View File

@ -0,0 +1,70 @@
#statusPanel
{
background-color: @darkGrey;
}
#statusPanel > #statusHead > #nameLabel {
font: @extraBig;
color: @white;
}
#statusPanel > #statusHead > #statusLabel {
font: @smallLight;
color: @lightGrey;
}
#statusPanel > #statusHead > #statusButton
{
background: none;
background-color: @mediumGrey;
border: none;
border-radius: 6px;
width: 20px;
height: 40px;
}
#statusPanel > #statusHead > #statusButton[status="online"]
{
image: url(":ui/statusButton/dot_online.png") center center;
}
#statusPanel > #statusHead > #statusButton[status="away"]
{
image: url(":ui/statusButton/dot_idle.png") center center;
}
#statusPanel > #statusHead > #statusButton[status="busy"]
{
image: url(":ui/statusButton/dot_busy.png") center center;
}
#statusPanel > #statusHead > #statusButton[status="offline"]
{
image: url(":ui/statusButton/dot_away.png") center center;
}
/*Bugged in Qt, but it's probably better to leave enabled so that users can tell it's clickable*/
#statusPanel > #statusHead > #statusButton:hover
{
background-color: @mediumGreyLight;
}
#statusPanel > #statusHead > #statusButton:pressed
{
background-color: @mediumGrey;
}
#statusPanel > #statusHead > #statusButton:focus {
outline: none;
}
#statusPanel > #statusHead > #statusButton::menu-indicator {image: none;}
#statusPanel > #statusHead > #statusButton::menu-indicator:pressed, #statusPanel > #statusHead > #statusButton::menu-indicator:open
{
image: url(":ui/statusButton/menu_indicator.png");
subcontrol-origin: padding;
subcontrol-position: bottom center;
position: relative;
bottom: 2px;
}

View File

@ -163,7 +163,7 @@ void ChatForm::onFileRecvRequest(ToxFile file)
connect(Core::getInstance(), SIGNAL(fileTransferBrokenUnbroken(ToxFile, bool)), fileTrans, SLOT(onFileTransferBrokenUnbroken(ToxFile, bool)));
Widget* w = Widget::getInstance();
if (!w->isFriendWidgetCurActiveWidget(f)|| w->getIsWindowMinimized() || !w->isActiveWindow())
if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow())
{
w->newMessageAlert();
f->hasNewEvents=true;
@ -204,7 +204,7 @@ void ChatForm::onAvInvite(int FriendId, int CallId, bool video)
}
Widget* w = Widget::getInstance();
if (!w->isFriendWidgetCurActiveWidget(f)|| w->getIsWindowMinimized() || !w->isActiveWindow())
if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow())
{
w->newMessageAlert();
f->hasNewEvents=true;

View File

@ -228,9 +228,8 @@ void GenericChatForm::addSystemInfoMessage(const QString &message, const QString
QString GenericChatForm::getElidedName(const QString& name)
{
QFont font;
font.setBold(true);
QFontMetrics fm(font);
// update this whenever you change the font in innerStyle.css
QFontMetrics fm(Style::getFont(Style::BigBold));
return fm.elidedText(name, Qt::ElideRight, chatWidget->nameColWidth());
}

View File

@ -149,6 +149,10 @@ void FriendWidget::onAvatarRemoved(int FriendId)
return;
isDefaultAvatar = true;
if (isActive())
avatar->setPixmap(QPixmap(":img/contact_dark.png"), Qt::transparent);
else
avatar->setPixmap(QPixmap(":img/contact.png"), Qt::transparent);
}

View File

@ -77,27 +77,16 @@ void GroupWidget::updateStatusLight()
{
Group *g = GroupList::findGroup(groupId);
if (Settings::getInstance().getUseNativeDecoration())
{
if (g->hasNewMessages == 0)
{
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"));
}
} else {
if (g->hasNewMessages == 0)
else
{
statusPic.setPixmap(QPixmap(":img/status/dot_groupchat.png"));
} else {
if (g->userWasMentioned == 0)
statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_newmessages.png"));
statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
else
statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_notification.png"));
}
statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
}
}

View File

@ -19,6 +19,7 @@
MaskablePixmapWidget::MaskablePixmapWidget(QWidget *parent, QSize size, QString maskName)
: QWidget(parent)
, renderTarget(size)
, backgroundColor(Qt::white)
, clickable(false)
{
@ -106,17 +107,16 @@ void MaskablePixmapWidget::setPixmap(const QPixmap &pmap)
QPixmap MaskablePixmapWidget::getPixmap() const
{
return pixmap;
return renderTarget;
}
void MaskablePixmapWidget::paintEvent(QPaintEvent *)
{
QPixmap tmp(width(), height());
tmp.fill(Qt::transparent);
renderTarget.fill(Qt::transparent);
QPoint offset((width() - pixmap.size().width())/2,(height() - pixmap.size().height())/2); // centering the pixmap
QPainter painter(&tmp);
QPainter painter(&renderTarget);
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
painter.fillRect(0,0,width(),height(),backgroundColor);
painter.drawPixmap(offset,pixmap);
@ -125,7 +125,7 @@ void MaskablePixmapWidget::paintEvent(QPaintEvent *)
painter.end();
painter.begin(this);
painter.drawPixmap(0,0,tmp);
painter.drawPixmap(0,0,renderTarget);
}
void MaskablePixmapWidget::mousePressEvent(QMouseEvent*)

View File

@ -42,6 +42,7 @@ protected:
private:
QPixmap pixmap;
QPixmap mask;
QPixmap renderTarget;
QSize size;
QString maskName;
QColor backgroundColor;

View File

@ -62,55 +62,8 @@ Widget::Widget(QWidget *parent)
restoreState(Settings::getInstance().getWindowState());
ui->mainSplitter->restoreState(Settings::getInstance().getSplitterState());
if (Settings::getInstance().getUseNativeDecoration())
{
ui->titleBar->hide();
this->layout()->setContentsMargins(0, 0, 0, 0);
ui->friendList->setObjectName("friendList");
layout()->setContentsMargins(0, 0, 0, 0);
ui->friendList->setStyleSheet(Style::getStylesheet(":ui/friendList/friendList.css"));
}
else
{
this->setObjectName("activeWindow");
this->setStyleSheet(Style::getStylesheet(":ui/window/window.css"));
ui->statusPanel->setStyleSheet(QString(""));
ui->friendList->setStyleSheet(QString(""));
ui->friendList->setObjectName("friendList");
ui->friendList->setStyleSheet(Style::getStylesheet(":ui/friendList/friendList.css"));
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);
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;
if (isMaximized())
{
showMaximized();
ui->pbMax->setObjectName("restoreButton");
}
}
isWindowMinimized = 0;
profilePicture = new MaskablePixmapWidget(this, QSize(40,40), ":/img/avatar_mask.png");
profilePicture->setPixmap(QPixmap(":/img/contact_dark.png"));
@ -130,16 +83,7 @@ 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::getStylesheet(":/ui/statusButton/statusButton.css"));
ui->statusPanel->setStyleSheet(Style::getStylesheet(":/ui/window/statusPanel.css"));
QMenu *statusButtonMenu = new QMenu(ui->statusButton);
QAction* setStatusOnline = statusButtonMenu->addAction(Widget::tr("Online","Button to set your status to 'Online'"));
@ -150,22 +94,12 @@ Widget::Widget(QWidget *parent)
setStatusBusy->setIcon(QIcon(":ui/statusButton/dot_busy.png"));
ui->statusButton->setMenu(statusButtonMenu);
ui->titleBar->setMouseTracking(true);
ui->LTitle->setMouseTracking(true);
ui->tbMenu->setMouseTracking(true);
ui->pbMin->setMouseTracking(true);
ui->pbMax->setMouseTracking(true);
ui->pbClose->setMouseTracking(true);
ui->statusHead->setMouseTracking(true);
//ui->friendList->viewport()->installEventFilter(this);
// disable proportional scaling
ui->mainSplitter->setStretchFactor(0,0);
ui->mainSplitter->setStretchFactor(1,1);
ui->statusButton->setObjectName("offline");
ui->statusButton->style()->polish(ui->statusButton);
ui->statusButton->setProperty("status", "offline");
Style::repolish(ui->statusButton);
camera = new Camera;
settingsDialog = new SettingsDialog(this);
@ -244,8 +178,6 @@ Widget::~Widget()
coreThread->terminate();
delete core;
hideMainForms();
for (Friend* f : FriendList::friendList)
delete f;
FriendList::friendList.clear();
@ -359,26 +291,23 @@ void Widget::onStatusSet(Status status)
{
//We have to use stylesheets here, there's no way to
//prevent the button icon from moving when pressed otherwise
if (status == Status::Online)
switch (status)
{
ui->statusButton->setObjectName("online");
ui->statusButton->style()->polish(ui->statusButton);
}
else if (status == Status::Away)
{
ui->statusButton->setObjectName("away");
ui->statusButton->style()->polish(ui->statusButton);
}
else if (status == Status::Busy)
{
ui->statusButton->setObjectName("busy");
ui->statusButton->style()->polish(ui->statusButton);
}
else if (status == Status::Offline)
{
ui->statusButton->setObjectName("offline");
ui->statusButton->style()->polish(ui->statusButton);
case Status::Online:
ui->statusButton->setProperty("status" ,"online");
break;
case Status::Away:
ui->statusButton->setProperty("status" ,"away");
break;
case Status::Busy:
ui->statusButton->setProperty("status" ,"busy");
break;
case Status::Offline:
ui->statusButton->setProperty("status" ,"offline");
break;
}
Style::repolish(ui->statusButton);
}
void Widget::onAddClicked()
@ -505,10 +434,6 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
f->friendStatus = status;
f->widget->updateStatusLight();
// Workaround widget style after returning to list
if (f->widget->isActive())
f->widget->setAsActiveChatroom();
}
void Widget::onFriendStatusMessageChanged(int friendId, const QString& message)
@ -557,7 +482,7 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message, bool
if (activeChatroomWidget != nullptr)
{
if ((static_cast<GenericChatroomWidget*>(f->widget) != activeChatroomWidget) || isWindowMinimized || !isActiveWindow())
if ((static_cast<GenericChatroomWidget*>(f->widget) != activeChatroomWidget) || isMinimized() || !isActiveWindow())
{
f->hasNewEvents = 1;
newMessageAlert();
@ -641,7 +566,7 @@ void Widget::onGroupMessageReceived(int groupnumber, int friendgroupnumber, cons
g->chatForm->addGroupMessage(message, friendgroupnumber);
if ((static_cast<GenericChatroomWidget*>(g->widget) != activeChatroomWidget) || isWindowMinimized || !isActiveWindow())
if ((static_cast<GenericChatroomWidget*>(g->widget) != activeChatroomWidget) || isMinimized() || !isActiveWindow())
{
g->hasNewMessages = 1;
if (message.contains(core->getUsername(), Qt::CaseInsensitive))
@ -734,368 +659,18 @@ bool Widget::isFriendWidgetCurActiveWidget(Friend* f)
bool Widget::event(QEvent * e)
{
if( e->type() == QEvent::WindowStateChange )
if (e->type() == QEvent::WindowActivate)
{
if(windowState().testFlag(Qt::WindowMinimized) == true)
{
isWindowMinimized = 1;
}
}
else if (e->type() == QEvent::WindowActivate)
{
if (!Settings::getInstance().getUseNativeDecoration())
{
this->setObjectName("activeWindow");
this->style()->polish(this);
}
isWindowMinimized = 0;
if (activeChatroomWidget != nullptr)
{
activeChatroomWidget->resetEventFlags();
activeChatroomWidget->updateStatusLight();
}
}
else if (e->type() == QEvent::WindowDeactivate && !Settings::getInstance().getUseNativeDecoration())
{
this->setObjectName("inactiveWindow");
this->style()->polish(this);
}
else if (e->type() == QEvent::MouseMove && !Settings::getInstance().getUseNativeDecoration())
{
QMouseEvent *k = (QMouseEvent *)e;
int xMouse = k->pos().x();
int yMouse = k->pos().y();
int wWidth = this->geometry().width();
int wHeight = this->geometry().height();
if (moveWidget)
{
inResizeZone = false;
moveWindow(k);
}
else if (allowToResize)
resizeWindow(k);
else if (xMouse >= wWidth - PIXELS_TO_ACT or allowToResize)
{
inResizeZone = true;
if (yMouse >= wHeight - PIXELS_TO_ACT)
{
setCursor(Qt::SizeFDiagCursor);
resizeWindow(k);
}
else if (yMouse <= PIXELS_TO_ACT)
{
setCursor(Qt::SizeBDiagCursor);
resizeWindow(k);
}
}
else
{
inResizeZone = false;
setCursor(Qt::ArrowCursor);
}
e->accept();
}
return QWidget::event(e);
}
void Widget::mousePressEvent(QMouseEvent *e)
{
if (!Settings::getInstance().getUseNativeDecoration())
{
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 (!Settings::getInstance().getUseNativeDecoration())
{
moveWidget = false;
allowToResize = false;
resizeVerSup = false;
resizeHorEsq = false;
resizeDiagSupEsq = false;
resizeDiagSupDer = false;
e->accept();
}
}
void Widget::mouseDoubleClickEvent(QMouseEvent *e)
{
if (!Settings::getInstance().getUseNativeDecoration())
{
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 (!Settings::getInstance().getUseNativeDecoration())
{
if (e->buttons() & Qt::LeftButton)
{
move(e->globalPos() - dragPosition);
e->accept();
}
}
}
void Widget::resizeWindow(QMouseEvent *e)
{
if (!Settings::getInstance().getUseNativeDecoration())
{
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);
}
}
void Widget::setStatusOnline()
{
core->setStatus(Status::Online);
@ -1111,21 +686,6 @@ void Widget::setStatusBusy()
core->setStatus(Status::Busy);
}
bool Widget::eventFilter(QObject *, QEvent *event)
{
if (event->type() == QEvent::Wheel)
{
QWheelEvent * whlEvnt = static_cast< QWheelEvent * >( event );
whlEvnt->angleDelta().setX(0);
}
return false;
}
bool Widget::getIsWindowMinimized()
{
return static_cast<bool>(isWindowMinimized);
}
void Widget::onMessageSendResult(int friendId, const QString& message, int messageId)
{
Q_UNUSED(message)

View File

@ -46,9 +46,6 @@ class Widget : public QMainWindow
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();
@ -71,8 +68,6 @@ signals:
void statusMessageChanged(const QString& statusMessage);
private slots:
void maximizeBtnClicked();
void minimizeBtnClicked();
void onConnected();
void onDisconnected();
void onStatusSet(Status status);
@ -108,32 +103,15 @@ private slots:
void onMessageSendResult(int friendId, const QString& message, int messageId);
void onGroupSendResult(int groupId, const QString& message, int result);
protected slots:
void moveWindow(QMouseEvent *e);
private:
void hideMainForms();
virtual bool event(QEvent * e);
Group* createGroup(int groupId);
private:
Ui::MainWindow *ui;
QSplitter *centralLayout;
QPoint dragPosition;
TitleMode m_titleMode;
bool moveWidget;
bool inResizeZone;
bool allowToResize;
bool resizeVerSup;
bool resizeHorEsq;
bool resizeDiagSupEsq;
bool resizeDiagSupDer;
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;
@ -145,7 +123,6 @@ private:
Camera* camera;
MaskablePixmapWidget* profilePicture;
bool notify(QObject *receiver, QEvent *event);
bool eventFilter(QObject *, QEvent *event);
};
#endif // WIDGET_H