Qt: fix more more Qt 5.13 deprecation warnings

Potential functional changes:
- rect_on_screen: the new function no longer subtracts the space needed
  for the dock, task bar, etc.
- fontMetrics().width(text) -> fontMetrics.boundingRect(text).width():
  the bounding box width could be larger than horizontalAdvance(text).
  For the bytes view, they should be the same due to monospace font.
  The display filter field calculation was made more accurate (it
  assumes that textMargins() is 0 which is the default).

Change-Id: I70b7937f9215d3bef278befdac7c36a023ffff84
Reviewed-on: https://code.wireshark.org/review/33770
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Peter Wu 2019-06-29 17:02:59 +02:00 committed by Anders Broman
parent 5599f8e492
commit a854811c4a
6 changed files with 31 additions and 18 deletions

View File

@ -568,7 +568,7 @@ void AdvancedPrefsModel::setFirstColumnSpanned(QTreeView* tree, const QModelInde
if (childCount > 0) {
tree->setFirstColumnSpanned(mIndex.row(), mIndex.parent(), true);
for (row = 0; row < childCount; row++) {
setFirstColumnSpanned(tree, mIndex.child(row, 0));
setFirstColumnSpanned(tree, index(row, 0, mIndex));
}
}
}

View File

@ -27,13 +27,13 @@
#include <QApplication>
#include <QDateTime>
#include <QDesktopServices>
#include <QDesktopWidget>
#include <QDir>
#include <QFileInfo>
#include <QFontDatabase>
#include <QProcess>
#include <QUrl>
#include <QUuid>
#include <QScreen>
/* Make the format_size_flags_e enum usable in C++ */
format_size_flags_e operator|(format_size_flags_e lhs, format_size_flags_e rhs) {
@ -229,10 +229,10 @@ void desktop_show_in_folder(const QString file_path)
bool rect_on_screen(const QRect &rect)
{
QDesktopWidget *desktop = qApp->desktop();
for (int i = 0; i < desktop->screenCount(); i++) {
if (desktop->availableGeometry(i).contains(rect))
foreach (QScreen *screen, qApp->screens()) {
if (screen->availableGeometry().contains(rect)) {
return true;
}
}
return false;

View File

@ -343,7 +343,7 @@ void ByteViewText::drawLine(QPainter *painter, const int offset, const int row_y
if (show_offset_) {
line = QString(" %1 ").arg(offset, offsetChars(false), 16, QChar('0'));
if (build_x_pos) {
x_pos_to_column_.fill(-1, fontMetrics().width(line));
x_pos_to_column_.fill(-1, fontMetrics().boundingRect(line).width());
}
}
@ -378,19 +378,19 @@ void ByteViewText::drawLine(QPainter *painter, const int offset, const int row_y
break;
}
if (build_x_pos) {
x_pos_to_column_ += QVector<int>().fill(tvb_pos - offset, fontMetrics().width(line) - x_pos_to_column_.size() + slop);
x_pos_to_column_ += QVector<int>().fill(tvb_pos - offset, fontMetrics().boundingRect(line).width() - x_pos_to_column_.size() + slop);
}
if (tvb_pos == hovered_byte_offset_ || tvb_pos == marked_byte_offset_) {
int ho_len = recent.gui_bytes_view == BYTES_HEX ? 2 : 8;
QRect ho_rect = painter->boundingRect(QRect(), Qt::AlignHCenter|Qt::AlignVCenter, line.right(ho_len));
ho_rect.moveRight(fontMetrics().width(line));
ho_rect.moveRight(fontMetrics().boundingRect(line).width());
ho_rect.moveTop(row_y);
hover_outlines_.append(ho_rect);
}
}
line += QString(ascii_start - line.length(), ' ');
if (build_x_pos) {
x_pos_to_column_ += QVector<int>().fill(-1, fontMetrics().width(line) - x_pos_to_column_.size());
x_pos_to_column_ += QVector<int>().fill(-1, fontMetrics().boundingRect(line).width() - x_pos_to_column_.size());
}
addHexFormatRange(fmt_list, proto_start_, proto_len_, offset, max_tvb_pos, ModeProtocol);
@ -439,11 +439,11 @@ void ByteViewText::drawLine(QPainter *painter, const int offset, const int row_y
}
}
if (build_x_pos) {
x_pos_to_column_ += QVector<int>().fill(tvb_pos - offset, fontMetrics().width(line) - x_pos_to_column_.size());
x_pos_to_column_ += QVector<int>().fill(tvb_pos - offset, fontMetrics().boundingRect(line).width() - x_pos_to_column_.size());
}
if (tvb_pos == hovered_byte_offset_ || tvb_pos == marked_byte_offset_) {
QRect ho_rect = painter->boundingRect(QRect(), 0, line.right(1));
ho_rect.moveRight(fontMetrics().width(line));
ho_rect.moveRight(fontMetrics().boundingRect(line).width());
ho_rect.moveTop(row_y);
hover_outlines_.append(ho_rect);
}
@ -462,9 +462,17 @@ void ByteViewText::drawLine(QPainter *painter, const int offset, const int row_y
addFormatRange(fmt_list, 0, offsetChars(), offset_mode);
layout_->clearLayout();
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
layout_->clearFormats();
#else
layout_->clearAdditionalFormats();
#endif
layout_->setText(line);
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
layout_->setFormats(fmt_list.toVector());
#else
layout_->setAdditionalFormats(fmt_list);
#endif
layout_->beginLayout();
QTextLine tl = layout_->createLine();
tl.setLineWidth(totalPixels());
@ -567,7 +575,7 @@ int ByteViewText::offsetPixels()
if (show_offset_) {
// One pad space before and after
QString zeroes = QString(offsetChars(), '0');
return fontMetrics().width(zeroes);
return fontMetrics().boundingRect(zeroes).width();
}
return 0;
}
@ -578,7 +586,7 @@ int ByteViewText::hexPixels()
if (show_hex_) {
// One pad space before and after
QString zeroes = QString(DataPrinter::hexChars() + 2, '0');
return fontMetrics().width(zeroes);
return fontMetrics().boundingRect(zeroes).width();
}
return 0;
}
@ -589,7 +597,7 @@ int ByteViewText::asciiPixels()
// Two pad spaces before, one after
int ascii_chars = (row_width_ + ((row_width_ - 1) / separator_interval_));
QString zeroes = QString(ascii_chars + 3, '0');
return fontMetrics().width(zeroes);
return fontMetrics().boundingRect(zeroes).width();
}
return 0;
}

View File

@ -29,7 +29,7 @@ CaptureFilterCombo::CaptureFilterCombo(QWidget *parent, bool plain) :
// Enabling autocompletion here gives us two simultaneous completions:
// Inline (highlighted text) for entire filters, handled here and popup
// completion for fields handled by CaptureFilterEdit.
setAutoCompletion(false);
setCompleter(0);
setLineEdit(cf_edit_);
// Default is Preferred.
setSizePolicy(QSizePolicy::MinimumExpanding, sizePolicy().verticalPolicy());

View File

@ -33,12 +33,12 @@ DisplayFilterCombo::DisplayFilterCombo(QWidget *parent) :
// Enabling autocompletion here gives us two simultaneous completions:
// Inline (highlighted text) for entire filters, handled here and popup
// completion for fields handled by DisplayFilterEdit.
setAutoCompletion(false);
setCompleter(0);
setLineEdit(new DisplayFilterEdit(this, DisplayFilterToApply));
// Default is Preferred.
setSizePolicy(QSizePolicy::MinimumExpanding, sizePolicy().verticalPolicy());
setAccessibleName(tr("Display filter selector"));
cur_display_filter_combo = this;
cur_display_filter_combo = this;
updateStyleSheet();
setToolTip(tr("Select from previously used filters."));

View File

@ -374,8 +374,13 @@ void SyntaxLineEdit::paintEvent(QPaintEvent *event)
initStyleOption(&opt);
QRect cr = style()->subElementRect(QStyle::SE_LineEditContents, &opt, this);
QRect sir = QRect(0, 0, 14, 14); // QIcon::paint scales, which is not what we want.
int textWidth = fontMetrics().boundingRect(text()).width();
// Qt always adds a margin of 6px between the border and text, see
// QLineEditPrivate::effectiveLeftTextMargin and
// QLineEditPrivate::sideWidgetParameters.
int margin = 2 * 6 + 1;
if (fontMetrics().width(text()) + cr.height() > cr.width() || cr.height() < sir.height()) {
if (cr.width() - margin - textWidth < sir.width() || cr.height() < sir.height()) {
// No space to draw
return;
}