xref: /glogg/src/mainwindow.h (revision d96f3f211e1e2a3a5b219145986c18e10b0f96aa)
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 
30 class QAction;
31 class Session;
32 class RecentFiles;
33 class MenuActionToolTipBehavior;
34 
35 // Main window of the application, creates menus, toolbar and
36 // the CrawlerWidget
37 class MainWindow : public QMainWindow
38 {
39     Q_OBJECT
40 
41   public:
42     // Constructor
43     // The ownership of the session is transferred to us
44     MainWindow( std::unique_ptr<Session> session );
45 
46     // Loads the initial file (parameter passed or from config file)
47     void loadInitialFile( QString fileName );
48 
49   protected:
50     void closeEvent( QCloseEvent* event );
51     // Drag and drop support
52     void dragEnterEvent( QDragEnterEvent* event );
53     void dropEvent( QDropEvent* event );
54 
55   private slots:
56     void open();
57     void openRecentFile();
58     void selectAll();
59     void copy();
60     void find();
61     void reload();
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 createCrawler();
100     void createRecentFileToolTipTimer();
101     void readSettings();
102     void writeSettings();
103     bool loadFile( const QString& fileName );
104     void setCurrentFile( const QString& fileName );
105     void updateRecentFileActions();
106     QString strippedName( const QString& fullFileName ) const;
107     // Returns the size in human readable format
108     QString readableSize( qint64 size ) const;
109 
110     std::unique_ptr<Session> session_;
111     SavedSearches *savedSearches;
112     CrawlerWidget *crawlerWidget;
113     RecentFiles& recentFiles;
114     QString loadingFileName;
115     QString currentFile;
116     QString previousFile;
117 
118     enum { MaxRecentFiles = 5 };
119     QAction *recentFileActions[MaxRecentFiles];
120     MenuActionToolTipBehavior *recentFileActionBehaviors[MaxRecentFiles];
121     QAction *separatorAction;
122 
123     QMenu *fileMenu;
124     QMenu *editMenu;
125     QMenu *viewMenu;
126     QMenu *toolsMenu;
127     QMenu *helpMenu;
128 
129     InfoLine *infoLine;
130     QLabel* lineNbField;
131     QToolBar *toolBar;
132 
133     QAction *openAction;
134     QAction *exitAction;
135     QAction *copyAction;
136     QAction *selectAllAction;
137     QAction *findAction;
138     QAction *overviewVisibleAction;
139     QAction *lineNumbersVisibleInMainAction;
140     QAction *lineNumbersVisibleInFilteredAction;
141     QAction *followAction;
142     QAction *reloadAction;
143     QAction *stopAction;
144     QAction *filtersAction;
145     QAction *optionsAction;
146     QAction *aboutAction;
147     QAction *aboutQtAction;
148 
149     QIcon mainIcon_;
150 };
151 
152 #endif
153