contextpanewidgetimage.h 5.25 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
**
hjk's avatar
hjk committed
24 25
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29

30 31 32
#ifndef CONTEXTPANEWIDGETIMAGE_H
#define CONTEXTPANEWIDGETIMAGE_H

33 34
#include "qmleditorwidgets_global.h"
#include "contextpanewidget.h"
Friedemann Kleint's avatar
Friedemann Kleint committed
35
#include <qdrawutil.h>
36

37 38 39
#include <QLabel>
#include <QPointer>

40
QT_BEGIN_NAMESPACE
41 42
namespace Ui {
    class ContextPaneWidgetImage;
43
    class ContextPaneWidgetBorderImage;
44
}
Thomas Hartmann's avatar
Thomas Hartmann committed
45
class QLabel;
46
class QSlider;
47
QT_END_NAMESPACE
48

49
namespace QmlJS { class PropertyReader; }
50

51 52 53
namespace QmlEditorWidgets {

class FileWidget;
54 55 56 57 58 59 60 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

class PreviewLabel : public QLabel
{
    Q_OBJECT

public:
    PreviewLabel(QWidget *parent = 0);
    void setZoom(int);
    void setIsBorderImage(bool b);
    void setMargins(int left, int top, int right, int bottom);
    int leftMarging() const { return m_left; }
    int topMarging() const { return m_top; }
    int rightMarging() const { return m_right; }
    int bottomMarging() const { return m_bottom; }

signals:
    void leftMarginChanged();
    void topMarginChanged();
    void bottomMarginChanged();
    void rightMarginChanged();

protected:
    void paintEvent(QPaintEvent *event);
    void mousePressEvent(QMouseEvent * event);
    void mouseReleaseEvent(QMouseEvent * event);
    void mouseMoveEvent(QMouseEvent * event);
    void leaveEvent(QEvent* event );
private:
    bool m_showBorders;
    int m_left, m_right, m_top, m_bottom;
    bool m_dragging_left;
    bool m_dragging_right;
    bool m_dragging_top;
    bool m_dragging_bottom;
    QPoint m_startPos;
    int m_zoom;
    bool m_borderImage;
91
    QLabel *m_hooverInfo;
92
};
93

Thomas Hartmann's avatar
Thomas Hartmann committed
94 95 96 97 98 99
class PreviewDialog : public DragWidget
{
    Q_OBJECT

public:
    PreviewDialog(QWidget *parent = 0);
100 101 102 103 104 105
    void setPixmap(const QPixmap &p, int zoom = 1);
    void setZoom(int z);
    void setIsBorderImage(bool b);
    PreviewLabel *previewLabel() const;
    int zoom() { return m_zoom; }

Thomas Hartmann's avatar
Thomas Hartmann committed
106 107
public slots:
    void onTogglePane();
108
    void onSliderMoved(int value);
Thomas Hartmann's avatar
Thomas Hartmann committed
109

110 111 112
protected:
    void wheelEvent(QWheelEvent* event);

Thomas Hartmann's avatar
Thomas Hartmann committed
113
private:
114 115
    PreviewLabel *m_label;
    QSlider *m_slider;
116
    QLabel *m_zoomLabel;
117 118 119
    int m_zoom;
    QPixmap m_pixmap;
    bool m_borderImage;
Thomas Hartmann's avatar
Thomas Hartmann committed
120 121
};

122
class QMLEDITORWIDGETS_EXPORT ContextPaneWidgetImage : public QWidget
123 124 125 126
{
    Q_OBJECT

public:
127
    explicit ContextPaneWidgetImage(QWidget *parent = 0, bool borderImage = false);
128 129
    ~ContextPaneWidgetImage();
    void setProperties(QmlJS::PropertyReader *propertyReader);
Orgad Shaneh's avatar
Orgad Shaneh committed
130
    void setPath(const QString& path);
131
    PreviewDialog* previewDialog();
132 133 134 135 136 137 138 139

signals:
    void propertyChanged(const QString &, const QVariant &);
    void removeProperty(const QString &);
    void removeAndChangeProperty(const QString &, const QString &, const QVariant &, bool removeFirst);

public slots:
    void onStretchChanged();
140 141
    void onVerticalStretchChanged();
    void onHorizontalStretchChanged();
142
    void onFileNameChanged();
Thomas Hartmann's avatar
Thomas Hartmann committed
143
    void onPixmapDoubleClicked();
144
    void setPixmap(const QString &fileName);
145 146 147 148
    void onLeftMarginsChanged();
    void onTopMarginsChanged();
    void onBottomMarginsChanged();
    void onRightMarginsChanged();
149 150 151

protected:
    void changeEvent(QEvent *e);
152 153
    void hideEvent(QHideEvent* event);
    void showEvent(QShowEvent* event);
154 155 156

private:
    Ui::ContextPaneWidgetImage *ui;
157
    Ui::ContextPaneWidgetBorderImage *uiBorderImage;
158
    QString m_path;
159
    QPointer<PreviewDialog> m_previewDialog;
160 161 162 163
    FileWidget *m_fileWidget;
    QLabel *m_sizeLabel;
    bool m_borderImage;
    bool previewWasVisible;
164 165
};

Thomas Hartmann's avatar
Thomas Hartmann committed
166 167 168 169 170 171 172 173 174 175 176
class LabelFilter: public QObject {

    Q_OBJECT
public:
    LabelFilter(QObject* parent =0) : QObject(parent) {}
signals:
    void doubleClicked();
protected:
    bool eventFilter(QObject *obj, QEvent *event);
};

177 178 179 180 181 182 183 184 185 186 187 188
class WheelFilter: public QObject {

    Q_OBJECT
public:
    WheelFilter(QObject* parent =0) : QObject(parent) {}
    void setTarget(QObject *target) { m_target = target; }
protected:
    bool eventFilter(QObject *obj, QEvent *event);
    QObject *m_target;
};


Thomas Hartmann's avatar
Thomas Hartmann committed
189 190 191



192 193 194
} //QmlDesigner

#endif // CONTEXTPANEWIDGETIMAGE_H