1 /***************************************************************************
5 clipboard options dialog page
7 -----------------------------------------------------------------------
9 begin : Sun Jun 27 11:07:24 1999
11 copyright : (C) 1999-2001 Ewald Arnold
12 (C) 2001 The KDE-EDU team
14 email : kvoctrain@ewald-arnold.de
16 -----------------------------------------------------------------------
19 ***************************************************************************/
21 /***************************************************************************
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 ***************************************************************************/
32 #include <qpushbutton.h>
33 #include <qcombobox.h>
34 #include <qcheckbox.h>
44 #include "PasteOptPage.h"
45 #include "GeneralOptionsDlg.h"
47 static const char *separator_name
[] = {
53 I18N_NOOP("TAB"), // 5
54 I18N_NOOP(">= 2 SPACES"), // 6
61 static const char *separator_id
[] = {
75 PasteOptPage::PasteOptPage
79 QStringList
&paste_list
,
86 PasteOptPageForm( parent
, name
),
90 connect( kcfg_useCurrent
, SIGNAL(toggled(bool)), SLOT(slotCurrentDoc(bool)) );
91 connect( item_down
, SIGNAL(clicked()), SLOT(slotItemDown()) );
92 connect( item_skip
, SIGNAL(clicked()), SLOT(slotItemSkip()) );
93 connect( item_up
, SIGNAL(clicked()), SLOT(slotItemUp()) );
94 connect( kcfg_separator
, SIGNAL(highlighted(int)), SLOT(slotSelectSep(int)) );
95 connect( order_list
, SIGNAL(highlighted(int)), SLOT(slotSelectOrder(int)) );
98 setCaption(i18n("Options" ));
100 useCurrent
= _useCurrent
;
103 const char **seps
= separator_name
;
104 const char **sepid
= separator_id
;
107 sel
= seps
- separator_name
;
108 kcfg_separator
->insertItem (i18n(*seps
));
112 kcfg_separator
->setSizeLimit( seps
- separator_name
);
113 kcfg_separator
->setCurrentItem(sel
);
114 label_sep
->setBuddy(kcfg_separator
);//could be done in the ui file
117 for (int i
= 0; i
< (int) paste_list
.count(); i
++) {
118 QString codename
= langset
.findLongId(paste_list
[i
]);
120 if (codename
.isEmpty())
121 codename
= paste_list
[i
];
122 order_list
->insertItem (codename
);
125 // any new languages to add to order-list ?
126 for (int i
= 0; i
< (int) langset
.size(); i
++) {
128 for (int j
= 0; j
< (int) order_list
->count(); j
++)
129 if (order_list
->text(j
) == langset
.longId(i
))
133 order_list
->insertItem(langset
.longId(i
));
136 order_list
->setCurrentItem (0);
137 kcfg_useCurrent
->setChecked (useCurrent
);
138 order_list
->setEnabled(!useCurrent
);
139 item_down
->setEnabled(!useCurrent
);
140 item_skip
->setEnabled(!useCurrent
);
141 item_up
->setEnabled(!useCurrent
);
146 void PasteOptPage::initFocus() const
148 kcfg_separator
->setFocus();
152 void PasteOptPage::slotSyncLangSet(const QString
& dlg_name
)
154 // skip "skip" elements at tail
155 if (dlg_name
== i18n("&Clipboard")) {
156 // order_list contains doublettes??
157 for (int j
= (int) order_list
->count()-1; j
> 1; j
--) {
158 QString comp
= order_list
->text(j
);
159 for (int i
= (int) j
-1; i
>=0; i
--) {
160 if ( order_list
->text(i
) == comp
161 && !order_list
->text(i
).isEmpty()) {
162 // cout << "remove " << j << " " << order_list->text(j).latin1() << endl;
163 order_list
->removeItem(j
);
168 // order_list contains elements unknown in language set? remove them
169 for (int i
= (int) order_list
->count()-1; i
>=0; i
--) {
170 // cout << order_list->text(i).latin1() << endl;
171 if (!order_list
->text(i
).isEmpty())
172 if (langset
.indexLongId(order_list
->text(i
)) < 0) {
173 order_list
->removeItem(i
);
176 // language set contains new elements? append them
177 for (int i
= 0; i
< (int) langset
.size(); i
++) {
178 // cout << langset.longId(i).latin1() << endl;
179 // cout << langset.shortId(i).latin1() << endl;
181 for (int j
= 0; j
< (int) order_list
->count(); j
++)
182 if (langset
.longId(i
) == order_list
->text(j
))
186 if (langset
.longId(i
).isEmpty())
187 order_list
->insertItem (langset
.shortId(i
));
189 order_list
->insertItem (langset
.longId(i
));
195 for (i
= (int) order_list
->count()-1;
196 i
>= 0 && order_list
->text(i
).isEmpty();
198 if (order_list
->currentItem() > (int) order_list
->count()-2)
199 order_list
->setCurrentItem(order_list
->count()-2);
200 order_list
->removeItem(i
);
205 void PasteOptPage::slotSelectSep(int idx
)
207 sep
= separator_id
[idx
];
211 void PasteOptPage::slotSelectOrder(int )
217 QStringList
PasteOptPage::getPasteOrder()
219 slotSyncLangSet(i18n("&Clipboard"));
221 // skip "skip" elements at tail
223 for (i
= (int) order_list
->count()-1;
224 i
>= 0 && order_list
->text(i
).isEmpty();
227 // insert language codes and "skips" between them
228 for ( /**/; i
>= 0; i
--) {
229 QString code
= langset
.findShortId(order_list
->text(i
));
231 code
= order_list
->text(i
); // no longId previously available
232 if (order_list
->text(i
).isEmpty())
233 sl
.insert (sl
.begin(), "");
235 sl
.insert (sl
.begin(), code
);
241 void PasteOptPage::slotItemSkip()
243 int pos
= order_list
->currentItem();
244 order_list
->insertItem("", order_list
->currentItem());
245 order_list
->setCurrentItem(pos
);
246 slotSyncLangSet(i18n("&Clipboard"));
247 order_list
->setFocus();
252 void PasteOptPage::slotEnableCursor()
254 order_list
->setEnabled(!useCurrent
);
255 if (order_list
->count() > 1 && !useCurrent
) {
256 item_down
->setEnabled(order_list
->currentItem() < (int) order_list
->count()-1);
257 item_skip
->setEnabled(true);
258 item_up
->setEnabled(order_list
->currentItem() != 0);
261 item_down
->setEnabled(false);
262 item_skip
->setEnabled(false);
263 item_up
->setEnabled(false);
268 void PasteOptPage::slotItemUp()
270 if (order_list
->currentItem() > 0
271 && (int) order_list
->count() > 1) {
272 int pos
= order_list
->currentItem();
273 QString item
= order_list
->text(pos
);
274 order_list
->removeItem(pos
);
275 order_list
->insertItem(item
, pos
-1);
276 order_list
->setCurrentItem(pos
-1);
277 slotSyncLangSet(i18n("&Clipboard"));
278 order_list
->setFocus();
284 void PasteOptPage::slotItemDown()
286 if ((int)order_list
->currentItem() < (int)order_list
->count()-1
287 && (int) order_list
->count() > 1) {
288 int pos
= order_list
->currentItem();
289 QString item
= order_list
->text(pos
);
290 order_list
->removeItem(pos
);
291 order_list
->insertItem(item
, pos
+1);
292 order_list
->setCurrentItem(pos
+1);
293 slotSyncLangSet(i18n("&Clipboard"));
294 order_list
->setFocus();
300 void PasteOptPage::slotCurrentDoc(bool use
)
304 order_list
->insertItem (langset
.findLongId(doc
->getOriginalIdent()));
305 for (int i
= 1; i
< (int) doc
->numLangs(); i
++)
306 order_list
->insertItem (langset
.findLongId(doc
->getIdent(i
)));
308 // any other languages to append besides those from doc?
309 for (int i
= 0; i
< (int) langset
.size(); i
++) {
311 for (int j
= 0; j
< (int) order_list
->count(); j
++)
312 if (order_list
->text(j
) == langset
.longId(i
))
316 order_list
->insertItem(langset
.longId(i
));
319 order_list
->setCurrentItem (0);
323 order_list
->setEnabled(!useCurrent
);
324 item_down
->setEnabled(!useCurrent
);
325 item_skip
->setEnabled(!useCurrent
);
326 item_up
->setEnabled(!useCurrent
);
332 void PasteOptPage::keyPressEvent( QKeyEvent
*e
)
334 if (e
->state() & AltButton
& ControlButton
& ShiftButton
== 0) {
335 if ( e
->key() == Key_Escape
)
337 else if ( e
->key() == Key_Enter
338 ||e
->key() == Key_Return
)
346 #include "PasteOptPage.moc"