1bb02e0acSNicolas Bonnefon /* 2093a1bf6SNicolas Bonnefon * Copyright (C) 2009, 2010, 2011, 2013, 2014 Nicolas Bonnefon and other contributors 3bb02e0acSNicolas Bonnefon * 4bb02e0acSNicolas Bonnefon * This file is part of glogg. 5bb02e0acSNicolas Bonnefon * 6bb02e0acSNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify 7bb02e0acSNicolas Bonnefon * it under the terms of the GNU General Public License as published by 8bb02e0acSNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or 9bb02e0acSNicolas Bonnefon * (at your option) any later version. 10bb02e0acSNicolas Bonnefon * 11bb02e0acSNicolas Bonnefon * glogg is distributed in the hope that it will be useful, 12bb02e0acSNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of 13bb02e0acSNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14bb02e0acSNicolas Bonnefon * GNU General Public License for more details. 15bb02e0acSNicolas Bonnefon * 16bb02e0acSNicolas Bonnefon * You should have received a copy of the GNU General Public License 17bb02e0acSNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>. 18bb02e0acSNicolas Bonnefon */ 19bb02e0acSNicolas Bonnefon 20bb02e0acSNicolas Bonnefon #ifndef MAINWINDOW_H 21bb02e0acSNicolas Bonnefon #define MAINWINDOW_H 22bb02e0acSNicolas Bonnefon 23d96f3f21SNicolas Bonnefon #include <memory> 24bb02e0acSNicolas Bonnefon #include <QMainWindow> 25d96f3f21SNicolas Bonnefon 26d96f3f21SNicolas Bonnefon #include "session.h" 27bb02e0acSNicolas Bonnefon #include "crawlerwidget.h" 28bb02e0acSNicolas Bonnefon #include "infoline.h" 29313a820fSNicolas Bonnefon #include "signalmux.h" 30093a1bf6SNicolas Bonnefon #include "tabbedcrawlerwidget.h" 31b423cd88SNicolas Bonnefon #include "quickfindwidget.h" 32b423cd88SNicolas Bonnefon #include "quickfindmux.h" 33bb02e0acSNicolas Bonnefon 34bb02e0acSNicolas Bonnefon class QAction; 35d96f3f21SNicolas Bonnefon class Session; 36bb02e0acSNicolas Bonnefon class RecentFiles; 37bb02e0acSNicolas Bonnefon class MenuActionToolTipBehavior; 3809aff35dSNicolas Bonnefon class ExternalCommunicator; 39bb02e0acSNicolas Bonnefon 40bb02e0acSNicolas Bonnefon // Main window of the application, creates menus, toolbar and 41bb02e0acSNicolas Bonnefon // the CrawlerWidget 42bb02e0acSNicolas Bonnefon class MainWindow : public QMainWindow 43bb02e0acSNicolas Bonnefon { 44bb02e0acSNicolas Bonnefon Q_OBJECT 45bb02e0acSNicolas Bonnefon 46bb02e0acSNicolas Bonnefon public: 47d96f3f21SNicolas Bonnefon // Constructor 48d96f3f21SNicolas Bonnefon // The ownership of the session is transferred to us 4909aff35dSNicolas Bonnefon MainWindow( std::unique_ptr<Session> session, 5009aff35dSNicolas Bonnefon std::shared_ptr<ExternalCommunicator> external_communicator ); 51bb02e0acSNicolas Bonnefon 528964a9adSNicolas Bonnefon // Re-load the files from the previous session 538964a9adSNicolas Bonnefon void reloadSession(); 54bb02e0acSNicolas Bonnefon // Loads the initial file (parameter passed or from config file) 55bb02e0acSNicolas Bonnefon void loadInitialFile( QString fileName ); 56*8a9275b2SNicolas Bonnefon // Starts the lower priority activities the MW controls such as 57*8a9275b2SNicolas Bonnefon // version checking etc... 58*8a9275b2SNicolas Bonnefon void startBackgroundTasks(); 59bb02e0acSNicolas Bonnefon 60bb02e0acSNicolas Bonnefon protected: 61bb02e0acSNicolas Bonnefon void closeEvent( QCloseEvent* event ); 62bb02e0acSNicolas Bonnefon // Drag and drop support 63bb02e0acSNicolas Bonnefon void dragEnterEvent( QDragEnterEvent* event ); 64bb02e0acSNicolas Bonnefon void dropEvent( QDropEvent* event ); 658570d8d2SNicolas Bonnefon void keyPressEvent( QKeyEvent* keyEvent ); 66bb02e0acSNicolas Bonnefon 67bb02e0acSNicolas Bonnefon private slots: 68bb02e0acSNicolas Bonnefon void open(); 69bb02e0acSNicolas Bonnefon void openRecentFile(); 70bb02e0acSNicolas Bonnefon void selectAll(); 71bb02e0acSNicolas Bonnefon void copy(); 72bb02e0acSNicolas Bonnefon void find(); 73bb02e0acSNicolas Bonnefon void filters(); 74bb02e0acSNicolas Bonnefon void options(); 75bb02e0acSNicolas Bonnefon void about(); 76bb02e0acSNicolas Bonnefon void aboutQt(); 77bb02e0acSNicolas Bonnefon 78bb02e0acSNicolas Bonnefon // Change the view settings 79bb02e0acSNicolas Bonnefon void toggleOverviewVisibility( bool isVisible ); 80bb02e0acSNicolas Bonnefon void toggleMainLineNumbersVisibility( bool isVisible ); 81bb02e0acSNicolas Bonnefon void toggleFilteredLineNumbersVisibility( bool isVisible ); 82bb02e0acSNicolas Bonnefon 83bb02e0acSNicolas Bonnefon // Disable the follow mode checkbox and send the followSet signal down 84bb02e0acSNicolas Bonnefon void disableFollow(); 85bb02e0acSNicolas Bonnefon 86bb02e0acSNicolas Bonnefon // Update the line number displayed in the status bar. 87bb02e0acSNicolas Bonnefon // Must be passed as the internal (starts at 0) line number. 88bb02e0acSNicolas Bonnefon void lineNumberHandler( int line ); 89bb02e0acSNicolas Bonnefon 90bb02e0acSNicolas Bonnefon // Instructs the widget to update the loading progress gauge 91bb02e0acSNicolas Bonnefon void updateLoadingProgress( int progress ); 92bb02e0acSNicolas Bonnefon // Instructs the widget to display the 'normal' status bar, 93bb02e0acSNicolas Bonnefon // without the progress gauge and with file info 94812146a8SNicolas Bonnefon // or an error recovery when loading is finished 95812146a8SNicolas Bonnefon void handleLoadingFinished( LoadingStatus status ); 96bb02e0acSNicolas Bonnefon 97cdd89779SNicolas Bonnefon // Close the tab with the passed index 98cdd89779SNicolas Bonnefon void closeTab( int index ); 99ee835f33SNicolas Bonnefon // Setup the tab with current index for view 100ee835f33SNicolas Bonnefon void currentTabChanged( int index ); 101bb02e0acSNicolas Bonnefon 1028570d8d2SNicolas Bonnefon // Instructs the widget to change the pattern in the QuickFind widget 1038570d8d2SNicolas Bonnefon // and confirm it. 1048570d8d2SNicolas Bonnefon void changeQFPattern( const QString& newPattern ); 1058570d8d2SNicolas Bonnefon 10609aff35dSNicolas Bonnefon // Load a file in a new tab (non-interactive) 10709aff35dSNicolas Bonnefon // (for use from e.g. IPC) 10809aff35dSNicolas Bonnefon void loadFileNonInteractive( const QString& file_name ); 10909aff35dSNicolas Bonnefon 110bb02e0acSNicolas Bonnefon signals: 111bb02e0acSNicolas Bonnefon // Is emitted when new settings must be used 112bb02e0acSNicolas Bonnefon void optionsChanged(); 113bb02e0acSNicolas Bonnefon // Is emitted when the 'follow' option is enabled/disabled 114bb02e0acSNicolas Bonnefon void followSet( bool checked ); 1158570d8d2SNicolas Bonnefon // Is emitted before the QuickFind box is activated, 1168570d8d2SNicolas Bonnefon // to allow crawlers to get search in the right view. 1178570d8d2SNicolas Bonnefon void enteringQuickFind(); 1188570d8d2SNicolas Bonnefon // Emitted when the quickfind bar is closed. 1198570d8d2SNicolas Bonnefon void exitingQuickFind(); 120bb02e0acSNicolas Bonnefon 121bb02e0acSNicolas Bonnefon private: 122bb02e0acSNicolas Bonnefon void createActions(); 123bb02e0acSNicolas Bonnefon void createMenus(); 124bb02e0acSNicolas Bonnefon void createContextMenu(); 125bb02e0acSNicolas Bonnefon void createToolBars(); 126bb02e0acSNicolas Bonnefon void createStatusBar(); 127bb02e0acSNicolas Bonnefon void createRecentFileToolTipTimer(); 128bb02e0acSNicolas Bonnefon void readSettings(); 129bb02e0acSNicolas Bonnefon void writeSettings(); 130bb02e0acSNicolas Bonnefon bool loadFile( const QString& fileName ); 1310e97f16dSNicolas Bonnefon void updateTitleBar( const QString& file_name ); 132bb02e0acSNicolas Bonnefon void updateRecentFileActions(); 133bb02e0acSNicolas Bonnefon QString strippedName( const QString& fullFileName ) const; 13427ddfd3aSNicolas Bonnefon CrawlerWidget* currentCrawlerWidget() const; 135b423cd88SNicolas Bonnefon void displayQuickFindBar( QuickFindMux::QFDirection direction ); 136bb02e0acSNicolas Bonnefon 137d96f3f21SNicolas Bonnefon std::unique_ptr<Session> session_; 13809aff35dSNicolas Bonnefon std::shared_ptr<ExternalCommunicator> externalCommunicator_; 13911582726SNicolas Bonnefon std::shared_ptr<RecentFiles> recentFiles_; 140bb02e0acSNicolas Bonnefon QString loadingFileName; 141bb02e0acSNicolas Bonnefon 142bb02e0acSNicolas Bonnefon enum { MaxRecentFiles = 5 }; 143bb02e0acSNicolas Bonnefon QAction *recentFileActions[MaxRecentFiles]; 144bb02e0acSNicolas Bonnefon MenuActionToolTipBehavior *recentFileActionBehaviors[MaxRecentFiles]; 145bb02e0acSNicolas Bonnefon QAction *separatorAction; 146bb02e0acSNicolas Bonnefon 147bb02e0acSNicolas Bonnefon QMenu *fileMenu; 148bb02e0acSNicolas Bonnefon QMenu *editMenu; 149bb02e0acSNicolas Bonnefon QMenu *viewMenu; 150bb02e0acSNicolas Bonnefon QMenu *toolsMenu; 151bb02e0acSNicolas Bonnefon QMenu *helpMenu; 152bb02e0acSNicolas Bonnefon 153bb02e0acSNicolas Bonnefon InfoLine *infoLine; 154bb02e0acSNicolas Bonnefon QLabel* lineNbField; 155bb02e0acSNicolas Bonnefon QToolBar *toolBar; 156bb02e0acSNicolas Bonnefon 157bb02e0acSNicolas Bonnefon QAction *openAction; 158bb02e0acSNicolas Bonnefon QAction *exitAction; 159bb02e0acSNicolas Bonnefon QAction *copyAction; 160bb02e0acSNicolas Bonnefon QAction *selectAllAction; 161bb02e0acSNicolas Bonnefon QAction *findAction; 162bb02e0acSNicolas Bonnefon QAction *overviewVisibleAction; 163bb02e0acSNicolas Bonnefon QAction *lineNumbersVisibleInMainAction; 164bb02e0acSNicolas Bonnefon QAction *lineNumbersVisibleInFilteredAction; 165bb02e0acSNicolas Bonnefon QAction *followAction; 166bb02e0acSNicolas Bonnefon QAction *reloadAction; 167bb02e0acSNicolas Bonnefon QAction *stopAction; 168bb02e0acSNicolas Bonnefon QAction *filtersAction; 169bb02e0acSNicolas Bonnefon QAction *optionsAction; 170bb02e0acSNicolas Bonnefon QAction *aboutAction; 171bb02e0acSNicolas Bonnefon QAction *aboutQtAction; 172bb02e0acSNicolas Bonnefon 173bb02e0acSNicolas Bonnefon QIcon mainIcon_; 174313a820fSNicolas Bonnefon 175313a820fSNicolas Bonnefon // Multiplex signals to any of the CrawlerWidgets 176313a820fSNicolas Bonnefon SignalMux signalMux_; 17727ddfd3aSNicolas Bonnefon 178b423cd88SNicolas Bonnefon // QuickFind widget 179b423cd88SNicolas Bonnefon QuickFindWidget quickFindWidget_; 180b423cd88SNicolas Bonnefon 181b423cd88SNicolas Bonnefon // Multiplex signals to/from the QuickFindWidget 182b423cd88SNicolas Bonnefon QuickFindMux quickFindMux_; 183b423cd88SNicolas Bonnefon 18427ddfd3aSNicolas Bonnefon // The main widget 185093a1bf6SNicolas Bonnefon TabbedCrawlerWidget mainTabWidget_; 186bb02e0acSNicolas Bonnefon }; 187bb02e0acSNicolas Bonnefon 188bb02e0acSNicolas Bonnefon #endif 189