xref: /glogg/src/logmainview.cpp (revision 8b941e123ddc1953f679547d44fb51d36b42e416) !
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 noModifier = keyEvent->modifiers() == Qt::NoModifier;
74 
75     if ( keyEvent->key() == Qt::Key_BracketLeft && noModifier ) {
76         qint64 line = filteredData_->getMarkBefore( getViewPosition() );
77         if ( line >= 0 ) {
78             selectAndDisplayLine( static_cast<LineNumber>( line ) );
79         }
80         keyEvent->accept();
81     }
82     else if ( keyEvent->key() == Qt::Key_BracketRight && noModifier ) {
83         qint64 line = filteredData_->getMarkAfter( getViewPosition() );
84         if ( line >= 0 ) {
85             selectAndDisplayLine( static_cast<LineNumber>( line ) );
86         }
87         keyEvent->accept();
88     }
89     else {
90         keyEvent->ignore();
91         AbstractLogView::keyPressEvent( keyEvent );
92     }
93 }
94