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 filters(); 63 void options(); 64 void about(); 65 void aboutQt(); 66 67 // Change the view settings 68 void toggleOverviewVisibility( bool isVisible ); 69 void toggleMainLineNumbersVisibility( bool isVisible ); 70 void toggleFilteredLineNumbersVisibility( bool isVisible ); 71 72 // Disable the follow mode checkbox and send the followSet signal down 73 void disableFollow(); 74 75 // Update the line number displayed in the status bar. 76 // Must be passed as the internal (starts at 0) line number. 77 void lineNumberHandler( int line ); 78 79 // Instructs the widget to update the loading progress gauge 80 void updateLoadingProgress( int progress ); 81 // Instructs the widget to display the 'normal' status bar, 82 // without the progress gauge and with file info 83 void displayNormalStatus( bool success ); 84 85 86 signals: 87 // Is emitted when new settings must be used 88 void optionsChanged(); 89 // Is emitted when the 'follow' option is enabled/disabled 90 void followSet( bool checked ); 91 92 private: 93 void createActions(); 94 void createMenus(); 95 void createContextMenu(); 96 void createToolBars(); 97 void createStatusBar(); 98 void createRecentFileToolTipTimer(); 99 void readSettings(); 100 void writeSettings(); 101 bool loadFile( const QString& fileName ); 102 void setCurrentFile( const QString& fileName ); 103 void updateRecentFileActions(); 104 QString strippedName( const QString& fullFileName ) const; 105 106 std::unique_ptr<Session> session_; 107 SavedSearches *savedSearches; 108 CrawlerWidget *crawlerWidget; 109 RecentFiles& recentFiles; 110 QString loadingFileName; 111 QString currentFile; 112 QString previousFile; 113 114 enum { MaxRecentFiles = 5 }; 115 QAction *recentFileActions[MaxRecentFiles]; 116 MenuActionToolTipBehavior *recentFileActionBehaviors[MaxRecentFiles]; 117 QAction *separatorAction; 118 119 QMenu *fileMenu; 120 QMenu *editMenu; 121 QMenu *viewMenu; 122 QMenu *toolsMenu; 123 QMenu *helpMenu; 124 125 InfoLine *infoLine; 126 QLabel* lineNbField; 127 QToolBar *toolBar; 128 129 QAction *openAction; 130 QAction *exitAction; 131 QAction *copyAction; 132 QAction *selectAllAction; 133 QAction *findAction; 134 QAction *overviewVisibleAction; 135 QAction *lineNumbersVisibleInMainAction; 136 QAction *lineNumbersVisibleInFilteredAction; 137 QAction *followAction; 138 QAction *reloadAction; 139 QAction *stopAction; 140 QAction *filtersAction; 141 QAction *optionsAction; 142 QAction *aboutAction; 143 QAction *aboutQtAction; 144 145 QIcon mainIcon_; 146 147 // Multiplex signals to any of the CrawlerWidgets 148 SignalMux signalMux_; 149 }; 150 151 #endif 152