Moved font logic into ResizingTextEdit, added namespaces

Couldn't use FontManager without including the namespaces (shouldn't they have been there in the first place?)
This commit is contained in:
CLouDY 2017-08-29 18:57:53 +01:00
parent 91dda9483b
commit ad1694234d
2 changed files with 24 additions and 0 deletions

View file

@ -1,5 +1,8 @@
#include "widgets/resizingtextedit.hpp" #include "widgets/resizingtextedit.hpp"
namespace chatterino {
namespace widgets {
ResizingTextEdit::ResizingTextEdit() ResizingTextEdit::ResizingTextEdit()
{ {
auto sizePolicy = this->sizePolicy(); auto sizePolicy = this->sizePolicy();
@ -30,6 +33,11 @@ int ResizingTextEdit::heightForWidth(int) const
return margins.top() + document()->size().height() + margins.bottom() + 5; return margins.top() + document()->size().height() + margins.bottom() + 5;
} }
QFont &ResizingTextEdit::getFont() const
{
return FontManager::getInstance().getFont(_font);
}
QString ResizingTextEdit::textUnderCursor(bool *hadSpace) const QString ResizingTextEdit::textUnderCursor(bool *hadSpace) const
{ {
auto currentText = this->toPlainText(); auto currentText = this->toPlainText();
@ -161,3 +169,6 @@ QCompleter *ResizingTextEdit::getCompleter() const
{ {
return this->completer; return this->completer;
} }
} // namespace widgets
} // namespace chatterino

View file

@ -1,15 +1,23 @@
#pragma once #pragma once
#include "fontmanager.hpp"
#include <QFont>
#include <QCompleter> #include <QCompleter>
#include <QKeyEvent> #include <QKeyEvent>
#include <QTextEdit> #include <QTextEdit>
#include <boost/signals2.hpp> #include <boost/signals2.hpp>
namespace chatterino {
namespace widgets {
class ResizingTextEdit : public QTextEdit class ResizingTextEdit : public QTextEdit
{ {
public: public:
ResizingTextEdit(); ResizingTextEdit();
QFont &getFont() const;
QSize sizeHint() const override; QSize sizeHint() const override;
bool hasHeightForWidth() const override; bool hasHeightForWidth() const override;
@ -26,6 +34,8 @@ protected:
private: private:
QCompleter *completer = nullptr; QCompleter *completer = nullptr;
FontManager::Type _font = FontManager::Small;
// hadSpace is set to true in case the "textUnderCursor" word was after a space // hadSpace is set to true in case the "textUnderCursor" word was after a space
QString textUnderCursor(bool *hadSpace = nullptr) const; QString textUnderCursor(bool *hadSpace = nullptr) const;
@ -34,3 +44,6 @@ private:
private slots: private slots:
void insertCompletion(const QString &completion); void insertCompletion(const QString &completion);
}; };
} // namespace widgets
} // namespace chatterino