mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Fixes #1344 Copying user id adds "ID: "
This commit is contained in:
parent
9874bd779a
commit
e31371fdf5
1 changed files with 17 additions and 9 deletions
|
@ -28,17 +28,23 @@
|
|||
|
||||
namespace chatterino {
|
||||
namespace {
|
||||
void addCopyableLabel(LayoutCreator<QHBoxLayout> box, Label **assign)
|
||||
Label *addCopyableLabel(LayoutCreator<QHBoxLayout> box)
|
||||
{
|
||||
auto label = box.emplace<Label>().assign(assign);
|
||||
auto label = box.emplace<Label>();
|
||||
auto button = box.emplace<Button>();
|
||||
button->setPixmap(getResources().buttons.copyDark);
|
||||
button->setScaleIndependantSize(18, 18);
|
||||
button->setDim(Button::Dim::Lots);
|
||||
QObject::connect(button.getElement(), &Button::leftClicked,
|
||||
[label = label.getElement()] {
|
||||
qApp->clipboard()->setText(label->getText());
|
||||
});
|
||||
QObject::connect(
|
||||
button.getElement(), &Button::leftClicked,
|
||||
[label = label.getElement()] {
|
||||
auto copyText = label->property("copy-text").toString();
|
||||
|
||||
qApp->clipboard()->setText(copyText.isEmpty() ? label->getText()
|
||||
: copyText);
|
||||
});
|
||||
|
||||
return label.getElement();
|
||||
};
|
||||
} // namespace
|
||||
|
||||
|
@ -77,10 +83,10 @@ UserInfoPopup::UserInfoPopup()
|
|||
auto box = vbox.emplace<QHBoxLayout>()
|
||||
.withoutMargin()
|
||||
.withoutSpacing();
|
||||
addCopyableLabel(box, &this->ui_.nameLabel);
|
||||
this->ui_.nameLabel = addCopyableLabel(box);
|
||||
this->ui_.nameLabel->setFontStyle(FontStyle::UiMediumBold);
|
||||
box->addStretch(1);
|
||||
addCopyableLabel(box, &this->ui_.userIDLabel);
|
||||
this->ui_.userIDLabel = addCopyableLabel(box);
|
||||
auto palette = QPalette();
|
||||
palette.setColor(QPalette::WindowText, QColor("#aaa"));
|
||||
this->ui_.userIDLabel->setPalette(palette);
|
||||
|
@ -369,6 +375,7 @@ void UserInfoPopup::setData(const QString &name, const ChannelPtr &channel)
|
|||
this->channel_ = channel;
|
||||
|
||||
this->ui_.nameLabel->setText(name);
|
||||
this->ui_.nameLabel->setProperty("copy-text", name);
|
||||
|
||||
this->updateUserData();
|
||||
|
||||
|
@ -384,7 +391,8 @@ void UserInfoPopup::updateUserData()
|
|||
|
||||
this->userId_ = id;
|
||||
|
||||
this->ui_.userIDLabel->setText(TEXT_USER_ID + this->userId_);
|
||||
this->ui_.userIDLabel->setText(TEXT_USER_ID + id);
|
||||
this->ui_.userIDLabel->setProperty("copy-text", id);
|
||||
// don't wait for the request to complete, just put the user id in the card
|
||||
// right away
|
||||
|
||||
|
|
Loading…
Reference in a new issue