1 /** 2 * UGENE - Integrated Bioinformatics Tools. 3 * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru> 4 * http://ugene.net 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 19 * MA 02110-1301, USA. 20 */ 21 22 #ifndef _U2_WORKFLOW_ITEM_STYLE_H_ 23 #define _U2_WORKFLOW_ITEM_STYLE_H_ 24 25 #include <QAction> 26 #include <QGraphicsItem> 27 #include <QGraphicsScene> 28 #include <QTextDocument> 29 30 class QDomElement; 31 32 namespace U2 { 33 34 class WorkflowProcessItem; 35 36 const qreal R = 30; 37 const qreal A = 8; 38 39 class ItemViewStyle : public QGraphicsObject { 40 Q_OBJECT 41 public: 42 ItemViewStyle(WorkflowProcessItem *p, const QString &id); getId()43 QString getId() const { 44 return id; 45 } 46 refresh()47 virtual void refresh() { 48 } sceneEventFilter(QGraphicsItem *,QEvent *)49 virtual bool sceneEventFilter(QGraphicsItem *, QEvent *) { 50 return false; 51 } getContextMenuActions()52 virtual QList<QAction *> getContextMenuActions() const { 53 return (QList<QAction *>() << bgColorAction << fontAction); 54 } 55 virtual void saveState(QDomElement &) const; 56 virtual void loadState(QDomElement &); 57 virtual QColor defaultColor() const = 0; getBgColor()58 QColor getBgColor() const { 59 return bgColor; 60 } setBgColor(const QColor & color)61 void setBgColor(const QColor &color) { 62 bgColor = color; 63 } defaultFont()64 QFont defaultFont() const { 65 return defFont; 66 } setDefaultFont(const QFont & font)67 void setDefaultFont(const QFont &font) { 68 defFont = font; 69 } getOwner()70 WorkflowProcessItem const *getOwner() const { 71 return owner; 72 } 73 74 protected: 75 WorkflowProcessItem *owner; 76 QColor bgColor; 77 QFont defFont; 78 79 QAction *bgColorAction; 80 QAction *fontAction; 81 QString id; 82 83 private slots: 84 void selectBGColor(); 85 void selectFont(); 86 }; 87 88 class SimpleProcStyle : public ItemViewStyle { 89 public: 90 SimpleProcStyle(WorkflowProcessItem *pit); 91 QRectF boundingRect(void) const; 92 QPainterPath shape() const; 93 QColor defaultColor() const; 94 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); 95 }; 96 97 class DescriptionItem; 98 99 class ExtendedProcStyle : public ItemViewStyle { 100 Q_OBJECT 101 public: 102 ExtendedProcStyle(WorkflowProcessItem *pit); boundingRect(void)103 QRectF boundingRect(void) const { 104 return bounds; 105 } 106 QPainterPath shape() const; 107 QColor defaultColor() const; 108 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); 109 virtual void refresh(); 110 virtual bool sceneEventFilter(QGraphicsItem *watched, QEvent *event); 111 virtual QList<QAction *> getContextMenuActions() const; 112 virtual void saveState(QDomElement &) const; 113 virtual void loadState(QDomElement &); 114 isAutoResized()115 bool isAutoResized() const { 116 return autoResize; 117 } 118 void setFixedBounds(const QRectF &b); 119 120 bool updateCursor(const QPointF &pos); 121 122 signals: 123 void linkActivated(const QString &); 124 125 private slots: 126 void setAutoResizeEnabled(bool b); 127 void linkHovered(const QString &); 128 129 private: 130 QTextDocument *doc; 131 QRectF bounds; 132 bool autoResize; 133 134 enum ResizeMode { NoResize = 0, 135 RightResize = 1, 136 LeftResize = 2, 137 BottomResize = 4, 138 TopResize = 8, 139 RBResize = RightResize + BottomResize, 140 RTResize = RightResize + TopResize, 141 LBResize = LeftResize + BottomResize, 142 LTResize = LeftResize + TopResize }; 143 int resizing; 144 145 QAction *resizeModeAction; 146 DescriptionItem *desc; 147 friend class DescriptionItem; 148 }; 149 150 class HintItem : public QGraphicsTextItem { 151 public: 152 HintItem(const QString &text, QGraphicsItem *parent); 153 154 protected: 155 virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); 156 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); 157 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); 158 159 private: 160 QPointF initPos; 161 bool dragging; 162 }; 163 164 class DescriptionItem : public QGraphicsTextItem { 165 Q_OBJECT 166 public: 167 DescriptionItem(ExtendedProcStyle *p); 168 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); 169 170 protected: 171 QRectF boundingRect() const; 172 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 173 bool sceneEvent(QEvent *event); 174 void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); 175 }; 176 177 } // namespace U2 178 179 #endif 180