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_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/QKeyEvent> 41 #if QT_VERSION < 0x050000 42 # include <QtGui/QCheckBox> 43 # include <QtGui/QComboBox> 44 # include <QtGui/QFrame> 45 # include <QtGui/QLineEdit> 46 # include <QtGui/QSpinBox> 47 #else 48 # include <QtWidgets/QCheckBox> 49 # include <QtWidgets/QComboBox> 50 # include <QtWidgets/QFrame> 51 # include <QtWidgets/QLineEdit> 52 # include <QtWidgets/QSpinBox> 53 #endif 54 55 #include "keyeditformbase.h" 56 #include "olisteditformbase.h" 57 58 class QListViewItem; 59 class QFileDialog; 60 class QPushButton; 61 class QTableWidget; 62 63 class UimCustomItemIface 64 { 65 public: 66 explicit UimCustomItemIface( struct uim_custom *c = 0 ) 67 { 68 m_custom = c; 69 70 // callback 71 uim_custom_cb_add( m_custom->symbol, this, UimCustomItemIface::update_cb ); 72 } ~UimCustomItemIface()73 virtual ~UimCustomItemIface() 74 { 75 if( m_custom ) uim_custom_free( m_custom ); 76 } 77 78 /* Custom Update Callback */ update_cb(void * ptr,const char * custom_sym)79 static void update_cb( void *ptr, const char *custom_sym ) 80 { 81 UimCustomItemIface *iface = static_cast<UimCustomItemIface*>( ptr ); 82 iface->updateItem( custom_sym ); 83 iface->update(); 84 } 85 virtual void update() = 0; 86 87 /* Set to default */ 88 virtual void setDefault() = 0; 89 90 protected: setCustom(struct uim_custom * custom)91 void setCustom( struct uim_custom *custom ) 92 { 93 uim_bool rv = uim_custom_set( custom ); 94 if( rv ) 95 currentCustomValueChanged(); 96 else 97 qFatal( "Failed to set value for \"%s\".", custom->symbol ); 98 } updateItem(const char * custom_sym)99 void updateItem( const char *custom_sym ) 100 { 101 // remove current custom 102 if( m_custom ) uim_custom_free( m_custom ); 103 // set new item 104 m_custom = uim_custom_get( custom_sym ); 105 } 106 107 virtual void currentCustomValueChanged() = 0; 108 109 protected: 110 struct uim_custom *m_custom; 111 }; 112 113 //---------------------------------------------------------------------------------------- 114 class CustomCheckBox : public QCheckBox, public UimCustomItemIface 115 { 116 Q_OBJECT 117 118 public: 119 explicit CustomCheckBox( struct uim_custom *c, QWidget *parent = 0 ); 120 121 virtual void update(); 122 virtual void setDefault(); 123 protected slots: 124 void slotCustomToggled( bool check ); 125 protected: currentCustomValueChanged()126 void currentCustomValueChanged(){ emit customValueChanged(); } 127 signals: 128 void customValueChanged(); 129 }; 130 131 //---------------------------------------------------------------------------------------- 132 class CustomSpinBox : public QSpinBox, public UimCustomItemIface 133 { 134 Q_OBJECT 135 136 public: 137 CustomSpinBox( struct uim_custom *c, QWidget *parent ); 138 139 virtual void update(); 140 virtual void setDefault(); 141 public slots: 142 void slotCustomValueChanged( int value ); 143 protected: currentCustomValueChanged()144 void currentCustomValueChanged(){ emit customValueChanged(); } 145 signals: 146 void customValueChanged(); 147 }; 148 149 //---------------------------------------------------------------------------------------- 150 class CustomLineEdit : public QLineEdit, public UimCustomItemIface 151 { 152 Q_OBJECT 153 154 public: 155 CustomLineEdit( struct uim_custom *c, QWidget *parent ); 156 157 virtual void update(); 158 virtual void setDefault(); 159 protected slots: 160 void slotCustomTextChanged( const QString &text ); 161 protected: currentCustomValueChanged()162 void currentCustomValueChanged(){ emit customValueChanged(); } 163 signals: 164 void customValueChanged(); 165 }; 166 167 //---------------------------------------------------------------------------------------- 168 class CustomPathnameEdit : public QFrame, public UimCustomItemIface 169 { 170 Q_OBJECT 171 172 public: 173 CustomPathnameEdit( struct uim_custom *c, QWidget *parent ); 174 175 virtual void update(); 176 virtual void setDefault(); 177 protected slots: 178 void slotPathnameButtonClicked(); 179 void slotCustomTextChanged( 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 ); 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 QFrame, public UimCustomItemIface 210 { 211 Q_OBJECT 212 213 public: 214 CustomOrderedListEdit( struct uim_custom *c, QWidget *parent ); 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 QList<struct uim_custom_choice *> m_validItemList; 225 QList<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 explicit OListEditForm( QWidget *parent = 0 ); 239 virtual ~OListEditForm(); 240 241 void addCheckItem( bool isActive, const QString &str ); 242 QStringList activeItemLabels() const; 243 protected slots: 244 void upItem(); 245 void downItem(); 246 }; 247 248 //---------------------------------------------------------------------------------------- 249 class CustomKeyEdit : public QFrame, public UimCustomItemIface 250 { 251 Q_OBJECT 252 253 public: 254 CustomKeyEdit( struct uim_custom *c, QWidget *parent ); 255 256 virtual void update(); 257 virtual void setDefault(); 258 protected: 259 void updateText(); 260 protected slots: 261 void slotKeyButtonClicked(); 262 private: 263 QLineEdit *m_lineEdit; 264 QPushButton *m_editButton; 265 protected: currentCustomValueChanged()266 void currentCustomValueChanged(){ emit customValueChanged(); } 267 signals: 268 void customValueChanged(); 269 }; 270 271 class KeyEditForm : public KeyEditFormBase { 272 Q_OBJECT 273 274 public: 275 explicit KeyEditForm( QWidget *parent = 0 ); 276 virtual ~KeyEditForm(); 277 278 void addKeyItem( const QString &str ); 279 const QStringList getKeyStrList(); 280 protected slots: 281 void slotAddClicked(); 282 void slotRemoveClicked(); 283 void slotEditClicked(); 284 void slotItemSelectionChanged(); 285 }; 286 287 class KeyGrabDialog : public QDialog { 288 Q_OBJECT 289 290 public: 291 explicit KeyGrabDialog( QWidget *parent = 0 ); 292 getKeyStr()293 QString getKeyStr() const { return m_keystr; } 294 295 virtual void keyPressEvent( QKeyEvent *e ); 296 virtual void keyReleaseEvent( QKeyEvent *e ); 297 298 protected: 299 void setKeyStr(); 300 301 protected: 302 int pressed_keyval; 303 Qt::KeyboardModifiers pressed_keystate; 304 QChar pressed_unichar; 305 QString m_keystr; 306 }; 307 308 //---------------------------------------------------------------------------------------- 309 class CustomTable : public QFrame, public UimCustomItemIface 310 { 311 Q_OBJECT 312 313 public: 314 CustomTable( struct uim_custom *c, QWidget *parent ); 315 316 virtual void update(); 317 virtual void setDefault(); 318 private slots: 319 void slotEditButtonClicked(); 320 protected: currentCustomValueChanged()321 void currentCustomValueChanged(){ emit customValueChanged(); } 322 signals: 323 void customValueChanged(); 324 }; 325 326 327 class TableEditForm : public QDialog 328 { 329 Q_OBJECT 330 331 public: 332 TableEditForm( QWidget *parent ); 333 334 void setTable( char ***custom_table ); 335 char ***table() const; 336 337 void setTableHeaderItem( const QString &item, int column ); 338 339 private: 340 QTableWidget *m_table; 341 QPushButton *m_removeButton; 342 QPushButton *m_upButton; 343 QPushButton *m_downButton; 344 char ***m_customTable; 345 private slots: 346 void slotItemSelectionChanged(); 347 void slotAddClicked(); 348 void slotRemoveClicked(); 349 void slotUpClicked(); 350 void slotDownClicked(); 351 }; 352 353 #endif /* Not def: UIM_QT4_PREF_CUSTOMWIDGETS_H */ 354