Skip to content

Commit

Permalink
Commit des tvx en cours sur QML. Ne devrait impacter que le build en
Browse files Browse the repository at this point in the history
debug
  • Loading branch information
dguihal@gmail.com committed Jul 11, 2014
1 parent 20a1afc commit 16174b7
Show file tree
Hide file tree
Showing 10 changed files with 461 additions and 206 deletions.
1 change: 1 addition & 0 deletions core/qqhuntpixmapitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class QQHuntPixmapItem : public QObject, public QGraphicsPixmapItem
{
Q_OBJECT
Q_PROPERTY(QPointF pos READ pos WRITE setPos)

public:
explicit QQHuntPixmapItem(QString srcBouchot, QString postId, bool selfItem, QObject *parent = 0);
~QQHuntPixmapItem();
Expand Down
38 changes: 38 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
#include <QDir>
#include <QSettings>

#ifdef QT_DEBUG
#if(QT_VERSION >= QT_VERSION_CHECK(5, 3, 0))
#include "qml/documenthandler.h"
#include <QQmlApplicationEngine>
#include <QQuickWindow>
#endif
#endif //QT_DEBUG

#ifdef Q_OS_UNIX
#undef signals
#include <libnotify/notify.h>
Expand Down Expand Up @@ -58,6 +66,15 @@ void purgeCache()
removeDirRecursive(dirCache.absoluteFilePath("networkCache"));
}

void dumpRecurse(QQuickItem *rootItem)
{
foreach (QQuickItem *item, rootItem->childItems())
{
qDebug() << Q_FUNC_INFO << item->childItems().size() << item->objectName();
dumpRecurse(item);
}
}

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Expand All @@ -75,5 +92,26 @@ int main(int argc, char *argv[])
MainWindow w;
w.show();

#ifdef QT_DEBUG
qmlRegisterType<DocumentHandler>("org.moules.quteqoin", 1, 0, "DocumentHandler");
QQmlApplicationEngine engine(QUrl("qrc:///qml/QQmlMain.qml"));
QQuickWindow *qmlRoot = qobject_cast<QQuickWindow *>(engine.rootObjects().at(0));
if(!qmlRoot)
{
qWarning("Error: Your root item has to be a Window.");
return -1;
}

QQuickItem *qmlRootItem = qmlRoot->contentItem();
dumpRecurse(qmlRootItem);
/*
if(textArea)
{
textArea->setProperty("text", "Lorem ipsum");
qDebug() << Q_FUNC_INFO << "textArea found";
}
*/
#endif

return a.exec();
}
63 changes: 63 additions & 0 deletions qml/QQmlMain.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import QtQuick 2.0
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.1
import org.moules.quteqoin 1.0


ApplicationWindow {
id: root
width: 400
height: 600
visible: true

ColumnLayout {
id: mainLayout
anchors.fill: parent
anchors.margins: 2
spacing: 2

RowLayout {
spacing: 2

ComboBox {
id: tabCB
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter
model: [ "Main", "Slow", "ReadOnly" ]
}

Button {
Layout.minimumWidth: 24
Layout.maximumWidth: 24
Layout.minimumHeight: 24
Layout.maximumHeight: 24
Layout.alignment: Qt.AlignVCenter

iconSource: "/img/settings-icon.png"
}
}

TextArea {
id: textArea

Layout.fillHeight: true
Layout.fillWidth: true

readOnly: true
wrapMode: TextEdit.Wrap
}

DocumentHandler {
id: document
target: textArea
cursorPosition: textArea.cursorPosition
selectionStart: textArea.selectionStart
selectionEnd: textArea.selectionEnd
}

QQmlPalmi {
id: palmi
Layout.fillWidth: true
}
}
}
28 changes: 28 additions & 0 deletions qml/QQmlPalmi.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import QtQuick 2.0
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.1

Item {
id:root
height: postInput.height

ColumnLayout {
id: mainLayout
anchors.fill: parent

RowLayout {
spacing: 2

TextField {
Layout.fillWidth: true
id: postInput
placeholderText: "coin ! coin !"
}

Button {
id: postBtn
text: qsTr("Post")
}
}
}
}
6 changes: 6 additions & 0 deletions qml/QQmlPinni.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import QtQuick 2.0

Pinnipede {
width: 100
height: 62
}
45 changes: 45 additions & 0 deletions qml/documenthandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "documenthandler.h"

DocumentHandler::DocumentHandler(QObject *parent) :
QObject(parent),
m_target(0),
m_doc(0),
m_cursorPosition(-1),
m_selectionStart(0),
m_selectionEnd(0)
{
}

void DocumentHandler::setTarget(QQuickItem *target)
{
m_doc = 0;
m_target = target;
if (!m_target)
return;

QVariant doc = m_target->property("textDocument");
if (doc.canConvert<QQuickTextDocument*>()) {
QQuickTextDocument *qqdoc = doc.value<QQuickTextDocument*>();
if (qqdoc)
m_doc = qqdoc->textDocument();
}
emit targetChanged();
}

void DocumentHandler::setCursorPosition(int position)
{
if (position == m_cursorPosition)
return;

m_cursorPosition = position;
}

void DocumentHandler::setSelectionStart(int position)
{
m_selectionStart = position;
}

void DocumentHandler::setSelectionEnd(int position)
{
m_selectionEnd = position;
}
51 changes: 51 additions & 0 deletions qml/documenthandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef DOCUMENTHANDLER_H
#define DOCUMENTHANDLER_H

#include <QQuickTextDocument>

QT_BEGIN_NAMESPACE
class QTextDocument;
QT_END_NAMESPACE

class DocumentHandler : public QObject
{
Q_OBJECT

Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged)
Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged)
Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged)

public:
explicit DocumentHandler(QObject *parent = 0);

QQuickItem *target() { return m_target; }

void setTarget(QQuickItem *target);

void setCursorPosition(int position);
void setSelectionStart(int position);
void setSelectionEnd(int position);

int cursorPosition() const { return m_cursorPosition; }
int selectionStart() const { return m_selectionStart; }
int selectionEnd() const { return m_selectionEnd; }

signals:
void targetChanged();
void cursorPositionChanged();
void selectionStartChanged();
void selectionEndChanged();

public slots:

private:
QQuickItem *m_target;
QTextDocument *m_doc;

int m_cursorPosition;
int m_selectionStart;
int m_selectionEnd;
};

#endif // DOCUMENTHANDLER_H
6 changes: 6 additions & 0 deletions qml/quteqoin_qml.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/qml">
<file>QQmlMain.qml</file>
<file>QQmlPalmi.qml</file>
</qresource>
</RCC>
Loading

0 comments on commit 16174b7

Please sign in to comment.