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 // Loads the initial file (parameter passed or from config file) 51 void loadInitialFile( QString fileName ); 52 53 protected: 54 void closeEvent( QCloseEvent* event ); 55 // Drag and drop support 56 void dragEnterEvent( QDragEnterEvent* event ); 57 void dropEvent( QDropEvent* event ); 58 void keyPressEvent( QKeyEvent* keyEvent ); 59 60 private slots: 61 void open(); 62 void openRecentFile(); 63 void selectAll(); 64 void copy(); 65 void find(); 66 void filters(); 67 void options(); 68 void about(); 69 void aboutQt(); 70 71 // Change the view settings 72 void toggleOverviewVisibility( bool isVisible ); 73 void toggleMainLineNumbersVisibility( bool isVisible ); 74 void toggleFilteredLineNumbersVisibility( bool isVisible ); 75 76 // Disable the follow mode checkbox and send the followSet signal down 77 void disableFollow(); 78 79 // Update the line number displayed in the status bar. 80 // Must be passed as the internal (starts at 0) line number. 81 void lineNumberHandler( int line ); 82 83 // Instructs the widget to update the loading progress gauge 84 void updateLoadingProgress( int progress ); 85 // Instructs the widget to display the 'normal' status bar, 86 // without the progress gauge and with file info 87 void displayNormalStatus( bool success ); 88 89 // Close the tab with the passed index 90 void closeTab( int index ); 91 92 // Instructs the widget to change the pattern in the QuickFind widget 93 // and confirm it. 94 void changeQFPattern( const QString& newPattern ); 95 96 signals: 97 // Is emitted when new settings must be used 98 void optionsChanged(); 99 // Is emitted when the 'follow' option is enabled/disabled 100 void followSet( bool checked ); 101 // Is emitted before the QuickFind box is activated, 102 // to allow crawlers to get search in the right view. 103 void enteringQuickFind(); 104 // Emitted when the quickfind bar is closed. 105 void exitingQuickFind(); 106 107 private: 108 void createActions(); 109 void createMenus(); 110 void createContextMenu(); 111 void createToolBars(); 112 void createStatusBar(); 113 void createRecentFileToolTipTimer(); 114 void readSettings(); 115 void writeSettings(); 116 bool loadFile( const QString& fileName ); 117 void setCurrentFile( const QString& fileName ); 118 void updateRecentFileActions(); 119 QString strippedName( const QString& fullFileName ) const; 120 CrawlerWidget* currentCrawlerWidget() const; 121 void displayQuickFindBar( QuickFindMux::QFDirection direction ); 122 123 std::unique_ptr<Session> session_; 124 RecentFiles& recentFiles; 125 QString loadingFileName; 126 QString currentFile; 127 QString previousFile; 128 129 enum { MaxRecentFiles = 5 }; 130 QAction *recentFileActions[MaxRecentFiles]; 131 MenuActionToolTipBehavior *recentFileActionBehaviors[MaxRecentFiles]; 132 QAction *separatorAction; 133 134 QMenu *fileMenu; 135 QMenu *editMenu; 136 QMenu *viewMenu; 137 QMenu *toolsMenu; 138 QMenu *helpMenu; 139 140 InfoLine *infoLine; 141 QLabel* lineNbField; 142 QToolBar *toolBar; 143 144 QAction *openAction; 145 QAction *exitAction; 146 QAction *copyAction; 147 QAction *selectAllAction; 148 QAction *findAction; 149 QAction *overviewVisibleAction; 150 QAction *lineNumbersVisibleInMainAction; 151 QAction *lineNumbersVisibleInFilteredAction; 152 QAction *followAction; 153 QAction *reloadAction; 154 QAction *stopAction; 155 QAction *filtersAction; 156 QAction *optionsAction; 157 QAction *aboutAction; 158 QAction *aboutQtAction; 159 160 QIcon mainIcon_; 161 162 // Multiplex signals to any of the CrawlerWidgets 163 SignalMux signalMux_; 164 165 // QuickFind widget 166 QuickFindWidget quickFindWidget_; 167 168 // Multiplex signals to/from the QuickFindWidget 169 QuickFindMux quickFindMux_; 170 171 // The main widget 172 TabbedCrawlerWidget mainTabWidget_; 173 }; 174 175 #endif 176