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