init
[qstardict] / qstardict / popupwindow.h
1 /*****************************************************************************
2  * popupwindow.h - QStarDict, a StarDict clone written with using Qt         *
3  * Copyright (C) 2007 Alexander Rodin                                        *
4  *                                                                           *
5  * This program is free software; you can redistribute it and/or modify      *
6  * it under the terms of the GNU General Public License as published by      *
7  * the Free Software Foundation; either version 2 of the License, or         *
8  * (at your option) any later version.                                       *
9  *                                                                           *
10  * This program is distributed in the hope that it will be useful,           *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
13  * GNU General Public License for more details.                              *
14  *                                                                           *
15  * You should have received a copy of the GNU General Public License along   *
16  * with this program; if not, write to the Free Software Foundation, Inc.,   *
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.               *
18  *****************************************************************************/
19
20 #ifndef POPUPWINDOW_H
21 #define POPUPWINDOW_H
22
23 #include "resizablepopup.h"
24
25 #include "dictcore.h"
26 #include "dictwidget.h"
27
28 namespace QStarDict
29 {
30
31 class DictWidget;
32 class Selection;
33
34 /**
35  * The PopupWindow is a window that scan selection and pop-up
36  * when needed.
37  */
38 class PopupWindow: public ResizablePopup
39 {
40     Q_OBJECT
41
42     public:
43         /**
44          * Construct new PopupWindow.
45          */
46         PopupWindow(QWidget *parent = 0);
47         /**
48          * Destructor.
49          */
50         ~PopupWindow();
51
52         /**
53          * Return true if scanning enabled, otherwise return false.
54          */
55         bool isScan() const;
56         /**
57          * Return modifier key. The modifiers are from
58          * Qt::KeyboardModifier enum.
59          */
60         int modifierKey() const
61         { return m_modifierKey; }
62         /**
63          * Set behaviour for not found in dictionary words.
64          */
65         bool showIfNotFound() const
66         { return m_showIfNotFound; }
67
68         /**
69          * Set the dictionary.
70          */
71         void setDict(DictCore *dict);
72
73         /**
74          * Returns the dictionary.
75          */
76         DictCore* dict() const
77         { return m_dict; }
78         /**
79          * Return true if shown words will be pronounced, othewise
80          * return false.
81          */
82         bool pronounceWord() const
83         { return m_pronounceWord; }
84
85         void setDefaultStyleSheet(const QString &css)
86         { translationView->setDefaultStyleSheet(css); }
87
88         QString defaultStyleSheet() const
89         { return translationView->defaultStyleSheet(); }
90
91     public slots:
92         /**
93          * Enable or disable scanning of selection.
94          */
95         void setScan(bool scan);
96         /**
97          * Set modifier key. If key not is 0 then popup will be shown
98          * only if key is pressed.
99          */
100         void setModifierKey(int key)
101         { m_modifierKey = key; }
102         /**
103          * Set beahivour for words that not in dictionaris.
104          * If true then popup will be shown with text "No found", otherwise
105          * popup will not be shown.
106          */
107         void setShowIfNotFound(bool mode)
108         { m_showIfNotFound = mode; }
109
110         /**
111          * Popup with translation of text.
112          */
113         void showTranslation(const QString &text);
114         /**
115          * If prounounceWord is true shown words will be prounounced.
116          */
117         void setPronounceWord(bool pronounceWord)
118         { m_pronounceWord = pronounceWord; }
119
120         void saveSettings();
121
122     private slots:
123         void selectionChanged(const QString &text);
124
125     signals:
126         void scanChanged(bool scan);
127
128     private:
129         void loadSettings();
130
131         DictWidget *translationView;
132         DictCore* m_dict;
133         int m_modifierKey;
134         bool m_showIfNotFound;
135         Selection *m_selection;
136         bool m_pronounceWord;
137 };
138
139 }
140
141 #endif // POPUPWINDOW_H
142
143 // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent textwidth=120 formatoptions=tc
144