Commit aa546e13 authored by Camilo higuita's avatar Camilo higuita

use more mauikit controls and tweaks on the baselist props

parent c8c9683d
...@@ -42,7 +42,6 @@ SOURCES += \ ...@@ -42,7 +42,6 @@ SOURCES += \
main.cpp \ main.cpp \
src/db/db.cpp \ src/db/db.cpp \
src/buho.cpp \ src/buho.cpp \
src/documenthandler.cpp \
src/linker.cpp \ src/linker.cpp \
src/utils/htmlparser.cpp \ src/utils/htmlparser.cpp \
src/models/notes/notes.cpp \ src/models/notes/notes.cpp \
...@@ -73,7 +72,6 @@ HEADERS += \ ...@@ -73,7 +72,6 @@ HEADERS += \
src/db/db.h \ src/db/db.h \
src/buho.h \ src/buho.h \
src/utils/owl.h \ src/utils/owl.h \
src/documenthandler.h \
src/linker.h \ src/linker.h \
src/utils/htmlparser.h \ src/utils/htmlparser.h \
src/models/notes/notes.h \ src/models/notes/notes.h \
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#endif #endif
#include "src/buho.h" #include "src/buho.h"
#include "src/documenthandler.h"
#include "src/linker.h" #include "src/linker.h"
#include "models/basemodel.h" #include "models/basemodel.h"
...@@ -65,8 +64,7 @@ int main(int argc, char *argv[]) ...@@ -65,8 +64,7 @@ int main(int argc, char *argv[])
Linker linker; Linker linker;
context->setContextProperty("linker", &linker); context->setContextProperty("linker", &linker);
qmlRegisterUncreatableMetaObject(OWL::staticMetaObject, "Owl", 1, 0, "KEY", "Error"); qmlRegisterUncreatableMetaObject(OWL::staticMetaObject, "OWL", 1, 0, "KEY", "Error");
qmlRegisterType<DocumentHandler>("org.buho.editor", 1, 0, "DocumentHandler");
qmlRegisterUncreatableType<BaseList>("BaseList", 1, 0, "BaseList", QStringLiteral("BaseList should not be created in QML")); qmlRegisterUncreatableType<BaseList>("BaseList", 1, 0, "BaseList", QStringLiteral("BaseList should not be created in QML"));
qmlRegisterType<BaseModel>("BuhoModel", 1, 0, "BuhoModel"); qmlRegisterType<BaseModel>("BuhoModel", 1, 0, "BuhoModel");
......
This diff is collapsed.
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef DOCUMENTHANDLER_H
#define DOCUMENTHANDLER_H
#include <QFont>
#include <QObject>
#include <QTextCursor>
#include <QUrl>
QT_BEGIN_NAMESPACE
class QTextDocument;
class QQuickTextDocument;
QT_END_NAMESPACE
class DocumentHandler : public QObject
{
Q_OBJECT
Q_PROPERTY(QQuickTextDocument *document READ document WRITE setDocument NOTIFY documentChanged)
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)
Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor NOTIFY textColorChanged)
Q_PROPERTY(QString fontFamily READ fontFamily WRITE setFontFamily NOTIFY fontFamilyChanged)
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
Q_PROPERTY(bool bold READ bold WRITE setBold NOTIFY boldChanged)
Q_PROPERTY(bool uppercase READ uppercase WRITE setUppercase NOTIFY uppercaseChanged)
Q_PROPERTY(bool italic READ italic WRITE setItalic NOTIFY italicChanged)
Q_PROPERTY(bool underline READ underline WRITE setUnderline NOTIFY underlineChanged)
Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
Q_PROPERTY(QString fileName READ fileName NOTIFY fileUrlChanged)
Q_PROPERTY(QString fileType READ fileType NOTIFY fileUrlChanged)
Q_PROPERTY(QUrl fileUrl READ fileUrl NOTIFY fileUrlChanged)
public:
explicit DocumentHandler(QObject *parent = nullptr);
QQuickTextDocument *document() const;
void setDocument(QQuickTextDocument *document);
int cursorPosition() const;
void setCursorPosition(int position);
int selectionStart() const;
void setSelectionStart(int position);
int selectionEnd() const;
void setSelectionEnd(int position);
QString fontFamily() const;
void setFontFamily(const QString &family);
QColor textColor() const;
void setTextColor(const QColor &color);
Qt::Alignment alignment() const;
void setAlignment(Qt::Alignment alignment);
bool bold() const;
void setBold(bool bold);
bool uppercase() const;
void setUppercase(bool uppercase);
bool italic() const;
void setItalic(bool italic);
bool underline() const;
void setUnderline(bool underline);
int fontSize() const;
void setFontSize(int size);
QString fileName() const;
QString fileType() const;
QUrl fileUrl() const;
public Q_SLOTS:
void load(const QUrl &fileUrl);
void saveAs(const QUrl &fileUrl);
Q_SIGNALS:
void documentChanged();
void cursorPositionChanged();
void selectionStartChanged();
void selectionEndChanged();
void fontFamilyChanged();
void textColorChanged();
void alignmentChanged();
void boldChanged();
void uppercaseChanged();
void italicChanged();
void underlineChanged();
void fontSizeChanged();
void textChanged();
void fileUrlChanged();
void loaded(const QString &text);
void error(const QString &message);
private:
void reset();
QTextCursor textCursor() const;
QTextDocument *textDocument() const;
void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
QQuickTextDocument *m_document;
int m_cursorPosition;
int m_selectionStart;
int m_selectionEnd;
QFont m_font;
int m_fontSize;
QUrl m_fileUrl;
};
#endif // DOCUMENTHANDLER_H
...@@ -7,15 +7,59 @@ ...@@ -7,15 +7,59 @@
class BaseList : public QObject class BaseList : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(OWL::KEY sortBy READ getSortBy WRITE setSortBy NOTIFY sortByChanged)
Q_PROPERTY(ORDER order READ getOrder WRITE setOrder NOTIFY orderChanged)
public: public:
explicit BaseList(QObject *parent = nullptr); explicit BaseList(QObject *parent = nullptr);
enum ORDER : uint8_t
{
DESC,
ASC
};
Q_ENUM(ORDER)
Q_ENUM(OWL::KEY)
//* To be overrided *// //* To be overrided *//
virtual OWL::DB_LIST items() const {return OWL::DB_LIST({{}});} virtual OWL::DB_LIST items() const {return OWL::DB_LIST({{}});}
virtual void setSortBy(const OWL::KEY &sort)
{
if(this->sort == sort)
return;
this->sort = sort;
emit this->sortByChanged();
}
virtual OWL::KEY getSortBy() const
{
return this->sort;
}
virtual void setOrder(const ORDER &order)
{
if(this->order == order)
return;
this->order = order;
emit this->orderChanged();
}
virtual ORDER getOrder() const
{
return this->order;
}
protected: protected:
OWL::KEY sort = OWL::KEY::UPDATED;
ORDER order = ORDER::DESC;
signals: signals:
void orderChanged();
void sortByChanged();
void preItemAppended(); void preItemAppended();
void postItemAppended(); void postItemAppended();
void preItemRemoved(int index); void preItemRemoved(int index);
...@@ -63,12 +107,6 @@ public slots: ...@@ -63,12 +107,6 @@ public slots:
Q_UNUSED(index); Q_UNUSED(index);
return false; return false;
} }
virtual void sortBy(const int &role, const QString &order)
{
Q_UNUSED(role);
Q_UNUSED(order);
}
}; };
#endif // BASELIST_H #endif // BASELIST_H
...@@ -14,15 +14,19 @@ Links::Links(QObject *parent) : BaseList(parent) ...@@ -14,15 +14,19 @@ Links::Links(QObject *parent) : BaseList(parent)
{ {
this->db = DB::getInstance(); this->db = DB::getInstance();
this->tag = Tagging::getInstance(OWL::App, OWL::version, "org.kde.buho", OWL::comment); this->tag = Tagging::getInstance(OWL::App, OWL::version, "org.kde.buho", OWL::comment);
this->sortBy(OWL::KEY::UPDATED, "DESC"); this->sortList();
connect(this, &Links::sortByChanged, this, &Links::sortList);
connect(this, &Links::orderChanged, this, &Links::sortList);
} }
void Links::sortBy(const int &role, const QString &order) void Links::sortList()
{ {
emit this->preListChanged(); emit this->preListChanged();
this->links = this->db->getDBData(QString("select * from links ORDER BY %1 %2").arg(OWL::KEYMAP[static_cast<OWL::KEY>(role)], order)); this->links = this->db->getDBData(QString("select * from links ORDER BY %1 %2").arg(
OWL::KEYMAP[this->sort],
this->order == ORDER::ASC ? "asc" : "desc"));
emit this->postListChanged(); emit this->postListChanged();
} }
QVariantMap Links::get(const int &index) const QVariantMap Links::get(const int &index) const
...@@ -175,7 +179,7 @@ bool Links::remove(const int &index) ...@@ -175,7 +179,7 @@ bool Links::remove(const int &index)
if(this->db->remove(OWL::TABLEMAP[OWL::TABLE::LINKS], link)) if(this->db->remove(OWL::TABLEMAP[OWL::TABLE::LINKS], link))
{ {
this->links.removeAt(index); this->links.removeAt(index);
emit this->postItemRemoved(); emit this->postItemRemoved();
return true; return true;
} }
......
...@@ -19,11 +19,11 @@ private: ...@@ -19,11 +19,11 @@ private:
Tagging *tag; Tagging *tag;
DB *db; DB *db;
OWL::DB_LIST links; OWL::DB_LIST links;
void sortList();
signals: signals:
public slots: public slots:
void sortBy(const int &role, const QString &order = "DESC") override;
QVariantMap get(const int &index) const override; QVariantMap get(const int &index) const override;
bool insert(const QVariantMap &link) override; bool insert(const QVariantMap &link) override;
bool update(const int &index, const QVariant &value, const int &role) override; //deprecrated bool update(const int &index, const QVariant &value, const int &role) override; //deprecrated
......
...@@ -14,13 +14,19 @@ Notes::Notes(QObject *parent) : BaseList(parent) ...@@ -14,13 +14,19 @@ Notes::Notes(QObject *parent) : BaseList(parent)
qDebug()<< "CREATING NOTES LIST"; qDebug()<< "CREATING NOTES LIST";
this->db = DB::getInstance(); this->db = DB::getInstance();
this->tag = Tagging::getInstance(OWL::App, OWL::version, "org.kde.buho", OWL::comment); this->tag = Tagging::getInstance(OWL::App, OWL::version, "org.kde.buho", OWL::comment);
this->sortBy(OWL::KEY::UPDATED, "DESC"); this->sortList();
connect(this, &Notes::sortByChanged, this, &Notes::sortList);
connect(this, &Notes::orderChanged, this, &Notes::sortList);
} }
void Notes::sortBy(const int &role, const QString &order) void Notes::sortList()
{ {
emit this->preListChanged(); emit this->preListChanged();
this->notes = this->db->getDBData(QString("select * from notes ORDER BY %1 %2").arg(OWL::KEYMAP[static_cast<OWL::KEY>(role)], order)); this->notes = this->db->getDBData(QString("select * from notes ORDER BY %1 %2").arg(
OWL::KEYMAP[this->sort],
this->order == ORDER::ASC ? "asc" : "desc"));
emit this->postListChanged(); emit this->postListChanged();
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <QObject> #include <QObject>
#include "./../baselist.h" #include "./../baselist.h"
#include "owl.h"
class DB; class DB;
class Tagging; class Tagging;
...@@ -10,9 +11,7 @@ class Tagging; ...@@ -10,9 +11,7 @@ class Tagging;
class Notes : public BaseList class Notes : public BaseList
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit Notes(QObject *parent = nullptr); explicit Notes(QObject *parent = nullptr);
OWL::DB_LIST items() const override; OWL::DB_LIST items() const override;
...@@ -20,6 +19,7 @@ private: ...@@ -20,6 +19,7 @@ private:
Tagging *tag; Tagging *tag;
DB *db; DB *db;
OWL::DB_LIST notes; OWL::DB_LIST notes;
void sortList();
signals: signals:
...@@ -27,7 +27,6 @@ public slots: ...@@ -27,7 +27,6 @@ public slots:
QVariantList getTags(const int &index); QVariantList getTags(const int &index);
QVariantMap get(const int &index) const override; QVariantMap get(const int &index) const override;
void sortBy(const int &role, const QString &order = "DESC") override;
bool insert(const QVariantMap &note) override; bool insert(const QVariantMap &note) override;
bool update(const int &index, const QVariant &value, const int &role) override; //deprecrated bool update(const int &index, const QVariant &value, const int &role) override; //deprecrated
bool update(const QVariantMap &data, const int &index) override; bool update(const QVariantMap &data, const int &index) override;
......
...@@ -76,7 +76,7 @@ namespace OWL ...@@ -76,7 +76,7 @@ namespace OWL
{TABLE::LINKS_TAGS,"links_tags"} {TABLE::LINKS_TAGS,"links_tags"}
}; };
enum KEY :uint8_t enum KEY : uint8_t
{ {
URL, URL,
UPDATED, UPDATED,
...@@ -112,7 +112,6 @@ namespace OWL ...@@ -112,7 +112,6 @@ namespace OWL
{KEY::PREVIEW, "preview"}, {KEY::PREVIEW, "preview"},
{KEY::IMAGE, "image"}, {KEY::IMAGE, "image"},
{KEY::LINK, "link"} {KEY::LINK, "link"}
}; };
static const QHash<QString, OWL::KEY> MAPKEY = static const QHash<QString, OWL::KEY> MAPKEY =
......
...@@ -4,9 +4,9 @@ import QtQuick.Controls 2.3 ...@@ -4,9 +4,9 @@ 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 org.kde.kirigami 2.2 as Kirigami
import Owl 1.0
import BuhoModel 1.0 import BuhoModel 1.0
import Links 1.0 import Links 1.0
import OWL 1.0
import "../../widgets" import "../../widgets"
...@@ -44,36 +44,56 @@ Maui.Page ...@@ -44,36 +44,56 @@ Maui.Page
Menu Menu
{ {
id: sortMenu id: sortMenu
MenuItem
Maui.MenuItem
{
text: qsTr("Ascedent")
checkable: true
checked: linksList.order === Links.ASC
onTriggered: linksList.order = Links.ASC
}
Maui.MenuItem
{
text: qsTr("Descendent")
checkable: true
checked: linksList.order === Links.DESC
onTriggered: linksList.order = Links.DESC
}
MenuSeparator{}
Maui.MenuItem
{ {
text: qsTr("Title") text: qsTr("Title")
onTriggered: linksList.sortBy(KEY.TITLE, "ASC") onTriggered: KEY.TITLE
} }
MenuItem Maui.MenuItem
{ {
text: qsTr("Color") text: qsTr("Color")
onTriggered: linksList.sortBy(KEY.COLOR, "ASC") onTriggered: linksList.sortBy = KEY.COLOR
} }
MenuItem Maui.MenuItem
{ {
text: qsTr("Add date") text: qsTr("Add date")
onTriggered: linksList.sortBy(KEY.ADD_DATE, "DESC") onTriggered: linksList.sortBy = KEY.ADD_DATE
} }
MenuItem Maui.MenuItem
{ {
text: qsTr("Updated") text: qsTr("Updated")
onTriggered: linksList.sortBy(KEY.UPDATED, "DESC") onTriggered: linksList.sortBy = KEY.UPDATED
} }
MenuItem
Maui.MenuItem
{ {
text: qsTr("Fav") text: qsTr("Fav")
onTriggered: linksList.sortBy(KEY.FAV, "DESC") onTriggered: linksList.sortBy = KEY.FAV
} }
} }
} }
] ]
......
...@@ -7,7 +7,7 @@ import org.kde.kirigami 2.2 as Kirigami ...@@ -7,7 +7,7 @@ import org.kde.kirigami 2.2 as Kirigami
import BuhoModel 1.0 import BuhoModel 1.0
import Notes 1.0 import Notes 1.0
import Owl 1.0 import OWL 1.0 //To get the enums
import "../../widgets" import "../../widgets"
...@@ -46,33 +46,53 @@ Maui.Page ...@@ -46,33 +46,53 @@ Maui.Page
{ {
id: sortMenu id: sortMenu
parent: parent parent: parent
MenuItem
Maui.MenuItem
{
text: qsTr("Ascedent")
checkable: true
checked: notesList.order === Notes.ASC
onTriggered: notesList.order = Notes.ASC
}
Maui.MenuItem
{
text: qsTr("Descendent")
checkable: true
checked: notesList.order === Notes.DESC
onTriggered: notesList.order = Notes.DESC
}
MenuSeparator{}
Maui.MenuItem
{ {
text: qsTr("Title") text: qsTr("Title")
onTriggered: notesList.sortBy(KEY.TITLE, "ASC") onTriggered: notesList.sortBy = KEY.TITLE
} }
MenuItem Maui.MenuItem
{ {
text: qsTr("Color") text: qsTr("Color")
onTriggered: notesList.sortBy(KEY.COLOR, "ASC") onTriggered: notesList.sortBy = KEY.COLOR
} }
MenuItem Maui.MenuItem
{ {
text: qsTr("Add date") text: qsTr("Add date")
onTriggered: notesList.sortBy(KEY.ADD_DATE, "DESC") onTriggered: notesList.sortBy = KEY.ADD_DATE
} }
MenuItem Maui.MenuItem
{ {
text: qsTr("Updated") text: qsTr("Updated")
onTriggered: notesList.sortBy(KEY.UPDATED, "DESC") onTriggered: notesList.sortBy = KEY.UPDATED
} }
MenuItem
Maui.MenuItem
{ {
text: qsTr("Fav") text: qsTr("Fav")
onTriggered: notesList.sortBy(KEY.FAV, "DESC") onTriggered: notesList.sortBy = KEY.FAV
} }
} }
} }
......
...@@ -2,7 +2,6 @@ import QtQuick 2.9 ...@@ -2,7 +2,6 @@ import QtQuick 2.9
import QtQuick.Controls 2.2 import QtQuick.Controls 2.2
import QtQuick.Layouts 1.0 import QtQuick.Layouts 1.0
import org.kde.mauikit 1.0 as Maui import org.kde.mauikit 1.0 as Maui
import org.buho.editor 1.0
import org.kde.kirigami 2.2 as Kirigami import org.kde.kirigami 2.2 as Kirigami
Maui.Dialog Maui.Dialog
...@@ -192,8 +191,6 @@ Maui.Dialog ...@@ -192,8 +191,6 @@ Maui.Dialog
} }
} }
function clear() function clear()
{ {
title.clear() title.clear()
......
...@@ -2,7 +2,6 @@ import QtQuick 2.9 ...@@ -2,7 +2,6 @@ import QtQuick 2.9
import QtQuick.Controls 2.2 import QtQuick.Controls 2.2
import QtQuick.Layouts 1.0 import QtQuick.Layouts 1.0
import org.kde.mauikit 1.0 as Maui import org.kde.mauikit 1.0 as Maui
import org.buho.editor 1.0
Maui.Dialog Maui.Dialog
{ {
...@@ -19,23 +18,14 @@ Maui.Dialog ...@@ -19,23 +18,14 @@ Maui.Dialog
rejectButton.visible: false rejectButton.visible: false
signal noteSaved(var note) signal noteSaved(var note)
page.margins: 0 page.margins: 0
colorScheme.backgroundColor: selectedColor