summaryrefslogtreecommitdiff
path: root/ui/qt/label_stack.cpp
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2015-03-04 08:12:58 -0800
committerGerald Combs <gerald@wireshark.org>2015-03-05 00:49:11 +0000
commit0a4f93ab2bc7d4f45bb97d25a953e474d79550f3 (patch)
treedfa87b514298a3ebf83cf13a4fdec9fff598983b /ui/qt/label_stack.cpp
parent9df502aff5981c7759968ad1a07365c6cfd3961c (diff)
downloadwireshark-0a4f93ab2bc7d4f45bb97d25a953e474d79550f3.tar.gz
Qt: Show the full file path in the status bar.
Add file_size_to_qstring and use it to show the file size. Add a "shrinkable" property to LabelStack. Make the info status shrinkable. Elide text so that long file paths don't widen the main window. Change-Id: Ieb1caaf7e016384609d41fcabaa63d8f7a293eff Bug: 10949 Reviewed-on: https://code.wireshark.org/review/7534 Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'ui/qt/label_stack.cpp')
-rw-r--r--ui/qt/label_stack.cpp42
1 files changed, 38 insertions, 4 deletions
diff --git a/ui/qt/label_stack.cpp b/ui/qt/label_stack.cpp
index 2ccb9092c3..d88613be98 100644
--- a/ui/qt/label_stack.cpp
+++ b/ui/qt/label_stack.cpp
@@ -20,8 +20,10 @@
*/
#include "label_stack.h"
-#include <QMouseEvent>
+
#include <QContextMenuEvent>
+#include <QPainter>
+#include <QMouseEvent>
#include "tango_colors.h"
@@ -32,12 +34,13 @@ const int temporary_flash_timeout_ = temporary_interval_ / 5;
const int num_flashes_ = 3;
LabelStack::LabelStack(QWidget *parent) :
- QLabel(parent)
+ QLabel(parent),
+ temporary_ctx_(-1),
+ shrinkable_(false)
{
#ifdef Q_OS_MAC
setAttribute(Qt::WA_MacSmallSize, true);
#endif
- temporary_ctx_ = -1;
fillLabel();
connect(&temporary_timer_, SIGNAL(timeout()), this, SLOT(updateTemporaryStatus()));
@@ -77,7 +80,7 @@ void LabelStack::fillLabel() {
setText(si.text);
}
-void LabelStack::pushText(QString &text, int ctx) {
+void LabelStack::pushText(const QString &text, int ctx) {
popText(ctx);
if (ctx == temporary_ctx_) {
@@ -95,6 +98,18 @@ void LabelStack::pushText(QString &text, int ctx) {
fillLabel();
}
+void LabelStack::setShrinkable(bool shrinkable)
+{
+ shrinkable_ = shrinkable;
+ int min_width = 0;
+
+ if (shrinkable) {
+ min_width = fontMetrics().height() * 5; // em-widths
+ }
+ setMinimumWidth(min_width);
+ fillLabel();
+}
+
void LabelStack::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
@@ -121,6 +136,25 @@ void LabelStack::contextMenuEvent(QContextMenuEvent *event)
emit mousePressedAt(QPoint(event->globalPos()), Qt::RightButton);
}
+void LabelStack::paintEvent(QPaintEvent *event)
+{
+ if (!shrinkable_) {
+ QLabel::paintEvent(event);
+ return;
+ }
+
+ // Other "elided label" examples draw the label text by hand,
+ // reimplementing QLabel::paintEvent. Disabling updates and letting
+ // QLabel do the work for us seems to work, however.
+ QString elided_text = fontMetrics().elidedText(text(), Qt::ElideMiddle, width());
+ QString full_text = text();
+ setUpdatesEnabled(false);
+ setText(elided_text);
+ QLabel::paintEvent(event);
+ setText(full_text);
+ setUpdatesEnabled(true);
+}
+
void LabelStack::popText(int ctx) {
QMutableListIterator<StackItem> iter(labels_);