refactor flag

main
Francois DELOBEL 3 weeks ago
parent ad9305e422
commit c3e3f4e53f

@ -1,4 +1,5 @@
import QtQuick 2.15
import I.hate.dictators 1.0
Rectangle {
width: lv.width
@ -6,6 +7,7 @@ Rectangle {
required property string name
required property string iso
required property CountryType self
Text {
@ -25,8 +27,7 @@ Rectangle {
MouseArea {
anchors.fill: parent
onClicked: {
choosenText.text = name
choosenFlag.source = flag.source
mainWindow.selectedCountry = self
}
}
}

@ -0,0 +1,35 @@
import QtQuick 2.15
import I.hate.dictators 1.0
Rectangle {
required property CountryType country
color: "lightgrey"
Column {
width: parent.width
Image {
id: choosenFlag
source: country?'qrc:/assets/flags/'+country.iso+'.svg':''
fillMode: Image.PreserveAspectFit
width: parent.width
}
Text {
id: nameText
text: country ? country.name : ""
font.pixelSize: 50
anchors.horizontalCenter: parent.horizontalCenter
}
Text {
text: country ? country.capital : ""
font.pixelSize: nameText.font.pixelSize
anchors.horizontalCenter: parent.horizontalCenter
}
Text {
text: country ? country.region : ""
font.pixelSize: nameText.font.pixelSize
anchors.horizontalCenter: parent.horizontalCenter
}
}
}

@ -1,5 +1,9 @@
#include "country.h"
Country::Country()
{
}
Country::Country(QString name, QString capital, QString iso, QString region, QString alt, QObject *object)
: QObject{object},
m_name{name},
@ -73,3 +77,10 @@ void Country::setAlt(const QString &newAlt)
m_alt = newAlt;
emit altChanged();
}
Country* Country::self()
{
return this;
}
void Country::setSelf(const Country *){}

@ -13,9 +13,12 @@ class Country : public QObject
Q_PROPERTY(QString iso READ iso WRITE setIso NOTIFY isoChanged FINAL)
Q_PROPERTY(QString region READ region WRITE setRegion NOTIFY regionChanged FINAL)
Q_PROPERTY(QString alt READ alt WRITE setAlt NOTIFY altChanged FINAL)
Q_PROPERTY(Country* self READ self WRITE setSelf NOTIFY selfChanged FINAL)
public:
Country();
Country(QString name, QString capital, QString iso, QString region,
QString alt, QObject *object = nullptr);
QString capital() const;
@ -32,6 +35,9 @@ public:
QString alt() const;
void setAlt(const QString &newAlt);
Country *self();
void setSelf(const Country*);;
signals:
void capitalChanged();
void nameChanged();
@ -42,6 +48,8 @@ signals:
void altChanged();
void selfChanged();
private:
QString m_name;
QString m_capital;

@ -29,6 +29,7 @@ int main(int argc, char *argv[])
for ( auto cr : countries)
cc.append(static_cast<QObject*>(cr));
engine.rootContext()->setContextProperty("countries", QVariant::fromValue(cc));
qmlRegisterType<Country>("I.hate.dictators",1,0,"CountryType" );
engine.load(url);

@ -1,11 +1,14 @@
import QtQuick 2.15
import QtQuick.Window 2.15
import I.hate.dictators 1.0
Window {
width: 640
height: 480
visible: true
title: qsTr("Flags of the world")
id: mainWindow
property CountryType selectedCountry
ListView {
id: lv
@ -14,31 +17,13 @@ Window {
width: parent.width / 3
model: countries
delegate: Country {
}
}
Rectangle {
CountryDetail {
anchors.right: parent.right
anchors.left: lv.right
height: parent.height
color: "lightgrey"
Column {
width: parent.width
Image {
id: choosenFlag
fillMode: Image.PreserveAspectFit
width: parent.width
}
Text {
id: choosenText
text: ""
font.pixelSize: 50
anchors.horizontalCenter: parent.horizontalCenter
}
}
country: selectedCountry
}
}

@ -204,5 +204,6 @@
<file>assets/map.svg</file>
<file>assets/map.svg.txt</file>
<file>Country.qml</file>
<file>CountryDetail.qml</file>
</qresource>
</RCC>

Loading…
Cancel
Save