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_ADV_SEQUENCE_WIDGET_H_
23 #define _U2_ADV_SEQUENCE_WIDGET_H_
24 
25 #include <QAction>
26 #include <QWidget>
27 
28 #include <U2Core/U2Region.h>
29 #include <U2Core/global.h>
30 
31 namespace U2 {
32 
33 class AnnotatedDNAView;
34 class U2SequenceObject;
35 class DNASequenceSelection;
36 class ADVSequenceWidgetAction;
37 class ADVSequenceObjectContext;
38 class GObject;
39 
40 class U2VIEW_EXPORT ADVSequenceWidget : public QWidget {
41     Q_OBJECT
42 public:
43     ADVSequenceWidget(AnnotatedDNAView *ctx);
44 
getAnnotatedDNAView()45     AnnotatedDNAView *getAnnotatedDNAView() const {
46         return ctx;
47     }
48 
49     virtual QList<U2SequenceObject *> getSequenceObjects() const;
getSequenceContexts()50     virtual QList<ADVSequenceObjectContext *> getSequenceContexts() const {
51         return seqContexts;
52     }
53 
54     /** actions associated with this block. Automatically deleted with block*/
55     virtual void addADVSequenceWidgetAction(ADVSequenceWidgetAction *action);
56 
57     ADVSequenceWidgetAction *getADVSequenceWidgetAction(const QString &objName) const;
58 
getADVSequenceWidgetActions()59     QList<ADVSequenceWidgetAction *> getADVSequenceWidgetActions() const {
60         return wActions;
61     }
62 
63     virtual ADVSequenceObjectContext *getActiveSequenceContext() const = 0;
64 
65     virtual void centerPosition(int pos, QWidget *skipView = nullptr) = 0;
66 
67     virtual void buildPopupMenu(QMenu &m);
68 
69     // TODO: replace with GObjectViewObjectHandler
isWidgetOnlyObject(GObject * o)70     virtual bool isWidgetOnlyObject(GObject *o) const {
71         Q_UNUSED(o);
72         return false;
73     }
74 
updateState(const QVariantMap & m)75     virtual void updateState(const QVariantMap &m) {
76         Q_UNUSED(m);
77     }
78 
saveState(QVariantMap & m)79     virtual void saveState(QVariantMap &m) {
80         Q_UNUSED(m);
81     }
82 
83     virtual U2Region getVisibleRange() const = 0;
84 
85     virtual void setVisibleRange(const U2Region &r) = 0;
86 
87     virtual int getNumBasesVisible() const = 0;
88 
89     virtual void setNumBasesVisible(qint64 n) = 0;
90 
91     virtual void onSequenceObjectRenamed(const QString &oldName) = 0;
92 
93 signals:
94     void si_sequenceObjectAdded(U2SequenceObject *);
95     void si_sequenceObjectRemoved(U2SequenceObject *);
96 
97 protected:
98     AnnotatedDNAView *ctx;
99     QList<ADVSequenceObjectContext *> seqContexts;
100     QList<ADVSequenceWidgetAction *> wActions;
101 };
102 
103 class U2VIEW_EXPORT ADVSequenceWidgetAction : public QAction {
104     Q_OBJECT
105 public:
ADVSequenceWidgetAction(const QString & objName,const QString & text)106     ADVSequenceWidgetAction(const QString &objName, const QString &text)
107         : QAction(text, nullptr), addToBar(false), addToMenu(false), seqWidget(nullptr) {
108         setObjectName(objName);
109     }
110 
111     bool addToBar;
112     bool addToMenu;
113     QString afterMenu;
114     ADVSequenceWidget *seqWidget;
115 };
116 
117 }  // namespace U2
118 
119 #endif
120