diff --git a/braindump/braindumpcore/StateCategory.cpp b/braindump/braindumpcore/StateCategory.cpp index 1774f2e732d..d59aba538d8 100644 --- a/braindump/braindumpcore/StateCategory.cpp +++ b/braindump/braindumpcore/StateCategory.cpp @@ -1,65 +1,65 @@ /* * Copyright (c) 2009 Cyrille Berger * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * either version 2, or (at your option) any later version of the License. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ +#include + #include "StateCategory.h" #include "StateCategory_p.h" -#include - #include "State.h" StateCategory::StateCategory(const QString& _id, const QString& _name, int _priority) : d(new Private) { d->id = _id; d->name = _name; d->priority = _priority; } StateCategory::~StateCategory() { delete d; } const QString& StateCategory::name() const { return d->name; } const QString& StateCategory::id() const { return d->id; } QList StateCategory::stateIds() const { return d->states.keys(); } const State* StateCategory::state(const QString& _id) const { if(d->states.contains(_id)) return d->states[_id]; - kWarning() << "No shape " << _id << " found in category " << name() << " choices: " << d->states.keys(); + qWarning() << "No shape " << _id << " found in category " << name() << " choices: " << d->states.keys(); return 0; } int StateCategory::priority() const { return d->priority; } diff --git a/braindump/braindumpcore/StatesRegistry.cpp b/braindump/braindumpcore/StatesRegistry.cpp index 266d7568a77..6e97a68a823 100644 --- a/braindump/braindumpcore/StatesRegistry.cpp +++ b/braindump/braindumpcore/StatesRegistry.cpp @@ -1,178 +1,178 @@ /* * Copyright (c) 2009 Cyrille Berger * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * either version 2, or (at your option) any later version of the License. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "StatesRegistry.h" #include #include +#include +#include +#include #include -#include #include #include #include -#include -#include #include "State.h" #include "StateCategory.h" #include "StateCategory_p.h" struct Q_DECL_HIDDEN StatesRegistry::Private { static StatesRegistry* s_instance; QMap categories; void parseStatesRC(const QString& _filename); }; StatesRegistry* StatesRegistry::Private::s_instance = 0; void StatesRegistry::Private::parseStatesRC(const QString& _filename) { QDomDocument doc; QFile file(_filename); if(!file.open(QIODevice::ReadOnly)) { - kError() << "Can't open " << _filename; + qCritical() << "Can't open " << _filename; return; } QString errMsg; int line, column; if(!doc.setContent(&file, &errMsg, &line, &column)) { - kError() << "At (" << line << ", " << column << ") " << errMsg; + qCritical() << "At (" << line << ", " << column << ") " << errMsg; file.close(); return; } file.close(); QDir directory = QFileInfo(_filename).absoluteDir(); QDomElement docElem = doc.documentElement(); if(docElem.nodeName() != "states") { - kError() << "Invalid state file"; + qCritical() << "Invalid state file"; return; } QDomNode nCat = docElem.firstChild(); while(!nCat.isNull()) { QDomElement eCat = nCat.toElement(); // try to convert the node to an element. if(!eCat.isNull() && eCat.tagName() == "category") { QString catId = eCat.attribute("id"); QString catName = eCat.attribute("name"); int catPriority = eCat.attribute("priority", "1000").toInt(); StateCategory* category = 0; if(catId.isEmpty()) { - kError() << "Missing category id"; + qCritical() << "Missing category id"; } else { if(categories.contains(catId)) { category = categories[catId]; } else if(!catName.isEmpty()) { category = new StateCategory(catId, i18n(catName.toUtf8()), catPriority); categories[catId] = category; } if(category) { // Parse the states QDomNode nState = eCat.firstChild(); while(!nState.isNull()) { QDomElement eState = nState.toElement(); if(!eState.isNull() && eState.tagName() == "state") { QString stateId = eState.attribute("id"); QString stateName = eState.attribute("name"); QString stateFilename = eState.attribute("filename"); int statePriority = eState.attribute("priority", "1000").toInt(); if(stateId.isEmpty() || stateName.isEmpty() || stateFilename.isEmpty()) { - kError() << "Missing attribute: id = " << stateId << " name = " << stateName << " filename = " << stateFilename; + qCritical() << "Missing attribute: id = " << stateId << " name = " << stateName << " filename = " << stateFilename; } else { QString file = directory.absoluteFilePath(stateFilename); if(QFileInfo(file).exists()) { if(category->d->states.contains(stateId)) { delete category->d->states[stateId]; } - kDebug() << "Adding state id = " << stateId << " name = " << stateName << " filename = " << stateFilename; + qDebug() << "Adding state id = " << stateId << " name = " << stateName << " filename = " << stateFilename; category->d->states[stateId] = new State(stateId, stateName, category, file, statePriority); } else { - kError() << "Missing file " << file; + qCritical() << "Missing file " << file; } } } else { - kError() << "Invalid node in category " << catId; + qCritical() << "Invalid node in category " << catId; } nState = nState.nextSibling(); } } else { - kError() << "Couldn't make a category for " << catId; + qCritical() << "Couldn't make a category for " << catId; } } } else { - kError() << "Invalid XML node."; + qCritical() << "Invalid XML node."; } nCat = nCat.nextSibling(); } } StatesRegistry::StatesRegistry() : d(new Private) { KGlobal::dirs()->addResourceType("stateshape_states", "data", "stateshape/states/"); QStringList statesFilenames = KGlobal::dirs()->findAllResources("stateshape_states", "*.xml", KStandardDirs::Recursive); foreach(const QString & filename, statesFilenames) { - kDebug() << "Load state: " << filename; + qDebug() << "Load state: " << filename; d->parseStatesRC(filename); } } StatesRegistry::~StatesRegistry() { delete d; } const StatesRegistry* StatesRegistry::instance() { if(!Private::s_instance) { Private::s_instance = new StatesRegistry; } return Private::s_instance; } QList StatesRegistry::categorieIds() const { return d->categories.keys(); } QList StatesRegistry::stateIds(const QString& _id) const { Q_ASSERT(d->categories.contains(_id)); return d->categories[_id]->stateIds(); } const State* StatesRegistry::state(const QString& _category, const QString& _state) const { if(d->categories.contains(_category)) return d->categories[_category]->state(_state); - kWarning() << "No category " << _category << " found among " << d->categories.keys(); + qWarning() << "No category " << _category << " found among " << d->categories.keys(); return 0; } const State* StatesRegistry::nextState(const State* _state) const { if(_state) { QList states = _state->category()->d->states.values(); int idx = states.indexOf(_state); idx += 1; if(idx >= states.count()) idx = 0; return states[idx]; } return 0; } diff --git a/braindump/plugins/stateshape/StateShape.cpp b/braindump/plugins/stateshape/StateShape.cpp index 00b28827848..f6b855562c7 100644 --- a/braindump/plugins/stateshape/StateShape.cpp +++ b/braindump/plugins/stateshape/StateShape.cpp @@ -1,102 +1,101 @@ /* * Copyright (c) 2009 Cyrille Berger * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * either version 2, or (at your option) any later version of the License. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "StateShape.h" #include #include - -#include +#include #include #include #include #include #include #include "State.h" #include "StatesRegistry.h" #include "../../src/Xml.h" StateShape::StateShape() : m_categoryId("todo"), m_stateId("unchecked") { setSize(QSizeF(10, 10)); } StateShape::~StateShape() { } void StateShape::paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &) { QRectF target = converter.documentToView(QRectF(QPointF(0, 0), size())); const State* state = StatesRegistry::instance()->state(m_categoryId, m_stateId); if(state) { state->renderer()->render(&painter, target); } else { - kError() << "No state found for m_categoryId = " << m_categoryId << " m_stateId = " << m_stateId; + qCritical() << "No state found for m_categoryId = " << m_categoryId << " m_stateId = " << m_stateId; } } void StateShape::saveOdf(KoShapeSavingContext & context) const { KoXmlWriter &writer = context.xmlWriter(); writer.startElement("braindump:state"); Xml::writeBraindumpNS(writer); writer.addAttribute("category", m_categoryId); writer.addAttribute("state", m_stateId); saveOdfAttributes(context, OdfAllAttributes); saveOdfCommonChildElements(context); writer.endElement(); // braindump:shape } bool StateShape::loadOdf(const KoXmlElement & element, KoShapeLoadingContext &context) { m_categoryId = element.attribute("category"); m_stateId = element.attribute("state"); loadOdfAttributes(element, context, OdfAllAttributes); return true; } const QString& StateShape::categoryId() const { return m_categoryId; } void StateShape::setCategoryId(const QString& _categoryId) { m_categoryId = _categoryId; notifyChanged(); update(); } const QString& StateShape::stateId() const { return m_stateId; } void StateShape::setStateId(const QString& _stateId) { m_stateId = _stateId; notifyChanged(); update(); } diff --git a/braindump/plugins/stateshape/StateShapeFactory.cpp b/braindump/plugins/stateshape/StateShapeFactory.cpp index b40c556d38a..226e075c5c0 100644 --- a/braindump/plugins/stateshape/StateShapeFactory.cpp +++ b/braindump/plugins/stateshape/StateShapeFactory.cpp @@ -1,70 +1,70 @@ /* * Copyright (c) 2009 Cyrille Berger * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * either version 2, or (at your option) any later version of the License. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "StateShapeFactory.h" #include "StateShape.h" -#include +#include #include #include StateShapeFactory::StateShapeFactory() : KoShapeFactoryBase(STATESHAPEID, i18n("State Shape")) { setToolTip(i18n("A state shape")); setIconName(koIconNameCStr("stateshape")); setXmlElementNames("http://kde.org/braindump", QStringList("state")); } KoShape *StateShapeFactory::createDefaultShape(KoDocumentResourceManager */*documentResources*/) const { StateShape* fooShape = new StateShape(); fooShape->setShapeId(STATESHAPEID); // set defaults return fooShape; } KoShape *StateShapeFactory::createShape(const KoProperties *params, KoDocumentResourceManager */*documentResources*/) const { Q_UNUSED(params); StateShape* fooShape = new StateShape(); fooShape->setShapeId(STATESHAPEID); if(params->contains("state")) { fooShape->setStateId(params->stringProperty("state")); } if(params->contains("category")) { fooShape->setCategoryId(params->stringProperty("category")); } // use the params return fooShape; } bool StateShapeFactory::supports(const KoXmlElement& e, KoShapeLoadingContext& /*context*/) const { return (e.localName() == "state" && e.namespaceURI() == "http://kde.org/braindump"); } QList StateShapeFactory::createShapeOptionPanels() { QList answer; return answer; } diff --git a/braindump/plugins/stateshape/StateShapePlugin.cpp b/braindump/plugins/stateshape/StateShapePlugin.cpp index e0a39092d5b..f2bd5e5a31f 100644 --- a/braindump/plugins/stateshape/StateShapePlugin.cpp +++ b/braindump/plugins/stateshape/StateShapePlugin.cpp @@ -1,42 +1,43 @@ /* * Copyright (c) 2009 Cyrille Berger * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * either version 2, or (at your option) any later version of the License. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "StateShapePlugin.h" #include + #include #include #include "StateShapeFactory.h" #include "StateToolFactory.h" K_PLUGIN_FACTORY(StateShapePluginFactory, registerPlugin();) StateShapePlugin::StateShapePlugin(QObject *parent, const QVariantList &) : QObject(parent) { // register the shape's factory KoShapeRegistry::instance()->add( new StateShapeFactory()); // we could register more things here in this same plugin. KoToolRegistry::instance()->add(new StateToolFactory()); } #include "StateShapePlugin.moc" diff --git a/braindump/plugins/webshape/WebShape.cpp b/braindump/plugins/webshape/WebShape.cpp index 5759939e122..39018988e11 100644 --- a/braindump/plugins/webshape/WebShape.cpp +++ b/braindump/plugins/webshape/WebShape.cpp @@ -1,204 +1,203 @@ /* * Copyright (c) 2009 Cyrille Berger * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * either version 2, or (at your option) any later version of the License. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "WebShape.h" #include // #include #include #include #include #include #include #include #include #include #include -#include #include <../../src/Xml.h> WebShape::WebShape() : m_webPage(new QWebPage), m_cached(false), m_cacheLocked(false), m_loaded(false), m_firstLoad(false), m_zoom(1.0), m_scrollPosition(0, 0) { m_webPage->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); m_webPage->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); connect(m_webPage, SIGNAL(loadFinished(bool)), SLOT(loadFinished(bool))); } WebShape::~WebShape() { } void WebShape::paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &) { QRectF target = converter.documentToView(QRectF(QPointF(0, 0), size())); m_webPage->setViewportSize(target.size().toSize()); qreal cz = target.width() / size().width(); m_webPage->mainFrame()->setZoomFactor(m_zoom * cz); m_webPage->mainFrame()->setScrollPosition(m_scrollPosition.toPoint()); m_webPage->mainFrame()->render(&painter); } void WebShape::saveOdf(KoShapeSavingContext & context) const { KoXmlWriter &writer = context.xmlWriter(); writer.startElement("braindump:web"); Xml::writeBraindumpNS(writer); writer.addAttribute("url", m_url.url()); writer.addAttribute("scroll_x", m_scrollPosition.x()); writer.addAttribute("scroll_y", m_scrollPosition.y()); writer.addAttribute("zoom", m_zoom); saveOdfAttributes(context, OdfAllAttributes); saveOdfCommonChildElements(context); if(m_cached) { writer.addAttribute("cached", "true"); } writer.startElement("cache"); writer.addTextNode(m_cache); // Save after the attribute otherwise it is seen as writer.endElement(); // Cache writer.endElement(); // braindump:web } bool WebShape::loadOdf(const KoXmlElement & element, KoShapeLoadingContext &context) { loadOdfAttributes(element, context, OdfAllAttributes); m_url = element.attribute("url"); m_scrollPosition.setX(element.attribute("scroll_x", "0").toDouble()); m_scrollPosition.setY(element.attribute("scroll_y", "0").toDouble()); m_zoom = element.attribute("zoom", "1.0").toDouble(); if(element.attribute("cached") == "true") { m_cached = true; m_cacheLocked = true; } else { m_cached = false; m_cacheLocked = false; } KoXmlElement childElement; forEachElement(childElement, element) { if(childElement.tagName() == "cache") { m_cache = childElement.text(); m_firstLoad = true; m_webPage->mainFrame()->setContent(m_cache.toUtf8()); } } if(!m_cached) { setUrl(m_url); } return true; } const KUrl& WebShape::url() { return m_url; } void WebShape::setUrl(const KUrl& _url) { m_url = _url; m_webPage->mainFrame()->load(_url); notifyChanged(); update(); m_loaded = false; m_cacheLocked = false; } void WebShape::loadFinished(bool) { update(); m_loaded = true; if(!m_cacheLocked) { updateCache(); } m_firstLoad = false; } void WebShape::updateCache() { m_cache = m_webPage->mainFrame()->toHtml(); m_cacheLocked = true; } bool WebShape::isCached() const { return m_cached; } void WebShape::setCached(bool _cache) { m_cached = _cache; if(m_cached) { m_cacheLocked = false; if(m_loaded) { updateCache(); } } else { m_webPage->mainFrame()->load(m_url); } update(); } void WebShape::setCache(const QString& _cache) { m_cache = _cache; m_cacheLocked = true; m_webPage->mainFrame()->setContent(_cache.toUtf8()); update(); } const QString& WebShape::cache() const { return m_cache; } void WebShape::scrollOf(const QPointF& _scroll) { m_scrollPosition += _scroll / m_zoom; } void WebShape::zoomOf(qreal z) { m_zoom *= z; if(m_zoom <= 0.01) m_zoom = 0.01; } QPointF WebShape::scroll() const { return m_scrollPosition; } void WebShape::setScroll(const QPointF& point) { m_scrollPosition = point; } qreal WebShape::zoom() const { return m_zoom; } void WebShape::setZoom(qreal _zoom) { m_zoom = _zoom; } #include "WebShape.moc" diff --git a/braindump/plugins/webshape/WebTool.cpp b/braindump/plugins/webshape/WebTool.cpp index c1a29f9619d..dddc315468c 100644 --- a/braindump/plugins/webshape/WebTool.cpp +++ b/braindump/plugins/webshape/WebTool.cpp @@ -1,174 +1,175 @@ /* * Copyright (c) 2009 Cyrille Berger * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * either version 2, or (at your option) any later version of the License. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "WebTool.h" -#include #include +#include +#include + #include #include #include #include #include "WebShape.h" -#include #include "WebToolWidget.h" class ChangeScroll : public KUndo2Command { public: ChangeScroll(WebShape* shape, const QPointF& oldScroll) : m_shape(shape), m_newScroll(shape->scroll()), m_oldScroll(oldScroll) { } virtual void undo() { m_shape->setScroll(m_oldScroll); m_shape->update(); } virtual void redo() { m_shape->setScroll(m_newScroll); m_shape->update(); } private: WebShape *m_shape; QPointF m_newScroll; QPointF m_oldScroll; }; class ChangeZoom : public KUndo2Command { public: ChangeZoom(WebShape* shape, qreal oldZoom) : m_shape(shape), m_newZoom(shape->zoom()), m_oldZoom(oldZoom) { } virtual void undo() { m_shape->setZoom(m_oldZoom); m_shape->update(); } virtual void redo() { m_shape->setZoom(m_newZoom); m_shape->update(); } private: WebShape *m_shape; qreal m_newZoom; qreal m_oldZoom; }; WebTool::WebTool(KoCanvasBase *canvas) : KoToolBase(canvas), m_tmpShape(0), m_dragMode(NO_DRAG) { } WebTool::~WebTool() { } void WebTool::activate(ToolActivation /*toolActivation*/, const QSet &/*shapes*/) { Q_ASSERT(m_dragMode == NO_DRAG); KoSelection *selection = canvas()->shapeManager()->selection(); foreach(KoShape * shape, selection->selectedShapes()) { m_currentShape = dynamic_cast(shape); if(m_currentShape) break; } emit(shapeChanged(m_currentShape)); if(m_currentShape == 0) { // none found emit done(); return; } } void WebTool::paint(QPainter &painter, const KoViewConverter &converter) { Q_UNUSED(painter); Q_UNUSED(converter); } void WebTool::mousePressEvent(KoPointerEvent *event) { WebShape *hit = 0; QRectF roi(event->point, QSizeF(1, 1)); QList shapes = canvas()->shapeManager()->shapesAt(roi); KoSelection *selection = canvas()->shapeManager()->selection(); foreach(KoShape * shape, shapes) { hit = dynamic_cast(shape); if(hit) { if(hit == m_currentShape) { m_scrollPoint = event->point; Q_ASSERT(m_dragMode == NO_DRAG); if(event->modifiers() & Qt::ShiftModifier) { m_oldZoom = m_currentShape->zoom(); m_dragMode = ZOOM_DRAG; } else { m_oldScroll = m_currentShape->scroll(); m_dragMode = SCROLL_DRAG; } } else { selection->deselectAll(); m_currentShape = hit; selection->select(m_currentShape); emit(shapeChanged(m_currentShape)); } } } } void WebTool::mouseMoveEvent(KoPointerEvent *event) { switch(m_dragMode) { case NO_DRAG: break; case SCROLL_DRAG: { m_currentShape->scrollOf(m_scrollPoint - event->point); m_scrollPoint = event->point; m_currentShape->update(); break; } case ZOOM_DRAG: { m_currentShape->zoomOf(1.0 - (event->point.y() - m_scrollPoint.y()) / 100.0); m_scrollPoint = event->point; m_currentShape->update(); } } } void WebTool::mouseReleaseEvent(KoPointerEvent *event) { Q_UNUSED(event); switch(m_dragMode) { case NO_DRAG: break; case SCROLL_DRAG: canvas()->addCommand(new ChangeScroll(m_currentShape, m_oldScroll)); break; case ZOOM_DRAG: canvas()->addCommand(new ChangeZoom(m_currentShape, m_oldZoom)); break; } m_dragMode = NO_DRAG; } QList > WebTool::createOptionWidgets() { QList > widgets; WebToolWidget* widget = new WebToolWidget(this); widget->open(m_currentShape); widgets.append(widget); return widgets; } diff --git a/braindump/plugins/webshape/WebTool.h b/braindump/plugins/webshape/WebTool.h index 223944907ab..d12693c0771 100644 --- a/braindump/plugins/webshape/WebTool.h +++ b/braindump/plugins/webshape/WebTool.h @@ -1,67 +1,68 @@ /* * Copyright (c) 2009 Cyrille Berger * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * either version 2, or (at your option) any later version of the License. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef _WEB_TOOL_H_ #define _WEB_TOOL_H_ -#include #include +#include + class WebShape; class KoShape; class WebTool : public KoToolBase { Q_OBJECT public: explicit WebTool(KoCanvasBase *canvas); ~WebTool(); /// reimplemented void activate(ToolActivation toolActivation, const QSet &shapes); /// reimplemented virtual void paint(QPainter &painter, const KoViewConverter &converter); /// reimplemented virtual void mousePressEvent(KoPointerEvent *event); /// reimplemented virtual void mouseMoveEvent(KoPointerEvent *event); /// reimplemented virtual void mouseReleaseEvent(KoPointerEvent *event); Q_SIGNALS: void shapeChanged(WebShape*); protected: virtual QList > createOptionWidgets(); private: WebShape* m_currentShape; KoShape* m_tmpShape; enum DragMode { NO_DRAG, SCROLL_DRAG, ZOOM_DRAG }; DragMode m_dragMode; QPointF m_scrollPoint; qreal m_oldZoom; QPointF m_oldScroll; }; #endif diff --git a/braindump/plugins/webshape/WebToolFactory.cpp b/braindump/plugins/webshape/WebToolFactory.cpp index f8f7448344f..95a11ab450b 100644 --- a/braindump/plugins/webshape/WebToolFactory.cpp +++ b/braindump/plugins/webshape/WebToolFactory.cpp @@ -1,44 +1,45 @@ /* * Copyright (c) 2009 Cyrille Berger * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * either version 2, or (at your option) any later version of the License. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ +#include + +#include + #include "WebToolFactory.h" #include "WebTool.h" #include "WebShape.h" -#include -#include - WebToolFactory::WebToolFactory() : KoToolFactoryBase("WebToolFactoryID") { setToolTip(i18n("Web shape editing")); setToolType(dynamicToolType()); setIconName(koIconNameCStr("applications-internet")); setPriority(1); setActivationShapeId(WEBSHAPEID); } WebToolFactory::~WebToolFactory() { } KoToolBase* WebToolFactory::createTool(KoCanvasBase * canvas) { return new WebTool(canvas); } diff --git a/braindump/plugins/webshape/WebToolWidget.cpp b/braindump/plugins/webshape/WebToolWidget.cpp index e2acf67944a..3c3716119e9 100644 --- a/braindump/plugins/webshape/WebToolWidget.cpp +++ b/braindump/plugins/webshape/WebToolWidget.cpp @@ -1,125 +1,128 @@ /* * Copyright (c) 2009 Cyrille Berger * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * either version 2, or (at your option) any later version of the License. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "WebToolWidget.h" -#include #include #include -#include "WebShape.h" -#include "WebTool.h" +#include + #include #include #include + +#include "WebShape.h" +#include "WebTool.h" + class ChangeUrl : public KUndo2Command { public: ChangeUrl(WebShape* shape, const QUrl& newUrl) : m_shape(shape), m_newUrl(newUrl), m_oldUrl(shape->url()) { } virtual void undo() { m_shape->setUrl(m_oldUrl); } virtual void redo() { m_shape->setUrl(m_newUrl); } private: WebShape *m_shape; QUrl m_newUrl; QUrl m_oldUrl; }; class ChangeCached : public KUndo2Command { public: ChangeCached(WebShape* shape) : m_shape(shape) { if(shape->isCached()) { m_cache = shape->cache(); } } virtual void undo() { m_shape->setCached(!m_shape->isCached()); if(m_shape->isCached()) { m_shape->setCache(m_cache); } } virtual void redo() { m_shape->setCached(!m_shape->isCached()); } private: WebShape *m_shape; QString m_cache; }; WebToolWidget::WebToolWidget(WebTool* _tool) : m_tool(_tool), m_shape(0) { m_widget.setupUi(this); connect(m_widget.urlEdit, SIGNAL(editingFinished()), SLOT(save())); connect(m_widget.useCache, SIGNAL(stateChanged(int)), SLOT(save())); connect(m_tool, SIGNAL(shapeChanged(WebShape*)), SLOT(open(WebShape*))); } void WebToolWidget::blockChildSignals(bool block) { m_widget.urlEdit->blockSignals(block); m_widget.useCache->blockSignals(block); } void WebToolWidget::open(WebShape *shape) { m_shape = shape; if(!m_shape) return; blockChildSignals(true); m_widget.urlEdit->setText(m_shape->url().url()); m_widget.useCache->setChecked(m_shape->isCached()); blockChildSignals(false); } void WebToolWidget::save() { if(!m_shape) return; QString newUrl = m_widget.urlEdit->text(); bool newCached = m_widget.useCache->isChecked(); KoCanvasController* canvasController = KoToolManager::instance()->activeCanvasController(); if(canvasController) { KoCanvasBase* canvas = canvasController->canvas(); if(newUrl != m_shape->url().url()) { canvas->addCommand(new ChangeUrl(m_shape, newUrl)); } if(newCached != m_shape->isCached()) { canvas->addCommand(new ChangeCached(m_shape)); } } } KUndo2Command * WebToolWidget::createCommand() { save(); return 0; } WebShape* WebToolWidget::shape() { return m_shape; } diff --git a/braindump/src/Canvas.cpp b/braindump/src/Canvas.cpp index fd71de8ad6b..f306c0606e0 100644 --- a/braindump/src/Canvas.cpp +++ b/braindump/src/Canvas.cpp @@ -1,357 +1,357 @@ /* * Copyright (c) 2006,2007 Thorsten Zachmann * Copyright (c) 2009,2010 Cyrille Berger * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * either version 2, or (at your option) any later version of the License. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "Canvas.h" #include #include #include #include #include #include #include #include #include #include #include #include "RootSection.h" #include "View.h" #include "ViewManager.h" #include "Section.h" #include "Layout.h" #include "SectionContainer.h" Canvas::Canvas(View* view, RootSection* doc, Section* currentSection) : QWidget(view) , KoCanvasBase(currentSection ? currentSection->sectionContainer() : 0) , m_origin(0, 0) , m_view(view) , m_doc(doc) { m_shapeManager = new KoShapeManager(this); connect(m_shapeManager, SIGNAL(selectionChanged()), SLOT(updateOriginAndSize())); m_toolProxy = new KoToolProxy(this); setFocusPolicy(Qt::StrongFocus); // this is much faster than painting it in the paintevent QPalette pal = palette(); pal.setColor(QPalette::Base, Qt::white); pal.setColor(QPalette::Text, Qt::black); setPalette(pal); setBackgroundRole(QPalette::Base); setAutoFillBackground(true); setAttribute(Qt::WA_InputMethodEnabled, true); if(currentSection) { QList shapes; shapes.push_back(currentSection->sectionContainer()->layer()); shapeManager()->setShapes(shapes, KoShapeManager::AddWithoutRepaint); KoShapeLayer* layer = currentSection->sectionContainer()->layer(); shapeManager()->selection()->setActiveLayer(layer); // Make sure the canvas is enabled setEnabled(true); update(); } else { setEnabled(false); } } Canvas::~Canvas() { delete m_toolProxy; delete m_shapeManager; } -#include + void Canvas::setDocumentOffset(const QPoint &offset) { m_originalOffset = offset; updateOffset(); } void Canvas::addCommand(KUndo2Command *command) { m_doc->addCommand(m_view->activeSection(), command); updateOriginAndSize(); } KoShapeManager * Canvas::shapeManager() const { return m_shapeManager; } void Canvas::updateCanvas(const QRectF& rc) { QRect clipRect(viewToWidget(viewConverter()->documentToView(rc).toRect())); clipRect.adjust(-2, -2, 2, 2); // Resize to fit anti-aliasing clipRect.moveTopLeft(clipRect.topLeft() - m_documentOffset); update(clipRect); emit canvasUpdated(); } KoViewConverter * Canvas::viewConverter() const { return m_view->zoomHandler(); } KoUnit Canvas::unit() const { return KoUnit(KoUnit::Centimeter); } const QPoint & Canvas::documentOffset() const { return m_documentOffset; } QPoint Canvas::documentOrigin() const { return m_origin; } void Canvas::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.translate(-documentOffset()); painter.setRenderHint(QPainter::Antialiasing); QRectF clipRect = event->rect().translated(documentOffset()); painter.setClipRect(clipRect); painter.translate(m_origin.x(), m_origin.y()); const KoViewConverter* converter = viewConverter(); shapeManager()->paint(painter, *converter, false); painter.setRenderHint(QPainter::Antialiasing, false); painter.setRenderHint(QPainter::Antialiasing); m_toolProxy->paint(painter, *converter); } void Canvas::tabletEvent(QTabletEvent *event) { m_toolProxy->tabletEvent(event, viewConverter()->viewToDocument(widgetToView(event->pos() + m_documentOffset))); } void Canvas::mousePressEvent(QMouseEvent *event) { m_toolProxy->mousePressEvent(event, viewConverter()->viewToDocument(widgetToView(event->pos() + m_documentOffset))); if(!event->isAccepted() && event->button() == Qt::RightButton) { showContextMenu(event->globalPos(), toolProxy()->popupActionList()); } event->setAccepted(true); } void Canvas::mouseDoubleClickEvent(QMouseEvent *event) { m_toolProxy->mouseDoubleClickEvent(event, viewConverter()->viewToDocument(widgetToView(event->pos() + m_documentOffset))); } void Canvas::mouseMoveEvent(QMouseEvent *event) { m_toolProxy->mouseMoveEvent(event, viewConverter()->viewToDocument(widgetToView(event->pos() + m_documentOffset))); } void Canvas::mouseReleaseEvent(QMouseEvent *event) { m_toolProxy->mouseReleaseEvent(event, viewConverter()->viewToDocument(widgetToView(event->pos() + m_documentOffset))); } void Canvas::keyPressEvent(QKeyEvent *event) { m_toolProxy->keyPressEvent(event); #if 0 if(! event->isAccepted()) { event->accept(); switch(event->key()) { case Qt::Key_Home: m_view->navigatePage(KoPageApp::PageFirst); break; case Qt::Key_PageUp: m_view->navigatePage(KoPageApp::PagePrevious); break; case Qt::Key_PageDown: m_view->navigatePage(KoPageApp::PageNext); break; case Qt::Key_End: m_view->navigatePage(KoPageApp::PageLast); break; default: event->ignore(); break; } } if(! event->isAccepted()) { if(event->key() == Qt::Key_Backtab or(event->key() == Qt::Key_Tab && (event->modifiers() & Qt::ShiftModifier))) { focusNextPrevChild(false); } else if(event->key() == Qt::Key_Tab) { focusNextPrevChild(true); } } #endif } void Canvas::keyReleaseEvent(QKeyEvent *event) { m_toolProxy->keyReleaseEvent(event); } void Canvas::wheelEvent(QWheelEvent * event) { m_toolProxy->wheelEvent(event, viewConverter()->viewToDocument(widgetToView(event->pos() + m_documentOffset))); } void Canvas::closeEvent(QCloseEvent * event) { event->ignore(); } void Canvas::updateInputMethodInfo() { updateMicroFocus(); } QVariant Canvas::inputMethodQuery(Qt::InputMethodQuery query) const { if (query == Qt::ImMicroFocus) { QRectF rect = (m_toolProxy->inputMethodQuery(query, *(viewConverter())).toRectF()).toRect(); QPointF scroll(canvasController()->scrollBarValue()); rect.translate(documentOrigin() - scroll); return rect.toRect(); } return m_toolProxy->inputMethodQuery(query, *(viewConverter())); } void Canvas::inputMethodEvent(QInputMethodEvent *event) { m_toolProxy->inputMethodEvent(event); } void Canvas::resizeEvent(QResizeEvent * event) { emit sizeChanged(event->size()); updateOriginAndSize(); } void Canvas::showContextMenu(const QPoint& globalPos, const QList& actionList) { m_view->unplugActionList("toolproxy_action_list"); m_view->plugActionList("toolproxy_action_list", actionList); QMenu *menu = dynamic_cast(m_view->factory()->container("default_canvas_popup", m_view)); if(menu) menu->exec(globalPos); } void Canvas::setBackgroundColor(const QColor &color) { QPalette pal = palette(); pal.setColor(QPalette::Normal, backgroundRole(), color); pal.setColor(QPalette::Inactive, backgroundRole(), color); setPalette(pal); } void Canvas::updateOriginAndSize() { if(m_view->activeSection()) { QRectF rect = m_view->activeSection()->layout()->boundingBox(); if(rect != m_oldDocumentRect) { m_oldDocumentRect = rect; emit(documentRect(rect)); update(); } QRect viewRect = viewConverter()->documentToView(rect).toRect(); if(m_oldViewDocumentRect != viewRect) { m_oldViewDocumentRect = viewRect; m_origin = -viewRect.topLeft(); KoCanvasController* controller = canvasController(); if(controller) { // tell canvas controller the new document size in pixel controller->updateDocumentSize(viewRect.size(), true); // make sure the actual selection is visible KoSelection * selection = m_shapeManager->selection(); if(selection->count()) controller->ensureVisible(viewConverter()->documentToView(selection->boundingRect())); updateOffset(); } } } } void Canvas::updateOffset() { qreal dx = qMax(0, (size().width() - m_oldViewDocumentRect.size().width()) / 2); qreal dy = qMax(0, (size().height() - m_oldViewDocumentRect.size().height()) / 2); m_documentOffset = m_originalOffset - QPoint(dx, dy); } void Canvas::gridSize(qreal *horizontal, qreal *vertical) const { *horizontal = 1; *vertical = 1; } bool Canvas::snapToGrid() const { return false; } void Canvas::setCursor(const QCursor &cursor) { QWidget::setCursor(cursor); } void Canvas::focusInEvent(QFocusEvent * event) { QWidget::focusInEvent(event); emit(canvasReceivedFocus()); } QPoint Canvas::widgetToView(const QPoint& p) const { return p - m_origin; } QRect Canvas::widgetToView(const QRect& r) const { return r.translated(- m_origin); } QPoint Canvas::viewToWidget(const QPoint& p) const { return p + m_origin; } QRect Canvas::viewToWidget(const QRect& r) const { return r.translated(m_origin); } #include "Canvas.moc" diff --git a/braindump/src/MainWindow.cpp b/braindump/src/MainWindow.cpp index 04d037d874c..592120387df 100644 --- a/braindump/src/MainWindow.cpp +++ b/braindump/src/MainWindow.cpp @@ -1,255 +1,255 @@ /* * Copyright (c) 2009 Cyrille Berger * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * either version 2, or (at your option) any later version of the License. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "MainWindow.h" #include #include #include #include #include +#include #include #include #include #include #include #include #include #include #include #include #include "RootSection.h" #include "View.h" #include "Canvas.h" #include "import/DockerManager.h" #include -#include #include "StatusBarItem.h" MainWindow::MainWindow(RootSection* document, const KComponentData &componentData) : m_doc(document), m_activeView(0), m_dockerManager(0) { Q_ASSERT(componentData.isValid()); KGlobal::setActiveComponent(componentData); // then, setup our actions setupActions(); // Create the docker manager after setting up the action m_dockerManager = new DockerManager(this); // Setup the view view = new View(m_doc, this); setCentralWidget(view); // a call to KXmlGuiWindow::setupGUI() populates the GUI // with actions, using KXMLGUI. // It also applies the saved mainwindow settings, if any, and ask the // mainwindow to automatically save settings if changed: window size, // toolbar position, icon size, etc. setupGUI(); activateView(view); // Position and show toolbars according to user's preference setAutoSaveSettings(componentData.componentName()); const int scnum = QApplication::desktop()->screenNumber(parentWidget()); QRect desk = QApplication::desktop()->screenGeometry(scnum); // if the desktop is virtual then use virtual screen size if(QApplication::desktop()->isVirtualDesktop()) desk = QApplication::desktop()->screenGeometry(QApplication::desktop()->screen()); KConfigGroup config(KGlobal::config(), componentData.componentName()); const QSize size(config.readEntry(QString::fromLatin1("Width %1").arg(desk.width()), 0), config.readEntry(QString::fromLatin1("Height %1").arg(desk.height()), 0)); resize(size); foreach(QDockWidget * wdg, m_dockWidgets) { if((wdg->features() & QDockWidget::DockWidgetClosable) == 0) { wdg->setVisible(true); } } forceDockTabFonts(); } MainWindow::~MainWindow() { // The view need to be deleted before the dockermanager delete view; } void MainWindow::setupActions() { KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollection()); m_doc->createActions(actionCollection()); m_dockWidgetMenu = new KActionMenu(i18n("Dockers"), this); actionCollection()->addAction("settings_dockers_menu", m_dockWidgetMenu); m_dockWidgetMenu->setVisible(false); } QDockWidget* MainWindow::createDockWidget(KoDockFactoryBase* factory) { QDockWidget* dockWidget = 0; if(!m_dockWidgetMap.contains(factory->id())) { dockWidget = factory->createDockWidget(); // It is quite possible that a dock factory cannot create the dock; don't // do anything in that case. if(!dockWidget) return 0; m_dockWidgets.push_back(dockWidget); dockWidget->setObjectName(factory->id()); dockWidget->setParent(this); if(dockWidget->widget() && dockWidget->widget()->layout()) dockWidget->widget()->layout()->setContentsMargins(1, 1, 1, 1); Qt::DockWidgetArea side = Qt::RightDockWidgetArea; bool visible = true; switch(factory->defaultDockPosition()) { case KoDockFactoryBase::DockTornOff: dockWidget->setFloating(true); // position nicely? break; case KoDockFactoryBase::DockTop: side = Qt::TopDockWidgetArea; break; case KoDockFactoryBase::DockLeft: side = Qt::LeftDockWidgetArea; break; case KoDockFactoryBase::DockBottom: side = Qt::BottomDockWidgetArea; break; case KoDockFactoryBase::DockRight: side = Qt::RightDockWidgetArea; break; case KoDockFactoryBase::DockMinimized: visible = false; break; default:; } addDockWidget(side, dockWidget); if(dockWidget->features() & QDockWidget::DockWidgetClosable) { m_dockWidgetMenu->addAction(dockWidget->toggleViewAction()); if(!visible) dockWidget->hide(); } m_dockWidgetMap.insert(factory->id(), dockWidget); } else { dockWidget = m_dockWidgetMap[ factory->id()]; } KConfigGroup group(KGlobal::config(), "GUI"); QFont dockWidgetFont = KGlobalSettings::generalFont(); qreal pointSize = group.readEntry("palettefontsize", dockWidgetFont.pointSize() * 0.75); pointSize = qMax(pointSize, KGlobalSettings::smallestReadableFont().pointSizeF()); dockWidgetFont.setPointSizeF(pointSize); #ifdef Q_WS_MAC dockWidget->setAttribute(Qt::WA_MacSmallSize, true); #endif dockWidget->setFont(dockWidgetFont); connect(dockWidget, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(forceDockTabFonts())); return dockWidget; } void MainWindow::forceDockTabFonts() { QObjectList chis = children(); for(int i = 0; i < chis.size(); ++i) { if(chis.at(i)->inherits("QTabBar")) { QFont dockWidgetFont = KGlobalSettings::generalFont(); qreal pointSize = KGlobalSettings::smallestReadableFont().pointSizeF(); dockWidgetFont.setPointSizeF(pointSize); ((QTabBar *)chis.at(i))->setFont(dockWidgetFont); } } } DockerManager* MainWindow::dockerManager() { return m_dockerManager; } void MainWindow::activateView(View* view) { Q_ASSERT(factory()); // Desactivate previous view if(m_activeView) { factory()->removeClient(m_activeView); foreach(StatusBarItem * item, m_statusBarItems[m_activeView]) { item->ensureItemHidden(statusBar()); } } // Set the new view m_activeView = view; if(m_activeView) { factory()->addClient(view); // Show the status widget for the current view foreach(StatusBarItem * item, m_statusBarItems[m_activeView]) { item->ensureItemShown(statusBar()); } } } void MainWindow::addStatusBarItem(QWidget* _widget, int _stretch, View* _view) { Q_ASSERT(_widget); Q_ASSERT(_view); QList& list = m_statusBarItems[_view]; StatusBarItem* item = new StatusBarItem(_widget, _stretch, _view); if(_view == m_activeView) { item->ensureItemShown(statusBar()); } list.append(item); } void MainWindow::removeStatusBarItem(QWidget* _widget) { foreach(View * key, m_statusBarItems.keys()) { QList& list = m_statusBarItems[key]; foreach(StatusBarItem * item, list) { if(item->m_widget == _widget) { list.removeAll(item); item->ensureItemHidden(statusBar()); delete item; return; } } } - kWarning() << "Widget " << _widget << " not found in the status bar"; + qWarning() << "Widget " << _widget << " not found in the status bar"; } QList MainWindow::canvasObservers() const { QList observers; foreach(QDockWidget * docker, m_dockWidgets) { KoCanvasObserverBase *observer = dynamic_cast(docker); if(observer) { observers << observer; } } return observers; } diff --git a/braindump/src/RootSection.cpp b/braindump/src/RootSection.cpp index 9a6902beceb..54839b80bab 100644 --- a/braindump/src/RootSection.cpp +++ b/braindump/src/RootSection.cpp @@ -1,90 +1,90 @@ /* * Copyright (c) 2009 Cyrille Berger * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * either version 2, or (at your option) any later version of the License. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "RootSection.h" +#include + #include #include "Section.h" #include "SectionsIO.h" #include "ViewManager.h" -#include - RootSection::RootSection() : SectionGroup(0), m_undoStack(new KUndo2Stack(this)), m_viewManager(new ViewManager(this)), m_sectionsSaver(new SectionsIO(this)), m_currentSection(0) { connect(m_undoStack, SIGNAL(indexChanged(int)), SIGNAL(commandExecuted())); connect(m_undoStack, SIGNAL(indexChanged(int)), SLOT(undoIndexChanged(int))); if(sections().isEmpty()) { newSection(0); } } RootSection::~RootSection() { } ViewManager* RootSection::viewManager() { return m_viewManager; } SectionsIO* RootSection::sectionsIO() { return m_sectionsSaver; } void RootSection::addCommand(Section* _section, KUndo2Command* _command) { - kDebug() << _command << " is added for section " << _section; + qDebug() << _command << " is added for section " << _section; m_commandsMap[_command] = _section; m_undoStack->push(_command); } void RootSection::createActions(KActionCollection* _actionCollection) { m_undoStack->createUndoAction(_actionCollection); m_undoStack->createRedoAction(_actionCollection); } KUndo2Stack* RootSection::undoStack() { return m_undoStack; } void RootSection::undoIndexChanged(int idx) { const KUndo2Command* command = m_undoStack->command(idx - 1); - kDebug() << idx << " " << command << " " << m_undoStack->count() << " " << m_undoStack->cleanIndex() << " " << m_undoStack->index(); + qDebug() << idx << " " << command << " " << m_undoStack->count() << " " << m_undoStack->cleanIndex() << " " << m_undoStack->index(); Section* section = m_commandsMap[command]; if(!section && idx == m_undoStack->count()) { section = m_currentSection; m_commandsMap[command] = section; } m_sectionsSaver->push(section); - kDebug() << "save section: " << section; + qDebug() << "save section: " << section; } void RootSection::setCurrentSection(Section* _section) { m_currentSection = _section; } #include "RootSection.moc" diff --git a/braindump/src/SectionsIO.cpp b/braindump/src/SectionsIO.cpp index 7eedb6207b8..2190fb20c5c 100644 --- a/braindump/src/SectionsIO.cpp +++ b/braindump/src/SectionsIO.cpp @@ -1,361 +1,360 @@ /* * Copyright (c) 2009 Cyrille Berger * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * either version 2, or (at your option) any later version of the License. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "SectionsIO.h" #include #include #include - -#include +#include #include #include #include #include #include #include #include #include #include #include #include #include "RootSection.h" #include "SectionGroup.h" #include "Section.h" #include "SectionContainer.h" #include "Layout.h" #include "LayoutFactoryRegistry.h" #include "Xml.h" SectionsIO::SectionsIO(RootSection* rootSection) : m_rootSection(rootSection), m_timer(new QTimer(this)), m_nextNumber(0) { m_timer->start(60 * 1000); // Every minute connect(m_timer, SIGNAL(timeout()), SLOT(save())); m_directory = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/sections/"; QDir().mkdir(m_directory); // Finally load load(); } SectionsIO::~SectionsIO() { } void SectionsIO::push(Section* _section, PushMode _pushMode) { if(!m_sectionsToSave.contains(_section)) { m_sectionsToSave.push_back(_section); } if(_pushMode == RecursivePush) { foreach(Section * sec, _section->sections()) { push(sec, RecursivePush); } } } struct SectionsIO::SaveContext { enum Version { VERSION_1 }; Section* section; QString filename; bool saveSection(SectionsIO* sectionsIO); bool loadSection(SectionsIO* sectionsIO, Version version); }; bool SectionsIO::SaveContext::saveSection(SectionsIO* sectionsIO) { struct Finally { Finally(KoStore *s) : store(s) { } ~Finally() { delete store; } KoStore *store; }; QString fullFileName = sectionsIO->m_directory + filename; QString fullFileNameTmpNew = fullFileName + ".tmp_new/"; QString fullFileNameTmpOld = fullFileName + ".tmp_old"; QDir().remove(fullFileNameTmpNew); const char* mimeType = KoOdf::mimeType(KoOdf::Text); QDir().mkdir(fullFileNameTmpNew); KoStore* store = KoStore::createStore(fullFileNameTmpNew, KoStore::Write, mimeType, KoStore::Directory); Finally finaly(store); KoOdfWriteStore odfStore(store); KoEmbeddedDocumentSaver embeddedSaver; KoXmlWriter* manifestWriter = odfStore.manifestWriter(mimeType); KoXmlWriter* contentWriter = odfStore.contentWriter(); KoXmlWriter* bodyWriter = odfStore.bodyWriter(); if(!manifestWriter || !contentWriter || !bodyWriter) { return false; } KoGenStyles mainStyles; KoShapeSavingContext * context = new KoShapeSavingContext(*bodyWriter, mainStyles, embeddedSaver); context->addOption(KoShapeSavingContext::DrawId); bodyWriter->startElement("office:body"); Xml::writeBraindumpNS(*bodyWriter); bodyWriter->startElement(KoOdf::bodyContentElement(KoOdf::Text, true)); section->sectionContainer()->saveOdf(*context); bodyWriter->startElement("braindump:layout"); bodyWriter->addAttribute("braindump:type", section->layout()->id()); bodyWriter->endElement(); // braindump:layout bodyWriter->endElement(); // office:element bodyWriter->endElement(); // office:body mainStyles.saveOdfStyles(KoGenStyles::DocumentAutomaticStyles, contentWriter); odfStore.closeContentWriter(); //add manifest line for content.xml manifestWriter->addManifestEntry("content.xml", "text/xml"); if(!mainStyles.saveOdfStylesDotXml(store, manifestWriter)) { return false; } if(!context->saveDataCenter(store, manifestWriter)) { - kDebug() << "save data centers failed"; + qDebug() << "save data centers failed"; return false; } // Save embedded objects KoDocumentBase::SavingContext documentContext(odfStore, embeddedSaver); if(!embeddedSaver.saveEmbeddedDocuments(documentContext)) { - kDebug() << "save embedded documents failed"; + qDebug() << "save embedded documents failed"; return false; } // Write out manifest file if(!odfStore.closeManifestWriter()) { return false; } delete store; finaly.store = 0; delete context; QDir().remove(fullFileNameTmpOld); QDir().rename(fullFileName, fullFileNameTmpOld); QDir().rename(fullFileNameTmpNew, fullFileName); QDir().remove(fullFileNameTmpOld); return true; } bool SectionsIO::SaveContext::loadSection(SectionsIO* sectionsIO, SectionsIO::SaveContext::Version version) { Q_UNUSED(version); // In case saving problem occurred, try to recover a directory either new or old QString fullFileName = sectionsIO->m_directory + filename; QString fullFileNameTmpNew = fullFileName + ".tmp_new/"; QString fullFileNameTmpOld = fullFileName + ".tmp_old"; if(!QFileInfo(fullFileName).exists()) { if(QFileInfo(fullFileNameTmpNew).exists()) { QDir().rename(fullFileNameTmpNew, fullFileName); } else if(QFileInfo(fullFileNameTmpOld).exists()) { QDir().rename(fullFileNameTmpOld, fullFileName); } else { return false; } } - kDebug() << "Loading from " << fullFileName; + qDebug() << "Loading from " << fullFileName; const char* mimeType = KoOdf::mimeType(KoOdf::Text); KoStore* store = KoStore::createStore(fullFileName + '/', KoStore::Read, mimeType, KoStore::Directory); KoOdfReadStore odfStore(store); QString errorMessage; if(! odfStore.loadAndParse(errorMessage)) { - kError() << "loading and parsing failed:" << errorMessage << endl; + qCritical() << "loading and parsing failed:" << errorMessage << endl; return false; } KoXmlElement content = odfStore.contentDoc().documentElement(); KoXmlElement realBody(KoXml::namedItemNS(content, KoXmlNS::office, "body")); KoXmlElement body = KoXml::namedItemNS(realBody, KoXmlNS::office, KoOdf::bodyContentElement(KoOdf::Text, false)); KoOdfLoadingContext loadingContext(odfStore.styles(), odfStore.store()); KoShapeLoadingContext context(loadingContext, section->sectionContainer()->resourceManager()); KoXmlElement element; QList shapes; forEachElement(element, body) { - kDebug() << "loading shape" << element.nodeName(); + qDebug() << "loading shape" << element.nodeName(); if(element.nodeName() == "braindump:section") { section->sectionContainer()->loadOdf(element, context, shapes); } else if(element.nodeName() == "braindump:layout") { QString type = element.attribute("type"); Layout* layout = LayoutFactoryRegistry::instance()->createLayout(type); if(layout) { section->setLayout(layout); } } } section->layout()->addShapes(shapes); return true; } void SectionsIO::saveTheStructure(QDomDocument& doc, QDomElement& elt, SectionGroup* root, QList& contextToRemove) { foreach(Section * section, root->sections()) { SaveContext* context = m_contextes[section]; if(context) { contextToRemove.removeAll(context); } else { context = new SaveContext; m_contextes[section] = context; context->section = section; context->filename = generateFileName(); } Q_ASSERT(context); QDomElement celt = doc.createElement("Section"); elt.appendChild(celt); celt.setAttribute("filename", context->filename); celt.setAttribute("name", section->name()); saveTheStructure(doc, celt, section, contextToRemove); } } void SectionsIO::save() { - kDebug() << "Start saving"; + qDebug() << "Start saving"; if(m_sectionsToSave.isEmpty()) { - kDebug() << "No section to save"; + qDebug() << "No section to save"; return; } QList contextToRemove = m_contextes.values(); // First: save the structure QDomDocument doc; QDomElement root = doc.createElement("RootElement"); doc.appendChild(root); saveTheStructure(doc, root, m_rootSection, contextToRemove); QFile file(structureFileName()); file.open(QIODevice::WriteOnly); file.write(doc.toString().toUtf8()); file.close(); // Second: save each section foreach(SaveContext * saveContext, m_contextes) { if(m_sectionsToSave.contains(saveContext->section)) { if(saveContext->saveSection(this)) { - kDebug() << "Successfully loaded: " << saveContext->section->name(); + qDebug() << "Successfully loaded: " << saveContext->section->name(); } else { - kDebug() << "Saving failed"; // TODO: Report it + qDebug() << "Saving failed"; // TODO: Report it } } } m_sectionsToSave.clear(); // Last remove unused sections foreach(SaveContext * saveContext, contextToRemove) { QDir().remove(m_directory + saveContext->filename); m_contextes.remove(saveContext->section); delete saveContext; } } void SectionsIO::loadTheStructure(QDomElement& elt, SectionGroup* parent, RootSection* _rootSection) { QDomNode n = elt.firstChild(); while(!n.isNull()) { QDomElement e = n.toElement(); // try to convert the node to an element. if(!e.isNull() && e.nodeName() == "Section") { Section* section = new Section(_rootSection); QString name = e.attribute("name", ""); if(name.isEmpty()) { name = SectionGroup::nextName(); } section->setName(name); parent->insertSection(section); SaveContext* context = new SaveContext; context->filename = e.attribute("filename", ""); context->section = section; m_contextes[section] = context; loadTheStructure(e, section, _rootSection); } n = n.nextSibling(); } } void SectionsIO::load() { QDomDocument doc; QFile file(structureFileName()); if(!file.open(QIODevice::ReadOnly)) return; if(!doc.setContent(&file)) { file.close(); return; } file.close(); QDomElement docElem = doc.documentElement(); if(docElem.nodeName() != "RootElement") return; loadTheStructure(docElem, m_rootSection, m_rootSection); // Second: load each section foreach(SaveContext * saveContext, m_contextes) { if(!saveContext->loadSection(this, SaveContext::VERSION_1)) { - kDebug() << "Loading failed"; // TODO: Report it + qDebug() << "Loading failed"; // TODO: Report it } } } QString SectionsIO::generateFileName() { for(; true; ++m_nextNumber) { QString filename = "section" + QString::number(m_nextNumber); if(!QFileInfo(m_directory + filename).exists() && !usedFileName(filename)) { return filename; } } } bool SectionsIO::usedFileName(const QString& filename) { foreach(SaveContext * context, m_contextes.values()) { if(context->filename == filename) return true; } return false; } QString SectionsIO::structureFileName() { return m_directory + "structure.xml"; } #include "SectionsIO.moc" diff --git a/braindump/src/View.cpp b/braindump/src/View.cpp index af74bd3b8ee..53d410a1c8c 100644 --- a/braindump/src/View.cpp +++ b/braindump/src/View.cpp @@ -1,421 +1,421 @@ /* * Copyright (c) 2009,2010 Cyrille Berger * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * either version 2, or (at your option) any later version of the License. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "View.h" #include #include #include #include #include #include #include #include #include #include +#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "KoZoomController.h" #include #include "Canvas.h" #include "RootSection.h" #include "Section.h" #include "ViewManager.h" #include "import/DockerManager.h" #include "KoToolBoxFactory.h" #include -#include #include #include #include #include #include #include #include "KoOdf.h" #include "KoShapeGroup.h" #include "KoShapeDeleteCommand.h" #include "KoShapeCreateCommand.h" #include "KoShapeGroupCommand.h" #include "KoShapeUngroupCommand.h" #include "MainWindow.h" #include "SectionContainer.h" #include "SectionsBoxDock.h" #include "Layout.h" #include "SectionPropertiesDock.h" #include "commands/RememberPositionCommand.h" View::View(RootSection *document, MainWindow* parent) : QWidget(parent) , m_doc(document) , m_canvas(0) , m_activeSection(0) , m_mainWindow(parent) , m_cutController(0) , m_copyController(0) { setXMLFile("braindumpview.rc"); m_doc->viewManager()->addView(this); m_editPaste = actionCollection()->addAction(KStandardAction::Paste, "edit_paste", this, SLOT(editPaste())); m_editCut = actionCollection()->addAction(KStandardAction::Cut, "edit_cut", 0, 0); m_editCopy = actionCollection()->addAction(KStandardAction::Copy, "edit_copy", 0, 0); initGUI(); initActions(); loadExtensions(); if(m_doc->sections().count() > 0) { setActiveSection(m_doc->sections()[0]); } else { setActiveSection(0); } m_doc->viewManager()->viewHasFocus(this); } View::~View() { m_doc->viewManager()->removeView(this); KoToolManager::instance()->removeCanvasController(m_canvasController); delete m_zoomController; } Section* View::activeSection() const { return m_activeSection; } void View::initGUI() { // add all plugins. foreach(const QString & docker, KoDockRegistry::instance()->keys()) { - kDebug() << "Creating docker: " << docker; + qDebug() << "Creating docker: " << docker; KoDockFactoryBase *factory = KoDockRegistry::instance()->value(docker); m_mainWindow->createDockWidget(factory); } // Init the widgets QGridLayout * gridLayout = new QGridLayout(this); gridLayout->setMargin(0); gridLayout->setSpacing(0); setLayout(gridLayout); m_canvasController = new KoCanvasControllerWidget(actionCollection(), this); m_canvasController->setCanvasMode(KoCanvasController::Infinite); createCanvas(0); KoToolManager::instance()->addController(m_canvasController); KoToolManager::instance()->registerTools(actionCollection(), m_canvasController); m_zoomController = new KoZoomController(m_canvasController, &m_zoomHandler, actionCollection()); connect(m_zoomController, SIGNAL(zoomChanged(KoZoomMode::Mode,qreal)), this, SLOT(slotZoomChanged(KoZoomMode::Mode,qreal))); m_zoomAction = m_zoomController->zoomAction(); m_mainWindow->addStatusBarItem(m_zoomAction->createWidget(m_mainWindow->statusBar()), 0, this); m_zoomController->setZoomMode(KoZoomMode::ZOOM_WIDTH); gridLayout->addWidget(m_canvasController, 1, 1); connect(m_canvasController->proxyObject, SIGNAL(canvasMousePositionChanged(QPoint)), this, SLOT(updateMousePosition(QPoint))); KoToolBoxFactory toolBoxFactory; m_mainWindow->createDockWidget(&toolBoxFactory); connect(m_canvasController, SIGNAL(toolOptionWidgetsChanged(QList >)), m_mainWindow->dockerManager(), SLOT(newOptionWidgets(QList >))); SectionsBoxDockFactory structureDockerFactory; m_sectionsBoxDock = qobject_cast(m_mainWindow->createDockWidget(&structureDockerFactory)); Q_ASSERT(m_sectionsBoxDock); m_sectionsBoxDock->setup(m_doc, this); SectionPropertiesDockFactory sectionPropertiesDockerFactory; m_sectionPropertiesDock = qobject_cast(m_mainWindow->createDockWidget(§ionPropertiesDockerFactory)); Q_ASSERT(m_sectionPropertiesDock); m_sectionPropertiesDock->setRootSection(m_doc); KoToolManager::instance()->requestToolActivation(m_canvasController); show(); } void View::initActions() { connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged())); clipboardDataChanged(); actionCollection()->addAction(KStandardAction::SelectAll, "edit_select_all", this, SLOT(editSelectAll())); actionCollection()->addAction(KStandardAction::Deselect, "edit_deselect_all", this, SLOT(editDeselectAll())); m_deleteSelectionAction = new KAction(koIcon("edit-delete"), i18n("D&elete"), this); actionCollection()->addAction("edit_delete", m_deleteSelectionAction); actionCollection()->setDefaultShortcut(m_deleteSelectionAction, QKeySequence("Del")); connect(m_deleteSelectionAction, SIGNAL(triggered()), this, SLOT(editDeleteSelection())); // Shapes menu // TODO: get an icon "edit-duplicate" KAction *actionDuplicate = new KAction(i18nc("Duplicate selection", "&Duplicate"), this); actionCollection()->addAction("shapes_duplicate", actionDuplicate); actionCollection()->setDefaultShortcut(actionDuplicate, QKeySequence("Ctrl+D")); connect(actionDuplicate, SIGNAL(triggered()), this, SLOT(selectionDuplicate())); m_groupShapes = new KAction(koIcon("object-group"), i18n("Group Shapes"), this); actionCollection()->addAction("shapes_group", m_groupShapes); actionCollection()->setDefaultShortcut(m_groupShapes, QKeySequence("Ctrl+G")); connect(m_groupShapes, SIGNAL(triggered()), this, SLOT(groupSelection())); m_ungroupShapes = new KAction(koIcon("object-ungroup"), i18n("Ungroup Shapes"), this); actionCollection()->addAction("shapes_ungroup", m_ungroupShapes); actionCollection()->setDefaultShortcut(m_ungroupShapes, QKeySequence("Ctrl+Shift+G")); connect(m_ungroupShapes, SIGNAL(triggered()), this, SLOT(ungroupSelection())); } void View::loadExtensions() { const QList offers = KoJsonTrader::self()->query("Braindump/Extensions", QString()); foreach(QPluginLoader *pluginLoader, offers) { KPluginFactory *factory = qobject_cast(pluginLoader->instance()); KXMLGUIClient *plugin = dynamic_cast(factory->create(this, QVariantList())); if (plugin) { insertChildClient(plugin); } } } void View::editPaste() { m_canvas->toolProxy()->paste(); } void View::editDeleteSelection() { m_canvas->toolProxy()->deleteSelection(); } void View::editSelectAll() { KoSelection* selection = canvas()->shapeManager()->selection(); if(!selection) return; KoShapeLayer *layer = activeSection()->sectionContainer()->layer(); QList layerShapes(layer->shapes()); foreach(KoShape * layerShape, layerShapes) { selection->select(layerShape); layerShape->update(); } } void View::editDeselectAll() { KoSelection* selection = canvas()->shapeManager()->selection(); if(selection) selection->deselectAll(); canvas()->update(); } void View::slotZoomChanged(KoZoomMode::Mode mode, qreal zoom) { Q_UNUSED(mode); Q_UNUSED(zoom); canvas()->updateOriginAndSize(); canvas()->update(); } void View::createCanvas(Section* _currentSection) { Canvas* canvas = new Canvas(this, m_doc, _currentSection); m_canvasController->setCanvas(canvas); // No need to delete the current canvas, it will be deleted in Viewport::setCanvas (flake/KoCanvasController_p.cpp) m_canvas = canvas; delete m_cutController; m_cutController = new KoCutController(m_canvas, m_editCut); delete m_copyController; m_copyController = new KoCopyController(m_canvas, m_editCopy); connect(m_canvas, SIGNAL(canvasReceivedFocus()), SLOT(canvasReceivedFocus())); connect(m_canvas, SIGNAL(documentRect(QRectF)), SLOT(documentRectChanged(QRectF))); connect(m_canvasController->proxyObject, SIGNAL(moveDocumentOffset(QPoint)), m_canvas, SLOT(setDocumentOffset(QPoint))); connect(m_canvas->toolProxy(), SIGNAL(toolChanged(QString)), this, SLOT(clipboardDataChanged())); m_canvas->updateOriginAndSize(); setEnabled(_currentSection); } void View::setActiveSection(Section* page) { m_activeSection = page; m_doc->setCurrentSection(page); createCanvas(m_activeSection); if(m_activeSection) { documentRectChanged(m_activeSection->layout()->boundingBox()); } m_sectionsBoxDock->updateGUI(); m_sectionPropertiesDock->setSection(m_activeSection); } void View::updateMousePosition(const QPoint& /*position*/) { QPoint canvasOffset(m_canvasController->canvasOffsetX(), m_canvasController->canvasOffsetY()); // the offset is positive it the canvas is shown fully visible canvasOffset.setX(canvasOffset.x() < 0 ? canvasOffset.x() : 0); canvasOffset.setY(canvasOffset.y() < 0 ? canvasOffset.y() : 0); } void View::clipboardDataChanged() { const QMimeData* data = QApplication::clipboard()->mimeData(); bool paste = false; if(data) { // TODO see if we can use the KoPasteController instead of having to add this feature in each calligra app. QStringList mimeTypes = m_canvas->toolProxy()->supportedPasteMimeTypes(); mimeTypes << KoOdf::mimeType(KoOdf::Graphics); mimeTypes << KoOdf::mimeType(KoOdf::Presentation); foreach(const QString & mimeType, mimeTypes) { if(data->hasFormat(mimeType)) { paste = true; break; } } } m_editPaste->setEnabled(paste); } void View::focusInEvent(QFocusEvent * event) { QWidget::focusInEvent(event); m_doc->viewManager()->viewHasFocus(this); } void View::canvasReceivedFocus() { m_doc->viewManager()->viewHasFocus(this); } void View::documentRectChanged(const QRectF& bb) { QSizeF pageSize(400, 400); // Make sure we never use an empty size if(!bb.isNull() && !bb.isEmpty()) { pageSize = bb.size(); } m_zoomController->setPageSize(pageSize); m_zoomController->setDocumentSize(pageSize); } void View::selectionDuplicate() { m_canvas->toolProxy()->copy(); m_canvas->toolProxy()->paste(); } void View::groupSelection() { KoSelection* selection = m_canvas->shapeManager()->selection(); if(! selection) return; QList selectedShapes = selection->selectedShapes(KoFlake::TopLevelSelection); QList groupedShapes; // only group shapes with an unselected parent foreach(KoShape * shape, selectedShapes) { if(selectedShapes.contains(shape->parent())) continue; groupedShapes << shape; } KoShapeGroup *group = new KoShapeGroup(); if(selection->activeLayer()) selection->activeLayer()->addShape(group); KUndo2Command *cmd = new KUndo2Command(kundo2_i18n("Group shapes")); new KoShapeCreateCommand(m_activeSection->sectionContainer(), group, cmd); new KoShapeGroupCommand(group, groupedShapes, cmd); m_canvas->addCommand(cmd); } void View::ungroupSelection() { KoSelection* selection = m_canvas->shapeManager()->selection(); if(! selection) return; QList selectedShapes = selection->selectedShapes(KoFlake::TopLevelSelection); QList containerSet; // only ungroup shape containers with an unselected parent foreach(KoShape * shape, selectedShapes) { if(selectedShapes.contains(shape->parent())) continue; containerSet << shape; } KUndo2Command *cmd = new KUndo2Command(kundo2_i18n("Ungroup shapes")); // add a ungroup command for each found shape container to the macro command foreach(KoShape * shape, containerSet) { KoShapeContainer *container = dynamic_cast(shape); if(container) { new KoShapeUngroupCommand(container, container->shapes(), QList(), cmd); new KoShapeDeleteCommand(m_activeSection->sectionContainer(), container, cmd); new RememberPositionCommand(container->shapes(), cmd); } } m_canvas->addCommand(cmd); } #include "View.moc" diff --git a/braindump/src/commands/MoveSectionCommand.cpp b/braindump/src/commands/MoveSectionCommand.cpp index 58e35123b65..defedfc2fbd 100644 --- a/braindump/src/commands/MoveSectionCommand.cpp +++ b/braindump/src/commands/MoveSectionCommand.cpp @@ -1,53 +1,52 @@ /* * Copyright (c) 2009 Cyrille Berger * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * either version 2, or (at your option) any later version of the License. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "MoveSectionCommand.h" #include "DocumentModel.h" #include "Section.h" -#include MoveSectionCommand::MoveSectionCommand(Section* _section, SectionGroup* _parent, DocumentModel* _model, Section* _above) : m_section(_section), m_parent(_parent), m_previousParent(_section->sectionParent()), m_model(_model), m_above(_above), m_idx(-1), m_previousIndex(_section->sectionParent()->indexOf(_section)) { Q_ASSERT(_above == 0 || _parent == _above->sectionParent()); Q_ASSERT(m_previousIndex >= 0 && m_previousIndex < m_previousParent->sections().count()); } MoveSectionCommand::MoveSectionCommand(Section* _section, SectionGroup* _parent, DocumentModel* _model, int _idx) : m_section(_section), m_parent(_parent), m_previousParent(_section->sectionParent()), m_model(_model), m_above(0), m_idx(_idx), m_previousIndex(_section->sectionParent()->indexOf(_section)) { Q_ASSERT(_idx >= 0 && _idx <= _parent->sections().count()); Q_ASSERT(m_previousIndex >= 0 && m_previousIndex < m_previousParent->sections().count()); } void MoveSectionCommand::undo() { m_model->removeSection(m_section); m_model->insertSection(m_section, m_previousParent, m_previousIndex); } void MoveSectionCommand::redo() { Q_ASSERT(m_idx != -1 || m_above); m_model->removeSection(m_section); if(m_above || m_idx == -1) { m_model->insertSection(m_section, m_parent, m_above); } else { m_model->insertSection(m_section, m_parent, m_idx); } } diff --git a/braindump/src/import/DockerManager.cpp b/braindump/src/import/DockerManager.cpp index 5a7da060a6d..5f3be65df23 100644 --- a/braindump/src/import/DockerManager.cpp +++ b/braindump/src/import/DockerManager.cpp @@ -1,73 +1,73 @@ /* This file is part of the KDE project * * Copyright (c) 2008,2010 C. Boemann * Copyright (c) 2009 Cyrille Berger * * 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 "DockerManager.h" #include "DockerManager_p.h" -#include "KoDockFactoryBase.h" + + +#include +#include #include -#include -#include "ToolDocker.h" +#include "KoDockFactoryBase.h" +#include "ToolDocker.h" #include "MainWindow.h" -#include -#include - DockerManager::DockerManager(MainWindow *mainWindow) : QObject(mainWindow), d(new Private(mainWindow)) { ToolDockerFactory toolDockerFactory; ToolBarsDockerFactory toolBarsDockerFactory; d->toolOptionsDocker = qobject_cast(mainWindow->createDockWidget(&toolDockerFactory)); Q_ASSERT(d->toolOptionsDocker); d->toolOptionsDocker->setVisible(false); d->toolBarsDocker = mainWindow->createDockWidget(&toolBarsDockerFactory); Q_ASSERT(d->toolBarsDocker); QWidget *dockedToolBarsWidget = new QWidget(); d->dockedToolBarsLayout = new QGridLayout(); d->dockedToolBarsLayout->setHorizontalSpacing(2); d->dockedToolBarsLayout->setVerticalSpacing(0); dockedToolBarsWidget->setLayout(d->dockedToolBarsLayout); d->toolBarsDocker->setAllowedAreas(Qt::TopDockWidgetArea); d->toolBarsDocker->setFeatures(QDockWidget::DockWidgetClosable); d->toolBarsDocker->setWidget(dockedToolBarsWidget); d->toolBarsDocker->setTitleBarWidget(new QWidget()); d->toolBarsDocker->setVisible(false); connect(d->toolBarsDocker, SIGNAL(visibilityChanged(bool)), this, SLOT(moveToolBars())); } DockerManager::~DockerManager() { delete d; } void DockerManager::newOptionWidgets(const QList > &optionWidgetMap) { d->toolOptionsDocker->setOptionWidgets(optionWidgetMap); } #include diff --git a/braindump/src/import/DockerManager_p.h b/braindump/src/import/DockerManager_p.h index 8e800b2005f..08f79e0a6ac 100644 --- a/braindump/src/import/DockerManager_p.h +++ b/braindump/src/import/DockerManager_p.h @@ -1,115 +1,114 @@ /* This file is part of the KDE project * * Copyright (c) 2008,2010 C. Boemann * Copyright (c) 2009 Cyrille Berger * * 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 DockerManager_p_h #define DockerManager_p_h #include "DockerManager.h" #include "KoDockFactoryBase.h" #include -#include #include #include "ToolDocker.h" #include "MainWindow.h" #include #include class ToolDockerFactory : public KoDockFactoryBase { public: ToolDockerFactory() : KoDockFactoryBase() { } QString id() const { return "sharedtooldocker"; } QDockWidget* createDockWidget() { ToolDocker * dockWidget = new ToolDocker(); return dockWidget; } DockPosition defaultDockPosition() const { return DockRight; } }; class ToolBarsDockerFactory : public KoDockFactoryBase { public: ToolBarsDockerFactory() : KoDockFactoryBase() { } QString id() const { return "ToolBarDocker"; } QDockWidget* createDockWidget() { return new QDockWidget(i18n("Tool Bars")); } DockPosition defaultDockPosition() const { return DockTop; } }; class DockerManager::Private { public: Private(MainWindow *mw) : dockedToolBarsLayout(0) , mainWindow(mw) , ignore(true) { } ToolDocker *toolOptionsDocker; QDockWidget *toolBarsDocker; QGridLayout *dockedToolBarsLayout; QList toolBarList; MainWindow *mainWindow; bool ignore; void moveToolBarsBack() { foreach(KToolBar * toolBar, toolBarList) { mainWindow->addToolBar(toolBar); } toolBarList.clear(); } void moveToolBars() { if(ignore) return; // Move toolbars to docker or back depending on visibllity of docker if(toolBarsDocker->isVisible()) { QList tmpList = mainWindow->toolBars(); toolBarList.append(tmpList); foreach(KToolBar * toolBar, tmpList) { dockedToolBarsLayout->addWidget(toolBar); } } else { moveToolBarsBack(); } } }; #endif diff --git a/braindump/src/import/ToolDocker.cpp b/braindump/src/import/ToolDocker.cpp index 28fd4ea3984..f4c1d51971d 100644 --- a/braindump/src/import/ToolDocker.cpp +++ b/braindump/src/import/ToolDocker.cpp @@ -1,127 +1,125 @@ /* This file is part of the KDE project * * Copyright (c) 2010-2011 C. Boemann * Copyright (c) 2005-2006 Boudewijn Rempt * Copyright (c) 2006 Thomas Zander * * 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 "ToolDocker.h" #include "ToolDocker_p.h" -#include - -#include - -#include -#include -#include -#include - #include #include #include #include #include #include #include #include #include #include +#include +#include +#include + +#include +#include + ToolDocker::ToolDocker(QWidget *parent) : QDockWidget(i18n("Tool Options"), parent), d(new Private(this)) { setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::TopDockWidgetArea); KConfigGroup cfg = KGlobal::config()->group("DockWidget sharedtooldocker"); d->tabbed = cfg.readEntry("TabbedMode", false); d->hasTitle = cfg.readEntry("Locked", true); toggleViewAction()->setVisible(false); //should always be visible, so hide option in menu setFeatures(DockWidgetMovable | DockWidgetFloatable); if(d->hasTitle) { setTitleBarWidget(new KoDockWidgetTitleBar(this)); } else { setTitleBarWidget(new QWidget()); } connect(this, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(locationChanged(Qt::DockWidgetArea))); d->housekeeperWidget = new QWidget(); d->housekeeperLayout = new QGridLayout(); d->housekeeperWidget->setLayout(d->housekeeperLayout); d->housekeeperLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); d->hiderWidget = new QWidget(d->housekeeperWidget); d->hiderWidget->setVisible(false); d->scrollArea = new QScrollArea(); d->scrollArea->setWidget(d->housekeeperWidget); d->scrollArea->setFrameShape(QFrame::NoFrame); d->scrollArea->setWidgetResizable(true); setWidget(d->scrollArea); d->lockButton = new QToolButton(this); if(d->hasTitle) { d->lockButton->setIcon(d->unlockIcon); } else { d->lockButton->setIcon(d->lockIcon); } d->lockButton->setToolTip(i18n("Toggles showing a title bar")); d->lockButton->setAutoRaise(true); connect(d->lockButton, SIGNAL(clicked()), SLOT(toggleLock())); d->lockButton->setVisible(true); d->lockButton->resize(d->lockButton->sizeHint()); d->tabButton = new QToolButton(this); // parent hack in toggleLock to keep it clickable d->tabButton->setIcon(d->tabIcon); d->tabButton->setToolTip(i18n("Toggles organising the options in tabs or not")); d->tabButton->setAutoRaise(true); connect(d->tabButton, SIGNAL(clicked()), SLOT(toggleTab())); d->tabButton->resize(d->tabButton->sizeHint()); d->tabButton->setVisible(d->hasTitle); } ToolDocker::~ToolDocker() { KConfigGroup cfg = KGlobal::config()->group("DockWidget sharedtooldocker"); cfg.writeEntry("TabbedMode", d->tabbed); cfg.writeEntry("Locked", d->hasTitle); cfg.sync(); delete d; } bool ToolDocker::hasOptionWidget() { return !d->currentWidgetList.isEmpty(); } void ToolDocker::setOptionWidgets(const QList > &optionWidgetList) { d->recreateLayout(optionWidgetList); } void ToolDocker::resizeEvent(QResizeEvent*) { int fw = isFloating() ? style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, this) : 0; d->lockButton->move(width() - d->lockButton->width() - d->scrollArea->verticalScrollBar()->sizeHint().width(), fw); d->tabButton->move(d->lockButton->x() - d->tabButton->width() - 2, d->lockButton->y()); } #include diff --git a/braindump/src/import/ToolDocker_p.h b/braindump/src/import/ToolDocker_p.h index 4e2f6c7deab..f45914fe478 100644 --- a/braindump/src/import/ToolDocker_p.h +++ b/braindump/src/import/ToolDocker_p.h @@ -1,194 +1,193 @@ /* This file is part of the KDE project * * Copyright (c) 2010-2011 C. Boemann * Copyright (c) 2005-2006 Boudewijn Rempt * Copyright (c) 2006 Thomas Zander * * 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 ToolDocker_p_h #define ToolDocker_p_h #include "ToolDocker.h" #include #include #include -#include #include #include #include #include #include #include #include #include #include #include class ToolDocker::Private { public: Private(ToolDocker *dock) : q(dock) , tabbed(false) , hasTitle(false) , lockIcon(koIconName("object-locked")) , unlockIcon(koIconName("object-unlocked")) , tabIcon(koIconName("tab-new")) , unTabIcon(koIconName("tab-close")) { } QList > currentWidgetList; QSet currentAuxWidgets; QScrollArea *scrollArea; QWidget *hiderWidget; // non current widgets are hidden by being children of this QWidget *housekeeperWidget; QGridLayout *housekeeperLayout; ToolDocker *q; Qt::DockWidgetArea dockingArea; bool tabbed :1; bool hasTitle :1; KIcon lockIcon; KIcon unlockIcon; KIcon tabIcon; KIcon unTabIcon; QToolButton *lockButton; QToolButton *tabButton; void recreateLayout(const QList > &optionWidgetList) { foreach(QPointer widget, currentWidgetList) { widget->setParent(hiderWidget); } qDeleteAll(currentAuxWidgets); currentAuxWidgets.clear(); currentWidgetList = optionWidgetList; if(tabbed && currentWidgetList.size() > 1) { QTabWidget *t; housekeeperLayout->addWidget(t = new QTabWidget(), 0, 0); currentAuxWidgets.insert(t); foreach(QWidget * widget, currentWidgetList) { if(widget->objectName().isEmpty()) { Q_ASSERT(!(widget->objectName().isEmpty())); continue; // skip this docker in release build when assert don't crash } t->addTab(widget, widget->windowTitle()); } } else { int cnt = 0; switch(dockingArea) { case Qt::TopDockWidgetArea: case Qt::BottomDockWidgetArea: housekeeperLayout->setHorizontalSpacing(2); housekeeperLayout->setVerticalSpacing(0); foreach(QWidget * widget, currentWidgetList) { QFrame *s; QLabel *l; if(widget->objectName().isEmpty()) { continue; // skip this docker in release build when assert don't crash } housekeeperLayout->addWidget(l = new QLabel(widget->windowTitle()), 0, 2 * cnt); currentAuxWidgets.insert(l); housekeeperLayout->addWidget(widget, 1, 2 * cnt); widget->show(); if(widget != currentWidgetList.last()) { housekeeperLayout->addWidget(s = new QFrame(), 0, 2 * cnt + 1, 2, 1); s->setFrameShape(QFrame::VLine); currentAuxWidgets.insert(s); } cnt++; } break; case Qt::LeftDockWidgetArea: case Qt::RightDockWidgetArea: housekeeperLayout->setHorizontalSpacing(0); housekeeperLayout->setVerticalSpacing(2); cnt = 0; foreach(QWidget * widget, currentWidgetList) { QFrame *s; QLabel *l; if(widget->objectName().isEmpty()) { Q_ASSERT(!(widget->objectName().isEmpty())); continue; // skip this docker in release build when assert don't crash } housekeeperLayout->addWidget(l = new QLabel(widget->windowTitle()), 3 * cnt, 0); currentAuxWidgets.insert(l); housekeeperLayout->addWidget(widget, 3 * cnt + 1, 0); widget->show(); if(widget != currentWidgetList.last()) { housekeeperLayout->addWidget(s = new QFrame(), 3 * cnt + 2, 0); s->setFrameShape(QFrame::HLine); currentAuxWidgets.insert(s); } cnt++; } break; default: break; } } housekeeperLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); housekeeperLayout->invalidate(); } void locationChanged(Qt::DockWidgetArea area) { dockingArea = area; recreateLayout(currentWidgetList); } void toggleLock() { if(!hasTitle) { q->setTitleBarWidget(new KoDockWidgetTitleBar(q)); hasTitle = true; lockButton->setIcon(unlockIcon); tabButton->setVisible(true); // parent hack to keep it clickable tabButton->setParent(q); tabButton->show(); lockButton->setParent(0); lockButton->setParent(q); lockButton->show(); } else { q->setTitleBarWidget(new QWidget()); hasTitle = false; lockButton->setIcon(lockIcon); tabButton->setVisible(false); // parent hack to keep it clickable tabButton->setParent(0); lockButton->setParent(0); lockButton->setParent(q); lockButton->show(); } q->resizeEvent(0); } void toggleTab() { if(!tabbed) { tabbed = true; tabButton->setIcon(unTabIcon); } else { tabbed = false; tabButton->setIcon(tabIcon); } recreateLayout(currentWidgetList); } }; #endif diff --git a/braindump/src/layouts/ColumnLayout.cpp b/braindump/src/layouts/ColumnLayout.cpp index e224508daad..ffc92ee779b 100644 --- a/braindump/src/layouts/ColumnLayout.cpp +++ b/braindump/src/layouts/ColumnLayout.cpp @@ -1,132 +1,134 @@ /* * Copyright (c) 2009 Cyrille Berger * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * either version 2, or (at your option) any later version of the License. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ColumnLayout.h" #include +#include -#include #include -#include + #include +#include + ColumnLayout::ColumnLayout() : Layout("columnlayout"), m_isUpdating(false) { } ColumnLayout::~ColumnLayout() { } QRectF ColumnLayout::boundingBox() const { QRectF rect = Layout::boundingBox(); rect.adjust(-10, -10, 10, 40); return rect; } void ColumnLayout::shapesAdded(QList _shapes) { foreach(KoShape * shape, _shapes) { m_shapes.push_back(shape); } } void ColumnLayout::shapeAdded(KoShape* _shape) { m_shapes.push_back(_shape); } void ColumnLayout::shapeRemoved(KoShape* _shape) { m_shapes.removeAll(_shape); } bool contains(const QList list1, const QList list2) { foreach(KoShape * shape, list2) { if(list1.contains(shape)) { return true; } } return false; } void ColumnLayout::shapeGeometryChanged(KoShape* _shape) { Q_UNUSED(_shape) Q_ASSERT(m_shapes.contains(_shape)); } bool shapeIsLessThan(KoShape* s1, KoShape* s2) { return s1->absolutePosition().y() < s2->absolutePosition().y(); } void ColumnLayout::relayout() { if(m_isUpdating) return; m_isUpdating = true; // First sort them - kDebug() << ""; + qDebug() << ""; foreach(KoShape * _shape, m_shapes) { - kDebug() << _shape << _shape->absolutePosition(KoFlake::TopLeftCorner).y() << " " << _shape->position().y(); + qDebug() << _shape << _shape->absolutePosition(KoFlake::TopLeftCorner).y() << " " << _shape->position().y(); } - kDebug() << ""; + qDebug() << ""; qSort(m_shapes.begin(), m_shapes.end(), shapeIsLessThan); // Update position qreal y = 0; - kDebug() << ""; + qDebug() << ""; foreach(KoShape * shape, m_shapes) { bool dependOnOtherShape = false; foreach(KoShape * otherShape, m_shapes) { if(otherShape->hasDependee(shape)) { - kDebug() << shape << " depends on " << otherShape; + qDebug() << shape << " depends on " << otherShape; dependOnOtherShape = true; break; } } if(!dependOnOtherShape) { shape->update(); QRectF b; Utils::containerBoundRec(shape, b); QPointF transfo = QPointF(0.0, y - b.topLeft().y()); shape->setAbsolutePosition(transfo + shape->absolutePosition()); y += b.height(); shape->update(); } } - kDebug() << ""; + qDebug() << ""; emit(boundingBoxChanged(boundingBox())); m_isUpdating = false; } ColumnLayoutFactory::ColumnLayoutFactory() : LayoutFactory("columnlayout", i18n("Column")) { } ColumnLayoutFactory::~ColumnLayoutFactory() { } Layout* ColumnLayoutFactory::createLayout() const { return new ColumnLayout; } diff --git a/braindump/src/layouts/FreeLayout.cpp b/braindump/src/layouts/FreeLayout.cpp index 06075d6eb8f..e785df7620a 100644 --- a/braindump/src/layouts/FreeLayout.cpp +++ b/braindump/src/layouts/FreeLayout.cpp @@ -1,71 +1,69 @@ /* * Copyright (c) 2009 Cyrille Berger * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * either version 2, or (at your option) any later version of the License. * * 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "FreeLayout.h" #include #include #include -#include - FreeLayout::FreeLayout() : Layout("freelayout") { } FreeLayout::~FreeLayout() { } QRectF FreeLayout::boundingBox() const { QRectF b = Layout::boundingBox(); qreal margin = qMin(200.0, 0.5 * (b.width() + b.height())); return b.adjusted(-margin, -margin, margin, margin); } void FreeLayout::shapeAdded(KoShape*) { } void FreeLayout::shapeRemoved(KoShape*) { } void FreeLayout::shapeGeometryChanged(KoShape*) { } void FreeLayout::relayout() { emit(boundingBoxChanged(boundingBox())); } FreeLayoutFactory::FreeLayoutFactory() : LayoutFactory("freelayout", i18n("Free")) { } FreeLayoutFactory::~FreeLayoutFactory() { } Layout* FreeLayoutFactory::createLayout() const { return new FreeLayout; }