2017-04-06 02:06:42 +03:00
|
|
|
/*
|
|
|
|
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QDebug>
|
2017-04-23 21:31:08 +03:00
|
|
|
#include <QFile>
|
2017-04-06 02:06:42 +03:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QStyleOption>
|
|
|
|
|
2017-07-15 17:11:46 +03:00
|
|
|
#include "Config.h"
|
2017-04-06 02:06:42 +03:00
|
|
|
#include "TextInputWidget.h"
|
|
|
|
|
2017-04-23 21:31:08 +03:00
|
|
|
FilteredTextEdit::FilteredTextEdit(QWidget *parent)
|
2017-08-20 13:47:22 +03:00
|
|
|
: QTextEdit(parent)
|
2017-04-23 21:31:08 +03:00
|
|
|
{
|
2017-05-31 02:35:28 +03:00
|
|
|
setAcceptRichText(false);
|
2017-04-23 21:31:08 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
FilteredTextEdit::keyPressEvent(QKeyEvent *event)
|
2017-04-23 21:31:08 +03:00
|
|
|
{
|
|
|
|
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
|
|
|
|
emit enterPressed();
|
|
|
|
else
|
|
|
|
QTextEdit::keyPressEvent(event);
|
|
|
|
}
|
|
|
|
|
2017-04-06 02:06:42 +03:00
|
|
|
TextInputWidget::TextInputWidget(QWidget *parent)
|
2017-08-20 13:47:22 +03:00
|
|
|
: QWidget(parent)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-04-19 19:38:39 +03:00
|
|
|
setFont(QFont("Emoji One"));
|
|
|
|
|
2017-04-06 02:06:42 +03:00
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
|
|
setCursor(Qt::ArrowCursor);
|
2017-04-14 15:13:09 +03:00
|
|
|
setStyleSheet("background-color: #f8fbfe; height: 45px;");
|
2017-04-06 02:06:42 +03:00
|
|
|
|
|
|
|
top_layout_ = new QHBoxLayout();
|
2017-04-23 21:31:08 +03:00
|
|
|
top_layout_->setSpacing(0);
|
|
|
|
top_layout_->setMargin(0);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
|
|
|
send_file_button_ = new FlatButton(this);
|
|
|
|
|
|
|
|
QIcon send_file_icon;
|
|
|
|
send_file_icon.addFile(":/icons/icons/clip-dark.png", QSize(), QIcon::Normal, QIcon::Off);
|
2017-04-14 15:13:09 +03:00
|
|
|
send_file_button_->setForegroundColor(QColor("#acc7dc"));
|
2017-04-06 02:06:42 +03:00
|
|
|
send_file_button_->setIcon(send_file_icon);
|
|
|
|
send_file_button_->setIconSize(QSize(24, 24));
|
|
|
|
|
2017-07-01 15:52:46 +03:00
|
|
|
QFont font;
|
2017-07-15 17:11:46 +03:00
|
|
|
font.setPixelSize(conf::fontSize);
|
2017-07-01 15:52:46 +03:00
|
|
|
|
2017-04-23 21:31:08 +03:00
|
|
|
input_ = new FilteredTextEdit(this);
|
|
|
|
input_->setFixedHeight(45);
|
2017-07-01 15:52:46 +03:00
|
|
|
input_->setFont(font);
|
2017-05-29 19:09:12 +03:00
|
|
|
input_->setPlaceholderText(tr("Write a message..."));
|
2017-07-01 15:52:46 +03:00
|
|
|
input_->setStyleSheet("color: #333333; border-radius: 0; padding-top: 10px;");
|
2017-04-06 02:06:42 +03:00
|
|
|
|
|
|
|
send_message_button_ = new FlatButton(this);
|
2017-04-14 15:13:09 +03:00
|
|
|
send_message_button_->setForegroundColor(QColor("#acc7dc"));
|
2017-04-06 02:06:42 +03:00
|
|
|
|
|
|
|
QIcon send_message_icon;
|
|
|
|
send_message_icon.addFile(":/icons/icons/share-dark.png", QSize(), QIcon::Normal, QIcon::Off);
|
|
|
|
send_message_button_->setIcon(send_message_icon);
|
|
|
|
send_message_button_->setIconSize(QSize(24, 24));
|
|
|
|
|
2017-04-23 21:31:08 +03:00
|
|
|
emoji_button_ = new EmojiPickButton(this);
|
|
|
|
emoji_button_->setForegroundColor(QColor("#acc7dc"));
|
|
|
|
|
|
|
|
QIcon emoji_icon;
|
|
|
|
emoji_icon.addFile(":/icons/icons/smile.png", QSize(), QIcon::Normal, QIcon::Off);
|
|
|
|
emoji_button_->setIcon(emoji_icon);
|
|
|
|
emoji_button_->setIconSize(QSize(24, 24));
|
|
|
|
|
2017-04-06 02:06:42 +03:00
|
|
|
top_layout_->addWidget(send_file_button_);
|
|
|
|
top_layout_->addWidget(input_);
|
2017-04-23 21:31:08 +03:00
|
|
|
top_layout_->addWidget(emoji_button_);
|
2017-04-06 02:06:42 +03:00
|
|
|
top_layout_->addWidget(send_message_button_);
|
|
|
|
|
|
|
|
setLayout(top_layout_);
|
|
|
|
|
|
|
|
connect(send_message_button_, SIGNAL(clicked()), this, SLOT(onSendButtonClicked()));
|
2017-04-23 21:31:08 +03:00
|
|
|
connect(input_, SIGNAL(enterPressed()), send_message_button_, SIGNAL(clicked()));
|
|
|
|
connect(emoji_button_, SIGNAL(emojiSelected(const QString &)), this, SLOT(addSelectedEmoji(const QString &)));
|
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
TextInputWidget::addSelectedEmoji(const QString &emoji)
|
2017-04-23 21:31:08 +03:00
|
|
|
{
|
|
|
|
QTextCursor cursor = input_->textCursor();
|
|
|
|
|
|
|
|
QFont emoji_font("Emoji One");
|
2017-07-15 17:11:46 +03:00
|
|
|
emoji_font.setPixelSize(conf::emojiSize);
|
2017-04-23 21:31:08 +03:00
|
|
|
|
|
|
|
QFont text_font("Open Sans");
|
2017-07-15 17:11:46 +03:00
|
|
|
text_font.setPixelSize(conf::fontSize);
|
2017-04-23 21:31:08 +03:00
|
|
|
|
|
|
|
QTextCharFormat charfmt;
|
|
|
|
charfmt.setFont(emoji_font);
|
|
|
|
input_->setCurrentCharFormat(charfmt);
|
|
|
|
|
|
|
|
input_->insertPlainText(emoji);
|
|
|
|
cursor.movePosition(QTextCursor::End);
|
|
|
|
|
|
|
|
charfmt.setFont(text_font);
|
|
|
|
input_->setCurrentCharFormat(charfmt);
|
|
|
|
|
|
|
|
input_->show();
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
TextInputWidget::onSendButtonClicked()
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-04-23 21:31:08 +03:00
|
|
|
auto msg_text = input_->document()->toPlainText().trimmed();
|
2017-04-06 02:06:42 +03:00
|
|
|
|
|
|
|
if (msg_text.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
emit sendTextMessage(msg_text);
|
2017-04-23 21:31:08 +03:00
|
|
|
|
2017-04-06 02:06:42 +03:00
|
|
|
input_->clear();
|
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
TextInputWidget::paintEvent(QPaintEvent *event)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
|
|
|
Q_UNUSED(event);
|
|
|
|
|
|
|
|
QStyleOption option;
|
|
|
|
option.initFrom(this);
|
|
|
|
|
|
|
|
QPainter painter(this);
|
|
|
|
style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
TextInputWidget::~TextInputWidget()
|
|
|
|
{
|
|
|
|
}
|