UBGraphicsTextItemDelegate.h 2.21 KB
Newer Older
Claudio Valerio's avatar
Claudio Valerio committed
1
/*
Claudio Valerio's avatar
Claudio Valerio committed
2 3
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
Claudio Valerio's avatar
Claudio Valerio committed
4
 * the Free Software Foundation, either version 2 of the License, or
Claudio Valerio's avatar
Claudio Valerio committed
5
 * (at your option) any later version.
Claudio Valerio's avatar
Claudio Valerio committed
6
 *
Claudio Valerio's avatar
Claudio Valerio committed
7 8 9 10 11 12 13
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Claudio Valerio's avatar
Claudio Valerio committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
 */

#ifndef UBGRAPHICSTEXTITEMDELEGATE_H_
#define UBGRAPHICSTEXTITEMDELEGATE_H_

#include <QtGui>

#include <QtSvg>

#include "core/UB.h"
#include "UBGraphicsItemDelegate.h"

class UBGraphicsTextItem;

class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate
{
30
    Q_OBJECT
Claudio Valerio's avatar
Claudio Valerio committed
31

Aleksei Kanash's avatar
Aleksei Kanash committed
32 33 34 35 36 37
    enum textChangeMode
    {
        changeSize = 0,
        scaleSize
    };

Claudio Valerio's avatar
Claudio Valerio committed
38 39 40
    public:
        UBGraphicsTextItemDelegate(UBGraphicsTextItem* pDelegated, QObject * parent = 0);
        virtual ~UBGraphicsTextItemDelegate();
41
        bool isEditable();
Aleksei Kanash's avatar
Aleksei Kanash committed
42
        void scaleTextSize(qreal multiplyer);
Claudio Valerio's avatar
Claudio Valerio committed
43 44 45

    public slots:
        void contentsChanged();
46
        virtual void setEditable(bool);
Claudio Valerio's avatar
Claudio Valerio committed
47 48 49

    protected:
        virtual void buildButtons();
50 51
        virtual void decorateMenu(QMenu *menu);
        virtual void updateMenuActionState();
Claudio Valerio's avatar
Claudio Valerio committed
52

Ivan Ilin's avatar
Ivan Ilin committed
53 54
        virtual void positionHandles();

Claudio Valerio's avatar
Claudio Valerio committed
55 56 57 58 59 60 61 62 63 64 65 66
    private:

        UBGraphicsTextItem* delegated();

        DelegateButton* mFontButton;
        DelegateButton* mColorButton;
        DelegateButton* mDecreaseSizeButton;
        DelegateButton* mIncreaseSizeButton;

        int mLastFontPixelSize;

        static const int sMinPixelSize;
67
        static const int sMinPointSize;
Claudio Valerio's avatar
Claudio Valerio committed
68 69 70

    private:
        void customize(QFontDialog &fontDialog);
Aleksei Kanash's avatar
Aleksei Kanash committed
71
        void ChangeTextSize(qreal factor, textChangeMode changeMode);
72

Ivan Ilin's avatar
Ivan Ilin committed
73
        QFont createDefaultFont();
74
        QAction *mEditableAction;
Claudio Valerio's avatar
Claudio Valerio committed
75 76 77 78 79 80 81 82 83

    private slots:

        void pickFont();
        void pickColor();

        void decreaseSize();
        void increaseSize();

84 85 86
private:
      const int delta;

Claudio Valerio's avatar
Claudio Valerio committed
87 88 89
};

#endif /* UBGRAPHICSTEXTITEMDELEGATE_H_ */