Commit 69ef48ec authored by Boudewijn Rempt's avatar Boudewijn Rempt

Move touch gui development to master

parent bebfdf33
......@@ -275,6 +275,23 @@ set_package_properties(Qt5Multimedia PROPERTIES
macro_bool_to_01(Qt5Multimedia_FOUND HAVE_QT_MULTIMEDIA)
configure_file(config-qtmultimedia.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-qtmultimedia.h )
find_package(Qt5Quick ${MIN_QT_VERSION})
set_package_properties(Qt5Quick PROPERTIES
DESCRIPTION "QtQuick"
URL "http://www.qt.io/"
TYPE OPTIONAL
PURPOSE "Optionally used for the touch gui for Krita")
macro_bool_to_01(Qt5Quick_FOUND HAVE_QT_QUICK)
find_package(Qt5QuickWidgets ${MIN_QT_VERSION})
set_package_properties(Qt5QuickWidgets PROPERTIES
DESCRIPTION "QtQuickWidgets"
URL "http://www.qt.io/"
TYPE OPTIONAL
PURPOSE "Optionally used for the touch gui for Krita")
if (NOT WIN32 AND NOT APPLE)
find_package(Qt5 ${MIN_QT_VERSION} REQUIRED X11Extras)
......
......@@ -17,3 +17,7 @@ add_subdirectory( ui )
add_subdirectory( vectorimage )
add_subdirectory( impex )
add_subdirectory( libkis )
if (HAVE_QT_QUICK)
add_subdirectory( libqml )
endif()
......@@ -43,6 +43,9 @@ public:
void setConfigurationSafe(const KisPropertiesConfigurationSP config);
protected:
friend class CompositeOpModel;
void setConfiguration(const KisPropertiesConfigurationSP config) override = 0;
virtual void writeConfiguration(KisPropertiesConfigurationSP config) const = 0;
......
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)
include_directories(SYSTEM
${Boost_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR}
)
add_subdirectory(plugins)
set(kritaqml_SRCS
DocumentManager.cpp
DocumentListModel.cpp
KisSelectionExtras.cpp
RecentFileManager.cpp
ProgressProxy.cpp
PropertyContainer.cpp
Settings.cpp
VirtualKeyboardController.cpp
Theme.cpp
QmlGlobalEngine.cpp
)
qt5_add_resources(kritaqml_SRCS qml.qrc)
add_library(kritaqml SHARED ${kritaqml_SRCS})
generate_export_header(kritaqml BASE_NAME krita_sketch)
set_target_properties(kritaqml
PROPERTIES VERSION ${GENERIC_KRITA_LIB_VERSION} SOVERSION ${GENERIC_KRITA_LIB_SOVERSION}
)
target_link_libraries(kritaqml
Qt5::Quick
Qt5::Gui
Qt5::Core
kritawidgets
kritaui
)
include(GNUInstallDirs)
install(TARGETS kritaqml ${INSTALL_TARGETS_DEFAULT_ARGS})
install(DIRECTORY themes DESTINATION ${DATA_INSTALL_DIR}/krita/qmlthemes)
/* This file is part of the KDE project
* Copyright (C) 2012 KO GmbH. Contact: Boudewijn Rempt <boud@kogmbh.com>
*
* This library 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 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "DocumentListModel.h"
#include <QTimer>
#include <QLocale>
#include <klocalizedstring.h>
class DocumentListModel::Private
{
public:
Private( DocumentListModel *qq) : q(qq), filter(DocumentListModel::UnknownType) { }
void relayout();
DocumentListModel* q;
QList<DocumentInfo> allDocumentInfos;
QList<DocumentInfo> currentDocumentInfos;
DocumentType filter;
QString searchPattern;
QTimer *timer;
};
QHash<QString, DocumentListModel::DocumentType> DocumentListModel::sm_extensions = QHash<QString, DocumentListModel::DocumentType>();
DocumentListModel::DocumentListModel(QObject *parent)
: QAbstractListModel(parent), d(new Private(this))
{
qRegisterMetaType<DocumentListModel::DocumentInfo>();
QHash<int, QByteArray> roleNames = QAbstractListModel::roleNames();
roleNames[FileNameRole] = "fileName";
roleNames[FilePathRole] = "filePath";
roleNames[DocTypeRole] = "docType";
roleNames[FileSizeRole] = "fileSize";
roleNames[AuthorNameRole] = "authorName";
roleNames[AccessedTimeRole] = "accessedTime";
roleNames[ModifiedTimeRole] = "modifiedTime";
roleNames[UUIDRole] = "uuid";
setRoleNames(roleNames);
}
DocumentListModel::~DocumentListModel()
{
}
void DocumentListModel::addDocument(const DocumentInfo &info)
{
if (d->allDocumentInfos.contains(info))
{
return;
}
d->allDocumentInfos.append(info);
}
int DocumentListModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return d->currentDocumentInfos.count();
}
int DocumentListModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return 1;
}
QVariant DocumentListModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) {
return QVariant();
}
const int row = index.row();
const DocumentInfo &info = d->currentDocumentInfos[row];
switch (role) {
case FileNameRole: // intentional fall through
case Qt::DisplayRole: return info.fileName;
case FilePathRole: return info.filePath;
case DocTypeRole: return info.docType;
case FileSizeRole: return info.fileSize;
case AuthorNameRole: return info.authorName;
case AccessedTimeRole: return prettyTime(info.accessedTime);
case ModifiedTimeRole: return prettyTime(info.modifiedTime);
case UUIDRole: return info.uuid;
default: return QVariant();
}
}
QString DocumentListModel::prettyTime( const QDateTime& theTime)
{
return QLocale().toString(theTime, QLocale::LongFormat);
}
QVariant DocumentListModel::headerData(int section, Qt::Orientation orientation, int role) const
{
Q_UNUSED(section)
Q_UNUSED(orientation)
Q_UNUSED(role)
return QVariant();
}
DocumentListModel::DocumentType DocumentListModel::filter()
{
return d->filter;
}
void DocumentListModel::setFilter( DocumentListModel::DocumentType newFilter)
{
d->filter = newFilter;
d->relayout();
}
DocumentListModel::DocumentType DocumentListModel::typeForFile ( const QString& file )
{
if (sm_extensions.isEmpty()) {
sm_extensions["odt"] = TextDocumentType;
sm_extensions["fodt"] = TextDocumentType;
sm_extensions["doc"] = TextDocumentType;
sm_extensions["docx"] = TextDocumentType;
sm_extensions["txt"] = TextDocumentType;
sm_extensions["odp"] = PresentationType;
sm_extensions["fodp"] = PresentationType;
sm_extensions["ppt"] = PresentationType;
sm_extensions["pptx"] = PresentationType;
sm_extensions["ods"] = SpreadsheetType;
sm_extensions["fods"] = SpreadsheetType;
sm_extensions["xls"] = SpreadsheetType;
sm_extensions["xlsx"] = SpreadsheetType;
sm_extensions["pdf"] = PDFDocumentType;
}
QString ext = file.split('.').last().toLower();
if (sm_extensions.contains(ext)) {
return sm_extensions.value(ext);
}
return UnknownType;
}
void DocumentListModel::Private::relayout()
{
emit q->layoutAboutToBeChanged();
QList<DocumentInfo> newList;
Q_FOREACH (const DocumentInfo &docInfo, allDocumentInfos) {
if (filter == UnknownType || docInfo.docType == filter) {
if (searchPattern.isEmpty() || docInfo.fileName.contains(searchPattern, Qt::CaseInsensitive)) {
newList.append(docInfo);
}
}
}
currentDocumentInfos = newList;
emit q->layoutChanged();
q->reset(); // ## Required for <= Qt 4.7.2
}
/* This file is part of the KDE project
* Copyright (C) 2012 KO GmbH. Contact: Boudewijn Rempt <boud@kogmbh.com>
*
* This library 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 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KRITA_SKETCH_DOCUMENTLISTMODEL_H
#define KRITA_SKETCH_DOCUMENTLISTMODEL_H
#include <QAbstractListModel>
#include <QDateTime>
#include <QColor>
#include <QUrl>
#include <QFont>
#include "krita_sketch_export.h"
class KRITA_SKETCH_EXPORT DocumentListModel : public QAbstractListModel
{
Q_OBJECT
Q_ENUMS(DocumentType)
Q_PROPERTY(DocumentType filter READ filter WRITE setFilter)
public:
DocumentListModel(QObject *parent = 0);
~DocumentListModel();
enum CustomRoles {
FileNameRole = Qt::UserRole + 1,
FilePathRole,
DocTypeRole,
FileSizeRole,
AuthorNameRole,
AccessedTimeRole,
ModifiedTimeRole,
UUIDRole,
};
enum DocumentType {
UnknownType,
TextDocumentType,
PresentationType,
SpreadsheetType,
PDFDocumentType,
};
struct DocumentInfo {
bool operator==(const DocumentInfo &other) const {
return filePath == other.filePath;
}
QString filePath;
QString fileName;
DocumentType docType;
QString fileSize;
QString authorName;
QDateTime accessedTime;
QDateTime modifiedTime;
QString uuid;
};
// reimp from QAbstractListModel
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
DocumentType filter();
static QString prettyTime(const QDateTime &theTime);
static DocumentType typeForFile(const QString &file);
public Q_SLOTS:
void addDocument(const DocumentListModel::DocumentInfo &info);
void setFilter(DocumentType newFilter);
private:
class Private;
const QScopedPointer<Private> d;
static QHash<QString, DocumentType> sm_extensions;
};
Q_DECLARE_METATYPE(DocumentListModel::DocumentInfo);
#endif // KRITA_SKETCH_DOCUMENTLISTMODEL_H
/* This file is part of the KDE project
* Copyright (C) 2012 Arjen Hiemstra <ahiemstra@heimr.nl>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, 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 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 "DocumentManager.h"
#include "ProgressProxy.h"
#include "Settings.h"
#include "RecentFileManager.h"
#include <KoColor.h>
#include <KisPart.h>
#include <KoColorSpaceRegistry.h>
#include <KisDocument.h>
#include <kis_image.h>
#include <KisMimeDatabase.h>
#include <QCoreApplication>
class DocumentManager::Private
{
public:
Private()
: proxy(0)
, document(0)
, settingsManager(0)
, recentFileManager(0)
, newDocWidth(0)
, newDocHeight(0)
, newDocResolution(0)
, importingDocument(false)
, temporaryFile(false)
{ }
ProgressProxy* proxy;
QPointer<KisDocument> document;
Settings* settingsManager;
RecentFileManager* recentFileManager;
QString saveAsFilename;
QString openDocumentFilename;
int newDocWidth, newDocHeight; float newDocResolution;
bool importingDocument;
QVariantMap newDocOptions;
bool temporaryFile;
};
DocumentManager *DocumentManager::sm_instance = 0;
KisDocument* DocumentManager::document() const
{
return d->document;
}
ProgressProxy* DocumentManager::progressProxy() const
{
return d->proxy;
}
Settings* DocumentManager::settingsManager() const
{
return d->settingsManager;
}
void DocumentManager::setSettingsManager(Settings* newManager)
{
d->settingsManager = newManager;
}
RecentFileManager* DocumentManager::recentFileManager() const
{
return d->recentFileManager;
}
bool DocumentManager::isTemporaryFile() const
{
return d->temporaryFile;
}
void DocumentManager::newDocument(int width, int height, float resolution)
{
closeDocument();
d->newDocWidth = width;
d->newDocHeight = height;
d->newDocResolution = resolution;
QTimer::singleShot(300, this, SLOT(delayedNewDocument()));
}
void DocumentManager::newDocument(const QVariantMap& options)
{
closeDocument();
d->newDocOptions = options;
QTimer::singleShot(300, this, SLOT(delayedNewDocument()));
}
void DocumentManager::delayedNewDocument()
{
d->document = KisPart::instance()->createDocument();
d->document->setProgressProxy(d->proxy);
if (qAppName().contains("sketch")) {
d->document->setFileBatchMode(true);
}
if (d->newDocOptions.isEmpty())
{
const KoColorSpace *cs = KoColorSpaceRegistry::instance()->rgb8(0);
QColor qc(Qt::white);
qc.setAlpha(0);
KoColor bgColor(qc, cs);
d->document->newImage("New Image", d->newDocWidth, d->newDocHeight, KoColorSpaceRegistry::instance()->rgb8(), bgColor, true, 2, "", d->newDocResolution);
d->document->resetURL();
}
else if (d->newDocOptions.contains("template")) {
QUrl url(d->newDocOptions.value("template").toString().remove("template://"));
bool ok = d->document->loadNativeFormat(url.toLocalFile());
d->document->setModified(false);
d->document->undoStack()->clear();
if (ok) {
QString mimeType = KisMimeDatabase::mimeTypeForFile(url.toLocalFile());
// in case this is a open document template remove the -template from the end
mimeType.remove( QRegExp( "-template$" ) );
d->document->setMimeTypeAfterLoading(mimeType);
d->document->resetURL();
}
}
else
{
QString name = d->newDocOptions.value("name", "New Image").toString();
int width = d->newDocOptions.value("width").toInt();
int height = d->newDocOptions.value("height").toInt();