mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
commit
c0f1f196b1
6
qtox.pro
6
qtox.pro
|
@ -84,7 +84,8 @@ HEADERS += widget/form/addfriendform.h \
|
|||
widget/camera.h \
|
||||
widget/netcamview.h \
|
||||
widget/tool/clickablelabel.h \
|
||||
smileypack.h
|
||||
smileypack.h \
|
||||
widget/emoticonswidget.h
|
||||
|
||||
SOURCES += \
|
||||
widget/form/addfriendform.cpp \
|
||||
|
@ -117,4 +118,5 @@ SOURCES += \
|
|||
widget/camera.cpp \
|
||||
widget/netcamview.cpp \
|
||||
widget/tool/clickablelabel.cpp \
|
||||
smileypack.cpp
|
||||
smileypack.cpp \
|
||||
widget/emoticonswidget.cpp
|
||||
|
|
3
res.qrc
3
res.qrc
|
@ -111,5 +111,8 @@
|
|||
<file>ui/statusButton/menu_indicator.png</file>
|
||||
<file>translations/de.qm</file>
|
||||
<file>translations/it.qm</file>
|
||||
<file>ui/emoticonWidget/dot_page.png</file>
|
||||
<file>ui/emoticonWidget/dot_page_current.png</file>
|
||||
<file>ui/emoticonWidget/emoticonWidget.css</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
#include "settings.h"
|
||||
#include "smileypack.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
|
@ -22,6 +23,7 @@
|
|||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
#include <QDebug>
|
||||
#include <QList>
|
||||
|
||||
const QString Settings::FILENAME = "settings.ini";
|
||||
bool Settings::makeToxPortable{false};
|
||||
|
@ -92,7 +94,7 @@ void Settings::load()
|
|||
|
||||
s.beginGroup("GUI");
|
||||
enableSmoothAnimation = s.value("smoothAnimation", true).toBool();
|
||||
smileyPack = s.value("smileyPack").toByteArray();
|
||||
smileyPack = s.value("smileyPack", !SmileyPack::listSmileyPacks().empty() ? SmileyPack::listSmileyPacks()[0].second : "").toString();
|
||||
customEmojiFont = s.value("customEmojiFont", true).toBool();
|
||||
emojiFontFamily = s.value("emojiFontFamily", "DejaVu Sans").toString();
|
||||
emojiFontPointSize = s.value("emojiFontPointSize", QApplication::font().pointSize()).toInt();
|
||||
|
|
|
@ -28,7 +28,7 @@ class SmileyPack : public QObject
|
|||
Q_OBJECT
|
||||
public:
|
||||
static SmileyPack& getInstance();
|
||||
static QList<QPair<QString, QString>> listSmileyPacks(const QString& path);
|
||||
static QList<QPair<QString, QString>> listSmileyPacks(const QString& path = "./smileys");
|
||||
|
||||
bool load(const QString &filename);
|
||||
QString smileyfied(QString msg);
|
||||
|
|
BIN
ui/emoticonWidget/dot_page.png
Normal file
BIN
ui/emoticonWidget/dot_page.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 233 B |
BIN
ui/emoticonWidget/dot_page_current.png
Normal file
BIN
ui/emoticonWidget/dot_page_current.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 263 B |
49
ui/emoticonWidget/emoticonWidget.css
Normal file
49
ui/emoticonWidget/emoticonWidget.css
Normal file
|
@ -0,0 +1,49 @@
|
|||
QPushButton
|
||||
{
|
||||
background-color: transparent;
|
||||
background-repeat: none;
|
||||
border: none;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
}
|
||||
|
||||
QRadioButton::indicator
|
||||
{
|
||||
width: 13px;
|
||||
height: 13px;
|
||||
}
|
||||
|
||||
QRadioButton::indicator::unchecked
|
||||
{
|
||||
image: url(:/ui/emoticonWidget/dot_page.png);
|
||||
}
|
||||
|
||||
QRadioButton::indicator:unchecked:hover
|
||||
{
|
||||
image: url(:/ui/emoticonWidget/dot_page.png);
|
||||
}
|
||||
|
||||
QRadioButton::indicator:unchecked:pressed
|
||||
{
|
||||
image: url(:/ui/emoticonWidget/dot_page.png);
|
||||
}
|
||||
|
||||
QRadioButton::indicator::checked
|
||||
{
|
||||
image: url(:/ui/emoticonWidget/dot_page_current.png);
|
||||
}
|
||||
|
||||
QRadioButton::indicator:checked:hover
|
||||
{
|
||||
image: url(:/ui/emoticonWidget/dot_page_current.png);
|
||||
}
|
||||
|
||||
QRadioButton::indicator:checked:pressed
|
||||
{
|
||||
image: url(:/ui/emoticonWidget/dot_page.png);
|
||||
}
|
||||
|
||||
QMenu
|
||||
{
|
||||
background-color: rgb(240,240,240); /* sets background of the menu */
|
||||
}
|
24
widget.ui
24
widget.ui
|
@ -1,20 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
This program is libre 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 COPYING file for more details.
|
||||
-->
|
||||
|
||||
<ui version="4.0">
|
||||
<class>Widget</class>
|
||||
<widget class="QWidget" name="Widget">
|
||||
|
@ -23,13 +7,13 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>640</width>
|
||||
<height>320</height>
|
||||
<height>420</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>640</width>
|
||||
<height>320</height>
|
||||
<height>420</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
|
@ -2131,8 +2115,8 @@ QSplitter:handle{
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>256</width>
|
||||
<height>199</height>
|
||||
<width>255</width>
|
||||
<height>299</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
|
|
135
widget/emoticonswidget.cpp
Normal file
135
widget/emoticonswidget.cpp
Normal file
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
This program is libre 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 COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "emoticonswidget.h"
|
||||
#include "smileypack.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QRadioButton>
|
||||
#include <QFile>
|
||||
#include <QLayout>
|
||||
#include <QGridLayout>
|
||||
|
||||
EmoticonsWidget::EmoticonsWidget(QWidget *parent) :
|
||||
QMenu(parent)
|
||||
{
|
||||
QFile f(":/ui/emoticonWidget/emoticonWidget.css");
|
||||
f.open(QFile::ReadOnly | QFile::Text);
|
||||
QString pageButtonCss = f.readAll();
|
||||
setStyleSheet(pageButtonCss);
|
||||
|
||||
setLayout(&layout);
|
||||
layout.addWidget(&stack);
|
||||
|
||||
QWidget* pageButtonsContainer = new QWidget;
|
||||
QHBoxLayout* buttonLayout = new QHBoxLayout;
|
||||
pageButtonsContainer->setLayout(buttonLayout);
|
||||
|
||||
layout.addWidget(pageButtonsContainer);
|
||||
|
||||
const int maxCols = 5;
|
||||
const int maxRows = 3;
|
||||
const int itemsPerPage = maxRows * maxCols;
|
||||
|
||||
const QList<QStringList>& emoticons = SmileyPack::getInstance().getEmoticons();
|
||||
int itemCount = emoticons.size();
|
||||
int pageCount = (itemCount / itemsPerPage) + 1;
|
||||
int currPage = 0;
|
||||
int currItem = 0;
|
||||
int row = 0;
|
||||
int col = 0;
|
||||
|
||||
// create pages
|
||||
buttonLayout->addStretch();
|
||||
for (int i = 0; i < pageCount; i++)
|
||||
{
|
||||
QGridLayout* pageLayout = new QGridLayout;
|
||||
pageLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), maxRows, 0);
|
||||
pageLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, maxCols);
|
||||
|
||||
QWidget* page = new QWidget;
|
||||
page->setLayout(pageLayout);
|
||||
stack.addWidget(page);
|
||||
|
||||
QRadioButton* pageButton = new QRadioButton;
|
||||
pageButton->setProperty("pageIndex", i);
|
||||
pageButton->setChecked(i == 0);
|
||||
buttonLayout->addWidget(pageButton);
|
||||
|
||||
connect(pageButton, &QRadioButton::clicked, this, &EmoticonsWidget::onPageButtonClicked);
|
||||
}
|
||||
buttonLayout->addStretch();
|
||||
|
||||
for (const QStringList& set : emoticons)
|
||||
{
|
||||
QPushButton* button = new QPushButton;
|
||||
button->setIcon(SmileyPack::getInstance().getAsIcon(set[0]));
|
||||
button->setToolTip(set.join(" "));
|
||||
button->setProperty("sequence", set[0]);
|
||||
button->setFlat(true);
|
||||
|
||||
connect(button, &QPushButton::clicked, this, &EmoticonsWidget::onSmileyClicked);
|
||||
|
||||
qobject_cast<QGridLayout*>(stack.widget(currPage)->layout())->addWidget(button, row, col);
|
||||
|
||||
col++;
|
||||
currItem++;
|
||||
|
||||
// next row
|
||||
if (col >= maxCols)
|
||||
{
|
||||
col = 0;
|
||||
row++;
|
||||
}
|
||||
|
||||
// next page
|
||||
if (currItem >= itemsPerPage)
|
||||
{
|
||||
row = 0;
|
||||
currItem = 0;
|
||||
currPage++;
|
||||
}
|
||||
}
|
||||
|
||||
// calculates sizeHint
|
||||
layout.activate();
|
||||
}
|
||||
|
||||
void EmoticonsWidget::onSmileyClicked()
|
||||
{
|
||||
// hide the QMenu
|
||||
QMenu::hide();
|
||||
|
||||
// emit insert emoticon
|
||||
QWidget* sender = qobject_cast<QWidget*>(QObject::sender());
|
||||
if (sender)
|
||||
emit insertEmoticon(' ' + sender->property("sequence").toString() + ' ');
|
||||
}
|
||||
|
||||
void EmoticonsWidget::onPageButtonClicked()
|
||||
{
|
||||
QWidget* sender = qobject_cast<QRadioButton*>(QObject::sender());
|
||||
if (sender)
|
||||
{
|
||||
int page = sender->property("pageIndex").toInt();
|
||||
stack.setCurrentIndex(page);
|
||||
}
|
||||
}
|
||||
|
||||
QSize EmoticonsWidget::sizeHint() const
|
||||
{
|
||||
return layout.sizeHint();
|
||||
}
|
45
widget/emoticonswidget.h
Normal file
45
widget/emoticonswidget.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
This program is libre 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 COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef EMOTICONSWIDGET_H
|
||||
#define EMOTICONSWIDGET_H
|
||||
|
||||
#include <QMenu>
|
||||
#include <QStackedWidget>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
class EmoticonsWidget : public QMenu
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit EmoticonsWidget(QWidget *parent = 0);
|
||||
|
||||
signals:
|
||||
void insertEmoticon(QString str);
|
||||
|
||||
private slots:
|
||||
void onSmileyClicked();
|
||||
void onPageButtonClicked();
|
||||
|
||||
private:
|
||||
QStackedWidget stack;
|
||||
QVBoxLayout layout;
|
||||
|
||||
public:
|
||||
virtual QSize sizeHint() const;
|
||||
};
|
||||
|
||||
#endif // EMOTICONSWIDGET_H
|
|
@ -20,6 +20,7 @@
|
|||
#include "widget/friendwidget.h"
|
||||
#include "widget/widget.h"
|
||||
#include "widget/filetransfertwidget.h"
|
||||
#include "widget/emoticonswidget.h"
|
||||
#include <QFont>
|
||||
#include <QTime>
|
||||
#include <QScrollBar>
|
||||
|
@ -176,10 +177,10 @@ ChatForm::ChatForm(Friend* chatFriend)
|
|||
sendButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
fileButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
emoteButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
// callButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
// videoButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
// msgEdit->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
// chatArea->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
// callButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
// videoButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
// msgEdit->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
// chatArea->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
|
||||
connect(Widget::getInstance()->getCore(), &Core::fileSendStarted, this, &ChatForm::startFileSend);
|
||||
connect(Widget::getInstance()->getCore(), &Core::videoFrameReceived, netcam, &NetCamView::updateDisplay);
|
||||
|
@ -313,7 +314,7 @@ void ChatForm::onSliderRangeChanged()
|
|||
{
|
||||
QScrollBar* scroll = chatArea->verticalScrollBar();
|
||||
if (lockSliderToBottom)
|
||||
scroll->setValue(scroll->maximum());
|
||||
scroll->setValue(scroll->maximum());
|
||||
}
|
||||
|
||||
void ChatForm::startFileSend(ToxFile file)
|
||||
|
@ -658,50 +659,23 @@ void ChatForm::onSaveLogClicked()
|
|||
|
||||
void ChatForm::onEmoteButtonClicked()
|
||||
{
|
||||
QList<QStringList> emoticons = SmileyPack::getInstance().getEmoticons();
|
||||
|
||||
QMenu menu;
|
||||
QGridLayout* gridLayout = new QGridLayout;
|
||||
menu.setLayout(gridLayout);
|
||||
|
||||
int colCount = sqrt(emoticons.size()) + 1;
|
||||
int row = 0;
|
||||
int col = 0;
|
||||
for (const QStringList& set : emoticons)
|
||||
{
|
||||
QPushButton* button = new QPushButton;
|
||||
button->setIcon(SmileyPack::getInstance().getAsIcon(set[0]));
|
||||
button->setToolTip(set.join(" "));
|
||||
button->setProperty("sequence", set[0]);
|
||||
connect(button, &QPushButton::clicked, this, &ChatForm::onAddEmote);
|
||||
|
||||
gridLayout->addWidget(button, row, ++col);
|
||||
if (col >= colCount)
|
||||
{
|
||||
col = 0;
|
||||
row++;
|
||||
}
|
||||
}
|
||||
EmoticonsWidget widget;
|
||||
connect(&widget, &EmoticonsWidget::insertEmoticon, this, &ChatForm::onEmoteInsertRequested);
|
||||
|
||||
QWidget* sender = qobject_cast<QWidget*>(QObject::sender());
|
||||
if (sender)
|
||||
{
|
||||
QPoint pos(gridLayout->totalSizeHint().width() / 2, gridLayout->totalSizeHint().height());
|
||||
menu.exec(sender->mapToGlobal(-pos));
|
||||
QPoint pos(widget.sizeHint().width() / 2, widget.sizeHint().height());
|
||||
widget.exec(sender->mapToGlobal(-pos - QPoint(0, 10)));
|
||||
}
|
||||
}
|
||||
|
||||
void ChatForm::onAddEmote()
|
||||
void ChatForm::onEmoteInsertRequested(QString str)
|
||||
{
|
||||
// hide the QMenu
|
||||
QMenu* menu = qobject_cast<QMenu*>(QObject::sender()->parent());
|
||||
if (menu)
|
||||
menu->hide();
|
||||
|
||||
// insert the emoticon
|
||||
QWidget* sender = qobject_cast<QWidget*>(QObject::sender());
|
||||
if (sender)
|
||||
msgEdit->insertPlainText(' ' + sender->property("sequence").toString() + ' ');
|
||||
msgEdit->insertPlainText(str);
|
||||
|
||||
msgEdit->setFocus(); // refocus so that you can continue typing
|
||||
msgEdit->setFocus(); // refocus so that we can continue typing
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ private slots:
|
|||
void onChatContextMenuRequested(QPoint pos);
|
||||
void onSaveLogClicked();
|
||||
void onEmoteButtonClicked();
|
||||
void onAddEmote();
|
||||
void onEmoteInsertRequested(QString str);
|
||||
|
||||
private:
|
||||
Friend* f;
|
||||
|
|
|
@ -54,7 +54,7 @@ SettingsForm::SettingsForm()
|
|||
makeToxPortable.setToolTip(tr("Save settings to the working directory instead of the usual conf dir","describes makeToxPortable checkbox"));
|
||||
|
||||
smileyPackLabel.setText(tr("Smiley Pack", "Text on smiley pack label"));
|
||||
for (auto entry : SmileyPack::listSmileyPacks("./smileys"))
|
||||
for (auto entry : SmileyPack::listSmileyPacks())
|
||||
smileyPackBrowser.addItem(entry.first, entry.second);
|
||||
smileyPackBrowser.setCurrentIndex(smileyPackBrowser.findData(Settings::getInstance().getSmileyPack()));
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user