mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Fix GenericChatroomWidget rigth click glitch
Qt doesn't get mouse move events after a right click, so right clicking on a GenericChatroomWidget would get it stuck in the highlighed style until hovered in and out again We now explicitely interpret a right click as the mouse going out and fix the style accordingly Since the stylesheet has precedence over a QPalette, there wasn't a clean way to handle that with a stylesheet, so we now use a QPalette directly
This commit is contained in:
parent
f7dec499a7
commit
f8b9741bc4
1
res.qrc
1
res.qrc
|
@ -72,7 +72,6 @@
|
|||
<file>ui/chatArea/scrollBarDownArrow.svg</file>
|
||||
<file>ui/chatArea/scrollBarLeftArrow.svg</file>
|
||||
<file>ui/chatArea/scrollBarRightArrow.svg</file>
|
||||
<file>ui/chatroomWidgets/genericChatroomWidget.css</file>
|
||||
<file>ui/emoteButton/emoteButton.css</file>
|
||||
<file>ui/emoteButton/emoteButton.svg</file>
|
||||
<file>ui/emoticonWidget/dot_page.svg</file>
|
||||
|
|
|
@ -223,6 +223,8 @@ void FriendWidget::mousePressEvent(QMouseEvent *ev)
|
|||
{
|
||||
if (ev->button() == Qt::LeftButton)
|
||||
dragStartPos = ev->pos();
|
||||
|
||||
GenericChatroomWidget::mousePressEvent(ev);
|
||||
}
|
||||
|
||||
void FriendWidget::mouseMoveEvent(QMouseEvent *ev)
|
||||
|
|
|
@ -23,45 +23,40 @@
|
|||
#include "maskablepixmapwidget.h"
|
||||
#include "src/widget/tool/croppinglabel.h"
|
||||
#include <QMouseEvent>
|
||||
#include <QStyle>
|
||||
|
||||
GenericChatroomWidget::GenericChatroomWidget(QWidget *parent)
|
||||
: QFrame(parent)
|
||||
: QFrame(parent), compact{Settings::getInstance().getCompactLayout()},
|
||||
active{false}
|
||||
{
|
||||
setProperty("compact", Settings::getInstance().getCompactLayout());
|
||||
|
||||
// avatar
|
||||
if (property("compact").toBool())
|
||||
{
|
||||
if (compact)
|
||||
avatar = new MaskablePixmapWidget(this, QSize(20,20), ":/img/avatar_mask.svg");
|
||||
}
|
||||
else
|
||||
{
|
||||
avatar = new MaskablePixmapWidget(this, QSize(40,40), ":/img/avatar_mask.svg");
|
||||
}
|
||||
|
||||
// status text
|
||||
statusMessageLabel = new CroppingLabel(this);
|
||||
statusMessageLabel->setObjectName("status");
|
||||
statusMessageLabel->setTextFormat(Qt::PlainText);
|
||||
statusMessageLabel->setForegroundRole(QPalette::WindowText);
|
||||
|
||||
// name text
|
||||
nameLabel = new CroppingLabel(this);
|
||||
nameLabel->setObjectName("name");
|
||||
nameLabel->setTextFormat(Qt::PlainText);
|
||||
statusMessageLabel->setTextFormat(Qt::PlainText);
|
||||
nameLabel->setForegroundRole(QPalette::WindowText);
|
||||
|
||||
onCompactChanged(property("compact").toBool());
|
||||
|
||||
setProperty("active", false);
|
||||
setStyleSheet(Style::getStylesheet(":/ui/chatroomWidgets/genericChatroomWidget.css"));
|
||||
setAutoFillBackground(true);
|
||||
reloadTheme();
|
||||
setCompact(compact);
|
||||
}
|
||||
|
||||
void GenericChatroomWidget::onCompactChanged(bool _compact)
|
||||
void GenericChatroomWidget::setCompact(bool _compact)
|
||||
{
|
||||
compact = _compact;
|
||||
|
||||
delete textLayout; // has to be first, deleted by layout
|
||||
delete layout;
|
||||
|
||||
setProperty("compact", _compact);
|
||||
compact = _compact;
|
||||
|
||||
layout = new QHBoxLayout;
|
||||
textLayout = new QVBoxLayout;
|
||||
|
@ -74,7 +69,7 @@ void GenericChatroomWidget::onCompactChanged(bool _compact)
|
|||
setLayoutDirection(Qt::LeftToRight); // parent might have set Qt::RightToLeft
|
||||
|
||||
// avatar
|
||||
if (property("compact").toBool())
|
||||
if (compact)
|
||||
{
|
||||
setFixedHeight(25);
|
||||
avatar->setSize(QSize(20,20));
|
||||
|
@ -105,19 +100,28 @@ void GenericChatroomWidget::onCompactChanged(bool _compact)
|
|||
layout->addSpacing(10);
|
||||
layout->activate();
|
||||
}
|
||||
|
||||
Style::repolish(this);
|
||||
}
|
||||
|
||||
bool GenericChatroomWidget::isActive()
|
||||
{
|
||||
return property("active").toBool();
|
||||
return active;
|
||||
}
|
||||
|
||||
void GenericChatroomWidget::setActive(bool active)
|
||||
void GenericChatroomWidget::setActive(bool _active)
|
||||
{
|
||||
setProperty("active", active);
|
||||
Style::repolish(this);
|
||||
active = _active;
|
||||
if (active)
|
||||
{
|
||||
setBackgroundRole(QPalette::Light);
|
||||
statusMessageLabel->setForegroundRole(QPalette::HighlightedText);
|
||||
nameLabel->setForegroundRole(QPalette::HighlightedText);
|
||||
}
|
||||
else
|
||||
{
|
||||
setBackgroundRole(QPalette::Window);
|
||||
statusMessageLabel->setForegroundRole(QPalette::WindowText);
|
||||
nameLabel->setForegroundRole(QPalette::WindowText);
|
||||
}
|
||||
}
|
||||
|
||||
void GenericChatroomWidget::setName(const QString &name)
|
||||
|
@ -140,14 +144,25 @@ QString GenericChatroomWidget::getStatusMsg() const
|
|||
return statusMessageLabel->text();
|
||||
}
|
||||
|
||||
void GenericChatroomWidget::mouseReleaseEvent(QMouseEvent*)
|
||||
{
|
||||
emit chatroomWidgetClicked(this);
|
||||
}
|
||||
|
||||
void GenericChatroomWidget::reloadTheme()
|
||||
{
|
||||
setStyleSheet(Style::getStylesheet(":/ui/chatroomWidgets/genericChatroomWidget.css"));
|
||||
QPalette p;
|
||||
|
||||
p = statusMessageLabel->palette();
|
||||
p.setColor(QPalette::WindowText, Style::getColor(Style::LightGrey)); // Base color
|
||||
p.setColor(QPalette::HighlightedText, Style::getColor(Style::MediumGrey)); // Color when active
|
||||
statusMessageLabel->setPalette(p);
|
||||
|
||||
p = nameLabel->palette();
|
||||
p.setColor(QPalette::WindowText, Style::getColor(Style::White)); // Base color
|
||||
p.setColor(QPalette::HighlightedText, Style::getColor(Style::DarkGrey)); // Color when active
|
||||
nameLabel->setPalette(p);
|
||||
|
||||
p = palette();
|
||||
p.setColor(QPalette::Window, Style::getColor(Style::ThemeMedium)); // Base background color
|
||||
p.setColor(QPalette::Highlight, Style::getColor(Style::ThemeLight)); // On mouse over
|
||||
p.setColor(QPalette::Light, Style::getColor(Style::White)); // When active
|
||||
setPalette(p);
|
||||
}
|
||||
|
||||
bool GenericChatroomWidget::isCompact() const
|
||||
|
@ -155,8 +170,25 @@ bool GenericChatroomWidget::isCompact() const
|
|||
return compact;
|
||||
}
|
||||
|
||||
void GenericChatroomWidget::setCompact(bool compact)
|
||||
void GenericChatroomWidget::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
this->compact = compact;
|
||||
Style::repolish(this);
|
||||
if (!active && event->button() == Qt::RightButton)
|
||||
setBackgroundRole(QPalette::Window);
|
||||
}
|
||||
|
||||
void GenericChatroomWidget::mouseReleaseEvent(QMouseEvent*)
|
||||
{
|
||||
emit chatroomWidgetClicked(this);
|
||||
}
|
||||
|
||||
void GenericChatroomWidget::enterEvent(QEvent*)
|
||||
{
|
||||
if (!active)
|
||||
setBackgroundRole(QPalette::Highlight);
|
||||
}
|
||||
|
||||
void GenericChatroomWidget::leaveEvent(QEvent*)
|
||||
{
|
||||
if (!active)
|
||||
setBackgroundRole(QPalette::Window);
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@ class GenericChatroomWidget : public QFrame
|
|||
Q_OBJECT
|
||||
public:
|
||||
GenericChatroomWidget(QWidget *parent = 0);
|
||||
void mouseReleaseEvent (QMouseEvent* event);
|
||||
|
||||
virtual void setAsActiveChatroom(){;}
|
||||
virtual void setAsInactiveChatroom(){;}
|
||||
|
@ -58,15 +57,18 @@ public:
|
|||
void reloadTheme();
|
||||
|
||||
bool isCompact() const;
|
||||
void setCompact(bool compact);
|
||||
|
||||
Q_PROPERTY(bool compact READ isCompact WRITE setCompact)
|
||||
public slots:
|
||||
void setCompact(bool compact);
|
||||
|
||||
signals:
|
||||
void chatroomWidgetClicked(GenericChatroomWidget* widget);
|
||||
|
||||
public slots:
|
||||
void onCompactChanged(bool compact);
|
||||
protected:
|
||||
virtual void mousePressEvent(QMouseEvent* event);
|
||||
virtual void mouseReleaseEvent (QMouseEvent* event);
|
||||
virtual void enterEvent(QEvent* e);
|
||||
virtual void leaveEvent(QEvent* e);
|
||||
|
||||
protected:
|
||||
QColor lastColor;
|
||||
|
@ -75,9 +77,7 @@ protected:
|
|||
MaskablePixmapWidget* avatar;
|
||||
QLabel statusPic;
|
||||
CroppingLabel* nameLabel, *statusMessageLabel;
|
||||
bool compact;
|
||||
|
||||
friend class Style; ///< To update our stylesheets
|
||||
bool compact, active;
|
||||
};
|
||||
|
||||
#endif // GENERICCHATROOMWIDGET_H
|
||||
|
|
|
@ -575,7 +575,7 @@ void Widget::addFriend(int friendId, const QString &userId)
|
|||
|
||||
Core* core = Nexus::getCore();
|
||||
connect(newfriend, &Friend::displayedNameChanged, contactListWidget, &FriendListWidget::moveWidget);
|
||||
connect(settingsWidget, &SettingsWidget::compactToggled, newfriend->getFriendWidget(), &GenericChatroomWidget::onCompactChanged);
|
||||
connect(settingsWidget, &SettingsWidget::compactToggled, newfriend->getFriendWidget(), &GenericChatroomWidget::setCompact);
|
||||
connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
|
||||
connect(newfriend->getFriendWidget(), SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
|
||||
connect(newfriend->getFriendWidget(), SIGNAL(copyFriendIdToClipboard(int)), this, SLOT(copyFriendIdToClipboard(int)));
|
||||
|
@ -1031,7 +1031,7 @@ Group *Widget::createGroup(int groupId)
|
|||
layout->addWidget(newgroup->getGroupWidget());
|
||||
newgroup->getGroupWidget()->updateStatusLight();
|
||||
|
||||
connect(settingsWidget, &SettingsWidget::compactToggled, newgroup->getGroupWidget(), &GenericChatroomWidget::onCompactChanged);
|
||||
connect(settingsWidget, &SettingsWidget::compactToggled, newgroup->getGroupWidget(), &GenericChatroomWidget::setCompact);
|
||||
connect(newgroup->getGroupWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
|
||||
connect(newgroup->getGroupWidget(), SIGNAL(removeGroup(int)), this, SLOT(removeGroup(int)));
|
||||
connect(newgroup->getGroupWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), newgroup->getChatForm(), SLOT(focusInput()));
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
GenericChatroomWidget
|
||||
{
|
||||
background-color: @themeMedium;
|
||||
}
|
||||
|
||||
GenericChatroomWidget[active="true"]
|
||||
{
|
||||
background-color: @white;
|
||||
}
|
||||
|
||||
GenericChatroomWidget[active="false"]:hover
|
||||
{
|
||||
background-color: @themeLight;
|
||||
}
|
||||
|
||||
GenericChatroomWidget[active="true"][compact="true"] > QLabel#status
|
||||
{
|
||||
font: @small;
|
||||
color: @mediumGrey;
|
||||
}
|
||||
|
||||
GenericChatroomWidget[active="false"][compact="true"] > QLabel#status
|
||||
{
|
||||
font: @small;
|
||||
color: @lightGrey;
|
||||
}
|
||||
|
||||
GenericChatroomWidget[active="true"][compact="true"] > QLabel#name
|
||||
{
|
||||
font: @medium;
|
||||
color: @darkGrey;
|
||||
}
|
||||
|
||||
GenericChatroomWidget[active="false"][compact="true"] > QLabel#name
|
||||
{
|
||||
font: @medium;
|
||||
color: @white;
|
||||
}
|
||||
|
||||
GenericChatroomWidget[active="true"][compact="false"] > QLabel#status
|
||||
{
|
||||
font: @medium;
|
||||
color: @mediumGrey;
|
||||
}
|
||||
|
||||
GenericChatroomWidget[active="false"][compact="false"] > QLabel#status
|
||||
{
|
||||
font: @medium;
|
||||
color: @lightGrey;
|
||||
}
|
||||
|
||||
GenericChatroomWidget[active="true"][compact="false"] > QLabel#name
|
||||
{
|
||||
font: @big;
|
||||
color: @darkGrey;
|
||||
}
|
||||
|
||||
GenericChatroomWidget[active="false"][compact="false"] > QLabel#name
|
||||
{
|
||||
font: @big;
|
||||
color: @white;
|
||||
}
|
Loading…
Reference in New Issue
Block a user