mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-17 15:31:20 +00:00
Use kSqueezedTextLabel for the label text on the statusbar
Summary: Following up from D8927; use kSqueezedTextLabel for the label text on the statusbar: - This simplifies the code in updateLabelText() - Remove the eventFilter as it's not needed any more since kSqueezedTextLabel has a resizeEvent function - Specify a stretch factor, 1, for m_label, m_zoomSlider and m_spaceInfo, this prevents the changing of the width of m_label when the label text is updated from changing the widths of the zoomSlider and the spaceInfo widgets as that is a bit too jumpy. (Thanks to the code of konversation statusbar for the hint about using the stretch factor in addWidget()). Reviewers: elvisangelaccio Subscribers: elvisangelaccio, #dolphin Differential Revision: https://phabricator.kde.org/D8991
This commit is contained in:
parent
a993485516
commit
11e2b186af
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
|
#include <KSqueezedTextLabel>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
|
||||||
#include "statusbarspaceinfo.h"
|
#include "statusbarspaceinfo.h"
|
||||||
|
@ -60,10 +61,9 @@ DolphinStatusBar::DolphinStatusBar(QWidget* parent) :
|
||||||
m_textTimestamp()
|
m_textTimestamp()
|
||||||
{
|
{
|
||||||
// Initialize text label
|
// Initialize text label
|
||||||
m_label = new QLabel(this);
|
m_label = new KSqueezedTextLabel(m_text, this);
|
||||||
m_label->setWordWrap(true);
|
m_label->setWordWrap(true);
|
||||||
m_label->setTextFormat(Qt::PlainText);
|
m_label->setTextFormat(Qt::PlainText);
|
||||||
m_label->installEventFilter(this);
|
|
||||||
|
|
||||||
// Initialize zoom widget
|
// Initialize zoom widget
|
||||||
m_zoomSlider = new QSlider(Qt::Horizontal, this);
|
m_zoomSlider = new QSlider(Qt::Horizontal, this);
|
||||||
|
@ -127,9 +127,9 @@ DolphinStatusBar::DolphinStatusBar(QWidget* parent) :
|
||||||
QHBoxLayout* topLayout = new QHBoxLayout(this);
|
QHBoxLayout* topLayout = new QHBoxLayout(this);
|
||||||
topLayout->setContentsMargins(2, 0, 2, 0);
|
topLayout->setContentsMargins(2, 0, 2, 0);
|
||||||
topLayout->setSpacing(4);
|
topLayout->setSpacing(4);
|
||||||
topLayout->addWidget(m_label);
|
topLayout->addWidget(m_label, 1);
|
||||||
topLayout->addWidget(m_zoomSlider);
|
topLayout->addWidget(m_zoomSlider, 1);
|
||||||
topLayout->addWidget(m_spaceInfo);
|
topLayout->addWidget(m_spaceInfo, 1);
|
||||||
topLayout->addWidget(m_stopButton);
|
topLayout->addWidget(m_stopButton);
|
||||||
topLayout->addWidget(m_progressTextLabel);
|
topLayout->addWidget(m_progressTextLabel);
|
||||||
topLayout->addWidget(m_progressBar);
|
topLayout->addWidget(m_progressBar);
|
||||||
|
@ -282,14 +282,6 @@ void DolphinStatusBar::contextMenuEvent(QContextMenuEvent* event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DolphinStatusBar::eventFilter(QObject* obj, QEvent* event)
|
|
||||||
{
|
|
||||||
if (obj == m_label && event->type() == QEvent::Resize) {
|
|
||||||
updateLabelText();
|
|
||||||
}
|
|
||||||
return QWidget::eventFilter(obj, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DolphinStatusBar::showZoomSliderToolTip(int zoomLevel)
|
void DolphinStatusBar::showZoomSliderToolTip(int zoomLevel)
|
||||||
{
|
{
|
||||||
updateZoomSliderToolTip(zoomLevel);
|
updateZoomSliderToolTip(zoomLevel);
|
||||||
|
@ -320,18 +312,7 @@ void DolphinStatusBar::updateProgressInfo()
|
||||||
void DolphinStatusBar::updateLabelText()
|
void DolphinStatusBar::updateLabelText()
|
||||||
{
|
{
|
||||||
const QString text = m_text.isEmpty() ? m_defaultText : m_text;
|
const QString text = m_text.isEmpty() ? m_defaultText : m_text;
|
||||||
|
m_label->setText(text);
|
||||||
// Set status bar text and elide it if too long
|
|
||||||
QFontMetrics fontMetrics(m_label->font());
|
|
||||||
const QString elidedText = fontMetrics.elidedText(text, Qt::ElideMiddle, m_label->width());
|
|
||||||
m_label->setText(elidedText);
|
|
||||||
|
|
||||||
// If the text has been elided, set the original text as tooltip
|
|
||||||
if (text != elidedText) {
|
|
||||||
m_label->setToolTip(Qt::convertFromPlainText(text));
|
|
||||||
} else {
|
|
||||||
m_label->setToolTip(QString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DolphinStatusBar::slotResetToDefaultText()
|
void DolphinStatusBar::slotResetToDefaultText()
|
||||||
|
|
|
@ -30,6 +30,7 @@ class QProgressBar;
|
||||||
class QToolButton;
|
class QToolButton;
|
||||||
class QSlider;
|
class QSlider;
|
||||||
class QTimer;
|
class QTimer;
|
||||||
|
class KSqueezedTextLabel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Represents the statusbar of a Dolphin view.
|
* @brief Represents the statusbar of a Dolphin view.
|
||||||
|
@ -102,7 +103,6 @@ signals:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void contextMenuEvent(QContextMenuEvent* event) override;
|
void contextMenuEvent(QContextMenuEvent* event) override;
|
||||||
bool eventFilter(QObject* obj, QEvent* event) override;
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void showZoomSliderToolTip(int zoomLevel);
|
void showZoomSliderToolTip(int zoomLevel);
|
||||||
|
@ -140,7 +140,7 @@ private:
|
||||||
private:
|
private:
|
||||||
QString m_text;
|
QString m_text;
|
||||||
QString m_defaultText;
|
QString m_defaultText;
|
||||||
QLabel* m_label;
|
KSqueezedTextLabel* m_label;
|
||||||
StatusBarSpaceInfo* m_spaceInfo;
|
StatusBarSpaceInfo* m_spaceInfo;
|
||||||
|
|
||||||
QSlider* m_zoomSlider;
|
QSlider* m_zoomSlider;
|
||||||
|
|
Loading…
Reference in a new issue