Fixes #1344 Copying user id adds "ID: "

This commit is contained in:
fourtf 2019-10-01 22:38:21 +02:00
parent 9874bd779a
commit e31371fdf5

View file

@ -28,17 +28,23 @@
namespace chatterino { namespace chatterino {
namespace { 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>(); auto button = box.emplace<Button>();
button->setPixmap(getResources().buttons.copyDark); button->setPixmap(getResources().buttons.copyDark);
button->setScaleIndependantSize(18, 18); button->setScaleIndependantSize(18, 18);
button->setDim(Button::Dim::Lots); button->setDim(Button::Dim::Lots);
QObject::connect(button.getElement(), &Button::leftClicked, QObject::connect(
[label = label.getElement()] { button.getElement(), &Button::leftClicked,
qApp->clipboard()->setText(label->getText()); [label = label.getElement()] {
}); auto copyText = label->property("copy-text").toString();
qApp->clipboard()->setText(copyText.isEmpty() ? label->getText()
: copyText);
});
return label.getElement();
}; };
} // namespace } // namespace
@ -77,10 +83,10 @@ UserInfoPopup::UserInfoPopup()
auto box = vbox.emplace<QHBoxLayout>() auto box = vbox.emplace<QHBoxLayout>()
.withoutMargin() .withoutMargin()
.withoutSpacing(); .withoutSpacing();
addCopyableLabel(box, &this->ui_.nameLabel); this->ui_.nameLabel = addCopyableLabel(box);
this->ui_.nameLabel->setFontStyle(FontStyle::UiMediumBold); this->ui_.nameLabel->setFontStyle(FontStyle::UiMediumBold);
box->addStretch(1); box->addStretch(1);
addCopyableLabel(box, &this->ui_.userIDLabel); this->ui_.userIDLabel = addCopyableLabel(box);
auto palette = QPalette(); auto palette = QPalette();
palette.setColor(QPalette::WindowText, QColor("#aaa")); palette.setColor(QPalette::WindowText, QColor("#aaa"));
this->ui_.userIDLabel->setPalette(palette); this->ui_.userIDLabel->setPalette(palette);
@ -369,6 +375,7 @@ void UserInfoPopup::setData(const QString &name, const ChannelPtr &channel)
this->channel_ = channel; this->channel_ = channel;
this->ui_.nameLabel->setText(name); this->ui_.nameLabel->setText(name);
this->ui_.nameLabel->setProperty("copy-text", name);
this->updateUserData(); this->updateUserData();
@ -384,7 +391,8 @@ void UserInfoPopup::updateUserData()
this->userId_ = id; 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 // don't wait for the request to complete, just put the user id in the card
// right away // right away