mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 23:31:32 +08:00
Restored initial implementation of ElidingLabel because vertical label is not required anymore - SideBarButton implements orientation feature
This commit is contained in:
parent
293bf9b74f
commit
43c8d69281
@ -29,7 +29,6 @@
|
||||
//============================================================================
|
||||
#include "ElidingLabel.h"
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
|
||||
|
||||
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
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user