forked from SmartisanTech/Wrench
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
T1Wrench.pro: add a t1wrench.h for some function definitions
build-linux.sh: use gdb to debug build-linux.sh: do gdb with t1wrench dialoggetemoji.cpp: add emoji filter support dialoggetemoji.cpp: can do emoji now dialoggetemoji.h: add emoji dialoggetemoji.h: can choose emoji now dialoggetemoji.ui: add emoji emojimodel.cpp: can do emoji emojimodel.cpp: can do emoji emojimodel.h: emoji emojis.lua: emoji main.cpp: try to use qtextedit qcellphonetextedit.cpp: use qtextedit qcellphonetextedit.cpp: can do emoji now qcellphonetextedit.h: can do emoji now t1wrench.lua: can do emoji now t1wrenchmainwindow.cpp: can do emoji t1wrenchmainwindow.cpp: emoji t1wrenchmainwindow.h: emoji Signed-off-by: Bao Haojun <[email protected]>
- Loading branch information
Showing
16 changed files
with
1,521 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "dialoggetemoji.h" | ||
#include "ui_dialoggetemoji.h" | ||
#include "emojimodel.h" | ||
|
||
DialogGetEmoji::DialogGetEmoji(QWidget *parent) : | ||
QDialog(parent), | ||
ui(new Ui::DialogGetEmoji) | ||
{ | ||
ui->setupUi(this); | ||
ui->emojiFilter->setFocus(); | ||
mEmojiModel = new EmojiModel(0); | ||
ui->emojiListView->setModel(mEmojiModel); | ||
} | ||
|
||
DialogGetEmoji::~DialogGetEmoji() | ||
{ | ||
delete ui; | ||
} | ||
|
||
void DialogGetEmoji::on_emojiFilter_textChanged() | ||
{ | ||
mEmojiModel->setFilter(ui->emojiFilter->toPlainText()); | ||
} | ||
|
||
void DialogGetEmoji::on_emojiListView_doubleClicked(const QModelIndex &index) | ||
{ | ||
int row = index.row(); | ||
QString emoji = mEmojiModel->getEmojiText(row); | ||
QString emojiPath = mEmojiModel->getEmojiPath(row); | ||
emit emojiSelected(emoji, emojiPath); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#ifndef DIALOGGETEMOJI_H | ||
#define DIALOGGETEMOJI_H | ||
|
||
#include <QDialog> | ||
#include "emojimodel.h" | ||
|
||
namespace Ui { | ||
class DialogGetEmoji; | ||
} | ||
|
||
class DialogGetEmoji : public QDialog | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit DialogGetEmoji(QWidget *parent = 0); | ||
~DialogGetEmoji(); | ||
|
||
private slots: | ||
void on_emojiFilter_textChanged(); | ||
|
||
void on_emojiListView_doubleClicked(const QModelIndex &index); | ||
signals: | ||
void emojiSelected(const QString&, const QString&); | ||
|
||
private: | ||
Ui::DialogGetEmoji *ui; | ||
|
||
EmojiModel* mEmojiModel; | ||
}; | ||
|
||
#endif // DIALOGGETEMOJI_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>DialogGetEmoji</class> | ||
<widget class="QDialog" name="DialogGetEmoji"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>400</width> | ||
<height>394</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Dialog</string> | ||
</property> | ||
<widget class="QDialogButtonBox" name="buttonBox"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>30</x> | ||
<y>350</y> | ||
<width>341</width> | ||
<height>32</height> | ||
</rect> | ||
</property> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="standardButtons"> | ||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> | ||
</property> | ||
</widget> | ||
<widget class="QWidget" name="verticalLayoutWidget"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>10</x> | ||
<y>59</y> | ||
<width>381</width> | ||
<height>291</height> | ||
</rect> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<widget class="QListView" name="emojiListView"/> | ||
</item> | ||
</layout> | ||
</widget> | ||
<widget class="QPlainTextEdit" name="emojiFilter"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>10</x> | ||
<y>10</y> | ||
<width>377</width> | ||
<height>31</height> | ||
</rect> | ||
</property> | ||
<property name="placeholderText"> | ||
<string>表情过滤</string> | ||
</property> | ||
</widget> | ||
</widget> | ||
<resources/> | ||
<connections> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>accepted()</signal> | ||
<receiver>DialogGetEmoji</receiver> | ||
<slot>accept()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>248</x> | ||
<y>254</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>157</x> | ||
<y>274</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>rejected()</signal> | ||
<receiver>DialogGetEmoji</receiver> | ||
<slot>reject()</slot> | ||
<hints> | ||
<hint type="sourcelabel"> | ||
<x>316</x> | ||
<y>260</y> | ||
</hint> | ||
<hint type="destinationlabel"> | ||
<x>286</x> | ||
<y>274</y> | ||
</hint> | ||
</hints> | ||
</connection> | ||
</connections> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#include "emojimodel.h" | ||
#include <QDebug> | ||
#include <QFont> | ||
#include <QBrush> | ||
#include <lua.hpp> | ||
|
||
EmojiModel::EmojiModel(QObject *parent) : | ||
QAbstractListModel(parent) | ||
{ | ||
L = luaL_newstate(); /* opens Lua */ | ||
luaL_openlibs(L); /* opens the standard libraries */ | ||
|
||
int error = luaL_loadstring(L, "emojis = require('emojis')") || lua_pcall(L, 0, 0, 0); | ||
if (error) { | ||
qDebug() << "Error loading emojis: " << lua_tolstring(L, -1, NULL); | ||
return; | ||
} | ||
|
||
lua_getglobal(L, "emojis"); | ||
int n = luaL_len(L, 1); | ||
for (int i = 1; i <= n; i++) { | ||
lua_rawgeti(L, -1, i); | ||
|
||
lua_rawgeti(L, -1, 1); | ||
QString text = lua_tolstring(L, -1, NULL); | ||
lua_settop(L, -2); | ||
|
||
lua_rawgeti(L, -1, 2); | ||
QString key = lua_tolstring(L, -1, NULL); | ||
key = key.sprintf("%04d %s", i, qPrintable(key)); | ||
lua_settop(L, -2); | ||
|
||
lua_rawgeti(L, -1, 3); | ||
QString pngPath = lua_tolstring(L, -1, NULL); | ||
lua_settop(L, 1); // finished with this small table | ||
|
||
mEmojiTextMap[key] = text; | ||
mEmojiIconPathMap[key] = pngPath; | ||
mKeyMap[i - 1] = key; | ||
} | ||
lua_settop(L, 0); | ||
setFilter(""); | ||
} | ||
|
||
int EmojiModel::rowCount(const QModelIndex & /*parent */) const | ||
{ | ||
return mFilteredKeys.length(); | ||
} | ||
|
||
//! [Quoting ModelView Tutorial] | ||
// mymodel.cpp | ||
QVariant EmojiModel::data(const QModelIndex &index, int role) const | ||
{ | ||
int row = index.row(); | ||
|
||
switch(role) { | ||
case Qt::DisplayRole: | ||
return mFilteredKeys[row]; | ||
break; | ||
case Qt::DecorationRole: | ||
if (1) { // for the key declaration | ||
if (row >= mFilteredKeys.size()) | ||
return QVariant(); | ||
QString key = mFilteredKeys[row]; | ||
if (!mEmojiIconMap.contains(key)) { | ||
const_cast<EmojiModel*>(this)->mEmojiIconMap[key] = QPixmap(mEmojiIconPathMap[key]); | ||
} | ||
return mEmojiIconMap[key]; | ||
} | ||
} | ||
return QVariant(); | ||
} | ||
|
||
void EmojiModel::setFilter(QString filter) | ||
{ | ||
mFilter = filter; | ||
int error = luaL_loadstring(L, "t1wrench = require('t1wrench')") || lua_pcall(L, 0, 0, 0); | ||
lua_getglobal(L, "t1wrench"); | ||
lua_getfield(L, -1, "split"); | ||
lua_pushstring(L, " "); | ||
lua_pushstring(L, mFilter.toUtf8().constData()); | ||
error = lua_pcall(L, 2, 1, 0); | ||
if (error) { | ||
qDebug() << "Error calling split:" << lua_tolstring(L, -1, NULL); | ||
return; | ||
} | ||
int nOldRows = mFilteredKeys.length(); | ||
mFilteredKeys.clear(); | ||
|
||
QStringList split; | ||
int n = luaL_len(L, -1); | ||
for (int i = 1; i <= n; i++) { | ||
lua_rawgeti(L, -1, i); | ||
split << lua_tolstring(L, -1, NULL); | ||
lua_settop(L, -2); | ||
} | ||
lua_settop(L, 0); | ||
|
||
for (int i = 0; i < mKeyMap.size(); i++) { | ||
bool match = 1; | ||
foreach(const QString& stem, split) { | ||
if (mKeyMap[i].indexOf(stem, 0, Qt::CaseInsensitive) < 0) { | ||
match = 0; | ||
break; | ||
} | ||
} | ||
if (match) { | ||
mFilteredKeys << mKeyMap[i]; | ||
} | ||
} | ||
|
||
this->dataChanged(index(0, 0), index(nOldRows, 0)); | ||
} | ||
|
||
QString EmojiModel::getEmojiText(int i) | ||
{ | ||
if (i >= 0 && i < mFilteredKeys.length()) { | ||
QString key = mFilteredKeys[i]; | ||
return mEmojiTextMap[key]; | ||
} | ||
return ""; | ||
} | ||
|
||
QString EmojiModel::getEmojiPath(int i) | ||
{ | ||
if (i >= 0 && i < mFilteredKeys.length()) { | ||
QString key = mFilteredKeys[i]; | ||
return mEmojiIconPathMap[key]; | ||
} | ||
return ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#ifndef EMOJIMODEL_H | ||
#define EMOJIMODEL_H | ||
|
||
#include <QAbstractTableModel> | ||
#include <QAbstractListModel> | ||
#include <QMap> | ||
#include <QPixmap> | ||
#include <QSharedPointer> | ||
#include <lua.hpp> | ||
|
||
class EmojiModel : public QAbstractListModel | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit EmojiModel(QObject *parent = 0); | ||
int rowCount(const QModelIndex &parent = QModelIndex()) const ; | ||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; | ||
void setFilter(QString filter); | ||
|
||
private: | ||
QString mFilter; | ||
QMap<QString, QString> mEmojiTextMap; | ||
QMap<QString, QString> mEmojiIconPathMap; | ||
QMap<QString, QPixmap> mEmojiIconMap; | ||
QMap<int, QString> mKeyMap; | ||
QStringList mFilteredKeys; | ||
lua_State *L; | ||
|
||
public: | ||
QString getEmojiText(int i); | ||
QString getEmojiPath(int i); | ||
signals: | ||
|
||
public slots: | ||
|
||
}; | ||
|
||
#endif // EMOJIMODEL_H |
Oops, something went wrong.