1 | #include "opt_appearance.h"
|
---|
2 | #include "opt_iconset.h"
|
---|
3 | #include "common.h"
|
---|
4 | #include "iconwidget.h"
|
---|
5 |
|
---|
6 | #include <qwhatsthis.h>
|
---|
7 | #include <qcheckbox.h>
|
---|
8 | #include <qslider.h>
|
---|
9 | #include <qlabel.h>
|
---|
10 | #include <qcombobox.h>
|
---|
11 | #include <qbuttongroup.h>
|
---|
12 | #include <qradiobutton.h>
|
---|
13 | #include <qpainter.h>
|
---|
14 | #include <qpixmap.h>
|
---|
15 | #include <qcolordialog.h>
|
---|
16 | #include <qfontdialog.h>
|
---|
17 | #include <qlineedit.h>
|
---|
18 |
|
---|
19 | #include "opt_appearance-ui.h"
|
---|
20 | #include "opt_appearance_misc-ui.h"
|
---|
21 |
|
---|
22 | //----------------------------------------------------------------------------
|
---|
23 | // FontLabel
|
---|
24 | //----------------------------------------------------------------------------
|
---|
25 |
|
---|
26 | FontLabel::FontLabel(QWidget *parent, const char *name)
|
---|
27 | : QLineEdit(parent, name)
|
---|
28 | {
|
---|
29 | setReadOnly(true);
|
---|
30 | setPaletteBackgroundColor(parent->paletteBackgroundColor());
|
---|
31 |
|
---|
32 | m_defaultHeight = QLineEdit::sizeHint().height();
|
---|
33 | }
|
---|
34 |
|
---|
35 | void FontLabel::setFont(QString fontName)
|
---|
36 | {
|
---|
37 | QFont f;
|
---|
38 | f.fromString(fontName);
|
---|
39 | m_font = fontName;
|
---|
40 | setText( tr("%1 %2").arg( f.family() ).arg( f.pointSize() ) );
|
---|
41 | QLineEdit::setFont(f);
|
---|
42 | }
|
---|
43 |
|
---|
44 | QString FontLabel::fontName() const
|
---|
45 | {
|
---|
46 | return m_font;
|
---|
47 | }
|
---|
48 |
|
---|
49 | QSize FontLabel::sizeHint() const
|
---|
50 | {
|
---|
51 | return QSize(QLineEdit::sizeHint().width(), m_defaultHeight);
|
---|
52 | }
|
---|
53 |
|
---|
54 |
|
---|
55 | //----------------------------------------------------------------------------
|
---|
56 | // OptionsTabAppearance
|
---|
57 | //----------------------------------------------------------------------------
|
---|
58 | OptionsTabAppearance::OptionsTabAppearance(QObject *parent) : MetaOptionsTab(parent, "appearance", "", tr("Appearance"), tr("Psi's Appearance"), "psi/appearance")
|
---|
59 | {
|
---|
60 | addTab( new OptionsTabAppearanceGeneral(this) );
|
---|
61 | addTab( new OptionsTabIconsetEmoticons(this) );
|
---|
62 | addTab( new OptionsTabIconsetRoster(this) );
|
---|
63 | addTab( new OptionsTabIconsetSystem(this) );
|
---|
64 | addTab( new OptionsTabAppearanceMisc(this) );
|
---|
65 | }
|
---|
66 |
|
---|
67 | //----------------------------------------------------------------------------
|
---|
68 | // OptionsTabAppearanceMisc
|
---|
69 | //----------------------------------------------------------------------------
|
---|
70 |
|
---|
71 | OptionsTabAppearanceMisc::OptionsTabAppearanceMisc(QObject *parent)
|
---|
72 | : OptionsTab(parent, "appearance_misc", "", tr("Misc."), tr("Miscellaneous Settings"))
|
---|
73 | {
|
---|
74 | w = 0;
|
---|
75 | o = new Options;
|
---|
76 | }
|
---|
77 |
|
---|
78 | OptionsTabAppearanceMisc::~OptionsTabAppearanceMisc()
|
---|
79 | {
|
---|
80 | delete o;
|
---|
81 | }
|
---|
82 |
|
---|
83 | QWidget *OptionsTabAppearanceMisc::widget()
|
---|
84 | {
|
---|
85 | if ( w )
|
---|
86 | return 0;
|
---|
87 |
|
---|
88 | w = new OptAppearanceMiscUI();
|
---|
89 |
|
---|
90 | #if defined(Q_WS_X11) || defined(Q_WS_PM) || (QT_VERSION < 0x030300)
|
---|
91 | OptAppearanceMiscUI *d = (OptAppearanceMiscUI *)w;
|
---|
92 | d->gb_opacity->hide();
|
---|
93 | #endif
|
---|
94 |
|
---|
95 | return w;
|
---|
96 | }
|
---|
97 |
|
---|
98 | void OptionsTabAppearanceMisc::applyOptions(Options *opt)
|
---|
99 | {
|
---|
100 | if ( !w )
|
---|
101 | return;
|
---|
102 |
|
---|
103 | OptAppearanceMiscUI *d = (OptAppearanceMiscUI *)w;
|
---|
104 |
|
---|
105 | opt->clNewHeadings = d->ck_newHeadings->isChecked();
|
---|
106 | opt->outlineHeadings = d->ck_outlineHeadings->isChecked();
|
---|
107 | opt->rosterOpacity = d->sl_rosterop->value();
|
---|
108 | opt->chatOpacity = d->sl_chatdlgop->value();
|
---|
109 | }
|
---|
110 |
|
---|
111 | void OptionsTabAppearanceMisc::restoreOptions(const Options *opt)
|
---|
112 | {
|
---|
113 | if ( !w )
|
---|
114 | return;
|
---|
115 |
|
---|
116 | OptAppearanceMiscUI *d = (OptAppearanceMiscUI *)w;
|
---|
117 |
|
---|
118 | d->ck_newHeadings->setChecked( opt->clNewHeadings );
|
---|
119 | d->ck_outlineHeadings->setChecked( opt->outlineHeadings );
|
---|
120 |
|
---|
121 | d->sl_rosterop->setValue( opt->rosterOpacity );
|
---|
122 | d->sl_chatdlgop->setValue( opt->chatOpacity );
|
---|
123 | }
|
---|
124 |
|
---|
125 | void OptionsTabAppearanceMisc::setData(PsiCon *, QWidget *parentDialog)
|
---|
126 | {
|
---|
127 | parentWidget = parentDialog;
|
---|
128 | }
|
---|
129 |
|
---|
130 | //----------------------------------------------------------------------------
|
---|
131 | // OptionsTabAppearanceGeneral: Fonts & Colours
|
---|
132 | //----------------------------------------------------------------------------
|
---|
133 |
|
---|
134 | OptionsTabAppearanceGeneral::OptionsTabAppearanceGeneral(QObject *parent)
|
---|
135 | : OptionsTab(parent, "appearance_general", "", tr("Fonts && Colors"), tr("Fonts && Color Settings"))
|
---|
136 | {
|
---|
137 | w = 0;
|
---|
138 | bg_font = 0;
|
---|
139 | bg_color = 0;
|
---|
140 | o = new Options;
|
---|
141 | }
|
---|
142 |
|
---|
143 | OptionsTabAppearanceGeneral::~OptionsTabAppearanceGeneral()
|
---|
144 | {
|
---|
145 | if ( bg_font )
|
---|
146 | delete bg_font;
|
---|
147 | if ( bg_color )
|
---|
148 | delete bg_color;
|
---|
149 | delete o;
|
---|
150 | }
|
---|
151 |
|
---|
152 | static QPixmap name2color(QString name) // taken from opt_general.cpp
|
---|
153 | {
|
---|
154 | QColor c(name);
|
---|
155 | QPixmap pix(16, 16);
|
---|
156 | QPainter p(&pix);
|
---|
157 |
|
---|
158 | p.fillRect(0, 0, pix.width(), pix.height(), QBrush(c));
|
---|
159 | p.setPen( QColor(0, 0, 0) );
|
---|
160 | p.drawRect(0, 0, pix.width(), pix.height());
|
---|
161 | p.end();
|
---|
162 |
|
---|
163 | return pix;
|
---|
164 | }
|
---|
165 |
|
---|
166 | QWidget *OptionsTabAppearanceGeneral::widget()
|
---|
167 | {
|
---|
168 | if ( w )
|
---|
169 | return 0;
|
---|
170 |
|
---|
171 | w = new OptAppearanceUI();
|
---|
172 | OptAppearanceUI *d = (OptAppearanceUI *)w;
|
---|
173 |
|
---|
174 | le_font[0] = d->le_fRoster;
|
---|
175 | le_font[1] = d->le_fMessage;
|
---|
176 | le_font[2] = d->le_fChat;
|
---|
177 | le_font[3] = d->le_fPopup;
|
---|
178 |
|
---|
179 | bg_font = new QButtonGroup;
|
---|
180 | bg_font->insert(d->pb_fRoster, 0);
|
---|
181 | bg_font->insert(d->pb_fMessage, 1);
|
---|
182 | bg_font->insert(d->pb_fChat, 2);
|
---|
183 | bg_font->insert(d->pb_fPopup, 3);
|
---|
184 | connect(bg_font, SIGNAL(clicked(int)), SLOT(chooseFont(int)));
|
---|
185 |
|
---|
186 | QWhatsThis::add(le_font[0],
|
---|
187 | tr("Specifies the font style for the main window."));
|
---|
188 | QWhatsThis::add(le_font[1],
|
---|
189 | tr("Specifies the font style for message windows."));
|
---|
190 | QWhatsThis::add(le_font[2],
|
---|
191 | tr("Specifies the font style for chat windows."));
|
---|
192 | QWhatsThis::add(le_font[3],
|
---|
193 | tr("Specifies the font style for popup windows."));
|
---|
194 | QWhatsThis::add(d->pb_fRoster,
|
---|
195 | tr("Selects a font for the a roster window using the font selection dialog."));
|
---|
196 | QWhatsThis::add(d->pb_fMessage,
|
---|
197 | tr("Selects a font for message windows using the font selection dialog."));
|
---|
198 | QWhatsThis::add(d->pb_fChat,
|
---|
199 | tr("Selects a font for chat windows using the font selection dialog."));
|
---|
200 |
|
---|
201 | bg_color = new QButtonGroup;
|
---|
202 | bg_color->insert(d->pb_cOnline, 0);
|
---|
203 | bg_color->insert(d->pb_cOffline, 1);
|
---|
204 | bg_color->insert(d->pb_cAway, 2);
|
---|
205 | bg_color->insert(d->pb_cDND, 3);
|
---|
206 | bg_color->insert(d->pb_cProfileFore, 4);
|
---|
207 | bg_color->insert(d->pb_cProfileBack, 5);
|
---|
208 | bg_color->insert(d->pb_cGroupFore, 6);
|
---|
209 | bg_color->insert(d->pb_cGroupBack, 7);
|
---|
210 | bg_color->insert(d->pb_cListBack, 8);
|
---|
211 | bg_color->insert(d->pb_cAnimFront, 9);
|
---|
212 | bg_color->insert(d->pb_cAnimBack, 10);
|
---|
213 | connect(bg_color, SIGNAL(clicked(int)), SLOT(chooseColor(int)));
|
---|
214 |
|
---|
215 | QString s = tr("Specifies the text color for a contact name in the main window when that user is \"%1\".");
|
---|
216 | QWhatsThis::add(d->pb_cOnline,
|
---|
217 | s.arg(tr("online")));
|
---|
218 | QWhatsThis::add(d->pb_cOffline,
|
---|
219 | s.arg(tr("offline")));
|
---|
220 | QWhatsThis::add(d->pb_cAway,
|
---|
221 | s.arg(tr("away")));
|
---|
222 | QWhatsThis::add(d->pb_cDND,
|
---|
223 | s.arg(tr("do not disturb")));
|
---|
224 | QWhatsThis::add(d->pb_cProfileBack,
|
---|
225 | tr("Specifies the background color for an account name in the main window."));
|
---|
226 | QWhatsThis::add(d->pb_cGroupBack,
|
---|
227 | tr("Specifies the background color for a group name in the main window."));
|
---|
228 | QWhatsThis::add(d->pb_cListBack,
|
---|
229 | tr("Specifies the background color for the main window."));
|
---|
230 | QWhatsThis::add(d->pb_cAnimFront,
|
---|
231 | tr("Specifies the foreground animation color for nicks."));
|
---|
232 | QWhatsThis::add(d->pb_cAnimBack,
|
---|
233 | tr("Specifies the background animation color for nicks."));
|
---|
234 |
|
---|
235 | // Avatars
|
---|
236 | //QWhatsThis::add(d->ck_avatarsChatdlg,
|
---|
237 | // tr("Toggles displaying of avatars in the chat dialog"));
|
---|
238 |
|
---|
239 | return w;
|
---|
240 | }
|
---|
241 |
|
---|
242 | void OptionsTabAppearanceGeneral::applyOptions(Options *opt)
|
---|
243 | {
|
---|
244 | if ( !w )
|
---|
245 | return;
|
---|
246 |
|
---|
247 | //OptAppearanceUI *d = (OptAppearanceUI *)w;
|
---|
248 | //opt->avatarsChatdlgEnabled = d->ck_avatarsChatdlg->isChecked(); // Avatars
|
---|
249 |
|
---|
250 | int n;
|
---|
251 | for (n = 0; n < 4; ++n)
|
---|
252 | opt->font[n] = le_font[n]->fontName();
|
---|
253 |
|
---|
254 | for (n = 0; n < 11; ++n)
|
---|
255 | opt->color[n] = o->color[n];
|
---|
256 | }
|
---|
257 |
|
---|
258 | void OptionsTabAppearanceGeneral::restoreOptions(const Options *opt)
|
---|
259 | {
|
---|
260 | if ( !w )
|
---|
261 | return;
|
---|
262 |
|
---|
263 | //OptAppearanceUI *d = (OptAppearanceUI *)w;
|
---|
264 | //d->ck_avatarsChatdlg->setChecked( opt->avatarsChatdlgEnabled ); // Avatars
|
---|
265 |
|
---|
266 | int n;
|
---|
267 | for (n = 0; n < 4; ++n)
|
---|
268 | le_font[n]->setFont(opt->font[n]);
|
---|
269 |
|
---|
270 | for (n = 0; n < 11; ++n) {
|
---|
271 | o->color[n] = opt->color[n];
|
---|
272 | ((QPushButton *)bg_color->find(n))->setPixmap(name2color(opt->color[n].name()));
|
---|
273 | }
|
---|
274 | }
|
---|
275 |
|
---|
276 | void OptionsTabAppearanceGeneral::setData(PsiCon *, QWidget *parentDialog)
|
---|
277 | {
|
---|
278 | parentWidget = parentDialog;
|
---|
279 | }
|
---|
280 |
|
---|
281 | void OptionsTabAppearanceGeneral::chooseFont(int x)
|
---|
282 | {
|
---|
283 | bool ok;
|
---|
284 | QFont font;
|
---|
285 | font.fromString( le_font[x]->fontName() );
|
---|
286 |
|
---|
287 | QString fnt = QFontDialog::getFont(&ok, font, parentWidget).toString();
|
---|
288 | le_font[x]->setFont(fnt);
|
---|
289 |
|
---|
290 | if(ok)
|
---|
291 | emit dataChanged();
|
---|
292 | }
|
---|
293 |
|
---|
294 | void OptionsTabAppearanceGeneral::chooseColor(int x)
|
---|
295 | {
|
---|
296 | QColor c = o->color[x];
|
---|
297 |
|
---|
298 | c = QColorDialog::getColor(c, parentWidget);
|
---|
299 | if(c.isValid()) {
|
---|
300 | o->color[x] = c;
|
---|
301 | ((QPushButton *)bg_color->find(x))->setPixmap(name2color(o->color[x].name()));
|
---|
302 |
|
---|
303 | emit dataChanged();
|
---|
304 | }
|
---|
305 | }
|
---|