Commit ca7387f5 authored by Camilo higuita's avatar Camilo higuita

multiple fixes on linker, linkcarddelegate, etc...

parent aee1f97a
...@@ -135,8 +135,7 @@ Maui.ApplicationWindow ...@@ -135,8 +135,7 @@ Maui.ApplicationWindow
NewLinkDialog NewLinkDialog
{ {
id: newLinkDialog id: newLinkDialog
onLinkSaved: if(owl.insertLink(link)) onLinkSaved: linksView.model.insert(link)
linksView.cardsView.currentItem.update(note)
} }
......
...@@ -17,5 +17,6 @@ ...@@ -17,5 +17,6 @@
<file>src/widgets/CardsList.qml</file> <file>src/widgets/CardsList.qml</file>
<file>src/widgets/CardMenu.qml</file> <file>src/widgets/CardMenu.qml</file>
<file>src/utils/owl.js</file> <file>src/utils/owl.js</file>
<file>src/widgets/LinkCardDelegate.qml</file>
</qresource> </qresource>
</RCC> </RCC>
...@@ -45,31 +45,34 @@ void Linker::extract(const QString &url) ...@@ -45,31 +45,34 @@ void Linker::extract(const QString &url)
{ {
auto data = getUrl(url); auto data = getUrl(url);
QString title = url;
auto titles = query(data, HtmlTag::TITLE); auto titles = query(data, HtmlTag::TITLE);
QStringList imgs ;
// auto tags = query(data, HtmlTag::META); if(!titles.isEmpty())
title = titles[0];
title = title.isEmpty() ? url : title;
QStringList imgs;
// auto tags = query(data, HtmlTag::META);
for(auto img : query(data, HtmlTag::IMG, "src")) for(auto img : query(data, HtmlTag::IMG, "src"))
{ {
if(imgs.contains(img) || img.isEmpty()) continue; if(imgs.contains(img) || img.isEmpty()) continue;
qDebug()<< "IMGAE URL" << img;
if((img.startsWith("http") || img.startsWith("https"))
&& (img.endsWith(".png", Qt::CaseInsensitive) ||
img.endsWith(".jpg", Qt::CaseInsensitive) ||
img.endsWith(".gif", Qt::CaseInsensitive) ||
img.endsWith(".jpeg", Qt::CaseInsensitive)))
if(url.at(url.length()-1) == "/") imgs << img;
{ else continue;
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},
LINK link_data {{OWL::KEYMAP[OWL::KEY::TITLE], title.trimmed()},
{OWL::KEYMAP[OWL::KEY::BODY], data}, {OWL::KEYMAP[OWL::KEY::BODY], data},
{OWL::KEYMAP[OWL::KEY::IMAGE], imgs}}; {OWL::KEYMAP[OWL::KEY::IMAGE], imgs}};
emit previewReady(link_data); emit previewReady(link_data);
......
...@@ -57,12 +57,13 @@ bool Links::insertLink(const QVariantMap &link) ...@@ -57,12 +57,13 @@ bool Links::insertLink(const QVariantMap &link)
for(auto tg : tags) for(auto tg : tags)
this->tag->tagAbstract(tg, OWL::TABLEMAP[OWL::TABLE::LINKS], url, color); this->tag->tagAbstract(tg, OWL::TABLEMAP[OWL::TABLE::LINKS], url, color);
this->links << OWL::DB this->links << OWL::DB
({ ({
{OWL::KEY::LINK, url}, {OWL::KEY::LINK, url},
{OWL::KEY::TITLE, title}, {OWL::KEY::TITLE, title},
{OWL::KEY::COLOR, color}, {OWL::KEY::COLOR, color},
{OWL::KEY::PREVIEW, preview}, {OWL::KEY::PREVIEW, image_path},
{OWL::KEY::PIN, QString::number(pin)}, {OWL::KEY::PIN, QString::number(pin)},
{OWL::KEY::FAV, QString::number(fav)}, {OWL::KEY::FAV, QString::number(fav)},
{OWL::KEY::UPDATED, QDateTime::currentDateTime().toString()}, {OWL::KEY::UPDATED, QDateTime::currentDateTime().toString()},
...@@ -70,7 +71,7 @@ bool Links::insertLink(const QVariantMap &link) ...@@ -70,7 +71,7 @@ bool Links::insertLink(const QVariantMap &link)
}); });
return true; return true;
} } else qDebug()<< "LINK COULD NTO BE INSTED";
return false; return false;
} }
......
...@@ -42,9 +42,12 @@ void LinksModel::sortBy(const int &index, const QString &order) ...@@ -42,9 +42,12 @@ void LinksModel::sortBy(const int &index, const QString &order)
bool LinksModel::insert(const QVariantMap &link) bool LinksModel::insert(const QVariantMap &link)
{ {
const int index = mLinks->items().size(); const int index = mLinks->items().size();
beginInsertRows(QModelIndex(), index, index); if( this->mLinks->insertLink(link))
this->mLinks->insertLink(link); {
endInsertRows(); beginInsertRows(QModelIndex(), index, index);
endInsertRows();
}
return false; return false;
} }
......
import QtQuick 2.9 import QtQuick 2.9
import QtQuick.Controls 2.3 import QtQuick.Controls 2.3
import org.kde.mauikit 1.0 as Maui import org.kde.mauikit 1.0 as Maui
import org.kde.kirigami 2.2 as Kirigami
import "../../widgets" import "../../widgets"
import "../../utils/owl.js" as O import "../../utils/owl.js" as O
...@@ -40,7 +41,7 @@ Maui.Page ...@@ -40,7 +41,7 @@ Maui.Page
Menu Menu
{ {
id: sortMenu id: sortMenu
MenuItem MenuItem
{ {
text: qsTr("Title") text: qsTr("Title")
...@@ -109,7 +110,6 @@ Maui.Page ...@@ -109,7 +110,6 @@ Maui.Page
{ {
id: cardsView id: cardsView
anchors.fill: parent anchors.fill: parent
onItemClicked: linkClicked(cardsView.model.get(index))
holder.emoji: "qrc:/Astronaut.png" holder.emoji: "qrc:/Astronaut.png"
holder.isMask: false holder.isMask: false
holder.title : "No Links!" holder.title : "No Links!"
...@@ -117,6 +117,33 @@ Maui.Page ...@@ -117,6 +117,33 @@ Maui.Page
holder.emojiSize: iconSizes.huge holder.emojiSize: iconSizes.huge
itemHeight: unit * 250 itemHeight: unit * 250
model: linksModel model: linksModel
delegate: LinkCardDelegate
{
id: delegate
cardWidth: Math.min(cardsView.cellWidth, cardsView.itemWidth) - Kirigami.Units.largeSpacing * 2
cardHeight: cardsView.itemHeight
anchors.left: parent.left
anchors.leftMargin: cardsView.width <= cardsView.itemWidth ? 0 : (index % 2 === 0 ? Math.max(0, cardsView.cellWidth - cardsView.itemWidth) :
cardsView.cellWidth)
onClicked:
{
currentIndex = index
linkClicked(cardsView.model.get(index))
}
onRightClicked:
{
currentIndex = index
cardsView.menu.popup()
}
onPressAndHold:
{
currentIndex = index
cardsView.menu.popup()
}
}
Connections Connections
{ {
......
...@@ -7,8 +7,8 @@ import "../../widgets" ...@@ -7,8 +7,8 @@ import "../../widgets"
Maui.Popup Maui.Popup
{ {
parent: parent parent: parent
heightHint: 0.95 heightHint: 0.97
widthHint: 0.95 widthHint: 0.97
maxWidth: 800*unit maxWidth: 800*unit
maxHeight: maxWidth maxHeight: maxWidth
......
...@@ -145,7 +145,6 @@ Maui.Page ...@@ -145,7 +145,6 @@ Maui.Page
Layout.fillHeight: true Layout.fillHeight: true
Layout.fillWidth: true Layout.fillWidth: true
width: parent.width width: parent.width
onItemClicked: noteClicked(notesModel.get(index))
holder.emoji: "qrc:/Type.png" holder.emoji: "qrc:/Type.png"
holder.emojiSize: iconSizes.huge holder.emojiSize: iconSizes.huge
holder.isMask: false holder.isMask: false
...@@ -153,6 +152,34 @@ Maui.Page ...@@ -153,6 +152,34 @@ Maui.Page
holder.body: "Click here to create a new note" holder.body: "Click here to create a new note"
model: notesModel model: notesModel
delegate: CardDelegate
{
id: delegate
cardWidth: Math.min(cardsView.cellWidth, cardsView.itemWidth) - Kirigami.Units.largeSpacing * 2
cardHeight: cardsView.itemHeight
anchors.left: parent.left
anchors.leftMargin: cardsView.width <= cardsView.itemWidth ? 0 : (index % 2 === 0 ? Math.max(0, cardsView.cellWidth - cardsView.itemWidth) :
cardsView.cellWidth)
onClicked:
{
currentIndex = index
noteClicked(notesModel.get(index))
}
onRightClicked:
{
currentIndex = index
cardsView.menu.popup()
}
onPressAndHold:
{
currentIndex = index
cardsView.menu.popup()
}
}
Connections Connections
{ {
target: cardsView.holder target: cardsView.holder
......
...@@ -36,33 +36,5 @@ GridView ...@@ -36,33 +36,5 @@ GridView
id: cardMenu id: cardMenu
} }
delegate: CardDelegate
{
id: delegate
cardWidth: Math.min(control.cellWidth, control.itemWidth) - Kirigami.Units.largeSpacing * 2
cardHeight: itemHeight
anchors.left: parent.left
anchors.leftMargin: control.width <= control.itemWidth ? 0 : (index % 2 === 0 ? Math.max(0, control.cellWidth - control.itemWidth) :
control.cellWidth)
onClicked:
{
currentIndex = index
itemClicked(index)
}
onRightClicked:
{
currentIndex = index
cardMenu.popup()
}
onPressAndHold:
{
currentIndex = index
cardMenu.popup()
}
}
ScrollBar.vertical: ScrollBar{ id:scrollBar; visible: !isMobile} ScrollBar.vertical: ScrollBar{ id:scrollBar; visible: !isMobile}
} }
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.0
import org.kde.kirigami 2.2 as Kirigami
ItemDelegate
{
id: control
property string noteColor : model.color ? model.color : viewBackgroundColor
property int cardWidth: visible ? unit * 200 : 0
property int cardHeight: visible ? unit * 120 : 0
property int cardRadius: radiusV
property bool condition : true
signal rightClicked();
visible: condition
width: cardWidth
height: cardHeight
hoverEnabled: !isMobile
background: Rectangle
{
color: "transparent"
}
MouseArea
{
anchors.fill: parent
acceptedButtons: Qt.RightButton
onClicked:
{
if(!isMobile && mouse.button === Qt.RightButton)
rightClicked()
}
}
Rectangle
{
id: card
z: -999
anchors.centerIn: control
anchors.fill: control
border.color: Qt.darker(noteColor, 1.2)
color: noteColor
radius: cardRadius
Loader
{
id: imgLoader
anchors.fill: parent
anchors.margins: space.small
clip: true
sourceComponent: typeof model.preview !== 'undefined' ? imgComponent : undefined
}
}
Rectangle
{
anchors.fill: parent
color: hovered? "#333" : "transparent"
z: 999
opacity: 0.2
radius: cardRadius
}
Item
{
visible: title.text.length > 0
height: layout.implicitHeight + space.big
anchors.right: parent.right
anchors.left: parent.left
anchors.bottom: parent.bottom
anchors.margins: unit
ColumnLayout
{
id: layout
anchors.fill: parent
anchors.margins: space.small
spacing: 0
Label
{
id: date
Layout.fillWidth: true
Layout.fillHeight: true
padding: 0
visible: date.text.length > 0
text: Qt.formatDateTime(new Date(model.updated), "d MMM h:mm")
color: model.color ? Qt.darker(model.color) : textColor
elide: Qt.ElideRight
wrapMode: TextEdit.WrapAnywhere
font.weight: Font.Bold
font.bold: true
font.pointSize: fontSizes.small
}
Label
{
id: title
padding: 0
Layout.fillWidth: true
Layout.fillHeight: true
text: model.title ? model.title : ""
color: model.color ? Qt.darker(model.color, 3) : textColor
elide: Qt.ElideRight
wrapMode: TextEdit.WrapAnywhere
font.weight: Font.Bold
font.bold: true
font.pointSize: fontSizes.large
clip: true
}
}
Rectangle
{
anchors.fill: parent
color: noteColor
z: -1
}
}
Component
{
id: bodyComponent
TextArea
{
id: body
padding: 0
visible: typeof model.body !== 'undefined'
enabled: false
text: model.body ? model.body : ""
color: model.color ? Qt.darker(model.color, 3) : textColor
wrapMode: TextEdit.WrapAnywhere
textFormat: TextEdit.RichText
font.pointSize: fontSizes.big
background: Rectangle
{
color: "transparent"
}
}
}
Component
{
id: imgComponent
Image
{
id: img
visible: status === Image.Ready
asynchronous: true
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
height: parent.height
width: parent.width
sourceSize.height: height
sourceSize.width: width
fillMode: Image.PreserveAspectCrop
source: model.preview ? "file://"+encodeURIComponent( model.preview ) : ''
layer.enabled: img.visible
layer.effect: OpacityMask
{
maskSource: Item
{
width: img.width
height: img.height
Rectangle
{
anchors.centerIn: parent
width: img.width
height: img.height
radius: cardRadius
// radius: Math.min(width, height)
}
}
}
}
}
function update(item)
{
console.log("update link color", item.color, item.tag)
model.title = item.title
model.body = item.body
model.color = item.color
model.pin = item.pin ? 1 : 0
model.fav = item.fav ? 1 : 0
model.updated = item.updated
model.tag = item.tag.join(",")
}
}
...@@ -235,7 +235,7 @@ Maui.Popup ...@@ -235,7 +235,7 @@ Maui.Popup
function fill(link) function fill(link)
{ {
title.text = link.title[0] title.text = link.title
populatePreviews(link.image) populatePreviews(link.image)
open() open()
...@@ -254,8 +254,8 @@ Maui.Popup ...@@ -254,8 +254,8 @@ Maui.Popup
{ {
var data = ({ var data = ({
link : link.text, link : link.text,
title: title.text.trim(), title: title.text,
preview: previewList.count > 0 ? previewList.model.get(previewList.currentIndex).url : "", preview: previewList.count > 0 ? previewList.model.get(previewList.currentIndex).url : "",
color: selectedColor, color: selectedColor,
tag: tagBar.getTags(), tag: tagBar.getTags(),
pin: pinButton.checked, pin: pinButton.checked,
......
<!DOCTYPE RCC>
<RCC version="1.0"/>
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