diff --git a/plugins/dockers/CMakeLists.txt b/plugins/dockers/CMakeLists.txt index 0840f5c6be..2efb2a0115 100644 --- a/plugins/dockers/CMakeLists.txt +++ b/plugins/dockers/CMakeLists.txt @@ -1,33 +1,34 @@ add_subdirectory(defaultdockers) add_subdirectory(smallcolorselector) add_subdirectory(specificcolorselector) add_subdirectory(digitalmixer) add_subdirectory(advancedcolorselector) add_subdirectory(presetdocker) add_subdirectory(historydocker) add_subdirectory(channeldocker) add_subdirectory(imagedocker) add_subdirectory(artisticcolorselector) add_subdirectory(tasksetdocker) add_subdirectory(compositiondocker) add_subdirectory(patterndocker) add_subdirectory(griddocker) add_subdirectory(arrangedocker) if(HAVE_OCIO) add_subdirectory(lut) endif() add_subdirectory(overview) add_subdirectory(palettedocker) add_subdirectory(colorslider) add_subdirectory(animation) add_subdirectory(presethistory) add_subdirectory(svgcollectiondocker) add_subdirectory(histogram) +add_subdirectory(pager) if(HAVE_QT_QUICK) add_subdirectory(touchdocker) option(ENABLE_CPU_THROTTLE "Build the CPU Throttle Docker" OFF) if (ENABLE_CPU_THROTTLE) add_subdirectory(throttle) endif() endif() diff --git a/plugins/dockers/pager/CMakeLists.txt b/plugins/dockers/pager/CMakeLists.txt new file mode 100644 index 0000000000..bed0953f45 --- /dev/null +++ b/plugins/dockers/pager/CMakeLists.txt @@ -0,0 +1,4 @@ +set(KRITA_PAGERDOCKER_SOURCES PagerDockerPlugin.cpp PagerDockerDock.cpp) +add_library(kritapagerdocker MODULE ${KRITA_PAGERDOCKER_SOURCES}) +target_link_libraries(kritapagerdocker kritaui) +install(TARGETS kritapagerdocker DESTINATION ${KRITA_PLUGIN_INSTALL_DIR}) diff --git a/plugins/dockers/pager/PagerDockerDock.cpp b/plugins/dockers/pager/PagerDockerDock.cpp new file mode 100644 index 0000000000..cfe1693a35 --- /dev/null +++ b/plugins/dockers/pager/PagerDockerDock.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2018 Jouni Pentikäinen + * + * 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 "PagerDockerDock.h" + +#include +#include +#include +#include +#include +#include +#include + +PagerDockerDock::PagerDockerDock() + : QDockWidget(i18n("Pager")) +{ + auto *widget = new QWidget(this); + setWidget(widget); + + auto *layout = new QHBoxLayout(widget); + widget->setLayout(layout); + + auto *nextButton = new QPushButton(">>", widget); + auto *previousButton = new QPushButton("<<", widget); + + layout->addWidget(previousButton); + layout->addWidget(nextButton); + + connect(nextButton, SIGNAL(clicked()), this, SLOT(slotNextPage())); + connect(previousButton, SIGNAL(clicked()), this, SLOT(slotPreviousPage())); +} + +PagerDockerDock::~PagerDockerDock() {} + +void PagerDockerDock::setCanvas(KoCanvasBase *canvas) +{ + m_canvas = qobject_cast(canvas); +} +void PagerDockerDock::unsetCanvas() +{ + m_canvas = nullptr; +} + +void PagerDockerDock::slotNextPage() +{ + flipPage(true); +} + +void PagerDockerDock::slotPreviousPage() +{ + flipPage(false); +} + +void PagerDockerDock::flipPage(bool forward) +{ + if (!m_canvas) return; + + KisDocument *activeDocument = m_canvas->imageView()->document(); + + QUrl url = activeDocument->url(); + if (url.isEmpty() || !url.isLocalFile()) return; + QFileInfo fileInfo(url.toLocalFile()); + QDir directory = fileInfo.absoluteDir(); + + QStringList openSiblingFiles = getOpenFilesInDirectory(directory.path()); + QStringList allSiblingFiles = getKraFilesInDirectory(directory); + + int step = chooseStepSize(fileInfo.fileName(), openSiblingFiles, allSiblingFiles, forward); + if (step == 0) return; + + pageViews(directory, allSiblingFiles, step); +} + +QStringList PagerDockerDock::getOpenFilesInDirectory(const QString &path) +{ + QStringList openSiblingFiles; + Q_FOREACH(KisDocument *document, KisPart::instance()->documents()) { + if (!document->url().isLocalFile()) continue; + + QFileInfo docFile(document->url().toLocalFile()); + if (docFile.absoluteDir() == path) { + openSiblingFiles.append(docFile.fileName()); + } + } + + return openSiblingFiles; +} + +QStringList PagerDockerDock::getKraFilesInDirectory(QDir directory) +{ + directory.setNameFilters({"*.kra"}); + directory.setFilter(QDir::Files); + directory.setSorting(QDir::Name | QDir::IgnoreCase); + return directory.entryList(); +} + +int PagerDockerDock::chooseStepSize(const QString &baseFile, + const QStringList &openSiblingFiles, const QStringList &allSiblingFiles, bool forward) const +{ + int baseIndex = allSiblingFiles.indexOf(baseFile); + if (baseIndex < 0) return 0; + + int step = 1; + while (baseIndex > 0 && openSiblingFiles.contains(allSiblingFiles[baseIndex - 1])) { + baseIndex--; + } + + while (baseIndex + step < allSiblingFiles.count() && openSiblingFiles.contains(allSiblingFiles[baseIndex + step])) { + step++; + } + + return forward ? step : -step; +} + +void PagerDockerDock::pageViews(const QDir &directory, const QStringList &allSiblingFiles, int step) const +{ + QList> views = KisPart::instance()->views(); + + Q_FOREACH(KisView *view, views) { + QString newFilename = getSteppedFilename(view->document(), directory, allSiblingFiles, step); + if (!newFilename.isEmpty()) { + if (!view->queryClose()) return; + } + } + + Q_FOREACH(KisView *view, views) { + QString newFilename = getSteppedFilename(view->document(), directory, allSiblingFiles, step); + if (newFilename.isEmpty()) continue; + + view->mainWindow()->openDocument(QUrl::fromLocalFile(newFilename), KisMainWindow::None); + view->closeView(); + } +} + +QString PagerDockerDock::getSteppedFilename(const KisDocument *document, const QDir &directory, + const QStringList &allSiblingFiles, int step) const +{ + QFileInfo file(document->url().toLocalFile()); + if (file.absoluteDir() != directory.path()) return QString(); + + int index = allSiblingFiles.indexOf(file.fileName()); + if (index < 0) return QString(); + + int newIndex = index + step; + if (newIndex < 0 || newIndex >= allSiblingFiles.size()) return QString(); + + return directory.filePath(allSiblingFiles[newIndex]); +} diff --git a/plugins/dockers/pager/PagerDockerDock.h b/plugins/dockers/pager/PagerDockerDock.h new file mode 100644 index 0000000000..07bd3f8fea --- /dev/null +++ b/plugins/dockers/pager/PagerDockerDock.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2018 Jouni Pentikäinen + * + * 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. + */ + +#ifndef PAGERDOCKERDOCK_H +#define PAGERDOCKERDOCK_H + +#include +#include +#include +#include + +#include + +class KisDocument; +class KisCanvas2; + +class PagerDockerDock : public QDockWidget, public KoCanvasObserverBase +{ + Q_OBJECT + +public: + PagerDockerDock(); + ~PagerDockerDock() override; + + QString observerName() override { return "PagerDockerDock"; } + +protected: + void setCanvas(KoCanvasBase *canvas) override; + void unsetCanvas() override; + +private Q_SLOTS: + void slotNextPage(); + void slotPreviousPage(); + +private: + void flipPage(bool forward); + QStringList getOpenFilesInDirectory(const QString &path); + QStringList getKraFilesInDirectory(QDir directory); + int chooseStepSize(const QString &baseFile, const QStringList &openSiblingFiles, const QStringList &allSiblingFiles, bool forward) const; + void pageViews(const QDir &directory, const QStringList &allSiblingFiles, int step) const; + QString getSteppedFilename(const KisDocument *document, const QDir &directory, const QStringList &allSiblingFiles, int step) const; + + KisCanvas2 *m_canvas; +}; + +#endif diff --git a/plugins/dockers/pager/PagerDockerPlugin.cpp b/plugins/dockers/pager/PagerDockerPlugin.cpp new file mode 100644 index 0000000000..98d270e9aa --- /dev/null +++ b/plugins/dockers/pager/PagerDockerPlugin.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018 Jouni Pentikäinen + * + * 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 "PagerDockerPlugin.h" + +#include +#include +#include + +#include "PagerDockerDock.h" + +K_PLUGIN_FACTORY_WITH_JSON(PagerDockerPluginFactory, "krita_pagerdocker.json", registerPlugin();) + +class PagerDockerDockFactory : public KoDockFactoryBase { +public: + PagerDockerDockFactory() + {} + + ~PagerDockerDockFactory() override {} + + QString id() const override + { + return QString( "PagerDocker" ); + } + + virtual Qt::DockWidgetArea defaultDockWidgetArea() const + { + return Qt::RightDockWidgetArea; + } + + QDockWidget* createDockWidget() override + { + PagerDockerDock * dockWidget = new PagerDockerDock(); + dockWidget->setObjectName(id()); + + return dockWidget; + } + + DockPosition defaultDockPosition() const override + { + return DockMinimized; + } +}; + +PagerDockerPlugin::PagerDockerPlugin(QObject *parent, const QVariantList &) + : QObject(parent) +{ + KoDockRegistry::instance()->add(new PagerDockerDockFactory()); +} + +PagerDockerPlugin::~PagerDockerPlugin() +{} + +#include "PagerDockerPlugin.moc" diff --git a/plugins/dockers/pager/PagerDockerPlugin.h b/plugins/dockers/pager/PagerDockerPlugin.h new file mode 100644 index 0000000000..935bba6b33 --- /dev/null +++ b/plugins/dockers/pager/PagerDockerPlugin.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018 Jouni Pentikäinen + * + * 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. + */ + +#ifndef PAGERDOCKER_H +#define PAGERDOCKER_H + +#include + +class PagerDockerPlugin : public QObject +{ +public: + PagerDockerPlugin(QObject *parent, const QVariantList &); + ~PagerDockerPlugin() override; +}; + +#endif diff --git a/plugins/dockers/pager/krita_pagerdocker.json b/plugins/dockers/pager/krita_pagerdocker.json new file mode 100644 index 0000000000..6a8f8053e0 --- /dev/null +++ b/plugins/dockers/pager/krita_pagerdocker.json @@ -0,0 +1,9 @@ +{ + "Id": "Pager Docker", + "Type": "Service", + "X-KDE-Library": "kritapagerdocker", + "X-KDE-ServiceTypes": [ + "Krita/Dock" + ], + "X-Krita-Version": "28" +}