Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
GaZaTu committed Oct 20, 2020
0 parents commit 00461a2
Show file tree
Hide file tree
Showing 3,376 changed files with 4,387 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
11 changes: 11 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
AlignAfterOpenBracket: DontAlign
AlignEscapedNewlines: Left
AlignOperands: 'false'
AlwaysBreakTemplateDeclarations: 'Yes'
ColumnLimit: 120
PointerAlignment: 'Left'
AllowShortFunctionsOnASingleLine: 'false'
AllowShortLambdasOnASingleLine: 'false'

...
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.sh]
end_of_line = lf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
11 changes: 11 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"configurations": [
{
"name": "Linux",
"intelliSenseMode": "gcc-x64",
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
35 changes: 35 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
// Resolved by CMake Tools:
"program": "${command:cmake.launchTargetPath}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{
// add the directory where our target was built to the PATHs
// it gets resolved by CMake Tools:
"name": "PATH",
"value": "$PATH:${command:cmake.launchTargetDirectory}"
}
],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
56 changes: 56 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"files.associations": {
"string": "cpp",
"cwchar": "cpp",
"iostream": "cpp",
"qapplication": "cpp",
"qpushbutton": "cpp",
"qtextedit": "cpp",
"qvboxlayout": "cpp",
"ostream": "cpp",
"array": "cpp",
"atomic": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"fstream": "cpp",
"functional": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numeric": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"system_error": "cpp",
"cinttypes": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"typeinfo": "cpp",
"cstddef": "cpp",
"algorithm": "cpp",
"iterator": "cpp",
"map": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"random": "cpp",
"qlabel": "cpp",
"qgridlayout": "cpp",
"qmainwindow": "cpp"
},
"cmake.sourceDirectory": "${workspaceFolder}/."
}
54 changes: 54 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
set(CMAKE_C_COMPILER "gcc-6")
set(CMAKE_CXX_COMPILER "g++-6")

cmake_minimum_required(VERSION 3.0.0)
project(emoji-picker VERSION 0.1.0)

include(CTest)
enable_testing()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

find_package(Qt5 REQUIRED COMPONENTS Widgets Core Gui)

find_library(ICU_UC_LIB icuuc REQUIRED)
add_library(ICU_UC SHARED IMPORTED)
set_target_properties(ICU_UC PROPERTIES
IMPORTED_LOCATION ${ICU_UC_LIB}
)

find_library(XDOTOOL_LIB xdo REQUIRED)
add_library(XDOTOOL SHARED IMPORTED)
set_target_properties(XDOTOOL PROPERTIES
IMPORTED_LOCATION ${XDOTOOL_LIB}
)

add_executable(emoji-picker
src/main.cpp
src/main.qrc
src/EmojiLineEdit.cpp
src/EmojiLineEdit.hpp
src/EmojiLabel.cpp
src/EmojiLabel.hpp
src/EmojiPicker.cpp
src/EmojiPicker.hpp
)

target_link_libraries(emoji-picker
Qt5::Core
Qt5::Gui
Qt5::Widgets
ICU_UC
XDOTOOL
)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

include(CPack)
51 changes: 51 additions & 0 deletions src/EmojiLabel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "EmojiLabel.hpp"
#include <sstream>
#include <unicode/schriter.h>
#include <unicode/unistr.h>

EmojiLabel::EmojiLabel(QWidget* parent) : QLabel(parent) {
}

EmojiLabel::EmojiLabel(QWidget* parent, const std::string& emojiStr) : EmojiLabel(parent) {
setEmojiStr(emojiStr);
}

// fdm `:/res/72x72/${[...emojiStr].map(c => c.toString(16)).join('-')}.png`
std::string getPixmapPathByEmojiStr(const std::string& emojiStr) {
std::stringstream emojiHexCodeStream;

emojiHexCodeStream << ":/res/72x72/";

bool firstCodepoint = true;
icu::UnicodeString emojiUStr(emojiStr.data(), emojiStr.length(), "utf-8");
icu::StringCharacterIterator emojiUStrIterator(emojiUStr);
while (emojiUStrIterator.hasNext()) {
UChar32 codepoint = emojiUStrIterator.next32PostInc();

if (firstCodepoint) {
firstCodepoint = false;
} else {
emojiHexCodeStream << "-";
}

emojiHexCodeStream << std::hex << codepoint;
}

emojiHexCodeStream << ".png";

return emojiHexCodeStream.str();
}

QPixmap getPixmapByEmojiStr(const std::string& emojiStr) {
return QPixmap(QString::fromStdString(getPixmapPathByEmojiStr(emojiStr)), "PNG");
}

const std::string& EmojiLabel::emojiStr() {
return _emojiStr;
}
void EmojiLabel::setEmojiStr(const std::string& emojiStr) {
_emojiStr = emojiStr;

setAccessibleName(QString::fromStdString(emojiStr));
setPixmap(getPixmapByEmojiStr(_emojiStr).scaled(24, 24, Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
17 changes: 17 additions & 0 deletions src/EmojiLabel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <QLabel>

class EmojiLabel : public QLabel {
Q_OBJECT

public:
explicit EmojiLabel(QWidget* parent = nullptr);
explicit EmojiLabel(QWidget* parent, const std::string& emojiStr);

const std::string& emojiStr();
void setEmojiStr(const std::string& emojiStr);

private:
std::string _emojiStr;
};
16 changes: 16 additions & 0 deletions src/EmojiLineEdit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "EmojiLineEdit.hpp"

EmojiLineEdit::EmojiLineEdit(QWidget* parent) : QLineEdit(parent) {
}

void EmojiLineEdit::keyPressEvent(QKeyEvent* event) {
if (event->key() == Qt::Key_Escape) {
emit escapePressed();
} else if (event->key() == Qt::Key_Up || event->key() == Qt::Key_Down || event->key() == Qt::Key_Left ||
event->key() == Qt::Key_Right) {
emit arrowKeyPressed(event->key());
} else {
// default handler for event
QLineEdit::keyPressEvent(event);
}
}
18 changes: 18 additions & 0 deletions src/EmojiLineEdit.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <QKeyEvent>
#include <QLineEdit>

class EmojiLineEdit : public QLineEdit {
Q_OBJECT

public:
explicit EmojiLineEdit(QWidget* parent = nullptr);

Q_SIGNALS:
void arrowKeyPressed(int key);
void escapePressed();

protected:
void keyPressEvent(QKeyEvent* event) override;
};
Loading

0 comments on commit 00461a2

Please sign in to comment.