1*bb02e0acSNicolas Bonnefon /* 2*bb02e0acSNicolas Bonnefon * Copyright (C) 2011, 2012 Nicolas Bonnefon and other contributors 3*bb02e0acSNicolas Bonnefon * 4*bb02e0acSNicolas Bonnefon * This file is part of glogg. 5*bb02e0acSNicolas Bonnefon * 6*bb02e0acSNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify 7*bb02e0acSNicolas Bonnefon * it under the terms of the GNU General Public License as published by 8*bb02e0acSNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or 9*bb02e0acSNicolas Bonnefon * (at your option) any later version. 10*bb02e0acSNicolas Bonnefon * 11*bb02e0acSNicolas Bonnefon * glogg is distributed in the hope that it will be useful, 12*bb02e0acSNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of 13*bb02e0acSNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*bb02e0acSNicolas Bonnefon * GNU General Public License for more details. 15*bb02e0acSNicolas Bonnefon * 16*bb02e0acSNicolas Bonnefon * You should have received a copy of the GNU General Public License 17*bb02e0acSNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>. 18*bb02e0acSNicolas Bonnefon */ 19*bb02e0acSNicolas Bonnefon 20*bb02e0acSNicolas Bonnefon #ifndef OVERVIEW_H 21*bb02e0acSNicolas Bonnefon #define OVERVIEW_H 22*bb02e0acSNicolas Bonnefon 23*bb02e0acSNicolas Bonnefon #include <QList> 24*bb02e0acSNicolas Bonnefon #include <QVector> 25*bb02e0acSNicolas Bonnefon 26*bb02e0acSNicolas Bonnefon class LogFilteredData; 27*bb02e0acSNicolas Bonnefon 28*bb02e0acSNicolas Bonnefon // Class implementing the logic behind the matches overview bar. 29*bb02e0acSNicolas Bonnefon // This class converts the matches found in a LogFilteredData in 30*bb02e0acSNicolas Bonnefon // a screen dependent set of coloured lines, which is cached. 31*bb02e0acSNicolas Bonnefon // This class is not a UI class, actual display is left to the client. 32*bb02e0acSNicolas Bonnefon // 33*bb02e0acSNicolas Bonnefon // This class is NOT thread-safe. 34*bb02e0acSNicolas Bonnefon class Overview 35*bb02e0acSNicolas Bonnefon { 36*bb02e0acSNicolas Bonnefon public: 37*bb02e0acSNicolas Bonnefon // A line with a position in pixel and a weight (darkness) 38*bb02e0acSNicolas Bonnefon class WeightedLine { 39*bb02e0acSNicolas Bonnefon public: 40*bb02e0acSNicolas Bonnefon static const int WEIGHT_STEPS = 3; 41*bb02e0acSNicolas Bonnefon WeightedLine()42*bb02e0acSNicolas Bonnefon WeightedLine() { pos_ = 0; weight_ = 0; } 43*bb02e0acSNicolas Bonnefon // (Necessary for QVector) WeightedLine(int pos)44*bb02e0acSNicolas Bonnefon WeightedLine( int pos ) { pos_ = pos; weight_ = 0; } 45*bb02e0acSNicolas Bonnefon position()46*bb02e0acSNicolas Bonnefon int position() const { return pos_; } weight()47*bb02e0acSNicolas Bonnefon int weight() const { return weight_; } 48*bb02e0acSNicolas Bonnefon load()49*bb02e0acSNicolas Bonnefon void load() { weight_ = qMin( weight_ + 1, WEIGHT_STEPS - 1 ); } 50*bb02e0acSNicolas Bonnefon 51*bb02e0acSNicolas Bonnefon private: 52*bb02e0acSNicolas Bonnefon int pos_; 53*bb02e0acSNicolas Bonnefon int weight_; 54*bb02e0acSNicolas Bonnefon }; 55*bb02e0acSNicolas Bonnefon 56*bb02e0acSNicolas Bonnefon Overview(); 57*bb02e0acSNicolas Bonnefon ~Overview(); 58*bb02e0acSNicolas Bonnefon 59*bb02e0acSNicolas Bonnefon // Associate the passed filteredData to this Overview 60*bb02e0acSNicolas Bonnefon void setFilteredData( const LogFilteredData* logFilteredData ); 61*bb02e0acSNicolas Bonnefon // Signal the overview its attached LogFilteredData has been changed and 62*bb02e0acSNicolas Bonnefon // the overview must be updated with the provided total number 63*bb02e0acSNicolas Bonnefon // of line of the file. 64*bb02e0acSNicolas Bonnefon void updateData( int totalNbLine ); 65*bb02e0acSNicolas Bonnefon // Set the visibility flag of this overview. setVisible(bool visible)66*bb02e0acSNicolas Bonnefon void setVisible( bool visible ) { visible_ = visible; dirty_ = visible; } 67*bb02e0acSNicolas Bonnefon 68*bb02e0acSNicolas Bonnefon // Update the current position in the file (to draw the view line) updateCurrentPosition(int firstLine,int lastLine)69*bb02e0acSNicolas Bonnefon void updateCurrentPosition( int firstLine, int lastLine ) 70*bb02e0acSNicolas Bonnefon { topLine_ = firstLine; nbLines_ = lastLine - firstLine; } 71*bb02e0acSNicolas Bonnefon 72*bb02e0acSNicolas Bonnefon // Returns weither this overview is visible. isVisible()73*bb02e0acSNicolas Bonnefon bool isVisible() { return visible_; } 74*bb02e0acSNicolas Bonnefon // Signal the overview the height of the display has changed, triggering 75*bb02e0acSNicolas Bonnefon // an update of its cache. 76*bb02e0acSNicolas Bonnefon void updateView( int height ); 77*bb02e0acSNicolas Bonnefon // Returns a list of lines (between 0 and 'height') representing matches. 78*bb02e0acSNicolas Bonnefon // (pointer returned is valid until next call to update*() 79*bb02e0acSNicolas Bonnefon const QVector<WeightedLine>* getMatchLines() const; 80*bb02e0acSNicolas Bonnefon // Returns a list of lines (between 0 and 'height') representing marks. 81*bb02e0acSNicolas Bonnefon // (pointer returned is valid until next call to update*() 82*bb02e0acSNicolas Bonnefon const QVector<WeightedLine>* getMarkLines() const; 83*bb02e0acSNicolas Bonnefon // Return a pair of lines (between 0 and 'height') representing the current view. 84*bb02e0acSNicolas Bonnefon std::pair<int,int> getViewLines() const; 85*bb02e0acSNicolas Bonnefon 86*bb02e0acSNicolas Bonnefon // Return the line number corresponding to the passed overview y coordinate. 87*bb02e0acSNicolas Bonnefon int fileLineFromY( int y ) const; 88*bb02e0acSNicolas Bonnefon // Return the y coordinate corresponding to the passed line number. 89*bb02e0acSNicolas Bonnefon int yFromFileLine( int file_line ) const; 90*bb02e0acSNicolas Bonnefon 91*bb02e0acSNicolas Bonnefon private: 92*bb02e0acSNicolas Bonnefon // List of matches associated with this Overview. 93*bb02e0acSNicolas Bonnefon const LogFilteredData* logFilteredData_; 94*bb02e0acSNicolas Bonnefon // Total number of lines in the file. 95*bb02e0acSNicolas Bonnefon int linesInFile_; 96*bb02e0acSNicolas Bonnefon // Whether the overview is visible. 97*bb02e0acSNicolas Bonnefon bool visible_; 98*bb02e0acSNicolas Bonnefon // First and last line currently viewed. 99*bb02e0acSNicolas Bonnefon int topLine_; 100*bb02e0acSNicolas Bonnefon int nbLines_; 101*bb02e0acSNicolas Bonnefon // Current height of view window. 102*bb02e0acSNicolas Bonnefon int height_; 103*bb02e0acSNicolas Bonnefon // Does the cache (matchesLines, markLines) need to be recalculated. 104*bb02e0acSNicolas Bonnefon int dirty_; 105*bb02e0acSNicolas Bonnefon 106*bb02e0acSNicolas Bonnefon // List of lines representing matches and marks (are shared with the client) 107*bb02e0acSNicolas Bonnefon QVector<WeightedLine> matchLines_; 108*bb02e0acSNicolas Bonnefon QVector<WeightedLine> markLines_; 109*bb02e0acSNicolas Bonnefon 110*bb02e0acSNicolas Bonnefon void recalculatesLines(); 111*bb02e0acSNicolas Bonnefon }; 112*bb02e0acSNicolas Bonnefon 113*bb02e0acSNicolas Bonnefon #endif 114