xref: /glogg/src/qfnotifications.h (revision 821cac888d515a4e41b5d4ba4130c56db4463501)
1 /*
2  * Copyright (C) 2013 Nicolas Bonnefon and other contributors
3  *
4  * This file is part of glogg.
5  *
6  * glogg is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * glogg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with glogg.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef QFNOTIFICATIONS_H
21 #define QFNOTIFICATIONS_H
22 
23 #include <QObject>
24 #include <QWidget>
25 #include <QFontMetrics>
26 
27 // Notifications sent by the QF for displaying to the user
28 // and their translation in UI text.
29 class QFNotification {
30   public:
31     virtual QString message() const = 0;
32 
33     // Max width of the message (in pixels)
34     static int maxWidth( const QWidget* widget ) {
35         QFontMetrics fm = widget->fontMetrics();
36         return qMax( fm.size( Qt::TextSingleLine, REACHED_BOF ).width(),
37                      fm.size( Qt::TextSingleLine, REACHED_EOF ).width() );
38     }
39 
40   protected:
41     static const QString REACHED_EOF;
42     static const QString REACHED_BOF;
43 };
44 
45 class QFNotificationReachedEndOfFile : public QFNotification
46 {
47     QString message() const {
48         return REACHED_EOF;
49     }
50 };
51 
52 class QFNotificationReachedBegininningOfFile : public QFNotification
53 {
54     QString message() const {
55         return REACHED_BOF;
56     }
57 };
58 
59 class QFNotificationProgress : public QFNotification {
60   public:
61     // Constructor taking the progress (in percent)
62     QFNotificationProgress( int progress_percent )
63     { progressPercent_ = progress_percent; }
64 
65     QString message() const {
66         return QString( QObject::tr("Searching (position %1 %)")
67                 .arg( progressPercent_ ) );
68     }
69   private:
70     int progressPercent_;
71 };
72 
73 #endif
74