1 /* 2 3 Copyright (c) 2003-2013 uim Project https://github.com/uim/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_QT_PREF_CUSTOMWIDGETS_H 34 #define UIM_QT_PREF_CUSTOMWIDGETS_H 35 36 #include <uim/uim.h> 37 #include <uim/uim-custom.h> 38 39 #include <qvbox.h> 40 #include <qhbox.h> 41 #include <qlayout.h> 42 #include <qlabel.h> 43 #include <qcheckbox.h> 44 #include <qtoolbutton.h> 45 #include <qpushbutton.h> 46 #include <qapplication.h> 47 #include <qsplitter.h> 48 #include <qlistview.h> 49 #include <qvbox.h> 50 #include <qspinbox.h> 51 #include <qhbox.h> 52 #include <qlabel.h> 53 #include <qlineedit.h> 54 #include <qfiledialog.h> 55 #include <qcombobox.h> 56 #include <qptrlist.h> 57 #include <qevent.h> 58 59 #include "olisteditformbase.h" 60 #include "keyeditformbase.h" 61 62 class UimCustomItemIface 63 { 64 public: 65 UimCustomItemIface( struct uim_custom *c = NULL ) 66 { 67 m_custom = c; 68 69 // callback 70 uim_custom_cb_add( m_custom->symbol, this, UimCustomItemIface::update_cb ); 71 } ~UimCustomItemIface()72 virtual ~UimCustomItemIface() 73 { 74 if( m_custom ) uim_custom_free( m_custom ); 75 } 76 77 /* Custom Update Callback */ update_cb(void * ptr,const char * custom_sym)78 static void update_cb( void *ptr, const char *custom_sym ) 79 { 80 UimCustomItemIface *iface = (UimCustomItemIface*)ptr; 81 iface->updateItem( custom_sym ); 82 iface->update(); 83 } 84 virtual void update() = 0; 85 86 /* Set to default */ 87 virtual void setDefault() = 0; 88 89 protected: setCustom(struct uim_custom * custom)90 void setCustom( struct uim_custom *custom ) 91 { 92 uim_bool rv = uim_custom_set( custom ); 93 if( rv ) 94 currentCustomValueChanged(); 95 else 96 qFatal( "Failed to set value for \"%s\".", custom->symbol ); 97 } updateItem(const char * custom_sym)98 void updateItem( const char *custom_sym ) 99 { 100 // remove current custom 101 if( m_custom ) uim_custom_free( m_custom ); 102 // set new item 103 m_custom = uim_custom_get( custom_sym ); 104 } 105 106 virtual void currentCustomValueChanged() = 0; 107 108 protected: 109 struct uim_custom *m_custom; 110 }; 111 112 //---------------------------------------------------------------------------------------- 113 class CustomCheckBox : public QCheckBox, public UimCustomItemIface 114 { 115 Q_OBJECT 116 117 public: 118 CustomCheckBox( struct uim_custom *c, QWidget *parent, const char *name = 0); 119 120 virtual void update(); 121 virtual void setDefault(); 122 protected slots: 123 void slotCustomToggled( bool check ); 124 protected: currentCustomValueChanged()125 void currentCustomValueChanged(){ emit customValueChanged(); } 126 signals: 127 void customValueChanged(); 128 }; 129 130 //---------------------------------------------------------------------------------------- 131 class CustomSpinBox : public QSpinBox, public UimCustomItemIface 132 { 133 Q_OBJECT 134 135 public: 136 CustomSpinBox( struct uim_custom *c, QWidget *parent, const char *name = 0 ); 137 138 virtual void update(); 139 virtual void setDefault(); 140 public slots: 141 void slotCustomValueChanged( int value ); 142 protected: currentCustomValueChanged()143 void currentCustomValueChanged(){ emit customValueChanged(); } 144 signals: 145 void customValueChanged(); 146 }; 147 148 //---------------------------------------------------------------------------------------- 149 class CustomLineEdit : public QLineEdit, public UimCustomItemIface 150 { 151 Q_OBJECT 152 153 public: 154 CustomLineEdit( struct uim_custom *c, QWidget *parent, const char *name = 0 ); 155 156 virtual void update(); 157 virtual void setDefault(); 158 protected slots: 159 void slotCustomTextChanged( const QString &text ); 160 protected: currentCustomValueChanged()161 void currentCustomValueChanged(){ emit customValueChanged(); } 162 signals: 163 void customValueChanged(); 164 }; 165 166 //---------------------------------------------------------------------------------------- 167 class CustomPathnameEdit : public QHBox, public UimCustomItemIface 168 { 169 Q_OBJECT 170 171 public: 172 CustomPathnameEdit( struct uim_custom *c, QWidget *parent, const char *name = 0 ); 173 174 virtual void update(); 175 virtual void setDefault(); 176 protected slots: 177 void slotPathnameButtonClicked(); 178 void slotCustomTextChanged( const QString & text ); 179 void slotFileDialogFilterSelected( const QString & text ); 180 private: 181 QLineEdit *m_lineEdit; 182 QPushButton *m_fileButton; 183 QFileDialog *m_fileDialog; 184 protected: currentCustomValueChanged()185 void currentCustomValueChanged(){ emit customValueChanged(); } 186 signals: 187 void customValueChanged(); 188 }; 189 190 //---------------------------------------------------------------------------------------- 191 class CustomChoiceCombo : public QComboBox, public UimCustomItemIface 192 { 193 Q_OBJECT 194 195 public: 196 CustomChoiceCombo( struct uim_custom *c, QWidget *parent, const char *name = 0 ); 197 198 virtual void update(); 199 virtual void setDefault(); 200 protected slots: 201 void slotActivated( int index ); 202 protected: currentCustomValueChanged()203 void currentCustomValueChanged(){ emit customValueChanged(); } 204 signals: 205 void customValueChanged(); 206 }; 207 208 //---------------------------------------------------------------------------------------- 209 class CustomOrderedListEdit : public QHBox, public UimCustomItemIface 210 { 211 Q_OBJECT 212 213 public: 214 CustomOrderedListEdit( struct uim_custom *c, QWidget *parent, const char *name = 0 ); 215 216 virtual void update(); 217 virtual void setDefault(); 218 protected slots: 219 void slotEditButtonClicked(); 220 private: 221 QLineEdit *m_lineEdit; 222 QPushButton *m_editButton; 223 224 QPtrList<struct uim_custom_choice> m_validItemList; 225 QPtrList<struct uim_custom_choice> m_itemList; 226 protected: 227 void updateText(); 228 void initPtrList(); currentCustomValueChanged()229 void currentCustomValueChanged(){ emit customValueChanged(); } 230 signals: 231 void customValueChanged(); 232 }; 233 234 class OListEditForm : public OListEditFormBase { 235 Q_OBJECT 236 237 public: 238 OListEditForm( QWidget *parent = 0, const char *name = 0 ); 239 240 void addCheckItem( bool isActive, const QString &str ); 241 QStringList activeItemLabels() const; 242 protected slots: 243 void upItem(); 244 void downItem(); 245 }; 246 247 //---------------------------------------------------------------------------------------- 248 class CustomKeyEdit : public QHBox, public UimCustomItemIface 249 { 250 Q_OBJECT 251 252 public: 253 CustomKeyEdit( struct uim_custom *c, QWidget *parent, const char *name = 0 ); 254 255 virtual void update(); 256 virtual void setDefault(); 257 protected: 258 void updateText(); 259 protected slots: 260 void slotKeyButtonClicked(); 261 private: 262 QLineEdit *m_lineEdit; 263 QPushButton *m_editButton; 264 protected: currentCustomValueChanged()265 void currentCustomValueChanged(){ emit customValueChanged(); } 266 signals: 267 void customValueChanged(); 268 }; 269 270 class KeyEditForm : public KeyEditFormBase { 271 Q_OBJECT 272 273 public: 274 KeyEditForm( QWidget *parent = 0, const char *name = 0 ); 275 276 void addKeyItem( const QString &str ); 277 const QStringList getKeyStrList(); 278 protected slots: 279 void slotAddClicked(); 280 void slotRemoveClicked(); 281 void slotEditClicked(); 282 void slotSelectionChanged( QListViewItem * ); 283 }; 284 285 class KeyGrabDialog : public QDialog { 286 Q_OBJECT 287 288 public: 289 KeyGrabDialog( QWidget *parent = 0, const char *name = 0 ); 290 getKeyStr()291 QString getKeyStr() const { return m_keystr; } 292 293 virtual void keyPressEvent( QKeyEvent *e ); 294 virtual void keyReleaseEvent( QKeyEvent *e ); 295 296 protected: 297 void setKeyStr(); 298 299 protected: 300 int pressed_keyval; 301 ButtonState pressed_keystate; 302 QChar pressed_unichar; 303 QString m_keystr; 304 }; 305 306 #endif /* Not def: UIM_QT_PREF_CUSTOMWIDGETS_H */ 307