diff options
| author | Xusheng <xusheng@vector35.com> | 2023-09-19 13:03:03 +0800 |
|---|---|---|
| committer | Xusheng <xusheng@vector35.com> | 2023-09-19 15:00:12 +0800 |
| commit | b1e5ac87b14610a577292a85319047426ff47a8e (patch) | |
| tree | 6f61e76862c1be76ffbaaf279879dad0194092d2 | |
| parent | beb79f0a7aa38bdf6818056d8c21c6e599456be8 (diff) | |
Extract class CopyableLabel to an independent file. Fix https://github.com/Vector35/binaryninja/issues/525 and https://github.com/Vector35/binaryninja-api/issues/4630
| -rw-r--r-- | examples/triage/fileinfo.cpp | 39 | ||||
| -rw-r--r-- | ui/copyablelable.h | 14 |
2 files changed, 15 insertions, 38 deletions
diff --git a/examples/triage/fileinfo.cpp b/examples/triage/fileinfo.cpp index 5ac32bc6..dbecaddc 100644 --- a/examples/triage/fileinfo.cpp +++ b/examples/triage/fileinfo.cpp @@ -1,49 +1,12 @@ #include "fileinfo.h" #include "fontsettings.h" #include "theme.h" +#include "copyablelable.h" #include <QClipboard> #include <QApplication> #include <QToolTip> #include <QPainter> -class CopyableLabel : public QLabel -{ - QColor m_desiredColor {}; - - public: - CopyableLabel(const QString& text, const QColor& color) : QLabel(text), m_desiredColor(color) - { - this->setMouseTracking(true); - auto style = QPalette(palette()); - style.setColor(QPalette::WindowText, m_desiredColor); - setPalette(style); - this->setToolTip("Click to Copy"); - } - - void enterEvent(QEnterEvent* event) override - { - auto font = this->font(); - font.setUnderline(true); - this->setFont(font); - this->setCursor(Qt::PointingHandCursor); - - } - - void leaveEvent(QEvent* event) override - { - auto font = this->font(); - font.setUnderline(false); - this->setFont(font); - this->setCursor(Qt::ArrowCursor); - } - - void mousePressEvent(QMouseEvent* event) override - { - if (event->button() == Qt::LeftButton) - QApplication::clipboard()->setText(this->text()); - } -}; - void FileInfoWidget::addCopyableField(const QString& name, const QVariant& value) { auto& [row, column] = this->m_fieldPosition; diff --git a/ui/copyablelable.h b/ui/copyablelable.h new file mode 100644 index 00000000..9cca2bef --- /dev/null +++ b/ui/copyablelable.h @@ -0,0 +1,14 @@ +#include <QLabel> +#include "uitypes.h" + +class BINARYNINJAUIAPI CopyableLabel: public QLabel +{ + QColor m_desiredColor {}; + QString altText = ""; + +public: + CopyableLabel(const QString& text, const QColor& color, bool show = true); + void enterEvent(QEnterEvent* event) override; + void leaveEvent(QEvent* event) override; + void mousePressEvent(QMouseEvent* event) override; +}; |
