如何利用Ubuntu Clipboard来复制并粘贴内容
展开全部
在Ubuntu平台里,有一个Clipboard API的接口。在这篇文章中,我们将介绍如何使用该API接口来复制和粘贴内容。
具体的API介绍,可以在网址:
https://developer.ubuntu.com/api/apps/qml/sdk-15.04/Ubuntu.Components.Clipboard/
为了测试Clipboard的功能,我们使用了如下的代码:
import QtQuick 2.0
import Ubuntu.Components 1.2
/*!
\brief MainView with a Label and Button elements.
*/
MainView {
// objectName for functional testing purposes (autopilot-qt5)
objectName: "mainView"
// Note! applicationName needs to match the "name" field of the click manifest
applicationName: "clipboard.liu-xiao-guo"
/*
This property enables the application to change orientation
when the device is rotated. The default is false.
*/
//automaticOrientation: true
// Removes the old toolbar and enables new features of the new header.
//useDeprecatedToolbar: false
width: units.gu(60)
height: units.gu(85)
Page {
title: i18n.tr("clipboard")
Column {
clip: true
anchors.centerIn: parent
spacing: units.gu(1)
Image {
id: image
width: 50
height: 50
source: "images/pic1.jpg"
}
TextArea {
id: editor
text: "This is cool!"
}
MimeData {
id: mimeData
color: "green"
text: editor.text
urls: [image.source]
}
Button {
text: "Copy method one"
onClicked: Clipboard.push(mimeData)
}
Button {
text: "Copy method two"
onClicked: {
//Clipboard.push(editor.text);
//Clipboard.push(["application/x-color", "green"]);
Clipboard.push(["application/x-color", "red",
"text/plain", editor.text,
"text/plain", [image.source]
]);
}
}
Button {
text: "Copy method three"
onClicked: {
var mimeData = Clipboard.newData();
mimeData.text = editor.text;
mimeData.color = "green";
mimeData.urls.push(image.source);
Clipboard.push(mimeData);
}
}
Row {
spacing: units.gu(1)
Button {
text: "Paste"
onClicked: {
editor1.text = Clipboard.data.text;
editor1.color = Clipboard.data.color;
image1.source = Clipboard.data.urls[0];
}
}
Button {
text: "Clear the textarea below"
onClicked: {
//Clipboard.clear();
editor1.text = "";
image1.source = "";
}
}
}
TextArea {
id: editor1
}
Image {
id: image1
width: 50
height: 50
}
}
}
}
具体的API介绍,可以在网址:
https://developer.ubuntu.com/api/apps/qml/sdk-15.04/Ubuntu.Components.Clipboard/
为了测试Clipboard的功能,我们使用了如下的代码:
import QtQuick 2.0
import Ubuntu.Components 1.2
/*!
\brief MainView with a Label and Button elements.
*/
MainView {
// objectName for functional testing purposes (autopilot-qt5)
objectName: "mainView"
// Note! applicationName needs to match the "name" field of the click manifest
applicationName: "clipboard.liu-xiao-guo"
/*
This property enables the application to change orientation
when the device is rotated. The default is false.
*/
//automaticOrientation: true
// Removes the old toolbar and enables new features of the new header.
//useDeprecatedToolbar: false
width: units.gu(60)
height: units.gu(85)
Page {
title: i18n.tr("clipboard")
Column {
clip: true
anchors.centerIn: parent
spacing: units.gu(1)
Image {
id: image
width: 50
height: 50
source: "images/pic1.jpg"
}
TextArea {
id: editor
text: "This is cool!"
}
MimeData {
id: mimeData
color: "green"
text: editor.text
urls: [image.source]
}
Button {
text: "Copy method one"
onClicked: Clipboard.push(mimeData)
}
Button {
text: "Copy method two"
onClicked: {
//Clipboard.push(editor.text);
//Clipboard.push(["application/x-color", "green"]);
Clipboard.push(["application/x-color", "red",
"text/plain", editor.text,
"text/plain", [image.source]
]);
}
}
Button {
text: "Copy method three"
onClicked: {
var mimeData = Clipboard.newData();
mimeData.text = editor.text;
mimeData.color = "green";
mimeData.urls.push(image.source);
Clipboard.push(mimeData);
}
}
Row {
spacing: units.gu(1)
Button {
text: "Paste"
onClicked: {
editor1.text = Clipboard.data.text;
editor1.color = Clipboard.data.color;
image1.source = Clipboard.data.urls[0];
}
}
Button {
text: "Clear the textarea below"
onClicked: {
//Clipboard.clear();
editor1.text = "";
image1.source = "";
}
}
}
TextArea {
id: editor1
}
Image {
id: image1
width: 50
height: 50
}
}
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询