aerothemeplasma/Plasma Widgets/SevenStart/contents/ui/IconPicker.qml

79 lines
2.4 KiB
QML
Raw Normal View History

import QtQuick 2.2
import QtQuick.Controls 1.3
import QtQuick.Layouts 1.1
import org.kde.kquickcontrolsaddons 2.0 as KQuickAddons
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
// basically taken from kickoff
Button {
id: iconButton
property string currentIcon
property string defaultIcon
signal iconChanged(string iconName)
Layout.minimumWidth: previewFrame.width + units.smallSpacing * 2
Layout.maximumWidth: Layout.minimumWidth
Layout.minimumHeight: previewFrame.height + units.smallSpacing * 2
Layout.maximumHeight: Layout.minimumWidth
KQuickAddons.IconDialog {
id: iconDialog
onIconNameChanged: {
iconPreview.source = iconName
iconChanged(iconName)
}
}
// just to provide some visual feedback, cannot have checked without checkable enabled
checkable: true
onClicked: {
checked = Qt.binding(function() { // never actually allow it being checked
return iconMenu.status === PlasmaComponents.DialogStatus.Open
})
iconMenu.open(0, height)
}
PlasmaCore.FrameSvgItem {
id: previewFrame
anchors.centerIn: parent
imagePath: plasmoid.location === PlasmaCore.Types.Vertical || plasmoid.location === PlasmaCore.Types.Horizontal
? "widgets/panel-background" : "widgets/background"
width: units.iconSizes.large + fixedMargins.left + fixedMargins.right
height: units.iconSizes.large + fixedMargins.top + fixedMargins.bottom
PlasmaCore.IconItem {
id: iconPreview
anchors.centerIn: parent
width: units.iconSizes.large
height: width
source: currentIcon
}
}
function setDefaultIcon() {
iconPreview.source = defaultIcon
iconChanged(defaultIcon)
}
// QQC Menu can only be opened at cursor position, not a random one
PlasmaComponents.ContextMenu {
id: iconMenu
visualParent: iconButton
PlasmaComponents.MenuItem {
text: i18nc("@item:inmenu Open icon chooser dialog", "Choose...")
icon: "document-open-folder"
onClicked: iconDialog.open()
}
PlasmaComponents.MenuItem {
text: i18nc("@item:inmenu Reset icon to default", "Clear Icon")
icon: "edit-clear"
onClicked: setDefaultIcon()
}
}
}