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_SINGLE_SEQ_WIDGET_H_
23 #define _U2_ADV_SINGLE_SEQ_WIDGET_H_
24 
25 #include <QLabel>
26 #include <QMenu>
27 #include <QSplitter>
28 #include <QToolBar>
29 #include <QToolButton>
30 #include <QVBoxLayout>
31 #include <QWidget>
32 
33 #include <U2Core/GAutoDeleteList.h>
34 #include <U2Core/U2Region.h>
35 
36 #include "ADVSequenceWidget.h"
37 #include "PanView.h"
38 
39 #ifdef Q_OS_UNIX
40 #    include <QTimer>
41 #endif  // Q_OS_UNIX
42 
43 namespace U2 {
44 
45 class ADVSequenceObjectContext;
46 class ADVSingleSequenceHeaderWidget;
47 class AnnotatedDNAView;
48 class Annotation;
49 class AnnotationSelection;
50 class DetView;
51 class DNAAlphabet;
52 class DNATranslation;
53 class GSequenceLineView;
54 class Overview;
55 class PanView;
56 class U2SequenceObject;
57 
58 class U2VIEW_EXPORT ADVSingleSequenceWidget : public ADVSequenceWidget {
59     Q_OBJECT
60 public:
61     ADVSingleSequenceWidget(ADVSequenceObjectContext *seqCtx, AnnotatedDNAView *ctx);
62     ~ADVSingleSequenceWidget();
63 
getLineViews()64     const QList<GSequenceLineView *> &getLineViews() const {
65         return lineViews;
66     }
67 
68     GSequenceLineView *getPanGSLView() const;
69 
70     GSequenceLineView *getDetGSLView() const;
71 
getPanView()72     PanView *getPanView() const {
73         return panView;
74     }
75 
getDetView()76     DetView *getDetView() const {
77         return detView;
78     }
79 
80     virtual void centerPosition(int pos, QWidget *skipView = nullptr);
81 
getActiveSequenceContext()82     ADVSequenceObjectContext *getActiveSequenceContext() const {
83         return (seqContexts.isEmpty()) ? nullptr : seqContexts.first();
84     }
getSequenceContext()85     ADVSequenceObjectContext *getSequenceContext() const {
86         return getActiveSequenceContext();
87     }
88 
89     DNATranslation *getComplementTT() const;
90 
91     DNATranslation *getAminoTT() const;
92 
93     DNASequenceSelection *getSequenceSelection() const;
94 
95     qint64 getSequenceLength() const;
96 
97     virtual void addSequenceView(GSequenceLineView *v, QWidget *after = nullptr);
98 
99     virtual void removeSequenceView(GSequenceLineView *v, bool deleteView = true);
100 
101     U2SequenceObject *getSequenceObject() const;
102 
103     virtual void buildPopupMenu(QMenu &m);
104 
105     virtual bool isWidgetOnlyObject(GObject *o) const;
106 
107     virtual void addADVSequenceWidgetAction(ADVSequenceWidgetAction *action);
108 
109     void addADVSequenceWidgetActionToViewsToolbar(ADVSequenceWidgetAction *action);
110 
111     void setViewCollapsed(bool v);
112     bool isViewCollapsed() const;
113     void updateViewButtonState();
114 
115     void setPanViewCollapsed(bool collapsed);
116     bool isPanViewCollapsed() const;
117 
118     void setDetViewCollapsed(bool collapsed);
119     bool isDetViewCollapsed() const;
120 
121     void setOverviewCollapsed(bool collapsed);
122     bool isOverviewCollapsed() const;
123 
124     virtual void updateState(const QVariantMap &m);
125     virtual void updateSelectionActions();
126     QVector<U2Region> getSelectedAnnotationRegions(int max);
127 
128     virtual void saveState(QVariantMap &m);
129 
130     void closeView();
131 
132     virtual U2Region getVisibleRange() const;
133 
134     virtual void setVisibleRange(const U2Region &r);
135 
136     virtual int getNumBasesVisible() const;
137 
138     virtual void setNumBasesVisible(qint64 n);
139 
getSelectRangeAction()140     QAction *getSelectRangeAction() const {
141         return selectRangeAction1;
142     }
143 
144     virtual void onSequenceObjectRenamed(const QString &oldName);
145 
146 signals:
147     void si_titleClicked(ADVSequenceWidget *);
148 
149 protected slots:
150     void sl_onViewDestroyed(QObject *);
151 
152     void sl_toggleAllSubViews();
153     void sl_togglePanView(bool checked);
154     void sl_toggleDetView(bool checked);
155     void sl_toggleOverview(bool checked);
156     void sl_onSelectRange();
157     void sl_onSelectInRange();
158     void sl_onSelectOutRange();
159     void sl_zoomToRange();
160     void sl_onLocalCenteringRequest(qint64 pos);
161     void sl_createCustomRuler();
162     void sl_removeCustomRuler();
163 
164     void sl_onAnnotationSelectionChanged(AnnotationSelection *thiz, const QList<Annotation *> &added, const QList<Annotation *> &removed);
165 
166     // QT 4.5.0 bug workaround
167 public slots:
168     void sl_closeView();
169 
170 signals:
171     void si_updateGraphView(const QStringList &, const QVariantMap &);
172 private slots:
173     void sl_saveScreenshot();
174 
175 protected:
176     void init();
177     bool eventFilter(QObject *o, QEvent *e);
178 
179 private:
180     virtual void updateMinMaxHeight();
181 
182     QToolButton *addButtonWithActionToToolbar(QAction *buttonAction, QToolBar *toolBar, int position = -1) const;
183     void addRulersMenu(QMenu &m);
184     void addSelectMenu(QMenu &m);
185 
186     /** Used by several other functions to set new selected region */
187     void setSelectedRegion(const U2Region &region);
188 
189     virtual GSequenceLineView *findSequenceViewByPos(const QPoint &globalPos) const;
190 
191     virtual void addZoomMenu(const QPoint &globalPos, QMenu *m);
192 
193     DetView *detView;
194     PanView *panView;
195     Overview *overview;
196     QList<GSequenceLineView *> lineViews;
197     QVBoxLayout *linesLayout;
198     QSplitter *linesSplitter;
199     ADVSingleSequenceHeaderWidget *headerWidget;
200 
201     QAction *toggleViewAction;
202     QAction *togglePanViewAction;
203     QAction *toggleDetViewAction;
204     QAction *toggleOverviewAction;
205     QAction *selectRangeAction1;
206     QAction *selectRangeAction2;
207     QAction *selectInAnnotationRangeAction;
208     QAction *selectOutAnnotationRangeAction;
209     QAction *zoomToRangeAction;
210     QAction *createNewRulerAction;
211     QAction *shotScreenAction;
212     QAction *closeViewAction;
213 
214     GAutoDeleteList<QAction> rulerActions;
215     QList<QString> *buttonTabOrederedNames;
216 
217     PanView::ZoomUseObject zoomUseObject;
218 
219     static const QString SEQUENCE_SETTINGS;
220     static const QString DET_VIEW_COLLAPSED;
221     static const QString ZOOM_VIEW_COLLAPSED;
222     static const QString OVERVIEW_COLLAPSED;
223 
224     friend class ADVSingleSequenceHeaderWidget;
225 };
226 
227 class U2VIEW_EXPORT ADVSingleSequenceHeaderWidget : public QWidget {
228     Q_OBJECT
229 public:
230     ADVSingleSequenceHeaderWidget(ADVSingleSequenceWidget *p);
231 
getStandardToolBar()232     QToolBar *getStandardToolBar() const {
233         return standardToolBar;
234     }
getViewsToolBar()235     QToolBar *getViewsToolBar() const {
236         return viewsToolBar;
237     }
238 
setTitle(const QString & title)239     void setTitle(const QString &title) {
240         nameLabel->setText(title);
241     }
242     void updateTitle();
243 
244 protected:
245     virtual void mouseDoubleClickEvent(QMouseEvent *e);
246     virtual void paintEvent(QPaintEvent *e);
247 
248 protected slots:
249     /** Toggles header active/inactive visual state if the old or the new widget is related to the header. */
250     void sl_onActiveSequenceWidgetChanged(ADVSequenceWidget *oldActiveWidget, ADVSequenceWidget *newActiveWidget);
251     void sl_actionTriggered(QAction *a);
252 
253 private:
254     void updateActiveState();
255     QString getShortAlphabetName(const DNAAlphabet *al);
256 
257     ADVSingleSequenceWidget *ctx;
258     QToolBar *standardToolBar;
259     QToolBar *viewsToolBar;
260     QLabel *pixLabel;
261     QLabel *nameLabel;
262 };
263 
264 }  // namespace U2
265 
266 #endif
267