~ubuntu-branches/ubuntu/maverick/uim/maverick

« back to all changes in this revision

Viewing changes to qt4/pref/customwidgets.h

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2010-01-22 17:44:19 UTC
  • mfrom: (1.1.12 upstream) (7.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100122174419-jvzfjkrbwv21kv0x
Tags: 1:1.5.7-2ubuntu1
* Merge from debian/unstable. No remaining changes.
* debian/control: added build dependency on libgnomeui-dev. This is mandatory
  to build the Gnome applet and fixes a FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
 Copyright (c) 2003-2009 uim Project http://code.google.com/p/uim/
 
4
 
 
5
 All rights reserved.
 
6
 
 
7
 Redistribution and use in source and binary forms, with or without
 
8
 modification, are permitted provided that the following conditions
 
9
 are met:
 
10
 
 
11
 1. Redistributions of source code must retain the above copyright
 
12
    notice, this list of conditions and the following disclaimer.
 
13
 2. Redistributions in binary form must reproduce the above copyright
 
14
    notice, this list of conditions and the following disclaimer in the
 
15
    documentation and/or other materials provided with the distribution.
 
16
 3. Neither the name of authors nor the names of its contributors
 
17
    may be used to endorse or promote products derived from this software
 
18
    without specific prior written permission.
 
19
 
 
20
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
 
21
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
22
 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
23
 ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
 
24
 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
25
 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 
26
 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
27
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 
28
 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 
29
 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 
30
 SUCH DAMAGE.
 
31
 
 
32
*/
 
33
#ifndef UIM_QT4_PREF_CUSTOMWIDGETS_H
 
34
#define UIM_QT4_PREF_CUSTOMWIDGETS_H
 
35
 
 
36
#include <uim/uim.h>
 
37
#include <uim/uim-custom.h>
 
38
 
 
39
#include <QtCore/QList>
 
40
#include <QtGui/QCheckBox>
 
41
#include <QtGui/QComboBox>
 
42
#include <QtGui/QFrame>
 
43
#include <QtGui/QKeyEvent>
 
44
#include <QtGui/QLineEdit>
 
45
#include <QtGui/QSpinBox>
 
46
 
 
47
#include "ui_olisteditformbase.h"
 
48
#include "ui_keyeditformbase.h"
 
49
 
 
50
class QPushButton;
 
51
class QListViewItem;
 
52
class QFileDialog;
 
53
 
 
54
class UimCustomItemIface
 
55
{
 
56
public:
 
57
    explicit UimCustomItemIface( struct uim_custom *c = 0 )
 
58
    {
 
59
        m_custom = c;
 
60
 
 
61
        // callback
 
62
        uim_custom_cb_add( m_custom->symbol, this, UimCustomItemIface::update_cb );
 
63
    }
 
64
    virtual ~UimCustomItemIface()
 
65
    {
 
66
        if( m_custom ) uim_custom_free( m_custom );
 
67
    }
 
68
 
 
69
    /* Custom Update Callback */
 
70
    static void update_cb( void *ptr, const char *custom_sym )
 
71
    {
 
72
        UimCustomItemIface *iface = (UimCustomItemIface*)ptr;
 
73
        iface->updateItem( custom_sym );        
 
74
        iface->update();
 
75
    }
 
76
    virtual void update() = 0;
 
77
 
 
78
    /* Set to default */
 
79
    virtual void setDefault() = 0;    
 
80
 
 
81
protected:
 
82
    void setCustom( struct uim_custom *custom )
 
83
    {
 
84
        uim_bool rv = uim_custom_set( custom );
 
85
        if( rv )
 
86
            currentCustomValueChanged();
 
87
        else
 
88
            qFatal( "Failed to set value for \"%s\".", custom->symbol );
 
89
    }
 
90
    void updateItem( const char *custom_sym )
 
91
    {
 
92
        // remove current custom
 
93
        if( m_custom ) uim_custom_free( m_custom );
 
94
        // set new item
 
95
        m_custom = uim_custom_get( custom_sym );
 
96
    }
 
97
 
 
98
    virtual void currentCustomValueChanged() = 0;
 
99
 
 
100
protected:
 
101
    struct uim_custom *m_custom;
 
102
};
 
103
 
 
104
//----------------------------------------------------------------------------------------
 
105
class CustomCheckBox : public QCheckBox, public UimCustomItemIface
 
106
{
 
107
    Q_OBJECT
 
108
 
 
109
public:
 
110
    explicit CustomCheckBox( struct uim_custom *c, QWidget *parent = 0 );
 
111
 
 
112
    virtual void update();
 
113
    virtual void setDefault();
 
114
protected slots:
 
115
    void slotCustomToggled( bool check );
 
116
protected:
 
117
    void currentCustomValueChanged(){ emit customValueChanged(); }
 
118
signals:
 
119
    void customValueChanged();
 
120
};
 
121
 
 
122
//----------------------------------------------------------------------------------------
 
123
class CustomSpinBox : public QSpinBox, public UimCustomItemIface
 
124
{
 
125
    Q_OBJECT
 
126
 
 
127
public:
 
128
    CustomSpinBox( struct uim_custom *c, QWidget *parent );
 
129
    
 
130
    virtual void update();
 
131
    virtual void setDefault();
 
132
public slots:
 
133
    void slotCustomValueChanged( int value );
 
134
protected:
 
135
    void currentCustomValueChanged(){ emit customValueChanged(); }    
 
136
signals:
 
137
    void customValueChanged();
 
138
};
 
139
 
 
140
//----------------------------------------------------------------------------------------
 
141
class CustomLineEdit : public QLineEdit, public UimCustomItemIface
 
142
{
 
143
    Q_OBJECT
 
144
 
 
145
public:
 
146
    CustomLineEdit( struct uim_custom *c, QWidget *parent );
 
147
 
 
148
    virtual void update();
 
149
    virtual void setDefault();
 
150
protected slots:
 
151
    void slotCustomTextChanged( const QString &text );
 
152
protected:
 
153
    void currentCustomValueChanged(){ emit customValueChanged(); }    
 
154
signals:
 
155
    void customValueChanged();
 
156
};
 
157
 
 
158
//----------------------------------------------------------------------------------------
 
159
class CustomPathnameEdit : public QFrame, public UimCustomItemIface
 
160
{
 
161
    Q_OBJECT
 
162
 
 
163
public:
 
164
    CustomPathnameEdit( struct uim_custom *c, QWidget *parent );
 
165
 
 
166
    virtual void update();
 
167
    virtual void setDefault();
 
168
protected slots:
 
169
    void slotPathnameButtonClicked();
 
170
    void slotCustomTextChanged( const QString & text );
 
171
private:
 
172
    QLineEdit *m_lineEdit;
 
173
    QPushButton *m_fileButton;
 
174
    QFileDialog *m_fileDialog;
 
175
protected:
 
176
    void currentCustomValueChanged(){ emit customValueChanged(); }
 
177
signals:
 
178
    void customValueChanged();
 
179
};
 
180
 
 
181
//----------------------------------------------------------------------------------------
 
182
class CustomChoiceCombo : public QComboBox, public UimCustomItemIface
 
183
{
 
184
    Q_OBJECT
 
185
 
 
186
public:
 
187
    CustomChoiceCombo( struct uim_custom *c, QWidget *parent );
 
188
 
 
189
    virtual void update();
 
190
    virtual void setDefault();
 
191
protected slots:
 
192
    void slotActivated( int index );
 
193
protected:
 
194
    void currentCustomValueChanged(){ emit customValueChanged(); }
 
195
signals:
 
196
    void customValueChanged();
 
197
};
 
198
 
 
199
//----------------------------------------------------------------------------------------
 
200
class CustomOrderedListEdit : public QFrame, public UimCustomItemIface
 
201
{
 
202
    Q_OBJECT
 
203
 
 
204
public:
 
205
    CustomOrderedListEdit( struct uim_custom *c, QWidget *parent );
 
206
    
 
207
    virtual void update();
 
208
    virtual void setDefault();
 
209
protected slots:
 
210
    void slotEditButtonClicked();
 
211
private:
 
212
    QLineEdit *m_lineEdit;
 
213
    QPushButton *m_editButton;
 
214
 
 
215
    QList<struct uim_custom_choice *> m_validItemList;
 
216
    QList<struct uim_custom_choice *> m_itemList;
 
217
protected:
 
218
    void updateText();
 
219
    void initPtrList();
 
220
    void currentCustomValueChanged(){ emit customValueChanged(); }
 
221
signals:
 
222
    void customValueChanged();
 
223
};
 
224
 
 
225
class OListEditForm : public QDialog, public Ui_OListEditFormBase {
 
226
    Q_OBJECT
 
227
 
 
228
public:
 
229
    explicit OListEditForm( QWidget *parent = 0 );
 
230
    virtual ~OListEditForm();    
 
231
 
 
232
    void addCheckItem( bool isActive, const QString &str );
 
233
    QStringList activeItemLabels() const;
 
234
protected slots:
 
235
    void upItem();
 
236
    void downItem();
 
237
};
 
238
 
 
239
//----------------------------------------------------------------------------------------
 
240
class CustomKeyEdit : public QFrame, public UimCustomItemIface
 
241
{
 
242
    Q_OBJECT
 
243
 
 
244
public:
 
245
    CustomKeyEdit( struct uim_custom *c, QWidget *parent );
 
246
 
 
247
    virtual void update();
 
248
    virtual void setDefault();
 
249
protected:
 
250
    void updateText();
 
251
protected slots:
 
252
    void slotKeyButtonClicked();
 
253
private:
 
254
    QLineEdit *m_lineEdit;
 
255
    QPushButton *m_editButton;
 
256
protected:
 
257
    void currentCustomValueChanged(){ emit customValueChanged(); }
 
258
signals:
 
259
    void customValueChanged();
 
260
};
 
261
 
 
262
class KeyEditForm : public QDialog, public Ui_KeyEditFormBase  {
 
263
    Q_OBJECT
 
264
 
 
265
public:
 
266
    explicit KeyEditForm( QWidget *parent = 0 );
 
267
    virtual ~KeyEditForm();
 
268
 
 
269
    void addKeyItem( const QString &str );
 
270
    const QStringList getKeyStrList();
 
271
protected slots:
 
272
    void slotAddClicked();
 
273
    void slotRemoveClicked();
 
274
    void slotEditClicked();
 
275
    void slotItemSelectionChanged();
 
276
};
 
277
 
 
278
class KeyGrabDialog : public QDialog {
 
279
    Q_OBJECT
 
280
 
 
281
public:
 
282
    explicit KeyGrabDialog( QWidget *parent = 0 );
 
283
 
 
284
    QString getKeyStr() const { return m_keystr; }
 
285
 
 
286
    virtual void keyPressEvent( QKeyEvent *e );
 
287
    virtual void keyReleaseEvent( QKeyEvent *e );
 
288
 
 
289
protected:
 
290
    void setKeyStr();
 
291
 
 
292
protected:
 
293
    int pressed_keyval;
 
294
    Qt::KeyboardModifiers pressed_keystate;
 
295
    QChar pressed_unichar;
 
296
    QString m_keystr; 
 
297
};
 
298
 
 
299
#endif /* Not def: UIM_QT4_PREF_CUSTOMWIDGETS_H */