Merge branch 'mart/inlineEditMenu'

REVIEW:124374
This commit is contained in:
Marco Martin 2015-09-02 11:58:06 +02:00
commit 573d2985ba
6 changed files with 341 additions and 0 deletions

View File

@ -0,0 +1,66 @@
/*
* Copyright (C) 2015 by Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, 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 Library General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA.
*/
import QtQuick 2.2
import org.kde.plasma.core 2.0 as PlasmaCore
Item {
id: root
property Item input: parent
width: units.smallSpacing
height: input.cursorRectangle.height
visible: input.activeFocus && input.selectionStart === input.selectionEnd
Rectangle {
width: units.smallSpacing
height: parent.height + units.gridUnit
radius: width
color: theme.highlightColor
}
Rectangle {
id: handle
x: -width/2 + parent.width/2
width: units.gridUnit
height: width
radius: width
color: theme.highlightColor
anchors.top: parent.bottom
}
MouseArea {
drag {
target: root
minimumX: 0
minimumY: 0
maximumX: input.width
maximumY: input.height - root.height
}
width: handle.width * 2
height: parent.height + handle.height
x: -width/2
onReleased: {
var pos = mapToItem(input, mouse.x, mouse.y);
input.cursorPosition = input.positionAt(pos.x, pos.y);
}
}
}

View File

@ -0,0 +1,51 @@
/*
* Copyright (C) 2015 by Marco MArtin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, 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 Library General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA.
*/
import QtQuick 2.2
import org.kde.plasma.core 2.0 as PlasmaCore
Item {
width: units.gridUnit
height: styleData.lineHeight + units.gridUnit
visible: styleData.hasSelection
Rectangle {
id: handle
width: units.gridUnit
height: width
radius: width
color: theme.highlightColor
anchors.bottom: parent.bottom
}
Rectangle {
width: units.gridUnit/2
height: width
anchors {
left: handle.left
top: handle.top
}
color: theme.highlightColor
}
Rectangle {
width: units.smallSpacing
height: styleData.lineHeight + units.gridUnit/2
color: theme.highlightColor
anchors.left: parent.left
}
}

View File

@ -0,0 +1,143 @@
/*
* Copyright (C) 2015 by Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, 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 Library General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA.
*/
import QtQuick 2.1
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.1
import QtQuick.Controls.Private 1.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
Item {
anchors.fill: parent
property Component defaultMenu: PlasmaCore.FrameSvgItem {
id: popup
imagePath: "widgets/background"
visible: false
width: childrenRect.width + margins.left + margins.right
height: childrenRect.height + margins.top + margins.bottom
z: 9999
Component.onCompleted: {
var par = control
//heuristic: if a flickable is found in the parents,
//reparent to it, so it scrolls together
while (par.parent && par.parent.contentY === undefined) {
par = par.parent
}
popup.parent = par
}
function popup(pos) {
popup.x = pos.x;
popup.y = pos.y;
popup.visible = true;
}
function dismiss() {
popup.visible = false;
}
Row {
x: parent.margins.left
y: parent.margins.top
property Item checkedButton
PlasmaComponents.ToolButton {
iconSource: "edit-cut"
flat: false
visible: input.selectedText != ""
onClicked: {
control.cut();
select(input.cursorPosition, input.cursorPosition);
}
}
PlasmaComponents.ToolButton {
iconSource: "edit-copy"
visible: input.selectedText != ""
flat: false
onClicked: {
control.copy();
select(input.cursorPosition, input.cursorPosition);
}
}
PlasmaComponents.ToolButton {
iconSource: "edit-paste"
enabled: input.canPaste
flat: false
onClicked: {
control.paste();
}
}
}
}
Connections {
target: mouseArea
onClicked: {
if (control.menu && getMenuInstance().__popupVisible) {
select(input.cursorPosition, input.cursorPosition);
} else {
input.activate();
}
if (input.activeFocus) {
var pos = input.positionAt(mouse.x, mouse.y)
input.moveHandles(pos, pos)
}
popupTimer.restart();
}
onPressAndHold: {
input.activate();
var pos = input.positionAt(mouseArea.mouseX, mouseArea.mouseY);
input.select(pos, pos);
selectWord();
popupTimer.restart();
}
}
Connections {
target: input
onSelectionStartChanged: popupTimer.restart()
onSelectionEndChanged: popupTimer.restart()
onActiveFocusChanged: popupTimer.restart()
}
Connections {
target: flickable
onMovingChanged: popupTimer.restart()
}
Timer {
id: popupTimer
interval: 1
onTriggered: {
if ((input.canPaste || selectionStart !== selectionEnd) && control.activeFocus) {
var startRect = input.positionToRectangle(input.selectionStart);
var endRect = input.positionToRectangle(input.selectionEnd);
var pos = getMenuInstance().parent.mapFromItem(input, startRect.x, startRect.y + units.gridUnit);
getMenuInstance().dismiss();
getMenuInstance().popup(pos);
} else {
getMenuInstance().dismiss();
}
}
}
}

View File

@ -0,0 +1,52 @@
/*
* Copyright (C) 2015 by Marco MArtin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, 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 Library General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA.
*/
import QtQuick 2.2
import org.kde.plasma.core 2.0 as PlasmaCore
Item {
width: units.gridUnit
x: -width
height: styleData.lineHeight + units.gridUnit
visible: styleData.hasSelection
Rectangle {
id: handle
width: units.gridUnit
height: width
radius: width
color: theme.highlightColor
anchors.bottom: parent.bottom
}
Rectangle {
width: units.gridUnit/2
height: width
anchors {
right: handle.right
top: handle.top
}
color: theme.highlightColor
}
Rectangle {
width: units.smallSpacing
height: styleData.lineHeight + units.gridUnit/2
color: theme.highlightColor
anchors.right: parent.right
}
}

View File

@ -20,6 +20,7 @@
import QtQuick 2.1
import QtQuick.Controls.Styles 1.1 as QtQuickControlStyle
import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate
import QtQuick.Controls 1.1
import org.kde.plasma.core 2.0 as PlasmaCore
@ -67,4 +68,17 @@ QtQuickControlStyle.TextAreaStyle {
incrementControl: svs.incrementControl
decrementControl: svs.decrementControl
Component {
id: editMenuTouch
EditMenuTouch {}
}
Component {
id: cursorTouch
CursorDelegate {}
}
__cursorHandle: CursorHandleStyle {}
__cursorDelegate: QtQuickControlsPrivate.Settings.isMobile ? cursorTouch : null
__selectionHandle: SelectionHandleStyle {}
property Component __editMenu: QtQuickControlsPrivate.Settings.isMobile ? editMenuTouch : null
}

View File

@ -19,6 +19,7 @@
import QtQuick 2.0
import QtQuick.Controls.Styles 1.1 as QtQuickControlStyle
import QtQuick.Controls.Private 1.0 as QtQuickControlsPrivate
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
@ -65,4 +66,18 @@ QtQuickControlStyle.TextFieldStyle {
root.padding.bottom = base.margins.bottom
}
}
Component {
id: editMenuTouch
EditMenuTouch {}
}
Component {
id: cursorTouch
CursorDelegate {}
}
__cursorHandle: CursorHandleStyle {}
__cursorDelegate: QtQuickControlsPrivate.Settings.isMobile ? cursorTouch : null
__selectionHandle: SelectionHandleStyle {}
property Component __editMenu: QtQuickControlsPrivate.Settings.isMobile ? editMenuTouch : null
}