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_SYNC_VIEW_MANAGER_H_
23 #define _U2_ADV_SYNC_VIEW_MANAGER_H_
24 
25 #include <QAction>
26 #include <QMenu>
27 #include <QToolBar>
28 #include <QToolButton>
29 
30 #include <U2Core/U2Region.h>
31 
32 namespace U2 {
33 
34 class AnnotatedDNAView;
35 class ADVSequenceWidget;
36 class ADVSingleSequenceWidget;
37 class LRegionsSelection;
38 
39 // Support for synchronous operation for ADVSingleSequenceViews: sync& lock scale, toggle visibility
40 class ADVSyncViewManager : public QObject {
41     Q_OBJECT
42 public:
43     ADVSyncViewManager(AnnotatedDNAView *v);
44     ~ADVSyncViewManager();
45 
46     void updateAutoAnnotationActions();
47     void updateToolbar1(QToolBar *tb);
48     void updateToolbar2(QToolBar *tb);
49 private slots:
50     void sl_rangeChanged();
51     void sl_onSelectionChanged(LRegionsSelection *thiz, const QVector<U2Region> &added, const QVector<U2Region> &removed);
52     void sl_sequenceWidgetAdded(ADVSequenceWidget *w);
53     void sl_sequenceWidgetRemoved(ADVSequenceWidget *w);
54 
55     void sl_lock();
56     void sl_sync();
57 
58     void sl_toggleVisualMode();
59     void sl_toggleAutoAnnotationHighlighting();
60     void sl_updateAutoAnnotationsMenu();
61     void sl_updateVisualMode();
62 
63 private:
64     enum SyncMode {
65         SyncMode_Start,
66         SyncMode_SeqSel,
67         SyncMode_AnnSel
68     };
69 
70     void sync(bool lock, SyncMode mode);
71 
72     int offsetBySeqSel(ADVSingleSequenceWidget *w) const;
73     int offsetByAnnSel(ADVSingleSequenceWidget *w) const;
74 
75     SyncMode detectSyncMode() const;
76     int findSelectedAnnotationPos(ADVSingleSequenceWidget *w) const;
77 
78     void unlock();
79     void updateEnabledState();
80     void toggleCheckedAction(SyncMode mode);
81 
82     QList<ADVSingleSequenceWidget *> getViewsFromADV() const;
83 
84     AnnotatedDNAView *adv;
85 
86     QAction *lockByStartPosAction;
87     QAction *lockBySeqSelAction;
88     QAction *lockByAnnSelAction;
89     QAction *syncByStartPosAction;
90     QAction *syncBySeqSelAction;
91     QAction *syncByAnnSelAction;
92     QActionGroup *lockActionGroup;
93 
94     QToolButton *syncButton;
95     QToolButton *lockButton;
96     QMenu *syncMenu;
97     QMenu *lockMenu;
98 
99     QAction *syncButtonTBAction;
100     QAction *lockButtonTBAction;
101 
102     bool selectionRecursion;
103     bool recursion;
104     QList<ADVSingleSequenceWidget *> views;
105 
106     // auto annotation highlighting
107     QMap<QString, QAction *> aaActionMap;
108     QAction *toggleAutoAnnotationsAction;
109     QMenu *toggleAutoAnnotationsMenu;
110     QToolButton *toggleAutoAnnotationsButton;
111 
112     // visual mode vars
113     QAction *toggleViewButtonAction;
114     QToolButton *toggleViewButton;
115     QMenu *toggleViewButtonMenu;
116     QAction *toggleAllAction;
117     QAction *toggleOveAction;
118     QAction *togglePanAction;
119     QAction *toggleDetAction;
120 };
121 
122 }  // namespace U2
123 #endif
124