diff --git a/src/controls/GridView.qml b/src/controls/GridView.qml index 2cf3d09..1098dcf 100644 --- a/src/controls/GridView.qml +++ b/src/controls/GridView.qml @@ -1,190 +1,190 @@ /* * Copyright 2018 Camilo Higuita * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.9 import QtQuick.Controls 2.10 import QtQuick.Layouts 1.3 import QtQuick.Controls.impl 2.3 import org.kde.mauikit 1.0 as Maui import org.kde.kirigami 2.7 as Kirigami import QtGraphicalEffects 1.0 Kirigami.ScrollablePage { id: control property int itemSize: 0 property int itemWidth : itemSize property int itemHeight : itemSize onItemWidthChanged : gridView.size_ = itemWidth property alias cellWidth: gridView.cellWidth property alias cellHeight: gridView.cellHeight property alias model : gridView.model property alias delegate : gridView.delegate property alias contentY: gridView.contentY property alias currentIndex : gridView.currentIndex property alias count : gridView.count property alias cacheBuffer : gridView.cacheBuffer property alias topMargin: gridView.topMargin property alias bottomMargin: gridView.bottomMargin property alias rightMargin: gridView.rightMargin property alias leftMarging: gridView.leftMargin property alias holder : _holder property alias gridView : gridView property bool centerContent: false //deprecrated property bool adaptContent: true signal areaClicked(var mouse) signal areaRightClicked() signal keyPress(var event) spacing: Maui.Style.space.medium Kirigami.Theme.colorSet: Kirigami.Theme.View padding: 0 leftPadding: control.ScrollBar.visible ? padding : control.ScrollBar.width rightPadding: padding topPadding: padding bottomPadding: padding focus: true keyboardNavigationEnabled: false Behavior on cellWidth { NumberAnimation { duration: Kirigami.Units.shortDuration easing.type: Easing.InQuad } } GridView { id: gridView //nasty trick property int size_ Component.onCompleted: { gridView.size_ = control.itemWidth } flow: GridView.FlowLeftToRight clip: true focus: true cellWidth: control.itemWidth cellHeight: control.itemHeight boundsBehavior: !Kirigami.Settings.isMobile? Flickable.StopAtBounds : Flickable.OvershootBounds flickableDirection: Flickable.AutoFlickDirection snapMode: GridView.NoSnap highlightMoveDuration: 0 interactive: true - onWidthChanged: adaptContent? control.adaptGrid() : undefined + onWidthChanged: if(control.adaptContent) control.adaptGrid() keyNavigationEnabled : true keyNavigationWraps : true Keys.onPressed: control.keyPress(event) Maui.Holder { id: _holder anchors.fill : parent } PinchArea { anchors.fill: parent z: -1 onPinchStarted: { console.log("pinch started") } onPinchUpdated: { } onPinchFinished: { console.log("pinch finished") resizeContent(pinch.scale) } MouseArea { anchors.fill: parent propagateComposedEvents: true acceptedButtons: Qt.RightButton | Qt.LeftButton onClicked: { control.forceActiveFocus() control.areaClicked(mouse) } onPressAndHold: control.areaRightClicked() // scrollGestureEnabled : false onWheel: { if (wheel.modifiers & Qt.ControlModifier) { if (wheel.angleDelta.y != 0) { var factor = 1 + wheel.angleDelta.y / 600; control.resizeContent(factor) } }else wheel.accepted = false } } } } function resizeContent(factor) { if(factor > 1) { gridView.size_ = gridView.size_ + 10 control.cellHeight = control.cellHeight + 10 } else { gridView.size_ = gridView.size_ - 10 control.cellHeight = control.cellHeight - 10 } if(adaptContent) control.adaptGrid() } function adaptGrid() { var amount = parseInt(gridView.width / (gridView.size_), 10) var leftSpace = parseInt(gridView.width - ( amount * (gridView.size_) ), 10) var size = parseInt((gridView.size_) + (parseInt(leftSpace/amount, 10)), 10) // size = size > gridView.size_? size : gridView.size_ control.cellWidth = size } } diff --git a/src/controls/ListBrowserDelegate.qml b/src/controls/ListBrowserDelegate.qml index 55b2603..381cfa5 100644 --- a/src/controls/ListBrowserDelegate.qml +++ b/src/controls/ListBrowserDelegate.qml @@ -1,123 +1,122 @@ /* * Copyright 2018 Camilo Higuita * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.0 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.3 import org.kde.kirigami 2.7 as Kirigami import org.kde.mauikit 1.0 as Maui import QtGraphicalEffects 1.0 import "private" Maui.ItemDelegate { id: control property bool showDetailsInfo: false property int folderSize : Maui.Style.iconSizes.medium property int emblemSize: Maui.Style.iconSizes.medium property alias showLabel : _template.labelsVisible property bool showEmblem : false property bool showTooltip : false property bool showThumbnails : false property bool isSelected : false property bool keepEmblemOverlay : false property string rightEmblem property string leftEmblem isCurrentItem : ListView.isCurrentItem || isSelected signal emblemClicked(int index) signal rightEmblemClicked(int index) signal leftEmblemClicked(int index) signal contentDropped(var drop) ToolTip.delay: 1000 ToolTip.timeout: 5000 ToolTip.visible: control.hovered && control.showTooltip ToolTip.text: model.tooltip ? model.tooltip : model.path property alias label1 : _template.label1 property alias label2 : _template.label2 property alias label3 : _template.label3 property alias label4 : _template.label4 property alias iconItem : _template.iconItem property alias iconVisible : _template.iconVisible property alias iconSizeHint : _template.iconSizeHint property alias imageSource : _template.imageSource property alias iconSource : _template.iconSource DropArea { id: _dropArea anchors.fill: parent enabled: control.draggable Rectangle { anchors.fill: parent radius: Maui.Style.radiusV color: control.Kirigami.Theme.highlightColor visible: parent.containsDrag } onDropped: { control.contentDropped(drop) } } Drag.active: mouseArea.drag.active && control.draggable Drag.dragType: Drag.Automatic Drag.supportedActions: Qt.CopyAction Drag.mimeData: { "text/uri-list": model.path } Maui.Badge { id: _leftEmblemIcon iconName: control.leftEmblem visible: (control.hovered || control.keepEmblemOverlay || control.isSelected) && control.showEmblem && control.leftEmblem anchors.top: parent.top anchors.left: parent.left onClicked: leftEmblemClicked(index) size: Maui.Style.iconSizes.small } Maui.ListItemTemplate { id: _template - width: parent.width - height: parent.height + anchors.fill: parent isCurrentItem : control.isCurrentItem iconSizeHint: control.folderSize imageSource: model.mime && model.thumbnail ? (Maui.FM.checkFileType(Maui.FMList.IMAGE, model.mime) && control.showThumbnails ? model.thumbnail : "") : "" iconSource: model.icon label1.text: model.label label3.text : model.mime === "inode/directory" ? (model.count ? model.count + qsTr(" items") : "") : Maui.FM.formatSize(model.size) label4.text: Maui.FM.formatDate(model.modified, "MM/dd/yyyy") } } diff --git a/src/utils/handy.cpp b/src/utils/handy.cpp index d0aa0bf..2a3e117 100644 --- a/src/utils/handy.cpp +++ b/src/utils/handy.cpp @@ -1,191 +1,189 @@ /* * Copyright 2018 Camilo Higuita * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "handy.h" #include "utils.h" #include #include #include #include #include #include #include #include "fmh.h" -Handy::Handy(QObject *parent) : QObject(parent) {} - -Handy::~Handy() {} +Handy::Handy(QObject *parent) : QObject(parent), m_isTouch(Handy::isTouch()) +{} #ifdef Q_OS_ANDROID static inline struct { QList urls; QString text; bool hasUrls(){ return !urls.isEmpty(); } bool hasText(){ return !text.isEmpty(); } } _clipboard; #endif QVariantMap Handy::appInfo() { auto res = QVariantMap({{FMH::MODEL_NAME[FMH::MODEL_KEY::NAME], qApp->applicationName()}, {FMH::MODEL_NAME[FMH::MODEL_KEY::VERSION], qApp->applicationVersion()}, {FMH::MODEL_NAME[FMH::MODEL_KEY::ORG], qApp->organizationName()}, {FMH::MODEL_NAME[FMH::MODEL_KEY::DOMAIN_M], qApp->organizationDomain()}, {"mauikit_version", MAUIKIT_VERSION_STR}, {"qt_version", QT_VERSION_STR} }); #ifdef Q_OS_ANDROID res.insert(FMH::MODEL_NAME[FMH::MODEL_KEY::ICON], QGuiApplication::windowIcon().name()); #else res.insert(FMH::MODEL_NAME[FMH::MODEL_KEY::ICON], QApplication::windowIcon().name()); #endif return res; } QVariantMap Handy::userInfo() { QString name = qgetenv("USER"); if (name.isEmpty()) name = qgetenv("USERNAME"); return QVariantMap({{FMH::MODEL_NAME[FMH::MODEL_KEY::NAME], name}}); } QString Handy::getClipboardText() { #ifdef Q_OS_ANDROID auto clipbopard = QGuiApplication::clipboard(); #else auto clipbopard = QApplication::clipboard(); #endif auto mime = clipbopard->mimeData(); if(mime->hasText()) return clipbopard->text(); return QString(); } QVariantMap Handy::getClipboard() { QVariantMap res; #ifdef Q_OS_ANDROID if(_clipboard.hasUrls()) res.insert("urls", QUrl::toStringList(_clipboard.urls)); if(_clipboard.hasText()) res.insert("text", _clipboard.text); #else auto clipboard = QApplication::clipboard(); auto mime = clipboard->mimeData(); if(mime->hasUrls()) res.insert("urls", QUrl::toStringList(mime->urls())); if(mime->hasText()) res.insert("text", mime->text()); #endif return res; } bool Handy::copyToClipboard(const QVariantMap &value) { #ifdef Q_OS_ANDROID if(value.contains("urls")) _clipboard.urls = QUrl::fromStringList(value["urls"].toStringList()); if(value.contains("text")) _clipboard.text = value["text"].toString(); return true; #else auto clipboard = QApplication::clipboard(); QMimeData* mimeData = new QMimeData(); if(value.contains("urls")) mimeData->setUrls(QUrl::fromStringList(value["urls"].toStringList())); if(value.contains("text")) mimeData->setText(value["text"].toString()); clipboard->setMimeData(mimeData); return true; #endif return false; } bool Handy::copyTextToClipboard(const QString &text) { #ifdef Q_OS_ANDROID Handy::copyToClipboard({{"text", text}}); #else QApplication::clipboard()->setText(text); #endif return true; } int Handy::version() { return QOperatingSystemVersion::current().majorVersion(); } bool Handy::isAndroid() { return FMH::isAndroid(); } bool Handy::isLinux() { return FMH::isLinux(); } bool Handy::isTouch() { qDebug()<< "CHECKIGN IS IT IS TROYCH"; for(const auto &device : QTouchDevice::devices()) { if(device->type() == QTouchDevice::TouchScreen) return true; qDebug()<< "DEVICE CAPABILITIES" << device->capabilities() << device->name(); } - return false; - + return false; } bool Handy::isWindows() { return FMH::isWindows(); } bool Handy::isMac() { return FMH::isMac(); } diff --git a/src/utils/handy.h b/src/utils/handy.h index 6cf4550..6cd36f3 100644 --- a/src/utils/handy.h +++ b/src/utils/handy.h @@ -1,103 +1,105 @@ /* * Copyright 2018 Camilo Higuita * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef HANDY_H #define HANDY_H #include #ifndef STATIC_MAUIKIT #include "mauikit_export.h" #endif #include /*! * \brief The Handy class contains useful static methods to be used as an attached property to the Maui application */ #ifdef STATIC_MAUIKIT class Handy : public QObject #else class MAUIKIT_EXPORT Handy : public QObject #endif { Q_OBJECT - Q_PROPERTY(bool isTouch READ isTouch CONSTANT FINAL) + Q_PROPERTY(bool isTouch MEMBER m_isTouch CONSTANT FINAL) Q_PROPERTY(bool isAndroid READ isAndroid CONSTANT FINAL) Q_PROPERTY(bool isLinux READ isLinux CONSTANT FINAL) Q_PROPERTY(bool isWindows READ isWindows CONSTANT FINAL) Q_PROPERTY(bool isMac READ isMac CONSTANT FINAL) public: Handy(QObject *parent = nullptr); - ~Handy(); + +private: + bool m_isTouch = false; public slots: /*! * \brief Returns the major version of the current OS * * This function is static. * \return Major OS version */ static int version(); /*! * \brief Returns a QVariantMap containing basic information about the current app * * The pairs keys for the information returned are: * "name", "version", "org", "domain", "mauikit_version" and "qt_version" * \return QVariantMap with app info */ static QVariantMap appInfo(); /*! * \brief Returns a QVariantMap containing basic information about the current user * * The pairs keys for the information returned are: * "name" * \return QVariantMap with user info */ static QVariantMap userInfo(); /*! * \brief Returns the text contained in the clipboard * \return QString containing clipboard text */ static QString getClipboardText(); static QVariantMap getClipboard(); /*! * \brief Copies text to the clipboard * \param text text to be copied to the clipboard * \return */ static bool copyTextToClipboard(const QString &text); static bool copyToClipboard(const QVariantMap &value); //TODO move to Device.h the defs and implementation of device specifics static bool isTouch(); static bool isAndroid(); static bool isWindows(); static bool isMac(); static bool isLinux(); }; #endif // HANDY_H