代码拉取完成,页面将自动刷新
同步操作将从 openKylin/ukui-clipboard 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import QtQuick 2.15
import QtGraphicalEffects 1.0
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import org.ukui.quick.items 1.0 as UkuiItems
import org.ukui.quick.platform 1.0 as Platform
import ContentMenu 1.0
ApplicationWindow {
id: clipboardWindow
visible: false
title: "Preview Window"
property int paddings: 4
property int shadowWidth: 8
property int windowWidth: 568
property int windowHeight: 412
property int maxContentWidth: 540
property int maxContentHeight: 360
property int windowRadius: 18
property var themeColor: Platform.Theme.themeColor
property var highlightColor: Platform.Theme.color(Platform.Theme.Highlight, Platform.Theme.Active, 1)
width: windowWidth
height: windowHeight
maximumWidth: width
maximumHeight: height
minimumWidth: width
minimumHeight: height
// 设置窗口背景颜色为透明,以便于显示圆角效果
color: "transparent"
onVisibleChanged: {
if (visible) {
var pos = backend.getGlobalMousePosition()
clipboardWindow.x = (Screen.width - clipboardWindow.width) / 2
clipboardWindow.y = (Screen.height - clipboardWindow.height) / 2
// 删除下拉菜单里多余的选项并切换到指定界面
buttonMenu.removeItem();
var currentType = backend.displayingType
stack.switchToSpecifiedPage(currentType)
}
}
onThemeColorChanged: {
highlightColor = Platform.Theme.color(Platform.Theme.Highlight, Platform.Theme.Active, 1)
}
Connections {
target: backend
function onClipboardWindowVisibleChanged(visible) {
clipboardWindow.visible = visible
}
function onIconThemeChanged() {
menuBack.restoreIconName = backend.getIcon(backend.displayedIconName)
}
function onDisplayedIconNameChanged() {
menuBack.restoreIconName = backend.getIcon(backend.displayedIconName)
}
}
// 鼠标拖动
MouseArea {
anchors.fill: parent
cursorShape: Qt.SizeAllCursor
property int mouseX: 0
property int mouseY: 0
onPressed: {
mouseX = mouse.x
mouseY = mouse.y
}
onPositionChanged: {
if (mouse.buttons === Qt.LeftButton) {
clipboardWindow.x += mouse.x - mouseX
clipboardWindow.y += mouse.y - mouseY
}
}
}
Rectangle {
id: menuBack
width: windowWidth
height: windowHeight
anchors.centerIn: parent
color: Qt.rgba(255, 255, 255, 0.95)
radius: windowRadius
clip : true
property int lastDisplayedType: -1
property var restoreIconName: backend.getIcon(backend.displayedIconName)
focus: true
Keys.enabled: true
Keys.onPressed: {
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter){
pasteButton.pasted();
}
}
Row {
id: topLine
spacing: 0
Layout.alignment: Qt.AlignRight
anchors.top: parent.top
anchors.right: parent.right
topPadding: 4
rightPadding: 8
Rectangle {
id: restoreBtn
width: 28
height: 28
radius: width / 2
border.width: 1
border.color: Qt.rgba(0, 0, 0, 0.05)
color: backend.displayingType !== backend.originalType ? highlightColor : Qt.rgba(0, 0, 0, 0.03)
// 深色主题下反色
UkuiItems.Icon {
height: 14
width: 14
anchors.centerIn: parent
mode: backend.displayingType !== backend.originalType ? UkuiItems.Icon.Highlight : UkuiItems.Icon.Normal
source: menuBack.restoreIconName
}
ToolTip {
text: backend.displayingType !== backend.originalType ? qsTr("click to cancel conversion") : qsTr("click to switch to the original format")
visible: restoreBtnArea.containsMouse
}
MouseArea {
id: restoreBtnArea
anchors.fill: parent
hoverEnabled: true
onClicked: {
var originalType = backend.originalType
if (originalType === backend.displayingType){
// setDisplayingType和switchToSpecifiedPage对顺序有要求
backend.setDisplayingType(menuBack.lastDisplayedType)
stack.switchToSpecifiedPage(menuBack.lastDisplayedType)
return
}
menuBack.lastDisplayedType = backend.displayingType
backend.setDisplayingType(originalType)
stack.switchToSpecifiedPage(originalType)
}
}
}
Rectangle {
id: menuBtn
width: 20
height: 28
color: "transparent"
// 深色主题下反色
UkuiItems.Icon {
height: 16
width: 16
anchors.centerIn: parent
source: backend.getIcon("ukui-down-symbolic");
rotation: buttonMenu.visible ? 180 : 0
}
ToolTip {
text: qsTr("more options")
visible: moreOptionArea.containsMouse && !buttonMenu.visible
}
MouseArea {
id: moreOptionArea
anchors.fill: parent
hoverEnabled: true
property bool menuVisible: false
onPressed: {
if (!menuVisible) {
buttonMenu.open()
menuVisible = true
} else {
menuVisible = false
}
}
}
}
}
Rectangle {
id: menuBackground
anchors.right: parent.right
anchors.top: topLine.bottom
width: buttonMenu.width + paddings * 2
height: buttonMenu.height + paddings * 2
visible: buttonMenu.visible
color: "transparent"
// 阴影区域
ShadowComponent {
visible: true
anchors.fill: parent
radius: paddings * 2
shadowWidth: paddings
}
// 关联菜单
Menu {
id: buttonMenu
width: control.menuItemWidth
anchors.centerIn: menuBackground
background: Rectangle {
anchors.fill: parent
radius: paddings * 2
color: "white"
}
Repeater {
id: control
model: backend.contentMenus
property int menuItemWidth: 120
delegate: MenuItem {
id: menuItem
width: control.menuItemWidth
text: modelData.itemName
contentItem: Row {
spacing: paddings
Image {
x: paddings * 2
height: 16
width: 16
fillMode: Image.PreserveAspectFit
mipmap: true
anchors.verticalCenter: parent.verticalCenter
source: Qt.resolvedUrl("image://theme/" + modelData.iconName)
}
Label {
id: label
text: menuItem.text
font: menuItem.font
verticalAlignment: Text.AlignVCenter
}
}
highlighted: buttonMenu.currentIndex === index
background: Rectangle {
anchors.fill: menuItem
color: "transparent"
radius: paddings
Rectangle {
width: parent.width - paddings * 2
height: parent.height - paddings * 2
radius: paddings
anchors.centerIn: parent
color: menuItem.highlighted ? Qt.rgba(0, 0, 0, 0.05) : "transparent"
}
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: buttonMenu.currentIndex = index
onExited: buttonMenu.currentIndex = -1
onClicked: menuItem.triggered()
}
onTriggered: {
var currentType = backend.contentMenus[index].contentType
if (currentType === backend.displayingType){
return
}
backend.setDisplayingType(currentType)
stack.switchToSpecifiedPage(currentType)
}
Component.onCompleted: {
var contentItemWidth = 16 + label.contentWidth +
control.count*paddings + paddings * 3
control.menuItemWidth = control.menuItemWidth >= contentItemWidth ?
control.menuItemWidth : contentItemWidth
}
}
}
function removeItem() {
for (var i = 0; i < control.model.length; i++) {
if(control.model[i].contentType === ContentType.Original) {
backend.removeContentMenu(i); // 删除项
break; // 只删除第一个匹配的项
}
}
}
}
}
StackView {
id: stack
replaceEnter: null
replaceExit: null
anchors.top: topLine.bottom
anchors.bottom: buttomLine.top
anchors.left: parent.left
anchors.right: parent.right
function switchToSpecifiedPage(currentType)
{
if (currentType === ContentType.PlainText) {
replace(currentItem, plainTextComponent.createObject())
} else if (currentType === ContentType.RichText) {
replace(currentItem, richTextComponent.createObject())
} else if (currentType === ContentType.Image){
replace(currentItem, imageComponent.createObject())
}
}
}
Row {
id: buttomLine
spacing: 0
Layout.alignment: Qt.AlignRight
anchors.bottom: parent.bottom
anchors.right: parent.right
rightPadding: 8
bottomPadding: 12
Rectangle {
id: operateButton
width: 81 + 2 * paddings
height: 32 + 2 * paddings
ShadowComponent {
visible: true
anchors.fill: parent
radius: paddings
shadowWidth: paddings
}
Item {
anchors.right: seperator.left
anchors.verticalCenter: parent.verticalCenter
width: 40
height: 32
UkuiItems.Icon {
height: 16
width: 16
anchors.centerIn: parent
source: backend.getIcon("application-exit-symbolic")
}
ToolTip {
text: qsTr("cancel")
visible: cancelArea.containsMouse
}
MouseArea {
id: cancelArea
anchors.fill: parent
hoverEnabled: true
onClicked: {
clipboardWindow.visible = false
backend.setClipboardWindowVisible(false)
}
}
}
Rectangle {
id: seperator
width: 1
height: 30
color: Qt.rgba(0, 0, 0, 0.18)
anchors.centerIn: parent
}
Item {
id: pasteButton
anchors.left: seperator.right
anchors.verticalCenter: parent.verticalCenter
width: 40
height: 32
UkuiItems.Icon {
height: 16
width: 16
anchors.centerIn: parent
source: backend.getIcon("object-select-symbolic")
}
ToolTip {
text: qsTr("confirm pasting")
visible: confirmArea.containsMouse
}
function pasted() {
var currentType = backend.displayingType
// 使用TextEdit自带的函数将文本拷贝到剪切板
if (currentType === ContentType.Image) {
backend.copyToClipboard(currentType)
} else {
stack.currentItem.copyToClipboard()
}
clipboardWindow.visible = false
backend.setClipboardWindowVisible(false)
backend.performPasteOperation()
}
MouseArea {
id: confirmArea
anchors.fill: parent
hoverEnabled: true
onClicked: {
pasteButton.pasted();
}
}
}
}
}
Component {
id: richTextComponent // 富文本项的Component
TextEditArea {
visibleWidth: maxContentWidth
visibleHeight: maxContentHeight
textFormat: Qt.RichText
}
}
Component {
id: imageComponent // 图片项的Component
ImagePreviewArea {
visibleWidth: maxContentWidth
visibleHeight: maxContentHeight
}
}
Component {
id: plainTextComponent // 纯文本项的Component
TextEditArea {
visibleWidth: maxContentWidth
visibleHeight: maxContentHeight
textFormat: Qt.PlainText
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。