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 #include <config.h>
34
35 #include "qt4.h"
36 #include "customwidgets.h"
37
38 #include <QtCore/QFile>
39 #include <QtCore/QSettings>
40 #if QT_VERSION < 0x050000
41 # include <QtGui/QApplication>
42 # include <QtGui/QCheckBox>
43 # include <QtGui/QGroupBox>
44 # include <QtGui/QHBoxLayout>
45 # include <QtGui/QLabel>
46 # include <QtGui/QMessageBox>
47 # include <QtGui/QPushButton>
48 # include <QtGui/QScrollArea>
49 # include <QtGui/QSplitter>
50 # include <QtGui/QStackedWidget>
51 # include <QtGui/QTreeWidget>
52 # include <QtGui/QTreeWidgetItem>
53 # include <QtGui/QVBoxLayout>
54 #else
55 # include <QtWidgets/QApplication>
56 # include <QtWidgets/QCheckBox>
57 # include <QtWidgets/QGroupBox>
58 # include <QtWidgets/QHBoxLayout>
59 # include <QtWidgets/QLabel>
60 # include <QtWidgets/QMessageBox>
61 # include <QtWidgets/QPushButton>
62 # include <QtWidgets/QScrollArea>
63 # include <QtWidgets/QSplitter>
64 # include <QtWidgets/QStackedWidget>
65 # include <QtWidgets/QTreeWidget>
66 # include <QtWidgets/QTreeWidgetItem>
67 # include <QtWidgets/QVBoxLayout>
68 #endif
69
70 #include "uim/counted-init.h"
71 #include "qtgettext.h"
72
73 #include <cstdlib>
74 #include <clocale>
75
76 static const int DEFAULT_WINDOW_WIDTH = 800;
77 static const int DEFAULT_WINDOW_HEIGHT = 600;
78
_FU8(const char string[])79 inline static QString _FU8( const char string[] )
80 {
81 return QString::fromUtf8( string );
82 }
83
UimPrefDialog(QWidget * parent)84 UimPrefDialog::UimPrefDialog( QWidget *parent )
85 : QDialog( parent ),
86 m_isValueChanged( false )
87 {
88 uim_counted_init();
89 if (uim_custom_enable()) {
90 checkDotUimFile();
91 setupWidgets();
92 } else {
93 #if defined(ENABLE_DEBUG)
94 qDebug("uim_custom_enable() failed.");
95 #endif
96 uim_counted_quit();
97 QApplication::exit( -1 );
98 }
99
100 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
101 setWindowTitle( "uim-pref-qt5" );
102 #else
103 setWindowTitle( "uim-pref-qt4" );
104 #endif
105 }
106
~UimPrefDialog()107 UimPrefDialog::~UimPrefDialog()
108 {
109 uim_counted_quit();
110 }
111
checkDotUimFile()112 void UimPrefDialog::checkDotUimFile()
113 {
114 /* Check Config */
115 QSettings settings;
116 bool isShowOnStartup
117 = settings.value( "/uim/qt/warnDotUim", true ).toBool();
118 if( !isShowOnStartup )
119 return;
120
121 /* Check File Existence */
122 QString homeDir = qgetenv( "HOME" );
123 if( homeDir.isEmpty() )
124 return;
125
126 QString dotUim = homeDir + "/.uim";
127 if( QFile::exists( dotUim ) )
128 {
129 QString msg = _("The user customize file \"~/.uim\" is found.\n"
130 "This file will override all conflicted settings set by\n"
131 "this tool (stored in ~/.uim.d/customs/*.scm).\n"
132 "Please check the file if you find your settings aren't applied.");
133
134 QConfirmDialog *d = new QConfirmDialog( msg,
135 "/uim/qt/warnDotUim",
136 this );
137 d->setWindowTitle( _("~/.uim exists!") );
138 d->exec();
139 delete d;
140 }
141 }
142
143 /*
144 * Building up GUI
145 */
setupWidgets()146 void UimPrefDialog::setupWidgets()
147 {
148 createMainWidgets();
149 createGroupWidgets();
150 }
151
createMainWidgets()152 void UimPrefDialog::createMainWidgets()
153 {
154 QVBoxLayout *mainVLayout = new QVBoxLayout( this );
155 mainVLayout->setMargin( 6 );
156
157 QSplitter *mainSplitter = new QSplitter( this );
158
159 /* ListView */
160 m_groupListView = new QTreeWidget( mainSplitter );
161 m_groupListView->setRootIsDecorated( false );
162 m_groupListView->setHeaderLabel( _("Group") );
163 m_groupListView->setSelectionMode( QAbstractItemView::SingleSelection );
164 connect( m_groupListView, SIGNAL(itemSelectionChanged()),
165 this, SLOT(slotItemSelectionChanged()) );
166
167 /* Contents Frame */
168 m_rightSideWidget = new QScrollArea( mainSplitter );
169 m_rightSideWidget->setWidgetResizable( true );
170 m_groupWidgetStack = new QStackedWidget;
171
172 /* Buttons */
173 QWidget *buttonHWidget = new QWidget( this );
174 buttonHWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed);
175 QHBoxLayout *buttonHLayout = new QHBoxLayout( buttonHWidget );
176 buttonHLayout->setMargin( 6 );
177 buttonHLayout->setSpacing( 6 );
178 QPushButton *defaultButton = new QPushButton( _("Defaults"), buttonHWidget );
179 connect( defaultButton, SIGNAL(clicked()),
180 this, SLOT(slotSetDefault()) );
181 QPushButton *okButton = new QPushButton( _("OK"), buttonHWidget );
182 connect( okButton, SIGNAL(clicked()),
183 this, SLOT(slotOK()) );
184 m_applyButton = new QPushButton( _("Apply"), buttonHWidget );
185 m_applyButton->setEnabled( false );
186 connect( m_applyButton, SIGNAL(clicked()),
187 this, SLOT(slotApply()) );
188 QPushButton *cancelButton = new QPushButton( _("Cancel"), buttonHWidget );
189 connect( cancelButton, SIGNAL(clicked()),
190 this, SLOT(slotCancel()) );
191 buttonHLayout->addWidget( defaultButton );
192 buttonHLayout->addStretch();
193 buttonHLayout->addWidget( okButton );
194 buttonHLayout->addWidget( m_applyButton );
195 buttonHLayout->addWidget( cancelButton );
196
197 QFrame *separator = new QFrame( this );
198 separator->setFrameShape( QFrame::HLine );
199 separator->setFrameShadow( QFrame::Sunken );
200 mainVLayout->setMargin( 0 );
201 mainVLayout->addWidget( mainSplitter );
202 mainVLayout->addWidget( separator );
203 mainVLayout->addWidget( buttonHWidget );
204
205 mainSplitter->setStretchFactor( 1, 1 );
206 }
207
createGroupWidgets()208 void UimPrefDialog::createGroupWidgets()
209 {
210 char **primary_groups = uim_custom_primary_groups();
211 char **grp = 0;
212 for( grp = primary_groups; *grp; grp++ )
213 {
214 struct uim_custom_group *group = uim_custom_group_get( *grp );
215 if( group == 0 )
216 continue;
217
218 /* insert item in uim's order */
219 m_groupListView->addTopLevelItem(
220 new QTreeWidgetItem( QStringList() << _FU8(group->label) ) );
221
222 GroupPageWidget *w = new GroupPageWidget( m_groupWidgetStack, *grp );
223 if ( grp == primary_groups )
224 w->setupWidgets();
225
226 connect( w, SIGNAL(customValueChanged()),
227 this, SLOT(slotCustomValueChanged()) );
228
229 m_groupWidgetsDict.insert( _FU8(group->label), w );
230 m_groupWidgetStack->addWidget( w );
231
232 uim_custom_group_free( group );
233 }
234 uim_custom_symbol_list_free( primary_groups );
235
236 m_rightSideWidget->setWidget( m_groupWidgetStack );
237 }
238
239 /*
240 * GUI event handling
241 */
slotItemSelectionChanged()242 void UimPrefDialog::slotItemSelectionChanged()
243 {
244 QList<QTreeWidgetItem *>items = m_groupListView->selectedItems();
245 if ( items.isEmpty() )
246 return;
247 QTreeWidgetItem *item = items[ 0 ];
248
249 /*
250 * Don't confirm on each change in slot selection according to
251 * [Anthy-dev 1795].
252 * Dec 09 2005 ekato
253 */
254 #if 0
255 /* confirm if save the change */
256 if( m_isValueChanged )
257 confirmChange();
258 #endif
259
260 /* switch group widget */
261 QString grpname = item->text( 0 );
262 static_cast<GroupPageWidget *>(m_groupWidgetsDict[grpname])->setupWidgets();
263 m_groupWidgetStack->setCurrentWidget( m_groupWidgetsDict[grpname] );
264
265 #if 0
266 m_applyButton->setEnabled( false );
267 #endif
268 }
269
slotCustomValueChanged()270 void UimPrefDialog::slotCustomValueChanged()
271 {
272 m_isValueChanged = true;
273 m_applyButton->setEnabled( true );
274 }
275
confirmChange()276 void UimPrefDialog::confirmChange()
277 {
278 int result = QMessageBox::question( this,
279 _("Save Confirm"),
280 _("The value was changed.\nSave?"),
281 _("OK"),
282 _("Cancel") );
283 switch(result)
284 {
285 case 0:
286 slotApply();
287 break;
288 case 1:
289 m_isValueChanged = false;
290 break;
291 }
292 }
293
confirmQuit()294 void UimPrefDialog::confirmQuit()
295 {
296 int result = QMessageBox::question( this,
297 _("Quit Confirm"),
298 _("Some value(s) have been changed.\n"
299 "Do you really quit this program?"),
300 _("Yes"),
301 _("No"),
302 "", 1, -1);
303 switch(result)
304 {
305 case 0:
306 reject();
307 break;
308 case 1:
309 break;
310 default:
311 break;
312 }
313 }
314
slotSetDefault()315 void UimPrefDialog::slotSetDefault()
316 {
317 QWidget *w = m_groupWidgetStack->currentWidget();
318 if( w )
319 {
320 (static_cast<GroupPageWidget*>(w))->setDefault();
321 }
322 }
323
slotApply()324 void UimPrefDialog::slotApply()
325 {
326 if( !m_isValueChanged )
327 return;
328
329 #if defined(ENABLE_DEBUG)
330 qDebug("start saving....");
331 #endif
332
333 uim_custom_save();
334 uim_custom_broadcast_reload_request();
335
336 m_isValueChanged = false;
337 m_applyButton->setEnabled( false );
338 }
339
slotOK()340 void UimPrefDialog::slotOK()
341 {
342 if( m_isValueChanged )
343 {
344 slotApply();
345 }
346 accept();
347 }
348
slotCancel()349 void UimPrefDialog::slotCancel()
350 {
351 /*
352 * Enable confirmation since each change in slot selection is not
353 * checked strictly according to [Anthy-dev 1795].
354 * Dec 09 2005 ekato
355 */
356 if( m_isValueChanged )
357 confirmQuit();
358 else
359 reject();
360 }
361
362 //-------------------------------------------------------------------------------------
QConfirmDialog(const QString & msg,const QString & confname,QWidget * parent)363 QConfirmDialog::QConfirmDialog( const QString &msg, const QString &confname, QWidget *parent )
364 : QDialog( parent ),
365 m_confname( confname )
366 {
367 QSettings settings;
368 bool isShowOnStartup = settings.value( m_confname, true ).toBool();
369 if( isShowOnStartup )
370 setupWidgets( msg );
371 }
372
setupWidgets(const QString & msg)373 void QConfirmDialog::setupWidgets( const QString&msg )
374 {
375 QVBoxLayout *vLayout = new QVBoxLayout( this );
376 vLayout->setSpacing( 6 );
377 vLayout->setMargin( 6 );
378 QLabel *msgLabel = new QLabel( msg, this );
379 QFrame *sep = new QFrame( this );
380 sep->setFrameShape( QFrame::HLine );
381 sep->setFrameShadow( QFrame::Sunken );
382 vLayout->addWidget( msgLabel );
383 vLayout->addWidget( sep );
384
385 QHBoxLayout *buttonHLayout = new QHBoxLayout;
386 vLayout->addLayout( buttonHLayout );
387 QCheckBox *checkBox = new QCheckBox( _("Show this dialog on startup"), this );
388 QSettings settings;
389 bool isWarnDotUim = settings.value( m_confname, true ).toBool();
390 checkBox->setChecked( isWarnDotUim );
391 QPushButton *ok = new QPushButton( _("OK"), this );
392 ok->setDefault(true);
393 buttonHLayout->addWidget( checkBox );
394 buttonHLayout->addStretch();
395 buttonHLayout->addWidget( ok );
396
397 connect( ok, SIGNAL(clicked()),
398 this, SLOT(accept()) );
399 connect( checkBox, SIGNAL(toggled(bool)),
400 this, SLOT(showOnStart(bool)) );
401 }
402
showOnStart(bool isShowOnStart)403 void QConfirmDialog::showOnStart( bool isShowOnStart )
404 {
405 QSettings settings;
406 settings.setValue( m_confname, isShowOnStart );
407
408 #if defined(ENABLE_DEBUG)
409 qDebug("show on start = %d", isShowOnStart );
410 #endif
411 }
412
413
414 //-----------------------------------------------------------------------------------
415
GroupPageWidget(QWidget * parent,const char * group_name)416 GroupPageWidget::GroupPageWidget( QWidget *parent, const char *group_name )
417 : QWidget( parent )
418 {
419 m_customIfaceList.clear();
420
421 m_group_sym = group_name;
422 m_widget_created = false;
423 }
424
setupWidgets()425 void GroupPageWidget::setupWidgets()
426 {
427 if ( m_widget_created )
428 return;
429
430 QVBoxLayout *vLayout = new QVBoxLayout( this );
431 vLayout->setMargin( 6 );
432 vLayout->setSpacing( 3 );
433
434 struct uim_custom_group *group
435 = uim_custom_group_get( m_group_sym.toLatin1().constData() );
436 if( group == 0 )
437 return;
438
439 QLabel *groupLabel = new QLabel( _FU8(group->label), this );
440 groupLabel->setAlignment( Qt::AlignLeft );
441 vLayout->addWidget( groupLabel );
442
443 QFrame *separator = new QFrame( this );
444 separator->setFrameShape( QFrame::HLine );
445 separator->setFrameShadow( QFrame::Sunken );
446 vLayout->addWidget( separator );
447
448 /* default QVGroupBox */
449 QGroupBox *defaultGroupVBox = new QGroupBox( this );
450 vLayout->addWidget( defaultGroupVBox );
451 defaultGroupVBox->hide();
452 #if 0
453 SubgroupData *sd = new SubgroupData( this, group_name );
454
455 /* add various widgets to the vbox */
456 char **custom_syms = uim_custom_collect_by_group( group_name );
457 if( custom_syms )
458 {
459 for( char **custom_sym = custom_syms; *custom_sym; custom_sym++ )
460 {
461 QGroupBox *vbox = sd->searchGroupVBoxByCustomSym( *custom_sym );
462 if( vbox == 0 )
463 {
464 vbox = defaultGroupVBox;
465 vbox->show();
466 }
467
468 UimCustomItemIface *iface = addCustom( vbox, *custom_sym );
469 if( iface )
470 m_customIfaceList.append( iface );
471 }
472
473 uim_custom_symbol_list_free( custom_syms );
474 }
475 #else
476 char **sub_groups
477 = uim_custom_group_subgroups( m_group_sym.toLatin1().constData() );
478 char **sgrp;
479 for( sgrp = sub_groups; *sgrp; sgrp++ )
480 {
481 struct uim_custom_group *sgroup_custom = uim_custom_group_get( *sgrp );
482 QGroupBox *vbox;
483 if( QString::compare( *sgrp, "main" ) == 0 )
484 {
485 vbox = defaultGroupVBox;
486 vbox->show();
487 }
488 else
489 {
490 vbox = new QGroupBox( _FU8(sgroup_custom->label), this );
491 vLayout->addWidget( vbox );
492 }
493 QVBoxLayout *layout = new QVBoxLayout;
494 vbox->setLayout( layout );
495
496 /* XXX quick hack to use AND expression of groups */
497 QString groups( m_group_sym );
498 groups += " '";
499 groups += *sgrp;
500 char **custom_syms
501 = uim_custom_collect_by_group( groups.toLatin1().constData() );
502 if( !custom_syms )
503 continue;
504
505 for( char **custom_sym = custom_syms; *custom_sym; custom_sym++ )
506 {
507 UimCustomItemIface *iface = addCustom( vbox, *custom_sym );
508 if( iface )
509 m_customIfaceList.append( iface );
510 }
511 uim_custom_symbol_list_free( custom_syms );
512
513
514 uim_custom_group_free( sgroup_custom );
515 }
516 uim_custom_symbol_list_free( sub_groups );
517 #endif
518
519 /* free */
520 //delete sd;
521 uim_custom_group_free( group );
522
523 /* bottom up */
524 vLayout->addStretch();
525
526 setLayout( vLayout );
527
528 m_widget_created = true;
529 }
530
531 /*
532 * Building up GUI in accordance with Custom Type.
533 */
addCustom(QGroupBox * vbox,const char * custom_sym)534 UimCustomItemIface *GroupPageWidget::addCustom( QGroupBox *vbox, const char *custom_sym )
535 {
536 UimCustomItemIface *w = 0;
537 struct uim_custom *custom = uim_custom_get( custom_sym );
538 if( custom )
539 {
540 switch( custom->type )
541 {
542 case UCustom_Bool:
543 w = addCustomTypeBool( vbox, custom );
544 break;
545 case UCustom_Int:
546 w = addCustomTypeInteger( vbox, custom );
547 break;
548 case UCustom_Str:
549 w = addCustomTypeString( vbox, custom );
550 break;
551 case UCustom_Pathname:
552 w = addCustomTypePathname( vbox, custom );
553 break;
554 case UCustom_Choice:
555 w = addCustomTypeChoice( vbox, custom );
556 break;
557 case UCustom_OrderedList:
558 w = addCustomTypeOrderedList( vbox, custom );
559 break;
560 case UCustom_Key:
561 w = addCustomTypeKey( vbox, custom );
562 break;
563 case UCustom_Table:
564 w = addCustomTypeTable( vbox, custom );
565 break;
566 default:
567 w = 0;
568 qWarning( "Invalid custom type: %d\n", custom->type );
569 uim_custom_free( custom );
570 break;
571 }
572 } else {
573 qWarning( "Failed to get uim_custom object for %s.", custom_sym );
574 }
575
576 /* custom is freed by UimCustomItemIface's destructor */
577
578 return w;
579 }
580
addCustomTypeBool(QGroupBox * vbox,struct uim_custom * custom)581 UimCustomItemIface *GroupPageWidget::addCustomTypeBool( QGroupBox *vbox, struct uim_custom *custom )
582 {
583 CustomCheckBox *checkBox = new CustomCheckBox( custom );
584 connect( checkBox, SIGNAL(customValueChanged()),
585 this, SLOT(slotCustomValueChanged()) );
586 vbox->layout()->addWidget( checkBox );
587
588 return checkBox;
589 }
590
addCustomTypeInteger(QGroupBox * vbox,struct uim_custom * custom)591 UimCustomItemIface *GroupPageWidget::addCustomTypeInteger( QGroupBox *vbox, struct uim_custom *custom )
592 {
593 QFrame *hbox = new QFrame;
594 QLabel *label = new QLabel( _FU8(custom->label), hbox );
595 CustomSpinBox *spinBox = new CustomSpinBox( custom, hbox );
596 label->setBuddy( spinBox );
597 connect( spinBox, SIGNAL(customValueChanged()),
598 this, SLOT(slotCustomValueChanged()) );
599
600 QHBoxLayout *layout = new QHBoxLayout;
601 layout->setMargin( 0 );
602 layout->setSpacing( 6 );
603 layout->addWidget( label );
604 layout->addStretch();
605 layout->addWidget( spinBox );
606
607 hbox->setLayout( layout );
608 vbox->layout()->addWidget( hbox );
609
610 return spinBox;
611 }
612
addCustomTypeString(QGroupBox * vbox,struct uim_custom * custom)613 UimCustomItemIface *GroupPageWidget::addCustomTypeString( QGroupBox *vbox, struct uim_custom *custom )
614 {
615 QFrame *hbox = new QFrame;
616 QLabel *label = new QLabel( _FU8(custom->label) + ':', hbox );
617 CustomLineEdit *lineEdit = new CustomLineEdit( custom, hbox );
618 label->setBuddy( lineEdit );
619 connect( lineEdit, SIGNAL(customValueChanged()),
620 this, SLOT(slotCustomValueChanged()) );
621
622 QHBoxLayout *layout = new QHBoxLayout;
623 layout->setMargin( 0 );
624 layout->setSpacing( 6 );
625 layout->addWidget( label );
626 layout->addWidget( lineEdit );
627
628 hbox->setLayout( layout );
629 vbox->layout()->addWidget( hbox );
630
631 return lineEdit;
632 }
633
addCustomTypePathname(QGroupBox * vbox,struct uim_custom * custom)634 UimCustomItemIface *GroupPageWidget::addCustomTypePathname( QGroupBox *vbox, struct uim_custom *custom )
635 {
636 QFrame *hbox = new QFrame;
637 QLabel *label = new QLabel( _FU8(custom->label), hbox );
638 CustomPathnameEdit *pathnameEdit = new CustomPathnameEdit( custom, hbox );
639 label->setBuddy( pathnameEdit );
640 connect( pathnameEdit, SIGNAL(customValueChanged()),
641 this, SLOT(slotCustomValueChanged()) );
642
643 QHBoxLayout *layout = new QHBoxLayout;
644 layout->setMargin( 0 );
645 layout->setSpacing( 6 );
646 layout->addWidget( label );
647 layout->addWidget( pathnameEdit );
648
649 hbox->setLayout( layout );
650 vbox->layout()->addWidget( hbox );
651
652 return pathnameEdit;
653 }
654
addCustomTypeChoice(QGroupBox * vbox,struct uim_custom * custom)655 UimCustomItemIface *GroupPageWidget::addCustomTypeChoice( QGroupBox *vbox, struct uim_custom *custom )
656 {
657 QFrame *hbox = new QFrame;
658 QLabel *label = new QLabel( _FU8(custom->label), hbox );
659
660 CustomChoiceCombo *choiceCombo = new CustomChoiceCombo( custom, hbox );
661 label->setBuddy( choiceCombo );
662 connect( choiceCombo, SIGNAL(customValueChanged()),
663 this, SLOT(slotCustomValueChanged()) );
664
665 QHBoxLayout *layout = new QHBoxLayout;
666 layout->setMargin( 0 );
667 layout->setSpacing( 6 );
668 layout->addWidget( label );
669 layout->addWidget( choiceCombo );
670
671 hbox->setLayout( layout );
672 vbox->layout()->addWidget( hbox );
673
674 return choiceCombo;
675 }
676
addCustomTypeOrderedList(QGroupBox * vbox,struct uim_custom * custom)677 UimCustomItemIface *GroupPageWidget::addCustomTypeOrderedList( QGroupBox *vbox, struct uim_custom *custom )
678 {
679 QFrame *hbox = new QFrame;
680 QLabel *label = new QLabel( _FU8(custom->label), hbox );
681 CustomOrderedListEdit *olistEditBox = new CustomOrderedListEdit( custom, hbox );
682 label->setBuddy( olistEditBox );
683 connect( olistEditBox, SIGNAL(customValueChanged()),
684 this, SLOT(slotCustomValueChanged()) );
685
686 QHBoxLayout *layout = new QHBoxLayout;
687 layout->setMargin( 0 );
688 layout->setSpacing( 6 );
689 layout->addWidget( label );
690 layout->addWidget( olistEditBox );
691
692 hbox->setLayout( layout );
693 vbox->layout()->addWidget( hbox );
694
695 return olistEditBox;
696 }
697
addCustomTypeKey(QGroupBox * vbox,struct uim_custom * custom)698 UimCustomItemIface *GroupPageWidget::addCustomTypeKey( QGroupBox *vbox, struct uim_custom *custom )
699 {
700 QFrame *hbox = new QFrame;
701 QLabel *label = new QLabel( _FU8(custom->label), hbox );
702 CustomKeyEdit *keyEditBox = new CustomKeyEdit( custom, hbox );
703 label->setBuddy( keyEditBox );
704 connect( keyEditBox, SIGNAL(customValueChanged()),
705 this, SLOT(slotCustomValueChanged()) );
706
707 QHBoxLayout *layout = new QHBoxLayout;
708 layout->setMargin( 0 );
709 layout->setSpacing( 6 );
710 layout->addWidget( label );
711 layout->addWidget( keyEditBox );
712
713 hbox->setLayout( layout );
714 vbox->layout()->addWidget( hbox );
715
716 return keyEditBox;
717 }
718
addCustomTypeTable(QGroupBox * vbox,struct uim_custom * custom)719 UimCustomItemIface *GroupPageWidget::addCustomTypeTable( QGroupBox *vbox, struct uim_custom *custom )
720 {
721 QFrame *hbox = new QFrame;
722 QLabel *label = new QLabel( _FU8(custom->label), hbox );
723 CustomTable *tableBox = new CustomTable( custom, hbox );
724 label->setBuddy( tableBox );
725 connect( tableBox, SIGNAL(customValueChanged()),
726 this, SLOT(slotCustomValueChanged()) );
727
728 QHBoxLayout *layout = new QHBoxLayout;
729 layout->setMargin( 0 );
730 layout->setSpacing( 6 );
731 layout->addWidget( label );
732 layout->addWidget( tableBox );
733
734 hbox->setLayout( layout );
735 vbox->layout()->addWidget( hbox );
736
737 return tableBox;
738 }
739
740
setDefault()741 void GroupPageWidget::setDefault()
742 {
743 foreach ( UimCustomItemIface *iface, m_customIfaceList )
744 iface->setDefault();
745 }
746
747 //--------------------------------------------------------------------------------------
main(int argc,char ** argv)748 int main( int argc, char **argv )
749 {
750 setlocale(LC_ALL, "");
751 bindtextdomain(PACKAGE, LOCALEDIR);
752 textdomain(PACKAGE);
753 bind_textdomain_codeset(PACKAGE, "UTF-8"); // ensure code encoding is UTF8-
754
755 QApplication a( argc, argv );
756
757 QCoreApplication::setOrganizationName( "uim" );
758 QCoreApplication::setApplicationName( "uim" );
759
760 UimPrefDialog *dlg = new UimPrefDialog();
761 dlg->resize( DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT );
762 dlg->setWindowIcon( QIcon( UIM_PIXMAPSDIR "/uim-icon.png" ) );
763 dlg->show();
764
765 return a.exec();
766 }
767