MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QDeclarativeView* dv = new QDeclarativeView();
dv->setSource(QUrl("qrc:/main.qml"));
QDeclarativeContext* cntx = dv->rootContext();
cntx->setContextProperty("window",this);
dv->setResizeMode(QDeclarativeView::SizeRootObjectToView);
setCentralWidget(dv);
}
public slots:
QString slotEncode(QString sIn);
QString slotDecode(QString sIn);
bool slotCheck(int val);
import QtQuick 1.0
Rectangle {
width: 365
height: 200
gradient: Gradient {
GradientStop {
position: 0
color: "#696363"
}
GradientStop {
position: 1
color: "#000000"
}
}
Text {
id: text1
x: 37
y: 27
color: "#fbfbfb"
text: " "
style: Text.Raised
font.pixelSize: 12
}
Text {
id: text2
x: 198
y: 27
color: "#ffffff"
text: " "
style: Text.Raised
font.pixelSize: 12
}
// .
Rectangle {
color: "#4de013"
radius: 6
border.width: 5
border.color: "#f5f9f4"
x: 36
y: 66
width: 133
height: 20
TextInput {
id: text_input1
width: parent.width - 20
height: parent.height - 5
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
text: ""
font.pixelSize: 12
}
}
// .
Rectangle {
color: "#48c819"
radius: 6
border.width: 5
border.color: "#f5f9f4"
width: 133
height: 20
x: 201
y: 66
TextInput {
id: text_input2
width: parent.width - 20
height: parent.height - 5
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
text: ""
font.pixelSize: 12
}
}
// .
Rectangle {
id: bEncode
property alias text: label.text
width: 135
height: 60
radius: 20
border.width: 2
border.color: "#090606"
gradient: Gradient {
GradientStop {
id: gradientstop1
position: 0.01
color: "#ffffff"
}
GradientStop {
id: gradientstop2
position: 0.28
color: "#867d7d"
}
GradientStop {
id: gradientstop3
position: 1
color: "#000000"
}
}
signal clicked()
x: 36
y: 110
Text {
id: label
color: "#ffffff"
text: ""
font.strikeout: false
font.pointSize: 10
horizontalAlignment: Text.AlignHCenter
anchors.centerIn: parent
}
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
onClicked: {
text_input2.text = window.slotEncode(text_input1.text)
}
onEntered: {
bEncode.state = "green"
}
onExited: {
bEncode.state = "gray"
}
}
states: [
State {
name: "gray"
},
State {
name: "green"
PropertyChanges {
target: gradientstop1
color: "#ffffff"
}
PropertyChanges {
target: gradientstop2
color: "#34c22a"
}
PropertyChanges {
target: gradientstop3
color: "#000000"
}
}
]
}
// .
Rectangle {
id: bDecode
property alias text: label.text
width: 136
height: 60
radius: 20
border.width: 2
border.color: "#090606"
gradient: Gradient {
GradientStop {
id: gradientstop21
position: 0.01
color: "#ffffff"
}
GradientStop {
id: gradientstop22
position: 0.28
color: "#867d7d"
}
GradientStop {
id: gradientstop23
position: 1
color: "#000000"
}
}
signal clicked()
x: 200
y: 110
Text {
id: label2
text: ""
color: "#ffffff"
font.strikeout: false
font.pointSize: 10
horizontalAlignment: Text.AlignHCenter
anchors.centerIn: parent
}
MouseArea {
id: mouseArea2
anchors.fill: parent
hoverEnabled: true
onClicked: {
text_input1.text = window.slotDecode(text_input2.text)
}
onEntered: {
bDecode.state = "green"
}
onExited: {
bDecode.state = "gray"
}
}
states: [
State {
name: "gray"
},
State {
name: "green"
PropertyChanges {
target: gradientstop21
color: "#ffffff"
}
PropertyChanges {
target: gradientstop22
color: "#34c22a"
}
PropertyChanges {
target: gradientstop23
color: "#000000"
}
}
]
}
}
Source: https://habr.com/ru/post/122046/