diff --git a/filters/karbon/CMakeLists.txt b/filters/karbon/CMakeLists.txt --- a/filters/karbon/CMakeLists.txt +++ b/filters/karbon/CMakeLists.txt @@ -3,6 +3,7 @@ ${KOTEXT_INCLUDES} ${KOMAIN_INCLUDES} ${FLAKE_INCLUDES} + ${KOPAGEAPP_INCLUDES} ${CMAKE_SOURCE_DIR}/karbon ${CMAKE_SOURCE_DIR}/karbon/common ${CMAKE_SOURCE_DIR}/karbon/ui diff --git a/filters/karbon/image/CMakeLists.txt b/filters/karbon/image/CMakeLists.txt --- a/filters/karbon/image/CMakeLists.txt +++ b/filters/karbon/image/CMakeLists.txt @@ -1,8 +1,5 @@ -include_directories( ${CMAKE_SOURCE_DIR}/karbon ) - - ########### next target ############### set(karbon2image_PART_SRCS ImageExport.cpp ImageExportOptionsWidget.cpp ) @@ -12,6 +9,6 @@ add_library(calligra_filter_karbon2image MODULE ${karbon2image_PART_SRCS}) calligra_filter_desktop_to_json(calligra_filter_karbon2image calligra_filter_karbon2image.desktop) -target_link_libraries(calligra_filter_karbon2image karbonui komain) +target_link_libraries(calligra_filter_karbon2image karbonui komain kopageapp) install(TARGETS calligra_filter_karbon2image DESTINATION ${PLUGIN_INSTALL_DIR}/calligra/formatfilters) diff --git a/filters/karbon/image/ImageExport.cpp b/filters/karbon/image/ImageExport.cpp --- a/filters/karbon/image/ImageExport.cpp +++ b/filters/karbon/image/ImageExport.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include @@ -77,7 +78,12 @@ KarbonDocument* doc = dynamic_cast(document); if (doc) { KoShapePainter painter; - painter.setShapes(doc->shapes()); + QList pages = doc->pages(); + if (pages.isEmpty()) { + return KoFilter::WrongFormat; + } + // TODO: Handle multiple pages + painter.setShapes(pages.at(0)->shapes()); // get the bounding rect of the content QRectF shapesRect = painter.contentRect(); diff --git a/filters/karbon/svg/CMakeLists.txt b/filters/karbon/svg/CMakeLists.txt --- a/filters/karbon/svg/CMakeLists.txt +++ b/filters/karbon/svg/CMakeLists.txt @@ -11,7 +11,7 @@ add_library(calligra_filter_karbon2svg MODULE ${karbon2svg_PART_SRCS}) calligra_filter_desktop_to_json(calligra_filter_karbon2svg calligra_filter_karbon2svg.desktop) -target_link_libraries(calligra_filter_karbon2svg karbonui) +target_link_libraries(calligra_filter_karbon2svg karbonui kopageapp) install(TARGETS calligra_filter_karbon2svg DESTINATION ${PLUGIN_INSTALL_DIR}/calligra/formatfilters) @@ -28,7 +28,7 @@ add_library(calligra_filter_svg2karbon MODULE ${svg2karbon_PART_SRCS}) calligra_filter_desktop_to_json(calligra_filter_svg2karbon calligra_filter_svg2karbon.desktop) -target_link_libraries(calligra_filter_svg2karbon karbonui KF5::Archive) +target_link_libraries(calligra_filter_svg2karbon karbonui kopageapp KF5::Archive) install(TARGETS calligra_filter_svg2karbon DESTINATION ${PLUGIN_INSTALL_DIR}/calligra/formatfilters) diff --git a/filters/karbon/svg/SvgExport.cpp b/filters/karbon/svg/SvgExport.cpp --- a/filters/karbon/svg/SvgExport.cpp +++ b/filters/karbon/svg/SvgExport.cpp @@ -41,6 +41,8 @@ #include #include +#include +#include #include @@ -67,7 +69,13 @@ if (!karbonPart) return KoFilter::WrongFormat; - SvgWriter writer(karbonPart->layers(), karbonPart->pageSize()); + KoPAPageBase *page = karbonPart->pages().value(0); + if (!page) { + return KoFilter::WrongFormat; + } + const KoPageLayout &layout = page->pageLayout(); + const QSizeF size(layout.width, layout.height); + SvgWriter writer(page->shapes(), size); if (!writer.save(m_chain->outputFile(), true)) return KoFilter::CreationError; diff --git a/filters/karbon/svg/SvgImport.cpp b/filters/karbon/svg/SvgImport.cpp --- a/filters/karbon/svg/SvgImport.cpp +++ b/filters/karbon/svg/SvgImport.cpp @@ -35,6 +35,9 @@ #include #include #include +#include +#include +#include #include #include @@ -117,9 +120,17 @@ } m_document = dynamic_cast(m_chain->outputDocument()); - if (! m_document) + if (!m_document) { return KoFilter::CreationError; - + } + if (m_document->pages().isEmpty()) { + KoPAMasterPage *mp = dynamic_cast(m_document->pages(true).value(0)); + if (!mp) { + mp = new KoPAMasterPage(); + m_document->insertPage(mp, 0); + } + m_document->insertPage(new KoPAPage(mp), 0); + } // Do the conversion! convert(inputDoc.documentElement()); @@ -143,60 +154,55 @@ buildDocument(toplevelShapes, parser.shapes()); // set the page size - m_document->setPageSize(pageSize); + KoPageLayout & layout = m_document->pages().at(0)->pageLayout(); + layout.width = pageSize.width(); + layout.height = pageSize.height(); } void SvgImport::buildDocument(const QList &toplevelShapes, const QList &shapes) { + Q_UNUSED(shapes); + KoPAPageBase *page = m_document->pages().first(); // if we have only top level groups, make them layers bool onlyTopLevelGroups = true; foreach(KoShape * shape, toplevelShapes) { if (! dynamic_cast(shape) || shape->filterEffectStack()) { onlyTopLevelGroups = false; break; } } - - // add all shapes to the document - foreach(KoShape * shape, shapes) { - m_document->add(shape); + KoShapeLayer *oldLayer = 0; + if (page->shapeCount()) { + oldLayer = dynamic_cast(page->shapes().first()); } - - KoShapeLayer * oldLayer = 0; - if (m_document->layers().count()) - oldLayer = m_document->layers().first(); - if (onlyTopLevelGroups) { foreach(KoShape * shape, toplevelShapes) { // ungroup toplevel groups - KoShapeGroup * group = dynamic_cast(shape); + KoShapeGroup *group = dynamic_cast(shape); QList children = group->shapes(); KoShapeUngroupCommand cmd(group, children, QList() << group); cmd.redo(); - KoShapeLayer * layer = new KoShapeLayer(); + KoShapeLayer *layer = new KoShapeLayer(); foreach(KoShape * child, children) { - m_document->add(child); layer->addShape(child); } - if (! group->name().isEmpty()) + if (!group->name().isEmpty()) { layer->setName(group->name()); + } layer->setVisible(group->isVisible()); layer->setZIndex(group->zIndex()); - m_document->insertLayer(layer); + page->addShape(layer); delete group; } } else { - KoShapeLayer * layer = new KoShapeLayer(); + KoShapeLayer *layer = new KoShapeLayer(); foreach(KoShape * shape, toplevelShapes) { - m_document->add(shape); layer->addShape(shape); } - m_document->insertLayer(layer); } - if (oldLayer) { - m_document->removeLayer(oldLayer); + page->removeShape(oldLayer); delete oldLayer; } } diff --git a/filters/karbon/wmf/CMakeLists.txt b/filters/karbon/wmf/CMakeLists.txt --- a/filters/karbon/wmf/CMakeLists.txt +++ b/filters/karbon/wmf/CMakeLists.txt @@ -28,7 +28,7 @@ set(karbon2wmf_PART_SRCS WmfExport.cpp) add_library(calligra_filter_karbon2wmf MODULE ${karbon2wmf_PART_SRCS}) -target_link_libraries(calligra_filter_karbon2wmf kovectorimage karboncommon karbonui) +target_link_libraries(calligra_filter_karbon2wmf kovectorimage karboncommon karbonui kopageapp) install(TARGETS calligra_filter_karbon2wmf DESTINATION ${PLUGIN_INSTALL_DIR}/calligra/formatfilters) calligra_filter_desktop_to_json(calligra_filter_karbon2wmf calligra_filter_karbon2wmf.desktop) diff --git a/filters/karbon/wmf/WmfExport.cpp b/filters/karbon/wmf/WmfExport.cpp --- a/filters/karbon/wmf/WmfExport.cpp +++ b/filters/karbon/wmf/WmfExport.cpp @@ -33,6 +33,8 @@ #include #include #include +#include +#include /* TODO: bs.wmf stroke in red with MSword and in brown with Words ?? @@ -83,11 +85,15 @@ void WmfExport::paintDocument(KarbonDocument* document) { - + KoPAPageBase *page = document->pages().value(0); + if (!page) { + return; + } // resolution mDpi = 1000; - QSizeF pageSize = document->pageSize(); + const KoPageLayout &layout = page->pageLayout(); + QSizeF pageSize(layout.width, layout.height); int width = static_cast(POINT_TO_INCH(pageSize.width()) * mDpi); int height = static_cast(POINT_TO_INCH(pageSize.height()) * mDpi); @@ -99,7 +105,7 @@ mScaleY = static_cast(height) / pageSize.height(); } - QList shapes = document->shapes(); + QList shapes = page->shapes(); qSort(shapes.begin(), shapes.end(), KoShape::compareShapeZIndex); // Export layers. diff --git a/karbon/CMakeLists.txt b/karbon/CMakeLists.txt --- a/karbon/CMakeLists.txt +++ b/karbon/CMakeLists.txt @@ -13,6 +13,7 @@ add_definitions(-DTRANSLATION_DOMAIN=\"karbon\") include_directories( + ${KOPAGEAPP_INCLUDES} ${FLAKE_INCLUDES} ${KOTEXT_INCLUDES} ${KOMAIN_INCLUDES} diff --git a/karbon/data/karbon.rc b/karbon/data/karbon.rc --- a/karbon/data/karbon.rc +++ b/karbon/data/karbon.rc @@ -1,6 +1,6 @@ - - + + @@ -127,12 +127,27 @@ Effe&cts &Settings - - + F&ormat + + + + + + &Page + + + + + + + + + + Edit diff --git a/karbon/ui/CMakeLists.txt b/karbon/ui/CMakeLists.txt --- a/karbon/ui/CMakeLists.txt +++ b/karbon/ui/CMakeLists.txt @@ -1,4 +1,5 @@ include_directories( + ${KOPAGEAPP_INCLUDES} ${KOODF_INCLUDES} ${KOMAIN_INCLUDES} ${CMAKE_SOURCE_DIR}/karbon/ @@ -15,19 +16,12 @@ KarbonDocument.cpp KarbonPart.cpp KarbonView.cpp - KarbonPrintJob.cpp - KarbonZoomController.cpp + ProxyView.cpp + KarbonDocumentMergeCommand.cpp - commands/KarbonLayerReorderCommand.cpp - dialogs/KarbonConfigureDialog.cpp - dockers/KarbonLayerDocker.cpp - dockers/KarbonLayerModel.cpp - dockers/KarbonLayerSortingModel.cpp - - widgets/KarbonCanvas.cpp widgets/KarbonSmallStylePreview.cpp widgets/KarbonPaletteBarWidget.cpp widgets/KarbonPaletteWidget.cpp @@ -42,6 +36,7 @@ karboncommon flake PRIVATE + kopageapp kowidgets koodf koplugin diff --git a/karbon/ui/KarbonDocument.h b/karbon/ui/KarbonDocument.h --- a/karbon/ui/KarbonDocument.h +++ b/karbon/ui/KarbonDocument.h @@ -39,7 +39,7 @@ #include -#include +#include #include #include @@ -61,40 +61,28 @@ * Keeps track of visual per document properties. * It loads initial settings and applies them to the document and its views. */ -class KARBONUI_EXPORT KarbonDocument : public KoDocument, public KoShapeBasedDocumentBase +class KARBONUI_EXPORT KarbonDocument : public KoPADocument { Q_OBJECT public: explicit KarbonDocument(KarbonPart *part); virtual ~KarbonDocument(); - /// reimplemented form KoDocument - virtual void paintContent(QPainter& painter, const QRect& rect); - /// reimplemented form KoDocument - virtual bool loadXML(const KoXmlDocument& document, KoStore *store); - /// reimplemented form KoDocument - virtual bool loadOdf(KoOdfReadStore & odfStore); + KoOdf::DocumentType documentType() const; + /// reimplemented form KoDocument virtual bool completeLoading(KoStore* store); - /// reimplemented form KoDocument - virtual bool saveOdf(SavingContext &documentContext); /// reimplemented from KoDocument virtual QByteArray nativeFormatMimeType() const { return KARBON_MIME_TYPE; } /// reimplemented from KoDocument virtual QByteArray nativeOasisMimeType() const { return KARBON_MIME_TYPE; } /// reimplemented from KoDocument virtual QStringList extraNativeMimeTypes() const { - return QStringList() << "application/vnd.oasis.opendocument.graphics" - << "application/vnd.oasis.opendocument.graphics-template"; + return QStringList() << "application/vnd.oasis.opendocument.graphics-template"; } - /// implemented from KoShapeController - virtual void addShape(KoShape* shape); - /// implemented from KoShapeController - virtual void removeShape(KoShape* shape); - /// Returns if status bar is shown bool showStatusBar() const; /// Shows/hides status bar @@ -106,151 +94,28 @@ /// Returns maximum number of recent files uint maxRecentFiles() const; - /// Sets page layout of the document - virtual void setPageLayout(const KoPageLayout& layout); - bool mergeNativeFormat(const QString & file); - // merged from original KarbonDocument - - /** - * Checks if specified layer can be raised. - * - * A layer can be raised if there is more than one layer and the specified layer - * is not already at the top. - * - * @param layer the layer to check - * @return true if layer can be raised, else false - */ - bool canRaiseLayer(KoShapeLayer* layer); - - /** - * Checks if specified layer can be lowered. - * - * A layer can be lowered if there is more than one layer and the specified layer - * is not already at the bottom. - * - * @param layer the layer to check - * @return true if layer can be lowered, else false - */ - bool canLowerLayer(KoShapeLayer* layer); - - /** - * Raises the layer. - * - * @param layer the layer to raise - */ - void raiseLayer(KoShapeLayer* layer); - - /** - * Lowers the layer. - * - * @param layer the layer to lower - */ - void lowerLayer(KoShapeLayer* layer); - - /** - * Returns the position of the specified layer. - * - * @param layer the layer to retrieve the position for - * @return the layer position - */ - int layerPos(KoShapeLayer* layer); - - /** - * Inserts a new layer. - * - * The layer is appended at the end, on top of all other layers, and is activated. - * - * @param layer the layer to insert - */ - void insertLayer(KoShapeLayer* layer); - - /** - * Removes the layer. - * - * If there is no layer left, a new layer is created, inserted and activated. - * - * @param layer the layer to remove - */ - void removeLayer(KoShapeLayer* layer); - - /** - * Returns the list of layers. - * The layer list provides a hierarchical view/access of the document data. - * All the documents shapes are children of a shape container, where a layer - * resembles a root container which can contain other containers in an - * arbitrary nesting depth. - */ - const QList layers() const; - - /** - * Returns the list of all shapes of the document. - * This list provides a flat view/access to all the documents shapes. - * For an hierarchical view/access one should retrieve the documents - * layers with layers(). - */ - const QList shapes() const; - - void saveOasis(KoShapeSavingContext & context) const; - bool loadOasis(const KoXmlElement &element, KoShapeLoadingContext &context); - void loadOdfStyles(KoShapeLoadingContext & context); - void saveOdfStyles(KoShapeSavingContext & context); - - /** - * Adds an object to the document. - * - * @param shape the object to append - */ - void add(KoShape* shape); - - /** - * Removes an object from the document. - * - * @param shape the object to append - */ - void remove(KoShape* shape); - - /// Returns the united bounding rectangle of the documents content and the document page - QRectF boundingRect() const; - - /// Returns the bounding rectangle of the documents content - QRectF contentRect() const; - - /// Returns the documents page size - QSizeF pageSize() const; - - /// Sets given page size to all attached views/canvases - void setPageSize(const QSizeF &pageSize); - - /// Sets the documents page size - //void setDocumentPageSize(QSizeF pageSize); - - /// Returns the documents image collection - KoImageCollection * imageCollection(); + // TODO: Start using or remove /// Returns the documents data centers QMap dataCenterMap() const; + // TODO: Start using or remove /// Sets the data centers to be used by this document void useExternalDataCenterMap(const QMap &dataCenters); + // TODO: Start using or remove void addToDataCenterMap(const QString &key, KoDataCenterBase* dataCenter); public Q_SLOTS: void slotDocumentRestored(); Q_SIGNALS: - void shapeCountChanged(); void applyCanvasConfiguration(KarbonCanvas *canvas); protected: - - /// Loads settings like grid and guide lines from given xml document - void loadOasisSettings(const KoXmlDocument & settingsDoc); - /// Saves settings like grid and guide lines to store - void saveOasisSettings(KoStore * store); - + virtual const char *odfTagName(bool withNamespace); /// Reads settings from config file void initConfig(); diff --git a/karbon/ui/KarbonDocument.cpp b/karbon/ui/KarbonDocument.cpp --- a/karbon/ui/KarbonDocument.cpp +++ b/karbon/ui/KarbonDocument.cpp @@ -45,7 +45,6 @@ #include "KarbonPart.h" #include "KarbonFactory.h" #include "KarbonView.h" -#include #include "KarbonUiDebug.h" #include @@ -98,44 +97,19 @@ { public: Private() - : pageSize(0.0, 0.0), - hasExternalDataCenterMap(false), + : hasExternalDataCenterMap(false), showStatusBar(true), merge(false), maxRecentFiles(10) {} ~Private() { - layers.clear(); - objects.clear(); if (!hasExternalDataCenterMap) qDeleteAll(dataCenterMap); } - qreal getAttribute(KoXmlElement &element, const char *attributeName, qreal defaultValue) - { - QString value = element.attribute(attributeName); - if (! value.isEmpty()) - return value.toDouble(); - else - return defaultValue; - } - - int getAttribute(KoXmlElement &element, const char *attributeName, int defaultValue) - { - QString value = element.attribute(attributeName); - if (! value.isEmpty()) - return value.toInt(); - else - return defaultValue; - } - // KarbonDocument document; ///< store non-visual doc info - QSizeF pageSize; ///< the documents page size - - QList objects; ///< The list of all object of the document. - QList layers; ///< The layers in this document. QMap dataCenterMap; bool hasExternalDataCenterMap; @@ -146,11 +120,10 @@ KarbonDocument::KarbonDocument(KarbonPart* part) - : KoDocument(part) - , d(new Private()) + : KoPADocument(part) + , d(new Private()) { Q_ASSERT(part); - resourceManager()->setUndoStack(undoStack()); initConfig(); @@ -170,83 +143,6 @@ delete d; } -void KarbonDocument::setPageLayout(const KoPageLayout& layout) -{ - KoDocument::setPageLayout(layout); - setPageSize(QSizeF(layout.width, layout.height)); -} - -bool KarbonDocument::loadXML(const KoXmlDocument&, KoStore*) -{ - return false; -} - -bool KarbonDocument::loadOdf(KoOdfReadStore & odfStore) -{ - debugKarbonUi << "Start loading OASIS document..." /*<< doc.toString()*/; - - KoXmlElement contents = odfStore.contentDoc().documentElement(); - debugKarbonUi << "Start loading OASIS document..." << contents.text(); - debugKarbonUi << "Start loading OASIS contents..." << contents.lastChild().localName(); - debugKarbonUi << "Start loading OASIS contents..." << contents.lastChild().namespaceURI(); - debugKarbonUi << "Start loading OASIS contents..." << contents.lastChild().isElement(); - KoXmlElement body(KoXml::namedItemNS(contents, KoXmlNS::office, "body")); - if (body.isNull()) { - debugKarbonUi << "No office:body found!"; - setErrorMessage(i18n("Invalid OASIS document. No office:body tag found.")); - return false; - } - - body = KoXml::namedItemNS(body, KoXmlNS::office, "drawing"); - if (body.isNull()) { - debugKarbonUi << "No office:drawing found!"; - setErrorMessage(i18n("Invalid OASIS document. No office:drawing tag found.")); - return false; - } - - KoXmlElement page(KoXml::namedItemNS(body, KoXmlNS::draw, "page")); - if (page.isNull()) { - debugKarbonUi << "No office:drawing found!"; - setErrorMessage(i18n("Invalid OASIS document. No draw:page tag found.")); - return false; - } - - KoXmlElement * master = 0; - if (odfStore.styles().masterPages().contains("Standard")) - master = odfStore.styles().masterPages().value("Standard"); - else if (odfStore.styles().masterPages().contains("Default")) - master = odfStore.styles().masterPages().value("Default"); - else if (! odfStore.styles().masterPages().empty()) - master = odfStore.styles().masterPages().begin().value(); - - if (master) { - const QString pageStyleName = master->attributeNS(KoXmlNS::style, "page-layout-name", QString()); - const KoXmlElement *style = odfStore.styles().findStyle(pageStyleName); - if (style) { - KoPageLayout layout; - layout.loadOdf(*style); - setPageLayout(layout); - } - } else { - warnKarbonUi << "No master page found!"; - return false; - } - - KoOdfLoadingContext context(odfStore.styles(), odfStore.store()); - KoShapeLoadingContext shapeContext(context, resourceManager()); - - loadOasis(page, shapeContext); - - if (pageSize().isEmpty()) { - QSizeF pageSize = contentRect().united(QRectF(0, 0, 1, 1)).size(); - setPageSize(pageSize); - } - - loadOasisSettings(odfStore.settingsDoc()); - - return true; -} - bool KarbonDocument::completeLoading(KoStore* store) { bool ok = true; @@ -256,124 +152,11 @@ return ok; } -void KarbonDocument::loadOasisSettings(const KoXmlDocument & settingsDoc) -{ - if (settingsDoc.isNull()) - return ; // not an error if some file doesn't have settings.xml - KoOasisSettings settings(settingsDoc); - KoOasisSettings::Items viewSettings = settings.itemSet("view-settings"); - if (!viewSettings.isNull()) { - setUnit(KoUnit::fromSymbol(viewSettings.parseConfigItemString("unit"))); - // FIXME: add other config here. - } - guidesData().loadOdfSettings(settingsDoc); - gridData().loadOdfSettings(settingsDoc); -} - -void KarbonDocument::saveOasisSettings(KoStore * store) -{ - KoStoreDevice settingsDev(store); - KoXmlWriter * settingsWriter = KoOdfWriteStore::createOasisXmlWriter(&settingsDev, "office:document-settings"); - - settingsWriter->startElement("office:settings"); - settingsWriter->startElement("config:config-item-set"); - settingsWriter->addAttribute("config:name", "view-settings"); - - saveUnitOdf(settingsWriter); - - settingsWriter->endElement(); // config:config-item-set - - settingsWriter->startElement("config:config-item-set"); - settingsWriter->addAttribute("config:name", "ooo:view-settings"); - settingsWriter->startElement("config:config-item-map-indexed"); - settingsWriter->addAttribute("config:name", "Views"); - settingsWriter->startElement("config:config-item-map-entry"); - - guidesData().saveOdfSettings(*settingsWriter); - gridData().saveOdfSettings(*settingsWriter); - - settingsWriter->endElement(); // config:config-item-map-entry - settingsWriter->endElement(); // config:config-item-map-indexed - settingsWriter->endElement(); // config:config-item-set - - settingsWriter->endElement(); // office:settings - settingsWriter->endElement(); // office:document-settings - - settingsWriter->endDocument(); - - delete settingsWriter; -} - -bool KarbonDocument::saveOdf(SavingContext &documentContext) -{ - KoStore * store = documentContext.odfStore.store(); - KoXmlWriter* contentWriter = documentContext.odfStore.contentWriter(); - if (!contentWriter) - return false; - - KoGenStyles mainStyles; - KoXmlWriter * bodyWriter = documentContext.odfStore.bodyWriter(); - - KoShapeSavingContext shapeContext(*bodyWriter, mainStyles, documentContext.embeddedSaver); - - // save text styles - saveOdfStyles(shapeContext); - - // save page - QString layoutName = mainStyles.insert(pageLayout().saveOdf(), "PL"); - KoGenStyle masterPage(KoGenStyle::MasterPageStyle); - masterPage.addAttribute("style:page-layout-name", layoutName); - mainStyles.insert(masterPage, "Default", KoGenStyles::DontAddNumberToName); - - bodyWriter->startElement("office:body"); - bodyWriter->startElement("office:drawing"); - - saveOasis(shapeContext); // Save contents - - bodyWriter->endElement(); // office:drawing - bodyWriter->endElement(); // office:body - - mainStyles.saveOdfStyles(KoGenStyles::DocumentAutomaticStyles, contentWriter); - - documentContext.odfStore.closeContentWriter(); - - //add manifest line for content.xml - documentContext.odfStore.manifestWriter()->addManifestEntry("content.xml", "text/xml"); - - if (!shapeContext.saveDataCenter(store, documentContext.odfStore.manifestWriter())) { - return false; - } - - if (! mainStyles.saveOdfStylesDotXml(store, documentContext.odfStore.manifestWriter())) - return false; - - if (! store->open("settings.xml")) - return false; - - saveOasisSettings(store); - - if (! store->close()) - return false; - - documentContext.odfStore.manifestWriter()->addManifestEntry("settings.xml", "text/xml"); - - setModified(false); - - return true; -} - void KarbonDocument::slotDocumentRestored() { setModified(false); } -void KarbonDocument::paintContent(QPainter &painter, const QRect& rect) -{ - KoShapePainter shapePainter; - shapePainter.setShapes(shapes()); - shapePainter.paint(painter, rect, QRectF(QPointF(), pageSize())); -} - bool KarbonDocument::showStatusBar() const { return d->showStatusBar; @@ -395,7 +178,6 @@ KarbonView * kv = qobject_cast(view); if (kv) { kv->reorganizeGUI(); - emit applyCanvasConfiguration(kv->canvasWidget()); } } } @@ -427,15 +209,6 @@ undoStack()->setUndoLimit(undos); setUnit(KoUnit::fromSymbol(defaultUnitSymbol)); - if (config->hasGroup("Grid")) { - KoGridData defGrid; - KConfigGroup gridGroup = config->group("Grid"); - qreal spacingX = gridGroup.readEntry("SpacingX", defGrid.gridX()); - qreal spacingY = gridGroup.readEntry("SpacingY", defGrid.gridY()); - gridData().setGrid(spacingX, spacingY); - QColor color = gridGroup.readEntry("Color", defGrid.gridColor()); - gridData().setGridColor(color); - } } bool KarbonDocument::mergeNativeFormat(const QString &file) @@ -448,293 +221,6 @@ return result; } -void KarbonDocument::addShape(KoShape* shape) -{ - KoCanvasController* canvasController = KoToolManager::instance()->activeCanvasController(); - - KoShapeLayer *layer = dynamic_cast(shape); - if (layer) { - insertLayer(layer); - if (canvasController) { - KoSelection *selection = canvasController->canvas()->shapeManager()->selection(); - selection->setActiveLayer(layer); - } - } else { - // only add shape to active layer if it has no parent yet - if (! shape->parent()) { - debugKarbonUi << "shape has no parent, adding to the active layer!"; - KoShapeLayer *activeLayer = 0; - if (canvasController) - activeLayer = canvasController->canvas()->shapeManager()->selection()->activeLayer(); - else if (layers().count()) - activeLayer = layers().first(); - - if (activeLayer) - activeLayer->addShape(shape); - } - - add(shape); - - foreach(KoView *view, documentPart()->views()) { - KarbonCanvas *canvas = ((KarbonView*)view)->canvasWidget(); - canvas->shapeManager()->addShape(shape); - } - } - - setModified(true); - emit shapeCountChanged(); -} - -void KarbonDocument::removeShape(KoShape* shape) -{ - KoShapeLayer *layer = dynamic_cast(shape); - if (layer) { - removeLayer(layer); - } else { - remove(shape); - foreach(KoView *view, documentPart()->views()) { - KarbonCanvas *canvas = ((KarbonView*)view)->canvasWidget(); - canvas->shapeManager()->remove(shape); - } - } - setModified(true); - emit shapeCountChanged(); -} - -void KarbonDocument::setPageSize(const QSizeF &pageSize) -{ - d->pageSize = pageSize; - foreach(KoView *view, documentPart()->views()) { - KarbonCanvas *canvas = ((KarbonView*)view)->canvasWidget(); - canvas->resourceManager()->setResource(KoCanvasResourceManager::PageSize, pageSize); - } -} - -QSizeF KarbonDocument::pageSize() const -{ - return d->pageSize; -} - -void KarbonDocument::insertLayer(KoShapeLayer* layer) -{ - if (!d->layers.contains(layer)) { - if (d->layers.count()) { - layer->setZIndex(d->layers.last()->zIndex() + 1); - } else { - layer->setZIndex(d->layers.count()); - } - d->layers.append(layer); - } -} - -void KarbonDocument::removeLayer(KoShapeLayer* layer) -{ - d->layers.removeAt(d->layers.indexOf(layer)); - if (d->layers.count() == 0) - d->layers.append(new KoShapeLayer()); -} - -bool KarbonDocument::canRaiseLayer(KoShapeLayer* layer) -{ - int pos = d->layers.indexOf(layer); - return (pos != int(d->layers.count()) - 1 && pos >= 0); -} - -bool KarbonDocument::canLowerLayer(KoShapeLayer* layer) -{ - int pos = d->layers.indexOf(layer); - return (pos > 0); -} - -void KarbonDocument::raiseLayer(KoShapeLayer* layer) -{ - int pos = d->layers.indexOf(layer); - if (pos != int(d->layers.count()) - 1 && pos >= 0) { - KoShapeLayer * layerAbove = d->layers.at(pos + 1); - int lowerZIndex = layer->zIndex(); - int upperZIndex = layerAbove->zIndex(); - layer->setZIndex(upperZIndex); - layerAbove->setZIndex(lowerZIndex); - d->layers.move(pos, pos + 1); - } -} - -void KarbonDocument::lowerLayer(KoShapeLayer* layer) -{ - int pos = d->layers.indexOf(layer); - if (pos > 0) { - KoShapeLayer * layerBelow = d->layers.at(pos - 1); - int upperZIndex = layer->zIndex(); - int lowerZIndex = layerBelow->zIndex(); - layer->setZIndex(lowerZIndex); - layerBelow->setZIndex(upperZIndex); - d->layers.move(pos, pos - 1); - } -} - -int KarbonDocument::layerPos(KoShapeLayer* layer) -{ - return d->layers.indexOf(layer); -} - -void KarbonDocument::add(KoShape* shape) -{ - if (! d->objects.contains(shape)) - d->objects.append(shape); -} - -void KarbonDocument::remove(KoShape* shape) -{ - d->objects.removeAt(d->objects.indexOf(shape)); -} - -void KarbonDocument::saveOasis(KoShapeSavingContext & context) const -{ - context.xmlWriter().startElement("draw:page"); - context.xmlWriter().addAttribute("draw:name", ""); - context.xmlWriter().addAttribute("draw:id", "page1"); - context.xmlWriter().addAttribute("xml:id", "page1"); - context.xmlWriter().addAttribute("draw:master-page-name", "Default"); - - foreach(KoShapeLayer * layer, d->layers) { - context.addLayerForSaving(layer); - } - context.saveLayerSet(context.xmlWriter()); - - foreach(KoShapeLayer * layer, d->layers) { - layer->saveOdf(context); - } - - context.xmlWriter().endElement(); // draw:page -} - -bool KarbonDocument::loadOasis(const KoXmlElement &element, KoShapeLoadingContext &context) -{ - // load text styles used by text shapes - loadOdfStyles(context); - - qDeleteAll(d->layers); - d->layers.clear(); - qDeleteAll(d->objects); - d->objects.clear(); - - const KoXmlElement & pageLayerSet = KoXml::namedItemNS(element, KoXmlNS::draw, "layer-set"); - const KoXmlElement & usedPageLayerSet = pageLayerSet.isNull() ? context.odfLoadingContext().stylesReader().layerSet() : pageLayerSet; - - KoXmlElement layerElement; - forEachElement(layerElement, usedPageLayerSet) { - KoShapeLayer * l = new KoShapeLayer(); - if (l->loadOdf(layerElement, context)) - insertLayer(l); - } - - KoShapeLayer * defaultLayer = 0; - - // check if we have to insert a default layer - if (d->layers.count() == 0) - defaultLayer = new KoShapeLayer(); - - KoXmlElement child; - forEachElement(child, element) { - debugKarbonUi << "loading shape" << child.localName(); - - KoShape * shape = KoShapeRegistry::instance()->createShapeFromOdf(child, context); - if (shape) - d->objects.append(shape); - } - - // add all toplevel shapes to the default layer - foreach(KoShape * shape, d->objects) { - if (! shape->parent()) { - if (! defaultLayer) - defaultLayer = new KoShapeLayer(); - - defaultLayer->addShape(shape); - } - } - - if (defaultLayer) - insertLayer(defaultLayer); - - KoOdfStylesReader & styleReader = context.odfLoadingContext().stylesReader(); - QHash masterPages = styleReader.masterPages(); - - KoXmlElement * master = 0; - if( masterPages.contains( "Standard" ) ) - master = masterPages.value( "Standard" ); - else if( masterPages.contains( "Default" ) ) - master = masterPages.value( "Default" ); - else if( ! masterPages.empty() ) - master = masterPages.begin().value(); - - if (master) { - context.odfLoadingContext().setUseStylesAutoStyles( true ); - - QList masterPageShapes; - KoXmlElement child; - forEachElement(child, (*master)) { - debugKarbonUi <<"loading master page shape" << child.localName(); - KoShape * shape = KoShapeRegistry::instance()->createShapeFromOdf( child, context ); - if( shape ) - masterPageShapes.append( shape ); - } - - KoShapeLayer * masterPageLayer = 0; - // add all toplevel shapes to the master page layer - foreach(KoShape * shape, masterPageShapes) { - d->objects.append( shape ); - if(!shape->parent()) { - if( ! masterPageLayer ) { - masterPageLayer = new KoShapeLayer(); - masterPageLayer->setName(i18n("Master Page")); - } - - masterPageLayer->addShape(shape); - } - } - - if( masterPageLayer ) - insertLayer( masterPageLayer ); - - context.odfLoadingContext().setUseStylesAutoStyles( false ); - } - - return true; -} - -QRectF KarbonDocument::boundingRect() const -{ - return contentRect().united(QRectF(QPointF(0, 0), d->pageSize)); -} - -QRectF KarbonDocument::contentRect() const -{ - QRectF bb; - foreach(KoShape* layer, d->layers) { - if (bb.isNull()) - bb = layer->boundingRect(); - else - bb = bb.united(layer->boundingRect()); - } - - return bb; -} - -const QList KarbonDocument::shapes() const -{ - return d->objects; -} - -const QList KarbonDocument::layers() const -{ - return d->layers; -} - -KoImageCollection * KarbonDocument::imageCollection() -{ - return resourceManager()->imageCollection(); -} - QMap KarbonDocument::dataCenterMap() const { return d->dataCenterMap; @@ -747,33 +233,17 @@ d->hasExternalDataCenterMap = true; } -void KarbonDocument::loadOdfStyles(KoShapeLoadingContext & context) +void KarbonDocument::addToDataCenterMap(const QString &key, KoDataCenterBase* dataCenter) { - // Only text styles (old style system). - KoStyleManager *styleManager = resourceManager()->resource(KoText::StyleManager).value(); - - if (! styleManager) - return; - - KoTextSharedLoadingData * sharedData = new KoTextSharedLoadingData(); - if (! sharedData) - return; - - sharedData->loadOdfStyles(context, styleManager); - context.addSharedData(KOTEXT_SHARED_LOADING_ID, sharedData); + d->dataCenterMap.insert(key, dataCenter); } -void KarbonDocument::saveOdfStyles(KoShapeSavingContext & context) +KoOdf::DocumentType KarbonDocument::documentType() const { - KoStyleManager * styleManager = dynamic_cast(dataCenterMap()["StyleManager"]); - if (! styleManager) - return; - - styleManager->saveOdf(context); + return KoOdf::Graphics; } -void KarbonDocument::addToDataCenterMap(const QString &key, KoDataCenterBase* dataCenter) +const char * KarbonDocument::odfTagName(bool withNamespace) { - d->dataCenterMap.insert(key, dataCenter); + return withNamespace ? "office:drawing": "drawing"; } - diff --git a/karbon/ui/KarbonDocumentMergeCommand.h b/karbon/ui/KarbonDocumentMergeCommand.h --- a/karbon/ui/KarbonDocumentMergeCommand.h +++ b/karbon/ui/KarbonDocumentMergeCommand.h @@ -27,14 +27,10 @@ class KarbonDocumentMergeCommand : public KUndo2Command { public: - KarbonDocumentMergeCommand(KarbonDocument * targetPart, KarbonDocument * sourcePart); - virtual ~KarbonDocumentMergeCommand(); - virtual void redo(); - virtual void undo(); - -private: - class Private; - Private * const d; + KarbonDocumentMergeCommand(KarbonDocument * targetPart, KarbonDocument &sourcePart, KUndo2Command *parent = 0); + virtual ~KarbonDocumentMergeCommand() Q_DECL_OVERRIDE = default; + virtual void redo() Q_DECL_OVERRIDE; + virtual void undo() Q_DECL_OVERRIDE; }; #endif // _KARBONDOCUMENTMERGECOMMAND_H_ diff --git a/karbon/ui/KarbonDocumentMergeCommand.cpp b/karbon/ui/KarbonDocumentMergeCommand.cpp --- a/karbon/ui/KarbonDocumentMergeCommand.cpp +++ b/karbon/ui/KarbonDocumentMergeCommand.cpp @@ -20,76 +20,112 @@ #include "KarbonDocumentMergeCommand.h" #include "KarbonPart.h" #include "KarbonDocument.h" + +#include #include "KoShapeLayer.h" +#include +#include +#include + #include -class KarbonDocumentMergeCommand::Private +class MergePageCommand : public KUndo2Command { public: - Private() : hasMerged(false) + MergePageCommand(KoPADocument *doc, KoPAPageBase *targetPage, KoPAPageBase *sourcePage, KUndo2Command *parent) + : KUndo2Command(parent) + , mine(true) + , doc(doc) + , targetPage(targetPage) { + layers = sourcePage->shapes(); + sourcePage->removeAllShapes(); } - - ~Private() - { - if (!hasMerged) { + ~MergePageCommand() { + if (mine) { qDeleteAll(layers); - qDeleteAll(shapes); } } + void redo() { + for (int i = 0; i < layers.count(); ++i) { + targetPage->addShape(layers.at(i)); + } + mine = false; + doc->emitUpdate(targetPage); + } + void undo() { + for (int i = 0; i < layers.count(); ++i) { + targetPage->removeShape(layers.at(i)); + } + mine = true; + doc->emitUpdate(targetPage); + } - KarbonDocument * targetPart; - QList layers; - QList shapes; - bool hasMerged; +private: + bool mine; + KoPADocument *doc; + KoPAPageBase *targetPage; + QList layers; }; -KarbonDocumentMergeCommand::KarbonDocumentMergeCommand(KarbonDocument *targetPart, KarbonDocument *sourcePart) - : KUndo2Command(0), d(new Private()) +class AddPageCommand : public KUndo2Command { - d->targetPart = targetPart; - d->layers = sourcePart->layers(); - d->shapes = sourcePart->shapes(); - foreach(KoShapeLayer * layer, d->layers) { - sourcePart->removeShape(layer); +public: + AddPageCommand(KarbonDocument *doc, KoPAPageBase *sourcePage, KUndo2Command *parent) + : KUndo2Command(parent) + , mine(true) + , doc(doc) + { + newPage = doc->newPage(dynamic_cast(doc->pages(true).value(0))); + QList layers = sourcePage->shapes(); + sourcePage->removeAllShapes(); + for (int i = 0; i < layers.count(); ++i) { + newPage->addShape(layers.at(i)); + } } - foreach(KoShape * shape, d->shapes) { - sourcePart->removeShape(shape); + ~AddPageCommand() { + if (mine) { + delete newPage; + } + } + void redo() { + doc->insertPage(newPage, doc->pages().count()); + mine = false; + } + void undo() { + doc->takePage(newPage); + mine = true; } - setText(kundo2_i18n("Insert graphics")); -} -KarbonDocumentMergeCommand::~KarbonDocumentMergeCommand() -{ - delete d; -} +private: + bool mine; + KarbonDocument *doc; + KoPAPageBase *newPage; +}; -void KarbonDocumentMergeCommand::redo() +KarbonDocumentMergeCommand::KarbonDocumentMergeCommand(KarbonDocument *targetPart, KarbonDocument &sourcePart, KUndo2Command *parent) + : KUndo2Command(parent) { - if (!d->hasMerged) { - foreach(KoShapeLayer * layer, d->layers) { - d->targetPart->addShape(layer); - } - foreach(KoShape * shape, d->shapes) { - d->targetPart->addShape(shape); + QList pages; + for(int i = 0; i < sourcePart.pages().count(); ++i) { + KoPAPageBase *sourcePage = sourcePart.pages().at(i); + pages << sourcePage; + if (i < targetPart->pages().count()) { + KoPAPageBase *targetPage = targetPart->pages().at(i); + new MergePageCommand(targetPart, targetPage, sourcePage, this); + } else { + new AddPageCommand(targetPart, sourcePage, this); } - d->hasMerged = true; } + setText(kundo2_i18n("Insert graphics")); +} +void KarbonDocumentMergeCommand::redo() +{ KUndo2Command::redo(); } void KarbonDocumentMergeCommand::undo() { KUndo2Command::undo(); - - if (d->hasMerged) { - foreach(KoShapeLayer * layer, d->layers) { - d->targetPart->removeShape(layer); - } - foreach(KoShape * shape, d->shapes) { - d->targetPart->removeShape(shape); - } - d->hasMerged = false; - } } diff --git a/karbon/ui/KarbonPart.h b/karbon/ui/KarbonPart.h --- a/karbon/ui/KarbonPart.h +++ b/karbon/ui/KarbonPart.h @@ -39,8 +39,6 @@ class KoView; class KoDocument; -class KarbonCanvas; - class KARBONUI_EXPORT KarbonPart : public KoPart { Q_OBJECT @@ -50,21 +48,14 @@ virtual ~KarbonPart(); - void setDocument(KoDocument *document); - /// reimplemented virtual KoView *createViewInstance(KoDocument *document, QWidget *parent); /// reimplemented virtual KoMainWindow *createMainWindow(); protected Q_SLOTS: - /// reimplemented virtual void openTemplate(const QUrl& url); - -private Q_SLOTS: - - void applyCanvasConfiguration(KarbonCanvas *canvas); }; #endif diff --git a/karbon/ui/KarbonPart.cpp b/karbon/ui/KarbonPart.cpp --- a/karbon/ui/KarbonPart.cpp +++ b/karbon/ui/KarbonPart.cpp @@ -43,16 +43,19 @@ #include "KarbonPart.h" #include "KarbonView.h" +#include "ProxyView.h" #include "KarbonDocument.h" #include "KarbonFactory.h" -#include "KarbonCanvas.h" +#include "KarbonPaletteBarWidget.h" #include #include #include #include +#include + KarbonPart::KarbonPart(QObject *parent) : KoPart(KarbonFactory::global(), parent) { @@ -63,25 +66,24 @@ { } -void KarbonPart::setDocument(KoDocument *document) -{ - KoPart::setDocument(document); - KarbonDocument *doc = qobject_cast(document); - connect(doc, SIGNAL(applyCanvasConfiguration(KarbonCanvas*)), SLOT(applyCanvasConfiguration(KarbonCanvas*))); -} - KoView * KarbonPart::createViewInstance(KoDocument *_document, QWidget *parent) { KarbonDocument *doc = qobject_cast(_document); + ProxyView *view = new ProxyView(this, doc, parent); - KarbonView *result = new KarbonView(this, doc, parent); + KarbonView *result = new KarbonView(this, doc, view); + view->view = result; - KoCanvasResourceManager * provider = result->canvasWidget()->resourceManager(); - provider->setResource(KoCanvasResourceManager::PageSize, doc->pageSize()); + // Add the color bar below the karbon view (the reason for the ProxyView) + QVBoxLayout *layout = new QVBoxLayout(view); + layout->setMargin(0); + layout->setSpacing(0); + layout->addWidget(result); + layout->addWidget(result->colorBar()); - applyCanvasConfiguration(result->canvasWidget()); + connect(doc, SIGNAL(replaceActivePage(KoPAPageBase*,KoPAPageBase*)), result, SLOT(replaceActivePage(KoPAPageBase*,KoPAPageBase*))); - return result; + return view; } KoMainWindow *KarbonPart::createMainWindow() @@ -99,17 +101,3 @@ document()->setOutputMimeType("application/vnd.oasis.opendocument.graphics"); } } - - -void KarbonPart::applyCanvasConfiguration(KarbonCanvas *canvas) -{ - KSharedConfigPtr config = componentData().config(); - - QColor color(Qt::white); - if (config->hasGroup("Interface")) { - color = config->group("Interface").readEntry("CanvasColor", color); - } - canvas->setBackgroundColor(color); -} - - diff --git a/karbon/ui/KarbonPrintJob.h b/karbon/ui/KarbonPrintJob.h deleted file mode 100644 --- a/karbon/ui/KarbonPrintJob.h +++ /dev/null @@ -1,48 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2007 Thomas Zander - * Copyright (C) 2012 Jan Hambrecht - * - * 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 KARBONPRINTJOB_H -#define KARBONPRINTJOB_H - -#include - -class KarbonView; - -class KarbonPrintJob : public KoPrintingDialog -{ -public: - // the available print modes - enum PrintMode { - PrintToPaper, ///< printing to to printer device - PrintToPdf ///< printing to pdf file - }; - - KarbonPrintJob(KarbonView *view, PrintMode printMode); - -protected: - virtual QRectF preparePage(int pageNumber); - virtual QList shapesOnPage(int pageNumber); - virtual QList createOptionWidgets() const; - -private: - KarbonView *m_view; -}; - -#endif // KARBONPRINTJOB_H diff --git a/karbon/ui/KarbonPrintJob.cpp b/karbon/ui/KarbonPrintJob.cpp deleted file mode 100644 --- a/karbon/ui/KarbonPrintJob.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2007 Thomas Zander - * Copyright (C) 2009,2012 Jan Hambrecht - * - * 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 "KarbonPrintJob.h" -#include "KarbonView.h" -#include "KarbonCanvas.h" -#include "KarbonPart.h" -#include "KarbonDocument.h" - -#include -#include - -#include - -KarbonPrintJob::KarbonPrintJob(KarbonView *view, PrintMode printMode) - : KoPrintingDialog(view), - m_view(view) -{ - setShapeManager(m_view->canvasWidget()->shapeManager()); - printer().setFromTo(1, 1); - - QSizeF pageSize = m_view->part()->pageSize(); - if (pageSize.width() > pageSize.height()) - printer().setOrientation(QPrinter::Landscape); - else - printer().setOrientation(QPrinter::Portrait); - - if (printMode == PrintToPdf) { - printer().setPaperSize(pageSize, QPrinter::Point); - printer().setFullPage(true); - } -} - -QRectF KarbonPrintJob::preparePage(int) -{ - // if we have any custom tabs, here is where can can read them out and do our thing. - - const QSizeF contentSize = m_view->part()->pageSize(); - const QRectF pageRectPt = printer().pageRect(QPrinter::Point); - const double scale = POINT_TO_INCH(printer().resolution()); - - qreal zoom = 1.0; - // fit document page to printer page if it is bigger than the printing page rect - if (contentSize.width() > pageRectPt.width() || contentSize.height() > pageRectPt.height()) { - qreal zoomX = pageRectPt.width() / contentSize.width(); - qreal zoomY = pageRectPt.height() / contentSize.height(); - zoom = qMin(zoomX, zoomY); - } - - painter().scale(zoom, zoom); - painter().setRenderHint(QPainter::Antialiasing); - - return QRectF(QPointF(), scale * contentSize); -} - -QList KarbonPrintJob::shapesOnPage(int) -{ - return shapeManager()->shapes(); -} - -QList KarbonPrintJob::createOptionWidgets() const -{ - return QList(); -} diff --git a/karbon/ui/KarbonView.h b/karbon/ui/KarbonView.h --- a/karbon/ui/KarbonView.h +++ b/karbon/ui/KarbonView.h @@ -34,49 +34,55 @@ #ifndef __KARBON_VIEW__ #define __KARBON_VIEW__ -#include +#include #include #include #include #include "KarbonBooleanCommand.h" class QDropEvent; class QResizeEvent; +class QLayout; class KarbonDocument; class KoColor; class KoUnit; +class KarbonPaletteBarWidget; class KarbonPart; -class KarbonCanvas; -class KARBONUI_EXPORT KarbonView : public KoView +class KoPACanvas; +class KoCanvasResourceManager; + +class KARBONUI_EXPORT KarbonView : public KoPAView { Q_OBJECT public: KarbonView(KarbonPart *part, KarbonDocument* doc, QWidget* parent = 0); virtual ~KarbonView(); /// Returns the view is attached to - KarbonDocument * part() const; + KarbonDocument * part() const; /// Returns the canvas widget of this view - KarbonCanvas * canvasWidget() const; + KoPACanvas *canvasWidget() const; void reorganizeGUI(); void setNumberOfRecentFiles(uint number); /// Reimplemented from QWidget virtual void setCursor(const QCursor &); /// Reimplemented from QWidget virtual void dropEvent(QDropEvent *e); - /// Reimplemented from KoView - virtual KoZoomController *zoomController() const; + KoCanvasResourceManager *resourceManager() const; + + KarbonPaletteBarWidget *colorBar() const; + public Q_SLOTS: // editing: void editSelectAll(); @@ -113,17 +119,9 @@ void pathSnapToGrid(); - void configure(); - - void configurePageLayout(); - void selectionChanged(); - void togglePageMargins(bool); - void showRuler(); - void showGuides(); void editGuides(); - void snapToGrid(); void showPalette(); protected Q_SLOTS: @@ -135,27 +133,22 @@ void zoomDrawing(); void mousePositionChanged(const QPoint &position); - void pageOffsetChanged(); - - void updateUnit(const KoUnit &unit); void applyFillToSelection(); void applyStrokeToSelection(); void applyPaletteColor(const KoColor &color); protected: + /// Use own configuaration dialog + virtual void openConfiguration(); + virtual void updateReadWrite(bool readwrite); virtual void resizeEvent(QResizeEvent* event); virtual void dragEnterEvent(QDragEnterEvent * event); - virtual void addImages(const QVector &imageList, const QPoint &insertAt); - void createLayersTabDock(); void createStrokeDock(); void createColorDock(); - virtual KoPrintJob * createPrintJob(); - virtual KoPrintJob * createPdfPrintJob(); - private: void initActions(); void updateRuler(); diff --git a/karbon/ui/KarbonView.cpp b/karbon/ui/KarbonView.cpp --- a/karbon/ui/KarbonView.cpp +++ b/karbon/ui/KarbonView.cpp @@ -48,29 +48,27 @@ // Dialogs. #include "KarbonConfigureDialog.h" -// Dockers. -#include "KarbonLayerDocker.h" - // The rest. #include "Karbon.h" #include "KarbonFactory.h" #include "KarbonPart.h" -#include "KarbonCanvas.h" #include "KarbonDocument.h" -#include "KarbonPrintJob.h" -#include "KarbonZoomController.h" #include "KarbonSmallStylePreview.h" #include "KarbonDocumentMergeCommand.h" #include "KarbonPaletteBarWidget.h" #include "KarbonUiDebug.h" +#include "KarbonOutlinePaintingStrategy.h" + +#include +#include +#include #include #include #include #include #include #include -#include #include #include #include @@ -103,7 +101,6 @@ #include #include #include -#include #include #include #include @@ -132,6 +129,7 @@ #include #include #include +#include // qt header #include @@ -152,23 +150,19 @@ { public: Private(KarbonPart *part, KarbonDocument * doc) - : karbonPart(part), part(doc), canvas(0), canvasController(0), horizRuler(0), vertRuler(0) + : karbonPart(part), part(doc) , colorBar(0), closePath(0), combinePath(0) , separatePath(0), reversePath(0), intersectPath(0), subtractPath(0) , unitePath(0), excludePath(0), pathSnapToGrid(0), configureAction(0) , deleteSelectionAction(0), clipObjects(0), unclipObjects(0) - , flipVertical(0), flipHorizontal(0), viewAction(0), showRulerAction(0) + , flipVertical(0), flipHorizontal(0), viewAction(0) , snapGridAction(0), showPageMargins(0), showGuidesAction(0) , showPaletteAction(0) - , status(0), cursorCoords(0), smallPreview(0), zoomActionWidget(0) + , status(0), cursorCoords(0), smallPreview(0) {} KarbonPart * karbonPart; KarbonDocument * part; - KarbonCanvas * canvas; - KoCanvasController * canvasController; - KoRuler * horizRuler; - KoRuler * vertRuler; KarbonPaletteBarWidget *colorBar; // actions: @@ -189,73 +183,40 @@ QAction * flipHorizontal; KToggleAction * viewAction; - KToggleAction * showRulerAction; + KToggleAction * snapGridAction; KToggleAction * showPageMargins; KToggleAction * showGuidesAction; + KToggleAction * showPaletteAction; //Status Bar QLabel * status; ///< ordinary status QLabel * cursorCoords; ///< cursor coordinates KarbonSmallStylePreview * smallPreview; ///< small style preview - QWidget * zoomActionWidget; ///< zoom action widget }; KarbonView::KarbonView(KarbonPart *karbonPart, KarbonDocument* doc, QWidget* parent) - : KoView(karbonPart, doc, parent), d(new Private(karbonPart, doc)) + : KoPAView(karbonPart, doc, KoPAView::NormalMode, parent) + , d(new Private(karbonPart, doc)) { setAcceptDrops(true); setXMLFile(QString::fromLatin1("karbon.rc")); - const int viewMargin = 250; - d->canvas = new KarbonCanvas(doc); - d->canvas->setParent(this); - d->canvas->setDocumentViewMargin(viewMargin); - connect(d->canvas->shapeManager()->selection(), SIGNAL(selectionChanged()), - this, SLOT(selectionChanged())); - - KoCanvasControllerWidget *canvasController = new KoCanvasControllerWidget(actionCollection(), this); - d->canvasController = canvasController; - canvasController->setMinimumSize(QSize(viewMargin + 50, viewMargin + 50)); - d->canvasController->setCanvas(d->canvas); - d->canvasController->setCanvasMode(KoCanvasController::Infinite); - // always show srollbars which fixes some nasty infinite - // recursion when scrollbars are disabled during resizing - canvasController->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - canvasController->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - canvasController->show(); - - // set up status bar message - d->status = new QLabel(QString(), this); - d->status->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); - d->status->setMinimumWidth(300); - addStatusBarItem(d->status, 1); - connect(KoToolManager::instance(), SIGNAL(changedStatusText(QString)), - d->status, SLOT(setText(QString))); d->cursorCoords = new QLabel(QString(), this); d->cursorCoords->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); d->cursorCoords->setMinimumWidth(50); addStatusBarItem(d->cursorCoords, 0); - - // TODO maybe the zoomHandler should be a member of the view and not the canvas. - // set up the zoom controller - KarbonZoomController * zoomController = new KarbonZoomController(d->canvasController, actionCollection(), this); - zoomController->setPageSize(d->part->pageSize()); - d->zoomActionWidget = zoomController->zoomAction()->createWidget(statusBar()); - addStatusBarItem(d->zoomActionWidget, 0); - zoomController->setZoomMode(KoZoomMode::ZOOM_PAGE); - connect(zoomController, SIGNAL(zoomedToSelection()), this, SLOT(zoomSelection())); - connect(zoomController, SIGNAL(zoomedToAll()), this, SLOT(zoomDrawing())); + connect(canvasController()->proxyObject, SIGNAL(canvasMousePositionChanged(QPoint)), this, SLOT(mousePositionChanged(QPoint))); d->smallPreview = new KarbonSmallStylePreview(this); connect(d->smallPreview, SIGNAL(fillApplied()), this, SLOT(applyFillToSelection())); connect(d->smallPreview, SIGNAL(strokeApplied()), this, SLOT(applyStrokeToSelection())); addStatusBarItem(d->smallPreview, 0); - - KoToolManager::instance()->addController(d->canvasController); - KoToolManager::instance()->registerTools(actionCollection(), d->canvasController); + // FIXME: This was not neccessary before refactoring to pageapp, why now? + // Also, changing colors of a shape does not update preview + connect(shapeManager(), SIGNAL(selectionChanged()), d->smallPreview, SLOT(selectionChanged())); initActions(); @@ -273,116 +234,66 @@ } } - unsigned int max = part()->maxRecentFiles(); - setNumberOfRecentFiles(max); - - // widgets: - d->horizRuler = new KoRuler(this, Qt::Horizontal, d->canvas->viewConverter()); - d->horizRuler->setShowMousePosition(true); - d->horizRuler->setUnit(doc->unit()); - d->horizRuler->setRightToLeft(false); - d->horizRuler->setVisible(false); - new KoRulerController(d->horizRuler, d->canvas->resourceManager()); - - connect(doc, SIGNAL(unitChanged(KoUnit)), this, SLOT(updateUnit(KoUnit))); - - d->vertRuler = new KoRuler(this, Qt::Vertical, d->canvas->viewConverter()); - d->vertRuler->setShowMousePosition(true); - d->vertRuler->setUnit(doc->unit()); - d->vertRuler->setVisible(false); - - connect(d->canvas, SIGNAL(documentOriginChanged(QPoint)), this, SLOT(pageOffsetChanged())); - connect(d->canvasController->proxyObject, SIGNAL(canvasOffsetXChanged(int)), this, SLOT(pageOffsetChanged())); - connect(d->canvasController->proxyObject, SIGNAL(canvasOffsetYChanged(int)), this, SLOT(pageOffsetChanged())); - connect(d->canvasController->proxyObject, SIGNAL(canvasMousePositionChanged(QPoint)), - this, SLOT(mousePositionChanged(QPoint))); - d->vertRuler->createGuideToolConnection(d->canvas); - d->horizRuler->createGuideToolConnection(d->canvas); - - updateRuler(); + // TODO: or remove? +// unsigned int max = kopaDocument()->maxRecentFiles(); +// setNumberOfRecentFiles(max); d->colorBar = new KarbonPaletteBarWidget(Qt::Horizontal, this); connect(d->colorBar, SIGNAL(colorSelected(KoColor)), this, SLOT(applyPaletteColor(KoColor))); - connect(d->canvas->shapeManager(), SIGNAL(selectionContentChanged()), d->colorBar, SLOT(updateDocumentColors())); - connect(part(), SIGNAL(shapeCountChanged()), d->colorBar, SLOT(updateDocumentColors())); + connect(shapeManager(), SIGNAL(selectionContentChanged()), d->colorBar, SLOT(updateDocumentColors())); + connect(kopaDocument(), SIGNAL(shapeAdded(KoShape*)), d->colorBar, SLOT(updateDocumentColors())); + connect(kopaDocument(), SIGNAL(shapeRemoved(KoShape*)), d->colorBar, SLOT(updateDocumentColors())); if (mainWindow()) { - // set the first layer active - d->canvasController->canvas()->shapeManager()->selection()->setActiveLayer(part()->layers().first()); - - //Create Dockers - createLayersTabDock(); - - // set one whitespace as title to allow a one column toolbox - KoToolBoxFactory toolBoxFactory; - mainWindow()->createDockWidget(&toolBoxFactory); - - connect(canvasController, SIGNAL(toolOptionWidgetsChanged(QList >)), - mainWindow()->dockerManager(), SLOT(newOptionWidgets(QList >))); - - KoToolManager::instance()->requestToolActivation(d->canvasController); - - KConfigGroup interfaceGroup = KarbonFactory::global().config()->group("Interface"); - if(interfaceGroup.readEntry("ShowRulers", false)) { - d->horizRuler->setVisible(true); - d->vertRuler->setVisible(true); - d->showRulerAction->setChecked(true); - } - if (!interfaceGroup.readEntry("ShowPalette", true)) { - d->colorBar->setVisible(false); - d->showPaletteAction->setChecked(false); + KSharedConfigPtr config = KSharedConfig::openConfig(); + if (config->hasGroup("Interface")) { + KConfigGroup interfaceGroup = config->group( "Interface" ); + if (!interfaceGroup.readEntry("ShowPalette", true)) { + d->colorBar->setVisible(false); + d->showPaletteAction->setChecked(false); + } } } - // layout: - QGridLayout *layout = new QGridLayout(); - layout->setMargin(0); - layout->setSpacing(0); - layout->addWidget(d->horizRuler->tabChooser(), 0, 0); - layout->addWidget(d->horizRuler, 0, 1); - layout->addWidget(d->vertRuler, 1, 0); - layout->addWidget(canvasController, 1, 1); - layout->addWidget(d->colorBar, 2, 1); - setLayout(layout); - reorganizeGUI(); setFocusPolicy(Qt::NoFocus); } KarbonView::~KarbonView() { - KoToolManager::instance()->removeCanvasController(d->canvasController); - - removeStatusBarItem(d->status); removeStatusBarItem(d->cursorCoords); removeStatusBarItem(d->smallPreview); - removeStatusBarItem(d->zoomActionWidget); + if (factory()) { + factory()->removeClient(this); + } delete d; } +KarbonPaletteBarWidget *KarbonView::colorBar() const +{ + return d->colorBar; +} + KarbonDocument * KarbonView::part() const { - return d->part; + return static_cast(kopaDocument()); } -KarbonCanvas * KarbonView::canvasWidget() const +KoCanvasResourceManager *KarbonView::resourceManager() const { - return d->canvas; + return kopaCanvas()->resourceManager(); } -KoZoomController * KarbonView::zoomController() const +KoPACanvas *KarbonView::canvasWidget() const { - return 0; + return dynamic_cast(kopaCanvas()); } void KarbonView::resizeEvent(QResizeEvent* /*event*/) { - if (!d->showRulerAction) - return; - - if (!d->canvas) + if (!kopaCanvas()) return; reorganizeGUI(); @@ -403,14 +314,14 @@ //Accepts QColor - from Color Manager's KColorPatch QColor color = KColorMimeData::fromMimeData(e->mimeData()); if (color.isValid()) { - KoSelection * selection = d->canvas->shapeManager()->selection(); + KoSelection * selection = shapeManager()->selection(); if (! selection) return; - if (! part()) + if (! kopaDocument()) return; - if (d->canvas->resourceManager()->intResource(KoCanvasResourceManager::ActiveStyleType) == KoFlake::Foreground) { + if (resourceManager()->intResource(KoCanvasResourceManager::ActiveStyleType) == KoFlake::Foreground) { QList strokes; QList selectedShapes = selection->selectedShapes(); foreach(KoShape * shape, selectedShapes) { @@ -424,60 +335,19 @@ } strokes.append(newStroke); } - d->canvas->addCommand(new KoShapeStrokeCommand(selectedShapes, strokes, 0)); + kopaCanvas()->addCommand(new KoShapeStrokeCommand(selectedShapes, strokes, 0)); } else { QSharedPointer fill(new KoColorBackground(color)); - d->canvas->addCommand(new KoShapeBackgroundCommand(selection->selectedShapes(), fill, 0)); + kopaCanvas()->addCommand(new KoShapeBackgroundCommand(selection->selectedShapes(), fill, 0)); } } - KoView::dropEvent(e); + KoPAView::dropEvent(e); } -void KarbonView::addImages(const QVector &imageList, const QPoint &insertAt) -{ - // get position from event and convert to document coordinates - QPointF pos = canvasWidget()->viewConverter()->viewToDocument(insertAt) - + canvasWidget()->documentOffset() - canvasWidget()->documentOrigin(); - - // create a factory - KoShapeFactoryBase *factory = KoShapeRegistry::instance()->value("PictureShape"); - if (!factory) { - warnKarbonUi << "No picture shape found, cannot drop images."; - return; - } - - foreach(const QImage &image, imageList) { - - KoProperties params; - QVariant v; - v.setValue(image); - params.setProperty("qimage", v); - - KoShape *shape = factory->createShape(¶ms, part()->resourceManager()); - - if (!shape) { - warnKarbonUi << "Could not create a shape from the image"; - return; - } - shape->setPosition(pos); - pos += QPointF(25,25); // increase the position for each shape we insert so the - // user can see them all. - KUndo2Command *cmd = canvasWidget()->shapeController()->addShapeDirect(shape); - if (cmd) { - KoSelection *selection = canvasWidget()->shapeManager()->selection(); - selection->deselectAll(); - selection->select(shape); - } - canvasWidget()->addCommand(cmd); - } -} - - - void KarbonView::fileImportGraphic() { - QByteArray nativeMimeType = part()->nativeFormatMimeType(); + QByteArray nativeMimeType = kopaDocument()->nativeFormatMimeType(); QStringList filter = KoFilterManager::mimeFilter(nativeMimeType, KoFilterManager::Import); QStringList imageFilter; @@ -494,12 +364,14 @@ if (fname.isEmpty()) return; - QMap dataCenters = part()->dataCenterMap(); + //TODO or remove + QMap dataCenters; KarbonPart importPart(0); KarbonDocument importDocument(&importPart); importPart.setDocument(&importDocument); + // TODO // use data centers of this document for importing importDocument.useExternalDataCenterMap(dataCenters); @@ -537,8 +409,8 @@ return; } - KoShape *picture = factory->createDefaultShape(part()->resourceManager()); - KoImageCollection *imageCollection = part()->resourceManager()->imageCollection(); + KoShape *picture = factory->createDefaultShape(kopaDocument()->resourceManager()); + KoImageCollection *imageCollection = kopaDocument()->resourceManager()->imageCollection(); if (!picture || !imageCollection) { KMessageBox::error(0, i18n("Could not create image shape."), i18n("Import graphic"), 0); return; @@ -556,13 +428,17 @@ picture->setPosition(QPointF()); picture->setKeepAspectRatio(true); - KUndo2Command * cmd = d->canvas->shapeController()->addShapeDirect(picture); + KUndo2Command * cmd = kopaCanvas()->shapeController()->addShapeDirect(picture); cmd->setText(kundo2_i18n("Insert graphics")); - d->canvas->addCommand(cmd); - d->canvas->shapeManager()->selection()->select(picture); + kopaCanvas()->addCommand(cmd); + shapeManager()->selection()->select(picture); return; } - + // TODO: It is not obvious how this is best implemented when importing multipage docs + // Append pages? + // Append layers to existing pages? + // Add shapes to active page? + // etc? // check if we are loading our native format if (nativeMimeType == currentMimeFilter) { // directly load the native format @@ -589,30 +465,32 @@ } if (success) { - QList importedShapes = importDocument.shapes(); - - KarbonDocumentMergeCommand * cmd = new KarbonDocumentMergeCommand(part(), &importDocument); - d->canvas->addCommand(cmd); - + KarbonDocumentMergeCommand * cmd = new KarbonDocumentMergeCommand(dynamic_cast(kopaDocument()), importDocument); + kopaCanvas()->addCommand(cmd); +/* foreach(KoShape * shape, importedShapes) { d->canvas->shapeManager()->selection()->select(shape, false); - } + }*/ } } void KarbonView::selectionDuplicate() { - d->canvas->toolProxy()->copy(); - d->canvas->toolProxy()->paste(); + kopaCanvas()->toolProxy()->copy(); + kopaCanvas()->toolProxy()->paste(); } void KarbonView::editSelectAll() { - KoSelection* selection = d->canvas->shapeManager()->selection(); - if (! selection) + KoSelection* selection = shapeManager()->selection(); + if (! selection) { return; - - QList shapes = part()->shapes(); + } + QList shapes; + for (int i = 0; i < kopaDocument()->pages().count(); ++i) { + KoShapeLayer *l = dynamic_cast(kopaDocument()->pages().at(i)); + shapes += l->shapes(); + } debugKarbonUi << "shapes.size() =" << shapes.size(); foreach(KoShape* shape, shapes) { @@ -625,16 +503,16 @@ void KarbonView::editDeselectAll() { - KoSelection* selection = d->canvas->shapeManager()->selection(); + KoSelection* selection = shapeManager()->selection(); if (selection) selection->deselectAll(); selectionChanged(); } void KarbonView::editDeleteSelection() { - d->canvas->toolProxy()->deleteSelection(); + kopaCanvas()->toolProxy()->deleteSelection(); } void KarbonView::selectionDistributeHorizontalCenter() @@ -679,21 +557,21 @@ void KarbonView::selectionDistribute(KoShapeDistributeCommand::Distribute distribute) { - KoSelection* selection = d->canvas->shapeManager()->selection(); + KoSelection* selection = shapeManager()->selection(); if (! selection) return; QList selectedShapes = selection->selectedShapes(KoFlake::TopLevelSelection); if (selectedShapes.count() < 2) return; KoShapeDistributeCommand *cmd = new KoShapeDistributeCommand(selectedShapes, distribute, selection->boundingRect()); - d->canvas->addCommand(cmd); + kopaCanvas()->addCommand(cmd); } void KarbonView::clipObjects() { - KoSelection* selection = d->canvas->shapeManager()->selection(); + KoSelection* selection = shapeManager()->selection(); if( ! selection ) return; @@ -715,13 +593,13 @@ if( ! clipPaths.count() ) return; - KUndo2Command * cmd = new KoShapeClipCommand( d->part, shapeToClip, clipPaths ); - d->canvas->addCommand( cmd ); + KUndo2Command * cmd = new KoShapeClipCommand( kopaDocument(), shapeToClip, clipPaths ); + kopaCanvas()->addCommand( cmd ); } void KarbonView::unclipObjects() { - KoSelection* selection = d->canvas->shapeManager()->selection(); + KoSelection* selection = shapeManager()->selection(); if( ! selection ) return; @@ -737,7 +615,7 @@ if (!shapesToUnclip.count()) return; - d->canvas->addCommand(new KoShapeUnclipCommand(d->part, shapesToUnclip)); + kopaCanvas()->addCommand(new KoShapeUnclipCommand(kopaDocument(), shapesToUnclip)); } void KarbonView::flipVertical() @@ -755,7 +633,7 @@ if (!horizontally && !vertically) return; - KoSelection* selection = d->canvas->shapeManager()->selection(); + KoSelection* selection = shapeManager()->selection(); if( ! selection ) return; @@ -793,7 +671,7 @@ cmd->setText(kundo2_i18n("Mirror Vertically")); else cmd->setText(kundo2_i18n("Mirror Horizontally and Vertically")); - d->canvas->addCommand(cmd); + kopaCanvas()->addCommand(cmd); } void KarbonView::closePath() @@ -803,7 +681,7 @@ void KarbonView::combinePath() { - KoSelection* selection = d->canvas->shapeManager()->selection(); + KoSelection* selection = shapeManager()->selection(); if (! selection) return; @@ -822,12 +700,12 @@ } if (paths.size()) - d->canvas->addCommand(new KoPathCombineCommand(part(), paths)); + kopaCanvas()->addCommand(new KoPathCombineCommand(kopaDocument(), paths)); } void KarbonView::separatePath() { - KoSelection* selection = d->canvas->shapeManager()->selection(); + KoSelection* selection = shapeManager()->selection(); if (! selection) return; @@ -854,26 +732,26 @@ QList newShapes; if (p->separate(separatedPaths)) { foreach(KoPathShape *subPath, separatedPaths) { - new KoShapeCreateCommand(part(), subPath, cmd); + new KoShapeCreateCommand(kopaDocument(), subPath, cmd); newShapes << subPath; } // make sure we put the new subpaths into the parent // of the original path KoShapeGroup *parentGroup = dynamic_cast(p->parent()); if (parentGroup) { new KoShapeGroupCommand(parentGroup, newShapes, cmd); } - new KoShapeDeleteCommand(part(), p, cmd); + new KoShapeDeleteCommand(kopaDocument(), p, cmd); } } - d->canvas->addCommand(cmd); + kopaCanvas()->addCommand(cmd); } void KarbonView::reversePath() { QList paths = selectedPathShapes(); if (paths.size()) - d->canvas->addCommand(new KoPathReverseCommand(paths)); + kopaCanvas()->addCommand(new KoPathReverseCommand(paths)); } void KarbonView::intersectPaths() @@ -898,7 +776,7 @@ void KarbonView::booleanOperation(KarbonBooleanCommand::BooleanOperation operation) { - KoSelection* selection = d->canvas->shapeManager()->selection(); + KoSelection* selection = shapeManager()->selection(); if (! selection) return; @@ -921,29 +799,29 @@ paramShape = dynamic_cast(paths[1]); if (paramShape && paramShape->isParametricShape()) new KoParameterToPathCommand(paramShape, macro); - new KarbonBooleanCommand(part(), paths[0], paths[1], operation, macro); - new KoShapeDeleteCommand(part(), paths[0], macro); - new KoShapeDeleteCommand(part(), paths[1], macro); - d->canvas->addCommand(macro); + new KarbonBooleanCommand(kopaDocument(), paths[0], paths[1], operation, macro); + new KoShapeDeleteCommand(kopaDocument(), paths[0], macro); + new KoShapeDeleteCommand(kopaDocument(), paths[1], macro); + kopaCanvas()->addCommand(macro); } } void KarbonView::pathSnapToGrid() { - KoSelection* selection = d->canvas->shapeManager()->selection(); + KoSelection* selection = shapeManager()->selection(); if (! selection) return; QList selectedShapes = selection->selectedShapes(); QList points; QVector offsets; // store current grid snap state - bool oldSnapToGrid = part()->gridData().snapToGrid(); + bool oldSnapToGrid = kopaDocument()->gridData().snapToGrid(); // enable grid snapping - part()->gridData().setSnapToGrid(true); + kopaDocument()->gridData().setSnapToGrid(true); - KoSnapGuide snapGuide(d->canvas); + KoSnapGuide snapGuide(kopaCanvas()); snapGuide.enableSnapStrategies(KoSnapGuide::GridSnapping); snapGuide.setSnapDistance(INT_MAX); @@ -974,52 +852,55 @@ } // reset grid snapping state to old value - part()->gridData().setSnapToGrid(oldSnapToGrid); + kopaDocument()->gridData().setSnapToGrid(oldSnapToGrid); - d->canvas->addCommand(new KoPathPointMoveCommand(points, offsets)); + kopaCanvas()->addCommand(new KoPathPointMoveCommand(points, offsets)); } void KarbonView::viewModeChanged(bool outlineMode) { - d->canvas->enableOutlineMode(outlineMode); - d->canvas->updateCanvas(d->canvas->canvasWidget()->rect()); + if (outlineMode) { + new KarbonOutlinePaintingStrategy(shapeManager()); + } else { + shapeManager()->setPaintingStrategy(new KoShapeManagerPaintingStrategy(shapeManager())); + } } void KarbonView::zoomSelection() { - KoSelection* selection = d->canvas->shapeManager()->selection(); + KoSelection* selection = shapeManager()->selection(); if (! selection) return; if (! selection->count()) return; - const KoZoomHandler * zoomHandler = dynamic_cast(d->canvas->viewConverter()); + const KoZoomHandler * zoomHandler = dynamic_cast(viewConverter()); if (! zoomHandler) return; QRectF bbox = selection->boundingRect(); QRect viewRect = zoomHandler->documentToView(bbox).toRect(); - d->canvasController->zoomTo(viewRect.translated(d->canvas->documentOrigin())); - QPointF newCenter = d->canvas->documentOrigin() + zoomHandler->documentToView(bbox.center()); - d->canvasController->setPreferredCenter(newCenter.toPoint()); + kopaCanvas()->canvasController()->zoomTo(viewRect.translated(kopaCanvas()->documentOrigin())); +// QPointF newCenter = kopaCanvas()->documentOrigin() + zoomHandler->documentToView(bbox.center()); +// kopaCanvas()->setPreferredCenter(newCenter.toPoint()); } void KarbonView::zoomDrawing() { - const KoZoomHandler * zoomHandler = dynamic_cast(d->canvas->viewConverter()); + const KoZoomHandler * zoomHandler = dynamic_cast(kopaCanvas()->viewConverter()); if (! zoomHandler) return; - QRectF bbox = d->part->contentRect(); + QRectF bbox = activePage()->contentRect(); if (bbox.isNull()) return; QRect viewRect = zoomHandler->documentToView(bbox).toRect(); - d->canvasController->zoomTo(viewRect.translated(d->canvas->documentOrigin())); - QPointF newCenter = d->canvas->documentOrigin() + zoomHandler->documentToView(bbox.center()); - d->canvasController->setPreferredCenter(newCenter.toPoint()); + kopaCanvas()->canvasController()->zoomTo(viewRect.translated(kopaCanvas()->documentOrigin())); +// QPointF newCenter = kopaCanvas()->documentOrigin() + zoomHandler->documentToView(bbox.center()); +// kopaCanvas()->setPreferredCenter(newCenter.toPoint()); } void KarbonView::initActions() @@ -1029,21 +910,17 @@ actionCollection()->addAction("view_mode", d->viewAction); connect(d->viewAction, SIGNAL(toggled(bool)), this, SLOT(viewModeChanged(bool))); - d->showPageMargins = new KToggleAction(i18n("Show Page Margins"), this); - actionCollection()->addAction("view_show_margins", d->showPageMargins); - connect(d->showPageMargins, SIGNAL(toggled(bool)), SLOT(togglePageMargins(bool))); - // No need for the other actions in read-only (embedded) mode if (!mainWindow()) return; // edit -----> QAction *action = actionCollection()->addAction(KStandardAction::Cut, "edit_cut", 0, 0); - new KoCutController(d->canvas, action); + new KoCutController(kopaCanvas(), action); action = actionCollection()->addAction(KStandardAction::Copy, "edit_copy", 0, 0); - new KoCopyController(d->canvas, action); + new KoCopyController(kopaCanvas(), action); action = actionCollection()->addAction(KStandardAction::Paste, "edit_paste", 0, 0); - new KoPasteController(d->canvas, action); + new KoPasteController(kopaCanvas(), action); actionCollection()->addAction(KStandardAction::SelectAll, "edit_select_all", this, SLOT(editSelectAll())); actionCollection()->addAction(KStandardAction::Deselect, "edit_deselect_all", this, SLOT(editDeselectAll())); @@ -1055,7 +932,7 @@ actionCollection()->addAction("edit_delete", d->deleteSelectionAction); d->deleteSelectionAction->setShortcut(QKeySequence("Del")); connect(d->deleteSelectionAction, SIGNAL(triggered()), this, SLOT(editDeleteSelection())); - connect(d->canvas->toolProxy(), SIGNAL(selectionChanged(bool)), d->deleteSelectionAction, SLOT(setEnabled(bool))); + connect(kopaCanvas()->toolProxy(), SIGNAL(selectionChanged(bool)), d->deleteSelectionAction, SLOT(setEnabled(bool))); QAction *actionEditGuides = new QAction(koIcon("edit-guides"), i18n("Edit Guides"), this); actionCollection()->addAction("edit_guides", actionEditGuides); @@ -1100,30 +977,12 @@ actionCollection()->addAction("object_distribute_vertical_top", actionDistributeTop); connect(actionDistributeTop, SIGNAL(triggered()), this, SLOT(selectionDistributeVerticalTop())); - d->showRulerAction = new KToggleAction(i18n("Show Rulers"), this); - actionCollection()->addAction("view_show_ruler", d->showRulerAction); - d->showRulerAction->setToolTip(i18n("Shows or hides rulers")); - d->showRulerAction->setChecked(false); - connect(d->showRulerAction, SIGNAL(triggered()), this, SLOT(showRuler())); - - KToggleAction *gridAction = d->part->gridData().gridToggleAction(d->canvas); - actionCollection()->addAction("view_grid", gridAction); - - d->showGuidesAction = KoStandardAction::showGuides(this, SLOT(showGuides()), this); - actionCollection()->addAction(KoStandardAction::name(KoStandardAction::ShowGuides), d->showGuidesAction); - d->showGuidesAction->setChecked(d->part->guidesData().showGuideLines()); - d->showPaletteAction = new KToggleAction(i18n("Show Color Palette"), this); actionCollection()->addAction("view_show_palette", d->showPaletteAction); d->showPaletteAction->setToolTip(i18n("Show or hide color palette")); d->showPaletteAction->setChecked(true); connect(d->showPaletteAction, SIGNAL(triggered()), this, SLOT(showPalette())); - d->snapGridAction = new KToggleAction(i18n("Snap to Grid"), this); - actionCollection()->addAction("view_snap_to_grid", d->snapGridAction); - d->snapGridAction->setToolTip(i18n("Snaps to grid")); - connect(d->snapGridAction, SIGNAL(triggered()), this, SLOT(snapToGrid())); - action = actionCollection()->action("object_group"); if (action) { action->setShortcut(QKeySequence("Ctrl+G")); @@ -1207,18 +1066,6 @@ // path <----- - d->configureAction = new QAction(koIcon("configure"), i18n("Configure Karbon..."), this); - actionCollection()->addAction("configure", d->configureAction); - connect(d->configureAction, SIGNAL(triggered()), this, SLOT(configure())); - // not sure why this isn't done through KStandardAction, but since it isn't - // we ought to set the MenuRole manually so the item ends up in the appropriate - // menu on OS X: - d->configureAction->setMenuRole(QAction::PreferencesRole); - - QAction *actionPageLayout = new QAction(i18n("Page &Layout..."), this); - actionCollection()->addAction("page_layout", actionPageLayout); - connect(actionPageLayout, SIGNAL(triggered()), this, SLOT(configurePageLayout())); - // view ----> QAction * zoomSelection = new QAction(koIcon("zoom-select"), i18n("Zoom to Selection"), this); actionCollection()->addAction("view_zoom_selection", zoomSelection); @@ -1232,16 +1079,12 @@ void KarbonView::mousePositionChanged(const QPoint &position) { - QPoint canvasOffset(d->canvasController->canvasOffsetX(), d->canvasController->canvasOffsetY()); - QPoint viewPos = position - d->canvas->documentOrigin() - canvasOffset; - if (d->horizRuler->isVisible()) - d->horizRuler->updateMouseCoordinate(viewPos.x()); - if (d->vertRuler->isVisible()) - d->vertRuler->updateMouseCoordinate(viewPos.y()); + const QPoint canvasOffset(canvasController()->canvasOffsetX(), canvasController()->canvasOffsetY() ); + const QPoint viewPos = position - kopaCanvas()->documentOrigin() - canvasOffset; - QPointF documentPos = d->canvas->viewConverter()->viewToDocument(viewPos); - qreal x = part()->unit().toUserValue(documentPos.x()); - qreal y = part()->unit().toUserValue(documentPos.y()); + QPointF documentPos = kopaCanvas()->viewConverter()->viewToDocument(viewPos); + qreal x = kopaDocument()->unit().toUserValue(documentPos.x()); + qreal y = kopaDocument()->unit().toUserValue(documentPos.y()); if (statusBar() && statusBar()->isVisible()) { QLocale locale; @@ -1251,73 +1094,33 @@ void KarbonView::reorganizeGUI() { - if (d->snapGridAction) - d->snapGridAction->setChecked(part()->gridData().snapToGrid()); - if (statusBar()) - statusBar()->setVisible(part()->showStatusBar()); + // TODO: Find a better solution, maybe move to KoPAView? + if (statusBar()) { + bool show = true; + if (mainWindow()) { + KSharedConfigPtr config = KSharedConfig::openConfig(); + if (config->hasGroup("Interface")) { + KConfigGroup interfaceGroup = config->group( "Interface" ); + if (!interfaceGroup.readEntry("ShowStatusBar", true)) { + show = false; + } + } + } + statusBar()->setVisible(show); + } } void KarbonView::setNumberOfRecentFiles(unsigned int number) { if (mainWindow()) // 0L when embedded into konq ! mainWindow()->setMaxRecentItems(number); } -void KarbonView::showRuler() -{ - if(!mainWindow()) - return; - - const bool showRuler = d->showRulerAction->isChecked(); - d->horizRuler->setVisible(showRuler); - d->vertRuler->setVisible(showRuler); - if (showRuler) - updateRuler(); - - // this will make the last setting of the ruler visibility persistent - KConfigGroup interfaceGroup = KarbonFactory::global().config()->group("Interface"); - if (!showRuler && !interfaceGroup.hasDefault("ShowRulers")) - interfaceGroup.revertToDefault("ShowRulers"); - else - interfaceGroup.writeEntry("ShowRulers", showRuler); -} - -void KarbonView::togglePageMargins(bool b) -{ - ((KToggleAction*)actionCollection()->action("view_show_margins"))->setChecked(b); - d->canvas->setShowPageMargins(b); - d->canvas->update(); -} - -void KarbonView::pageOffsetChanged() -{ - d->horizRuler->setOffset(d->canvasController->canvasOffsetX() + d->canvas->documentOrigin().x()); - d->vertRuler->setOffset(d->canvasController->canvasOffsetY() + d->canvas->documentOrigin().y()); -} - -void KarbonView::updateRuler() -{ - d->horizRuler->setRulerLength(part()->pageSize().width()); - d->vertRuler->setRulerLength(part()->pageSize().height()); -} - -void KarbonView::showGuides() -{ - d->part->guidesData().setShowGuideLines(d->showGuidesAction->isChecked()); - d->canvas->update(); -} - void KarbonView::editGuides() { KoToolManager::instance()->switchToolRequested("GuidesTool_ID"); } -void KarbonView::snapToGrid() -{ - d->part->gridData().setSnapToGrid(d->snapGridAction->isChecked()); - d->canvas->update(); -} - void KarbonView::showPalette() { if(!mainWindow()) @@ -1334,36 +1137,19 @@ interfaceGroup.writeEntry("ShowPalette", showPalette); } -void KarbonView::configure() +void KarbonView::openConfiguration() { QPointer dialog = new KarbonConfigureDialog(this); dialog->exec(); delete dialog; - d->part->reorganizeGUI(); - d->canvas->update(); -} - -void KarbonView::configurePageLayout() -{ - QPointer dlg = new KoPageLayoutDialog(this, part()->pageLayout()); - dlg->showPageSpread(false); - dlg->showTextDirection(false); - dlg->setPageSpread(false); - dlg->setUnit(d->part->unit()); - - if (dlg->exec() == QDialog::Accepted) { - if (dlg) { - part()->setPageLayout(dlg->pageLayout()); - } - } - delete dlg; + reorganizeGUI(); } void KarbonView::selectionChanged() { if (!mainWindow()) return; - KoSelection *selection = d->canvas->shapeManager()->selection(); + KoSelection *selection = kopaCanvas()->shapeManager()->selection(); QList selectedShapes = selection->selectedShapes(KoFlake::FullSelection); const int count = selectedShapes.count(); @@ -1426,39 +1212,17 @@ void KarbonView::setCursor(const QCursor &c) { - d->canvas->setCursor(c); -} - -void KarbonView::createLayersTabDock() -{ - if (mainWindow()) - { - KarbonLayerDockerFactory layerFactory; - KarbonLayerDocker * layerDocker = qobject_cast(mainWindow()->createDockWidget(&layerFactory)); - layerDocker->setCanvas(d->canvas); - connect(d->canvas->shapeManager(), SIGNAL(selectionChanged()), - layerDocker, SLOT(updateView())); - connect(d->canvas->shapeManager(), SIGNAL(selectionContentChanged()), - layerDocker, SLOT(updateView())); - connect(d->part, SIGNAL(shapeCountChanged()), layerDocker, SLOT(updateView())); - } + kopaCanvas()->setCursor(c); } void KarbonView::updateReadWrite(bool readwrite) { Q_UNUSED(readwrite); } -void KarbonView::updateUnit(const KoUnit &unit) -{ - d->horizRuler->setUnit(unit); - d->vertRuler->setUnit(unit); - d->canvas->resourceManager()->setResource(KoCanvasResourceManager::Unit, unit); -} - QList KarbonView::selectedPathShapes() { - KoSelection* selection = d->canvas->shapeManager()->selection(); + KoSelection* selection = shapeManager()->selection(); if (! selection) return QList(); @@ -1476,43 +1240,33 @@ return paths; } -KoPrintJob * KarbonView::createPrintJob() -{ - return new KarbonPrintJob(this, KarbonPrintJob::PrintToPaper); -} - -KoPrintJob * KarbonView::createPdfPrintJob() -{ - return new KarbonPrintJob(this, KarbonPrintJob::PrintToPdf); -} - void KarbonView::applyFillToSelection() { - KoSelection *selection = d->canvas->shapeManager()->selection(); + KoSelection *selection = shapeManager()->selection(); if (! selection->count()) return; KoShape * shape = selection->firstSelectedShape(); - d->canvas->addCommand(new KoShapeBackgroundCommand(selection->selectedShapes(), shape->background())); + kopaCanvas()->addCommand(new KoShapeBackgroundCommand(selection->selectedShapes(), shape->background())); } void KarbonView::applyStrokeToSelection() { - KoSelection *selection = d->canvas->shapeManager()->selection(); + KoSelection *selection = shapeManager()->selection(); if (! selection->count()) return; KoShape * shape = selection->firstSelectedShape(); - d->canvas->addCommand(new KoShapeStrokeCommand(selection->selectedShapes(), shape->stroke())); + kopaCanvas()->addCommand(new KoShapeStrokeCommand(selection->selectedShapes(), shape->stroke())); } void KarbonView::applyPaletteColor(const KoColor &color) { - KoSelection *selection = d->canvas->shapeManager()->selection(); + KoSelection *selection = shapeManager()->selection(); if (! selection->count()) return; - int style = d->canvas->resourceManager()->intResource(KoCanvasResourceManager::ActiveStyleType); + int style = resourceManager()->intResource(KoCanvasResourceManager::ActiveStyleType); if (style == KoFlake::Foreground) { QList newStrokes; foreach(KoShape *shape, selection->selectedShapes()) { @@ -1526,12 +1280,12 @@ newStrokes << new KoShapeStroke(1.0, color.toQColor()); } } - d->canvas->addCommand(new KoShapeStrokeCommand(selection->selectedShapes(), newStrokes)); - d->canvas->resourceManager()->setForegroundColor(color); + kopaCanvas()->addCommand(new KoShapeStrokeCommand(selection->selectedShapes(), newStrokes)); + resourceManager()->setForegroundColor(color); } else { QSharedPointer fill(new KoColorBackground(color.toQColor())); - d->canvas->addCommand(new KoShapeBackgroundCommand(selection->selectedShapes(), fill)); - d->canvas->resourceManager()->setBackgroundColor(color); + kopaCanvas()->addCommand(new KoShapeBackgroundCommand(selection->selectedShapes(), fill)); + resourceManager()->setBackgroundColor(color); } } diff --git a/karbon/ui/dockers/KarbonLayerSortingModel.h b/karbon/ui/ProxyView.h rename from karbon/ui/dockers/KarbonLayerSortingModel.h rename to karbon/ui/ProxyView.h --- a/karbon/ui/dockers/KarbonLayerSortingModel.h +++ b/karbon/ui/ProxyView.h @@ -1,5 +1,5 @@ /* This file is part of the KDE project - * Copyright (C) 2008-2009 Jan Hambrecht + * Copyright (C) 2019 Dag Andersen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -17,24 +17,32 @@ * Boston, MA 02110-1301, USA. */ -#ifndef KARBON_LAYER_SORTING_MODEL_H -#define KARBON_LAYER_SORTING_MODEL_H +#ifndef __PROXYVIEW_H__ +#define __PROXYVIEW_H__ -#include +#include +#include -class KarbonDocument; - -class KarbonLayerSortingModel : public QSortFilterProxyModel +class ProxyView : public KoView { Q_OBJECT public: - explicit KarbonLayerSortingModel(QObject *parent); - /// Sets a new document to use for sorting - void setDocument(KarbonDocument * newDocument); -protected: - virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const; + ProxyView(KoPart *part, KoDocument* doc, QWidget* parent = 0); + ~ProxyView() Q_DECL_OVERRIDE; + + virtual void updateReadWrite(bool readwrite) Q_DECL_OVERRIDE; + virtual KoZoomController *zoomController() const Q_DECL_OVERRIDE; + virtual KoPageLayout pageLayout() const Q_DECL_OVERRIDE; + virtual void guiActivateEvent(bool activated) Q_DECL_OVERRIDE; + + virtual QPrintDialog *createPrintDialog(KoPrintJob *printJob, QWidget *parent) Q_DECL_OVERRIDE; + virtual KoPrintJob *createPrintJob() Q_DECL_OVERRIDE; + virtual KoPrintJob *createPdfPrintJob() Q_DECL_OVERRIDE; + private: - KarbonDocument *m_document; ///< the underlying data structure + friend class KarbonPart; + KoView *view; }; -#endif // KARBON_LAYER_SORTING_MODEL_H +#endif + diff --git a/karbon/ui/ProxyView.cpp b/karbon/ui/ProxyView.cpp new file mode 100644 --- /dev/null +++ b/karbon/ui/ProxyView.cpp @@ -0,0 +1,76 @@ +/* This file is part of the KDE project + * Copyright (C) 2019 Dag Andersen + * + * 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 "ProxyView.h" + +#include + +#include + +ProxyView::ProxyView(KoPart *karbonPart, KoDocument* doc, QWidget* parent) + : KoView(karbonPart, doc, parent) +{ + setObjectName("Karbon view helper"); +} + +ProxyView::~ProxyView() +{ + if (factory()) { + factory()->removeClient(this); + } +} + +void ProxyView::updateReadWrite(bool readwrite) +{ + view->updateReadWrite(readwrite); +} + +KoZoomController *ProxyView::zoomController() const +{ + return view->zoomController(); +} + +KoPageLayout ProxyView::pageLayout() const +{ + return view->pageLayout(); +} + +void ProxyView::guiActivateEvent(bool activated) +{ + if (activated) { + factory()->addClient(view); + } else { + factory()->removeClient(view); + } +} + +QPrintDialog *ProxyView::createPrintDialog(KoPrintJob *printJob, QWidget *parent) +{ + return view->createPrintDialog(printJob, parent); +} + +KoPrintJob *ProxyView::createPrintJob() +{ + return view->createPrintJob(); +} + +KoPrintJob *ProxyView::createPdfPrintJob() +{ + return view->createPdfPrintJob(); +} diff --git a/karbon/ui/dockers/KarbonLayerDocker.h b/karbon/ui/dockers/KarbonLayerDocker.h deleted file mode 100644 --- a/karbon/ui/dockers/KarbonLayerDocker.h +++ /dev/null @@ -1,91 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2006-2007 Jan Hambrecht - * - * 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 KARBONLAYERDOCKER_H -#define KARBONLAYERDOCKER_H - -#include -#include -#include -#include -#include - -class KoShape; -class KoShapeLayer; -class KoShapeGroup; -class KarbonLayerModel; -class KarbonLayerSortingModel; -class KarbonDocument; -class QModelIndex; - -class KarbonLayerDockerFactory : public KoDockFactoryBase -{ -public: - KarbonLayerDockerFactory(); - - virtual QString id() const; - virtual QDockWidget* createDockWidget(); - DockPosition defaultDockPosition() const { - return DockRight; - } -}; - -class KarbonLayerDocker : public QDockWidget, public KoCanvasObserverBase -{ - Q_OBJECT - -public: - KarbonLayerDocker(); - virtual ~KarbonLayerDocker(); - - virtual QString observerName() const { return QStringLiteral("KarbonLayerDocker"); } - -public Q_SLOTS: - void updateView(); - virtual void setCanvas(KoCanvasBase* canvas); - virtual void unsetCanvas(); -private Q_SLOTS: - void slotButtonClicked(int buttonId); - void addLayer(); - void deleteItem(); - void raiseItem(); - void lowerItem(); - void itemClicked(const QModelIndex &index); - void minimalView(); - void detailedView(); - void thumbnailView(); -private: - void extractSelectedLayersAndShapes(QList &layers, QList &shapes, bool addChilds = false); - void addChildsRecursive(KoShapeGroup * parent, QList &shapes); - - KoShape * shapeFromIndex(const QModelIndex &index); - - void setViewMode(KoDocumentSectionView::DisplayMode mode); - void selectLayers(const QList &layers); - - KarbonDocument * m_doc; - KarbonLayerModel * m_model; - KarbonLayerSortingModel * m_sortModel; - KoDocumentSectionView * m_layerView; - QTimer m_updateTimer; - QHash m_viewModeActions; -}; - -#endif // KARBONLAYERDOCKER_H - -// kate: replace-tabs on; space-indent on; indent-width 4; mixedindent off; indent-mode cstyle; diff --git a/karbon/ui/dockers/KarbonLayerDocker.cpp b/karbon/ui/dockers/KarbonLayerDocker.cpp deleted file mode 100644 --- a/karbon/ui/dockers/KarbonLayerDocker.cpp +++ /dev/null @@ -1,492 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2006-2009 Jan Hambrecht - * - * 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 "KarbonLayerDocker.h" -#include "KarbonLayerModel.h" -#include "KarbonLayerSortingModel.h" -#include "KarbonFactory.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 -#include -#include -#include - -enum ButtonIds { - Button_New, - Button_Raise, - Button_Lower, - Button_Delete -}; - -KarbonLayerDockerFactory::KarbonLayerDockerFactory() -{ -} - -QString KarbonLayerDockerFactory::id() const -{ - return QString("Layer view"); -} - -QDockWidget* KarbonLayerDockerFactory::createDockWidget() -{ - KarbonLayerDocker* widget = new KarbonLayerDocker(); - widget->setObjectName(id()); - - return widget; -} - -KarbonLayerDocker::KarbonLayerDocker() - : m_doc(0), m_model(0), m_updateTimer(this) -{ - setWindowTitle(i18n("Layer view")); - - QWidget *mainWidget = new QWidget(this); - QGridLayout* layout = new QGridLayout(mainWidget); - layout->addWidget(m_layerView = new KoDocumentSectionView(mainWidget), 0, 0, 1, 6); - - QButtonGroup *buttonGroup = new QButtonGroup(mainWidget); - buttonGroup->setExclusive(false); - - QPushButton *button = new QPushButton(mainWidget); - button->setIcon(koIcon("list-add")); - button->setToolTip(i18n("Add a new layer")); - buttonGroup->addButton(button, Button_New); - layout->addWidget(button, 1, 0); - - button = new QPushButton(mainWidget); - button->setIcon(koIcon("list-remove")); - button->setToolTip(i18n("Delete selected objects")); - buttonGroup->addButton(button, Button_Delete); - layout->addWidget(button, 1, 1); - - button = new QPushButton(mainWidget); - button->setIcon(koIcon("go-up")); - button->setToolTip(i18n("Raise selected objects")); - buttonGroup->addButton(button, Button_Raise); - layout->addWidget(button, 1, 2); - - button = new QPushButton(mainWidget); - button->setIcon(koIcon("go-down")); - button->setToolTip(i18n("Lower selected objects")); - buttonGroup->addButton(button, Button_Lower); - layout->addWidget(button, 1, 3); - - QToolButton * toolButton = new QToolButton(mainWidget); - QMenu * menu = new QMenu(this); - QActionGroup *group = new QActionGroup(this); - - m_viewModeActions.insert(KoDocumentSectionView::MinimalMode, - menu->addAction(koIcon("view-list-text"), i18n("Minimal View"), this, SLOT(minimalView()))); - m_viewModeActions.insert(KoDocumentSectionView::DetailedMode, - menu->addAction(koIcon("view-list-details"), i18n("Detailed View"), this, SLOT(detailedView()))); - m_viewModeActions.insert(KoDocumentSectionView::ThumbnailMode, - menu->addAction(koIcon("view-preview"), i18n("Thumbnail View"), this, SLOT(thumbnailView()))); - - foreach(QAction* action, m_viewModeActions) { - action->setCheckable(true); - action->setActionGroup(group); - } - - toolButton->setMenu(menu); - toolButton->setPopupMode(QToolButton::InstantPopup); - toolButton->setIcon(koIcon("view-choose")); - toolButton->setText(i18n("View mode")); - layout->addWidget(toolButton, 1, 5); - layout->setSpacing(0); - layout->setMargin(3); - - setWidget(mainWidget); - - connect(buttonGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotButtonClicked(int))); - - m_model = new KarbonLayerModel(this); - m_model->setDocument(m_doc ? m_doc : 0); - m_sortModel = new KarbonLayerSortingModel(this); - m_sortModel->setDocument(m_doc ? m_doc : 0); - m_sortModel->setSourceModel(m_model); - - m_layerView->setItemsExpandable(true); - m_layerView->setModel(m_sortModel); - m_layerView->setDisplayMode(KoDocumentSectionView::MinimalMode); - m_layerView->setSelectionMode(QAbstractItemView::ExtendedSelection); - m_layerView->setSelectionBehavior(QAbstractItemView::SelectRows); - m_layerView->setDragDropMode(QAbstractItemView::InternalMove); - m_layerView->setSortingEnabled(true); - - KoDocumentSectionView::DisplayMode mode = KoDocumentSectionView::MinimalMode; - KSharedConfigPtr config = KarbonFactory::karbonConfig(); - if (config->hasGroup("Interface")) { - QString modeStr = config->group("Interface").readEntry("LayerDockerMode", "minimal"); - if (modeStr == "detailed") - mode = KoDocumentSectionView::DetailedMode; - else if (modeStr == "thumbnail") - mode = KoDocumentSectionView::ThumbnailMode; - } - setViewMode(mode); - - connect(m_layerView, SIGNAL(clicked(QModelIndex)), this, SLOT(itemClicked(QModelIndex))); - - m_updateTimer.setSingleShot(true); - m_updateTimer.setInterval(250); - connect(&m_updateTimer, SIGNAL(timeout()), m_model, SLOT(update())); -} - -KarbonLayerDocker::~KarbonLayerDocker() -{ - KSharedConfigPtr config = KarbonFactory::karbonConfig(); - QString modeStr; - switch (m_layerView->displayMode()) { - case KoDocumentSectionView::MinimalMode: - modeStr = "minimal"; - break; - case KoDocumentSectionView::DetailedMode: - modeStr = "detailed"; - break; - case KoDocumentSectionView::ThumbnailMode: - modeStr = "thumbnail"; - break; - } - config->group("Interface").writeEntry("LayerDockerMode", modeStr); -} - -void KarbonLayerDocker::updateView() -{ - if (m_updateTimer.isActive()) - return; - - m_updateTimer.start(); -} - -void KarbonLayerDocker::setCanvas(KoCanvasBase* canvas) -{ - KarbonCanvas *c = dynamic_cast(canvas); - if (c) { - m_doc = c->document(); - m_sortModel->setDocument(m_doc ? m_doc : 0); - m_model->setDocument(m_doc ? m_doc : 0); - m_model->update(); - } -} - -void KarbonLayerDocker::unsetCanvas() -{ - m_doc = 0; - m_sortModel->setDocument(0); - m_model->setDocument(0); - m_model->update(); -} - -//Adapt code and connect okbutton or other to new slot. It doesn't exist in qdialog -void KarbonLayerDocker::slotButtonClicked(int buttonId) -{ - switch (buttonId) { - case Button_New: - addLayer(); - break; - case Button_Raise: - raiseItem(); - break; - case Button_Lower: - lowerItem(); - break; - case Button_Delete: - deleteItem(); - break; - } -} - -void KarbonLayerDocker::itemClicked(const QModelIndex &index) -{ - KoShape *shape = shapeFromIndex(index); - if (! shape) - return; - - KoCanvasController * canvasController = KoToolManager::instance()->activeCanvasController(); - if (! canvasController) - return; - - KoSelection *selection = canvasController->canvas()->shapeManager()->selection(); - if (! selection) - return; - - KoShapeLayer * layer = dynamic_cast(shape); - if (layer) { - selection->setActiveLayer(layer); - return; - } - - QList selectedLayers; - QList selectedShapes; - - // separate selected layers and selected shapes - extractSelectedLayersAndShapes(selectedLayers, selectedShapes); - - foreach(KoShape* shape, selection->selectedShapes()) - shape->update(); - - selection->deselectAll(); - - foreach(KoShape* shape, selectedShapes) { - if (shape) { - selection->select(shape, false); - shape->update(); - } - } -} - -void KarbonLayerDocker::addLayer() -{ - bool ok = true; - QString name = QInputDialog::getText(this, - i18n("New Layer"), - i18n("Enter the name of the new layer:"), - QLineEdit::Normal, - i18n("New layer"), &ok); - if (ok) { - KoShapeLayer* layer = new KoShapeLayer(); - layer->setName(name); - KoCanvasController* canvasController = KoToolManager::instance()->activeCanvasController(); - KUndo2Command *cmd = new KoShapeCreateCommand(m_doc, layer, 0); - cmd->setText(kundo2_i18n("Create Layer")); - canvasController->canvas()->addCommand(cmd); - m_model->update(); - } -} - -void KarbonLayerDocker::deleteItem() -{ - QList selectedLayers; - QList selectedShapes; - - // separate selected layers and selected shapes - extractSelectedLayersAndShapes(selectedLayers, selectedShapes); - - KUndo2Command *cmd = 0; - - if (selectedLayers.count()) { - if (m_doc->layers().count() > selectedLayers.count()) { - QList deleteShapes; - foreach(KoShapeLayer* layer, selectedLayers) { - deleteShapes += layer->shapes(); - deleteShapes.append(layer); - } - cmd = new KoShapeDeleteCommand(m_doc, deleteShapes); - cmd->setText(kundo2_i18n("Delete Layer")); - } else { - KMessageBox::error(0L, i18n("Could not delete all layers. At least one layer is required."), i18n("Error deleting layers")); - } - } else if (selectedShapes.count()) { - cmd = new KoShapeDeleteCommand(m_doc, selectedShapes); - } - - if (cmd) { - KoCanvasController* canvasController = KoToolManager::instance()->activeCanvasController(); - canvasController->canvas()->addCommand(cmd); - m_model->update(); - } -} - -void KarbonLayerDocker::raiseItem() -{ - QList selectedLayers; - QList selectedShapes; - - // separate selected layers and selected shapes - extractSelectedLayersAndShapes(selectedLayers, selectedShapes, true); - - KoCanvasBase* canvas = KoToolManager::instance()->activeCanvasController()->canvas(); - - KUndo2Command *cmd = 0; - - if (selectedLayers.count()) { - // check if all layers could be raised - foreach(KoShapeLayer* layer, selectedLayers) - if (! m_doc->canRaiseLayer(layer)) - return; - - cmd = new KarbonLayerReorderCommand(m_doc, selectedLayers, KarbonLayerReorderCommand::RaiseLayer); - } else if (selectedShapes.count()) { - cmd = KoShapeReorderCommand::createCommand(selectedShapes, canvas->shapeManager(), KoShapeReorderCommand::RaiseShape); - } - - if (cmd) { - canvas->addCommand(cmd); - m_model->update(); - - // adjust layer selection - if (selectedLayers.count()) { - selectLayers(selectedLayers); - } - } -} - -void KarbonLayerDocker::lowerItem() -{ - QList selectedLayers; - QList selectedShapes; - - // separate selected layers and selected shapes - extractSelectedLayersAndShapes(selectedLayers, selectedShapes, true); - - KoCanvasBase* canvas = KoToolManager::instance()->activeCanvasController()->canvas(); - - KUndo2Command *cmd = 0; - - if (selectedLayers.count()) { - // check if all layers could be raised - foreach(KoShapeLayer* layer, selectedLayers) - if (! m_doc->canLowerLayer(layer)) - return; - - cmd = new KarbonLayerReorderCommand(m_doc, selectedLayers, KarbonLayerReorderCommand::LowerLayer); - } else if (selectedShapes.count()) { - cmd = KoShapeReorderCommand::createCommand(selectedShapes, canvas->shapeManager(), KoShapeReorderCommand::LowerShape); - } - - if (cmd) { - canvas->addCommand(cmd); - m_model->update(); - - // adjust layer selection - if (selectedLayers.count()) { - selectLayers(selectedLayers); - } - } -} - -void KarbonLayerDocker::selectLayers(const QList &layers) -{ - QItemSelectionModel * selModel = m_layerView->selectionModel(); - selModel->clearSelection(); - foreach(KoShapeLayer * layer, layers) { - int layerPos = m_doc->layerPos(layer); - QModelIndex child = m_model->index(layerPos, 0); - selModel->select(m_sortModel->mapFromSource(child), QItemSelectionModel::Select); - } -} - -void KarbonLayerDocker::extractSelectedLayersAndShapes( - QList &layers, QList &shapes, bool addChilds) -{ - layers.clear(); - shapes.clear(); - - QModelIndexList selectedItems = m_layerView->selectionModel()->selectedIndexes(); - if (selectedItems.count() == 0) - return; - - // separate selected layers and selected shapes - foreach(const QModelIndex & index, selectedItems) { - KoShape *shape = shapeFromIndex(index); - KoShapeLayer *layer = dynamic_cast(shape); - if (layer) { - layers.append(layer); - } else if (! selectedItems.contains(index.parent())) { - shapes.append(shape); - KoShapeGroup * group = dynamic_cast(shape); - if (group && addChilds) - addChildsRecursive(group, shapes); - } - } -} - -void KarbonLayerDocker::addChildsRecursive(KoShapeGroup * parent, QList &shapes) -{ - foreach(KoShape * child, parent->shapes()) { - if (! shapes.contains(child)) - shapes.append(child); - KoShapeGroup * group = dynamic_cast(child); - if (group) - addChildsRecursive(group, shapes); - } -} - -KoShape * KarbonLayerDocker::shapeFromIndex(const QModelIndex &index) -{ - Q_ASSERT(index.internalPointer()); - - QModelIndex sourceIndex = index; - if (index.model() != m_model) - sourceIndex = m_sortModel->mapToSource(index); - - if (! sourceIndex.isValid()) - return 0; - - return static_cast(sourceIndex.internalPointer()); -} - -void KarbonLayerDocker::minimalView() -{ - setViewMode(KoDocumentSectionView::MinimalMode); -} - -void KarbonLayerDocker::detailedView() -{ - setViewMode(KoDocumentSectionView::DetailedMode); -} - -void KarbonLayerDocker::thumbnailView() -{ - setViewMode(KoDocumentSectionView::ThumbnailMode); -} - -void KarbonLayerDocker::setViewMode(KoDocumentSectionView::DisplayMode mode) -{ - const bool expandable = (mode != KoDocumentSectionView::ThumbnailMode); - - // collapse all layers if in thumbnail mode - if (!expandable) - m_layerView->collapseAll(); - - m_layerView->setDisplayMode(mode); - m_layerView->setItemsExpandable(expandable); - m_layerView->setRootIsDecorated(expandable); - m_layerView->setSortingEnabled(true); - m_viewModeActions[mode]->setChecked(true); -} - - -// kate: replace-tabs on; space-indent on; indent-width 4; mixedindent off; indent-mode cstyle; diff --git a/karbon/ui/dockers/KarbonLayerModel.h b/karbon/ui/dockers/KarbonLayerModel.h deleted file mode 100644 --- a/karbon/ui/dockers/KarbonLayerModel.h +++ /dev/null @@ -1,81 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2007-2008 Jan Hambrecht - * - * 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 KARBONLAYERMODEL_H -#define KARBONLAYERMODEL_H - -#include - -#include - -class KarbonDocument; -class KoShape; -class KoShapeContainer; -class QAbstractItemModel; - -class KarbonLayerModel : public KoDocumentSectionModel -{ - Q_OBJECT - -public: - /// Constructs a new layer model using the specified documents data - explicit KarbonLayerModel(QObject *parent = 0); - - /// Sets a new document to show contents of - void setDocument(KarbonDocument * newDocument); - - // from QAbstractItemModel - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; - virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; - virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; - virtual QModelIndex parent(const QModelIndex &child) const; - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - virtual Qt::ItemFlags flags(const QModelIndex &index) const; - virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); - virtual Qt::DropActions supportedDropActions() const; - virtual QStringList mimeTypes() const; - virtual QMimeData * mimeData(const QModelIndexList & indexes) const; - virtual bool dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent); - virtual Qt::DropActions supportedDragActions() const; - -public Q_SLOTS: - /// Triggers an update of the complete model - void update(); - -private: - /// Returns properties of the given shape - PropertyList properties(KoShape* shape) const; - /// Sets the properties on the given shape - void setProperties(KoShape* shape, const PropertyList &properties); - /// Creates a thumbnail image with the specified size from the given shape - QImage createThumbnail(KoShape* shape, const QSize &thumbSize) const; - /// Returns the child shape with the given index from the parent shape - KoShape * childFromIndex(KoShapeContainer *parent, int row) const; - /// Returns the zero based index of a child shape within its parent shape - int indexFromChild(KoShapeContainer *parent, KoShape *child) const; - /// Returns the parent model index from the given child shape - QModelIndex parentIndexFromShape(const KoShape * child) const; - - /// Recursively locks children of the specified shape container - void lockRecursively(KoShapeContainer *container, bool lock); - - QPointer m_document; ///< the underlying data structure -}; - -#endif // KARBONLAYERMODEL_H diff --git a/karbon/ui/dockers/KarbonLayerModel.cpp b/karbon/ui/dockers/KarbonLayerModel.cpp deleted file mode 100644 --- a/karbon/ui/dockers/KarbonLayerModel.cpp +++ /dev/null @@ -1,535 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2007-2008,2011 Jan Hambrecht - * - * 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 "KarbonLayerModel.h" - -#include "KarbonUiDebug.h" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -KoShapeContainer *shapeToContainer(KoShape *shape) -{ - KoShapeGroup *group = dynamic_cast(shape); - if (group) - return group; - KoShapeLayer *layer = dynamic_cast(shape); - if (layer) - return layer; - - return 0; -} - -KarbonLayerModel::KarbonLayerModel(QObject * parent) - : KoDocumentSectionModel(parent), m_document(0) -{ -} - -Qt::DropActions KarbonLayerModel::supportedDragActions() const -{ - return Qt::MoveAction; -} - -void KarbonLayerModel::update() -{ - emit layoutAboutToBeChanged(); - emit layoutChanged(); -} - -void KarbonLayerModel::setDocument(KarbonDocument * newDocument) -{ - beginResetModel(); - m_document = newDocument; - endResetModel(); -} - -int KarbonLayerModel::rowCount(const QModelIndex &parent) const -{ - if (! m_document) - return 0; - - // check if parent is root node - if (! parent.isValid()) - return m_document->layers().count(); - - Q_ASSERT(parent.model() == this); - Q_ASSERT(parent.internalPointer()); - - KoShapeContainer *parentShape = shapeToContainer((KoShape*)parent.internalPointer()); - if (! parentShape) - return 0; - - return parentShape->shapeCount(); -} - -int KarbonLayerModel::columnCount(const QModelIndex &) const -{ - if (! m_document) - return 0; - else - return 1; -} - -QModelIndex KarbonLayerModel::index(int row, int column, const QModelIndex &parent) const -{ - if (! m_document) - return QModelIndex(); - - // check if parent is root node - if (! parent.isValid()) { - if (row >= 0 && row < m_document->layers().count()) - return createIndex(row, column, m_document->layers().at(row)); - else - return QModelIndex(); - } - - Q_ASSERT(parent.model() == this); - Q_ASSERT(parent.internalPointer()); - - KoShapeContainer *parentShape = shapeToContainer((KoShape*)parent.internalPointer()); - if (! parentShape) - return QModelIndex(); - - if (row < parentShape->shapeCount()) - return createIndex(row, column, childFromIndex(parentShape, row)); - else - return QModelIndex(); -} - -QModelIndex KarbonLayerModel::parent(const QModelIndex &child) const -{ - // check if child is root node - if (! m_document || ! child.isValid()) - return QModelIndex(); - - Q_ASSERT(child.model() == this); - Q_ASSERT(child.internalPointer()); - - KoShape *childShape = static_cast(child.internalPointer()); - if (! childShape) - return QModelIndex(); - - return parentIndexFromShape(childShape); -} - -QVariant KarbonLayerModel::data(const QModelIndex &index, int role) const -{ - if (! index.isValid()) - return QVariant(); - - Q_ASSERT(index.model() == this); - Q_ASSERT(index.internalPointer()); - - KoShape *shape = static_cast(index.internalPointer()); - - switch (role) { - case Qt::DisplayRole: { - QString name = shape->name(); - if (name.isEmpty()) { - if (dynamic_cast(shape)) - name = i18n("Layer"); - else if (dynamic_cast(shape)) - name = i18nc("A group of shapes", "Group"); - else - name = i18n("Shape"); - } - return name; - } - case Qt::DecorationRole: - return QVariant(); - case Qt::EditRole: - return shape->name(); - case Qt::SizeHintRole: - return shape->size(); - case ActiveRole: { - KoCanvasController * canvasController = KoToolManager::instance()->activeCanvasController(); - KoSelection * selection = canvasController->canvas()->shapeManager()->selection(); - if (! selection) - return false; - - KoShapeLayer *layer = dynamic_cast(shape); - if (layer) - return (layer == selection->activeLayer()); - else - return selection->isSelected(shape); - } - case PropertiesRole: - return QVariant::fromValue(properties(shape)); - case AspectRatioRole: { - QTransform matrix = shape->absoluteTransformation(0); - QRectF bbox = matrix.mapRect(shape->outline().boundingRect()); - KoShapeContainer *container = dynamic_cast(shape); - if (container) { - bbox = QRectF(); - foreach(KoShape* shape, container->shapes()) { - bbox = bbox.united(shape->outline().boundingRect()); - } - } - return qreal(bbox.width()) / bbox.height(); - } - default: - if (role >= int(BeginThumbnailRole)) - return createThumbnail(shape, QSize(role - int(BeginThumbnailRole), role - int(BeginThumbnailRole))); - else - return QVariant(); - } -} - -Qt::ItemFlags KarbonLayerModel::flags(const QModelIndex &index) const -{ - if (! index.isValid()) - return 0; - - Q_ASSERT(index.model() == this); - Q_ASSERT(index.internalPointer()); - - Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEditable; - //if( dynamic_cast( (KoShape*)index.internalPointer() ) ) - flags |= Qt::ItemIsDropEnabled; - return flags; -} - -bool KarbonLayerModel::setData(const QModelIndex &index, const QVariant &value, int role) -{ - if (! index.isValid()) - return false; - - Q_ASSERT(index.model() == this); - Q_ASSERT(index.internalPointer()); - - KoShape *shape = static_cast(index.internalPointer()); - switch (role) { - case Qt::DisplayRole: - case Qt::EditRole: - shape->setName(value.toString()); - break; - case PropertiesRole: - setProperties(shape, value.value()); - // fall through - case ActiveRole: { - KoCanvasController * canvasController = KoToolManager::instance()->activeCanvasController(); - KoSelection * selection = canvasController->canvas()->shapeManager()->selection(); - - KoShapeLayer *layer = dynamic_cast(shape); - if (layer && selection) - selection->setActiveLayer(layer); - } - break; - default: - return false; - } - - emit dataChanged(index, index); - return true; -} - -KoDocumentSectionModel::PropertyList KarbonLayerModel::properties(KoShape* shape) const -{ - PropertyList l; - l << Property(i18nc("Visibility state of the shape", "Visible"), koIcon("layer-visible-on"), koIcon("layer-visible-off"), shape->isVisible()); - l << Property(i18nc("Lock state of the shape", "Locked"), koIcon("object-locked"), koIcon("object-unlocked"), shape->isGeometryProtected()); - l << Property(i18nc("The z-index of the shape", "zIndex"), QString("%1").arg(shape->zIndex())); - l << Property(i18nc("The opacity of the shape", "Opacity"), QString("%1").arg(1.0 - shape->transparency())); - l << Property(i18nc("Clipped state of the shape", "Clipped"), shape->clipPath() ? i18n("yes") : i18n("no")); - return l; -} - -void KarbonLayerModel::setProperties(KoShape* shape, const PropertyList &properties) -{ - bool oldVisibleState = shape->isVisible(); - bool oldLockedState = shape->isGeometryProtected(); - bool newVisibleState = properties.at(0).state.toBool(); - bool newLockedState = properties.at(1).state.toBool(); - - shape->setVisible(newVisibleState); - shape->setGeometryProtected(newLockedState); - - KoShapeContainer * container = dynamic_cast(shape); - if (container) - lockRecursively(container, newLockedState); - else - shape->setSelectable(!newLockedState); - - if ((oldVisibleState != shape->isVisible()) || (oldLockedState != shape->isGeometryProtected())) - shape->update(); -} - -void KarbonLayerModel::lockRecursively(KoShapeContainer *container, bool lock) -{ - if (!container) - return; - - if (!lock) { - container->setSelectable(!container->isGeometryProtected()); - } else { - container->setSelectable(!lock); - } - - foreach(KoShape *shape, container->shapes()) { - KoShapeContainer * shapeContainer = dynamic_cast(shape); - if (shapeContainer) { - lockRecursively(shapeContainer, lock); - } else { - if (!lock) { - shape->setSelectable(!shape->isGeometryProtected()); - } else { - shape->setSelectable(!lock); - } - } - } -} - -QImage KarbonLayerModel::createThumbnail(KoShape* shape, const QSize &thumbSize) const -{ - KoShapePainter painter; - - QList shapes; - - shapes.append(shape); - KoShapeContainer * container = dynamic_cast(shape); - if (container) - shapes.append(container->shapes()); - - painter.setShapes(shapes); - - QImage thumb(thumbSize, QImage::Format_RGB32); - // draw the background of the thumbnail - thumb.fill(QColor(Qt::white).rgb()); - - QRect imageRect = thumb.rect(); - // use 2 pixel border around the content - imageRect.adjust(2, 2, -2, -2); - - QPainter p(&thumb); - painter.paint(p, imageRect, painter.contentRect()); - - return thumb; -} - -KoShape * KarbonLayerModel::childFromIndex(KoShapeContainer *parent, int row) const -{ - return parent->shapes().at(row); -} - -int KarbonLayerModel::indexFromChild(KoShapeContainer *parent, KoShape *child) const -{ - return parent->shapes().indexOf(child); -} - -Qt::DropActions KarbonLayerModel::supportedDropActions() const -{ - return Qt::MoveAction | Qt::CopyAction; -} - -QStringList KarbonLayerModel::mimeTypes() const -{ - QStringList types; - types << QLatin1String("application/x-karbonlayermodeldatalist"); - return types; -} - -QMimeData * KarbonLayerModel::mimeData(const QModelIndexList & indexes) const -{ - // check if there is data to encode - if (! indexes.count()) - return 0; - - // check if we support a format - QStringList types = mimeTypes(); - if (types.isEmpty()) - return 0; - - QMimeData *data = new QMimeData(); - QString format = types[0]; - QByteArray encoded; - QDataStream stream(&encoded, QIODevice::WriteOnly); - - // encode the data - QModelIndexList::ConstIterator it = indexes.begin(); - for (; it != indexes.end(); ++it) - stream << QVariant::fromValue(qulonglong(it->internalPointer())); - - data->setData(format, encoded); - return data; -} - -bool KarbonLayerModel::dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent) -{ - Q_UNUSED(row); - Q_UNUSED(column); - - // check if the action is supported - if (! data || action != Qt::MoveAction) - return false; - // check if the format is supported - QStringList types = mimeTypes(); - if (types.isEmpty()) - return false; - QString format = types[0]; - if (! data->hasFormat(format)) - return false; - - QByteArray encoded = data->data(format); - QDataStream stream(&encoded, QIODevice::ReadOnly); - QList shapes; - - // decode the data - while (! stream.atEnd()) { - QVariant v; - stream >> v; - shapes.append(static_cast((void*)v.value())); - } - - // no shapes to drop, exit gracefully - if (shapes.count() == 0) - return false; - - QList toplevelShapes; - QList layers; - // remove shapes having its parent in the list - // and separate the layers - foreach(KoShape * shape, shapes) { - KoShapeContainer * parent = shape->parent(); - bool hasParentInList = false; - while (parent) { - if (shapes.contains(parent)) { - hasParentInList = true; - break; - } - parent = parent->parent(); - } - if (hasParentInList) - continue; - - KoShapeLayer * layer = dynamic_cast(shape); - if (layer) - layers.append(layer); - else - toplevelShapes.append(shape); - } - - if (! parent.isValid()) { - debugKarbonUi << "KarbonLayerModel::dropMimeData parent = root"; - return false; - } - KoShape *shape = static_cast(parent.internalPointer()); - KoShapeContainer * container = dynamic_cast(shape); - if (container) { - KoShapeGroup * group = dynamic_cast(container); - KoShapeLayer * layer = dynamic_cast(container); - if (layer && layers.count()) { - debugKarbonUi << "dropping layer on a layer (not implemented yet)"; - // TODO layers are dropped on a layer, so change layer ordering - return false; - } else if (group || layer) { - debugKarbonUi << "dropping on group or layer"; - if (! toplevelShapes.count()) - return false; - - emit layoutAboutToBeChanged(); - - beginInsertRows(parent, container->shapeCount(), container->shapeCount() + toplevelShapes.count()); - - KUndo2Command * cmd = new KUndo2Command(); - cmd->setText(kundo2_i18n("Reparent shapes")); - - QList clipped, inheritTransform; - foreach(KoShape * shape, toplevelShapes) { - new KoShapeUngroupCommand(shape->parent(), QList() << shape, QList(), cmd); - clipped.append(false); - inheritTransform.append(false); - } - - if (group) { - new KoShapeGroupCommand(group, toplevelShapes, cmd); - } else if (layer) { - new KoShapeGroupCommand(layer, toplevelShapes, clipped, inheritTransform, cmd); - } - KoCanvasController * canvasController = KoToolManager::instance()->activeCanvasController(); - canvasController->canvas()->addCommand(cmd); - - endInsertRows(); - - emit layoutChanged(); - } else { - debugKarbonUi << "dropping on unhandled container (" << container->shapeId() << ")"; - // every other container we don't want to handle - return false; - } - } else { - debugKarbonUi << "KarbonLayerModel::dropMimeData parent = shape"; - if (! toplevelShapes.count()) - return false; - - // TODO shapes are dropped on a shape, reorder them - return false; - } - - return true; -} - -QModelIndex KarbonLayerModel::parentIndexFromShape(const KoShape * child) const -{ - if (! m_document) - return QModelIndex(); - - // check if child shape is a layer, and return invalid model index if it is - const KoShapeLayer *childlayer = dynamic_cast(child); - if (childlayer) - return QModelIndex(); - - // get the children's parent shape - KoShapeContainer *parentShape = child->parent(); - if (! parentShape) - return QModelIndex(); - - // check if the parent is a layer - KoShapeLayer *parentLayer = dynamic_cast(parentShape); - if (parentLayer) - return createIndex(m_document->layers().indexOf(parentLayer), 0, parentShape); - - // get the grandparent to determine the row of the parent shape - KoShapeContainer *grandParentShape = parentShape->parent(); - if (! grandParentShape) - return QModelIndex(); - - return createIndex(indexFromChild(grandParentShape, parentShape), 0, parentShape); -} - - -// kate: replace-tabs on; space-indent on; indent-width 4; mixedindent off; indent-mode cstyle; diff --git a/karbon/ui/dockers/KarbonLayerSortingModel.cpp b/karbon/ui/dockers/KarbonLayerSortingModel.cpp deleted file mode 100644 --- a/karbon/ui/dockers/KarbonLayerSortingModel.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* This file is part of the KDE project - * Copyright (C) 2008-2009 Jan Hambrecht - * - * 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 "KarbonLayerSortingModel.h" -#include "KarbonDocument.h" -#include -#include -#include - -KarbonLayerSortingModel::KarbonLayerSortingModel(QObject * parent) - : QSortFilterProxyModel(parent) - , m_document(0) -{ - setDynamicSortFilter(true); - // in qt-4.5.1 there was a bug (254234) preventing sorting to be enabled - // so we explicitly trigger the sorting before setting the source model - sort(0, Qt::DescendingOrder); -} - -void KarbonLayerSortingModel::setDocument(KarbonDocument * newDocument) -{ - m_document = newDocument; - invalidate(); -} - -bool KarbonLayerSortingModel::lessThan(const QModelIndex &left, const QModelIndex &right) const -{ - KoShape * leftShape = static_cast(left.internalPointer()); - KoShape * rightShape = static_cast(right.internalPointer()); - - if (! leftShape || ! rightShape) - return false; - - if (m_document) { - KoShapeLayer * leftLayer = dynamic_cast(leftShape); - KoShapeLayer * rightLayer = dynamic_cast(rightShape); - if (leftLayer && rightLayer) { - return m_document->layerPos(leftLayer) < m_document->layerPos(rightLayer); - } else { - if (leftShape->zIndex() == rightShape->zIndex()) { - KoShapeContainer * leftParent = leftShape->parent(); - KoShapeContainer * rightParent = rightShape->parent(); - if (leftParent && leftParent == rightParent) { - QList children = leftParent->shapes(); - return children.indexOf(leftShape) < children.indexOf(rightShape); - } else { - return leftShape < rightShape; - } - } else { - return leftShape->zIndex() < rightShape->zIndex(); - } - } - } else { - if (leftShape->zIndex() == rightShape->zIndex()) - return leftShape < rightShape; - else - return leftShape->zIndex() < rightShape->zIndex(); - } -} - diff --git a/karbon/ui/widgets/KarbonCanvas.h b/karbon/ui/widgets/KarbonCanvas.h deleted file mode 100644 --- a/karbon/ui/widgets/KarbonCanvas.h +++ /dev/null @@ -1,173 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001-2002 Lennart Kudling - Copyright (C) 2001-2003 Rob Buis - Copyright (C) 2003 Dirk Mueller - Copyright (C) 2005 Laurent Montel - Copyright (C) 2005-2007 Thomas Zander - Copyright (C) 2006-2007 Jan Hambrecht - Copyright (C) 2006 Tim Beaulen - Copyright (C) 2006 Sven Langkamp - Copyright (C) 2006 Boudewijn Rempt - Copyright (C) 2006 Thorsten Zachmann - Copyright (C) 2006 C. Boemann - Copyright (C) 2006 Peter Simonsson - Copyright (C) 2007 David Faure - - 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 KARBONCANVAS_H -#define KARBONCANVAS_H - -#include - -#include - -#include -#include - -class KarbonDocument; -class KoViewConverter; -class KoShapeManager; -class KoToolProxy; -class QRectF; -class QPainter; -class QPaintEvent; -class QWheelEvent; -class QTabletEvent; -class QResizeEvent; - -class KarbonCanvas: public QWidget, public KoCanvasBase -{ - Q_OBJECT - -public: - explicit KarbonCanvas(KarbonDocument *p); - virtual ~KarbonCanvas(); - - /// reimplemented from KoCanvasBase - virtual void gridSize(qreal *horizontal, qreal *vertical) const; - /// reimplemented from KoCanvasBase - virtual bool snapToGrid() const; - /// reimplemented from KoCanvasBase - virtual KoUnit unit() const; - /// reimplemented from KoCanvasBase - void addCommand(KUndo2Command *command); - /// reimplemented from KoCanvasBase - KoShapeManager *shapeManager() const; - /// reimplemented from KoCanvasBase - KoViewConverter *viewConverter() const; - /// reimplemented from KoCanvasBase - KoToolProxy * toolProxy() const; - /// reimplemented from KoCanvasBase - virtual QPoint documentOrigin() const; - /// reimplemented from KoCanvasBase - QWidget *canvasWidget(); - /// reimplemented from KoCanvasBase - const QWidget *canvasWidget() const; - /// reimplemented from KoCanvasBase - void updateCanvas(const QRectF& rc); - /// reimplemented from KoCanvasBase - virtual void updateInputMethodInfo(); - /// reimplemented from KoCanvasBase - virtual KoGuidesData * guidesData(); - virtual void setCursor(const QCursor &cursor); - /// Enables/disables showing page margins - void setShowPageMargins(bool on); - - /** - * Sets the viewing margin around the document in pt - * @param margin the viewing margin around the document - */ - void setDocumentViewMargin(int margin); - - /// Returns the viewing margin around the document - int documentViewMargin() const; - - /** - * Returns the document bounding rect with the viewing margin applied. - * The rect is returned in pt. - * @return the document bounding rect with viewing margins applied. - */ - QRectF documentViewRect(); - - /// Sets the canvas background color to the given color - void setBackgroundColor(const QColor &color); - - /// @return the offset of the document in canvas position. - const QPoint &documentOffset() const; - - /// @return the document used by the canvas. - KarbonDocument *document() const; - -public Q_SLOTS: - - /** - * Tell the canvas that it has to adjust its document origin. - * The new origin depends on the current document size, the actual zoom factor - * and the actual canvas size. - */ - void adjustOrigin(); - void setDocumentOffset(const QPoint &offset); - - /// Enables/disables outline painting mode - void enableOutlineMode(bool on); - -Q_SIGNALS: - - /** - * This signal is emitted when the document origin has changed. - * The document origin is the point (in pixel) on the virtual - * canvas where the documents origin (0,0) or the top left - * corner of the page is. - */ - void documentOriginChanged(const QPoint &origin); - -protected: - bool event(QEvent *); - void paintEvent(QPaintEvent * ev); - void mouseEvent(QMouseEvent *e); - void mouseReleaseEvent(QMouseEvent *e); - void keyReleaseEvent(QKeyEvent *e); - void keyPressEvent(QKeyEvent *e); - void mouseMoveEvent(QMouseEvent *e); - void mousePressEvent(QMouseEvent *e); - void mouseDoubleClickEvent(QMouseEvent *e); - void tabletEvent(QTabletEvent *e); - void wheelEvent(QWheelEvent *e); - void resizeEvent(QResizeEvent *e); - /// reimplemented method from superclass - virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const; - /// reimplemented method from superclass - virtual void inputMethodEvent(QInputMethodEvent *event); - - QPoint widgetToView(const QPoint& p) const; - QRect widgetToView(const QRect& r) const; - QPoint viewToWidget(const QPoint& p) const; - QRect viewToWidget(const QRect& r) const; - -private Q_SLOTS: - void updateSizeAndOffset(); - -private: - /// paint page margins - void paintMargins(QPainter &painter, const KoViewConverter &converter); - - class KarbonCanvasPrivate; - KarbonCanvasPrivate * const d; -}; - -#endif // KARBONCANVAS_H diff --git a/karbon/ui/widgets/KarbonCanvas.cpp b/karbon/ui/widgets/KarbonCanvas.cpp deleted file mode 100644 --- a/karbon/ui/widgets/KarbonCanvas.cpp +++ /dev/null @@ -1,469 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001-2002 Lennart Kudling - Copyright (C) 2001-2002 Rob Buis - Copyright (C) 2002-2004, 2006 Laurent Montel - Copyright (C) 2002 Benoit Vautrin - Copyright (C) 2004 Waldo Bastian - Copyright (C) 2004-2005 David Faure - Copyright (C) 2005-2006 Tim Beaulen - Copyright (C) 2007 Thomas Zander - Copyright (C) 2005-2007 Jan Hambrecht - Copyright (C) 2006 Peter Simonsson - Copyright (C) 2006 C. Boemann - Copyright (C) 2006 Thorsten Zachmann - Copyright (C) 2010 Boudewijn Rempt - - 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 "KarbonCanvas.h" -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -class KarbonCanvas::KarbonCanvasPrivate { -public: - KarbonCanvasPrivate() - : zoomHandler() - , part(0) - , showMargins(false) - , documentOffset(0, 0) - , viewMargin(100) - { - pixelGrid.setGrid(1.0, 1.0); - pixelGrid.setShowGrid(true); - } - - ~KarbonCanvasPrivate() { - delete toolProxy; - toolProxy = 0; - delete shapeManager; - } - - KoShapeManager* shapeManager; - KoZoomHandler zoomHandler; - - KoToolProxy *toolProxy; - - KarbonDocument *part; - QPoint origin; ///< the origin of the document page rect - bool showMargins; ///< should page margins be shown - QPoint documentOffset; ///< the offset of the virtual canvas from the viewport - int viewMargin; ///< the view margin around the document in pixels - QRectF documentViewRect; ///< the last calculated document view rect - KoGridData pixelGrid; ///< pixel grid data -}; - -KarbonCanvas::KarbonCanvas(KarbonDocument *p) - : QWidget() , KoCanvasBase(p), d(new KarbonCanvasPrivate()) -{ - d->part = p; - d->toolProxy = new KoToolProxy(this); - d->shapeManager = new KoShapeManager(this, d->part->shapes()); - connect(d->shapeManager, SIGNAL(selectionChanged()), this, SLOT(updateSizeAndOffset())); - - setBackgroundRole(QPalette::Base); - setAutoFillBackground(true); - setBackgroundColor(Qt::white); - setMouseTracking(true); - setFocusPolicy(Qt::StrongFocus); // allow to receive keyboard input - updateSizeAndOffset(); - setAttribute(Qt::WA_InputMethodEnabled, true); - setAttribute(Qt::WA_AcceptTouchEvents, true); -} - -KarbonCanvas::~KarbonCanvas() -{ - delete d; -} - -KoShapeManager * KarbonCanvas::shapeManager() const -{ - return d->shapeManager; -} - -KoViewConverter * KarbonCanvas::viewConverter() const -{ - return &d->zoomHandler; -} - -KoToolProxy * KarbonCanvas::toolProxy() const -{ - return d->toolProxy; -} - -QWidget * KarbonCanvas::canvasWidget() -{ - return this; -} - -const QWidget * KarbonCanvas::canvasWidget() const -{ - return this; -} - -bool KarbonCanvas::event(QEvent *e) -{ - if(toolProxy()) { - - if (e->type() == QEvent::TouchBegin || - e->type() == QEvent::TouchUpdate || - e->type() == QEvent::TouchEnd) { - toolProxy()->touchEvent(dynamic_cast(e)); - } - - toolProxy()->processEvent(e); - } - return QWidget::event(e); -} - -void KarbonCanvas::paintEvent(QPaintEvent * ev) -{ - QPainter painter(this); - painter.translate(-d->documentOffset); - - QRect clipRect = ev->rect().translated(d->documentOffset); - painter.setClipRect(clipRect); - - painter.translate(d->origin.x(), d->origin.y()); - painter.setPen(QPen(Qt::black, 0)); - - // paint the page rect - painter.drawRect(d->zoomHandler.documentToView(QRectF(QPointF(0.0, 0.0), d->part->pageSize()))); - - // paint the page margins - paintMargins(painter, d->zoomHandler); - - // get the cliprect in document coordinates - QRectF updateRect = d->zoomHandler.viewToDocument(widgetToView(clipRect)); - - // paint the shapes - painter.setRenderHint(QPainter::Antialiasing); - d->shapeManager->paint(painter, d->zoomHandler, false); - - // paint the grid and guides - painter.setRenderHint(QPainter::Antialiasing, false); - // check how big a single point is and paint a pixel grid if big enough - const qreal pointSize = d->zoomHandler.zoomItX(1.0); - if (pointSize > 10.0 && d->part->gridData().showGrid()) { - // set a slightly lighter color than the current grid color - d->pixelGrid.setGridColor(d->part->gridData().gridColor().lighter(110)); - d->pixelGrid.paintGrid(painter, d->zoomHandler, updateRect); - } - d->part->gridData().paintGrid(painter, d->zoomHandler, updateRect); - d->part->guidesData().paintGuides(painter, d->zoomHandler, updateRect); - - // paint the tool decorations - painter.setRenderHint(QPainter::Antialiasing); - d->toolProxy->paint(painter, d->zoomHandler); - - painter.end(); -} - -void KarbonCanvas::paintMargins(QPainter &painter, const KoViewConverter &converter) -{ - if (! d->showMargins) - return; - - KoPageLayout pl = d->part->pageLayout(); - - QSizeF pageSize = d->part->pageSize(); - QRectF marginRect(pl.leftMargin, pl.topMargin, - pageSize.width() - pl.leftMargin - pl.rightMargin, - pageSize.height() - pl.topMargin - pl.bottomMargin); - - QPen pen(Qt::blue, 0); - QVector pattern; - pattern << 5 << 5; - pen.setDashPattern(pattern); - painter.setPen(pen); - painter.drawRect(converter.documentToView(marginRect)); -} - -void KarbonCanvas::mouseMoveEvent(QMouseEvent *e) -{ - d->toolProxy->mouseMoveEvent(e, d->zoomHandler.viewToDocument(widgetToView(e->pos() + d->documentOffset))); -} - -void KarbonCanvas::mousePressEvent(QMouseEvent *e) -{ - d->toolProxy->mousePressEvent(e, d->zoomHandler.viewToDocument(widgetToView(e->pos() + d->documentOffset))); - if (!e->isAccepted() && e->button() == Qt::RightButton) { - QList actions = d->toolProxy->popupActionList(); - if (!actions.isEmpty()) { - QMenu menu(this); - foreach(QAction *action, d->toolProxy->popupActionList()) { - menu.addAction(action); - } - menu.exec(e->globalPos()); - } - } - - e->setAccepted(true); -} - -void KarbonCanvas::mouseDoubleClickEvent(QMouseEvent *e) -{ - d->toolProxy->mouseDoubleClickEvent(e, d->zoomHandler.viewToDocument(widgetToView(e->pos() + d->documentOffset))); -} - -void KarbonCanvas::mouseReleaseEvent(QMouseEvent *e) -{ - d->toolProxy->mouseReleaseEvent(e, d->zoomHandler.viewToDocument(widgetToView(e->pos() + d->documentOffset))); -} - -void KarbonCanvas::keyReleaseEvent(QKeyEvent *e) -{ - d->toolProxy->keyReleaseEvent(e); -} - -void KarbonCanvas::keyPressEvent(QKeyEvent *e) -{ - d->toolProxy->keyPressEvent(e); - if (! e->isAccepted()) { - if (e->key() == Qt::Key_Backtab - || (e->key() == Qt::Key_Tab && (e->modifiers() & Qt::ShiftModifier))) - focusNextPrevChild(false); - else if (e->key() == Qt::Key_Tab) - focusNextPrevChild(true); - } -} - -void KarbonCanvas::tabletEvent(QTabletEvent *e) -{ - d->toolProxy->tabletEvent(e, d->zoomHandler.viewToDocument(widgetToView(e->pos() + d->documentOffset))); -} - -void KarbonCanvas::wheelEvent(QWheelEvent *e) -{ - d->toolProxy->wheelEvent(e, d->zoomHandler.viewToDocument(widgetToView(e->pos() + d->documentOffset))); -} - -QVariant KarbonCanvas::inputMethodQuery(Qt::InputMethodQuery query) const -{ - if (query == Qt::ImMicroFocus) { - QRectF rect = (d->toolProxy->inputMethodQuery(query, *(viewConverter())).toRectF()).toRect(); - QPointF scroll(canvasController()->scrollBarValue()); - rect.translate(documentOrigin() - scroll); - return rect.toRect(); - } - return d->toolProxy->inputMethodQuery(query, *(viewConverter())); -} - -void KarbonCanvas::inputMethodEvent(QInputMethodEvent *event) -{ - d->toolProxy->inputMethodEvent(event); -} - -void KarbonCanvas::resizeEvent(QResizeEvent *) -{ - updateSizeAndOffset(); -} - -void KarbonCanvas::gridSize(qreal *horizontal, qreal *vertical) const -{ - if (horizontal) - *horizontal = d->part->gridData().gridX(); - if (vertical) - *vertical = d->part->gridData().gridY(); -} - -bool KarbonCanvas::snapToGrid() const -{ - return d->part->gridData().snapToGrid(); -} - -void KarbonCanvas::addCommand(KUndo2Command *command) -{ - d->part->addCommand(command); - updateSizeAndOffset(); -} - -void KarbonCanvas::updateCanvas(const QRectF& rc) -{ - QRect clipRect(viewToWidget(d->zoomHandler.documentToView(rc).toRect())); - clipRect.adjust(-2, -2, 2, 2); // grow for anti-aliasing - clipRect.moveTopLeft(clipRect.topLeft() - d->documentOffset); - update(clipRect); -} - -void KarbonCanvas::updateSizeAndOffset() -{ - // save the old view rect for comparing - QRectF oldDocumentViewRect = d->documentViewRect; - d->documentViewRect = documentViewRect(); - // check if the view rect has changed and emit signal if it has - if (oldDocumentViewRect != d->documentViewRect) { - QRectF viewRect = d->zoomHandler.documentToView(d->documentViewRect); - KoCanvasController * controller = canvasController(); - if (controller) { - // tell canvas controller the new document size in pixel - controller->updateDocumentSize(viewRect.size().toSize(), true); - // make sure the actual selection is visible - KoSelection * selection = d->shapeManager->selection(); - if (selection->count()) - controller->ensureVisible(d->zoomHandler.documentToView(selection->boundingRect())); - } - } - adjustOrigin(); - update(); -} - -void KarbonCanvas::adjustOrigin() -{ - // calculate the zoomed document bounding rect - QRect documentRect = d->zoomHandler.documentToView(documentViewRect()).toRect(); - - // save the old origin to see if it has changed - QPoint oldOrigin = d->origin; - - // set the origin to the zoom document rect origin - d->origin = -documentRect.topLeft(); - - // the document bounding rect is always centered on the virtual canvas - // if there are margins left around the zoomed document rect then - // distribute them evenly on both sides - int widthDiff = size().width() - documentRect.width(); - if (widthDiff > 0) - d->origin.rx() += qRound(0.5 * widthDiff); - int heightDiff = size().height() - documentRect.height(); - if (heightDiff > 0) - d->origin.ry() += qRound(0.5 * heightDiff); - - // check if the origin has changed and emit signal if it has - if (d->origin != oldOrigin) - emit documentOriginChanged(d->origin); -} - -void KarbonCanvas::setDocumentOffset(const QPoint &offset) -{ - d->documentOffset = offset; -} - -const QPoint &KarbonCanvas::documentOffset() const -{ - return d->documentOffset; -} - -KarbonDocument *KarbonCanvas::document() const -{ - return d->part; -} - -void KarbonCanvas::enableOutlineMode(bool on) -{ - if (on) - new KarbonOutlinePaintingStrategy(d->shapeManager); - else { - d->shapeManager->setPaintingStrategy(new KoShapeManagerPaintingStrategy(d->shapeManager)); - } -} - -QPoint KarbonCanvas::widgetToView(const QPoint& p) const -{ - return p - d->origin; -} - -QRect KarbonCanvas::widgetToView(const QRect& r) const -{ - return r.translated(- d->origin); -} - -QPoint KarbonCanvas::viewToWidget(const QPoint& p) const -{ - return p + d->origin; -} - -QRect KarbonCanvas::viewToWidget(const QRect& r) const -{ - return r.translated(d->origin); -} - -KoUnit KarbonCanvas::unit() const -{ - return d->part->unit(); -} - -QPoint KarbonCanvas::documentOrigin() const -{ - return d->origin; -} - -void KarbonCanvas::setShowPageMargins(bool on) -{ - d->showMargins = on; -} - -void KarbonCanvas::setDocumentViewMargin(int margin) -{ - d->viewMargin = margin; -} - -int KarbonCanvas::documentViewMargin() const -{ - return d->viewMargin; -} - -QRectF KarbonCanvas::documentViewRect() -{ - QRectF bbox = d->part->boundingRect(); - d->documentViewRect = bbox.adjusted(-d->viewMargin, -d->viewMargin, d->viewMargin, d->viewMargin); - return d->documentViewRect; -} - -void KarbonCanvas::updateInputMethodInfo() -{ - updateMicroFocus(); -} - -KoGuidesData * KarbonCanvas::guidesData() -{ - return &d->part->guidesData(); -} - -void KarbonCanvas::setBackgroundColor(const QColor &color) -{ - QPalette pal = palette(); - pal.setColor(QPalette::Normal, backgroundRole(), color); - pal.setColor(QPalette::Inactive, backgroundRole(), color); - setPalette(pal); -} - -void KarbonCanvas::setCursor(const QCursor &cursor) -{ - QWidget::setCursor(cursor); -} - - diff --git a/karbon/ui/widgets/KarbonConfigInterfacePage.cpp b/karbon/ui/widgets/KarbonConfigInterfacePage.cpp --- a/karbon/ui/widgets/KarbonConfigInterfacePage.cpp +++ b/karbon/ui/widgets/KarbonConfigInterfacePage.cpp @@ -70,20 +70,23 @@ m_showStatusBar->setChecked(oldShowStatusBar); interfaceLayout->addRow(i18n("Show status bar:"), m_showStatusBar); - m_recentFiles = new QSpinBox(tmpQGroupBox); - m_recentFiles->setRange(1, 20); - m_recentFiles->setSingleStep(1); - m_recentFiles->setValue(m_oldRecentFiles); - interfaceLayout->addRow(i18n("Number of recent files:"), m_recentFiles); - - m_dockerFontSize = new QSpinBox(tmpQGroupBox); - m_dockerFontSize->setRange(5, 20); - m_dockerFontSize->setSingleStep(1); - m_dockerFontSize->setValue(m_oldDockerFontSize); - interfaceLayout->addRow(i18n("Palette font size:"), m_dockerFontSize); - - m_canvasColor = new KColorButton(m_oldCanvasColor, tmpQGroupBox); - interfaceLayout->addRow(i18n("Canvas color:"), m_canvasColor); +// TODO or move or remove? +// m_recentFiles = new QSpinBox(tmpQGroupBox); +// m_recentFiles->setRange(1, 20); +// m_recentFiles->setSingleStep(1); +// m_recentFiles->setValue(m_oldRecentFiles); +// interfaceLayout->addRow(i18n("Number of recent files:"), m_recentFiles); + +// TODO or move or remove? +// m_dockerFontSize = new QSpinBox(tmpQGroupBox); +// m_dockerFontSize->setRange(5, 20); +// m_dockerFontSize->setSingleStep(1); +// m_dockerFontSize->setValue(m_oldDockerFontSize); +// interfaceLayout->addRow(i18n("Palette font size:"), m_dockerFontSize); + +// TODO or move or remove? +// m_canvasColor = new KColorButton(m_oldCanvasColor, tmpQGroupBox); +// interfaceLayout->addRow(i18n("Canvas color:"), m_canvasColor); } void KarbonConfigInterfacePage::apply() @@ -94,13 +97,14 @@ KConfigGroup interfaceGroup = m_config->group("Interface"); - int recent = m_recentFiles->value(); - - if (recent != m_oldRecentFiles) { - interfaceGroup.writeEntry("NbRecentFile", recent); - m_view->setNumberOfRecentFiles(recent); - m_oldRecentFiles = recent; - } +// TODO +// int recent = m_recentFiles->value(); +// +// if (recent != m_oldRecentFiles) { +// interfaceGroup.writeEntry("NbRecentFile", recent); +// m_view->setNumberOfRecentFiles(recent); +// m_oldRecentFiles = recent; +// } bool refreshGUI = false; @@ -110,19 +114,19 @@ refreshGUI = true; } - int dockerFontSize = m_dockerFontSize->value(); - - if (dockerFontSize != m_oldDockerFontSize) { - m_config->group("GUI").writeEntry("palettefontsize", dockerFontSize); - m_oldDockerFontSize = dockerFontSize; - refreshGUI = true; - } - - QColor canvasColor = m_canvasColor->color(); - if (canvasColor != m_oldCanvasColor) { - interfaceGroup.writeEntry("CanvasColor", canvasColor); - refreshGUI = true; - } +// int dockerFontSize = m_dockerFontSize->value(); +// +// if (dockerFontSize != m_oldDockerFontSize) { +// m_config->group("GUI").writeEntry("palettefontsize", dockerFontSize); +// m_oldDockerFontSize = dockerFontSize; +// refreshGUI = true; +// } +// +// QColor canvasColor = m_canvasColor->color(); +// if (canvasColor != m_oldCanvasColor) { +// interfaceGroup.writeEntry("CanvasColor", canvasColor); +// refreshGUI = true; +// } if (refreshGUI) part->reorganizeGUI(); diff --git a/karbon/ui/widgets/KarbonSmallStylePreview.h b/karbon/ui/widgets/KarbonSmallStylePreview.h --- a/karbon/ui/widgets/KarbonSmallStylePreview.h +++ b/karbon/ui/widgets/KarbonSmallStylePreview.h @@ -40,7 +40,7 @@ void fillApplied(); void strokeApplied(); -private Q_SLOTS: +public Q_SLOTS: void selectionChanged(); void canvasChanged(const KoCanvasBase *canvas); diff --git a/libs/pageapp/KoPAView.h b/libs/pageapp/KoPAView.h --- a/libs/pageapp/KoPAView.h +++ b/libs/pageapp/KoPAView.h @@ -45,6 +45,7 @@ class QTabBar; class KoCopyController; class KoCutController; +class KoCanvasController; /// Creates a view with a KoPACanvasBase and rulers class KOPAGEAPP_EXPORT KoPAView : public KoView, public KoPAViewBase @@ -93,6 +94,7 @@ KoRuler *horizontalRuler(); KoRuler *verticalRuler(); + KoCanvasController *canvasController() const; /// @return the canvas for the application KoPACanvasBase * kopaCanvas() const; /// @return the document for the application @@ -297,6 +299,10 @@ */ void updateUnit(const KoUnit &unit); +protected: + /// Re-implement this if you need special configuration control + virtual void openConfiguration(); + private: class Private; Private * const d; diff --git a/libs/pageapp/KoPAView.cpp b/libs/pageapp/KoPAView.cpp --- a/libs/pageapp/KoPAView.cpp +++ b/libs/pageapp/KoPAView.cpp @@ -457,6 +457,10 @@ actionCollection()->action( "object_ungroup" )->setShortcut( QKeySequence( "Ctrl+Shift+G" ) ); } +KoCanvasController *KoPAView::canvasController() const +{ + return d->canvasController; +} KoPACanvasBase * KoPAView::kopaCanvas() const { @@ -697,11 +701,16 @@ } void KoPAView::configure() +{ + openConfiguration(); + // TODO update canvas +} + +void KoPAView::openConfiguration() { QPointer dialog(new KoPAConfigureDialog(this)); dialog->exec(); delete dialog; - // TODO update canvas } void KoPAView::setMasterMode( bool master )