author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 3 | 41300fa6a67c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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"; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
402 |
static const char *tabMovableKey = "movable"; |
0 | 403 |
|
404 |
QTabWidgetPropertySheet::QTabWidgetPropertySheet(QTabWidget *object, QObject *parent) : |
|
405 |
QDesignerPropertySheet(object, parent), |
|
406 |
m_tabWidget(object) |
|
407 |
{ |
|
408 |
createFakeProperty(QLatin1String(currentTabTextKey), qVariantFromValue(qdesigner_internal::PropertySheetStringValue())); |
|
409 |
createFakeProperty(QLatin1String(currentTabNameKey), QString()); |
|
410 |
createFakeProperty(QLatin1String(currentTabIconKey), qVariantFromValue(qdesigner_internal::PropertySheetIconValue())); |
|
411 |
if (formWindowBase()) |
|
412 |
formWindowBase()->addReloadableProperty(this, indexOf(QLatin1String(currentTabIconKey))); |
|
413 |
createFakeProperty(QLatin1String(currentTabToolTipKey), qVariantFromValue(qdesigner_internal::PropertySheetStringValue())); |
|
414 |
createFakeProperty(QLatin1String(currentTabWhatsThisKey), qVariantFromValue(qdesigner_internal::PropertySheetStringValue())); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
415 |
// Prevent the tab widget's drag and drop handling from interfering with Designer's |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
416 |
createFakeProperty(QLatin1String(tabMovableKey), QVariant(false)); |
0 | 417 |
} |
418 |
||
419 |
QTabWidgetPropertySheet::TabWidgetProperty QTabWidgetPropertySheet::tabWidgetPropertyFromName(const QString &name) |
|
420 |
{ |
|
421 |
typedef QHash<QString, TabWidgetProperty> TabWidgetPropertyHash; |
|
422 |
static TabWidgetPropertyHash tabWidgetPropertyHash; |
|
423 |
if (tabWidgetPropertyHash.empty()) { |
|
424 |
tabWidgetPropertyHash.insert(QLatin1String(currentTabTextKey), PropertyCurrentTabText); |
|
425 |
tabWidgetPropertyHash.insert(QLatin1String(currentTabNameKey), PropertyCurrentTabName); |
|
426 |
tabWidgetPropertyHash.insert(QLatin1String(currentTabIconKey), PropertyCurrentTabIcon); |
|
427 |
tabWidgetPropertyHash.insert(QLatin1String(currentTabToolTipKey), PropertyCurrentTabToolTip); |
|
428 |
tabWidgetPropertyHash.insert(QLatin1String(currentTabWhatsThisKey), PropertyCurrentTabWhatsThis); |
|
429 |
} |
|
430 |
return tabWidgetPropertyHash.value(name, PropertyTabWidgetNone); |
|
431 |
} |
|
432 |
||
433 |
void QTabWidgetPropertySheet::setProperty(int index, const QVariant &value) |
|
434 |
{ |
|
435 |
const TabWidgetProperty tabWidgetProperty = tabWidgetPropertyFromName(propertyName(index)); |
|
436 |
if (tabWidgetProperty == PropertyTabWidgetNone) { |
|
437 |
QDesignerPropertySheet::setProperty(index, value); |
|
438 |
return; |
|
439 |
} |
|
440 |
||
441 |
// index-dependent |
|
442 |
const int currentIndex = m_tabWidget->currentIndex(); |
|
443 |
QWidget *currentWidget = m_tabWidget->currentWidget(); |
|
444 |
if (!currentWidget) |
|
445 |
return; |
|
446 |
||
447 |
switch (tabWidgetProperty) { |
|
448 |
case PropertyCurrentTabText: |
|
449 |
m_tabWidget->setTabText(currentIndex, qvariant_cast<QString>(resolvePropertyValue(index, value))); |
|
450 |
m_pageToData[currentWidget].text = qVariantValue<qdesigner_internal::PropertySheetStringValue>(value); |
|
451 |
break; |
|
452 |
case PropertyCurrentTabName: |
|
453 |
currentWidget->setObjectName(value.toString()); |
|
454 |
break; |
|
455 |
case PropertyCurrentTabIcon: |
|
456 |
m_tabWidget->setTabIcon(currentIndex, qvariant_cast<QIcon>(resolvePropertyValue(index, value))); |
|
457 |
m_pageToData[currentWidget].icon = qVariantValue<qdesigner_internal::PropertySheetIconValue>(value); |
|
458 |
break; |
|
459 |
case PropertyCurrentTabToolTip: |
|
460 |
m_tabWidget->setTabToolTip(currentIndex, qvariant_cast<QString>(resolvePropertyValue(index, value))); |
|
461 |
m_pageToData[currentWidget].tooltip = qVariantValue<qdesigner_internal::PropertySheetStringValue>(value); |
|
462 |
break; |
|
463 |
case PropertyCurrentTabWhatsThis: |
|
464 |
m_tabWidget->setTabWhatsThis(currentIndex, qvariant_cast<QString>(resolvePropertyValue(index, value))); |
|
465 |
m_pageToData[currentWidget].whatsthis = qVariantValue<qdesigner_internal::PropertySheetStringValue>(value); |
|
466 |
break; |
|
467 |
case PropertyTabWidgetNone: |
|
468 |
break; |
|
469 |
} |
|
470 |
} |
|
471 |
||
472 |
bool QTabWidgetPropertySheet::isEnabled(int index) const |
|
473 |
{ |
|
474 |
if (tabWidgetPropertyFromName(propertyName(index)) == PropertyTabWidgetNone) |
|
475 |
return QDesignerPropertySheet::isEnabled(index); |
|
476 |
return m_tabWidget->currentIndex() != -1; |
|
477 |
} |
|
478 |
||
479 |
QVariant QTabWidgetPropertySheet::property(int index) const |
|
480 |
{ |
|
481 |
const TabWidgetProperty tabWidgetProperty = tabWidgetPropertyFromName(propertyName(index)); |
|
482 |
if (tabWidgetProperty == PropertyTabWidgetNone) |
|
483 |
return QDesignerPropertySheet::property(index); |
|
484 |
||
485 |
// index-dependent |
|
486 |
QWidget *currentWidget = m_tabWidget->currentWidget(); |
|
487 |
if (!currentWidget) { |
|
488 |
if (tabWidgetProperty == PropertyCurrentTabIcon) |
|
489 |
return qVariantFromValue(qdesigner_internal::PropertySheetIconValue()); |
|
490 |
if (tabWidgetProperty == PropertyCurrentTabText) |
|
491 |
return qVariantFromValue(qdesigner_internal::PropertySheetStringValue()); |
|
492 |
if (tabWidgetProperty == PropertyCurrentTabToolTip) |
|
493 |
return qVariantFromValue(qdesigner_internal::PropertySheetStringValue()); |
|
494 |
if (tabWidgetProperty == PropertyCurrentTabWhatsThis) |
|
495 |
return qVariantFromValue(qdesigner_internal::PropertySheetStringValue()); |
|
496 |
return QVariant(QString()); |
|
497 |
} |
|
498 |
||
499 |
// index-dependent |
|
500 |
switch (tabWidgetProperty) { |
|
501 |
case PropertyCurrentTabText: |
|
502 |
return qVariantFromValue(m_pageToData.value(currentWidget).text); |
|
503 |
case PropertyCurrentTabName: |
|
504 |
return currentWidget->objectName(); |
|
505 |
case PropertyCurrentTabIcon: |
|
506 |
return qVariantFromValue(m_pageToData.value(currentWidget).icon); |
|
507 |
case PropertyCurrentTabToolTip: |
|
508 |
return qVariantFromValue(m_pageToData.value(currentWidget).tooltip); |
|
509 |
case PropertyCurrentTabWhatsThis: |
|
510 |
return qVariantFromValue(m_pageToData.value(currentWidget).whatsthis); |
|
511 |
case PropertyTabWidgetNone: |
|
512 |
break; |
|
513 |
} |
|
514 |
return QVariant(); |
|
515 |
} |
|
516 |
||
517 |
bool QTabWidgetPropertySheet::reset(int index) |
|
518 |
{ |
|
519 |
const TabWidgetProperty tabWidgetProperty = tabWidgetPropertyFromName(propertyName(index)); |
|
520 |
if (tabWidgetProperty == PropertyTabWidgetNone) |
|
521 |
return QDesignerPropertySheet::reset(index); |
|
522 |
||
523 |
// index-dependent |
|
524 |
QWidget *currentWidget = m_tabWidget->currentWidget(); |
|
525 |
if (!currentWidget) |
|
526 |
return false; |
|
527 |
||
528 |
// index-dependent |
|
529 |
switch (tabWidgetProperty) { |
|
530 |
case PropertyCurrentTabName: |
|
531 |
setProperty(index, QString()); |
|
532 |
break; |
|
533 |
case PropertyCurrentTabToolTip: |
|
534 |
m_pageToData[currentWidget].tooltip = qdesigner_internal::PropertySheetStringValue(); |
|
535 |
setProperty(index, QString()); |
|
536 |
break; |
|
537 |
case PropertyCurrentTabWhatsThis: |
|
538 |
m_pageToData[currentWidget].whatsthis = qdesigner_internal::PropertySheetStringValue(); |
|
539 |
setProperty(index, QString()); |
|
540 |
break; |
|
541 |
case PropertyCurrentTabText: |
|
542 |
m_pageToData[currentWidget].text = qdesigner_internal::PropertySheetStringValue(); |
|
543 |
setProperty(index, QString()); |
|
544 |
break; |
|
545 |
case PropertyCurrentTabIcon: |
|
546 |
m_pageToData[currentWidget].icon = qdesigner_internal::PropertySheetIconValue(); |
|
547 |
setProperty(index, QIcon()); |
|
548 |
break; |
|
549 |
case PropertyTabWidgetNone: |
|
550 |
break; |
|
551 |
} |
|
552 |
return true; |
|
553 |
} |
|
554 |
||
555 |
bool QTabWidgetPropertySheet::checkProperty(const QString &propertyName) |
|
556 |
{ |
|
557 |
switch (tabWidgetPropertyFromName(propertyName)) { |
|
558 |
case PropertyCurrentTabText: |
|
559 |
case PropertyCurrentTabName: |
|
560 |
case PropertyCurrentTabToolTip: |
|
561 |
case PropertyCurrentTabWhatsThis: |
|
562 |
case PropertyCurrentTabIcon: |
|
563 |
return false; |
|
564 |
default: |
|
565 |
break; |
|
566 |
} |
|
567 |
return true; |
|
568 |
} |
|
569 |
||
570 |
QT_END_NAMESPACE |
|
571 |
||
572 |
#include "qdesigner_tabwidget.moc" // required for MyMimeData |