1bb02e0acSNicolas Bonnefon /* 2*8e788202SNicolas Bonnefon * Copyright (C) 2009, 2010, 2011, 2013, 2017 Nicolas Bonnefon 3bb02e0acSNicolas Bonnefon * and other contributors 4bb02e0acSNicolas Bonnefon * 5bb02e0acSNicolas Bonnefon * This file is part of glogg. 6bb02e0acSNicolas Bonnefon * 7bb02e0acSNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify 8bb02e0acSNicolas Bonnefon * it under the terms of the GNU General Public License as published by 9bb02e0acSNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or 10bb02e0acSNicolas Bonnefon * (at your option) any later version. 11bb02e0acSNicolas Bonnefon * 12bb02e0acSNicolas Bonnefon * glogg is distributed in the hope that it will be useful, 13bb02e0acSNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of 14bb02e0acSNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15bb02e0acSNicolas Bonnefon * GNU General Public License for more details. 16bb02e0acSNicolas Bonnefon * 17bb02e0acSNicolas Bonnefon * You should have received a copy of the GNU General Public License 18bb02e0acSNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>. 19bb02e0acSNicolas Bonnefon */ 20bb02e0acSNicolas Bonnefon 21bb02e0acSNicolas Bonnefon // This file implements the LogMainView concrete class. 22bb02e0acSNicolas Bonnefon // Most of the actual drawing and event management is done in AbstractLogView 23bb02e0acSNicolas Bonnefon // Only behaviour specific to the main (top) view is implemented here. 24bb02e0acSNicolas Bonnefon 25bb02e0acSNicolas Bonnefon #include "logmainview.h" 26bb02e0acSNicolas Bonnefon 27bb02e0acSNicolas Bonnefon #include "data/logfiltereddata.h" 28bb02e0acSNicolas Bonnefon #include "overview.h" 29bb02e0acSNicolas Bonnefon 30*8e788202SNicolas Bonnefon #include <QKeyEvent> 31*8e788202SNicolas Bonnefon 32bb02e0acSNicolas Bonnefon LogMainView::LogMainView( const LogData* newLogData, 33bb02e0acSNicolas Bonnefon const QuickFindPattern* const quickFindPattern, 34bb02e0acSNicolas Bonnefon Overview* overview, 35bb02e0acSNicolas Bonnefon OverviewWidget* overview_widget, 36bb02e0acSNicolas Bonnefon QWidget* parent) 37bb02e0acSNicolas Bonnefon : AbstractLogView( newLogData, quickFindPattern, parent ) 38bb02e0acSNicolas Bonnefon { 39bb02e0acSNicolas Bonnefon filteredData_ = NULL; 40bb02e0acSNicolas Bonnefon 41bb02e0acSNicolas Bonnefon // The main data has a real (non NULL) Overview 42bb02e0acSNicolas Bonnefon setOverview( overview, overview_widget ); 43bb02e0acSNicolas Bonnefon } 44bb02e0acSNicolas Bonnefon 45bb02e0acSNicolas Bonnefon // Just update our internal record. 46bb02e0acSNicolas Bonnefon void LogMainView::useNewFiltering( LogFilteredData* filteredData ) 47bb02e0acSNicolas Bonnefon { 48bb02e0acSNicolas Bonnefon filteredData_ = filteredData; 49bb02e0acSNicolas Bonnefon 50bb02e0acSNicolas Bonnefon if ( getOverview() != NULL ) 51bb02e0acSNicolas Bonnefon getOverview()->setFilteredData( filteredData_ ); 52bb02e0acSNicolas Bonnefon } 53bb02e0acSNicolas Bonnefon 54bb02e0acSNicolas Bonnefon AbstractLogView::LineType LogMainView::lineType( int lineNumber ) const 55bb02e0acSNicolas Bonnefon { 56bb02e0acSNicolas Bonnefon if ( filteredData_ != NULL ) { 57bb02e0acSNicolas Bonnefon LineType line_type; 58bb02e0acSNicolas Bonnefon if ( filteredData_->isLineMarked( lineNumber ) ) 59bb02e0acSNicolas Bonnefon line_type = Marked; 60bb02e0acSNicolas Bonnefon else if ( filteredData_->isLineInMatchingList( lineNumber ) ) 61bb02e0acSNicolas Bonnefon line_type = Match; 62bb02e0acSNicolas Bonnefon else 63bb02e0acSNicolas Bonnefon line_type = Normal; 64bb02e0acSNicolas Bonnefon 65bb02e0acSNicolas Bonnefon return line_type; 66bb02e0acSNicolas Bonnefon } 67bb02e0acSNicolas Bonnefon else 68bb02e0acSNicolas Bonnefon return Normal; 69bb02e0acSNicolas Bonnefon } 70*8e788202SNicolas Bonnefon 71*8e788202SNicolas Bonnefon void LogMainView::keyPressEvent( QKeyEvent* keyEvent ) 72*8e788202SNicolas Bonnefon { 73*8e788202SNicolas Bonnefon bool shiftModifier = (keyEvent->modifiers() & Qt::ShiftModifier) == Qt::ShiftModifier; 74*8e788202SNicolas Bonnefon bool noModifier = keyEvent->modifiers() == Qt::NoModifier; 75*8e788202SNicolas Bonnefon 76*8e788202SNicolas Bonnefon if ( keyEvent->key() == Qt::Key_BracketLeft && noModifier ) { 77*8e788202SNicolas Bonnefon qint64 line = filteredData_->getMarkBefore( getViewPosition() ); 78*8e788202SNicolas Bonnefon if ( line >= 0 ) { 79*8e788202SNicolas Bonnefon selectAndDisplayLine( static_cast<LineNumber>( line ) ); 80*8e788202SNicolas Bonnefon } 81*8e788202SNicolas Bonnefon keyEvent->accept(); 82*8e788202SNicolas Bonnefon } 83*8e788202SNicolas Bonnefon else if ( keyEvent->key() == Qt::Key_BracketRight && noModifier ) { 84*8e788202SNicolas Bonnefon qint64 line = filteredData_->getMarkAfter( getViewPosition() ); 85*8e788202SNicolas Bonnefon if ( line >= 0 ) { 86*8e788202SNicolas Bonnefon selectAndDisplayLine( static_cast<LineNumber>( line ) ); 87*8e788202SNicolas Bonnefon } 88*8e788202SNicolas Bonnefon keyEvent->accept(); 89*8e788202SNicolas Bonnefon } 90*8e788202SNicolas Bonnefon else { 91*8e788202SNicolas Bonnefon keyEvent->ignore(); 92*8e788202SNicolas Bonnefon AbstractLogView::keyPressEvent( keyEvent ); 93*8e788202SNicolas Bonnefon } 94*8e788202SNicolas Bonnefon } 95