Commit 3edd3118 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Fill the svg symbol collection docker

D&D to the canvas doesn't work yet because I am puzzled by the
ancient KoCreateShapesTool code.
parent 69a9ccf3
......@@ -144,6 +144,7 @@ bool KoSvgSymbolCollectionResource::loadFromDevice(QIODevice *dev)
<< d->symbols[0]->shape->size();
d->title = parser.documentTitle();
setName(d->title);
d->description = parser.documentDescription();
if (d->symbols.size() < 1) {
......@@ -152,21 +153,23 @@ bool KoSvgSymbolCollectionResource::loadFromDevice(QIODevice *dev)
}
setValid(true);;
QImage image(100, 100, QImage::Format_ARGB32_Premultiplied);
QPainter gc(&image);
image.fill(Qt::white);
KoViewConverter vc;
KoShapePaintingContext ctx;
for(int i = 0; i < d->symbols.size(); ++i) {
KoShapeGroup *group = dynamic_cast<KoShapeGroup*>(d->symbols[0]->shape);
group->setSize(QSizeF(100.0, 100.0));
Q_ASSERT(group);
paintGroup(group, gc, vc, ctx);
QImage image(100, 100, QImage::Format_ARGB32_Premultiplied);
QPainter gc(&image);
image.fill(Qt::white);
KoViewConverter vc;
KoShapePaintingContext ctx;
KoShapeGroup *group = dynamic_cast<KoShapeGroup*>(d->symbols[i]->shape);
group->setSize(QSizeF(100.0, 100.0));
Q_ASSERT(group);
paintGroup(group, gc, vc, ctx);
gc.end();
d->symbols[i]->icon = image;
gc.end();
setImage(image);
}
image.save("bla.png");
setImage(d->symbols[0]->icon);
return true;
}
......@@ -235,3 +238,8 @@ QStringList KoSvgSymbolCollectionResource::permits() const
{
return QStringList();
}
QVector<KoSvgSymbol *> KoSvgSymbolCollectionResource::symbols() const
{
return d->symbols;
}
......@@ -23,6 +23,7 @@
#include <QColor>
#include <QVector>
#include <QScopedPointer>
#include <QImage>
#include <resources/KoResource.h>
......@@ -44,6 +45,7 @@ struct KoSvgSymbol {
QString id;
QString title;
KoShape *shape;
QImage icon;
bool operator==(const KoSvgSymbol& rhs) const {
return title == rhs.title;
......@@ -86,6 +88,9 @@ public:
QString license() const;
QStringList permits() const;
QVector<KoSvgSymbol *> symbols() const;
private:
struct Private;
......
......@@ -210,7 +210,6 @@ KoResourceServerProvider::KoResourceServerProvider() : d(new Private)
}
d->svgSymbolCollectionThread = new KoResourceLoaderThread(d->svgSymbolCollectionServer);
d->svgSymbolCollectionThread ->loadSynchronously();
}
KoResourceServerProvider::~KoResourceServerProvider()
......
project(calligradockers)
set(calligradockers_SRCS
shapecollection/ShapeCollectionDocker.cpp
shapecollection/CollectionItemModel.cpp
svgsymbolcollection/SvgSymbolCollectionDocker.cpp
ShapeCollectionDocker.cpp
CollectionItemModel.cpp
SvgSymbolCollectionDocker.cpp
Plugin.cpp
)
ki18n_wrap_ui(calligradockers_SRCS
WdgSvgCollection.ui
)
add_library(krita_docker_defaults MODULE ${calligradockers_SRCS})
target_link_libraries(krita_docker_defaults kritawidgets)
......
/* This file is part of the KDE project
* Copyright (C) 2007 Thomas Zander <zander@kde.org>
*
* Copyright (C) 2017 Boudewijn Rempt <boud@valdyas.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
......@@ -17,8 +18,8 @@
* Boston, MA 02110-1301, USA.
*/
#include "Plugin.h"
#include "shapecollection/ShapeCollectionDocker.h"
#include "svgsymbolcollection/SvgSymbolCollectionDocker.h"
#include "ShapeCollectionDocker.h"
#include "SvgSymbolCollectionDocker.h"
#include <KoDockRegistry.h>
......
......@@ -23,6 +23,11 @@
#include <QDebug>
#include <KoResourceServerProvider.h>
#include <KoResourceServer.h>
#include "ui_WdgSvgCollection.h"
//
// SvgSymbolCollectionDockerFactory
//
......@@ -50,8 +55,27 @@ QDockWidget *SvgSymbolCollectionDockerFactory::createDockWidget()
SvgSymbolCollectionDocker::SvgSymbolCollectionDocker(QWidget *parent)
: QDockWidget(parent)
, m_wdgSvgCollection(new Ui_WdgSvgCollection())
{
setWindowTitle(i18n("Vector Libraries"));
QWidget* mainWidget = new QWidget(this);
setWidget(mainWidget);
m_wdgSvgCollection->setupUi(mainWidget);
connect(m_wdgSvgCollection->cmbCollections, SIGNAL(activated(int)), SLOT(collectionActivated(int)));
KoResourceServer<KoSvgSymbolCollectionResource> *svgCollectionProvider = KoResourceServerProvider::instance()->svgSymbolCollectionServer();
Q_FOREACH(KoSvgSymbolCollectionResource *r, svgCollectionProvider->resources()) {
QVariant v = QVariant::fromValue<KoSvgSymbolCollectionResource*>(r);
m_wdgSvgCollection->cmbCollections->addItem(r->name(), v);
}
m_wdgSvgCollection->listCollection->setDragEnabled(true);
m_wdgSvgCollection->listCollection->setDragDropMode(QAbstractItemView::DragOnly);
m_wdgSvgCollection->listCollection->setSelectionMode(QListView::SingleSelection);
collectionActivated(0);
}
void SvgSymbolCollectionDocker::setCanvas(KoCanvasBase *canvas)
......@@ -63,3 +87,18 @@ void SvgSymbolCollectionDocker::unsetCanvas()
{
setEnabled(false);
}
void SvgSymbolCollectionDocker::collectionActivated(int index)
{
QVariant v = m_wdgSvgCollection->cmbCollections->itemData(index);
KoSvgSymbolCollectionResource *r = v.value<KoSvgSymbolCollectionResource *>();
if (r) {
m_wdgSvgCollection->listCollection->clear();
Q_FOREACH(KoSvgSymbol *symbol, r->symbols()) {
QListWidgetItem *item = new QListWidgetItem(symbol->title);
item->setIcon(QIcon(QPixmap::fromImage(symbol->icon)));
m_wdgSvgCollection->listCollection->addItem(item);
}
}
}
......@@ -27,6 +27,9 @@
#include <KoDockFactoryBase.h>
#include <KoCanvasObserverBase.h>
#include "ui_WdgSvgCollection.h"
class SvgSymbolCollectionDockerFactory : public KoDockFactoryBase
{
public:
......@@ -51,7 +54,13 @@ public:
void setCanvas(KoCanvasBase *canvas) override;
void unsetCanvas() override;
private Q_SLOTS:
void collectionActivated(int index);
private:
Ui_WdgSvgCollection *m_wdgSvgCollection;
};
#endif //KOSHAPECOLLECTIONDOCKER_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WdgSvgCollection</class>
<widget class="QWidget" name="WdgSvgCollection">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QComboBox" name="cmbCollections"/>
</item>
<item>
<widget class="QListWidget" name="listCollection"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
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