| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the Qt Designer of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 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 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 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 | #ifndef QT_NO_DRAGANDDROP
|
|---|
| 218 | QDrag *drg = new QDrag(m_tabWidget);
|
|---|
| 219 | drg->setMimeData(new qdesigner_internal::MyMimeData(m_tabWidget));
|
|---|
| 220 | #endif
|
|---|
| 221 |
|
|---|
| 222 | m_dragIndex = index;
|
|---|
| 223 | m_dragPage = m_tabWidget->currentWidget();
|
|---|
| 224 | m_dragLabel = m_tabWidget->tabText(index);
|
|---|
| 225 | m_dragIcon = m_tabWidget->tabIcon(index);
|
|---|
| 226 | if (m_dragIcon.isNull()) {
|
|---|
| 227 | QLabel *label = new QLabel(m_dragLabel);
|
|---|
| 228 | label->adjustSize();
|
|---|
| 229 | #ifndef QT_NO_DRAGANDDROP
|
|---|
| 230 | drg->setPixmap(QPixmap::grabWidget(label));
|
|---|
| 231 | #endif
|
|---|
| 232 | label->deleteLater();
|
|---|
| 233 | } else {
|
|---|
| 234 | #ifndef QT_NO_DRAGANDDROP
|
|---|
| 235 | drg->setPixmap(m_dragIcon.pixmap(22, 22));
|
|---|
| 236 | #endif
|
|---|
| 237 | }
|
|---|
| 238 |
|
|---|
| 239 | m_tabWidget->removeTab(m_dragIndex);
|
|---|
| 240 |
|
|---|
| 241 | #ifndef QT_NO_DRAGANDDROP
|
|---|
| 242 | const Qt::DropActions dropAction = drg->start(Qt::MoveAction);
|
|---|
| 243 | #else
|
|---|
| 244 | const Qt::DropActions dropAction = Qt::IgnoreAction;
|
|---|
| 245 | #endif
|
|---|
| 246 |
|
|---|
| 247 | if (dropAction == Qt::IgnoreAction) {
|
|---|
| 248 | // abort
|
|---|
| 249 | m_tabWidget->insertTab(m_dragIndex, m_dragPage, m_dragIcon, m_dragLabel);
|
|---|
| 250 | m_tabWidget->setCurrentIndex(m_dragIndex);
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | if (m_dropIndicator)
|
|---|
| 254 | m_dropIndicator->hide();
|
|---|
| 255 | }
|
|---|
| 256 | } break;
|
|---|
| 257 |
|
|---|
| 258 | case QEvent::DragLeave: {
|
|---|
| 259 | if (m_dropIndicator)
|
|---|
| 260 | m_dropIndicator->hide();
|
|---|
| 261 | } break;
|
|---|
| 262 |
|
|---|
| 263 | case QEvent::DragEnter:
|
|---|
| 264 | case QEvent::DragMove: {
|
|---|
| 265 | #ifndef QT_NO_DRAGANDDROP
|
|---|
| 266 | QDragMoveEvent *de = static_cast<QDragMoveEvent*>(e);
|
|---|
| 267 | if (!qdesigner_internal::MyMimeData::fromMyTab(de->mimeData(), m_tabWidget))
|
|---|
| 268 | return false;
|
|---|
| 269 |
|
|---|
| 270 | if (de->proposedAction() == Qt::MoveAction)
|
|---|
| 271 | de->acceptProposedAction();
|
|---|
| 272 | else {
|
|---|
| 273 | de->setDropAction(Qt::MoveAction);
|
|---|
| 274 | de->accept();
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | QRect rect;
|
|---|
| 278 | const int index = pageFromPosition(de->pos(), rect);
|
|---|
| 279 |
|
|---|
| 280 | if (!m_dropIndicator) {
|
|---|
| 281 | m_dropIndicator = new QWidget(m_tabWidget);
|
|---|
| 282 | QPalette p = m_dropIndicator->palette();
|
|---|
| 283 | p.setColor(m_tabWidget->backgroundRole(), Qt::red);
|
|---|
| 284 | m_dropIndicator->setPalette(p);
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 | QPoint pos;
|
|---|
| 288 | if (index == m_tabWidget->count())
|
|---|
| 289 | pos = tabBar()->mapToParent(QPoint(rect.x() + rect.width(), rect.y()));
|
|---|
| 290 | else
|
|---|
| 291 | pos = tabBar()->mapToParent(QPoint(rect.x(), rect.y()));
|
|---|
| 292 |
|
|---|
| 293 | m_dropIndicator->setGeometry(pos.x(), pos.y() , 3, rect.height());
|
|---|
| 294 | m_dropIndicator->show();
|
|---|
| 295 | #else
|
|---|
| 296 | return false;
|
|---|
| 297 | #endif
|
|---|
| 298 |
|
|---|
| 299 | } break;
|
|---|
| 300 |
|
|---|
| 301 | case QEvent::Drop: {
|
|---|
| 302 | #ifndef QT_NO_DRAGANDDROP
|
|---|
| 303 | QDropEvent *de = static_cast<QDropEvent*>(e);
|
|---|
| 304 | if (!qdesigner_internal::MyMimeData::fromMyTab(de->mimeData(), m_tabWidget))
|
|---|
| 305 | return false;
|
|---|
| 306 | de->acceptProposedAction();
|
|---|
| 307 | de->accept();
|
|---|
| 308 |
|
|---|
| 309 | QRect rect;
|
|---|
| 310 | const int newIndex = pageFromPosition(de->pos(), rect);
|
|---|
| 311 |
|
|---|
| 312 | qdesigner_internal::MoveTabPageCommand *cmd = new qdesigner_internal::MoveTabPageCommand(fw);
|
|---|
| 313 | m_tabWidget->insertTab(m_dragIndex, m_dragPage, m_dragIcon, m_dragLabel);
|
|---|
| 314 | cmd->init(m_tabWidget, m_dragPage, m_dragIcon, m_dragLabel, m_dragIndex, newIndex);
|
|---|
| 315 | fw->commandHistory()->push(cmd);
|
|---|
| 316 | #else
|
|---|
| 317 | return false;
|
|---|
| 318 | #endif
|
|---|
| 319 | } break;
|
|---|
| 320 |
|
|---|
| 321 | default:
|
|---|
| 322 | break;
|
|---|
| 323 | }
|
|---|
| 324 |
|
|---|
| 325 | return false;
|
|---|
| 326 | }
|
|---|
| 327 |
|
|---|
| 328 | void QTabWidgetEventFilter::removeCurrentPage()
|
|---|
| 329 | {
|
|---|
| 330 | if (!m_tabWidget->currentWidget())
|
|---|
| 331 | return;
|
|---|
| 332 |
|
|---|
| 333 | if (QDesignerFormWindowInterface *fw = formWindow()) {
|
|---|
| 334 | qdesigner_internal::DeleteTabPageCommand *cmd = new qdesigner_internal::DeleteTabPageCommand(fw);
|
|---|
| 335 | cmd->init(m_tabWidget);
|
|---|
| 336 | fw->commandHistory()->push(cmd);
|
|---|
| 337 | }
|
|---|
| 338 | }
|
|---|
| 339 |
|
|---|
| 340 | void QTabWidgetEventFilter::addPage()
|
|---|
| 341 | {
|
|---|
| 342 | if (QDesignerFormWindowInterface *fw = formWindow()) {
|
|---|
| 343 | qdesigner_internal::AddTabPageCommand *cmd = new qdesigner_internal::AddTabPageCommand(fw);
|
|---|
| 344 | cmd->init(m_tabWidget, qdesigner_internal::AddTabPageCommand::InsertBefore);
|
|---|
| 345 | fw->commandHistory()->push(cmd);
|
|---|
| 346 | }
|
|---|
| 347 | }
|
|---|
| 348 |
|
|---|
| 349 | void QTabWidgetEventFilter::addPageAfter()
|
|---|
| 350 | {
|
|---|
| 351 | if (QDesignerFormWindowInterface *fw = formWindow()) {
|
|---|
| 352 | qdesigner_internal::AddTabPageCommand *cmd = new qdesigner_internal::AddTabPageCommand(fw);
|
|---|
| 353 | cmd->init(m_tabWidget, qdesigner_internal::AddTabPageCommand::InsertAfter);
|
|---|
| 354 | fw->commandHistory()->push(cmd);
|
|---|
| 355 | }
|
|---|
| 356 | }
|
|---|
| 357 |
|
|---|
| 358 | QDesignerFormWindowInterface *QTabWidgetEventFilter::formWindow() const
|
|---|
| 359 | {
|
|---|
| 360 | return QDesignerFormWindowInterface::findFormWindow(const_cast<QTabWidget*>(m_tabWidget));
|
|---|
| 361 | }
|
|---|
| 362 |
|
|---|
| 363 | // Get page from mouse position. Default to new page if in right half of last page?
|
|---|
| 364 | int QTabWidgetEventFilter::pageFromPosition(const QPoint &pos, QRect &rect) const
|
|---|
| 365 | {
|
|---|
| 366 | int index = 0;
|
|---|
| 367 | const QTabBar *tabbar = tabBar();
|
|---|
| 368 | const int count = m_tabWidget->count();
|
|---|
| 369 | for (; index < count; index++) {
|
|---|
| 370 | const QRect rc = tabbar->tabRect(index);
|
|---|
| 371 | if (rc.contains(pos)) {
|
|---|
| 372 | rect = rc;
|
|---|
| 373 | break;
|
|---|
| 374 | }
|
|---|
| 375 | }
|
|---|
| 376 |
|
|---|
| 377 | if (index == count -1) {
|
|---|
| 378 | QRect rect2 = rect;
|
|---|
| 379 | rect2.setLeft(rect2.left() + rect2.width() / 2);
|
|---|
| 380 | if (rect2.contains(pos))
|
|---|
| 381 | index++;
|
|---|
| 382 | }
|
|---|
| 383 | return index;
|
|---|
| 384 | }
|
|---|
| 385 |
|
|---|
| 386 | QMenu *QTabWidgetEventFilter::addContextMenuActions(QMenu *popup)
|
|---|
| 387 | {
|
|---|
| 388 | QMenu *pageMenu = 0;
|
|---|
| 389 | const int count = m_tabWidget->count();
|
|---|
| 390 | m_actionDeletePage->setEnabled(count);
|
|---|
| 391 | if (count) {
|
|---|
| 392 | const int currentIndex = m_tabWidget->currentIndex();
|
|---|
| 393 | const QString pageSubMenuLabel = tr("Page %1 of %2").arg(currentIndex + 1).arg(count);
|
|---|
| 394 | pageMenu = popup->addMenu(pageSubMenuLabel);
|
|---|
| 395 | pageMenu->addAction(m_actionDeletePage);
|
|---|
| 396 | // Set up promotion menu for current widget.
|
|---|
| 397 | if (QWidget *page = m_tabWidget->currentWidget ()) {
|
|---|
| 398 | m_pagePromotionTaskMenu->setWidget(page);
|
|---|
| 399 | m_pagePromotionTaskMenu->addActions(QDesignerFormWindowInterface::findFormWindow(m_tabWidget),
|
|---|
| 400 | qdesigner_internal::PromotionTaskMenu::SuppressGlobalEdit,
|
|---|
| 401 | pageMenu);
|
|---|
| 402 | }
|
|---|
| 403 | QMenu *insertPageMenu = popup->addMenu(tr("Insert Page"));
|
|---|
| 404 | insertPageMenu->addAction(m_actionInsertPageAfter);
|
|---|
| 405 | insertPageMenu->addAction(m_actionInsertPage);
|
|---|
| 406 | } else {
|
|---|
| 407 | QAction *insertPageAction = popup->addAction(tr("Insert Page"));
|
|---|
| 408 | connect(insertPageAction, SIGNAL(triggered()), this, SLOT(addPage()));
|
|---|
| 409 | }
|
|---|
| 410 | popup->addSeparator();
|
|---|
| 411 | return pageMenu;
|
|---|
| 412 | }
|
|---|
| 413 |
|
|---|
| 414 | // ----------- QTabWidgetPropertySheet
|
|---|
| 415 |
|
|---|
| 416 | static const char *currentTabTextKey = "currentTabText";
|
|---|
| 417 | static const char *currentTabNameKey = "currentTabName";
|
|---|
| 418 | static const char *currentTabIconKey = "currentTabIcon";
|
|---|
| 419 | static const char *currentTabToolTipKey = "currentTabToolTip";
|
|---|
| 420 | static const char *currentTabWhatsThisKey = "currentTabWhatsThis";
|
|---|
| 421 | static const char *tabMovableKey = "movable";
|
|---|
| 422 |
|
|---|
| 423 | QTabWidgetPropertySheet::QTabWidgetPropertySheet(QTabWidget *object, QObject *parent) :
|
|---|
| 424 | QDesignerPropertySheet(object, parent),
|
|---|
| 425 | m_tabWidget(object)
|
|---|
| 426 | {
|
|---|
| 427 | createFakeProperty(QLatin1String(currentTabTextKey), qVariantFromValue(qdesigner_internal::PropertySheetStringValue()));
|
|---|
| 428 | createFakeProperty(QLatin1String(currentTabNameKey), QString());
|
|---|
| 429 | createFakeProperty(QLatin1String(currentTabIconKey), qVariantFromValue(qdesigner_internal::PropertySheetIconValue()));
|
|---|
| 430 | if (formWindowBase())
|
|---|
| 431 | formWindowBase()->addReloadableProperty(this, indexOf(QLatin1String(currentTabIconKey)));
|
|---|
| 432 | createFakeProperty(QLatin1String(currentTabToolTipKey), qVariantFromValue(qdesigner_internal::PropertySheetStringValue()));
|
|---|
| 433 | createFakeProperty(QLatin1String(currentTabWhatsThisKey), qVariantFromValue(qdesigner_internal::PropertySheetStringValue()));
|
|---|
| 434 | // Prevent the tab widget's drag and drop handling from interfering with Designer's
|
|---|
| 435 | createFakeProperty(QLatin1String(tabMovableKey), QVariant(false));
|
|---|
| 436 | }
|
|---|
| 437 |
|
|---|
| 438 | QTabWidgetPropertySheet::TabWidgetProperty QTabWidgetPropertySheet::tabWidgetPropertyFromName(const QString &name)
|
|---|
| 439 | {
|
|---|
| 440 | typedef QHash<QString, TabWidgetProperty> TabWidgetPropertyHash;
|
|---|
| 441 | static TabWidgetPropertyHash tabWidgetPropertyHash;
|
|---|
| 442 | if (tabWidgetPropertyHash.empty()) {
|
|---|
| 443 | tabWidgetPropertyHash.insert(QLatin1String(currentTabTextKey), PropertyCurrentTabText);
|
|---|
| 444 | tabWidgetPropertyHash.insert(QLatin1String(currentTabNameKey), PropertyCurrentTabName);
|
|---|
| 445 | tabWidgetPropertyHash.insert(QLatin1String(currentTabIconKey), PropertyCurrentTabIcon);
|
|---|
| 446 | tabWidgetPropertyHash.insert(QLatin1String(currentTabToolTipKey), PropertyCurrentTabToolTip);
|
|---|
| 447 | tabWidgetPropertyHash.insert(QLatin1String(currentTabWhatsThisKey), PropertyCurrentTabWhatsThis);
|
|---|
| 448 | }
|
|---|
| 449 | return tabWidgetPropertyHash.value(name, PropertyTabWidgetNone);
|
|---|
| 450 | }
|
|---|
| 451 |
|
|---|
| 452 | void QTabWidgetPropertySheet::setProperty(int index, const QVariant &value)
|
|---|
| 453 | {
|
|---|
| 454 | const TabWidgetProperty tabWidgetProperty = tabWidgetPropertyFromName(propertyName(index));
|
|---|
| 455 | if (tabWidgetProperty == PropertyTabWidgetNone) {
|
|---|
| 456 | QDesignerPropertySheet::setProperty(index, value);
|
|---|
| 457 | return;
|
|---|
| 458 | }
|
|---|
| 459 |
|
|---|
| 460 | // index-dependent
|
|---|
| 461 | const int currentIndex = m_tabWidget->currentIndex();
|
|---|
| 462 | QWidget *currentWidget = m_tabWidget->currentWidget();
|
|---|
| 463 | if (!currentWidget)
|
|---|
| 464 | return;
|
|---|
| 465 |
|
|---|
| 466 | switch (tabWidgetProperty) {
|
|---|
| 467 | case PropertyCurrentTabText:
|
|---|
| 468 | m_tabWidget->setTabText(currentIndex, qvariant_cast<QString>(resolvePropertyValue(index, value)));
|
|---|
| 469 | m_pageToData[currentWidget].text = qVariantValue<qdesigner_internal::PropertySheetStringValue>(value);
|
|---|
| 470 | break;
|
|---|
| 471 | case PropertyCurrentTabName:
|
|---|
| 472 | currentWidget->setObjectName(value.toString());
|
|---|
| 473 | break;
|
|---|
| 474 | case PropertyCurrentTabIcon:
|
|---|
| 475 | m_tabWidget->setTabIcon(currentIndex, qvariant_cast<QIcon>(resolvePropertyValue(index, value)));
|
|---|
| 476 | m_pageToData[currentWidget].icon = qVariantValue<qdesigner_internal::PropertySheetIconValue>(value);
|
|---|
| 477 | break;
|
|---|
| 478 | case PropertyCurrentTabToolTip:
|
|---|
| 479 | m_tabWidget->setTabToolTip(currentIndex, qvariant_cast<QString>(resolvePropertyValue(index, value)));
|
|---|
| 480 | m_pageToData[currentWidget].tooltip = qVariantValue<qdesigner_internal::PropertySheetStringValue>(value);
|
|---|
| 481 | break;
|
|---|
| 482 | case PropertyCurrentTabWhatsThis:
|
|---|
| 483 | m_tabWidget->setTabWhatsThis(currentIndex, qvariant_cast<QString>(resolvePropertyValue(index, value)));
|
|---|
| 484 | m_pageToData[currentWidget].whatsthis = qVariantValue<qdesigner_internal::PropertySheetStringValue>(value);
|
|---|
| 485 | break;
|
|---|
| 486 | case PropertyTabWidgetNone:
|
|---|
| 487 | break;
|
|---|
| 488 | }
|
|---|
| 489 | }
|
|---|
| 490 |
|
|---|
| 491 | bool QTabWidgetPropertySheet::isEnabled(int index) const
|
|---|
| 492 | {
|
|---|
| 493 | if (tabWidgetPropertyFromName(propertyName(index)) == PropertyTabWidgetNone)
|
|---|
| 494 | return QDesignerPropertySheet::isEnabled(index);
|
|---|
| 495 | return m_tabWidget->currentIndex() != -1;
|
|---|
| 496 | }
|
|---|
| 497 |
|
|---|
| 498 | QVariant QTabWidgetPropertySheet::property(int index) const
|
|---|
| 499 | {
|
|---|
| 500 | const TabWidgetProperty tabWidgetProperty = tabWidgetPropertyFromName(propertyName(index));
|
|---|
| 501 | if (tabWidgetProperty == PropertyTabWidgetNone)
|
|---|
| 502 | return QDesignerPropertySheet::property(index);
|
|---|
| 503 |
|
|---|
| 504 | // index-dependent
|
|---|
| 505 | QWidget *currentWidget = m_tabWidget->currentWidget();
|
|---|
| 506 | if (!currentWidget) {
|
|---|
| 507 | if (tabWidgetProperty == PropertyCurrentTabIcon)
|
|---|
| 508 | return qVariantFromValue(qdesigner_internal::PropertySheetIconValue());
|
|---|
| 509 | if (tabWidgetProperty == PropertyCurrentTabText)
|
|---|
| 510 | return qVariantFromValue(qdesigner_internal::PropertySheetStringValue());
|
|---|
| 511 | if (tabWidgetProperty == PropertyCurrentTabToolTip)
|
|---|
| 512 | return qVariantFromValue(qdesigner_internal::PropertySheetStringValue());
|
|---|
| 513 | if (tabWidgetProperty == PropertyCurrentTabWhatsThis)
|
|---|
| 514 | return qVariantFromValue(qdesigner_internal::PropertySheetStringValue());
|
|---|
| 515 | return QVariant(QString());
|
|---|
| 516 | }
|
|---|
| 517 |
|
|---|
| 518 | // index-dependent
|
|---|
| 519 | switch (tabWidgetProperty) {
|
|---|
| 520 | case PropertyCurrentTabText:
|
|---|
| 521 | return qVariantFromValue(m_pageToData.value(currentWidget).text);
|
|---|
| 522 | case PropertyCurrentTabName:
|
|---|
| 523 | return currentWidget->objectName();
|
|---|
| 524 | case PropertyCurrentTabIcon:
|
|---|
| 525 | return qVariantFromValue(m_pageToData.value(currentWidget).icon);
|
|---|
| 526 | case PropertyCurrentTabToolTip:
|
|---|
| 527 | return qVariantFromValue(m_pageToData.value(currentWidget).tooltip);
|
|---|
| 528 | case PropertyCurrentTabWhatsThis:
|
|---|
| 529 | return qVariantFromValue(m_pageToData.value(currentWidget).whatsthis);
|
|---|
| 530 | case PropertyTabWidgetNone:
|
|---|
| 531 | break;
|
|---|
| 532 | }
|
|---|
| 533 | return QVariant();
|
|---|
| 534 | }
|
|---|
| 535 |
|
|---|
| 536 | bool QTabWidgetPropertySheet::reset(int index)
|
|---|
| 537 | {
|
|---|
| 538 | const TabWidgetProperty tabWidgetProperty = tabWidgetPropertyFromName(propertyName(index));
|
|---|
| 539 | if (tabWidgetProperty == PropertyTabWidgetNone)
|
|---|
| 540 | return QDesignerPropertySheet::reset(index);
|
|---|
| 541 |
|
|---|
| 542 | // index-dependent
|
|---|
| 543 | QWidget *currentWidget = m_tabWidget->currentWidget();
|
|---|
| 544 | if (!currentWidget)
|
|---|
| 545 | return false;
|
|---|
| 546 |
|
|---|
| 547 | // index-dependent
|
|---|
| 548 | switch (tabWidgetProperty) {
|
|---|
| 549 | case PropertyCurrentTabName:
|
|---|
| 550 | setProperty(index, QString());
|
|---|
| 551 | break;
|
|---|
| 552 | case PropertyCurrentTabToolTip:
|
|---|
| 553 | m_pageToData[currentWidget].tooltip = qdesigner_internal::PropertySheetStringValue();
|
|---|
| 554 | setProperty(index, QString());
|
|---|
| 555 | break;
|
|---|
| 556 | case PropertyCurrentTabWhatsThis:
|
|---|
| 557 | m_pageToData[currentWidget].whatsthis = qdesigner_internal::PropertySheetStringValue();
|
|---|
| 558 | setProperty(index, QString());
|
|---|
| 559 | break;
|
|---|
| 560 | case PropertyCurrentTabText:
|
|---|
| 561 | m_pageToData[currentWidget].text = qdesigner_internal::PropertySheetStringValue();
|
|---|
| 562 | setProperty(index, QString());
|
|---|
| 563 | break;
|
|---|
| 564 | case PropertyCurrentTabIcon:
|
|---|
| 565 | m_pageToData[currentWidget].icon = qdesigner_internal::PropertySheetIconValue();
|
|---|
| 566 | setProperty(index, QIcon());
|
|---|
| 567 | break;
|
|---|
| 568 | case PropertyTabWidgetNone:
|
|---|
| 569 | break;
|
|---|
| 570 | }
|
|---|
| 571 | return true;
|
|---|
| 572 | }
|
|---|
| 573 |
|
|---|
| 574 | bool QTabWidgetPropertySheet::checkProperty(const QString &propertyName)
|
|---|
| 575 | {
|
|---|
| 576 | switch (tabWidgetPropertyFromName(propertyName)) {
|
|---|
| 577 | case PropertyCurrentTabText:
|
|---|
| 578 | case PropertyCurrentTabName:
|
|---|
| 579 | case PropertyCurrentTabToolTip:
|
|---|
| 580 | case PropertyCurrentTabWhatsThis:
|
|---|
| 581 | case PropertyCurrentTabIcon:
|
|---|
| 582 | return false;
|
|---|
| 583 | default:
|
|---|
| 584 | break;
|
|---|
| 585 | }
|
|---|
| 586 | return true;
|
|---|
| 587 | }
|
|---|
| 588 |
|
|---|
| 589 | QT_END_NAMESPACE
|
|---|
| 590 |
|
|---|
| 591 | #include "qdesigner_tabwidget.moc" // required for MyMimeData
|
|---|