~cyberspace/homerun/trunk

« back to all changes in this revision

Viewing changes to fixes/qml/TextField.qml

  • Committer: Eike Hein
  • Author(s): Leszek Lesner
  • Date: 2013-12-13 15:24:52 UTC
  • Revision ID: git-v1:76b5a94e6dfec0283fb3189f47dff2d5ce8ae366
Added contextmenu for TextField

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
import QtQuick 1.1
21
21
import org.kde.plasma.core 0.1 as PlasmaCore
 
22
import org.kde.plasma.components 0.1 as PlasmaComponents
22
23
import "private" as Private
23
24
 
24
25
/**
27
28
FocusScope {
28
29
    id: textField
29
30
 
 
31
 
 
32
    property int selectStart
 
33
    property int selectEnd
 
34
    property int curPos
30
35
    // Common API
31
36
    /**
32
37
     * Whether the text field is highlighted or not
358
363
        }
359
364
        onAccepted: textField.accepted()
360
365
        Keys.forwardTo: textField
 
366
        MouseArea {
 
367
            anchors.fill: parent
 
368
            acceptedButtons: Qt.RightButton
 
369
            onClicked: {
 
370
                // FIXME: We're having to cache these and recreating the selection because TextInput's implementation clears the selection on focus loss; this should be re-evaluated and hopefully dropped in future versions
 
371
                selectStart = textInput.selectionStart;
 
372
                selectEnd = textInput.selectionEnd;
 
373
                curPos = textInput.cursorPosition;
 
374
                contextMenu.open(mouse.x, mouse.y);
 
375
                textInput.cursorPosition = curPos;
 
376
                textInput.select(selectStart,selectEnd);
 
377
            }
 
378
        }
 
379
    }
 
380
 
 
381
    PlasmaComponents.ContextMenu {
 
382
        id: contextMenu
 
383
        visualParent: textInput
 
384
 
 
385
        PlasmaComponents.MenuItem {
 
386
            text: qsTr("Cut")
 
387
            icon: QIcon("edit-cut")
 
388
            onClicked: {
 
389
                cut();
 
390
            }
 
391
        }
 
392
        PlasmaComponents.MenuItem {
 
393
            text: qsTr("Copy")
 
394
            icon: QIcon("edit-copy")
 
395
            onClicked: {
 
396
                copy();
 
397
            }
 
398
        }
 
399
        PlasmaComponents.MenuItem {
 
400
            text: qsTr("Paste")
 
401
            icon: QIcon("edit-paste")
 
402
            onClicked: {
 
403
                paste();
 
404
            }
 
405
        }
361
406
    }
362
407
 
363
408
    PlasmaCore.IconItem {