Warning, /games/kreversi/src/qml/Popup.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 SPDX-FileCopyrightText: 2007 Dmitry Suzdalev <dimsuz@gmail.com>
0003 SPDX-FileCopyrightText: 2012 Viranch Mehta <viranch.mehta@gmail.com
0004 SPDX-FileCopyrightText: 2013 Denis Kuplyakov <dener.kup@gmail.com>
0005
0006 SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008
0009 import QtQuick 2.3
0010 import ColorScheme 1.0
0011
0012 /**
0013 * Popup
0014 *
0015 * Represents popup. It's analog of KGamePopupItem.
0016 *
0017 * TODO: move it to libkdegames
0018 */
0019
0020 Rectangle {
0021 id: popup
0022
0023 // constants
0024
0025 /**
0026 * Margin on the sides of message box
0027 */
0028 property int marginOnSides: 15
0029 /**
0030 * Space between pixmap and text
0031 */
0032 property int marginIconText: 10
0033
0034 // API properties
0035
0036 // TODO: If item is hovered with mouse it will hide only after user moves the mouse away
0037 /**
0038 * The amount of time the item will stay visible on screen before it goes away.
0039 * By default item is shown for 2000 msec.
0040 */
0041 property int timeout: 2000
0042 /**
0043 * The popup angles sharpness
0044 */
0045 property alias sharpness: popup.radius
0046 /**
0047 * Name of the icon to show at popup
0048 */
0049 property string iconName: "dialog-information"
0050 /**
0051 * Sets whether to hide this popup item on mouse click.
0052 *
0053 * By default a mouse click will cause an item to hide
0054 */
0055 property alias hideOnMouseClick: mouseArea.enabled
0056 /**
0057 * Sets default color for unformatted text.
0058 * By default system-default color is used.
0059 */
0060 property alias textColor: text.color
0061 /**
0062 * Sets default color for background.
0063 * By default system-default color is used.
0064 */
0065 property alias backgroundColor: popup.color
0066 /**
0067 * Sets whether to use custom border color or system-default one.
0068 * By default system-default color is used.
0069 */
0070 property bool useCustomBorderColor: false
0071 /**
0072 * Border's color.
0073 * By default system-default color is used.
0074 */
0075 property color borderColor: popup.border.color
0076 /**
0077 * Border's width in pixels.
0078 * By default it's equals 1
0079 */
0080 property int borderWidth: 1
0081 /**
0082 * Sets whether new message is replacing already showing one or ignored
0083 */
0084 property bool isReplacing: false
0085
0086 // API signals
0087 /**
0088 * Emitted when user clicks on a link in item.
0089 */
0090 signal linkActivated(string link)
0091 /**
0092 * Emitted when popup hides.
0093 */
0094 signal hidden()
0095
0096 // private properties
0097 height: row.height + 2 * marginOnSides
0098 width: row.width + 2 * marginOnSides
0099
0100 color: colorScheme.background
0101 border.color: useCustomBorderColor ? black : colorScheme.border
0102 border.width: borderWidth
0103
0104 function show(message, showing_state) {
0105 if (!timer.running || isReplacing) {
0106 text.text = message
0107 timer.restart()
0108 state = showing_state
0109 }
0110 }
0111
0112 ColorScheme {
0113 id: colorScheme
0114 }
0115
0116 Timer {
0117 id: timer
0118 repeat: false
0119 interval: timeout
0120 onTriggered: {
0121 state = ""
0122 hidden()
0123 }
0124 }
0125
0126 Row {
0127 id: row
0128 anchors.centerIn: parent
0129 spacing: marginIconText
0130
0131 Image {
0132 id: icon
0133 anchors.verticalCenter: parent.verticalCenter
0134 width: visible ? 32 : 0
0135 height: width
0136
0137 visible: iconName != ""
0138
0139 source: "image://icon/" + iconName
0140 }
0141
0142
0143 Text {
0144 id: text
0145 anchors.verticalCenter: parent.verticalCenter
0146 color: colorScheme.foreground
0147 wrapMode: Text.WordWrap
0148
0149 onLinkActivated: popup.linkActivated(link);
0150 }
0151 }
0152
0153 MouseArea {
0154 id: mouseArea
0155 anchors.fill: parent
0156
0157 onClicked: {
0158 popup.state = ""
0159 timer.stop()
0160 hidden()
0161 }
0162 }
0163 }