diff --git a/chatterino.pro b/chatterino.pro index f9dcbee56..8425168bd 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -68,7 +68,8 @@ SOURCES += main.cpp\ widgets/settingsdialog.cpp \ widgets/settingsdialogtab.cpp \ widgets/textinputdialog.cpp \ - windows.cpp + windows.cpp \ + logging.cpp HEADERS += account.h \ asyncexec.h \ @@ -109,7 +110,8 @@ HEADERS += account.h \ widgets/textinputdialog.h \ windows.h \ widgets/resizingtextedit.h \ - settingssnapshot.h + settingssnapshot.h \ + logging.h PRECOMPILED_HEADER = diff --git a/ircmanager.cpp b/ircmanager.cpp index 977cd16de..e8fdce5b0 100644 --- a/ircmanager.cpp +++ b/ircmanager.cpp @@ -155,6 +155,14 @@ IrcManager::disconnect() IrcManager::connectionMutex.unlock(); } +void +IrcManager::send(QString raw) +{ + IrcManager::connectionMutex.lock(); + IrcManager::connection->sendRaw(raw); + IrcManager::connectionMutex.unlock(); +} + void IrcManager::joinChannel(const QString &channel) { diff --git a/ircmanager.h b/ircmanager.h index b006435f6..713eb6897 100644 --- a/ircmanager.h +++ b/ircmanager.h @@ -20,6 +20,8 @@ public: static void connect(); static void disconnect(); + static void send(QString raw); + static const QString defaultClientId; bool isTwitchBlockedUser(QString const &username); diff --git a/logging.cpp b/logging.cpp new file mode 100644 index 000000000..5a33d793b --- /dev/null +++ b/logging.cpp @@ -0,0 +1,6 @@ +#include "logging.h" + +Logging::Logging() +{ + +} diff --git a/logging.h b/logging.h new file mode 100644 index 000000000..2b2e40a21 --- /dev/null +++ b/logging.h @@ -0,0 +1,11 @@ +#ifndef LOGGING_H +#define LOGGING_H + +class Logging +{ +public: +private: + Logging(); +}; + +#endif // LOGGING_H diff --git a/widgets/chatwidget.cpp b/widgets/chatwidget.cpp index 184271374..133c9ec04 100644 --- a/widgets/chatwidget.cpp +++ b/widgets/chatwidget.cpp @@ -19,7 +19,7 @@ ChatWidget::ChatWidget(QWidget *parent) , vbox(this) , header(this) , view(this) - , input() + , input(this) { this->vbox.setSpacing(0); this->vbox.setMargin(1); diff --git a/widgets/chatwidgetinput.cpp b/widgets/chatwidgetinput.cpp index 04edc2d04..1141a2f64 100644 --- a/widgets/chatwidgetinput.cpp +++ b/widgets/chatwidgetinput.cpp @@ -1,14 +1,18 @@ #include "widgets/chatwidgetinput.h" +#include "chatwidget.h" #include "colorscheme.h" +#include "ircmanager.h" #include "settings.h" #include +#include namespace chatterino { namespace widgets { -ChatWidgetInput::ChatWidgetInput() - : hbox() +ChatWidgetInput::ChatWidgetInput(ChatWidget *widget) + : chatWidget(widget) + , hbox() , vbox() , editContainer() , edit() @@ -36,13 +40,28 @@ ChatWidgetInput::ChatWidgetInput() ""); - // this->emotesLabel.setMaximumSize(12, 12); + QObject::connect(&edit, &ResizingTextEdit::textChanged, this, + &ChatWidgetInput::editTextChanged); + + // QObject::connect(&edit, &ResizingTextEdit::keyPressEvent, this, + // &ChatWidgetInput::editKeyPressed); this->refreshTheme(); - this->setMessageLengthVisisble( Settings::getInstance().showMessageLength.get()); + this->edit.keyPressed.connect([this](QKeyEvent *event) { + if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) { + Channel *c = this->chatWidget->getChannel(); + if (c != nullptr) { + IrcManager::send("PRIVMSG #" + c->getName() + ": " + + this->edit.toPlainText()); + event->accept(); + this->edit.setText(QString()); + } + } + }); + /* XXX(pajlada): FIX THIS QObject::connect(&Settings::getInstance().showMessageLength, &BoolSetting::valueChanged, this, @@ -72,6 +91,21 @@ ChatWidgetInput::refreshTheme() edit.setStyleSheet(ColorScheme::getInstance().InputStyleSheet); } +void +ChatWidgetInput::editTextChanged() +{ +} + +// void +// ChatWidgetInput::editKeyPressed(QKeyEvent *event) +//{ +// if (event->key() == Qt::Key_Enter) { +// event->accept(); +// IrcManager::send("PRIVMSG #" + edit.toPlainText(); +// edit.setText(QString()); +// } +//} + void ChatWidgetInput::paintEvent(QPaintEvent *) { diff --git a/widgets/chatwidgetinput.h b/widgets/chatwidgetinput.h index b86087527..9c6512536 100644 --- a/widgets/chatwidgetinput.h +++ b/widgets/chatwidgetinput.h @@ -15,12 +15,14 @@ namespace chatterino { namespace widgets { +class ChatWidget; + class ChatWidgetInput : public QWidget { Q_OBJECT public: - ChatWidgetInput(); + ChatWidgetInput(ChatWidget *parent); ~ChatWidgetInput(); protected: @@ -29,6 +31,8 @@ protected: void resizeEvent(QResizeEvent *); private: + ChatWidget *chatWidget; + QHBoxLayout hbox; QVBoxLayout vbox; QHBoxLayout editContainer; @@ -43,6 +47,8 @@ private slots: { this->textLengthLabel.setHidden(!value); } + void editTextChanged(); + // void editKeyPressed(QKeyEvent *event); }; } } diff --git a/widgets/resizingtextedit.h b/widgets/resizingtextedit.h index e471ce839..ef6b250dc 100644 --- a/widgets/resizingtextedit.h +++ b/widgets/resizingtextedit.h @@ -1,12 +1,15 @@ #ifndef RESIZINGTEXTEDIT_H #define RESIZINGTEXTEDIT_H +#include #include +#include class ResizingTextEdit : public QTextEdit { public: ResizingTextEdit() + : keyPressed() { auto sizePolicy = this->sizePolicy(); sizePolicy.setHeightForWidth(true); @@ -29,6 +32,8 @@ public: return true; } + boost::signals2::signal keyPressed; + protected: int heightForWidth(int) const override @@ -38,6 +43,18 @@ protected: return margins.top() + document()->size().height() + margins.bottom() + 5; } + + void + keyPressEvent(QKeyEvent *event) + { + event->ignore(); + + keyPressed(event); + + if (!event->isAccepted()) { + QTextEdit::keyPressEvent(event); + } + } }; #endif // RESIZINGTEXTEDIT_H diff --git a/widgets/settingsdialog.cpp b/widgets/settingsdialog.cpp index fc72b34c3..c754d2c4a 100644 --- a/widgets/settingsdialog.cpp +++ b/widgets/settingsdialog.cpp @@ -179,6 +179,11 @@ SettingsDialog::addTabs() vbox->addStretch(1); addTab(vbox, "Links", ":/images/VSO_Link_blue_16x.png"); + // Logging + vbox = new QVBoxLayout(); + vbox->addStretch(1); + addTab(vbox, "Logs", ":/images/VSO_Link_blue_16x.png"); + // Highlighting vbox = new QVBoxLayout(); vbox->addStretch(1);