From 43c8d69281009ae9140503c08760c927ea82e0d0 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Wed, 26 Oct 2022 07:28:58 +0200 Subject: [PATCH] Restored initial implementation of ElidingLabel because vertical label is not required anymore - SideBarButton implements orientation feature --- src/ElidingLabel.cpp | 116 ++----------------------------------------- src/ElidingLabel.h | 26 +--------- 2 files changed, 5 insertions(+), 137 deletions(-) diff --git a/src/ElidingLabel.cpp b/src/ElidingLabel.cpp index f865941..ac52122 100644 --- a/src/ElidingLabel.cpp +++ b/src/ElidingLabel.cpp @@ -29,7 +29,6 @@ //============================================================================ #include "ElidingLabel.h" #include -#include namespace ads @@ -118,7 +117,7 @@ Qt::TextElideMode CElidingLabel::elideMode() const void CElidingLabel::setElideMode(Qt::TextElideMode mode) { d->ElideMode = mode; - d->elideText(availableWidthForText()); + d->elideText(size().width()); } //============================================================================ @@ -155,26 +154,12 @@ void CElidingLabel::resizeEvent(QResizeEvent *event) { if (!d->isModeElideNone()) { - d->elideText(availableWidthForText(event)); + d->elideText(event->size().width()); } Super::resizeEvent(event); } -//============================================================================ -int CElidingLabel::availableWidthForText() const -{ - return size().width(); -} - - -//============================================================================ -int CElidingLabel::availableWidthForText(QResizeEvent* event) const -{ - return event->size().width(); -} - - //============================================================================ QSize CElidingLabel::minimumSizeHint() const { @@ -230,7 +215,7 @@ void CElidingLabel::setText(const QString &text) else { internal::setToolTip(this, text); - d->elideText(availableWidthForText()); + d->elideText(this->size().width()); } } @@ -240,101 +225,6 @@ QString CElidingLabel::text() const { return d->Text; } - - -/** - * Private data of public CVerticalElidingLabel - */ -struct VerticalElidingLabelPrivate -{ - CVerticalElidingLabel* _this; - Qt::Orientation Orientation {Qt::Horizontal}; - - VerticalElidingLabelPrivate(CVerticalElidingLabel* _public); -}; - - -//============================================================================ -VerticalElidingLabelPrivate::VerticalElidingLabelPrivate(CVerticalElidingLabel* _public) - : _this(_public) -{ -} - - -//============================================================================ -CVerticalElidingLabel::CVerticalElidingLabel(QWidget* parent, Qt::WindowFlags f) : - CElidingLabel(parent, f), - d(new VerticalElidingLabelPrivate(this)) -{ -} - - -//============================================================================ -void CVerticalElidingLabel::setOrientation(Qt::Orientation orientation) -{ - d->Orientation = orientation; - updateGeometry(); -} - -//============================================================================ -void CVerticalElidingLabel::paintEvent(QPaintEvent* event) -{ - if (d->Orientation == Qt::Vertical) - { - QPainter painter(this); - painter.rotate(90); - painter.drawText(0,0, QLabel::text()); - return; - } - - CElidingLabel::paintEvent(event); -} - -//============================================================================ -QSize CVerticalElidingLabel::sizeHint() const -{ - if (d->Orientation == Qt::Vertical) - { - QSize s = CElidingLabel::minimumSizeHint(); - return QSize(s.height(), s.width()); - } - - return CElidingLabel::sizeHint(); -} - -//============================================================================ -QSize CVerticalElidingLabel::minimumSizeHint() const -{ - if (d->Orientation == Qt::Vertical) - { - QSize s = CElidingLabel::sizeHint(); - return QSize(s.height(), s.width()); - } - - return CElidingLabel::minimumSizeHint(); -} - -//============================================================================ -int CVerticalElidingLabel::availableWidthForText() const -{ - if (d->Orientation == Qt::Vertical) - { - return size().height(); - } - - return CElidingLabel::availableWidthForText(); -} - -//============================================================================ -int CVerticalElidingLabel::availableWidthForText(QResizeEvent* event) const -{ - if (d->Orientation == Qt::Vertical) - { - return event->size().height(); - } - - return CElidingLabel::availableWidthForText(event); -} } // namespace QtLabb //--------------------------------------------------------------------------- diff --git a/src/ElidingLabel.h b/src/ElidingLabel.h index 811a974..894dcb0 100644 --- a/src/ElidingLabel.h +++ b/src/ElidingLabel.h @@ -36,7 +36,7 @@ namespace ads { struct ElidingLabelPrivate; -struct VerticalElidingLabelPrivate; + /** * A QLabel that supports eliding text. * Because the functions setText() and text() are no virtual functions setting @@ -55,9 +55,6 @@ protected: virtual void resizeEvent( QResizeEvent *event ) override; virtual void mouseDoubleClickEvent( QMouseEvent *ev ) override; - virtual int availableWidthForText() const; - virtual int availableWidthForText(QResizeEvent* event) const; - public: using Super = QLabel; @@ -105,26 +102,7 @@ Q_SIGNALS: void elidedChanged(bool elided); }; //class CElidingLabel - -class CVerticalElidingLabel : public CElidingLabel -{ -private: - VerticalElidingLabelPrivate* d; - -protected: - void paintEvent(QPaintEvent* event) override; - QSize sizeHint() const override; - QSize minimumSizeHint() const override; - int availableWidthForText() const override; - int availableWidthForText(QResizeEvent* event) const override; - -public: - CVerticalElidingLabel(QWidget* parent = 0, Qt::WindowFlags f = Qt::WindowFlags ()); - - void setOrientation(Qt::Orientation orientation); -}; // class CVerticalElidingLabel - -} // namespace ads +} // namespace QtLabb //--------------------------------------------------------------------------- #endif // ElidingLabelH