Merge branch 'auto_hide_feature' of github.com:duerr-ndt/Qt-Advanced-Docking-System into auto_hide_feature

This commit is contained in:
Syarif Fakhri 2022-09-09 13:37:14 +08:00
commit 54b9a8dc50
2 changed files with 35 additions and 4 deletions

View File

@ -118,7 +118,7 @@ Qt::TextElideMode CElidingLabel::elideMode() const
void CElidingLabel::setElideMode(Qt::TextElideMode mode) void CElidingLabel::setElideMode(Qt::TextElideMode mode)
{ {
d->ElideMode = mode; d->ElideMode = mode;
d->elideText(size().width()); d->elideText(availableWidthForText());
} }
//============================================================================ //============================================================================
@ -155,12 +155,26 @@ void CElidingLabel::resizeEvent(QResizeEvent *event)
{ {
if (!d->isModeElideNone()) if (!d->isModeElideNone())
{ {
d->elideText(event->size().width()); d->elideText(availableWidthForText(event));
} }
Super::resizeEvent(event); Super::resizeEvent(event);
} }
//============================================================================
int CElidingLabel::availableWidthForText() const
{
return size().width();
}
//============================================================================
int CElidingLabel::availableWidthForText(QResizeEvent* event) const
{
return event->size().width();
}
//============================================================================ //============================================================================
QSize CElidingLabel::minimumSizeHint() const QSize CElidingLabel::minimumSizeHint() const
{ {
@ -216,7 +230,7 @@ void CElidingLabel::setText(const QString &text)
else else
{ {
internal::setToolTip(this, text); internal::setToolTip(this, text);
d->elideText(this->size().width()); d->elideText(availableWidthForText());
} }
} }
@ -238,7 +252,7 @@ void CVerticalElidingLabel::paintEvent(QPaintEvent* event)
{ {
QPainter painter(this); QPainter painter(this);
painter.rotate(90); painter.rotate(90);
painter.drawText(0,0, text()); painter.drawText(0,0, QLabel::text());
} }
//============================================================================ //============================================================================
@ -254,6 +268,18 @@ QSize CVerticalElidingLabel::minimumSizeHint() const
QSize s = CElidingLabel::sizeHint(); QSize s = CElidingLabel::sizeHint();
return QSize(s.height(), s.width()); return QSize(s.height(), s.width());
} }
//============================================================================
int CVerticalElidingLabel::availableWidthForText() const
{
return size().height();
}
//============================================================================
int CVerticalElidingLabel::availableWidthForText(QResizeEvent* event) const
{
return event->size().height();
}
} // namespace QtLabb } // namespace QtLabb
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -55,6 +55,9 @@ protected:
virtual void resizeEvent( QResizeEvent *event ) override; virtual void resizeEvent( QResizeEvent *event ) override;
virtual void mouseDoubleClickEvent( QMouseEvent *ev ) override; virtual void mouseDoubleClickEvent( QMouseEvent *ev ) override;
virtual int availableWidthForText() const;
virtual int availableWidthForText(QResizeEvent* event) const;
public: public:
using Super = QLabel; using Super = QLabel;
@ -109,6 +112,8 @@ protected:
void paintEvent(QPaintEvent* event) override; void paintEvent(QPaintEvent* event) override;
QSize sizeHint() const override; QSize sizeHint() const override;
QSize minimumSizeHint() const override; QSize minimumSizeHint() const override;
int availableWidthForText() const override;
int availableWidthForText(QResizeEvent* event) const override;
public: public:
CVerticalElidingLabel(QWidget* parent = 0, Qt::WindowFlags f = Qt::WindowFlags ()); CVerticalElidingLabel(QWidget* parent = 0, Qt::WindowFlags f = Qt::WindowFlags ());