UBThumbnailWidget.h 18 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)
Claudio Valerio's avatar
Claudio Valerio committed
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 14 15 16 17
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License,
 * 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 22 23
 * GNU General Public License for more details.
 *
 * 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
 */

Claudio Valerio's avatar
Claudio Valerio committed
27 28


Claudio Valerio's avatar
Claudio Valerio committed
29

Claudio Valerio's avatar
Claudio Valerio committed
30 31 32 33 34 35 36 37
#ifndef UBTHUMBNAILWIDGET_H_
#define UBTHUMBNAILWIDGET_H_

#include <QtGui>
#include <QtSvg>
#include <QTime>
#include <QGraphicsSceneHoverEvent>

38 39
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
Claudio Valerio's avatar
Claudio Valerio committed
40 41 42
#include "frameworks/UBCoreGraphicsScene.h"
#include "core/UBSettings.h"
#include "domain/UBItem.h"
43 44 45 46 47 48
#include "gui/UBThumbnailView.h"
#include "document/UBDocumentProxy.h"

#include <QLabel>
#include <QHBoxLayout>

Claudio Valerio's avatar
Claudio Valerio committed
49 50

#define STARTDRAGTIME   1000000
51 52
#define BUTTONSIZE      96
#define BUTTONSPACING 10
Claudio Valerio's avatar
Claudio Valerio committed
53 54 55 56 57 58 59

class UBDocumentProxy;
class UBThumbnailTextItem;
class UBThumbnail;

class UBThumbnailWidget : public QGraphicsView
{
60
    Q_OBJECT
Claudio Valerio's avatar
Claudio Valerio committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 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

    public:
        UBThumbnailWidget(QWidget* parent);
        virtual ~UBThumbnailWidget();

        QList<QGraphicsItem*> selectedItems();
        void selectItemAt(int pIndex, bool extend = false);
        void unselectItemAt(int pIndex);

        qreal thumbnailWidth()
        {
            return mThumbnailWidth;
        }

        void setBackgroundBrush(const QBrush& brush)
        {
            mThumbnailsScene.setBackgroundBrush(brush);
        }

    public slots:
        void setThumbnailWidth(qreal pThumbnailWidth);
        void setSpacing(qreal pSpacing);
        virtual void setGraphicsItems(const QList<QGraphicsItem*>& pGraphicsItems, const QList<QUrl>& pItemPaths, const QStringList pLabels = QStringList(), const QString& pMimeType = QString(""));
        void refreshScene();
        void sceneSelectionChanged();

    signals:
        void resized();
        void selectionChanged();
        void mouseDoubleClick(QGraphicsItem* item, int index);
        void mouseClick(QGraphicsItem* item, int index);


    protected:
        virtual void mousePressEvent(QMouseEvent *event);
        virtual void mouseMoveEvent(QMouseEvent *event);
        virtual void mouseReleaseEvent(QMouseEvent *event);
        virtual void resizeEvent(QResizeEvent * event);
        void mouseDoubleClickEvent(QMouseEvent * event);

        virtual void keyPressEvent(QKeyEvent *event);
        virtual void focusInEvent(QFocusEvent *event);

        QList<QGraphicsItem*> mGraphicItems;
        QList<UBThumbnailTextItem*> mLabelsItems;
        QPointF mMousePressScenePos;
        QPoint mMousePressPos;

    protected:
        qreal spacing() { return mSpacing; }
        QList<QUrl> mItemsPaths;
        QStringList mLabels;
        bool bSelectionInProgress;
114
        bool bCanDrag;
Claudio Valerio's avatar
Claudio Valerio committed
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

    private:
        void selectAll();
        void selectItems(int startIndex, int count);
        int rowCount() const;
        int columnCount() const;

        static bool thumbnailLessThan(QGraphicsItem* item1, QGraphicsItem* item2);

        void deleteLasso();

        UBCoreGraphicsScene mThumbnailsScene;

        QString mMimeType;

        QPointF prevMoveMousePos;

        qreal mThumbnailWidth;
        qreal mThumbnailHeight;
        qreal mSpacing;

        UBThumbnail *mLastSelectedThumbnail;
        int mSelectionSpan;
        QRectF mPrevLassoRect;
        QGraphicsRectItem *mLassoRectItem;
        QSet<QGraphicsItem*> mSelectedThumbnailItems;
        QSet<QGraphicsItem*> mPreviouslyIncrementalSelectedItemsX;
        QSet<QGraphicsItem*> mPreviouslyIncrementalSelectedItemsY;
        QTime mClickTime;
};

class UBThumbnail
{
    public:
        UBThumbnail();

        virtual ~UBThumbnail();

        QStyleOptionGraphicsItem muteStyleOption(const QStyleOptionGraphicsItem *option)
        {
            // Never draw the rubber band, we draw our custom selection with the DelegateFrame
            QStyleOptionGraphicsItem styleOption = QStyleOptionGraphicsItem(*option);
            styleOption.state &= ~QStyle::State_Selected;

            return styleOption;
        }

         virtual void itemChange(QGraphicsItem *item, QGraphicsItem::GraphicsItemChange change, const QVariant &value)
        {
            Q_UNUSED(value);

            if ((change == QGraphicsItem::ItemSelectedHasChanged
                    || change == QGraphicsItem::ItemTransformHasChanged
                    || change == QGraphicsItem::ItemPositionHasChanged)
                    &&  item->scene())
            {
                if (item->isSelected())
                {
                    if (!mSelectionItem->scene())
                    {
                        item->scene()->addItem(mSelectionItem);
                        mSelectionItem->setZValue(item->zValue() - 1);
                        mAddedToScene = true;
                    }

                    mSelectionItem->setRect(
                        item->sceneBoundingRect().x() - 5,
                        item->sceneBoundingRect().y() - 5,
                        item->sceneBoundingRect().width() + 10,
                        item->sceneBoundingRect().height() + 10);

                    mSelectionItem->show();

                }
                else
                {
                    mSelectionItem->hide();
                }
            }
        }

        int column() { return mColumn; }
        void setColumn(int column) { mColumn = column; }
        int row() { return mRow; }
        void setRow(int row) { mRow = row; }
200 201
        UBThumbnailTextItem *label(){return mLabel;}
        void setLabel(UBThumbnailTextItem *label){mLabel = label;}
Claudio Valerio's avatar
Claudio Valerio committed
202 203 204 205 206 207 208 209

    protected:
        QGraphicsRectItem *mSelectionItem;
        private:
        bool mAddedToScene;

        int mColumn;
        int mRow;
210
        UBThumbnailTextItem *mLabel;
Claudio Valerio's avatar
Claudio Valerio committed
211 212
};

213
class UBThumbnailTextItem : public QGraphicsTextItem
Claudio Valerio's avatar
Claudio Valerio committed
214
{
215
    Q_OBJECT
Claudio Valerio's avatar
Claudio Valerio committed
216
    public:
217 218 219 220 221 222 223 224 225 226 227 228 229 230
        UBThumbnailTextItem(int index)
            : QGraphicsTextItem(tr("Page %0").arg(index+1))
            , mWidth(0)
            , mUnelidedText(toPlainText())
            , mIsHighlighted(false)
        {

        }

        UBThumbnailTextItem(const QString& text)
            : QGraphicsTextItem(text)
            , mWidth(0)
            , mUnelidedText(text)
            , mIsHighlighted(false)
Claudio Valerio's avatar
Claudio Valerio committed
231 232 233 234
        {
            setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
        }

235 236 237
        QRectF boundingRect() const { return QRectF(QPointF(0.0, 0.0), QSize(mWidth, QFontMetricsF(font()).height() + 5));}

        void setWidth(qreal pWidth)
Claudio Valerio's avatar
Claudio Valerio committed
238
        {
239 240 241 242 243 244
                if (mWidth != pWidth)
                {
                        prepareGeometryChange();
                        mWidth = pWidth;
                        computeText();
                }
Claudio Valerio's avatar
Claudio Valerio committed
245 246
        }

247 248 249
        qreal width() {return mWidth;}

        void highlight()
Claudio Valerio's avatar
Claudio Valerio committed
250
        {
251 252 253 254 255
                if (!mIsHighlighted)
                {
                        mIsHighlighted = true;
                        computeText();
                }
Claudio Valerio's avatar
Claudio Valerio committed
256 257
        }

258
        void computeText()
Claudio Valerio's avatar
Claudio Valerio committed
259
        {
260 261 262 263 264 265 266 267 268 269 270
            QFontMetricsF fm(font());
            QString elidedText = fm.elidedText(mUnelidedText, Qt::ElideRight, mWidth);

            if (mIsHighlighted)
            {
                setHtml("<span style=\"color: #6682b5\">" + elidedText + "</span>");
            }
            else
            {
                setPlainText(elidedText);
            }
Claudio Valerio's avatar
Claudio Valerio committed
271 272
        }

273 274 275 276
    private:
        qreal mWidth;
        QString mUnelidedText;
        bool mIsHighlighted;
Claudio Valerio's avatar
Claudio Valerio committed
277 278 279 280 281 282 283 284 285 286 287 288 289
};

class UBThumbnailPixmap : public QGraphicsPixmapItem, public UBThumbnail
{
    public:
        UBThumbnailPixmap(const QPixmap& pix)
            : QGraphicsPixmapItem(pix)
        {
            setTransformationMode(Qt::SmoothTransformation); // UB 4.3 may be expensive -- make configurable
            setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
            setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
        }

290 291 292 293 294
        virtual ~UBThumbnailPixmap()
        {
            // NOOP
        }

Claudio Valerio's avatar
Claudio Valerio committed
295 296 297 298 299 300 301
        virtual QPainterPath shape () const
        {
            QPainterPath path;
            path.addRect(boundingRect());
            return path;
        }

302

Claudio Valerio's avatar
Claudio Valerio committed
303 304 305 306 307 308 309 310 311 312 313
        virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
        {
            QStyleOptionGraphicsItem styleOption = UBThumbnail::muteStyleOption(option);
            QGraphicsPixmapItem::paint(painter, &styleOption, widget);
        }

        virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
        {
            UBThumbnail::itemChange(this, change, value);
            return QGraphicsPixmapItem::itemChange(change, value);
        }
314
};
Claudio Valerio's avatar
Claudio Valerio committed
315

316 317 318 319 320 321 322
class UBSceneThumbnailPixmap : public UBThumbnailPixmap
{
    public:
        UBSceneThumbnailPixmap(const QPixmap& pix, UBDocumentProxy* proxy, int pSceneIndex)
            : UBThumbnailPixmap(pix)
            , mProxy(proxy)
            , mSceneIndex(pSceneIndex)
323
        {
324 325
            // NOOP
        }
Claudio Valerio's avatar
Claudio Valerio committed
326

327 328 329
        virtual ~UBSceneThumbnailPixmap()
        {
            // NOOP
330 331
        }

332
        UBDocumentProxy* proxy()
333
        {
334
            return mProxy;
335 336 337 338 339 340
        }

        int sceneIndex()
        {
            return mSceneIndex;
        }
341 342 343 344 345 346 347 348

        void highlight()
        {
            //NOOP
        }

    private:
        UBDocumentProxy* mProxy;
349 350 351
        int mSceneIndex;
};

352 353 354 355 356 357
class UBSceneThumbnailNavigPixmap : public UBSceneThumbnailPixmap
{
    public:
        UBSceneThumbnailNavigPixmap(const QPixmap& pix, UBDocumentProxy* proxy, int pSceneIndex);
        ~UBSceneThumbnailNavigPixmap();

358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
        bool editable()
        {
            return mEditable;
        }

        bool deletable()
        {
            return proxy()->pageCount() > 1;
        }

        bool movableUp()
        {
            return sceneIndex() > 0;
        }

        bool movableDown()
        {
            return sceneIndex() < (proxy()->pageCount() -1);
        }

        void showUI()
        {
            setEditable(true);
        }

        void hideUI()
        {
            setEditable(false);
        }

        void setEditable(bool editable)
        {
            mEditable = editable;
        }

393 394 395 396 397 398 399 400 401 402 403 404
    protected:
        void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
        void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
        void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
        void mousePressEvent(QGraphicsSceneMouseEvent *event);

    private:
        void deletePage();
        void duplicatePage();
        void moveUpPage();
        void moveDownPage();

405
        bool mEditable;
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
};

class UBImgTextThumbnailElement
{
private:
    UBSceneThumbnailNavigPixmap* thumbnail;
    UBThumbnailTextItem* caption;
    int border;

public:
    UBImgTextThumbnailElement(UBSceneThumbnailNavigPixmap* thumb, UBThumbnailTextItem* text): border(0)
    {
        this->thumbnail = thumb;
        this->caption = text;
    }

    UBSceneThumbnailNavigPixmap* getThumbnail() const { return this->thumbnail; }
    void setThumbnail(UBSceneThumbnailNavigPixmap* newGItem) { this->thumbnail = newGItem; }

    UBThumbnailTextItem* getCaption() const { return this->caption; }
    void setCaption(UBThumbnailTextItem* newcaption) { this->caption = newcaption; }

    void Place(int row, int col, qreal width, qreal height);

    int getBorder() const { return this->border; }
    void setBorder(int newBorder) { this->border = newBorder; }
};

434
class UBThumbnailProxyWidget : public QGraphicsProxyWidget
Claudio Valerio's avatar
Claudio Valerio committed
435 436
{
    public:
437 438 439
        UBThumbnailProxyWidget(UBDocumentProxy* proxy, int index)
            : mDocumentProxy(proxy)
            , mSceneIndex(index)
Claudio Valerio's avatar
Claudio Valerio committed
440
        {
441

Claudio Valerio's avatar
Claudio Valerio committed
442 443
        }

444
        UBDocumentProxy* documentProxy()
Claudio Valerio's avatar
Claudio Valerio committed
445
        {
446
            return mDocumentProxy;
Claudio Valerio's avatar
Claudio Valerio committed
447 448
        }

449
        void setSceneIndex(int i)
Claudio Valerio's avatar
Claudio Valerio committed
450
        {
451
            mSceneIndex = i;
Claudio Valerio's avatar
Claudio Valerio committed
452 453 454 455 456 457 458
        }

        int sceneIndex()
        {
            return mSceneIndex;
        }

459 460
private:
        UBDocumentProxy* mDocumentProxy;
Claudio Valerio's avatar
Claudio Valerio committed
461 462 463
        int mSceneIndex;
};

464
class UBDraggableThumbnail : public UBThumbnailProxyWidget
Claudio Valerio's avatar
Claudio Valerio committed
465
{
466
    Q_OBJECT
Claudio Valerio's avatar
Claudio Valerio committed
467
    public:
468 469
        UBDraggableThumbnail(UBDocumentProxy* documentProxy, int index)
        : UBThumbnailProxyWidget(documentProxy, index)
470
        , mPageNumber(new UBThumbnailTextItem(index))
471 472 473 474 475
        , mEditable(false)
        {

        }

476 477 478 479 480
        ~UBDraggableThumbnail()
        {
            delete mPageNumber; // not a child of "this" QObject so it has to be deleted manually
        }

481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
        bool editable()
        {
            return mEditable;
        }

        bool deletable()
        {
            return documentProxy()->pageCount() > 1;
        }

        bool movableUp()
        {
            return sceneIndex() > 0;
        }

        bool movableDown()
        {
            return sceneIndex() < (documentProxy()->pageCount() -1);
        }

        void showUI()
        {
            setEditable(true);
        }

        void hideUI()
        {
            setEditable(false);
        }

        void setEditable(bool editable)
        {
            mEditable = editable;
        }
Claudio Valerio's avatar
Claudio Valerio committed
515

516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
        UBThumbnailTextItem* pageNumber()
        {
            return mPageNumber;
        }

        void setPageNumber(int i)
        {
            mPageNumber->setPlainText(tr("Page %0").arg(i+1));

            if (UBApplication::boardController->activeSceneIndex() == i)
                mPageNumber->setHtml("<span style=\";font-weight:bold;color: red\">" + tr("Page %0").arg(i+1) + "</span>");
            else
                mPageNumber->setHtml("<span style=\";color: #000000\">" + tr("Page %0").arg(i+1) + "</span>");
        }

        virtual void updatePos(qreal w, qreal h);

Claudio Valerio's avatar
Claudio Valerio committed
533 534 535 536 537
    protected:
        void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
        void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
        void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
        void mousePressEvent(QGraphicsSceneMouseEvent *event);
538
        void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
Claudio Valerio's avatar
Claudio Valerio committed
539

540
        UBThumbnailTextItem* mPageNumber;
Claudio Valerio's avatar
Claudio Valerio committed
541 542 543 544 545 546
    private:
        void deletePage();
        void duplicatePage();
        void moveUpPage();
        void moveDownPage();

547
        bool mEditable;
Claudio Valerio's avatar
Claudio Valerio committed
548 549
};

550
class UBDraggableThumbnailPixmap : public UBDraggableThumbnail
Claudio Valerio's avatar
Claudio Valerio committed
551
{
552
    Q_OBJECT
Claudio Valerio's avatar
Claudio Valerio committed
553
    public:
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
        UBDraggableThumbnailPixmap(UBThumbnailPixmap* thumbnailPixmap, UBDocumentProxy* documentProxy, int index)
            : UBDraggableThumbnail(documentProxy, index)
            , mThumbnailPixmap(thumbnailPixmap)
        {
            setFlag(QGraphicsItem::ItemIsSelectable, true);
            setAcceptDrops(true);
        }

        ~UBDraggableThumbnailPixmap()
        {

        }

        UBThumbnailPixmap* thumbnailPixmap()
        {
            return mThumbnailPixmap;
        }

        void updatePos(qreal w, qreal h);

    private:
        UBThumbnailPixmap* mThumbnailPixmap;
Claudio Valerio's avatar
Claudio Valerio committed
576 577
};

578
class UBDraggableThumbnailView : public UBDraggableThumbnail
Claudio Valerio's avatar
Claudio Valerio committed
579
{
580
    Q_OBJECT
Claudio Valerio's avatar
Claudio Valerio committed
581
    public:
582 583 584
        UBDraggableThumbnailView(UBThumbnailView* thumbnailView, UBDocumentProxy* documentProxy, int index)
            : UBDraggableThumbnail(documentProxy, index)
            , mThumbnailView(thumbnailView)
Claudio Valerio's avatar
Claudio Valerio committed
585
        {
586 587 588
            setFlag(QGraphicsItem::ItemIsSelectable, true);
            setWidget(mThumbnailView);
            setAcceptDrops(true);            
Claudio Valerio's avatar
Claudio Valerio committed
589 590
        }

591
        ~UBDraggableThumbnailView()
Claudio Valerio's avatar
Claudio Valerio committed
592
        {
593 594
            delete mPageNumber; // not a child of "this" QObject so it has to be deleted manually
        }
Claudio Valerio's avatar
Claudio Valerio committed
595

596
        UBThumbnailView* thumbnailView()
Claudio Valerio's avatar
Claudio Valerio committed
597
        {
598
            return mThumbnailView;
Claudio Valerio's avatar
Claudio Valerio committed
599 600
        }

601
        UBThumbnailTextItem* pageNumber()
Claudio Valerio's avatar
Claudio Valerio committed
602
        {
603 604
            return mPageNumber;
        }
Claudio Valerio's avatar
Claudio Valerio committed
605

606 607 608
        void setPageNumber(int i)
        {
            mPageNumber->setPlainText(tr("Page %0").arg(i+1));
609

610
            if (UBApplication::boardController->activeSceneIndex() == i)
611
                mPageNumber->setHtml("<span style=\";font-weight:bold;color: red\">" + tr("Page %0").arg(i+1) + "</span>");
612
            else
613
                mPageNumber->setHtml("<span style=\";color: #000000\">" + tr("Page %0").arg(i+1) + "</span>");
Claudio Valerio's avatar
Claudio Valerio committed
614 615
        }

616
    private:        
617
        UBThumbnailView* mThumbnailView;
Claudio Valerio's avatar
Claudio Valerio committed
618 619
};

620
namespace UBThumbnailUI
Claudio Valerio's avatar
Claudio Valerio committed
621
{
622 623
    const int ICONSIZE      = 96;
    const int ICONSPACING   = 10;
Claudio Valerio's avatar
Claudio Valerio committed
624

625
    class UBThumbnailUIIcon : public QPixmap
Claudio Valerio's avatar
Claudio Valerio committed
626
    {
627
        public:
Claudio Valerio's avatar
Claudio Valerio committed
628

629 630 631 632 633 634 635 636 637 638 639
            UBThumbnailUIIcon(const QString& filename, int pos)
                : QPixmap(QSize(ICONSIZE, ICONSIZE))
                , mPos(pos)
            {
                QSvgRenderer svgRenderer(filename);
                QPainter painter;
                fill(Qt::transparent);
                painter.begin(this);
                svgRenderer.render(&painter);
                painter.end();
            }
Claudio Valerio's avatar
Claudio Valerio committed
640

641 642 643 644
            int pos() const
            {
                return mPos;
            }
Claudio Valerio's avatar
Claudio Valerio committed
645

646 647 648 649 650
            bool triggered(qreal x) const
            {
                using namespace UBThumbnailUI;
                return (x >= pos()*(ICONSIZE + ICONSPACING) && x <= (pos()+1)*ICONSIZE + pos()*ICONSPACING);
            }
Claudio Valerio's avatar
Claudio Valerio committed
651

652 653 654 655 656 657 658 659 660 661
        private:
            int mPos;
    };

    namespace _private
    {
        //do not use this directly
        static QMap<QString, UBThumbnailUIIcon*> catalog;
        void initCatalog();
    }
Claudio Valerio's avatar
Claudio Valerio committed
662

663 664 665 666 667
    UBThumbnailUIIcon* addIcon(const QString& thumbnailIcon, int pos);
    UBThumbnailUIIcon* getIcon(const QString& thumbnailIcon);
    void draw(QPainter* painter, const UBThumbnailUIIcon& thumbnailIcon);
    bool triggered(qreal y);
}
Claudio Valerio's avatar
Claudio Valerio committed
668 669

#endif /* UBTHUMBNAILWIDGET_H_ */