forked from osmocom/wireshark
Qt: ElidedLabel doesn't support rich text / HTML.
Change-Id: Ia5ca9784c60325c01ba5e6378997008f8ef1dd6e Reviewed-on: https://code.wireshark.org/review/7091 Reviewed-by: Gerald Combs <gerald@wireshark.org>
This commit is contained in:
parent
f1d1354b83
commit
a5652c7257
|
@ -22,9 +22,11 @@
|
|||
#include "elided_label.h"
|
||||
|
||||
#include <QFontMetrics>
|
||||
#include <QResizeEvent>
|
||||
|
||||
ElidedLabel::ElidedLabel(QWidget *parent) :
|
||||
QLabel(parent)
|
||||
QLabel(parent),
|
||||
small_text_(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -34,25 +36,27 @@ void ElidedLabel::setUrl(const QString &url)
|
|||
updateText();
|
||||
}
|
||||
|
||||
void ElidedLabel::resizeEvent(QResizeEvent *evt)
|
||||
void ElidedLabel::resizeEvent(QResizeEvent *)
|
||||
{
|
||||
Q_UNUSED(evt)
|
||||
updateText();
|
||||
}
|
||||
|
||||
void ElidedLabel::updateText()
|
||||
{
|
||||
QString elided_text = fontMetrics().elidedText(full_text_, Qt::ElideMiddle, width());
|
||||
int fudged_width = small_text_ ? width() * 1.2 : width();
|
||||
QString elided_text = fontMetrics().elidedText(full_text_, Qt::ElideMiddle, fudged_width);
|
||||
QString label_text = small_text_ ? "<small><i>" : "<i>";
|
||||
|
||||
if (url_.length() > 0) {
|
||||
QLabel::setText(QString("<i><a href=\"%1\">%2</a></i>")
|
||||
label_text.append(QString("<a href=\"%1\">%2</a>")
|
||||
.arg(url_)
|
||||
.arg(elided_text)
|
||||
);
|
||||
} else {
|
||||
QLabel::setText(QString("<i>%1</i>")
|
||||
.arg(elided_text)
|
||||
);
|
||||
label_text += elided_text;
|
||||
}
|
||||
label_text += small_text_ ? "</i></small>" : "</i>";
|
||||
QLabel::setText(label_text);
|
||||
}
|
||||
|
||||
void ElidedLabel::clear()
|
||||
|
|
|
@ -30,11 +30,13 @@ class ElidedLabel : public QLabel
|
|||
public:
|
||||
explicit ElidedLabel(QWidget *parent = 0);
|
||||
void setUrl(const QString &url);
|
||||
void setSmallText(bool small_text = true) { small_text_ = small_text; }
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *evt);
|
||||
void resizeEvent(QResizeEvent *);
|
||||
|
||||
private:
|
||||
bool small_text_;
|
||||
QString full_text_;
|
||||
QString url_;
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
|
||||
#include "frame_tvbuff.h"
|
||||
|
||||
#include "ui/utf8_entities.h"
|
||||
|
||||
#include "byte_view_tab.h"
|
||||
#include "proto_tree.h"
|
||||
#include "wireshark_application.h"
|
||||
|
@ -44,6 +46,7 @@ PacketDialog::PacketDialog(QWidget &parent, CaptureFile &cf, bool from_reference
|
|||
packet_data_(NULL)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->hintLabel->setSmallText();
|
||||
|
||||
// XXX Use recent settings instead
|
||||
resize(parent.width() * 4 / 5, parent.height() * 4 / 5);
|
||||
|
@ -98,10 +101,12 @@ PacketDialog::PacketDialog(QWidget &parent, CaptureFile &cf, bool from_reference
|
|||
|
||||
QStringList col_parts;
|
||||
for (int i = 0; i < cap_file_.capFile()->cinfo.num_cols; ++i) {
|
||||
col_parts << QString("<b>%1</b>").arg(get_column_title(i));
|
||||
col_parts << cap_file_.capFile()->cinfo.col_data[i];
|
||||
// ElidedLabel doesn't support rich text / HTML
|
||||
col_parts << QString("%1: %2")
|
||||
.arg(get_column_title(i))
|
||||
.arg(cap_file_.capFile()->cinfo.col_data[i]);
|
||||
}
|
||||
col_info_ = col_parts.join(" ");
|
||||
col_info_ = col_parts.join(" " UTF8_MIDDLE_DOT " ");
|
||||
setHintText();
|
||||
|
||||
connect(this, SIGNAL(monospaceFontChanged(QFont)),
|
||||
|
@ -140,8 +145,7 @@ void PacketDialog::captureFileClosing()
|
|||
|
||||
void PacketDialog::setHintText(QString &hint)
|
||||
{
|
||||
ui->hintLabel->setText(QString("<small><i>%1</i></small>")
|
||||
.arg(hint.isEmpty() ? col_info_ : hint));
|
||||
ui->hintLabel->setText(hint.isEmpty() ? col_info_ : hint);
|
||||
}
|
||||
|
||||
void PacketDialog::on_buttonBox_helpRequested()
|
||||
|
|
Loading…
Reference in New Issue