Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat(toxid): Show NoSpam and checksum parts of ToxID in colors.
Browse files Browse the repository at this point in the history
Also added the explanation to the ToxID tooltip message.
  • Loading branch information
yurivict committed Jun 15, 2017
1 parent 23ed1a3 commit c0951a5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
17 changes: 9 additions & 8 deletions src/widget/form/profileform.cpp
Expand Up @@ -62,8 +62,6 @@ ProfileForm::ProfileForm(QWidget* parent)

// tox
toxId = new ClickableTE();
toxId->setReadOnly(true);
toxId->setFrame(false);
toxId->setFont(Style::getFont(Style::Small));
toxId->setToolTip(bodyUI->toxId->toolTip());

Expand Down Expand Up @@ -213,13 +211,11 @@ void ProfileForm::showProfilePictureContextMenu(const QPoint& point)

void ProfileForm::copyIdClicked()
{
toxId->selectAll();
QString txt = toxId->text();
txt.replace('\n', "");
txt.remove(QRegularExpression("<[^>]*>"));
QApplication::clipboard()->setText(txt, QClipboard::Clipboard);
if (QApplication::clipboard()->supportsSelection())
QApplication::clipboard()->setText(txt, QClipboard::Selection);
toxId->setCursorPosition(0);

if (!hasCheck) {
bodyUI->toxIdLabel->setText(bodyUI->toxIdLabel->text() + "");
Expand All @@ -245,8 +241,12 @@ void ProfileForm::onSelfAvatarLoaded(const QPixmap& pic)

void ProfileForm::setToxId(const ToxId& id)
{
toxId->setText(id.toString());
toxId->setCursorPosition(0);
auto idString = id.toString();
static const QString ToxIdColor = QStringLiteral("%1<span style='color:blue'>%2</span><span style='color:gray'>%3</span>");
toxId->setText(ToxIdColor
.arg(idString.mid(0, 64))
.arg(idString.mid(64, 8))
.arg(idString.mid(72, 4)));

delete qr;
qr = new QRWidget();
Expand Down Expand Up @@ -466,7 +466,8 @@ void ProfileForm::retranslateUi()
// We have to add the toxId tooltip here and not in the .ui or Qt won't know how to translate it
// dynamically
toxId->setToolTip(tr("This bunch of characters tells other Tox clients how to contact "
"you.\nShare it with your friends to communicate."));
"you.\nShare it with your friends to communicate.\n\n"
"This ID includes the NoSpam code (in blue), and the checksum (in gray)."));
}

void ProfileForm::showRegisterToxme()
Expand Down
2 changes: 1 addition & 1 deletion src/widget/form/profileform.h
Expand Up @@ -36,7 +36,7 @@ namespace Ui {
class IdentitySettings;
}

class ClickableTE : public QLineEdit
class ClickableTE : public QLabel
{
Q_OBJECT
public:
Expand Down
6 changes: 3 additions & 3 deletions src/widget/form/profileform.ui
Expand Up @@ -206,12 +206,12 @@ Share it with your friends to communicate.</string>
</widget>
</item>
<item>
<widget class="QLineEdit" name="toxId">
<widget class="QLabel" name="toxId">
<property name="accessibleDescription">
<string>Your Tox ID</string>
</property>
<property name="frame">
<bool>true</bool>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
</widget>
</item>
Expand Down

0 comments on commit c0951a5

Please sign in to comment.