kviewshell
selection.h
Go to the documentation of this file.00001 // -*- C++ -*- 00002 // 00003 // selection.h 00004 // 00005 // (C) 2001-20004 Stefan Kebekus 00006 // Distributed under the GPL 00007 00008 #ifndef selection_h 00009 #define selection_h 00010 00011 #include "pageNumber.h" 00012 00013 #include <qstring.h> 00014 00015 00016 /* The --very simple-- class TextSelection represents text that the 00017 user has selected on a certain page of a document. The class stores 00018 00019 the page number, 00020 00021 two Q_INT32 numbers, 'selectedTextStart' and 'selectedTextEnd' that 00022 should hold indiced referring to the start and the end of the 00023 selected text in the appropriate documentPage's textLinkList 00024 00025 a QString, 'selectedText' that holds the text that is selected 00026 00027 these values can be stored, retrieved, it can be checked if the 00028 selection is empty, and signals are emitted when the values change 00029 */ 00030 00031 class TextSelection 00032 { 00033 00034 public: 00035 // Constructs an empty selection with an invalid page number, and an 00036 // empty text string. The values 'selectedTextStart' and 00037 // 'selectedTextEnd' are set to 0. None of the signals pageChanged() 00038 // or selectionIsNotEmpty() is emitted at construction time 00039 TextSelection(); 00040 00041 void clear(); 00042 00043 // Use this method to set the data that is described above. Note 00044 // that the consistency of 'pageNr' 'selectedTextStart' and 00045 // 'selectedTextEnd' are not checked; it is entirely of the program 00046 // that calls this method to make sure that it sets reasonable 00047 // values; it is not even checked if selectedTextStart <= 00048 // selectedTextEnd! The signals pageChanged() and 00049 // selectionIsNotEmpty() are emitted if appropriate. 00050 void set(const PageNumber& pageNr, Q_INT32 selectedTextStart, Q_INT32 selectedTextEnd, const QString& text); 00051 00052 // This method can be used to find out if the selection is empty, 00053 // i.e. if the page number is invalid or the selected text is empty. 00054 bool isEmpty() const {return (!page.isValid() || selectedText.isEmpty());} 00055 00056 // Method used to retrieve the data described above 00057 Q_INT32 getSelectedTextStart() const {return selectedTextStart;} 00058 00059 // Method used to retrieve the data described above 00060 Q_INT32 getSelectedTextEnd() const {return selectedTextEnd;} 00061 00062 // Method used to retrieve the data described above 00063 const QString &getSelectedText() const {return selectedText;} 00064 00065 // Method used to retrieve the data described above 00066 PageNumber getPageNumber() const {return page;} 00067 00068 // If the selection is not empty, this method copies the text to the 00069 // system clipboard. If the selection is empty, nothing is done. 00070 void copyText() const; 00071 00072 bool operator== (const TextSelection&) const; 00073 bool operator!= (const TextSelection&) const; 00074 00075 private: 00076 // Described above 00077 PageNumber page; 00078 00079 // Described above 00080 Q_INT32 selectedTextStart, selectedTextEnd; 00081 00082 // Described above 00083 QString selectedText; 00084 }; 00085 00086 #endif