UBWidgetUniboardAPI.h 9.35 KB
Newer Older
Claudio Valerio's avatar
Claudio Valerio committed
1
/*
2
 * Copyright (C) 2015-2018 Département de l'Instruction Publique (DIP-SEM)
Craig Watson's avatar
Craig Watson committed
3
 *
Claudio Valerio's avatar
Claudio Valerio committed
4
 * Copyright (C) 2013 Open Education Foundation
Claudio Valerio's avatar
Claudio Valerio committed
5
 *
Claudio Valerio's avatar
Claudio Valerio committed
6 7
 * Copyright (C) 2010-2013 Groupement d'Intérêt Public pour
 * l'Education Numérique en Afrique (GIP ENA)
8
 *
Claudio Valerio's avatar
Claudio Valerio committed
9 10 11
 * This file is part of OpenBoard.
 *
 * OpenBoard is free software: you can redistribute it and/or modify
Claudio Valerio's avatar
Claudio Valerio committed
12 13
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License,
14 15 16 17
 * with a specific linking exception for the OpenSSL project's
 * "OpenSSL" library (or with modified versions of it that use the
 * same license as the "OpenSSL" library).
 *
Claudio Valerio's avatar
Claudio Valerio committed
18
 * OpenBoard is distributed in the hope that it will be useful,
Claudio Valerio's avatar
Claudio Valerio committed
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Claudio Valerio's avatar
Claudio Valerio committed
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Claudio Valerio's avatar
Claudio Valerio committed
21
 * GNU General Public License for more details.
Claudio Valerio's avatar
Claudio Valerio committed
22
 *
Claudio Valerio's avatar
Claudio Valerio committed
23
 * You should have received a copy of the GNU General Public License
Claudio Valerio's avatar
Claudio Valerio committed
24
 * along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
Claudio Valerio's avatar
Claudio Valerio committed
25
 */
26 27


Claudio Valerio's avatar
Claudio Valerio committed
28

Claudio Valerio's avatar
Claudio Valerio committed
29

Claudio Valerio's avatar
Claudio Valerio committed
30 31 32 33
#ifndef UBWIDGETAPI_H
#define UBWIDGETAPI_H

#include <QtCore>
34
#include <QGraphicsSceneDragDropEvent>
Claudio Valerio's avatar
Claudio Valerio committed
35 36

#include "UBW3CWidgetAPI.h"
37
#include "core/UBDownloadManager.h"
Claudio Valerio's avatar
Claudio Valerio committed
38 39 40 41 42 43 44 45 46 47 48

class UBGraphicsScene;
class UBGraphicsWidgetItem;
class UBGraphicsW3CWidgetItem;

class UBWidgetMessageAPI;
class UBDatastoreAPI;
class UBDocumentDatastoreAPI;

class UBWidgetUniboardAPI : public QObject
{
49
    Q_OBJECT
Claudio Valerio's avatar
Claudio Valerio committed
50 51 52 53

    /**
     * The number of pages in the current document
     */
54
    Q_PROPERTY(int pageCount READ pageCount SCRIPTABLE true)
Claudio Valerio's avatar
Claudio Valerio committed
55 56 57 58

    /**
     * The page number of the current page
     */
59
    Q_PROPERTY(int currentPageNumber READ currentPageNumber SCRIPTABLE true)
Claudio Valerio's avatar
Claudio Valerio committed
60 61 62 63 64

    /**
     * instance UUID, return a unique identifier for the widget, this value is guaranted to be unique
     * and constant for a widget, deprecated, use window.widget.uuid instead
     */
65
    Q_PROPERTY(QString uuid READ uuid SCRIPTABLE true)
Claudio Valerio's avatar
Claudio Valerio committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

    /**
     * Returns the language and eventually the country of this locale as a string of the form
     * "language-country" or only "language" if the country is unknown,
     * where language is a lowercase, two-letter ISO 639 language code, and country is an uppercase,
     * two-letter ISO 3166 country code.
     *
     * some potential values are
     *
     * en
     * en-UK
     * fr
     * fr-CH
     * fr-FR
     *
     */
82
    Q_PROPERTY(QString lang READ lang SCRIPTABLE true)
Claudio Valerio's avatar
Claudio Valerio committed
83

84
    Q_PROPERTY(QObject* messages READ messages SCRIPTABLE true)
Claudio Valerio's avatar
Claudio Valerio committed
85

86
    Q_PROPERTY(QObject* datastore READ datastore SCRIPTABLE true)
Claudio Valerio's avatar
Claudio Valerio committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239

    public:

        UBWidgetUniboardAPI(UBGraphicsScene *pScene, UBGraphicsWidgetItem *widget = 0);
        ~UBWidgetUniboardAPI();

        QObject* messages();

        QObject* datastore();

    public slots:

        void setScene(UBGraphicsScene* pScene)
        {
            mScene = pScene;
        }

        // global

        /**
         * Set the tool (pen, marker, arrow, line)
         */
        void setTool(const QString& toolString);

        /**
         * an HTML color (red, blue, ...) or rgb (#FF0000) or a default Uniboard color (1, 2, 3, 4)
         */
        void setPenColor(const QString& penColor);

        /**
         * an HTML color (red, blue, ...) or rgba (#FF000077) or a default Uniboard color (1, 2, 3, 4)
         */
        void setMarkerColor(const QString& penColor);

        /**
         * return the url of the thumbnail of a page
         */
        QString pageThumbnail(const int pageNumber);

        //view based

        /**
         * Zoom the current view port centered on scene position x/y
         */
        void zoom(const qreal factor, const qreal x, const qreal y);

        /**
         * move the view port of x/y pixels
         */
        void move(const qreal x, const qreal y);


        //scene based

        /**
         * move the control to position x/y in scene coordinate
         */
        void moveTo(const qreal x, const qreal y);

        /**
         * draw a line from current pos to x/y in scene coordinate
         */
        void drawLineTo(const qreal x, const qreal y, const qreal pWidth);

        /**
         * erase any line from current pos to x/y in scene coordinate
         */
        void eraseLineTo(const qreal x, const qreal y, const qreal pWidth);

        /**
         * remove all drawing/object from current scene
         */
        void clear();

        /**
         * set the scene backgroung to black/white with crossing or not
         */
        void setBackground(bool pIsDark, bool pIsCrossed);

        /**
         * add any supported objects (pictures/video/widget) centered at scene position x/y.
         * width and height may be supplied, this is useful for flash (.swf) objects
         * if background is true, the object is not selectable and sits in the lowest z pos possible
         *
         */
        void addObject(QString pUrl, int width = 0, int height = 0, int x = 0, int y = 0, bool background = false);


        /**
         * The widget notify the container to resized to width/height in scene (DOM) coordintates
         */
        void resize(qreal width, qreal height);


        // widget based


        /**
         * Returns the language and eventually the country of this locale as a string of the form
         * "language_country" or only "language" if the country is unknown,
         * where language is a lowercase, two-letter ISO 639 language code, and country is an uppercase,
         * two-letter ISO 3166 country code.
         *
         * some potential values are
         *
         * en
         * en_UK
         * fr
         * fr_CH
         * fr_FR
         *
         * deprecated as it does not folow xml normas, replaced by property 'lang'
         *
         */
        QString locale();

        /**
         * Save a preference for this widget instance
         */
        void setPreference(const QString& key, QString value);


        /**
         * retreive widget instance preference
         */
        QString preference(const QString& key, const QString& pDefault = QString());


        /**
         * retreive a list of widget instance preferences
         */
        QStringList preferenceKeys();


        /**
         * Display a message on the top bottom corner of the board
         */
        void showMessage(const QString& message);


        /**
         * Center the scene coordinates within the display port
         *
         */
        void centerOn(const qreal x, const qreal y);


        /**
         * Write some text on the board
         */
        void addText(const QString& text, const qreal x, const qreal y, const int height = -1, const QString& font = ""
                , bool bold = false, bool italic = false);

240 241 242
        void returnStatus(const QString& method, const QString& status);
        void usedMethods(QStringList methods);
        void response(bool correct);
243 244 245 246 247 248 249 250 251 252

        /**
          * Give the file metadata to Sankore. The format must be
          * <metbadata>
          *     <key>File Size</<key>
          *     <value>1024</value>
          * </metadata>
          */
        void sendFileMetadata(QString metaData);

253 254 255 256 257

        // widget download
        /**
         * If the widget support a the drop of an object it will notify sankore about this.
         */
258
        void enableDropOnWidget (bool enable = true);
259 260 261 262 263

        /**
         * When an object is dropped on a widget, this one send us the informations to download it locally.
         * this method download the object on the widget directory and return the path of the downloaded object
         */
264
        void ProcessDropEvent(QGraphicsSceneDragDropEvent *);
Ivan Ilin's avatar
Ivan Ilin committed
265
        bool isDropableData(const QMimeData *pMimeData) const;
266 267

private slots:
268
        void onDownloadFinished(bool pSuccess, sDownloadFileDesc desc, QByteArray pData);
269 270 271

private:
        inline void registerIDWidget(int id){webDownloadIds.append(id);}
272
        inline bool takeIDWidget(int id);
273

Ivan Ilin's avatar
Ivan Ilin committed
274

Claudio Valerio's avatar
Claudio Valerio committed
275 276 277 278 279 280 281 282 283
    private:

        QString uuid();

        QString lang();

        int pageCount();

        int currentPageNumber();
284 285 286 287
        QString getObjDir();
        QString createMimeText(bool downloaded, const QString &mimeType, const QString &fileName);
        bool supportedTypeHeader(const QString &) const;
        QString boolToStr(bool value) const {return value ? "true" : "false";}
Claudio Valerio's avatar
Claudio Valerio committed
288 289 290 291 292 293 294 295 296 297

        UBGraphicsScene* mScene;

        UBGraphicsWidgetItem* mGraphicsWidget;

        bool mIsVisible;

        UBWidgetMessageAPI* mMessagesAPI;

        UBDatastoreAPI* mDatastoreAPI;
298
        QList<int> webDownloadIds;
Claudio Valerio's avatar
Claudio Valerio committed
299 300 301 302 303
};


class UBDatastoreAPI : public QObject
{
304
    Q_OBJECT
Claudio Valerio's avatar
Claudio Valerio committed
305

306
    Q_PROPERTY(QObject* document READ document SCRIPTABLE true)
Claudio Valerio's avatar
Claudio Valerio committed
307 308 309

    public:
        UBDatastoreAPI(UBGraphicsW3CWidgetItem *widget);
310
        virtual ~UBDatastoreAPI(){;}
Claudio Valerio's avatar
Claudio Valerio committed
311 312 313 314 315 316 317 318 319 320 321 322

        QObject* document();

    private:

        UBDocumentDatastoreAPI* mDocumentDatastore;

};


class UBDocumentDatastoreAPI : public UBW3CWebStorage
{
323
    Q_OBJECT
Claudio Valerio's avatar
Claudio Valerio committed
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346

    public:
        UBDocumentDatastoreAPI(UBGraphicsW3CWidgetItem *graphicsWidget);

        virtual ~UBDocumentDatastoreAPI();

    public slots:

        virtual QString key(int index);
        virtual QString getItem(const QString& key);
        virtual void setItem(const QString& key, const QString& value);
        virtual void removeItem(const QString& key);
        virtual void clear();

    protected:
        virtual int length();

    private:
        UBGraphicsW3CWidgetItem* mGraphicsW3CWidget;

};

#endif // UBWIDGETAPI_H