Compare commits

..

3 Commits
flags ... main

@ -0,0 +1,82 @@
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------
*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash
# qtcreator generated files
*.pro.user*
*.qbs.user*
CMakeLists.txt.user*
# xemacs temporary files
*.flc
# Vim temporary files
.*.swp
# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*
# MinGW generated files
*.Debug
*.Release
# Python byte code
*.pyc
# Binaries
# --------
*.dll
*.exe
# Directories with generated files
.moc/
.obj/
.pch/
.rcc/
.uic/
/build*/

@ -0,0 +1,11 @@
TEMPLATE = app
CONFIG += console c++17
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
dice.cpp \
main.cpp
HEADERS += \
dice.h

@ -0,0 +1,12 @@
#include "dice.h"
#include <random>
unsigned int dice(unsigned int minDice, unsigned int maxDice)
{
static std::random_device rd;
static std::mt19937 gen(rd());
static std::uniform_int_distribution<> distrib(minDice, maxDice);
return distrib(gen);
}

@ -0,0 +1,7 @@
#ifndef _dice_hpp_
#define _dice_hpp_
/** Petit jeu avec des static dedans **/
unsigned int dice(unsigned int minDice, unsigned int maxDice);
#endif

@ -0,0 +1,9 @@
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}

@ -0,0 +1,33 @@
import QtQuick 2.15
import I.hate.dictators 1.0
Rectangle {
width: lv.width
height: 30
required property string name
required property string iso
required property CountryType self
Text {
text: parent.name
font.pixelSize: 20
anchors.verticalCenter: parent.verticalCenter
}
Image {
id: flag
source: "qrc:/assets/flags/"+parent.iso+".svg"
height: parent.height - 4
anchors.right: parent.right
fillMode: Image.PreserveAspectFit
anchors.verticalCenter: parent.verticalCenter
}
MouseArea {
anchors.fill: parent
onClicked: {
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" #include "country.h"
Country::Country()
{
}
Country::Country(QString name, QString capital, QString iso, QString region, QString alt, QObject *object) Country::Country(QString name, QString capital, QString iso, QString region, QString alt, QObject *object)
: QObject{object}, : QObject{object},
m_name{name}, m_name{name},
@ -73,3 +77,10 @@ void Country::setAlt(const QString &newAlt)
m_alt = newAlt; m_alt = newAlt;
emit altChanged(); 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 iso READ iso WRITE setIso NOTIFY isoChanged FINAL)
Q_PROPERTY(QString region READ region WRITE setRegion NOTIFY regionChanged 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(QString alt READ alt WRITE setAlt NOTIFY altChanged FINAL)
Q_PROPERTY(Country* self READ self WRITE setSelf NOTIFY selfChanged FINAL)
public: public:
Country();
Country(QString name, QString capital, QString iso, QString region, Country(QString name, QString capital, QString iso, QString region,
QString alt, QObject *object = nullptr); QString alt, QObject *object = nullptr);
QString capital() const; QString capital() const;
@ -32,6 +35,9 @@ public:
QString alt() const; QString alt() const;
void setAlt(const QString &newAlt); void setAlt(const QString &newAlt);
Country *self();
void setSelf(const Country*);;
signals: signals:
void capitalChanged(); void capitalChanged();
void nameChanged(); void nameChanged();
@ -42,6 +48,8 @@ signals:
void altChanged(); void altChanged();
void selfChanged();
private: private:
QString m_name; QString m_name;
QString m_capital; QString m_capital;

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

@ -1,33 +1,29 @@
import QtQuick 2.15 import QtQuick 2.15
import QtQuick.Window 2.15 import QtQuick.Window 2.15
import I.hate.dictators 1.0
Window { Window {
width: 640 width: 640
height: 480 height: 480
visible: true visible: true
title: qsTr("Flags of the world") title: qsTr("Flags of the world")
id: mainWindow
property CountryType selectedCountry
ListView { ListView {
id: lv id: lv
anchors.fill: parent anchors.left: parent.left
height: parent.height
width: parent.width / 3
model: countries model: countries
delegate: Rectangle { delegate: Country {
width: lv.width/3 }
height: 30
Text {
text: name
font.pixelSize: 20
anchors.verticalCenter: parent.verticalCenter
} }
Image { CountryDetail {
source: "qrc:/assets/flags/"+iso+".svg"
height: parent.height - 4
anchors.right: parent.right anchors.right: parent.right
fillMode: Image.PreserveAspectFit anchors.left: lv.right
anchors.verticalCenter: parent.verticalCenter height: parent.height
} country: selectedCountry
}
} }
} }

@ -203,5 +203,7 @@
<file>assets/data_en-GB.xml</file> <file>assets/data_en-GB.xml</file>
<file>assets/map.svg</file> <file>assets/map.svg</file>
<file>assets/map.svg.txt</file> <file>assets/map.svg.txt</file>
<file>Country.qml</file>
<file>CountryDetail.qml</file>
</qresource> </qresource>
</RCC> </RCC>

Loading…
Cancel
Save