2017-06-07 10:09:24 +02:00
|
|
|
#pragma once
|
2017-01-21 05:14:27 +01:00
|
|
|
|
2017-07-09 00:09:02 +02:00
|
|
|
#include <QCompleter>
|
2017-01-29 13:23:22 +01:00
|
|
|
#include <QKeyEvent>
|
2017-01-21 05:14:27 +01:00
|
|
|
#include <QTextEdit>
|
2017-01-29 13:23:22 +01:00
|
|
|
#include <boost/signals2.hpp>
|
2017-01-21 05:14:27 +01:00
|
|
|
|
|
|
|
class ResizingTextEdit : public QTextEdit
|
|
|
|
{
|
|
|
|
public:
|
2017-07-09 00:09:02 +02:00
|
|
|
ResizingTextEdit();
|
2017-01-21 05:14:27 +01:00
|
|
|
|
2017-07-09 00:09:02 +02:00
|
|
|
QSize sizeHint() const override;
|
2017-01-29 13:23:22 +01:00
|
|
|
|
2017-07-09 00:09:02 +02:00
|
|
|
bool hasHeightForWidth() const override;
|
2017-01-21 05:14:27 +01:00
|
|
|
|
2017-07-09 00:09:02 +02:00
|
|
|
boost::signals2::signal<void(QKeyEvent *)> keyPressed;
|
2017-01-29 13:23:22 +01:00
|
|
|
|
2017-07-09 00:09:02 +02:00
|
|
|
void setCompleter(QCompleter *c);
|
|
|
|
QCompleter *getCompleter() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int heightForWidth(int) const override;
|
|
|
|
void keyPressEvent(QKeyEvent *event) override;
|
2017-01-29 13:23:22 +01:00
|
|
|
|
2017-07-09 00:09:02 +02:00
|
|
|
private:
|
|
|
|
QCompleter *completer = nullptr;
|
2017-08-01 00:10:02 +02:00
|
|
|
|
|
|
|
// hadSpace is set to true in case the "textUnderCursor" word was after a space
|
|
|
|
QString textUnderCursor(bool *hadSpace = nullptr) const;
|
|
|
|
|
2017-07-09 00:09:02 +02:00
|
|
|
bool nextCompletion = false;
|
2017-01-29 13:23:22 +01:00
|
|
|
|
2017-07-09 00:09:02 +02:00
|
|
|
private slots:
|
|
|
|
void insertCompletion(const QString &completion);
|
2017-01-21 05:14:27 +01:00
|
|
|
};
|