source: psi/trunk/src/options/optionstab.cpp@ 16

Last change on this file since 16 was 2, checked in by dmik, 19 years ago

Imported original Psi 0.10 sources from Affinix

File size: 5.5 KB
Line 
1#include "optionstab.h"
2#include "iconset.h"
3
4#include <qtabwidget.h>
5#include <qlayout.h>
6#include <qmap.h>
7
8//----------------------------------------------------------------------------
9// OptionsTab
10//----------------------------------------------------------------------------
11
12OptionsTab::OptionsTab(QObject *parent, const char *name)
13: QObject(parent, name)
14{
15}
16
17OptionsTab::OptionsTab(QObject *parent, QCString _id, QCString _parentId, QString _name, QString _desc, QString _tabIconName, QString _iconName)
18: QObject(parent, _name.latin1())
19{
20 v_id = _id;
21 v_parentId = _parentId;
22 v_name = _name;
23 v_desc = _desc;
24 v_tabIconName = _tabIconName;
25 v_iconName = _iconName;
26}
27
28OptionsTab::~OptionsTab()
29{
30}
31
32QCString OptionsTab::id() const
33{
34 return v_id;
35}
36
37QCString OptionsTab::parentId() const
38{
39 return v_parentId;
40}
41
42QString OptionsTab::tabName() const
43{
44 return v_name;
45}
46
47Icon *OptionsTab::tabIcon() const
48{
49 if ( v_tabIconName.isEmpty() )
50 return 0;
51
52 return (Icon *)IconsetFactory::iconPtr( v_tabIconName );
53}
54
55QString OptionsTab::name() const
56{
57 return v_name;
58}
59
60QString OptionsTab::desc() const
61{
62 return v_desc;
63}
64
65Icon *OptionsTab::icon() const
66{
67 if ( v_iconName.isEmpty() ) {
68 //if ( tabIcon() )
69 // return tabIcon();
70
71 return (Icon *)IconsetFactory::iconPtr("psi/psi32");
72 }
73
74 return (Icon *)IconsetFactory::iconPtr( v_iconName );
75}
76
77void OptionsTab::applyOptions(Options *)
78{
79}
80
81void OptionsTab::restoreOptions(const Options *)
82{
83}
84
85void OptionsTab::tabAdded(OptionsTab *)
86{
87}
88
89bool OptionsTab::stretchable() const
90{
91 return false;
92}
93
94void OptionsTab::setData(PsiCon *, QWidget *)
95{
96}
97
98//----------------------------------------------------------------------------
99// OptionsTabWidget
100//----------------------------------------------------------------------------
101
102class OptionsTabWidget : public QTabWidget
103{
104 Q_OBJECT
105public:
106 OptionsTabWidget(QWidget *parent);
107 void addTab(OptionsTab *);
108 void restoreOptions(const Options *);
109
110signals:
111 void connectDataChanged(QWidget *);
112 void noDirty(bool);
113
114private slots:
115 void updateCurrent(QWidget *);
116
117private:
118 struct TabData {
119 TabData() { tab = 0; initialized = false; }
120 TabData(OptionsTab *t) { tab = t; initialized = false; }
121 OptionsTab *tab;
122 bool initialized;
123 };
124 QMap<QWidget *, TabData> w2tab;
125 Options *opt;
126};
127
128OptionsTabWidget::OptionsTabWidget(QWidget *parent)
129: QTabWidget(parent)
130{
131 connect(this, SIGNAL(currentChanged(QWidget *)), SLOT(updateCurrent(QWidget *)));
132 opt = 0;
133}
134
135void OptionsTabWidget::addTab(OptionsTab *tab)
136{
137 if ( tab->tabName().isEmpty() )
138 return; // skip the dummy tabs
139
140 QWidget *w = new QWidget(this, tab->name().latin1());
141
142 if ( tab->tabIcon() )
143 insertTab(w, tab->tabIcon()->iconSet(), tab->tabName());
144 else
145 insertTab(w, tab->tabName());
146
147 if ( !tab->desc().isEmpty() )
148 setTabToolTip(w, tab->desc());
149
150 w2tab[w] = TabData(tab);
151}
152
153void OptionsTabWidget::updateCurrent(QWidget *w)
154{
155 if ( !w2tab[w].initialized ) {
156 QVBoxLayout *vbox = new QVBoxLayout(w, 5);
157 OptionsTab *opttab = w2tab[w].tab;
158
159 QWidget *tab = opttab->widget();
160 if ( !tab )
161 return;
162
163 tab->reparent(w, 0, QPoint(0, 0));
164 vbox->addWidget(tab);
165 if ( !opttab->stretchable() )
166 vbox->addStretch();
167
168 if ( opt ) {
169 emit noDirty(true);
170 opttab->restoreOptions(opt);
171 emit noDirty(false);
172 }
173 emit connectDataChanged(tab);
174
175 tab->show();
176 w2tab[w].initialized = true;
177 }
178}
179
180void OptionsTabWidget::restoreOptions(const Options *o)
181{
182 bool doRestore = !opt;
183 opt = (Options *)o;
184
185 if ( doRestore ) {
186 emit noDirty(true);
187 w2tab[currentPage()].tab->restoreOptions(opt);
188 emit noDirty(false);
189 }
190}
191
192//----------------------------------------------------------------------------
193// MetaOptionsTab
194//----------------------------------------------------------------------------
195
196MetaOptionsTab::MetaOptionsTab(QObject *parent, const char *name)
197: OptionsTab(parent, name)
198{
199 init();
200}
201
202MetaOptionsTab::MetaOptionsTab(QObject *parent, QCString id, QCString parentId, QString name, QString desc, QString tabIconName, QString iconName)
203: OptionsTab(parent, id, parentId, name, desc, tabIconName, iconName)
204{
205 init();
206}
207
208MetaOptionsTab::~MetaOptionsTab()
209{
210 if ( w )
211 delete w;
212}
213
214void MetaOptionsTab::init()
215{
216 w = 0;
217 tabs.setAutoDelete(true);
218}
219
220void MetaOptionsTab::addTab(OptionsTab *tab)
221{
222 connect(tab, SIGNAL(dataChanged()), SIGNAL(dataChanged()));
223 //connect(tab, SIGNAL(addWidgetChangedSignal(QString, QCString)), SIGNAL(addWidgetChangedSignal(QString, QCString)));
224 connect(tab, SIGNAL(noDirty(bool)), SIGNAL(noDirty(bool)));
225 connect(tab, SIGNAL(connectDataChanged(QWidget *)), SIGNAL(connectDataChanged(QWidget *)));
226
227 tabs.append(tab);
228}
229
230QWidget *MetaOptionsTab::widget()
231{
232 if ( w )
233 return w;
234
235 OptionsTabWidget *t = new OptionsTabWidget(0);
236 w = t;
237
238 connect(w, SIGNAL(connectDataChanged(QWidget *)), SIGNAL(connectDataChanged(QWidget *)));
239 connect(w, SIGNAL(noDirty(bool)), SIGNAL(noDirty(bool)));
240
241 QPtrListIterator<OptionsTab> it(tabs);
242 for ( ; it.current(); ++it)
243 t->addTab(it.current());
244
245 return w;
246}
247
248void MetaOptionsTab::applyOptions(Options *opt)
249{
250 QPtrListIterator<OptionsTab> it(tabs);
251 for ( ; it.current(); ++it)
252 it.current()->applyOptions(opt);
253}
254
255void MetaOptionsTab::restoreOptions(const Options *opt)
256{
257 if ( w ) {
258 OptionsTabWidget *d = (OptionsTabWidget *)w;
259 d->restoreOptions(opt);
260 }
261
262 QPtrListIterator<OptionsTab> it(tabs);
263 for ( ; it.current(); ++it)
264 it.current()->restoreOptions(opt);
265}
266
267void MetaOptionsTab::setData(PsiCon *psi, QWidget *w)
268{
269 QPtrListIterator<OptionsTab> it(tabs);
270 for ( ; it.current(); ++it)
271 it.current()->setData(psi, w);
272}
273
274#include "optionstab.moc"
Note: See TracBrowser for help on using the repository browser.