1 | #include "opt_groupchat.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_groupchat.h"
|
---|
17 |
|
---|
18 | //----------------------------------------------------------------------------
|
---|
19 | // OptionsTabGroupchat -- TODO: simplify the code
|
---|
20 | //----------------------------------------------------------------------------
|
---|
21 |
|
---|
22 | OptionsTabGroupchat::OptionsTabGroupchat(QObject *parent)
|
---|
23 | : OptionsTab(parent, "groupchat", "", tr("Groupchat"), tr("Configure the groupchat"), "psi/groupChat")
|
---|
24 | {
|
---|
25 | w = 0;
|
---|
26 | }
|
---|
27 |
|
---|
28 | void OptionsTabGroupchat::setData(PsiCon *, QWidget *_dlg)
|
---|
29 | {
|
---|
30 | dlg = _dlg;
|
---|
31 | }
|
---|
32 |
|
---|
33 | QWidget *OptionsTabGroupchat::widget()
|
---|
34 | {
|
---|
35 | if ( w )
|
---|
36 | return 0;
|
---|
37 |
|
---|
38 | w = new GeneralGroupchatUI();
|
---|
39 | GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
|
---|
40 |
|
---|
41 | connect(d->pb_nickColor, SIGNAL(clicked()), SLOT(chooseGCNickColor()));
|
---|
42 | connect(d->lb_nickColors, SIGNAL(highlighted(int)), SLOT(selectedGCNickColor()));
|
---|
43 |
|
---|
44 | connect(d->pb_addHighlightWord, SIGNAL(clicked()), SLOT(addGCHighlight()));
|
---|
45 | connect(d->pb_removeHighlightWord, SIGNAL(clicked()), SLOT(removeGCHighlight()));
|
---|
46 |
|
---|
47 | connect(d->pb_addNickColor, SIGNAL(clicked()), SLOT(addGCNickColor()));
|
---|
48 | connect(d->pb_removeNickColor, SIGNAL(clicked()), SLOT(removeGCNickColor()));
|
---|
49 |
|
---|
50 | // TODO: add QWhatsThis for all controls on widget
|
---|
51 |
|
---|
52 | return w;
|
---|
53 | }
|
---|
54 |
|
---|
55 | void OptionsTabGroupchat::applyOptions(Options *opt)
|
---|
56 | {
|
---|
57 | if ( !w )
|
---|
58 | return;
|
---|
59 |
|
---|
60 | GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
|
---|
61 | opt->gcHighlighting = d->ck_gcHighlights->isChecked();
|
---|
62 | opt->gcNickColoring = d->ck_gcNickColoring->isChecked();
|
---|
63 |
|
---|
64 | QStringList highlight;
|
---|
65 | int i;
|
---|
66 | for (i = 0; i < (int)d->lb_highlightWords->count(); i++)
|
---|
67 | highlight << d->lb_highlightWords->item(i)->text();
|
---|
68 | opt->gcHighlights = highlight;
|
---|
69 |
|
---|
70 | QStringList colors;
|
---|
71 | for (i = 0; i < (int)d->lb_nickColors->count(); i++)
|
---|
72 | colors << d->lb_nickColors->item(i)->text();
|
---|
73 | opt->gcNickColors = colors;
|
---|
74 | }
|
---|
75 |
|
---|
76 | void OptionsTabGroupchat::restoreOptions(const Options *opt)
|
---|
77 | {
|
---|
78 | if ( !w )
|
---|
79 | return;
|
---|
80 |
|
---|
81 | GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
|
---|
82 |
|
---|
83 | // no need to call dataChanged() when these widgets are modified
|
---|
84 | disconnect(d->le_newNickColor, SIGNAL(textChanged(const QString &)), 0, 0);
|
---|
85 | disconnect(d->le_newHighlightWord, SIGNAL(textChanged(const QString &)), 0, 0);
|
---|
86 | connect(d->le_newNickColor, SIGNAL(textChanged(const QString &)), SLOT(displayGCNickColor()));
|
---|
87 |
|
---|
88 | d->ck_gcHighlights->setChecked( true );
|
---|
89 | d->ck_gcHighlights->setChecked( opt->gcHighlighting );
|
---|
90 | d->ck_gcNickColoring->setChecked( true );
|
---|
91 | d->ck_gcNickColoring->setChecked( opt->gcNickColoring );
|
---|
92 | d->lb_highlightWords->clear();
|
---|
93 | d->lb_highlightWords->insertStringList( opt->gcHighlights );
|
---|
94 | d->lb_nickColors->clear();
|
---|
95 |
|
---|
96 | QStringList::ConstIterator it = opt->gcNickColors.begin();
|
---|
97 | for ( ; it != opt->gcNickColors.end(); ++it)
|
---|
98 | addNickColor( *it );
|
---|
99 |
|
---|
100 | d->le_newHighlightWord->setText("");
|
---|
101 | d->le_newNickColor->setText("#FFFFFF");
|
---|
102 | }
|
---|
103 |
|
---|
104 | static QPixmap name2color(QString name)
|
---|
105 | {
|
---|
106 | QColor c(name);
|
---|
107 | QPixmap pix(16, 16);
|
---|
108 | QPainter p(&pix);
|
---|
109 |
|
---|
110 | p.fillRect(0, 0, pix.width(), pix.height(), QBrush(c));
|
---|
111 | p.setPen( QColor(0, 0, 0) );
|
---|
112 | p.drawRect(0, 0, pix.width(), pix.height());
|
---|
113 | p.end();
|
---|
114 |
|
---|
115 | return pix;
|
---|
116 | }
|
---|
117 |
|
---|
118 | void OptionsTabGroupchat::addNickColor(QString name)
|
---|
119 | {
|
---|
120 | GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
|
---|
121 | d->lb_nickColors->insertItem(name2color(name), name);
|
---|
122 | }
|
---|
123 |
|
---|
124 | void OptionsTabGroupchat::addGCHighlight()
|
---|
125 | {
|
---|
126 | GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
|
---|
127 | if ( d->le_newHighlightWord->text().isEmpty() )
|
---|
128 | return;
|
---|
129 |
|
---|
130 | d->lb_highlightWords->insertItem( d->le_newHighlightWord->text() );
|
---|
131 | d->le_newHighlightWord->setFocus();
|
---|
132 | d->le_newHighlightWord->setText("");
|
---|
133 |
|
---|
134 | emit dataChanged();
|
---|
135 | }
|
---|
136 |
|
---|
137 | void OptionsTabGroupchat::removeGCHighlight()
|
---|
138 | {
|
---|
139 | GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
|
---|
140 | int id = d->lb_highlightWords->currentItem();
|
---|
141 | if ( id == -1 )
|
---|
142 | return;
|
---|
143 |
|
---|
144 | d->lb_highlightWords->removeItem(id);
|
---|
145 |
|
---|
146 | emit dataChanged();
|
---|
147 | }
|
---|
148 |
|
---|
149 | void OptionsTabGroupchat::addGCNickColor()
|
---|
150 | {
|
---|
151 | GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
|
---|
152 | if ( d->le_newNickColor->text().isEmpty() )
|
---|
153 | return;
|
---|
154 |
|
---|
155 | addNickColor( d->le_newNickColor->text() );
|
---|
156 | d->le_newNickColor->setFocus();
|
---|
157 | d->le_newNickColor->setText("");
|
---|
158 |
|
---|
159 | emit dataChanged();
|
---|
160 | }
|
---|
161 |
|
---|
162 | void OptionsTabGroupchat::removeGCNickColor()
|
---|
163 | {
|
---|
164 | GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
|
---|
165 | int id = d->lb_nickColors->currentItem();
|
---|
166 | if ( id == -1 )
|
---|
167 | return;
|
---|
168 |
|
---|
169 | d->lb_nickColors->removeItem(id);
|
---|
170 |
|
---|
171 | emit dataChanged();
|
---|
172 | }
|
---|
173 |
|
---|
174 | void OptionsTabGroupchat::chooseGCNickColor()
|
---|
175 | {
|
---|
176 | GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
|
---|
177 | QColor c = QColorDialog::getColor(QColor(d->le_newNickColor->text()), dlg);
|
---|
178 | if ( c.isValid() ) {
|
---|
179 | QString cs = c.name();
|
---|
180 | d->le_newNickColor->setText(cs);
|
---|
181 | }
|
---|
182 | }
|
---|
183 |
|
---|
184 | void OptionsTabGroupchat::selectedGCNickColor()
|
---|
185 | {
|
---|
186 | GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
|
---|
187 | int id = d->lb_nickColors->currentItem();
|
---|
188 | if ( id == -1 )
|
---|
189 | return;
|
---|
190 |
|
---|
191 | d->le_newNickColor->setText( d->lb_nickColors->text(id) );
|
---|
192 | }
|
---|
193 |
|
---|
194 | void OptionsTabGroupchat::displayGCNickColor()
|
---|
195 | {
|
---|
196 | GeneralGroupchatUI *d = (GeneralGroupchatUI *)w;
|
---|
197 | d->pb_nickColor->setPixmap( name2color(d->le_newNickColor->text()) );
|
---|
198 | }
|
---|