mirror-chatterino2/widgets/resizingtextedit.h

44 lines
933 B
C
Raw Normal View History

2017-01-21 05:14:27 +01:00
#ifndef RESIZINGTEXTEDIT_H
#define RESIZINGTEXTEDIT_H
#include <QTextEdit>
class ResizingTextEdit : public QTextEdit
{
public:
ResizingTextEdit()
{
auto sizePolicy = this->sizePolicy();
sizePolicy.setHeightForWidth(true);
sizePolicy.setVerticalPolicy(QSizePolicy::Preferred);
this->setSizePolicy(sizePolicy);
2017-01-23 16:38:06 +01:00
QObject::connect(this, &QTextEdit::textChanged, this,
&QWidget::updateGeometry);
2017-01-21 05:14:27 +01:00
}
QSize
sizeHint() const override
{
return QSize(this->width(), this->heightForWidth(this->width()));
}
bool
hasHeightForWidth() const override
{
return true;
}
protected:
int
2017-01-23 16:38:06 +01:00
heightForWidth(int) const override
2017-01-21 05:14:27 +01:00
{
auto margins = this->contentsMargins();
2017-01-23 16:38:06 +01:00
return margins.top() + document()->size().height() + margins.bottom() +
5;
2017-01-21 05:14:27 +01:00
}
};
#endif // RESIZINGTEXTEDIT_H