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 QFNOTIFICATIONS_H 21*bb02e0acSNicolas Bonnefon #define QFNOTIFICATIONS_H 22*bb02e0acSNicolas Bonnefon 23*bb02e0acSNicolas Bonnefon #include <QObject> 24*bb02e0acSNicolas Bonnefon #include <QWidget> 25*bb02e0acSNicolas Bonnefon #include <QFontMetrics> 26*bb02e0acSNicolas Bonnefon 27*bb02e0acSNicolas Bonnefon // Notifications sent by the QF for displaying to the user 28*bb02e0acSNicolas Bonnefon // and their translation in UI text. 29*bb02e0acSNicolas Bonnefon class QFNotification { 30*bb02e0acSNicolas Bonnefon public: 31*bb02e0acSNicolas Bonnefon virtual QString message() const = 0; 32*bb02e0acSNicolas Bonnefon 33*bb02e0acSNicolas Bonnefon // Max width of the message (in pixels) maxWidth(const QWidget * widget)34*bb02e0acSNicolas Bonnefon static int maxWidth( const QWidget* widget ) { 35*bb02e0acSNicolas Bonnefon QFontMetrics fm = widget->fontMetrics(); 36*bb02e0acSNicolas Bonnefon return qMax( fm.size( Qt::TextSingleLine, REACHED_BOF ).width(), 37*bb02e0acSNicolas Bonnefon fm.size( Qt::TextSingleLine, REACHED_EOF ).width() ); 38*bb02e0acSNicolas Bonnefon } 39*bb02e0acSNicolas Bonnefon 40*bb02e0acSNicolas Bonnefon protected: 41*bb02e0acSNicolas Bonnefon static const QString REACHED_EOF; 42*bb02e0acSNicolas Bonnefon static const QString REACHED_BOF; 43*bb02e0acSNicolas Bonnefon }; 44*bb02e0acSNicolas Bonnefon 45*bb02e0acSNicolas Bonnefon class QFNotificationReachedEndOfFile : public QFNotification 46*bb02e0acSNicolas Bonnefon { message()47*bb02e0acSNicolas Bonnefon QString message() const { 48*bb02e0acSNicolas Bonnefon return REACHED_EOF; 49*bb02e0acSNicolas Bonnefon } 50*bb02e0acSNicolas Bonnefon }; 51*bb02e0acSNicolas Bonnefon 52*bb02e0acSNicolas Bonnefon class QFNotificationReachedBegininningOfFile : public QFNotification 53*bb02e0acSNicolas Bonnefon { message()54*bb02e0acSNicolas Bonnefon QString message() const { 55*bb02e0acSNicolas Bonnefon return REACHED_BOF; 56*bb02e0acSNicolas Bonnefon } 57*bb02e0acSNicolas Bonnefon }; 58*bb02e0acSNicolas Bonnefon 59*bb02e0acSNicolas Bonnefon class QFNotificationProgress : public QFNotification { 60*bb02e0acSNicolas Bonnefon public: 61*bb02e0acSNicolas Bonnefon // Constructor taking the progress (in percent) QFNotificationProgress(int progress_percent)62*bb02e0acSNicolas Bonnefon QFNotificationProgress( int progress_percent ) 63*bb02e0acSNicolas Bonnefon { progressPercent_ = progress_percent; } 64*bb02e0acSNicolas Bonnefon message()65*bb02e0acSNicolas Bonnefon QString message() const { 66*bb02e0acSNicolas Bonnefon return QString( QObject::tr("Searching (position %1 %)") 67*bb02e0acSNicolas Bonnefon .arg( progressPercent_ ) ); 68*bb02e0acSNicolas Bonnefon } 69*bb02e0acSNicolas Bonnefon private: 70*bb02e0acSNicolas Bonnefon int progressPercent_; 71*bb02e0acSNicolas Bonnefon }; 72*bb02e0acSNicolas Bonnefon 73*bb02e0acSNicolas Bonnefon #endif 74