xref: /glogg/src/mainwindow.h (revision 32e44cfdc623782d0ed539a56e61636702f974ba)
1 /*
2  * Copyright (C) 2009, 2010, 2011, 2013 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 
31 class QAction;
32 class Session;
33 class RecentFiles;
34 class MenuActionToolTipBehavior;
35 
36 // Main window of the application, creates menus, toolbar and
37 // the CrawlerWidget
38 class MainWindow : public QMainWindow
39 {
40     Q_OBJECT
41 
42   public:
43     // Constructor
44     // The ownership of the session is transferred to us
45     MainWindow( std::unique_ptr<Session> session );
46 
47     // Loads the initial file (parameter passed or from config file)
48     void loadInitialFile( QString fileName );
49 
50   protected:
51     void closeEvent( QCloseEvent* event );
52     // Drag and drop support
53     void dragEnterEvent( QDragEnterEvent* event );
54     void dropEvent( QDropEvent* event );
55 
56   private slots:
57     void open();
58     void openRecentFile();
59     void selectAll();
60     void copy();
61     void find();
62     void stop();
63     void filters();
64     void options();
65     void about();
66     void aboutQt();
67 
68     // Change the view settings
69     void toggleOverviewVisibility( bool isVisible );
70     void toggleMainLineNumbersVisibility( bool isVisible );
71     void toggleFilteredLineNumbersVisibility( bool isVisible );
72 
73     // Disable the follow mode checkbox and send the followSet signal down
74     void disableFollow();
75 
76     // Update the line number displayed in the status bar.
77     // Must be passed as the internal (starts at 0) line number.
78     void lineNumberHandler( int line );
79 
80     // Instructs the widget to update the loading progress gauge
81     void updateLoadingProgress( int progress );
82     // Instructs the widget to display the 'normal' status bar,
83     // without the progress gauge and with file info
84     void displayNormalStatus( bool success );
85 
86 
87   signals:
88     // Is emitted when new settings must be used
89     void optionsChanged();
90     // Is emitted when the 'follow' option is enabled/disabled
91     void followSet( bool checked );
92 
93   private:
94     void createActions();
95     void createMenus();
96     void createContextMenu();
97     void createToolBars();
98     void createStatusBar();
99     void createRecentFileToolTipTimer();
100     void readSettings();
101     void writeSettings();
102     bool loadFile( const QString& fileName );
103     void setCurrentFile( const QString& fileName );
104     void updateRecentFileActions();
105     QString strippedName( const QString& fullFileName ) const;
106 
107     std::unique_ptr<Session> session_;
108     SavedSearches *savedSearches;
109     CrawlerWidget *crawlerWidget;
110     RecentFiles& recentFiles;
111     QString loadingFileName;
112     QString currentFile;
113     QString previousFile;
114 
115     enum { MaxRecentFiles = 5 };
116     QAction *recentFileActions[MaxRecentFiles];
117     MenuActionToolTipBehavior *recentFileActionBehaviors[MaxRecentFiles];
118     QAction *separatorAction;
119 
120     QMenu *fileMenu;
121     QMenu *editMenu;
122     QMenu *viewMenu;
123     QMenu *toolsMenu;
124     QMenu *helpMenu;
125 
126     InfoLine *infoLine;
127     QLabel* lineNbField;
128     QToolBar *toolBar;
129 
130     QAction *openAction;
131     QAction *exitAction;
132     QAction *copyAction;
133     QAction *selectAllAction;
134     QAction *findAction;
135     QAction *overviewVisibleAction;
136     QAction *lineNumbersVisibleInMainAction;
137     QAction *lineNumbersVisibleInFilteredAction;
138     QAction *followAction;
139     QAction *reloadAction;
140     QAction *stopAction;
141     QAction *filtersAction;
142     QAction *optionsAction;
143     QAction *aboutAction;
144     QAction *aboutQtAction;
145 
146     QIcon mainIcon_;
147 
148     // Multiplex signals to any of the CrawlerWidgets
149     SignalMux signalMux_;
150 };
151 
152 #endif
153