mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Make compact contact layout dynamically changeable
There was some various minor incidental cleanups as well
This commit is contained in:
parent
1b2b4a1267
commit
e90293b47a
|
@ -351,6 +351,7 @@ void GeneralForm::onFauxOfflineMessaging()
|
|||
void GeneralForm::onCompactLayout()
|
||||
{
|
||||
Settings::getInstance().setCompactLayout(bodyUI->cbCompactLayout->isChecked());
|
||||
emit parent->compactToggled(bodyUI->cbCompactLayout->isChecked());
|
||||
}
|
||||
|
||||
void GeneralForm::onThemeColorChanged(int)
|
||||
|
|
|
@ -330,7 +330,7 @@
|
|||
<item row="3" column="1">
|
||||
<widget class="QCheckBox" name="cbCompactLayout">
|
||||
<property name="text">
|
||||
<string>Compact contact list (restart required)</string>
|
||||
<string>Compact contact list</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -42,15 +42,15 @@ public:
|
|||
void show(Ui::MainWindow &ui);
|
||||
void setBodyHeadStyle(QString style);
|
||||
|
||||
signals:
|
||||
void setShowSystemTray(bool newValue);
|
||||
void compactToggled(bool compact);
|
||||
|
||||
private slots:
|
||||
void onTabChanged(int);
|
||||
|
||||
signals:
|
||||
void setShowSystemTray(bool newValue);
|
||||
|
||||
private:
|
||||
QWidget *head, *body; // keep the others private
|
||||
IdentityForm *ifrm;
|
||||
QWidget *head, *body;
|
||||
QTabWidget *settingsWidgets;
|
||||
QLabel *nameLabel, *imgLabel;
|
||||
};
|
||||
|
|
|
@ -27,22 +27,6 @@ GenericChatroomWidget::GenericChatroomWidget(QWidget *parent)
|
|||
{
|
||||
setProperty("compact", Settings::getInstance().getCompactLayout());
|
||||
|
||||
if (property("compact").toBool())
|
||||
{
|
||||
setFixedHeight(25);
|
||||
}
|
||||
else
|
||||
{
|
||||
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
|
||||
if (property("compact").toBool())
|
||||
{
|
||||
|
@ -60,40 +44,66 @@ GenericChatroomWidget::GenericChatroomWidget(QWidget *parent)
|
|||
// name text
|
||||
nameLabel = new CroppingLabel(this);
|
||||
nameLabel->setObjectName("name");
|
||||
|
||||
if (property("compact").toBool())
|
||||
{
|
||||
layout.addSpacing(18);
|
||||
layout.addWidget(avatar);
|
||||
layout.addSpacing(5);
|
||||
layout.addWidget(nameLabel);
|
||||
layout.addWidget(statusMessageLabel);
|
||||
layout.addSpacing(5);
|
||||
layout.addWidget(&statusPic);
|
||||
layout.addSpacing(5);
|
||||
layout.activate();
|
||||
}
|
||||
else
|
||||
{
|
||||
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();
|
||||
}
|
||||
onCompactChanged(property("compact").toBool());
|
||||
|
||||
setProperty("active", false);
|
||||
setStyleSheet(Style::getStylesheet(":/ui/chatroomWidgets/genericChatroomWidget.css"));
|
||||
}
|
||||
|
||||
void GenericChatroomWidget::onCompactChanged(bool _compact)
|
||||
{
|
||||
delete textLayout; // has to be first, deleted by layout
|
||||
delete layout;
|
||||
|
||||
setProperty("compact", _compact);
|
||||
|
||||
layout = new QHBoxLayout;
|
||||
textLayout = new QVBoxLayout;
|
||||
|
||||
setLayout(layout);
|
||||
layout->setSpacing(0);
|
||||
layout->setMargin(0);
|
||||
textLayout->setSpacing(0);
|
||||
textLayout->setMargin(0);
|
||||
setLayoutDirection(Qt::LeftToRight); // parent might have set Qt::RightToLeft
|
||||
|
||||
// avatar
|
||||
if (property("compact").toBool())
|
||||
{
|
||||
setFixedHeight(25);
|
||||
avatar->setSize(QSize(20,20));
|
||||
layout->addSpacing(18);
|
||||
layout->addWidget(avatar);
|
||||
layout->addSpacing(5);
|
||||
layout->addWidget(nameLabel);
|
||||
layout->addWidget(statusMessageLabel);
|
||||
layout->addSpacing(5);
|
||||
layout->addWidget(&statusPic);
|
||||
layout->addSpacing(5);
|
||||
layout->activate();
|
||||
}
|
||||
else
|
||||
{
|
||||
setFixedHeight(55);
|
||||
avatar->setSize(QSize(40,40));
|
||||
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();
|
||||
}
|
||||
|
||||
Style::repolish(this);
|
||||
}
|
||||
|
||||
bool GenericChatroomWidget::isActive()
|
||||
{
|
||||
return property("active").toBool();
|
||||
|
|
|
@ -62,14 +62,15 @@ signals:
|
|||
void chatroomWidgetClicked(GenericChatroomWidget* widget);
|
||||
|
||||
public slots:
|
||||
void onCompactChanged(bool compact);
|
||||
|
||||
protected:
|
||||
QColor lastColor;
|
||||
QHBoxLayout layout;
|
||||
QVBoxLayout textLayout;
|
||||
QHBoxLayout* layout = nullptr;
|
||||
QVBoxLayout* textLayout = nullptr;
|
||||
MaskablePixmapWidget* avatar;
|
||||
QLabel statusPic;
|
||||
CroppingLabel *nameLabel, *statusMessageLabel;
|
||||
CroppingLabel* nameLabel, * statusMessageLabel;
|
||||
bool compact;
|
||||
|
||||
friend class Style; ///< To update our stylesheets
|
||||
|
|
|
@ -19,16 +19,11 @@
|
|||
|
||||
MaskablePixmapWidget::MaskablePixmapWidget(QWidget *parent, QSize size, QString maskName)
|
||||
: QWidget(parent)
|
||||
, renderTarget(size)
|
||||
, maskName(maskName)
|
||||
, backgroundColor(Qt::white)
|
||||
, clickable(false)
|
||||
{
|
||||
setFixedSize(size);
|
||||
|
||||
QPixmap pmapMask = QPixmap(maskName);
|
||||
|
||||
if (!pmapMask.isNull())
|
||||
mask = QPixmap(maskName).scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
setSize(size);
|
||||
}
|
||||
|
||||
void MaskablePixmapWidget::autopickBackground()
|
||||
|
@ -63,16 +58,11 @@ void MaskablePixmapWidget::autopickBackground()
|
|||
|
||||
QColor color = QColor::fromRgb(r,g,b);
|
||||
backgroundColor = QColor::fromRgb(0xFFFFFF ^ color.rgb());
|
||||
manualColor = false;
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void MaskablePixmapWidget::setBackground(QColor color)
|
||||
{
|
||||
backgroundColor = color;
|
||||
update();
|
||||
}
|
||||
|
||||
void MaskablePixmapWidget::setClickable(bool clickable)
|
||||
{
|
||||
this->clickable = clickable;
|
||||
|
@ -87,9 +77,10 @@ void MaskablePixmapWidget::setPixmap(const QPixmap &pmap, QColor background)
|
|||
{
|
||||
if (!pmap.isNull())
|
||||
{
|
||||
unscaled = pmap;
|
||||
pixmap = pmap.scaled(width(), height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
|
||||
backgroundColor = background;
|
||||
|
||||
manualColor = true;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
@ -98,25 +89,44 @@ void MaskablePixmapWidget::setPixmap(const QPixmap &pmap)
|
|||
{
|
||||
if (!pmap.isNull())
|
||||
{
|
||||
unscaled = pmap;
|
||||
pixmap = pmap.scaled(width(), height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
|
||||
autopickBackground();
|
||||
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
QPixmap MaskablePixmapWidget::getPixmap() const
|
||||
{
|
||||
return renderTarget;
|
||||
return *renderTarget;
|
||||
}
|
||||
|
||||
void MaskablePixmapWidget::setSize(QSize size)
|
||||
{
|
||||
setFixedSize(size);
|
||||
delete renderTarget;
|
||||
renderTarget = new QPixmap(size);
|
||||
|
||||
QPixmap pmapMask = QPixmap(maskName);
|
||||
if (!pmapMask.isNull())
|
||||
mask = pmapMask.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
|
||||
if (!unscaled.isNull())
|
||||
{
|
||||
pixmap = unscaled.scaled(width(), height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
|
||||
if (!manualColor)
|
||||
autopickBackground();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void MaskablePixmapWidget::paintEvent(QPaintEvent *)
|
||||
{
|
||||
renderTarget.fill(Qt::transparent);
|
||||
renderTarget->fill(Qt::transparent);
|
||||
|
||||
QPoint offset((width() - pixmap.size().width())/2,(height() - pixmap.size().height())/2); // centering the pixmap
|
||||
|
||||
QPainter painter(&renderTarget);
|
||||
QPainter painter(renderTarget);
|
||||
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
||||
painter.fillRect(0,0,width(),height(),backgroundColor);
|
||||
painter.drawPixmap(offset,pixmap);
|
||||
|
@ -125,7 +135,7 @@ void MaskablePixmapWidget::paintEvent(QPaintEvent *)
|
|||
painter.end();
|
||||
|
||||
painter.begin(this);
|
||||
painter.drawPixmap(0,0,renderTarget);
|
||||
painter.drawPixmap(0,0,*renderTarget);
|
||||
}
|
||||
|
||||
void MaskablePixmapWidget::mousePressEvent(QMouseEvent*)
|
||||
|
|
|
@ -26,11 +26,11 @@ public:
|
|||
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;
|
||||
void setSize(QSize size);
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
|
@ -40,13 +40,12 @@ protected:
|
|||
virtual void mousePressEvent(QMouseEvent *);
|
||||
|
||||
private:
|
||||
QPixmap pixmap;
|
||||
QPixmap mask;
|
||||
QPixmap renderTarget;
|
||||
QPixmap pixmap, mask, unscaled; // a lot of memory...
|
||||
QPixmap* renderTarget = nullptr; // pointer to dynamically call the constructor
|
||||
QSize size;
|
||||
QString maskName;
|
||||
QColor backgroundColor;
|
||||
bool clickable;
|
||||
bool clickable, manualColor = false;
|
||||
};
|
||||
|
||||
#endif // MASKABLEPIXMAPWIDGET_H
|
||||
|
|
|
@ -214,7 +214,7 @@ void Widget::init()
|
|||
addFriendForm = new AddFriendForm;
|
||||
settingsWidget = new SettingsWidget();
|
||||
|
||||
connect(settingsWidget, SIGNAL(setShowSystemTray(bool)), this, SLOT(onSetShowSystemTray(bool)));
|
||||
connect(settingsWidget, &SettingsWidget::setShowSystemTray, this, &Widget::onSetShowSystemTray);
|
||||
|
||||
connect(core, &Core::connected, this, &Widget::onConnected);
|
||||
connect(core, &Core::disconnected, this, &Widget::onDisconnected);
|
||||
|
@ -672,6 +672,7 @@ void Widget::addFriend(int friendId, const QString &userId)
|
|||
if (Settings::getInstance().getEnableLogging())
|
||||
newfriend->getChatForm()->loadHistory(QDateTime::currentDateTime().addDays(-7), true);
|
||||
|
||||
connect(settingsWidget, &SettingsWidget::compactToggled, newfriend->getFriendWidget(), &GenericChatroomWidget::onCompactChanged);
|
||||
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)));
|
||||
|
|
Loading…
Reference in New Issue
Block a user