| 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 |
|
|---|
| 12 | OptionsTab::OptionsTab(QObject *parent, const char *name)
|
|---|
| 13 | : QObject(parent, name)
|
|---|
| 14 | {
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | OptionsTab::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 |
|
|---|
| 28 | OptionsTab::~OptionsTab()
|
|---|
| 29 | {
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | QCString OptionsTab::id() const
|
|---|
| 33 | {
|
|---|
| 34 | return v_id;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | QCString OptionsTab::parentId() const
|
|---|
| 38 | {
|
|---|
| 39 | return v_parentId;
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | QString OptionsTab::tabName() const
|
|---|
| 43 | {
|
|---|
| 44 | return v_name;
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | Icon *OptionsTab::tabIcon() const
|
|---|
| 48 | {
|
|---|
| 49 | if ( v_tabIconName.isEmpty() )
|
|---|
| 50 | return 0;
|
|---|
| 51 |
|
|---|
| 52 | return (Icon *)IconsetFactory::iconPtr( v_tabIconName );
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | QString OptionsTab::name() const
|
|---|
| 56 | {
|
|---|
| 57 | return v_name;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | QString OptionsTab::desc() const
|
|---|
| 61 | {
|
|---|
| 62 | return v_desc;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | Icon *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 |
|
|---|
| 77 | void OptionsTab::applyOptions(Options *)
|
|---|
| 78 | {
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | void OptionsTab::restoreOptions(const Options *)
|
|---|
| 82 | {
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | void OptionsTab::tabAdded(OptionsTab *)
|
|---|
| 86 | {
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | bool OptionsTab::stretchable() const
|
|---|
| 90 | {
|
|---|
| 91 | return false;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | void OptionsTab::setData(PsiCon *, QWidget *)
|
|---|
| 95 | {
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | //----------------------------------------------------------------------------
|
|---|
| 99 | // OptionsTabWidget
|
|---|
| 100 | //----------------------------------------------------------------------------
|
|---|
| 101 |
|
|---|
| 102 | class OptionsTabWidget : public QTabWidget
|
|---|
| 103 | {
|
|---|
| 104 | Q_OBJECT
|
|---|
| 105 | public:
|
|---|
| 106 | OptionsTabWidget(QWidget *parent);
|
|---|
| 107 | void addTab(OptionsTab *);
|
|---|
| 108 | void restoreOptions(const Options *);
|
|---|
| 109 |
|
|---|
| 110 | signals:
|
|---|
| 111 | void connectDataChanged(QWidget *);
|
|---|
| 112 | void noDirty(bool);
|
|---|
| 113 |
|
|---|
| 114 | private slots:
|
|---|
| 115 | void updateCurrent(QWidget *);
|
|---|
| 116 |
|
|---|
| 117 | private:
|
|---|
| 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 |
|
|---|
| 128 | OptionsTabWidget::OptionsTabWidget(QWidget *parent)
|
|---|
| 129 | : QTabWidget(parent)
|
|---|
| 130 | {
|
|---|
| 131 | connect(this, SIGNAL(currentChanged(QWidget *)), SLOT(updateCurrent(QWidget *)));
|
|---|
| 132 | opt = 0;
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | void 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 |
|
|---|
| 153 | void 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 |
|
|---|
| 180 | void 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 |
|
|---|
| 196 | MetaOptionsTab::MetaOptionsTab(QObject *parent, const char *name)
|
|---|
| 197 | : OptionsTab(parent, name)
|
|---|
| 198 | {
|
|---|
| 199 | init();
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | MetaOptionsTab::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 |
|
|---|
| 208 | MetaOptionsTab::~MetaOptionsTab()
|
|---|
| 209 | {
|
|---|
| 210 | if ( w )
|
|---|
| 211 | delete w;
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | void MetaOptionsTab::init()
|
|---|
| 215 | {
|
|---|
| 216 | w = 0;
|
|---|
| 217 | tabs.setAutoDelete(true);
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | void 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 |
|
|---|
| 230 | QWidget *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 |
|
|---|
| 248 | void MetaOptionsTab::applyOptions(Options *opt)
|
|---|
| 249 | {
|
|---|
| 250 | QPtrListIterator<OptionsTab> it(tabs);
|
|---|
| 251 | for ( ; it.current(); ++it)
|
|---|
| 252 | it.current()->applyOptions(opt);
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | void 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 |
|
|---|
| 267 | void 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"
|
|---|