diff --git a/src/activities/baby_wordprocessor/BabyWordprocessor.qml b/src/activities/baby_wordprocessor/BabyWordprocessor.qml index 4be3cbb27..d982be32c 100644 --- a/src/activities/baby_wordprocessor/BabyWordprocessor.qml +++ b/src/activities/baby_wordprocessor/BabyWordprocessor.qml @@ -1,261 +1,258 @@ /* GCompris - baby_wordprocessor.qml * * Copyright (C) 2015 Bruno Coudoin * * Authors: * Bruno Coudoin (GTK+ version) * Bruno Coudoin (Qt Quick port) * * This program is free 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 * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ import QtQuick 2.1 import GCompris 1.0 import QtQuick.Controls 1.0 import "../../core" ActivityBase { id: activity onStart: focus = true onStop: {} pageComponent: Rectangle { id: background anchors.fill: parent color: 'white' signal start signal stop Component.onCompleted: { activity.start.connect(start) } onStart: { keyboard.populate(); edit.forceActiveFocus(); } Column { id: controls - width: 200 * ApplicationInfo.ratio + width: 120 * ApplicationInfo.ratio anchors { right: parent.right top: parent.top bottom: bar.top margins: 10 } spacing: 10 Button { - style: GCButtonStyle {} - height: 30 * ApplicationInfo.ratio - width: parent.width + style: GCButtonStyle { textSize: "title"} text: qsTr("Title") + width: parent.width onClicked: edit.formatLineWith('h2') } Button { - style: GCButtonStyle {} - height: 30 * ApplicationInfo.ratio - width: parent.width + style: GCButtonStyle { textSize: "subtitle"} text: qsTr("Subtitle") + width: parent.width onClicked: edit.formatLineWith('h3') } Button { - style: GCButtonStyle {} - height: 30 * ApplicationInfo.ratio + style: GCButtonStyle { textSize: "regular"} width: parent.width text: qsTr("Paragraph") onClicked: edit.formatLineWith('p') } } Flickable { id: flick anchors { left: parent.left right: controls.left top: parent.top bottom: bar.top margins: 10 } contentWidth: edit.paintedWidth contentHeight: edit.paintedHeight clip: true flickableDirection: Flickable.VerticalFlick function ensureVisible(r) { if (contentX >= r.x) contentX = r.x; else if (contentX+width <= r.x+r.width) contentX = r.x+r.width-width; if (contentY >= r.y) contentY = r.y; else if (contentY+height <= r.y+r.height) contentY = r.y+r.height-height; } TextEdit { id: edit width: flick.width height: flick.height focus: true wrapMode: TextEdit.Wrap onCursorRectangleChanged: flick.ensureVisible(cursorRectangle) textFormat: TextEdit.RichText font { pointSize: (18 + ApplicationSettings.baseFontSize) * ApplicationInfo.fontRatio capitalization: ApplicationSettings.fontCapitalization weight: Font.DemiBold family: GCSingletonFontLoader.fontLoader.name letterSpacing: ApplicationSettings.fontLetterSpacing wordSpacing: 10 } cursorDelegate: Rectangle { id: cursor width: 10 // height should be set automatically as mention in cursorRectangle property // documentation but it does not work height: parent.cursorRectangle.height color: 'red' SequentialAnimation on opacity { running: true loops: Animation.Infinite PropertyAnimation { to: 0.2 duration: 1000 } PropertyAnimation { to: 1 duration: 1000 } } } function insertText(text) { edit.insert(cursorPosition, text) } function backspace() { if(cursorPosition > 0) { moveCursorSelection(cursorPosition - 1, TextEdit.SelectCharacters) cut() } } function formatLineWith(tag) { var text = getText(0, length) var initialPosition = cursorPosition var first = cursorPosition - 1 for(; first >= 0; first--) { if(text.charCodeAt(first) === 8233) break } first++ var last = cursorPosition for(; last < text.length; last++) { if(text.charCodeAt(last) === 8233) break } var line = getText(first, last) remove(first, last) insert(first, '<' + tag + '>' + line + '') cursorPosition = initialPosition } } } DialogHelp { id: dialogHelp onClose: home() } Bar { id: bar anchors.bottom: keyboard.top content: BarEnumContent { value: help | home | reload } onHelpClicked: { displayDialog(dialogHelp) } onHomeClicked: activity.home() onReloadClicked: edit.text = '' } VirtualKeyboard { id: keyboard anchors.bottom: parent.bottom anchors.horizontalCenter: parent.horizontalCenter width: parent.width visible: ApplicationSettings.isVirtualKeyboard && !ApplicationInfo.isMobile onKeypress: { if(text == backspace) edit.backspace() else edit.insertText(text) } onError: console.log("VirtualKeyboard error: " + msg); function populate() { layout = [ [ { label: "0" }, { label: "1" }, { label: "2" }, { label: "3" }, { label: "4" }, { label: "5" }, { label: "6" }, { label: "7" }, { label: "8" }, { label: "9" } ], [ { label: "A" }, { label: "B" }, { label: "C" }, { label: "D" }, { label: "E" }, { label: "F" }, { label: "G" }, { label: "H" }, { label: "I" } ], [ { label: "J" }, { label: "K" }, { label: "L" }, { label: "M" }, { label: "N" }, { label: "O" }, { label: "P" }, { label: "Q" }, { label: "R" } ], [ { label: "S" }, { label: "T" }, { label: "U" }, { label: "V" }, { label: "W" }, { label: "X" }, { label: "Y" }, { label: "Z" }, { label: " " }, { label: backspace } ] ] } } } } diff --git a/src/core/GCButtonStyle.qml b/src/core/GCButtonStyle.qml index acb21564e..e9a9bc709 100644 --- a/src/core/GCButtonStyle.qml +++ b/src/core/GCButtonStyle.qml @@ -1,111 +1,129 @@ /* GCompris - GCButtonStyle.qml * * Copyright (C) 2014 Bruno Coudoin * * Authors: * Bruno Coudoin * * This program is free 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 * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ import QtQuick 2.2 import QtQuick.Controls 1.0 import QtQuick.Controls.Styles 1.0 import GCompris 1.0 /** * Provides styling for GCompris' Buttons. * @ingroup components * * @inherit QtQuick.Controls.Styles.ButtonStyle */ ButtonStyle { /** * type:real * Fixed font size of the label in pt. * * Set to a value > 0 for enforcing a fixed font.pointSize for the label, * that won't be updated with ApplicationSettings.baseFontSize. * @sa ApplicationSettings.baseFontSize, GCText.fixFontSize */ property real fixedFontSize: -1 /** * type:string * theme of the button. For now, two themes are accepted: "light" and "dark" * * Default is dark. */ property string theme: "dark" /** * type:variant * existing themes for the button. * A theme is composed of: * the colors of the button when selected: selectedColorGradient0 and selectedColorGradient1. * the colors of the button when not selected: backgroundColorGradient0 and backgroundColorGradient1. * the button's border color * the text color */ property variant themes: { "dark": { backgroundColorGradient0: "#23373737", selectedColorGradient0: "#C03ACAFF", backgroundColorGradient1: "#13373737", selectedColorGradient1: "#803ACAFF", borderColor: "#FF373737", textColor: "#FF373737" }, "light": { backgroundColorGradient0: "#42FFFFFF", selectedColorGradient0: "#C03ACAFF", backgroundColorGradient1: "#23FFFFFF", selectedColorGradient1: "#803ACAFF", borderColor: "white", textColor: "white" } } + property string textSize: "regular" + + property variant textSizes: { + "regular": { + fontSize: 14, + fontBold: false + }, + "subtitle": { + fontSize: 16, + fontBold: true + }, + "title": { + fontSize: 24, + fontBold: true + } + } + background: Rectangle { border.width: control.activeFocus ? 4 : 2 border.color: themes[theme].borderColor radius: 10 gradient: Gradient { GradientStop { position: 0 ; color: control.pressed ? themes[theme].selectedColorGradient0 : themes[theme].backgroundColorGradient0 } GradientStop { position: 1 ; color: control.pressed ? themes[theme].selectedColorGradient1 : themes[theme].backgroundColorGradient1 } } } label: Item { id: labelItem anchors.fill: parent implicitWidth: labelText.implicitWidth implicitHeight: labelText.implicitHeight GCText { id: labelText color: themes[theme].textColor text: control.text - fontSize: regularSize + fontSize: textSizes[textSize].fontSize + font.bold: textSizes[textSize].fontBold anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter wrapMode: Text.WordWrap Component.onCompleted: { if (fixedFontSize > 0) { labelText.fixFontSize = true; labelText.fontSize = fixedFontSize; } } } } }