Fix correct indent style

This commit is contained in:
Angela Mazzurco 2017-09-06 18:48:51 +02:00
parent 79f09f14ac
commit efd14e4465
3 changed files with 90 additions and 45 deletions

View File

@ -1,12 +1,14 @@
import QtQuick 2.7 import QtQuick 2.7
import QtQuick.Controls.Styles 1.2 import QtQuick.Controls.Styles 1.2
Rectangle { Rectangle
{
id: emojiButton id: emojiButton
property var fontName property var fontName
Text { Text
{
id: emojiText id: emojiText
color: "gray" color: "gray"
text: qsTr(eCatText) text: qsTr(eCatText)
@ -17,17 +19,22 @@ Rectangle {
state: "RELEASED" state: "RELEASED"
states: [ states:
State { [
State
{
name: "PRESSED" name: "PRESSED"
PropertyChanges { PropertyChanges
{
target: emojiText target: emojiText
font.pixelSize: emojiButton.width - 10 font.pixelSize: emojiButton.width - 10
} }
}, },
State { State
{
name: "RELEASED" name: "RELEASED"
PropertyChanges { PropertyChanges
{
target: emojiText target: emojiText
font.pixelSize: emojiButton.width - 8 font.pixelSize: emojiButton.width - 8
} }
@ -35,20 +42,25 @@ Rectangle {
] ]
MouseArea { MouseArea
{
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
onEntered: { onEntered:
{
emojiText.color = "black" emojiText.color = "black"
} }
onExited: { onExited:
{
emojiText.color = "gray" emojiText.color = "gray"
} }
onPressedChanged: { onPressedChanged:
{
emojiButton.state = emojiButton.state == "PRESSED" ? "RELEASED" : "PRESSED" emojiButton.state = emojiButton.state == "PRESSED" ? "RELEASED" : "PRESSED"
} }
onClicked: { onClicked:
{
Qt.emojiClickedHandler(emojiText.text) Qt.emojiClickedHandler(emojiText.text)
} }
} }

View File

@ -1,30 +1,37 @@
import QtQuick 2.7 import QtQuick 2.7
import QtQuick.Controls.Styles 1.2 import QtQuick.Controls.Styles 1.2
Rectangle { Rectangle
{
id: emojiCategoryButton id: emojiCategoryButton
property string categoryName property string categoryName
property var fontName property var fontName
function completedHandler() { function completedHandler()
{
categoryName = eCatName categoryName = eCatName
//initialize //initialize
if (parent.currSelEmojiButton === undefined) { if (parent.currSelEmojiButton === undefined)
{
clickedHandler() clickedHandler()
} }
} }
function pressedHandler() { function pressedHandler()
if (state != "SELECTED") { {
if (state != "SELECTED")
{
state = state == "PRESSED" ? "RELEASED" : "PRESSED" state = state == "PRESSED" ? "RELEASED" : "PRESSED"
} }
} }
function clickedHandler() { function clickedHandler()
if (parent.currSelEmojiButton !== undefined) { {
if (parent.currSelEmojiButton !== undefined)
{
parent.currSelEmojiButton.state = "RELEASED" parent.currSelEmojiButton.state = "RELEASED"
} }
@ -34,7 +41,8 @@ Rectangle {
} }
Text { Text
{
id: emojiText id: emojiText
color: "gray" color: "gray"
text: qsTr(eCatText) text: qsTr(eCatText)
@ -45,31 +53,39 @@ Rectangle {
state: "RELEASED" state: "RELEASED"
states: [ states:
State { [
State
{
name: "PRESSED" name: "PRESSED"
PropertyChanges { PropertyChanges
{
target: emojiText target: emojiText
font.pixelSize: emojiCategoryButton.width - 10 font.pixelSize: emojiCategoryButton.width - 10
} }
}, },
State { State
{
name: "RELEASED" name: "RELEASED"
PropertyChanges { PropertyChanges
{
target: emojiText target: emojiText
font.pixelSize: emojiCategoryButton.width - 8 font.pixelSize: emojiCategoryButton.width - 8
} }
}, },
State { State
{
name: "SELECTED" name: "SELECTED"
PropertyChanges { PropertyChanges
{
target: emojiCategoryButton target: emojiCategoryButton
color: "#ADD6FF" color: "#ADD6FF"
} }
} }
] ]
MouseArea { MouseArea
{
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
onEntered: emojiText.color = "black" onEntered: emojiText.color = "black"

View File

@ -2,7 +2,8 @@ import QtQuick 2.7
import QtQuick.Controls 2.0 import QtQuick.Controls 2.0
import "emoji.js" as EmojiJSON import "emoji.js" as EmojiJSON
Rectangle { Rectangle
{
id: emojiPicker id: emojiPicker
property EmojiCategoryButton currSelEmojiButton property EmojiCategoryButton currSelEmojiButton
property variant emojiParsedJson property variant emojiParsedJson
@ -12,23 +13,27 @@ Rectangle {
property var rootFontName: theme.emojiFontName property var rootFontName: theme.emojiFontName
//displays all Emoji of one categroy by modifying the ListModel of emojiGrid //displays all Emoji of one categroy by modifying the ListModel of emojiGrid
function categoryChangedHandler (newCategoryName){ function categoryChangedHandler (newCategoryName)
{
emojiByCategory.clear() emojiByCategory.clear()
for (var i = 0; i < emojiParsedJson.emoji_by_category[newCategoryName].length; i++) { for (var i = 0; i < emojiParsedJson.emoji_by_category[newCategoryName].length; i++)
{
var elem = emojiParsedJson.emoji_by_category[newCategoryName][i] var elem = emojiParsedJson.emoji_by_category[newCategoryName][i]
emojiByCategory.append({eCatName: newCategoryName, eCatText: elem}) emojiByCategory.append({eCatName: newCategoryName, eCatText: elem})
} }
} }
//adds the clicked Emoji (and one ' ' if the previous character isn't an Emoji) to textArea //adds the clicked Emoji (and one ' ' if the previous character isn't an Emoji) to textArea
function emojiClickedHandler(selectedEmoji) { function emojiClickedHandler(selectedEmoji)
{
var strAppnd = "" var strAppnd = ""
var plainText = textArea.getText(0, textArea.length) var plainText = textArea.getText(0, textArea.length)
if (plainText.length > 0) { if (plainText.length > 0) {
var lastChar = plainText[plainText.length-1] var lastChar = plainText[plainText.length-1]
if ((lastChar !== ' ') && (lastChar.charCodeAt(0) < 255)) { if ((lastChar !== ' ') && (lastChar.charCodeAt(0) < 255))
{
strAppnd = " " strAppnd = " "
} }
} }
@ -38,10 +43,12 @@ Rectangle {
} }
//parses JSON, publishes button handlers and inits textArea //parses JSON, publishes button handlers and inits textArea
function completedHandler() { function completedHandler()
{
// emojiParsedJson = JSON.parse(EmojiJSON.emoji_json) // emojiParsedJson = JSON.parse(EmojiJSON.emoji_json)
emojiParsedJson = EmojiJSON.emoji_json emojiParsedJson = EmojiJSON.emoji_json
for (var i = 0; i < emojiParsedJson.emoji_categories.length; i++) { for (var i = 0; i < emojiParsedJson.emoji_categories.length; i++)
{
var elem = emojiParsedJson.emoji_categories[i] var elem = emojiParsedJson.emoji_categories[i]
emojiCategoryButtons.append({eCatName: elem.name, eCatText: elem.emoji_unified}) emojiCategoryButtons.append({eCatName: elem.name, eCatText: elem.emoji_unified})
} }
@ -56,21 +63,25 @@ Rectangle {
//checks if the previous character is an Emoji and adds a ' ' if that's the case //checks if the previous character is an Emoji and adds a ' ' if that's the case
//this is necessary, because Emoji use a bigger font-size, and that font-size is kept using without a ' ' //this is necessary, because Emoji use a bigger font-size, and that font-size is kept using without a ' '
function keyPressedHandler(event) { function keyPressedHandler(event)
{
var testStr = textArea.getText(textArea.length-2, textArea.length) var testStr = textArea.getText(textArea.length-2, textArea.length)
var ptrn = new RegExp("[\uD800-\uDBFF][\uDC00-\uDFFF]") var ptrn = new RegExp("[\uD800-\uDBFF][\uDC00-\uDFFF]")
if ((event.key !== Qt.Key_Backspace) && (ptrn.test(testStr))) { if ((event.key !== Qt.Key_Backspace) && (ptrn.test(testStr)))
{
textArea.text += " " textArea.text += " "
textArea.cursorPosition = textArea.length textArea.cursorPosition = textArea.length
} }
} }
//all emoji of one category //all emoji of one category
ListModel { ListModel
{
id: emojiByCategory id: emojiByCategory
} }
GridView { GridView
{
id: emojiGrid id: emojiGrid
width: parent.width width: parent.width
anchors.fill: parent anchors.fill: parent
@ -78,7 +89,8 @@ Rectangle {
cellWidth: buttonWidth; cellHeight: buttonWidth cellWidth: buttonWidth; cellHeight: buttonWidth
model: emojiByCategory model: emojiByCategory
delegate: EmojiButton { delegate: EmojiButton
{
width: buttonWidth width: buttonWidth
height: buttonWidth height: buttonWidth
color: emojiPicker.color color: emojiPicker.color
@ -88,13 +100,15 @@ Rectangle {
//seperator //seperator
Rectangle { Rectangle
{
color: emojiPicker.color color: emojiPicker.color
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
width: parent.width width: parent.width
height: buttonWidth height: buttonWidth
} }
Rectangle { Rectangle
{
color: "black" color: "black"
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.bottomMargin: buttonWidth anchors.bottomMargin: buttonWidth
@ -103,14 +117,16 @@ Rectangle {
} }
//emoji category selector //emoji category selector
ListView { ListView
{
width: parent.width width: parent.width
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.bottomMargin: buttonWidth anchors.bottomMargin: buttonWidth
orientation: ListView.Horizontal orientation: ListView.Horizontal
model: emojiCategoryButtons model: emojiCategoryButtons
delegate: EmojiCategoryButton { delegate: EmojiCategoryButton
{
width: buttonWidth width: buttonWidth
height: buttonWidth height: buttonWidth
color: emojiPicker.color color: emojiPicker.color
@ -118,7 +134,8 @@ Rectangle {
} }
} }
ListModel { ListModel
{
id: emojiCategoryButtons id: emojiCategoryButtons
} }