aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2019-06-29 17:02:59 +0200
committerAnders Broman <a.broman58@gmail.com>2019-06-30 13:08:13 +0000
commita854811c4aa40d717c17499ead06cfec5f077fa5 (patch)
tree775f57969d0543fc8fcbcbfd50ff8c8af2cb0079 /ui
parent5599f8e492723c5d496e23ad5465f47e63334c5a (diff)
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>
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/models/pref_models.cpp2
-rw-r--r--ui/qt/utils/qt_ui_utils.cpp8
-rw-r--r--ui/qt/widgets/byte_view_text.cpp26
-rw-r--r--ui/qt/widgets/capture_filter_combo.cpp2
-rw-r--r--ui/qt/widgets/display_filter_combo.cpp4
-rw-r--r--ui/qt/widgets/syntax_line_edit.cpp7
6 files changed, 31 insertions, 18 deletions
diff --git a/ui/qt/models/pref_models.cpp b/ui/qt/models/pref_models.cpp
index 975b7c97de..c6b8f4fc95 100644
--- a/ui/qt/models/pref_models.cpp
+++ b/ui/qt/models/pref_models.cpp
@@ -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));
}
}
}
diff --git a/ui/qt/utils/qt_ui_utils.cpp b/ui/qt/utils/qt_ui_utils.cpp
index 9d243d1412..66acfab44e 100644
--- a/ui/qt/utils/qt_ui_utils.cpp
+++ b/ui/qt/utils/qt_ui_utils.cpp
@@ -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;
diff --git a/ui/qt/widgets/byte_view_text.cpp b/ui/qt/widgets/byte_view_text.cpp
index 6e2c1dcd50..71fa7cf82d 100644
--- a/ui/qt/widgets/byte_view_text.cpp
+++ b/ui/qt/widgets/byte_view_text.cpp
@@ -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;
}
diff --git a/ui/qt/widgets/capture_filter_combo.cpp b/ui/qt/widgets/capture_filter_combo.cpp
index 427868a1dd..7ed5389656 100644
--- a/ui/qt/widgets/capture_filter_combo.cpp
+++ b/ui/qt/widgets/capture_filter_combo.cpp
@@ -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());
diff --git a/ui/qt/widgets/display_filter_combo.cpp b/ui/qt/widgets/display_filter_combo.cpp
index 3814c398f0..d9e9e84ed7 100644
--- a/ui/qt/widgets/display_filter_combo.cpp
+++ b/ui/qt/widgets/display_filter_combo.cpp
@@ -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."));
diff --git a/ui/qt/widgets/syntax_line_edit.cpp b/ui/qt/widgets/syntax_line_edit.cpp
index feee60a8fe..ba65df1a44 100644
--- a/ui/qt/widgets/syntax_line_edit.cpp
+++ b/ui/qt/widgets/syntax_line_edit.cpp
@@ -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;
}