mirror-chatterino2/src/widgets/helper/ResizingTextEdit.hpp
pajlada 032f290767
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories

In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:

    In ChatterSet.hpp, I changed lrucache to a <>include
    In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
    In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
    In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
    clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00

76 lines
2 KiB
C++

#pragma once
#include <pajlada/signals/signal.hpp>
#include <QCompleter>
#include <QKeyEvent>
#include <QTextEdit>
namespace chatterino {
class ResizingTextEdit : public QTextEdit
{
public:
ResizingTextEdit();
QSize sizeHint() const override;
bool hasHeightForWidth() const override;
bool isFirstWord() const;
pajlada::Signals::Signal<QKeyEvent *> keyPressed;
pajlada::Signals::NoArgSignal focused;
pajlada::Signals::NoArgSignal focusLost;
pajlada::Signals::Signal<const QMimeData *> imagePasted;
void setCompleter(QCompleter *c);
QCompleter *getCompleter() const;
/**
* Resets a completion for this text if one was is progress.
* See `completionInProgress_`.
*/
void resetCompletion();
protected:
int heightForWidth(int) const override;
void keyPressEvent(QKeyEvent *event) override;
void focusInEvent(QFocusEvent *event) override;
void focusOutEvent(QFocusEvent *event) override;
bool canInsertFromMimeData(const QMimeData *source) const override;
void insertFromMimeData(const QMimeData *source) 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;
/**
* This is true if a completion was done but the user didn't type yet,
* and might want to press `Tab` again to get the next completion
* on the original text.
*
* For example:
*
* input: "pog"
* `Tab` pressed:
* - complete to "PogBones"
* - retain "pog" for next completion
* - set `completionInProgress_ = true`
* `Tab` pressed again:
* - complete ["pog"] to "PogChamp"
*
* [other key] pressed - updating the input text:
* - set `completionInProgress_ = false`
*/
bool completionInProgress_ = false;
bool eventFilter(QObject *obj, QEvent *event) override;
private slots:
void insertCompletion(const QString &completion);
};
} // namespace chatterino