1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #pragma once 27 28 #include "qmleditorwidgets_global.h" 29 #include "contextpanewidget.h" 30 #include <qdrawutil.h> 31 32 #include <QLabel> 33 #include <QPointer> 34 35 QT_BEGIN_NAMESPACE 36 namespace Ui { 37 class ContextPaneWidgetImage; 38 class ContextPaneWidgetBorderImage; 39 } 40 class QLabel; 41 class QSlider; 42 QT_END_NAMESPACE 43 44 namespace QmlJS { class PropertyReader; } 45 46 namespace QmlEditorWidgets { 47 48 class FileWidget; 49 50 class PreviewLabel : public QLabel 51 { 52 Q_OBJECT 53 54 public: 55 PreviewLabel(QWidget *parent = nullptr); 56 void setZoom(int); 57 void setIsBorderImage(bool b); 58 void setMargins(int left, int top, int right, int bottom); leftMarging()59 int leftMarging() const { return m_left; } topMarging()60 int topMarging() const { return m_top; } rightMarging()61 int rightMarging() const { return m_right; } bottomMarging()62 int bottomMarging() const { return m_bottom; } 63 64 signals: 65 void leftMarginChanged(); 66 void topMarginChanged(); 67 void bottomMarginChanged(); 68 void rightMarginChanged(); 69 70 protected: 71 void paintEvent(QPaintEvent *event) final; 72 void mousePressEvent(QMouseEvent * event) final; 73 void mouseReleaseEvent(QMouseEvent * event) final; 74 void mouseMoveEvent(QMouseEvent * event) final; 75 void leaveEvent(QEvent* event ) final; 76 private: 77 bool m_showBorders; 78 int m_left, m_right, m_top, m_bottom; 79 bool m_dragging_left; 80 bool m_dragging_right; 81 bool m_dragging_top; 82 bool m_dragging_bottom; 83 QPoint m_startPos; 84 int m_zoom; 85 bool m_borderImage; 86 QLabel *m_hooverInfo; 87 }; 88 89 class PreviewDialog : public DragWidget 90 { 91 Q_OBJECT 92 93 public: 94 PreviewDialog(QWidget *parent = nullptr); 95 void setPixmap(const QPixmap &p, int zoom = 1); 96 void setZoom(int z); 97 void setIsBorderImage(bool b); 98 PreviewLabel *previewLabel() const; zoom()99 int zoom() { return m_zoom; } 100 101 void onTogglePane(); 102 void onSliderMoved(int value); 103 104 protected: 105 void wheelEvent(QWheelEvent* event) final; 106 107 private: 108 PreviewLabel *m_label; 109 QSlider *m_slider; 110 QLabel *m_zoomLabel; 111 int m_zoom; 112 QPixmap m_pixmap; 113 bool m_borderImage; 114 }; 115 116 class QMLEDITORWIDGETS_EXPORT ContextPaneWidgetImage : public QWidget 117 { 118 Q_OBJECT 119 120 public: 121 explicit ContextPaneWidgetImage(QWidget *parent = nullptr, bool borderImage = false); 122 ~ContextPaneWidgetImage(); 123 void setProperties(QmlJS::PropertyReader *propertyReader); 124 void setPath(const QString& path); 125 PreviewDialog* previewDialog(); 126 127 signals: 128 void propertyChanged(const QString &, const QVariant &); 129 void removeProperty(const QString &); 130 void removeAndChangeProperty(const QString &, const QString &, const QVariant &, bool removeFirst); 131 132 public: 133 void onStretchChanged(); 134 void onVerticalStretchChanged(); 135 void onHorizontalStretchChanged(); 136 void onFileNameChanged(); 137 void onPixmapDoubleClicked(); 138 void setPixmap(const QString &fileName); 139 void onLeftMarginsChanged(); 140 void onTopMarginsChanged(); 141 void onBottomMarginsChanged(); 142 void onRightMarginsChanged(); 143 144 protected: 145 void changeEvent(QEvent *e) override; 146 void hideEvent(QHideEvent* event) override; 147 void showEvent(QShowEvent* event) override; 148 149 private: 150 Ui::ContextPaneWidgetImage *ui; 151 Ui::ContextPaneWidgetBorderImage *uiBorderImage; 152 QString m_path; 153 QPointer<PreviewDialog> m_previewDialog; 154 FileWidget *m_fileWidget; 155 QLabel *m_sizeLabel; 156 bool m_borderImage; 157 bool previewWasVisible; 158 }; 159 160 class LabelFilter: public QObject { 161 162 Q_OBJECT 163 public: QObject(parent)164 LabelFilter(QObject* parent =nullptr) : QObject(parent) {} 165 signals: 166 void doubleClicked(); 167 protected: 168 bool eventFilter(QObject *obj, QEvent *event) final; 169 }; 170 171 class WheelFilter: public QObject { 172 173 Q_OBJECT 174 public: QObject(parent)175 WheelFilter(QObject* parent =nullptr) : QObject(parent) {} setTarget(QObject * target)176 void setTarget(QObject *target) { m_target = target; } 177 protected: 178 bool eventFilter(QObject *obj, QEvent *event) final; 179 QObject *m_target; 180 }; 181 182 183 184 185 186 } //QmlDesigner 187