Commit f9a6c5f7 authored by camilo higuita's avatar camilo higuita

workflow and ux of the books feature

parent 6a8fe9b1
......@@ -13,5 +13,6 @@
<file>buho96.png</file>
<file>buho.svg</file>
<file>booklet.svg</file>
<file>notepad.png</file>
</qresource>
</RCC>
......@@ -4,7 +4,13 @@
Booklet::Booklet(Syncer *_syncer, QObject *parent) : MauiList(parent),
syncer(_syncer)
{
connect(this->syncer, &Syncer::bookletReady, [&](FMH::MODEL_LIST booklets)
{
emit this->preListChanged();
this->m_list = booklets;
emit this->postListChanged();
});
connect(this, &Booklet::bookChanged, syncer, &Syncer::getBooklet);
}
FMH::MODEL_LIST Booklet::items() const
......@@ -37,11 +43,12 @@ QString Booklet::getBook() const
return m_book;
}
void Booklet::setBook(const QString &book)
void Booklet::setBook(const QString &book) //book id
{
if (m_book == book)
return;
this->setBookTitle(book);
m_book = book;
emit bookChanged(m_book);
}
......@@ -75,3 +82,20 @@ void Booklet::sortList()
{
}
void Booklet::setBookTitle(const QString &title)
{
if (m_bookTitle == title)
return;
m_bookTitle = title;
emit bookTitleChanged(m_bookTitle);
}
QVariantMap Booklet::get(const int &index) const
{
if(index >= this->m_list.size() || index < 0)
return QVariantMap();
return FMH::toMap(this->m_list.at(index));
}
......@@ -18,6 +18,7 @@ class Booklet : public MauiList
Q_PROPERTY(SORTBY sortBy READ getSortBy WRITE setSortBy NOTIFY sortByChanged)
Q_PROPERTY(ORDER order READ getOrder WRITE setOrder NOTIFY orderChanged)
Q_PROPERTY(QString book READ getBook NOTIFY bookChanged)
Q_PROPERTY(QString bookTitle READ getBookTitle NOTIFY bookTitleChanged)
public:
Booklet(Syncer *_syncer = nullptr, QObject *parent = nullptr);
......@@ -50,7 +51,14 @@ public:
QString getBook() const;
void setBook(const QString &book);
void setBookTitle(const QString &title);
QString getBookTitle() const
{
return m_bookTitle;
}
public slots:
QVariantMap get(const int &index) const;
void insert(const QVariantMap &data);
void update(const QVariantMap &data, const int &index);
void remove(const int &index);
......@@ -61,15 +69,19 @@ private:
void sortList();
SORTBY sort = SORTBY::MODIFIED;
ORDER order = ORDER::DESC;
QString m_book;
QString m_bookTitle;
signals:
void sortByChanged();
void orderChanged();
void bookChanged(QString book);
void bookTitleChanged(QString bookTitle);
};
#endif // BOOKLET_H
......@@ -8,6 +8,8 @@ Books::Books(QObject *parent) : MauiList(parent),
{
this->syncer->setProvider(new NextNote);
connect(this, &Books::currentBookChanged, this, &Books::openBook);
connect(syncer, &Syncer::booksReady, [&](FMH::MODEL_LIST books)
{
emit this->preListChanged();
......@@ -100,7 +102,9 @@ void Books::openBook(const int &index)
{
if(index >= this->m_list.size() || index < 0)
return;
this->m_booklet->setBook(this->m_list.at(index)[FMH::MODEL_KEY::ID]);
this->m_booklet->setBookTitle(this->m_list.at(index)[FMH::MODEL_KEY::TITLE]);
}
void Books::setCurrentBook(int currentBook)
......@@ -109,6 +113,5 @@ void Books::setCurrentBook(int currentBook)
return;
m_currentBook = currentBook;
this->openBook(m_currentBook);
emit currentBookChanged(m_currentBook);
}
......@@ -121,6 +121,13 @@ void Syncer::insertBook(FMH::MODEL &book)
emit this->bookInserted(book, {STATE::TYPE::LOCAL, STATE::STATUS::OK, "Book inserted locally sucessfully"});
}
void Syncer::getBooklet(const QString &id)
{
const auto res = this->db->getDBData(QString("select * from booklets where book = '%1'").arg(id));
emit this->bookletReady(res);
}
void Syncer::insertBooklet(const QString &bookId, FMH::MODEL &booklet)
{
if(!this->insertBookletLocal(bookId, booklet))
......
......@@ -286,7 +286,6 @@ signals:
void bookletInserted(FMH::MODEL booklet, STATE state);
void bookletUpdated(FMH::MODEL booklet, STATE state);
void bookletRemoved(FMH::MODEL booklet, STATE state);
void bookletReady(FMH::MODEL booklet);
void bookletReady(FMH::MODEL_LIST booklets);
......
......@@ -10,6 +10,7 @@ Item
signal exit()
Maui.BaseModel
{
id: _bookletModel
......@@ -24,34 +25,52 @@ Item
headBar.leftContent: [
ToolButton
{
icon.name: "go-previous"
onClicked: control.exit()
},
TextField
{
id: title
Layout.fillWidth: true
Layout.margins: space.medium
placeholderText: qsTr("New chapter...")
font.weight: Font.Bold
font.bold: true
font.pointSize: fontSizes.large
// Kirigami.Theme.backgroundColor: selectedColor
// Kirigami.Theme.textColor: Qt.darker(selectedColor, 2.5)
// color: fgColor
background: Rectangle
{
color: "transparent"
}
}
{
icon.name: "go-previous"
onClicked: control.exit()
},
ToolButton
{
icon.name: "document-save"
// onClicked: control.exit()
},
TextField
{
id: title
Layout.fillWidth: true
Layout.margins: space.medium
placeholderText: qsTr("New chapter...")
font.weight: Font.Bold
font.bold: true
font.pointSize: fontSizes.large
// Kirigami.Theme.backgroundColor: selectedColor
// Kirigami.Theme.textColor: Qt.darker(selectedColor, 2.5)
// color: fgColor
background: Rectangle
{
color: "transparent"
}
}
]
Maui.Holder
{
id: _holder
visible: !_listView.count
emoji: "qrc:/Type.png"
emojiSize: iconSizes.huge
isMask: false
title : "Nothing to edit!"
body: "Select a chapter or create a new one"
}
Maui.Editor
{
anchors.fill: parent
visible: !_holder.visible
}
Maui.Dialog
......@@ -73,43 +92,89 @@ Item
id: _drawer
edge: Qt.RightEdge
width: Kirigami.Units.gridUnit * 16
height: parent.height - headBar.height
y: headBar.height
height: parent.height - _page.headBar.height
y: _page.headBar.height
modal: !isWide
visible: _holder.visible
ListView
contentItem: Maui.Page
{
anchors.fill: parent
model: _bookletModel
delegate: Maui.LabelDelegate
title: "argh"
headBar.visible: true
headBar.rightContent: ToolButton
{
label: model.title
icon.name: "view-sort"
}
}
Rectangle
{
z: 999
anchors.bottom: parent.bottom
anchors.margins: toolBarHeight
anchors.horizontalCenter: parent.horizontalCenter
height: toolBarHeight
width: height
background: Rectangle
{
color: "transparent"
}
color: Kirigami.Theme.highlightColor
radius: radiusV
Maui.Holder
{
anchors.margins: space.huge
visible: !_listView.count
emoji: "qrc:/E-reading.png"
emojiSize: iconSizes.huge
isMask: false
title : "This book is empty!"
body: "Start by creating a new chapter for your book by clicking the + icon"
}
ToolButton
ListView
{
anchors.centerIn: parent
icon.name: "list-add"
icon.color: Qt.darker(parent.color, 2)
id: _listView
anchors.fill: parent
model: _bookletModel
clip: true
delegate: Maui.LabelDelegate
{
id: _delegate
label: index + " - " + model.title
Connections
{
target:_delegate
onClicked:
{
_listView.currentIndex = index
console.log("Booklet cliked:", _booksList.booklet.get(index).url, _booksList.booklet.get(index).content )
}
}
}
onClicked: _newChapter.open()
}
Rectangle
{
z: 999
anchors.bottom: parent.bottom
anchors.margins: space.huge
anchors.horizontalCenter: parent.horizontalCenter
height: toolBarHeight
width: height
color: Kirigami.Theme.positiveTextColor
radius: radiusV
ToolButton
{
anchors.centerIn: parent
icon.name: "list-add"
icon.color: "white"
onClicked: _newChapter.open()
}
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment