~ubuntu-branches/ubuntu/edgy/psi/edgy

« back to all changes in this revision

Viewing changes to src/options/opt_general.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2004-06-15 00:10:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040615001041-enywb6pcpe4sjsw6
Tags: 0.9.2-1
* New upstream release
* Set KDEDIR for ./configure so kde specific files get installed
* Don't install libpsiwidgets.so. It got installed in /usr/share
  where it doesn't belong. May be included (at a better location)
  later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "opt_general.h"
 
2
#include "common.h"
 
3
#include "iconwidget.h"
 
4
 
 
5
#include <qbuttongroup.h>
 
6
#include <qwhatsthis.h>
 
7
#include <qcheckbox.h>
 
8
#include <qradiobutton.h>
 
9
#include <qcombobox.h>
 
10
#include <qlineedit.h>
 
11
#include <qsignalmapper.h>
 
12
#include <qpixmap.h>
 
13
#include <qpainter.h>
 
14
#include <qcolordialog.h>
 
15
 
 
16
#include "opt_general_roster.h"
 
17
#include "opt_general_docking.h"
 
18
#include "opt_general_misc.h"
 
19
#include "opt_general_notify.h"
 
20
#include "opt_general_groupchat.h"
 
21
 
 
22
//----------------------------------------------------------------------------
 
23
// OptionsTabGeneral
 
24
//----------------------------------------------------------------------------
 
25
 
 
26
OptionsTabGeneral::OptionsTabGeneral(QObject *parent)
 
27
: MetaOptionsTab(parent, "general", "", tr("General"), tr("General options"), "psi/psi16")
 
28
{
 
29
        addTab( new OptionsTabGeneralRoster(this) );
 
30
        addTab( new OptionsTabGeneralDocking(this) );
 
31
        addTab( new OptionsTabGeneralMisc(this) );
 
32
        addTab( new OptionsTabGeneralNotifications(this) );
 
33
        addTab( new OptionsTabGeneralGroupchat(this) );
 
34
}
 
35
 
 
36
//----------------------------------------------------------------------------
 
37
// OptionsTabGeneralRoster
 
38
//----------------------------------------------------------------------------
 
39
 
 
40
OptionsTabGeneralRoster::OptionsTabGeneralRoster(QObject *parent)
 
41
: OptionsTab(parent, "general_roster", "general", tr("Roster"), tr("Configure your roster"))
 
42
{
 
43
        w = 0;
 
44
        bg_defAct = 0;
 
45
}
 
46
 
 
47
OptionsTabGeneralRoster::~OptionsTabGeneralRoster()
 
48
{
 
49
        if ( bg_defAct )
 
50
                delete bg_defAct;
 
51
}
 
52
 
 
53
QWidget *OptionsTabGeneralRoster::widget()
 
54
{
 
55
        if ( w )
 
56
                return 0;
 
57
 
 
58
        w = new GeneralRosterUI();
 
59
        GeneralRosterUI *d = (GeneralRosterUI *)w;
 
60
 
 
61
        bg_defAct = new QButtonGroup;
 
62
        bg_defAct->setRadioButtonExclusive( true );
 
63
        bg_defAct->insert( d->rb_defActMsg,  0 );
 
64
        bg_defAct->insert( d->rb_defActChat, 1 );
 
65
 
 
66
        QWhatsThis::add(d->ck_useleft,
 
67
                tr("Normally, right-clicking with the mouse on a contact will activate the context-menu."
 
68
                "  Check this option if you'd rather use a left-click."));
 
69
        QWhatsThis::add(d->ck_singleclick,
 
70
                tr("Normally, a double-click on a contact will invoke the default action."
 
71
                "  Check this option if you'd rather invoke with a single-click."));
 
72
 
 
73
        QWhatsThis::add(d->rb_defActMsg,
 
74
                tr("Make the default action open a chat window."));
 
75
        QWhatsThis::add(d->rb_defActChat,
 
76
                tr("Make the default action open a normal message window."));
 
77
 
 
78
        QWhatsThis::add(d->ck_showself,
 
79
                tr("If checked, always show the self-contact in roster, "
 
80
                   "otherwise it is shown only when multiple resources are connected to your account."));
 
81
 
 
82
        return w;
 
83
}
 
84
 
 
85
void OptionsTabGeneralRoster::applyOptions(Options *opt)
 
86
{
 
87
        if ( !w )
 
88
                return;
 
89
 
 
90
        GeneralRosterUI *d = (GeneralRosterUI *)w;
 
91
        opt->useleft = d->ck_useleft->isChecked();
 
92
        opt->singleclick = d->ck_singleclick->isChecked();
 
93
        opt->defaultAction = bg_defAct->id(bg_defAct->selected());
 
94
        opt->alwaysShowSelf = d->ck_showself->isChecked();
 
95
}
 
96
 
 
97
void OptionsTabGeneralRoster::restoreOptions(const Options *opt)
 
98
{
 
99
        if ( !w )
 
100
                return;
 
101
 
 
102
        GeneralRosterUI *d = (GeneralRosterUI *)w;
 
103
        d->ck_useleft->setChecked( opt->useleft );
 
104
        d->ck_singleclick->setChecked( opt->singleclick );
 
105
        bg_defAct->setButton( opt->defaultAction );
 
106
        d->ck_showself->setChecked( opt->alwaysShowSelf );
 
107
}
 
108
 
 
109
//----------------------------------------------------------------------------
 
110
// OptionsTabGeneralDocking
 
111
//----------------------------------------------------------------------------
 
112
 
 
113
OptionsTabGeneralDocking::OptionsTabGeneralDocking(QObject *parent)
 
114
: OptionsTab(parent, "general_docking", "general", tr("Docking"), tr("Configure the Psi docklet"))
 
115
{
 
116
        w = 0;
 
117
}
 
118
 
 
119
QWidget *OptionsTabGeneralDocking::widget()
 
120
{
 
121
        if ( w )
 
122
                return 0;
 
123
 
 
124
        w = new GeneralDockingUI();
 
125
        GeneralDockingUI *d = (GeneralDockingUI *)w;
 
126
 
 
127
        connect(d->ck_docklet, SIGNAL(toggled(bool)), d->ck_dockDCstyle, SLOT(setEnabled(bool)));
 
128
        connect(d->ck_docklet, SIGNAL(toggled(bool)), d->ck_dockHideMW,  SLOT(setEnabled(bool)));
 
129
        connect(d->ck_docklet, SIGNAL(toggled(bool)), d->ck_dockToolMW,  SLOT(setEnabled(bool)));
 
130
 
 
131
        QWhatsThis::add(d->ck_docklet,
 
132
                tr("Makes Psi use a docklet icon, also known as system tray icon."));
 
133
        QWhatsThis::add(d->ck_dockDCstyle,
 
134
                tr("Normally, single-clicking on the Psi docklet icon brings the main window to"
 
135
                " the foreground.  Check this option if you would rather use a double-click."));
 
136
        QWhatsThis::add(d->ck_dockHideMW,
 
137
                tr("Starts Psi with only the docklet icon visible."));
 
138
        QWhatsThis::add(d->ck_dockToolMW,
 
139
                tr("Prevents Psi from taking up a slot on the taskbar and makes the main "
 
140
                "window use a small titlebar."));
 
141
 
 
142
        return w;
 
143
}
 
144
 
 
145
void OptionsTabGeneralDocking::applyOptions(Options *opt)
 
146
{
 
147
        if ( !w )
 
148
                return;
 
149
 
 
150
        GeneralDockingUI *d = (GeneralDockingUI *)w;
 
151
        opt->useDock = d->ck_docklet->isChecked();
 
152
        opt->dockDCstyle = d->ck_dockDCstyle->isChecked();
 
153
        opt->dockHideMW = d->ck_dockHideMW->isChecked();
 
154
        opt->dockToolMW = d->ck_dockToolMW->isChecked();
 
155
}
 
156
 
 
157
void OptionsTabGeneralDocking::restoreOptions(const Options *opt)
 
158
{
 
159
        if ( !w )
 
160
                return;
 
161
 
 
162
        GeneralDockingUI *d = (GeneralDockingUI *)w;
 
163
        d->ck_docklet->setChecked( opt->useDock );
 
164
        d->ck_dockDCstyle->setChecked( opt->dockDCstyle );
 
165
        d->ck_dockHideMW->setChecked( opt->dockHideMW );
 
166
        d->ck_dockToolMW->setChecked( opt->dockToolMW );
 
167
 
 
168
        if( !d->ck_docklet->isChecked() ) {
 
169
                d->ck_dockDCstyle->setEnabled(false);
 
170
                d->ck_dockHideMW->setEnabled(false);
 
171
                d->ck_dockToolMW->setEnabled(false);
 
172
        }
 
173
}
 
174
 
 
175
//----------------------------------------------------------------------------
 
176
// OptionsTabGeneralMisc
 
177
//----------------------------------------------------------------------------
 
178
 
 
179
OptionsTabGeneralMisc::OptionsTabGeneralMisc(QObject *parent)
 
180
: OptionsTab(parent, "general_misc", "general", tr("Misc"), tr("Miscellaneous settings"))
 
181
{
 
182
        w = 0;
 
183
        bg_delChats = 0;
 
184
}
 
185
 
 
186
OptionsTabGeneralMisc::~OptionsTabGeneralMisc()
 
187
{
 
188
        if ( bg_delChats )
 
189
                delete bg_delChats;
 
190
}
 
191
 
 
192
QWidget *OptionsTabGeneralMisc::widget()
 
193
{
 
194
        if ( w )
 
195
                return 0;
 
196
 
 
197
        w = new GeneralMiscUI();
 
198
        GeneralMiscUI *d = (GeneralMiscUI *)w;
 
199
 
 
200
        // chat
 
201
        QWhatsThis::add(d->ck_chatSays,
 
202
                tr("<P>Changes the normal chat style from:</P>"
 
203
                "<P>[01:23:45] &lt;MyName&gt; Hi</P>"
 
204
                "<P>[01:23:56] &lt;YourName&gt; How are you?</P>"
 
205
                "<P>to:</P>"
 
206
                "<P>[01:23:45] MyName says:</P>"
 
207
                "<P>Hi</P>"
 
208
                "<P>[01:23:56] YourName says:</P>"
 
209
                "<P>How are you?</P>"));
 
210
        QWhatsThis::add(d->ck_chatSoftReturn,
 
211
                tr("<P>When checked, pressing Enter in a chat window will send your message."
 
212
                   "  You must use Shift+Enter in order to create a newline in the chat message."
 
213
                   "  If unchecked, messages are sent by pressing Alt-S or Control-Enter, just as they are with regular messages.</P>"));
 
214
 
 
215
        // misc
 
216
        bg_delChats = new QButtonGroup;
 
217
        bg_delChats->setRadioButtonExclusive( true );
 
218
        bg_delChats->insert( d->rb_delChatsClose, 0 );
 
219
        bg_delChats->insert( d->rb_delChatsHour,  1 );
 
220
        bg_delChats->insert( d->rb_delChatsDay,   2 );
 
221
        bg_delChats->insert( d->rb_delChatsNever, 3 );
 
222
 
 
223
        QWhatsThis::add(d->ck_alwaysOnTop,
 
224
                tr("Makes the main Psi window always be in front of other windows."));
 
225
        QWhatsThis::add(d->ck_keepSizes,
 
226
                tr("Makes Psi remember window size and positions for chats and messages."
 
227
                "  If disabled, the windows will always appear in their default positions and sizes."));
 
228
        QWhatsThis::add(d->ck_jidComplete,
 
229
                tr("Enables as-you-type JID autocompletion in message dialog."));
 
230
        QWhatsThis::add(d->ck_grabUrls,
 
231
                tr("Automatically attaches URLs from clipboard to the messages when enabled"));
 
232
 
 
233
        QString s = tr("<P>Controls how long the chat log will be kept in memory after the"
 
234
                " chat window is closed.</P>");
 
235
        QWhatsThis::add(d->rb_delChatsClose, s +
 
236
                tr("<P>This option does not keep the chat log in memory.</P>"));
 
237
        QWhatsThis::add(d->rb_delChatsHour, s +
 
238
                tr("<P>This option keeps the chat log for 1 hour before deleting it.</P>"));
 
239
        QWhatsThis::add(d->rb_delChatsDay, s +
 
240
                tr("<P>This option keeps the chat log for 1 day before deleting it.</P>"));
 
241
        QWhatsThis::add(d->rb_delChatsNever, s +
 
242
                tr("<P>This options keeps the chat log forever.</P>"));
 
243
 
 
244
        // links
 
245
        QWhatsThis::add(d->cb_link,
 
246
                tr("Selects what applications to use for handling URLs and e-mail addresses."
 
247
                "  You can choose between the system default and custom applications."));
 
248
 
 
249
        s = tr("Enter the path to the application's executable and choose \"Custom\" in the list above.");
 
250
        QWhatsThis::add(d->le_linkBrowser,
 
251
                tr("Specify what custom browser application to use for handling URLs here.") + "  " + s);
 
252
        QWhatsThis::add(d->le_linkMailer,
 
253
                tr("Specify what custom mailer application to use for handling e-mail addresses here.") + "  " + s);
 
254
 
 
255
        return w;
 
256
}
 
257
 
 
258
static int om_x11browse[] = { 0, 2, 1 };
 
259
 
 
260
void OptionsTabGeneralMisc::applyOptions(Options *opt)
 
261
{
 
262
        if ( !w )
 
263
                return;
 
264
 
 
265
        GeneralMiscUI *d = (GeneralMiscUI *)w;
 
266
 
 
267
        // chat
 
268
        opt->chatSays       = d->ck_chatSays->isChecked();
 
269
        opt->chatSoftReturn = d->ck_chatSoftReturn->isChecked();
 
270
 
 
271
        // misc
 
272
        opt->alwaysOnTop = d->ck_alwaysOnTop->isChecked();
 
273
        opt->keepSizes   = d->ck_keepSizes->isChecked();
 
274
        opt->jidComplete = d->ck_jidComplete->isChecked();
 
275
        opt->grabUrls    = d->ck_grabUrls->isChecked();
 
276
        opt->delChats    = bg_delChats->id( bg_delChats->selected() );
 
277
 
 
278
        // links
 
279
#ifdef Q_WS_X11
 
280
        opt->browser = om_x11browse[ d->cb_link->currentItem() ];
 
281
#else
 
282
        opt->browser = d->cb_link->currentItem();
 
283
#endif
 
284
        opt->customBrowser = d->le_linkBrowser->text();
 
285
        opt->customMailer  = d->le_linkMailer->text();
 
286
}
 
287
 
 
288
void OptionsTabGeneralMisc::restoreOptions(const Options *opt)
 
289
{
 
290
        if ( !w )
 
291
                return;
 
292
 
 
293
        GeneralMiscUI *d = (GeneralMiscUI *)w;
 
294
 
 
295
        // chat
 
296
        d->ck_chatSays->setChecked( opt->chatSays );
 
297
        d->ck_chatSoftReturn->setChecked( opt->chatSoftReturn );
 
298
 
 
299
        // misc
 
300
#ifdef Q_WS_MAC
 
301
        d->ck_alwaysOnTop->setEnabled( false );
 
302
#else
 
303
        d->ck_alwaysOnTop->setChecked( opt->alwaysOnTop );
 
304
#endif
 
305
        d->ck_keepSizes->setChecked( opt->keepSizes );
 
306
        d->ck_jidComplete->setChecked( opt->jidComplete );
 
307
        d->ck_grabUrls->setChecked( opt->grabUrls );
 
308
 
 
309
        bg_delChats->setButton( opt->delChats );
 
310
 
 
311
        // links
 
312
        connect(d->cb_link, SIGNAL(activated(int)), SLOT(selectBrowser(int)));
 
313
#ifdef Q_WS_WIN
 
314
        d->cb_link->insertItem(tr("Windows Default Browser/Mail"));
 
315
        d->cb_link->insertItem(tr("Custom"));
 
316
        d->cb_link->setCurrentItem( opt->browser );
 
317
        selectBrowser( opt->browser );
 
318
#endif
 
319
#ifdef Q_WS_X11
 
320
        d->cb_link->insertItem(tr("KDE Default Browser/Mail"));
 
321
        d->cb_link->insertItem(tr("GNOME2 Default Browser/Mail"));
 
322
        d->cb_link->insertItem(tr("Custom"));
 
323
        int rbi = om_x11browse[ opt->browser ];
 
324
        d->cb_link->setCurrentItem( rbi );
 
325
        selectBrowser( rbi );
 
326
#endif
 
327
#ifdef Q_WS_MAC
 
328
        d->cb_link->insertItem(tr("MacOS Default Browser/Mail"));
 
329
        d->cb_link->setCurrentItem( opt->browser );
 
330
        selectBrowser( opt->browser );
 
331
#endif
 
332
        d->le_linkBrowser->setText( opt->customBrowser );
 
333
        d->le_linkMailer->setText( opt->customMailer );
 
334
}
 
335
 
 
336
void OptionsTabGeneralMisc::selectBrowser(int x)
 
337
{
 
338
        if ( !w )
 
339
                return;
 
340
 
 
341
        bool enableCustom = TRUE;
 
342
 
 
343
#ifdef Q_WS_WIN
 
344
        if(x == 0)
 
345
                enableCustom = FALSE;
 
346
#endif
 
347
#ifdef Q_WS_X11
 
348
        if(x == 0 || x == 1)
 
349
                enableCustom = FALSE;
 
350
#endif
 
351
#ifdef Q_WS_MAC
 
352
        if(x == 0)
 
353
                enableCustom = FALSE;
 
354
#endif
 
355
 
 
356
        GeneralMiscUI *d = (GeneralMiscUI *)w;
 
357
        d->gb_linkCustom->setEnabled(enableCustom);
 
358
}
 
359
 
 
360
//----------------------------------------------------------------------------
 
361
// OptionsTabGeneralNotifications
 
362
//----------------------------------------------------------------------------
 
363
 
 
364
OptionsTabGeneralNotifications::OptionsTabGeneralNotifications(QObject *parent)
 
365
: OptionsTab(parent, "general_notifications", "general", tr("Notifications"), tr("Configure the popup notifications"))
 
366
{
 
367
        w = 0;
 
368
}
 
369
 
 
370
QWidget *OptionsTabGeneralNotifications::widget()
 
371
{
 
372
        if ( w )
 
373
                return 0;
 
374
 
 
375
        w = new GeneralNotifyUI();
 
376
        //GeneralNotifyUI *d = (GeneralNotifyUI *)w;
 
377
 
 
378
        // TODO: add QWhatsThis for all controls on widget
 
379
 
 
380
        return w;
 
381
}
 
382
 
 
383
void OptionsTabGeneralNotifications::applyOptions(Options *opt)
 
384
{
 
385
        if ( !w )
 
386
                return;
 
387
 
 
388
        GeneralNotifyUI *d = (GeneralNotifyUI *)w;
 
389
        opt->ppIsOn = d->ck_popupOn->isChecked();
 
390
        opt->ppMessage = d->ck_popupOnMessage->isChecked();
 
391
        opt->ppChat    = d->ck_popupOnChat->isChecked();
 
392
        opt->ppHeadline = d->ck_popupOnHeadline->isChecked();
 
393
        opt->ppStatus  = d->ck_popupOnStatus->isChecked();
 
394
        opt->ppOnline  = d->ck_popupOnOnline->isChecked();
 
395
        opt->ppOffline = d->ck_popupOnOffline->isChecked();
 
396
}
 
397
 
 
398
void OptionsTabGeneralNotifications::restoreOptions(const Options *opt)
 
399
{
 
400
        if ( !w )
 
401
                return;
 
402
 
 
403
        GeneralNotifyUI *d = (GeneralNotifyUI *)w;
 
404
        d->ck_popupOn->setChecked( true );
 
405
        d->ck_popupOn->setChecked( opt->ppIsOn );
 
406
        d->ck_popupOnMessage->setChecked( opt->ppMessage );
 
407
        d->ck_popupOnChat->setChecked( opt->ppChat );
 
408
        d->ck_popupOnHeadline->setChecked( opt->ppHeadline );
 
409
        d->ck_popupOnStatus->setChecked( opt->ppStatus );
 
410
        d->ck_popupOnOnline->setChecked( opt->ppOnline );
 
411
        d->ck_popupOnOffline->setChecked( opt->ppOffline );
 
412
}
 
413
 
 
414
//----------------------------------------------------------------------------
 
415
// OptionsTabGeneralGroupchat -- TODO: simplify the code
 
416
//----------------------------------------------------------------------------
 
417
 
 
418
OptionsTabGeneralGroupchat::OptionsTabGeneralGroupchat(QObject *parent)
 
419
: OptionsTab(parent, "general_groupchat", "general", tr("Groupchat"), tr("Configure the groupchat"))
 
420
{
 
421
        w = 0;
 
422
}
 
423
 
 
424
void OptionsTabGeneralGroupchat::setData(PsiCon *, QWidget *_dlg)
 
425
{
 
426
        dlg = _dlg;
 
427
}
 
428
 
 
429
QWidget *OptionsTabGeneralGroupchat::widget()
 
430
{
 
431
        if ( w )
 
432
                return 0;
 
433
 
 
434
        w = new GeneralGroupchatUI();
 
435
        GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
 
436
 
 
437
        connect(d->pb_nickColor,           SIGNAL(clicked()), SLOT(chooseGCNickColor()));
 
438
        connect(d->lb_nickColors,          SIGNAL(highlighted(int)), SLOT(selectedGCNickColor()));
 
439
 
 
440
        connect(d->pb_addHighlightWord,    SIGNAL(clicked()), SLOT(addGCHighlight()));
 
441
        connect(d->pb_removeHighlightWord, SIGNAL(clicked()), SLOT(removeGCHighlight()));
 
442
 
 
443
        connect(d->pb_addNickColor,        SIGNAL(clicked()), SLOT(addGCNickColor()));
 
444
        connect(d->pb_removeNickColor,     SIGNAL(clicked()), SLOT(removeGCNickColor()));
 
445
 
 
446
        // TODO: add QWhatsThis for all controls on widget
 
447
 
 
448
        return w;
 
449
}
 
450
 
 
451
void OptionsTabGeneralGroupchat::applyOptions(Options *opt)
 
452
{
 
453
        if ( !w )
 
454
                return;
 
455
 
 
456
        GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
 
457
        opt->gcHighlighting = d->ck_gcHighlights->isChecked();
 
458
        opt->gcNickColoring = d->ck_gcNickColoring->isChecked();
 
459
 
 
460
        QStringList highlight;
 
461
        int i;
 
462
        for (i = 0; i < (int)d->lb_highlightWords->count(); i++)
 
463
                highlight << d->lb_highlightWords->item(i)->text();
 
464
        opt->gcHighlights = highlight;
 
465
 
 
466
        QStringList colors;
 
467
        for (i = 0; i < (int)d->lb_nickColors->count(); i++)
 
468
                colors << d->lb_nickColors->item(i)->text();
 
469
        opt->gcNickColors = colors;
 
470
}
 
471
 
 
472
void OptionsTabGeneralGroupchat::restoreOptions(const Options *opt)
 
473
{
 
474
        if ( !w )
 
475
                return;
 
476
 
 
477
        GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
 
478
 
 
479
        // no need to call dataChanged() when these widgets are modified
 
480
        disconnect(d->le_newNickColor,     SIGNAL(textChanged(const QString &)), 0, 0);
 
481
        disconnect(d->le_newHighlightWord, SIGNAL(textChanged(const QString &)), 0, 0);
 
482
        connect(d->le_newNickColor,        SIGNAL(textChanged(const QString &)), SLOT(displayGCNickColor()));
 
483
 
 
484
        d->ck_gcHighlights->setChecked( true );
 
485
        d->ck_gcHighlights->setChecked( opt->gcHighlighting );
 
486
        d->ck_gcNickColoring->setChecked( true );
 
487
        d->ck_gcNickColoring->setChecked( opt->gcNickColoring );
 
488
        d->lb_highlightWords->clear();
 
489
        d->lb_highlightWords->insertStringList( opt->gcHighlights );
 
490
        d->lb_nickColors->clear();
 
491
 
 
492
        QStringList::ConstIterator it = opt->gcNickColors.begin();
 
493
        for ( ; it != opt->gcNickColors.end(); ++it)
 
494
                addNickColor( *it );
 
495
 
 
496
        d->le_newHighlightWord->setText("");
 
497
        d->le_newNickColor->setText("#FFFFFF");
 
498
}
 
499
 
 
500
static QPixmap name2color(QString name)
 
501
{
 
502
        QColor c(name);
 
503
        QPixmap pix(16, 16);
 
504
        QPainter p(&pix);
 
505
 
 
506
        p.fillRect(0, 0, pix.width(), pix.height(), QBrush(c));
 
507
        p.setPen( QColor(0, 0, 0) );
 
508
        p.drawRect(0, 0, pix.width(), pix.height());
 
509
        p.end();
 
510
 
 
511
        return pix;
 
512
}
 
513
 
 
514
void OptionsTabGeneralGroupchat::addNickColor(QString name)
 
515
{
 
516
        GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
 
517
        d->lb_nickColors->insertItem(name2color(name), name);
 
518
}
 
519
 
 
520
void OptionsTabGeneralGroupchat::addGCHighlight()
 
521
{
 
522
        GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
 
523
        if ( d->le_newHighlightWord->text().isEmpty() )
 
524
                return;
 
525
 
 
526
        d->lb_highlightWords->insertItem( d->le_newHighlightWord->text() );
 
527
        d->le_newHighlightWord->setFocus();
 
528
        d->le_newHighlightWord->setText("");
 
529
 
 
530
        emit dataChanged();
 
531
}
 
532
 
 
533
void OptionsTabGeneralGroupchat::removeGCHighlight()
 
534
{
 
535
        GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
 
536
        int id = d->lb_highlightWords->currentItem();
 
537
        if ( id == -1 )
 
538
                return;
 
539
 
 
540
        d->lb_highlightWords->removeItem(id);
 
541
 
 
542
        emit dataChanged();
 
543
}
 
544
 
 
545
void OptionsTabGeneralGroupchat::addGCNickColor()
 
546
{
 
547
        GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
 
548
        if ( d->le_newNickColor->text().isEmpty() )
 
549
                return;
 
550
 
 
551
        addNickColor( d->le_newNickColor->text() );
 
552
        d->le_newNickColor->setFocus();
 
553
        d->le_newNickColor->setText("");
 
554
 
 
555
        emit dataChanged();
 
556
}
 
557
 
 
558
void OptionsTabGeneralGroupchat::removeGCNickColor()
 
559
{
 
560
        GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
 
561
        int id = d->lb_nickColors->currentItem();
 
562
        if ( id == -1 )
 
563
                return;
 
564
 
 
565
        d->lb_nickColors->removeItem(id);
 
566
 
 
567
        emit dataChanged();
 
568
}
 
569
 
 
570
void OptionsTabGeneralGroupchat::chooseGCNickColor()
 
571
{
 
572
        GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
 
573
        QColor c = QColorDialog::getColor(QColor(d->le_newNickColor->text()), dlg);
 
574
        if ( c.isValid() ) {
 
575
                QString cs = c.name();
 
576
                d->le_newNickColor->setText(cs);
 
577
        }
 
578
}
 
579
 
 
580
void OptionsTabGeneralGroupchat::selectedGCNickColor()
 
581
{
 
582
        GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
 
583
        int id = d->lb_nickColors->currentItem();
 
584
        if ( id == -1 )
 
585
                return;
 
586
 
 
587
        d->le_newNickColor->setText( d->lb_nickColors->text(id) );
 
588
}
 
589
 
 
590
void OptionsTabGeneralGroupchat::displayGCNickColor()
 
591
{
 
592
        GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
 
593
        d->pb_nickColor->setPixmap( name2color(d->le_newNickColor->text()) );
 
594
}