Skip to content

Commit

Permalink
T1Wrench.pro: add a t1wrench.h for some function definitions
Browse files Browse the repository at this point in the history
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
baohaojun committed Nov 24, 2014
1 parent 50fddf0 commit bfd2f2b
Show file tree
Hide file tree
Showing 16 changed files with 1,521 additions and 15 deletions.
12 changes: 9 additions & 3 deletions T1Wrench.pro
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ SOURCES += main.cpp\
screencapture.cpp \
painterwidget.cpp \
painterrectitem.cpp \
painterpathitem.cpp
painterpathitem.cpp \
dialoggetemoji.cpp \
emojimodel.cpp

HEADERS += t1wrenchmainwindow.h \
adbstatethread.hpp \
Expand All @@ -44,9 +46,13 @@ HEADERS += t1wrenchmainwindow.h \
painterwidget.h \
painteritem.h \
painterrectitem.h \
painterpathitem.h
painterpathitem.h \
dialoggetemoji.h \
emojimodel.h \
t1wrench.h

FORMS += t1wrenchmainwindow.ui
FORMS += t1wrenchmainwindow.ui \
dialoggetemoji.ui

RESOURCES += \
T1Wrench.qrc
8 changes: 7 additions & 1 deletion build-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ rsync -L $(which the-true-adb) ~/src/github/T1Wrench-linux
smb-push T1Wrench-linux.tgz ~/smb/share.smartisan.cn/share/baohaojun/T1Wrench
rsync T1Wrench-linux.tgz rem:/var/www/html/baohaojun/
)&
./T1Wrench
if test $# = 1 -a "$1" = debug; then
ps-killall gdb.T1Wrench
myscr gdb ./T1Wrench
find-or-exec konsole
else
./T1Wrench
fi
31 changes: 31 additions & 0 deletions dialoggetemoji.cpp
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);
}
32 changes: 32 additions & 0 deletions dialoggetemoji.h
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
96 changes: 96 additions & 0 deletions dialoggetemoji.ui
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>
131 changes: 131 additions & 0 deletions emojimodel.cpp
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 "";
}
38 changes: 38 additions & 0 deletions emojimodel.h
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
Loading

0 comments on commit bfd2f2b

Please sign in to comment.