Skycoder42
7 years ago
13 changed files with 354 additions and 11 deletions
@ -0,0 +1,32 @@ |
|||
import QtQuick 2.10 |
|||
import QtQuick.Controls 2.3 |
|||
import de.skycoder42.QtMvvm.Core 1.0 |
|||
|
|||
QtObject { |
|||
id: _dialogPresenter |
|||
|
|||
property Item rootItem: null |
|||
|
|||
function showDialog(config, result) { |
|||
if(config.type == "msgbox") { |
|||
createMsgBox(config, result) |
|||
return true; |
|||
} else |
|||
return false; |
|||
} |
|||
|
|||
property Component _msgBoxComponent: Component { |
|||
MsgBox { |
|||
id: __msgBox |
|||
Component.onCompleted: __msgBox.open() |
|||
} |
|||
} |
|||
|
|||
function createMsgBox(config, result) { |
|||
var props = config.viewProperties; |
|||
props["msgConfig"] = config; |
|||
props["msgResult"] = result; |
|||
var incubator = _msgBoxComponent.incubateObject(rootItem, props); |
|||
return incubator.status !== Component.Error; |
|||
} |
|||
} |
@ -0,0 +1,128 @@ |
|||
import QtQuick 2.10 |
|||
import QtQuick.Controls 2.3 |
|||
import QtQuick.Window 2.2 |
|||
import QtQuick.Layouts 1.3 |
|||
import de.skycoder42.QtMvvm.Core 1.0 |
|||
|
|||
Dialog { |
|||
id: _msgBox |
|||
|
|||
property var msgConfig |
|||
property MessageResult msgResult |
|||
|
|||
property real extraHeight: 0 |
|||
|
|||
x: parent ? (parent.width - width) / 2 : 0 |
|||
y: parent ? deltaY() : 0 |
|||
width: parent ? Math.min(Math.max(implicitWidth, 300), parent.width - 28) : implicitWidth |
|||
height: parent ? Math.min(implicitHeight, parent.height - 28) : implicitWidth |
|||
modal: true |
|||
focus: true |
|||
closePolicy: Popup.CloseOnEscape |
|||
|
|||
function deltaY() { |
|||
var unscaled = Qt.inputMethod.keyboardRectangle.height / Screen.devicePixelRatio; |
|||
var availHeight = (parent.height + extraHeight) - unscaled - 28;//spacing |
|||
var rawDelta = (Math.max(0, availHeight - height) / 2); |
|||
return rawDelta + 14 - extraHeight;//spacing |
|||
} |
|||
|
|||
header: RowLayout { |
|||
spacing: 14 |
|||
|
|||
TintIcon { |
|||
id: icon |
|||
property int iconType |
|||
|
|||
Layout.preferredWidth: 24 |
|||
Layout.preferredHeight: 24 |
|||
Layout.margins: 24 |
|||
Layout.bottomMargin: 0 |
|||
Layout.rightMargin: 0 |
|||
visible: msgConfig.subType != "about" |
|||
source: { |
|||
var base = "image://svg/de/skycoder42/qtmvvm/quick/icons/ic_%1"; |
|||
switch(msgConfig.subType) { |
|||
case "information": |
|||
base = base.arg("info"); |
|||
break; |
|||
case "question": |
|||
base = base.arg("help"); |
|||
break; |
|||
case "warning": |
|||
base = base.arg("warning"); |
|||
break; |
|||
case "critical": |
|||
base = base.arg("error"); |
|||
break; |
|||
case "about": |
|||
default: |
|||
return ""; |
|||
} |
|||
return base; |
|||
} |
|||
} |
|||
|
|||
Label { |
|||
text: msgConfig.title |
|||
visible: msgConfig.title |
|||
elide: Label.ElideRight |
|||
font.bold: true |
|||
font.pixelSize: 16 |
|||
Layout.fillWidth: true |
|||
Layout.margins: 24 |
|||
Layout.bottomMargin: 0 |
|||
Layout.leftMargin: icon.visible ? 0 : 24 |
|||
} |
|||
} |
|||
|
|||
Label { |
|||
id: _contentLabel |
|||
text: msgConfig.text.replace(/<\/p>/g, "</p><br/>") //needed because qml does not put space between paragraphs... |
|||
visible: text != "" |
|||
anchors.fill: parent |
|||
wrapMode: Text.Wrap |
|||
onLinkActivated: Qt.openUrlExternally(link) |
|||
} |
|||
|
|||
footer: DialogButtonBox { |
|||
id: _btnBox |
|||
|
|||
readonly property var _allBtns: [ |
|||
DialogButtonBox.NoButton, |
|||
DialogButtonBox.Ok, |
|||
DialogButtonBox.Save, |
|||
DialogButtonBox.SaveAll, |
|||
DialogButtonBox.Open, |
|||
DialogButtonBox.Yes, |
|||
DialogButtonBox.YesToAll, |
|||
DialogButtonBox.No, |
|||
DialogButtonBox.NoToAll, |
|||
DialogButtonBox.Abort, |
|||
DialogButtonBox.Retry, |
|||
DialogButtonBox.Ignore, |
|||
DialogButtonBox.Close, |
|||
DialogButtonBox.Cancel, |
|||
DialogButtonBox.Discard, |
|||
DialogButtonBox.Help, |
|||
DialogButtonBox.Apply, |
|||
DialogButtonBox.Reset, |
|||
DialogButtonBox.RestoreDefaults, |
|||
] |
|||
|
|||
standardButtons: msgConfig.buttons |
|||
onStandardButtonsChanged: { |
|||
for(var key in msgConfig.buttonTexts) |
|||
standardButton(DialogButtonBox.Ok).text = msgConfig.buttonTexts[key] |
|||
} |
|||
|
|||
onClicked: { |
|||
if(msgResult) { |
|||
_allBtns.forEach(function(sBtn) { |
|||
if(button === standardButton(sBtn)) |
|||
msgResult.complete(sBtn) |
|||
}) |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,39 @@ |
|||
import QtQuick 2.10 |
|||
import QtQuick.Controls.Material 2.3 |
|||
import QtQuick.Controls.Universal 2.3 |
|||
import QtGraphicalEffects 1.0 |
|||
import de.skycoder42.QtMvvm.Quick 1.0 |
|||
|
|||
Item { |
|||
id: _tintIcon |
|||
|
|||
property size iconSize: Qt.size(24, 24) |
|||
property alias tintColor: _overlay.color |
|||
property alias source: _image.source |
|||
|
|||
Image { |
|||
id: _image |
|||
anchors.centerIn: parent |
|||
fillMode: Image.PreserveAspectFit |
|||
horizontalAlignment: Image.AlignHCenter |
|||
verticalAlignment: Image.AlignVCenter |
|||
width: iconSize.width |
|||
height: iconSize.height |
|||
sourceSize: iconSize |
|||
visible: false |
|||
} |
|||
|
|||
ColorOverlay { |
|||
id: _overlay |
|||
anchors.fill: _image |
|||
source: _image |
|||
color: { |
|||
if(QuickPresenter.currentStyle === "Material") |
|||
return Material.foreground; |
|||
else if(QuickPresenter.currentStyle === "Universal") |
|||
return Universal.foreground; |
|||
else |
|||
return "black"; |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue