xref: /glogg/src/mainwindow.h (revision ee835f33dbd005e7b5095ad459f11d878d0b3ced)
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     void displayNormalStatus( bool success );
90 
91     // Close the tab with the passed index
92     void closeTab( int index );
93     // Setup the tab with current index for view
94     void currentTabChanged( int index );
95 
96     // Instructs the widget to change the pattern in the QuickFind widget
97     // and confirm it.
98     void changeQFPattern( const QString& newPattern );
99 
100   signals:
101     // Is emitted when new settings must be used
102     void optionsChanged();
103     // Is emitted when the 'follow' option is enabled/disabled
104     void followSet( bool checked );
105     // Is emitted before the QuickFind box is activated,
106     // to allow crawlers to get search in the right view.
107     void enteringQuickFind();
108     // Emitted when the quickfind bar is closed.
109     void exitingQuickFind();
110 
111   private:
112     void createActions();
113     void createMenus();
114     void createContextMenu();
115     void createToolBars();
116     void createStatusBar();
117     void createRecentFileToolTipTimer();
118     void readSettings();
119     void writeSettings();
120     bool loadFile( const QString& fileName );
121     void setCurrentFile( const QString& fileName );
122     void updateRecentFileActions();
123     QString strippedName( const QString& fullFileName ) const;
124     CrawlerWidget* currentCrawlerWidget() const;
125     void displayQuickFindBar( QuickFindMux::QFDirection direction );
126 
127     std::unique_ptr<Session> session_;
128     RecentFiles& recentFiles;
129     QString loadingFileName;
130     QString currentFile;
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