xref: /glogg/src/mainwindow.h (revision 11582726a85c08832d009bfe179074b8d1152d21)
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 updateTitleBar( const QString& file_name );
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     std::shared_ptr<RecentFiles> recentFiles_;
129     QString loadingFileName;
130 
131     enum { MaxRecentFiles = 5 };
132     QAction *recentFileActions[MaxRecentFiles];
133     MenuActionToolTipBehavior *recentFileActionBehaviors[MaxRecentFiles];
134     QAction *separatorAction;
135 
136     QMenu *fileMenu;
137     QMenu *editMenu;
138     QMenu *viewMenu;
139     QMenu *toolsMenu;
140     QMenu *helpMenu;
141 
142     InfoLine *infoLine;
143     QLabel* lineNbField;
144     QToolBar *toolBar;
145 
146     QAction *openAction;
147     QAction *exitAction;
148     QAction *copyAction;
149     QAction *selectAllAction;
150     QAction *findAction;
151     QAction *overviewVisibleAction;
152     QAction *lineNumbersVisibleInMainAction;
153     QAction *lineNumbersVisibleInFilteredAction;
154     QAction *followAction;
155     QAction *reloadAction;
156     QAction *stopAction;
157     QAction *filtersAction;
158     QAction *optionsAction;
159     QAction *aboutAction;
160     QAction *aboutQtAction;
161 
162     QIcon mainIcon_;
163 
164     // Multiplex signals to any of the CrawlerWidgets
165     SignalMux signalMux_;
166 
167     // QuickFind widget
168     QuickFindWidget quickFindWidget_;
169 
170     // Multiplex signals to/from the QuickFindWidget
171     QuickFindMux quickFindMux_;
172 
173     // The main widget
174     TabbedCrawlerWidget mainTabWidget_;
175 };
176 
177 #endif
178