Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit f8c760c9 authored by Camilo Higuita's avatar Camilo Higuita

switch between grid and list view for notes and links

parent d6634591
......@@ -77,5 +77,8 @@ HEADERS += \
src/linker.h \
src/utils/htmlparser.h
INCLUDEPATH += \
src/utils/
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
......@@ -71,7 +71,18 @@ Maui.ApplicationWindow
footBar.leftContent: Maui.ToolButton
{
iconName: "document-share"
iconName: swipeView.currentItem.cardsView.gridView ? "view-list-icons" : "view-list-details"
onClicked:
{
switch(swipeView.currentIndex)
{
case views.notes:
notesView.cardsView.gridView = !notesView.cardsView.gridView
notesView.cardsView.refresh()
break
}
}
}
footBar.rightContent: Maui.ToolButton
......@@ -113,6 +124,7 @@ Maui.ApplicationWindow
SwipeView
{
id: swipeView
anchors.fill: parent
currentIndex: views.notes
......
#include "linker.h"
#include <QEventLoop>
#include "owl.h"
#include "qgumbodocument.h"
#include "qgumbonode.h"
#include "utils/htmlparser.h"
Linker::Linker(QObject *parent) : QObject(parent)
{
......@@ -14,7 +12,33 @@ Linker::Linker(QObject *parent) : QObject(parent)
void Linker::extract(const QString &url)
{
auto data = this->getUrl(url);
qDebug()<< query(data, "title");
auto titles = query(data, HtmlTag::TITLE);
QStringList imgs ;
for(auto img : query(data, HtmlTag::IMG, "src"))
{
if(imgs.contains(img) || img.isEmpty()) continue;
if(url.at(url.length()-1) == "/")
{
if(img.startsWith("http"))
imgs << img;
else
imgs << url+img;
}else
{
if(img.startsWith("http"))
imgs << img;
else
imgs << url+"/"+img;
}
}
LINK link_data {{OWL::KEYMAP[OWL::KEY::TITLE], titles},
{OWL::KEYMAP[OWL::KEY::BODY], data},
{OWL::KEYMAP[OWL::KEY::IMAGE], imgs}};
emit previewReady(link_data);
}
QByteArray Linker::getUrl(const QString &url)
......@@ -49,13 +73,21 @@ QByteArray Linker::getUrl(const QString &url)
return QByteArray();
}
QString Linker::query(const QByteArray &array,const HtmlTag &tag)
QStringList Linker::query(const QByteArray &array, const HtmlTag &tag, const QString &attribute)
{
QStringList res;
auto doc = QGumboDocument::parse(array);
auto root = doc.rootNode();
auto nodes = root.getElementsByTagName(tag);
Q_ASSERT(nodes.size() == 1);
auto title = nodes.front();
return title.innerText();
auto node = root.getElementsByTagName(tag);
for(const auto &i : node)
{
if(attribute.isEmpty())
res << i.innerText();
else res << i.getAttribute(attribute);
}
return res;
}
......@@ -6,6 +6,9 @@
#include <QNetworkReply>
#include <QUrl>
#include "qgumbodocument.h"
#include "qgumbonode.h"
typedef QVariantMap LINK;
class Linker : public QObject
......@@ -18,10 +21,12 @@ public:
private:
QByteArray getUrl(const QString &url);
QString query(const QByteArray &array, const QString &qq);
QStringList query(const QByteArray &array, const HtmlTag &tag, const QString &attribute = QString());
QGumboNodes nodes;
signals:
void previewReady(LINK data);
void previewReady(QVariantMap link);
public slots:
......
......@@ -90,6 +90,7 @@ enum class KEY :uint8_t
ADD_DATE,
TAG,
PREVIEW,
IMAGE,
NONE
};
......@@ -107,7 +108,8 @@ static const DB KEYMAP =
{KEY::COLOR, "color"},
{KEY::ADD_DATE, "addDate"},
{KEY::TAG, "tag"},
{KEY::PREVIEW, "preview"}
{KEY::PREVIEW, "preview"},
{KEY::IMAGE, "image"}
};
const QString CollectionDBPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)+"/buho/";
......
......@@ -8,6 +8,7 @@ Maui.Page
property var currentNote : ({})
signal noteClicked(var note)
headBarVisible: false
CardsView
{
......@@ -19,11 +20,9 @@ Maui.Page
function populate()
{
var data = owl.getNotes()
for(var i in data)
{
console.log("OCLOR", data[i].color)
for(var i in data)
append(data[i])
}
}
function append(note)
......
......@@ -5,9 +5,11 @@ import org.kde.maui 1.0 as Maui
GridView
{
property bool gridView : true
property alias holder : holder
readonly property int defaultSize : Kirigami.Units.devicePixelRatio * 200
property int itemWidth : !isMobile ? Kirigami.Units.devicePixelRatio * 200 : parent.width
property int itemWidth : !gridView ? parent.width : Kirigami.Units.devicePixelRatio * 200
property int itemHeight: Kirigami.Units.devicePixelRatio * 120
property int itemSpacing: space.huge
......@@ -23,7 +25,7 @@ GridView
message: "<h3>No notes!</h3><p>You can create new notes<br>links and books</p>"
}
model: ListModel { }
model: ListModel { id: cardsModel}
delegate: CardDelegate
{
......@@ -38,7 +40,7 @@ GridView
}
}
onWidthChanged: if(!isMobile) adaptGrid()
// onWidthChanged: if(!isMobile && gridView) adaptGrid()
function adaptGrid()
{
......@@ -50,4 +52,10 @@ GridView
cellWidth = size
}
function refresh()
{
model = cardsModel
}
}
......@@ -3,12 +3,13 @@ import QtQuick.Controls 2.2
import QtQuick.Layouts 1.0
import org.kde.maui 1.0 as Maui
import org.buho.editor 1.0
import org.kde.kirigami 2.2 as Kirigami
Popup
{
parent: ApplicationWindow.overlay
height: previewReady ? parent.height * (isMobile ? 0.8 : 0.7) :
toolBarHeight
toolBarHeight
width: parent.width * (isMobile ? 0.9 : 0.7)
signal linkSaved(var note)
......@@ -19,6 +20,16 @@ Popup
padding: 1
Connections
{
target: linker
onPreviewReady:
{
previewReady = true
fill(link)
}
}
Rectangle
{
id: bg
......@@ -60,29 +71,51 @@ Popup
placeholderText: qsTr("Title")
font.weight: Font.Bold
font.bold: true
font.pointSize: fontSizes.large
background: Rectangle
{
color: "transparent"
}
}
ScrollView
Item
{
Layout.fillHeight: true
Layout.fillWidth: true
Layout.margins: space.medium
Layout.fillHeight: true
visible: previewReady
TextArea
ListView
{
id: body
placeholderText: qsTr("Body")
textFormat : TextEdit.AutoText
enabled: false
background: Rectangle
id: previewList
anchors.fill: parent
anchors.centerIn: parent
clip: true
snapMode: ListView.SnapOneItem
orientation: ListView.Horizontal
interactive: count > 1
model: ListModel{}
delegate: ItemDelegate
{
color: "transparent"
height: previewList.height
width: previewList.width
background: Rectangle
{
color: "transparent"
}
Image
{
id: img
source: model.url
fillMode: Image.PreserveAspectFit
asynchronous: true
width: parent.width
height: parent.height
sourceSize.height: height
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
}
}
}
}
......@@ -95,6 +128,7 @@ Popup
Layout.alignment: Qt.AlignRight
spacing: space.medium
visible: previewReady
layoutDirection: Qt.RightToLeft
Button
{
id: save
......@@ -127,11 +161,17 @@ Popup
function fill(note)
{
document.load("qrc:/texteditor.html")
title.text = note.title
body.text = note.body
selectedColor = note.color
title.text = note.title[0]
populatePreviews(note.image)
open()
}
function populatePreviews(imgs)
{
for(var i in imgs)
{
console.log("IMAGE:", imgs[i])
previewList.model.append({url : imgs[i]})}
}
}
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