kis_part2.cpp 5.44 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/* This file is part of the KDE project
   Copyright (C) 2012 C. Boemann <cbo@kogmbh.com>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include "kis_part2.h"
#include "kis_view2.h"
#include "kis_doc2.h"
#include "kis_factory2.h"
#include "kis_config.h"
#include "kis_clipboard.h"
#include "kis_custom_image_widget.h"
27
#include "kis_image_from_clipboard_widget.h"
28
#include "kis_shape_controller.h"
29 30
#include "KisFlipbookSelector.h"
#include "kis_flipbook.h"
31
#include "kis_resource_server_provider.h"
32 33 34 35 36 37 38 39 40

#include <KoColorSpaceEngine.h>
#include <KoCanvasBase.h>
#include <KoToolManager.h>
#include <KoInteractionTool.h>
#include <KoShapeRegistry.h>
#include <KoShapeManager.h>
#include <KoDocument.h>
#include <KoShapeBasedDocumentBase.h>
41
#include <KoResourceServerProvider.h>
42 43 44 45 46 47 48 49

#include <kapplication.h>
#include <kmessagebox.h>

#include <QApplication>

KisPart2::KisPart2(QObject *parent)
    : KoPart(parent)
50
    , m_flipbook(0)
51
    , m_dieOnError(false)
52
    , m_document(0)
53
{
54 55
    KisFactory2 factory;
    setComponentData(factory.componentData());
56
    setTemplateType("krita_template");
57 58 59 60

    // Preload all the resources in the background
    Q_UNUSED(KoResourceServerProvider::instance());
    Q_UNUSED(KisResourceServerProvider::instance());
61 62 63 64
}

KisPart2::~KisPart2()
{
65
    delete m_flipbook;
66 67 68 69 70 71 72 73
}

void KisPart2::setDocument(KisDoc2 *document)
{
    KoPart::setDocument(document);
    m_document = document;
}

74
KoView *KisPart2::createViewInstance(KoDocument *document, QWidget *parent)
75 76
{
    qApp->setOverrideCursor(Qt::WaitCursor);
77
    KisView2 *v = new KisView2(this, qobject_cast<KisDoc2*>(document), parent);
78 79

    //XXX : fix this ugliness
80
    dynamic_cast<KisShapeController*>(qobject_cast<KisDoc2*>(document)->shapeController())->setInitialShapeForView(v);
81 82 83 84 85
    KoToolManager::instance()->switchToolRequested("KritaShape/KisToolBrush");

    // XXX: this prevents a crash when opening a new document after opening a
    // a document that has not been touched! I have no clue why, though.
    // see: https://bugs.kde.org/show_bug.cgi?id=208239.
86 87
    document->setModified(true);
    document->setModified(false);
88 89 90 91 92
    qApp->restoreOverrideCursor();

    return v;
}

93
QGraphicsItem *KisPart2::createCanvasItem(KoDocument *document)
94
{
95
    Q_UNUSED(document);
96 97 98
    return 0;
}

99 100 101 102 103
KoMainWindow *KisPart2::createMainWindow()
{
    return new KoMainWindow(KIS_MIME_TYPE, componentData());
}

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
void KisPart2::showStartUpWidget(KoMainWindow *parent, bool alwaysShow)
{
    // print error if the lcms engine is not available
    if (!KoColorSpaceEngineRegistry::instance()->contains("icc")) {
        // need to wait 1 event since exiting here would not work.
        m_errorMessage = i18n("The Calligra LittleCMS color management plugin is not installed. Krita will quit now.");
        m_dieOnError = true;
        QTimer::singleShot(0, this, SLOT(showErrorAndDie()));
    }

    KoPart::showStartUpWidget(parent, alwaysShow);
}

QList<KoPart::CustomDocumentWidgetItem> KisPart2::createCustomDocumentWidgets(QWidget *parent)
{
    KisConfig cfg;

    int w = cfg.defImageWidth();
    int h = cfg.defImageHeight();

    QList<KoPart::CustomDocumentWidgetItem> widgetList;
125 126 127
    {
        KoPart::CustomDocumentWidgetItem item;
        item.widget = new KisCustomImageWidget(parent,
128
                                               qobject_cast<KisDoc2*>(document()), w, h, cfg.defImageResolution(), cfg.defColorModel(), cfg.defaultColorDepth(), cfg.defColorProfile(),
Halla Rempt's avatar
Halla Rempt committed
129
                                               i18n("unnamed"));
130 131 132 133

        item.icon = "application-x-krita";
        widgetList << item;
    }
134 135 136 137 138 139 140 141 142
    {
        QSize sz = KisClipboard::instance()->clipSize();
        if (sz.isValid() && sz.width() != 0 && sz.height() != 0) {
            w = sz.width();
            h = sz.height();
        }

        KoPart::CustomDocumentWidgetItem item;
        item.widget = new KisImageFromClipboard(parent,
143
                                               qobject_cast<KisDoc2*>(document()), w, h, cfg.defImageResolution(), cfg.defColorModel(), cfg.defaultColorDepth(), cfg.defColorProfile(),
144 145
                                               i18n("unnamed"));

Halla Rempt's avatar
Halla Rempt committed
146
        item.title = i18n("Create from Clipboard");
147 148 149 150 151 152
        item.icon = "klipper";

        widgetList << item;


    }
153
#if 0
154 155 156 157 158 159 160
    {
        KoPart::CustomDocumentWidgetItem item;
        item.widget = new KisFlipbookSelector(parent, qobject_cast<KisDoc2*>(document()));
        item.title = i18n("Flipbooks");
        item.icon = "folder-video";
        widgetList << item;
    }
161
#endif
162 163 164
    return widgetList;
}

165 166 167 168
void KisPart2::setFlipbook(KisFlipbook *flipbook)
{
    m_flipbook = flipbook;
}
169 170 171

void KisPart2::showErrorAndDie()
{
172
    KMessageBox::error(0,
173 174 175 176 177 178 179
                       m_errorMessage,
                       i18n("Installation error"));
    if (m_dieOnError) {
        exit(10);
    }
}