xref: /glogg/src/mainwindow.h (revision 812146a8302488475ae27a1d22ae44a1379476a9)
1 /*
2  * Copyright (C) 2009, 2010, 2011, 2013, 2014 Nicolas Bonnefon and other contributors
3  *
4  * This file is part of glogg.
5  *
6  * glogg is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * glogg 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 glogg.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef MAINWINDOW_H
21 #define MAINWINDOW_H
22 
23 #include <memory>
24 #include <QMainWindow>
25 
26 #include "session.h"
27 #include "crawlerwidget.h"
28 #include "infoline.h"
29 #include "signalmux.h"
30 #include "tabbedcrawlerwidget.h"
31 #include "quickfindwidget.h"
32 #include "quickfindmux.h"
33 
34 class QAction;
35 class Session;
36 class RecentFiles;
37 class MenuActionToolTipBehavior;
38 
39 // Main window of the application, creates menus, toolbar and
40 // the CrawlerWidget
41 class MainWindow : public QMainWindow
42 {
43     Q_OBJECT
44 
45   public:
46     // Constructor
47     // The ownership of the session is transferred to us
48     MainWindow( std::unique_ptr<Session> session );
49 
50     // Re-load the files from the previous session
51     void reloadSession();
52     // Loads the initial file (parameter passed or from config file)
53     void loadInitialFile( QString fileName );
54 
55   protected:
56     void closeEvent( QCloseEvent* event );
57     // Drag and drop support
58     void dragEnterEvent( QDragEnterEvent* event );
59     void dropEvent( QDropEvent* event );
60     void keyPressEvent( QKeyEvent* keyEvent );
61 
62   private slots:
63     void open();
64     void openRecentFile();
65     void selectAll();
66     void copy();
67     void find();
68     void filters();
69     void options();
70     void about();
71     void aboutQt();
72 
73     // Change the view settings
74     void toggleOverviewVisibility( bool isVisible );
75     void toggleMainLineNumbersVisibility( bool isVisible );
76     void toggleFilteredLineNumbersVisibility( bool isVisible );
77 
78     // Disable the follow mode checkbox and send the followSet signal down
79     void disableFollow();
80 
81     // Update the line number displayed in the status bar.
82     // Must be passed as the internal (starts at 0) line number.
83     void lineNumberHandler( int line );
84 
85     // Instructs the widget to update the loading progress gauge
86     void updateLoadingProgress( int progress );
87     // Instructs the widget to display the 'normal' status bar,
88     // without the progress gauge and with file info
89     // or an error recovery when loading is finished
90     void handleLoadingFinished( LoadingStatus status );
91 
92     // Close the tab with the passed index
93     void closeTab( int index );
94     // Setup the tab with current index for view
95     void currentTabChanged( int index );
96 
97     // Instructs the widget to change the pattern in the QuickFind widget
98     // and confirm it.
99     void changeQFPattern( const QString& newPattern );
100 
101   signals:
102     // Is emitted when new settings must be used
103     void optionsChanged();
104     // Is emitted when the 'follow' option is enabled/disabled
105     void followSet( bool checked );
106     // Is emitted before the QuickFind box is activated,
107     // to allow crawlers to get search in the right view.
108     void enteringQuickFind();
109     // Emitted when the quickfind bar is closed.
110     void exitingQuickFind();
111 
112   private:
113     void createActions();
114     void createMenus();
115     void createContextMenu();
116     void createToolBars();
117     void createStatusBar();
118     void createRecentFileToolTipTimer();
119     void readSettings();
120     void writeSettings();
121     bool loadFile( const QString& fileName );
122     void updateTitleBar( const QString& file_name );
123     void updateRecentFileActions();
124     QString strippedName( const QString& fullFileName ) const;
125     CrawlerWidget* currentCrawlerWidget() const;
126     void displayQuickFindBar( QuickFindMux::QFDirection direction );
127 
128     std::unique_ptr<Session> session_;
129     std::shared_ptr<RecentFiles> recentFiles_;
130     QString loadingFileName;
131 
132     enum { MaxRecentFiles = 5 };
133     QAction *recentFileActions[MaxRecentFiles];
134     MenuActionToolTipBehavior *recentFileActionBehaviors[MaxRecentFiles];
135     QAction *separatorAction;
136 
137     QMenu *fileMenu;
138     QMenu *editMenu;
139     QMenu *viewMenu;
140     QMenu *toolsMenu;
141     QMenu *helpMenu;
142 
143     InfoLine *infoLine;
144     QLabel* lineNbField;
145     QToolBar *toolBar;
146 
147     QAction *openAction;
148     QAction *exitAction;
149     QAction *copyAction;
150     QAction *selectAllAction;
151     QAction *findAction;
152     QAction *overviewVisibleAction;
153     QAction *lineNumbersVisibleInMainAction;
154     QAction *lineNumbersVisibleInFilteredAction;
155     QAction *followAction;
156     QAction *reloadAction;
157     QAction *stopAction;
158     QAction *filtersAction;
159     QAction *optionsAction;
160     QAction *aboutAction;
161     QAction *aboutQtAction;
162 
163     QIcon mainIcon_;
164 
165     // Multiplex signals to any of the CrawlerWidgets
166     SignalMux signalMux_;
167 
168     // QuickFind widget
169     QuickFindWidget quickFindWidget_;
170 
171     // Multiplex signals to/from the QuickFindWidget
172     QuickFindMux quickFindMux_;
173 
174     // The main widget
175     TabbedCrawlerWidget mainTabWidget_;
176 };
177 
178 #endif
179