Files
SceneSwitcher/src/utils/resizing-text-edit.cpp
WarmUpTill 2c5caabab0 Add advss namespace
Fixes name conflict with "Duration" class and typedef of the same name
on MacOS
2023-04-17 11:33:24 -07:00

36 lines
868 B
C++

#include "resizing-text-edit.hpp"
namespace advss {
ResizingPlainTextEdit::ResizingPlainTextEdit(QWidget *parent,
const int scrollAt,
const int minLines,
const int paddingLines)
: QPlainTextEdit(parent),
_scrollAt(scrollAt),
_minLines(minLines),
_paddingLines(paddingLines)
{
QWidget::connect(this, SIGNAL(textChanged()), this,
SLOT(ResizeTexteditArea()));
}
void ResizingPlainTextEdit::ResizeTexteditArea()
{
QFontMetrics f(font());
int rowHeight = f.lineSpacing();
int numLines = document()->blockCount();
if (numLines + _paddingLines < _minLines) {
setFixedHeight(_minLines * rowHeight);
} else if (numLines + _paddingLines < _scrollAt) {
setFixedHeight((numLines + _paddingLines) * rowHeight);
} else {
setFixedHeight(_scrollAt * rowHeight);
}
adjustSize();
updateGeometry();
}
} // namespace advss