mirror-chatterino2/src/widgets/helper/ResizingTextEdit.hpp
2018-08-06 21:17:03 +02:00

46 lines
1.1 KiB
C++

#pragma once
#include <QCompleter>
#include <QKeyEvent>
#include <QTextEdit>
#include <pajlada/signals/signal.hpp>
namespace chatterino {
class ResizingTextEdit : public QTextEdit
{
public:
ResizingTextEdit();
QSize sizeHint() const override;
bool hasHeightForWidth() const override;
pajlada::Signals::Signal<QKeyEvent *> keyPressed;
pajlada::Signals::NoArgSignal focused;
pajlada::Signals::NoArgSignal focusLost;
void setCompleter(QCompleter *c);
QCompleter *getCompleter() const;
protected:
int heightForWidth(int) const override;
void keyPressEvent(QKeyEvent *event) override;
void focusInEvent(QFocusEvent *event) override;
void focusOutEvent(QFocusEvent *event) override;
private:
// hadSpace is set to true in case the "textUnderCursor" word was after a
// space
QString textUnderCursor(bool *hadSpace = nullptr) const;
QCompleter *completer_ = nullptr;
bool completionInProgress_ = false;
private slots:
void insertCompletion(const QString &completion);
};
} // namespace chatterino