1*bb02e0acSNicolas Bonnefon /* 2*bb02e0acSNicolas Bonnefon * Copyright (C) 2013 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 QUICKFINDMUX_H 21*bb02e0acSNicolas Bonnefon #define QUICKFINDMUX_H 22*bb02e0acSNicolas Bonnefon 23*bb02e0acSNicolas Bonnefon #include <QObject> 24*bb02e0acSNicolas Bonnefon #include <QString> 25*bb02e0acSNicolas Bonnefon 26*bb02e0acSNicolas Bonnefon #include "quickfindpattern.h" 27*bb02e0acSNicolas Bonnefon 28*bb02e0acSNicolas Bonnefon // Interface representing a widget searchable in both direction. 29*bb02e0acSNicolas Bonnefon class SearchableWidgetInterface { 30*bb02e0acSNicolas Bonnefon public: 31*bb02e0acSNicolas Bonnefon virtual void searchForward() = 0; 32*bb02e0acSNicolas Bonnefon virtual void searchBackward() = 0; 33*bb02e0acSNicolas Bonnefon 34*bb02e0acSNicolas Bonnefon virtual void incrementallySearchForward() = 0; 35*bb02e0acSNicolas Bonnefon virtual void incrementallySearchBackward() = 0; 36*bb02e0acSNicolas Bonnefon virtual void incrementalSearchStop() = 0; 37*bb02e0acSNicolas Bonnefon virtual void incrementalSearchAbort() = 0; 38*bb02e0acSNicolas Bonnefon }; 39*bb02e0acSNicolas Bonnefon 40*bb02e0acSNicolas Bonnefon // Interface representing the selector. It will be called and asked 41*bb02e0acSNicolas Bonnefon // who the search have to be forwarded to. 42*bb02e0acSNicolas Bonnefon class QuickFindMuxSelectorInterface { 43*bb02e0acSNicolas Bonnefon public: 44*bb02e0acSNicolas Bonnefon virtual SearchableWidgetInterface* getActiveSearchable() const = 0; 45*bb02e0acSNicolas Bonnefon }; 46*bb02e0acSNicolas Bonnefon 47*bb02e0acSNicolas Bonnefon class QFNotification; 48*bb02e0acSNicolas Bonnefon 49*bb02e0acSNicolas Bonnefon // Represents a multiplexer (unique application wise) dispatching the 50*bb02e0acSNicolas Bonnefon // Quick Find search from the UI to the relevant view. 51*bb02e0acSNicolas Bonnefon // It is also its responsability to determine if an incremental search 52*bb02e0acSNicolas Bonnefon // must be performed and to react accordingly. 53*bb02e0acSNicolas Bonnefon // It owns the QuickFindPattern. 54*bb02e0acSNicolas Bonnefon class QuickFindMux : public QObject 55*bb02e0acSNicolas Bonnefon { 56*bb02e0acSNicolas Bonnefon Q_OBJECT 57*bb02e0acSNicolas Bonnefon 58*bb02e0acSNicolas Bonnefon public: 59*bb02e0acSNicolas Bonnefon 60*bb02e0acSNicolas Bonnefon enum QFDirection { 61*bb02e0acSNicolas Bonnefon Forward, 62*bb02e0acSNicolas Bonnefon Backward, 63*bb02e0acSNicolas Bonnefon }; 64*bb02e0acSNicolas Bonnefon 65*bb02e0acSNicolas Bonnefon // Construct the multiplexer, the selector class will be called 66*bb02e0acSNicolas Bonnefon // and ask who the search have to be forwarded to. 67*bb02e0acSNicolas Bonnefon QuickFindMux( const QuickFindMuxSelectorInterface* selector ); 68*bb02e0acSNicolas Bonnefon 69*bb02e0acSNicolas Bonnefon // Register/unregister this searchable widget with the mux for messages 70*bb02e0acSNicolas Bonnefon // to be forwarded back to the client. 71*bb02e0acSNicolas Bonnefon // The client should call this for each possible searchable widget. 72*bb02e0acSNicolas Bonnefon void registerSearchable( QObject* searchable ); 73*bb02e0acSNicolas Bonnefon void unregisterSearchable( QObject* searchable ); 74*bb02e0acSNicolas Bonnefon 75*bb02e0acSNicolas Bonnefon // Set the direction that will be used by the search when searching 76*bb02e0acSNicolas Bonnefon // forward. 77*bb02e0acSNicolas Bonnefon void setDirection( QFDirection direction ); 78*bb02e0acSNicolas Bonnefon 79*bb02e0acSNicolas Bonnefon // Get a pointer to the pattern 80*bb02e0acSNicolas Bonnefon QuickFindPattern* getPattern() { return &pattern_; } 81*bb02e0acSNicolas Bonnefon 82*bb02e0acSNicolas Bonnefon signals: 83*bb02e0acSNicolas Bonnefon void patternChanged( const QString& ); 84*bb02e0acSNicolas Bonnefon void notify( const QFNotification& ); 85*bb02e0acSNicolas Bonnefon void clearNotification(); 86*bb02e0acSNicolas Bonnefon 87*bb02e0acSNicolas Bonnefon public slots: 88*bb02e0acSNicolas Bonnefon // Signal the current pattern must be altered (will start an incremental 89*bb02e0acSNicolas Bonnefon // search if the options are configured in such a way). 90*bb02e0acSNicolas Bonnefon void setNewPattern( const QString& new_pattern, bool ignore_case ); 91*bb02e0acSNicolas Bonnefon 92*bb02e0acSNicolas Bonnefon // Signal the current pattern must be altered and is confirmed 93*bb02e0acSNicolas Bonnefon // (will stop an incremental search if needed) 94*bb02e0acSNicolas Bonnefon void confirmPattern( const QString& new_pattern, bool ignore_case ); 95*bb02e0acSNicolas Bonnefon 96*bb02e0acSNicolas Bonnefon // Signal the user cancelled the search 97*bb02e0acSNicolas Bonnefon // (used for incremental only) 98*bb02e0acSNicolas Bonnefon void cancelSearch(); 99*bb02e0acSNicolas Bonnefon 100*bb02e0acSNicolas Bonnefon // Starts a search in the specified direction 101*bb02e0acSNicolas Bonnefon void searchNext(); 102*bb02e0acSNicolas Bonnefon void searchPrevious(); 103*bb02e0acSNicolas Bonnefon 104*bb02e0acSNicolas Bonnefon // Idem but ignore the direction and always search in the 105*bb02e0acSNicolas Bonnefon // specified direction 106*bb02e0acSNicolas Bonnefon void searchForward(); 107*bb02e0acSNicolas Bonnefon void searchBackward(); 108*bb02e0acSNicolas Bonnefon 109*bb02e0acSNicolas Bonnefon private slots: 110*bb02e0acSNicolas Bonnefon void changeQuickFind( const QString& new_pattern, 111*bb02e0acSNicolas Bonnefon QuickFindMux::QFDirection new_direction ); 112*bb02e0acSNicolas Bonnefon void notifyPatternChanged(); 113*bb02e0acSNicolas Bonnefon 114*bb02e0acSNicolas Bonnefon private: 115*bb02e0acSNicolas Bonnefon const QuickFindMuxSelectorInterface* selector_; 116*bb02e0acSNicolas Bonnefon 117*bb02e0acSNicolas Bonnefon // The (application wide) quick find pattern 118*bb02e0acSNicolas Bonnefon QuickFindPattern pattern_; 119*bb02e0acSNicolas Bonnefon 120*bb02e0acSNicolas Bonnefon QFDirection currentDirection_; 121*bb02e0acSNicolas Bonnefon 122*bb02e0acSNicolas Bonnefon SearchableWidgetInterface* getSearchableWidget() const; 123*bb02e0acSNicolas Bonnefon }; 124*bb02e0acSNicolas Bonnefon 125*bb02e0acSNicolas Bonnefon #endif 126