|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Designer of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qdesigner_tabwidget_p.h" |
|
43 #include "qdesigner_command_p.h" |
|
44 #include "qdesigner_propertycommand_p.h" |
|
45 #include "promotiontaskmenu_p.h" |
|
46 #include "formwindowbase_p.h" |
|
47 |
|
48 #include <QtDesigner/QDesignerFormWindowInterface> |
|
49 |
|
50 #include <QtGui/QApplication> |
|
51 #include <QtGui/QTabBar> |
|
52 #include <QtGui/QAction> |
|
53 #include <QtGui/QMouseEvent> |
|
54 #include <QtGui/QMenu> |
|
55 #include <QtGui/QLabel> |
|
56 #include <QtGui/QTabWidget> |
|
57 |
|
58 #include <QtCore/qdebug.h> |
|
59 |
|
60 QT_BEGIN_NAMESPACE |
|
61 |
|
62 namespace qdesigner_internal { |
|
63 // Store tab widget as drag source |
|
64 class MyMimeData : public QMimeData |
|
65 { |
|
66 Q_OBJECT |
|
67 public: |
|
68 MyMimeData(const QTabWidget *tab) : m_tab(tab) {} |
|
69 static bool fromMyTab(const QMimeData *mimeData, const QTabWidget *tab) { |
|
70 if (!mimeData) |
|
71 return false; |
|
72 const MyMimeData *m = qobject_cast<const MyMimeData *>(mimeData); |
|
73 return m && m->m_tab == tab; |
|
74 } |
|
75 private: |
|
76 const QTabWidget *m_tab; |
|
77 }; |
|
78 |
|
79 } // namespace qdesigner_internal |
|
80 |
|
81 // ------------- QTabWidgetEventFilter |
|
82 |
|
83 QTabWidgetEventFilter::QTabWidgetEventFilter(QTabWidget *parent) : |
|
84 QObject(parent), |
|
85 m_tabWidget(parent), |
|
86 m_dropIndicator(0), |
|
87 m_dragPage(0), |
|
88 m_mousePressed(false), |
|
89 m_actionDeletePage(new QAction(tr("Delete"), this)), |
|
90 m_actionInsertPage(new QAction(tr("Before Current Page"), this)), |
|
91 m_actionInsertPageAfter(new QAction(tr("After Current Page"), this)), |
|
92 m_pagePromotionTaskMenu(new qdesigner_internal::PromotionTaskMenu(0, qdesigner_internal::PromotionTaskMenu::ModeSingleWidget, this)) |
|
93 { |
|
94 tabBar()->setAcceptDrops(true); |
|
95 tabBar()->installEventFilter(this); |
|
96 |
|
97 connect(m_actionInsertPage, SIGNAL(triggered()), this, SLOT(addPage())); |
|
98 connect(m_actionInsertPageAfter, SIGNAL(triggered()), this, SLOT(addPageAfter())); |
|
99 connect(m_actionDeletePage, SIGNAL(triggered()), this, SLOT(removeCurrentPage())); |
|
100 } |
|
101 |
|
102 QTabWidgetEventFilter::~QTabWidgetEventFilter() |
|
103 { |
|
104 } |
|
105 |
|
106 void QTabWidgetEventFilter::install(QTabWidget *tabWidget) |
|
107 { |
|
108 new QTabWidgetEventFilter(tabWidget); |
|
109 } |
|
110 |
|
111 QTabWidgetEventFilter *QTabWidgetEventFilter::eventFilterOf(const QTabWidget *tabWidget) |
|
112 { |
|
113 // Look for 1st order children only..otherwise, we might get filters of nested tab widgets |
|
114 const QObjectList children = tabWidget->children(); |
|
115 const QObjectList::const_iterator cend = children.constEnd(); |
|
116 for (QObjectList::const_iterator it = children.constBegin(); it != cend; ++it) { |
|
117 QObject *o = *it; |
|
118 if (!o->isWidgetType()) |
|
119 if (QTabWidgetEventFilter *ef = qobject_cast<QTabWidgetEventFilter*>(o)) |
|
120 return ef; |
|
121 } |
|
122 return 0; |
|
123 } |
|
124 |
|
125 QMenu *QTabWidgetEventFilter::addTabWidgetContextMenuActions(const QTabWidget *tabWidget, QMenu *popup) |
|
126 { |
|
127 QTabWidgetEventFilter *filter = eventFilterOf(tabWidget); |
|
128 if (!filter) |
|
129 return 0; |
|
130 return filter->addContextMenuActions(popup); |
|
131 } |
|
132 |
|
133 QTabBar *QTabWidgetEventFilter::tabBar() const |
|
134 { |
|
135 // QTabWidget::tabBar() accessor is protected, grmbl... |
|
136 if (!m_cachedTabBar) { |
|
137 const QList<QTabBar *> tabBars = qFindChildren<QTabBar *>(m_tabWidget); |
|
138 Q_ASSERT(tabBars.size() == 1); |
|
139 m_cachedTabBar = tabBars.front(); |
|
140 } |
|
141 return m_cachedTabBar; |
|
142 |
|
143 } |
|
144 |
|
145 static bool canMove(const QPoint &pressPoint, const QMouseEvent *e) |
|
146 { |
|
147 const QPoint pt = pressPoint - e->pos(); |
|
148 return pt.manhattanLength() > QApplication::startDragDistance(); |
|
149 } |
|
150 |
|
151 bool QTabWidgetEventFilter::eventFilter(QObject *o, QEvent *e) |
|
152 { |
|
153 const QEvent::Type type = e->type(); |
|
154 // Do not try to locate tab bar and form window, etc. for uninteresting events and |
|
155 // avoid asserts about missing tab bars when being destroyed |
|
156 switch (type) { |
|
157 case QEvent::MouseButtonDblClick: |
|
158 case QEvent::MouseButtonPress: |
|
159 case QEvent::MouseButtonRelease: |
|
160 case QEvent::MouseMove: |
|
161 case QEvent::DragLeave: |
|
162 case QEvent::DragEnter: |
|
163 case QEvent::DragMove: |
|
164 case QEvent::Drop: |
|
165 break; |
|
166 default: |
|
167 return false; |
|
168 } |
|
169 |
|
170 if (o != tabBar()) |
|
171 return false; |
|
172 |
|
173 QDesignerFormWindowInterface *fw = formWindow(); |
|
174 if (!fw) |
|
175 return false; |
|
176 |
|
177 switch (type) { |
|
178 case QEvent::MouseButtonDblClick: |
|
179 break; |
|
180 case QEvent::MouseButtonPress: { |
|
181 QMouseEvent *mev = static_cast<QMouseEvent*>(e); |
|
182 if (QDesignerFormWindowInterface *fw = formWindow()) { |
|
183 fw->clearSelection(); |
|
184 fw->selectWidget(m_tabWidget, true); |
|
185 } |
|
186 if (mev->button() & Qt::LeftButton) { |
|
187 m_mousePressed = true; |
|
188 m_pressPoint = mev->pos(); |
|
189 |
|
190 QTabBar *tabbar = tabBar(); |
|
191 const int count = tabbar->count(); |
|
192 for (int i = 0; i < count; ++i) { |
|
193 if (tabbar->tabRect(i).contains(m_pressPoint)) { |
|
194 if (i != tabbar->currentIndex()) { |
|
195 qdesigner_internal::SetPropertyCommand *cmd = new qdesigner_internal::SetPropertyCommand(fw); |
|
196 cmd->init(m_tabWidget, QLatin1String("currentIndex"), i); |
|
197 fw->commandHistory()->push(cmd); |
|
198 } |
|
199 break; |
|
200 } |
|
201 } |
|
202 } |
|
203 } break; |
|
204 |
|
205 case QEvent::MouseButtonRelease: |
|
206 m_mousePressed = false; |
|
207 break; |
|
208 |
|
209 case QEvent::MouseMove: { |
|
210 QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(e); |
|
211 if (m_mousePressed && canMove(m_pressPoint, mouseEvent)) { |
|
212 const int index = m_tabWidget->currentIndex(); |
|
213 if (index == -1) |
|
214 break; |
|
215 |
|
216 m_mousePressed = false; |
|
217 QDrag *drg = new QDrag(m_tabWidget); |
|
218 drg->setMimeData(new qdesigner_internal::MyMimeData(m_tabWidget)); |
|
219 |
|
220 m_dragIndex = index; |
|
221 m_dragPage = m_tabWidget->currentWidget(); |
|
222 m_dragLabel = m_tabWidget->tabText(index); |
|
223 m_dragIcon = m_tabWidget->tabIcon(index); |
|
224 if (m_dragIcon.isNull()) { |
|
225 QLabel *label = new QLabel(m_dragLabel); |
|
226 label->adjustSize(); |
|
227 drg->setPixmap(QPixmap::grabWidget(label)); |
|
228 label->deleteLater(); |
|
229 } else { |
|
230 drg->setPixmap(m_dragIcon.pixmap(22, 22)); |
|
231 } |
|
232 |
|
233 m_tabWidget->removeTab(m_dragIndex); |
|
234 |
|
235 const Qt::DropActions dropAction = drg->start(Qt::MoveAction); |
|
236 |
|
237 if (dropAction == Qt::IgnoreAction) { |
|
238 // abort |
|
239 m_tabWidget->insertTab(m_dragIndex, m_dragPage, m_dragIcon, m_dragLabel); |
|
240 m_tabWidget->setCurrentIndex(m_dragIndex); |
|
241 } |
|
242 |
|
243 if (m_dropIndicator) |
|
244 m_dropIndicator->hide(); |
|
245 } |
|
246 } break; |
|
247 |
|
248 case QEvent::DragLeave: { |
|
249 if (m_dropIndicator) |
|
250 m_dropIndicator->hide(); |
|
251 } break; |
|
252 |
|
253 case QEvent::DragEnter: |
|
254 case QEvent::DragMove: { |
|
255 QDragMoveEvent *de = static_cast<QDragMoveEvent*>(e); |
|
256 if (!qdesigner_internal::MyMimeData::fromMyTab(de->mimeData(), m_tabWidget)) |
|
257 return false; |
|
258 |
|
259 if (de->proposedAction() == Qt::MoveAction) |
|
260 de->acceptProposedAction(); |
|
261 else { |
|
262 de->setDropAction(Qt::MoveAction); |
|
263 de->accept(); |
|
264 } |
|
265 |
|
266 QRect rect; |
|
267 const int index = pageFromPosition(de->pos(), rect); |
|
268 |
|
269 if (!m_dropIndicator) { |
|
270 m_dropIndicator = new QWidget(m_tabWidget); |
|
271 QPalette p = m_dropIndicator->palette(); |
|
272 p.setColor(m_tabWidget->backgroundRole(), Qt::red); |
|
273 m_dropIndicator->setPalette(p); |
|
274 } |
|
275 |
|
276 QPoint pos; |
|
277 if (index == m_tabWidget->count()) |
|
278 pos = tabBar()->mapToParent(QPoint(rect.x() + rect.width(), rect.y())); |
|
279 else |
|
280 pos = tabBar()->mapToParent(QPoint(rect.x(), rect.y())); |
|
281 |
|
282 m_dropIndicator->setGeometry(pos.x(), pos.y() , 3, rect.height()); |
|
283 m_dropIndicator->show(); |
|
284 } break; |
|
285 |
|
286 case QEvent::Drop: { |
|
287 QDropEvent *de = static_cast<QDropEvent*>(e); |
|
288 if (!qdesigner_internal::MyMimeData::fromMyTab(de->mimeData(), m_tabWidget)) |
|
289 return false; |
|
290 de->acceptProposedAction(); |
|
291 de->accept(); |
|
292 |
|
293 QRect rect; |
|
294 const int newIndex = pageFromPosition(de->pos(), rect); |
|
295 |
|
296 qdesigner_internal::MoveTabPageCommand *cmd = new qdesigner_internal::MoveTabPageCommand(fw); |
|
297 m_tabWidget->insertTab(m_dragIndex, m_dragPage, m_dragIcon, m_dragLabel); |
|
298 cmd->init(m_tabWidget, m_dragPage, m_dragIcon, m_dragLabel, m_dragIndex, newIndex); |
|
299 fw->commandHistory()->push(cmd); |
|
300 } break; |
|
301 |
|
302 default: |
|
303 break; |
|
304 } |
|
305 |
|
306 return false; |
|
307 } |
|
308 |
|
309 void QTabWidgetEventFilter::removeCurrentPage() |
|
310 { |
|
311 if (!m_tabWidget->currentWidget()) |
|
312 return; |
|
313 |
|
314 if (QDesignerFormWindowInterface *fw = formWindow()) { |
|
315 qdesigner_internal::DeleteTabPageCommand *cmd = new qdesigner_internal::DeleteTabPageCommand(fw); |
|
316 cmd->init(m_tabWidget); |
|
317 fw->commandHistory()->push(cmd); |
|
318 } |
|
319 } |
|
320 |
|
321 void QTabWidgetEventFilter::addPage() |
|
322 { |
|
323 if (QDesignerFormWindowInterface *fw = formWindow()) { |
|
324 qdesigner_internal::AddTabPageCommand *cmd = new qdesigner_internal::AddTabPageCommand(fw); |
|
325 cmd->init(m_tabWidget, qdesigner_internal::AddTabPageCommand::InsertBefore); |
|
326 fw->commandHistory()->push(cmd); |
|
327 } |
|
328 } |
|
329 |
|
330 void QTabWidgetEventFilter::addPageAfter() |
|
331 { |
|
332 if (QDesignerFormWindowInterface *fw = formWindow()) { |
|
333 qdesigner_internal::AddTabPageCommand *cmd = new qdesigner_internal::AddTabPageCommand(fw); |
|
334 cmd->init(m_tabWidget, qdesigner_internal::AddTabPageCommand::InsertAfter); |
|
335 fw->commandHistory()->push(cmd); |
|
336 } |
|
337 } |
|
338 |
|
339 QDesignerFormWindowInterface *QTabWidgetEventFilter::formWindow() const |
|
340 { |
|
341 return QDesignerFormWindowInterface::findFormWindow(const_cast<QTabWidget*>(m_tabWidget)); |
|
342 } |
|
343 |
|
344 // Get page from mouse position. Default to new page if in right half of last page? |
|
345 int QTabWidgetEventFilter::pageFromPosition(const QPoint &pos, QRect &rect) const |
|
346 { |
|
347 int index = 0; |
|
348 const QTabBar *tabbar = tabBar(); |
|
349 const int count = m_tabWidget->count(); |
|
350 for (; index < count; index++) { |
|
351 const QRect rc = tabbar->tabRect(index); |
|
352 if (rc.contains(pos)) { |
|
353 rect = rc; |
|
354 break; |
|
355 } |
|
356 } |
|
357 |
|
358 if (index == count -1) { |
|
359 QRect rect2 = rect; |
|
360 rect2.setLeft(rect2.left() + rect2.width() / 2); |
|
361 if (rect2.contains(pos)) |
|
362 index++; |
|
363 } |
|
364 return index; |
|
365 } |
|
366 |
|
367 QMenu *QTabWidgetEventFilter::addContextMenuActions(QMenu *popup) |
|
368 { |
|
369 QMenu *pageMenu = 0; |
|
370 const int count = m_tabWidget->count(); |
|
371 m_actionDeletePage->setEnabled(count); |
|
372 if (count) { |
|
373 const int currentIndex = m_tabWidget->currentIndex(); |
|
374 const QString pageSubMenuLabel = tr("Page %1 of %2").arg(currentIndex + 1).arg(count); |
|
375 pageMenu = popup->addMenu(pageSubMenuLabel); |
|
376 pageMenu->addAction(m_actionDeletePage); |
|
377 // Set up promotion menu for current widget. |
|
378 if (QWidget *page = m_tabWidget->currentWidget ()) { |
|
379 m_pagePromotionTaskMenu->setWidget(page); |
|
380 m_pagePromotionTaskMenu->addActions(QDesignerFormWindowInterface::findFormWindow(m_tabWidget), |
|
381 qdesigner_internal::PromotionTaskMenu::SuppressGlobalEdit, |
|
382 pageMenu); |
|
383 } |
|
384 QMenu *insertPageMenu = popup->addMenu(tr("Insert Page")); |
|
385 insertPageMenu->addAction(m_actionInsertPageAfter); |
|
386 insertPageMenu->addAction(m_actionInsertPage); |
|
387 } else { |
|
388 QAction *insertPageAction = popup->addAction(tr("Insert Page")); |
|
389 connect(insertPageAction, SIGNAL(triggered()), this, SLOT(addPage())); |
|
390 } |
|
391 popup->addSeparator(); |
|
392 return pageMenu; |
|
393 } |
|
394 |
|
395 // ----------- QTabWidgetPropertySheet |
|
396 |
|
397 static const char *currentTabTextKey = "currentTabText"; |
|
398 static const char *currentTabNameKey = "currentTabName"; |
|
399 static const char *currentTabIconKey = "currentTabIcon"; |
|
400 static const char *currentTabToolTipKey = "currentTabToolTip"; |
|
401 static const char *currentTabWhatsThisKey = "currentTabWhatsThis"; |
|
402 |
|
403 QTabWidgetPropertySheet::QTabWidgetPropertySheet(QTabWidget *object, QObject *parent) : |
|
404 QDesignerPropertySheet(object, parent), |
|
405 m_tabWidget(object) |
|
406 { |
|
407 createFakeProperty(QLatin1String(currentTabTextKey), qVariantFromValue(qdesigner_internal::PropertySheetStringValue())); |
|
408 createFakeProperty(QLatin1String(currentTabNameKey), QString()); |
|
409 createFakeProperty(QLatin1String(currentTabIconKey), qVariantFromValue(qdesigner_internal::PropertySheetIconValue())); |
|
410 if (formWindowBase()) |
|
411 formWindowBase()->addReloadableProperty(this, indexOf(QLatin1String(currentTabIconKey))); |
|
412 createFakeProperty(QLatin1String(currentTabToolTipKey), qVariantFromValue(qdesigner_internal::PropertySheetStringValue())); |
|
413 createFakeProperty(QLatin1String(currentTabWhatsThisKey), qVariantFromValue(qdesigner_internal::PropertySheetStringValue())); |
|
414 } |
|
415 |
|
416 QTabWidgetPropertySheet::TabWidgetProperty QTabWidgetPropertySheet::tabWidgetPropertyFromName(const QString &name) |
|
417 { |
|
418 typedef QHash<QString, TabWidgetProperty> TabWidgetPropertyHash; |
|
419 static TabWidgetPropertyHash tabWidgetPropertyHash; |
|
420 if (tabWidgetPropertyHash.empty()) { |
|
421 tabWidgetPropertyHash.insert(QLatin1String(currentTabTextKey), PropertyCurrentTabText); |
|
422 tabWidgetPropertyHash.insert(QLatin1String(currentTabNameKey), PropertyCurrentTabName); |
|
423 tabWidgetPropertyHash.insert(QLatin1String(currentTabIconKey), PropertyCurrentTabIcon); |
|
424 tabWidgetPropertyHash.insert(QLatin1String(currentTabToolTipKey), PropertyCurrentTabToolTip); |
|
425 tabWidgetPropertyHash.insert(QLatin1String(currentTabWhatsThisKey), PropertyCurrentTabWhatsThis); |
|
426 } |
|
427 return tabWidgetPropertyHash.value(name, PropertyTabWidgetNone); |
|
428 } |
|
429 |
|
430 void QTabWidgetPropertySheet::setProperty(int index, const QVariant &value) |
|
431 { |
|
432 const TabWidgetProperty tabWidgetProperty = tabWidgetPropertyFromName(propertyName(index)); |
|
433 if (tabWidgetProperty == PropertyTabWidgetNone) { |
|
434 QDesignerPropertySheet::setProperty(index, value); |
|
435 return; |
|
436 } |
|
437 |
|
438 // index-dependent |
|
439 const int currentIndex = m_tabWidget->currentIndex(); |
|
440 QWidget *currentWidget = m_tabWidget->currentWidget(); |
|
441 if (!currentWidget) |
|
442 return; |
|
443 |
|
444 switch (tabWidgetProperty) { |
|
445 case PropertyCurrentTabText: |
|
446 m_tabWidget->setTabText(currentIndex, qvariant_cast<QString>(resolvePropertyValue(index, value))); |
|
447 m_pageToData[currentWidget].text = qVariantValue<qdesigner_internal::PropertySheetStringValue>(value); |
|
448 break; |
|
449 case PropertyCurrentTabName: |
|
450 currentWidget->setObjectName(value.toString()); |
|
451 break; |
|
452 case PropertyCurrentTabIcon: |
|
453 m_tabWidget->setTabIcon(currentIndex, qvariant_cast<QIcon>(resolvePropertyValue(index, value))); |
|
454 m_pageToData[currentWidget].icon = qVariantValue<qdesigner_internal::PropertySheetIconValue>(value); |
|
455 break; |
|
456 case PropertyCurrentTabToolTip: |
|
457 m_tabWidget->setTabToolTip(currentIndex, qvariant_cast<QString>(resolvePropertyValue(index, value))); |
|
458 m_pageToData[currentWidget].tooltip = qVariantValue<qdesigner_internal::PropertySheetStringValue>(value); |
|
459 break; |
|
460 case PropertyCurrentTabWhatsThis: |
|
461 m_tabWidget->setTabWhatsThis(currentIndex, qvariant_cast<QString>(resolvePropertyValue(index, value))); |
|
462 m_pageToData[currentWidget].whatsthis = qVariantValue<qdesigner_internal::PropertySheetStringValue>(value); |
|
463 break; |
|
464 case PropertyTabWidgetNone: |
|
465 break; |
|
466 } |
|
467 } |
|
468 |
|
469 bool QTabWidgetPropertySheet::isEnabled(int index) const |
|
470 { |
|
471 if (tabWidgetPropertyFromName(propertyName(index)) == PropertyTabWidgetNone) |
|
472 return QDesignerPropertySheet::isEnabled(index); |
|
473 return m_tabWidget->currentIndex() != -1; |
|
474 } |
|
475 |
|
476 QVariant QTabWidgetPropertySheet::property(int index) const |
|
477 { |
|
478 const TabWidgetProperty tabWidgetProperty = tabWidgetPropertyFromName(propertyName(index)); |
|
479 if (tabWidgetProperty == PropertyTabWidgetNone) |
|
480 return QDesignerPropertySheet::property(index); |
|
481 |
|
482 // index-dependent |
|
483 QWidget *currentWidget = m_tabWidget->currentWidget(); |
|
484 if (!currentWidget) { |
|
485 if (tabWidgetProperty == PropertyCurrentTabIcon) |
|
486 return qVariantFromValue(qdesigner_internal::PropertySheetIconValue()); |
|
487 if (tabWidgetProperty == PropertyCurrentTabText) |
|
488 return qVariantFromValue(qdesigner_internal::PropertySheetStringValue()); |
|
489 if (tabWidgetProperty == PropertyCurrentTabToolTip) |
|
490 return qVariantFromValue(qdesigner_internal::PropertySheetStringValue()); |
|
491 if (tabWidgetProperty == PropertyCurrentTabWhatsThis) |
|
492 return qVariantFromValue(qdesigner_internal::PropertySheetStringValue()); |
|
493 return QVariant(QString()); |
|
494 } |
|
495 |
|
496 // index-dependent |
|
497 switch (tabWidgetProperty) { |
|
498 case PropertyCurrentTabText: |
|
499 return qVariantFromValue(m_pageToData.value(currentWidget).text); |
|
500 case PropertyCurrentTabName: |
|
501 return currentWidget->objectName(); |
|
502 case PropertyCurrentTabIcon: |
|
503 return qVariantFromValue(m_pageToData.value(currentWidget).icon); |
|
504 case PropertyCurrentTabToolTip: |
|
505 return qVariantFromValue(m_pageToData.value(currentWidget).tooltip); |
|
506 case PropertyCurrentTabWhatsThis: |
|
507 return qVariantFromValue(m_pageToData.value(currentWidget).whatsthis); |
|
508 case PropertyTabWidgetNone: |
|
509 break; |
|
510 } |
|
511 return QVariant(); |
|
512 } |
|
513 |
|
514 bool QTabWidgetPropertySheet::reset(int index) |
|
515 { |
|
516 const TabWidgetProperty tabWidgetProperty = tabWidgetPropertyFromName(propertyName(index)); |
|
517 if (tabWidgetProperty == PropertyTabWidgetNone) |
|
518 return QDesignerPropertySheet::reset(index); |
|
519 |
|
520 // index-dependent |
|
521 QWidget *currentWidget = m_tabWidget->currentWidget(); |
|
522 if (!currentWidget) |
|
523 return false; |
|
524 |
|
525 // index-dependent |
|
526 switch (tabWidgetProperty) { |
|
527 case PropertyCurrentTabName: |
|
528 setProperty(index, QString()); |
|
529 break; |
|
530 case PropertyCurrentTabToolTip: |
|
531 m_pageToData[currentWidget].tooltip = qdesigner_internal::PropertySheetStringValue(); |
|
532 setProperty(index, QString()); |
|
533 break; |
|
534 case PropertyCurrentTabWhatsThis: |
|
535 m_pageToData[currentWidget].whatsthis = qdesigner_internal::PropertySheetStringValue(); |
|
536 setProperty(index, QString()); |
|
537 break; |
|
538 case PropertyCurrentTabText: |
|
539 m_pageToData[currentWidget].text = qdesigner_internal::PropertySheetStringValue(); |
|
540 setProperty(index, QString()); |
|
541 break; |
|
542 case PropertyCurrentTabIcon: |
|
543 m_pageToData[currentWidget].icon = qdesigner_internal::PropertySheetIconValue(); |
|
544 setProperty(index, QIcon()); |
|
545 break; |
|
546 case PropertyTabWidgetNone: |
|
547 break; |
|
548 } |
|
549 return true; |
|
550 } |
|
551 |
|
552 bool QTabWidgetPropertySheet::checkProperty(const QString &propertyName) |
|
553 { |
|
554 switch (tabWidgetPropertyFromName(propertyName)) { |
|
555 case PropertyCurrentTabText: |
|
556 case PropertyCurrentTabName: |
|
557 case PropertyCurrentTabToolTip: |
|
558 case PropertyCurrentTabWhatsThis: |
|
559 case PropertyCurrentTabIcon: |
|
560 return false; |
|
561 default: |
|
562 break; |
|
563 } |
|
564 return true; |
|
565 } |
|
566 |
|
567 QT_END_NAMESPACE |
|
568 |
|
569 #include "qdesigner_tabwidget.moc" // required for MyMimeData |