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 #include <QTabWidget> 26 27 #include "session.h" 28 #include "crawlerwidget.h" 29 #include "infoline.h" 30 #include "signalmux.h" 31 32 class QAction; 33 class Session; 34 class RecentFiles; 35 class MenuActionToolTipBehavior; 36 37 // Main window of the application, creates menus, toolbar and 38 // the CrawlerWidget 39 class MainWindow : public QMainWindow 40 { 41 Q_OBJECT 42 43 public: 44 // Constructor 45 // The ownership of the session is transferred to us 46 MainWindow( std::unique_ptr<Session> session ); 47 48 // Loads the initial file (parameter passed or from config file) 49 void loadInitialFile( QString fileName ); 50 51 protected: 52 void closeEvent( QCloseEvent* event ); 53 // Drag and drop support 54 void dragEnterEvent( QDragEnterEvent* event ); 55 void dropEvent( QDropEvent* event ); 56 57 private slots: 58 void open(); 59 void openRecentFile(); 60 void selectAll(); 61 void copy(); 62 void find(); 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 CrawlerWidget* currentCrawlerWidget() const; 107 108 std::unique_ptr<Session> session_; 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 // The main widget 151 QTabWidget mainTabWidget_; 152 }; 153 154 #endif 155