tools/designer/src/components/taskmenu/containerwidget_taskmenu.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the Qt Designer of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 /*
00025 TRANSLATOR qdesigner_internal::ContainerWidgetTaskMenu
00026 */
00027 
00028 #include "containerwidget_taskmenu.h"
00029 
00030 #include <QtDesigner/QtDesigner>
00031 #include <QtDesigner/QExtensionManager>
00032 
00033 #include <qdesigner_command_p.h>
00034 #include <qdesigner_stackedbox_p.h>
00035 #include <qdesigner_tabwidget_p.h>
00036 #include <qdesigner_toolbox_p.h>
00037 #include <qdesigner_dockwidget_p.h>
00038 
00039 #include <QtGui/QAction>
00040 #include <QtGui/QMainWindow>
00041 
00042 #include <QtCore/qdebug.h>
00043 
00044 using namespace qdesigner_internal;
00045 
00046 ContainerWidgetTaskMenu::ContainerWidgetTaskMenu(QWidget *widget, QObject *parent)
00047     : QDesignerTaskMenu(widget, parent),
00048       m_containerWidget(widget)
00049 {
00050     QAction *sep = new QAction(this);
00051     sep->setSeparator(true);
00052     m_taskActions.append(sep);
00053 
00054     m_actionDeletePage = new QAction(tr("Delete Page"), this);
00055     connect(m_actionDeletePage, SIGNAL(triggered()), this, SLOT(removeCurrentPage()));
00056 
00057     m_actionInsertPage = new QAction(tr("Insert Page Before Current Page"), this);
00058     connect(m_actionInsertPage, SIGNAL(triggered()), this, SLOT(addPage()));
00059 
00060     m_actionInsertPageAfter = new QAction(tr("Insert Page After Current Page"), this);
00061     connect(m_actionInsertPageAfter, SIGNAL(triggered()), this, SLOT(addPageAfter()));
00062 
00063     m_taskActions.append(m_actionDeletePage);
00064 
00065     sep = new QAction(this);
00066     sep->setSeparator(true);
00067     m_taskActions.append(sep);
00068 
00069     m_taskActions.append(m_actionInsertPageAfter);
00070     m_taskActions.append(m_actionInsertPage);
00071 }
00072 
00073 ContainerWidgetTaskMenu::~ContainerWidgetTaskMenu()
00074 {
00075 }
00076 
00077 QAction *ContainerWidgetTaskMenu::preferredEditAction() const
00078 {
00079     return 0;
00080 }
00081 
00082 QList<QAction*> ContainerWidgetTaskMenu::taskActions() const
00083 {
00084     QList<QAction*> actions = QDesignerTaskMenu::taskActions();
00085     actions += m_taskActions;
00086     if (QDesignerContainerExtension *ce = containterExtension())
00087         m_actionDeletePage->setEnabled(ce->count() > 1);
00088     return actions;
00089 }
00090 
00091 QDesignerFormEditorInterface *ContainerWidgetTaskMenu::core() const
00092 {
00093     if (QDesignerFormWindowInterface *fw = formWindow())
00094         return fw->core();
00095 
00096     return 0;
00097 }
00098 
00099 QDesignerFormWindowInterface *ContainerWidgetTaskMenu::formWindow() const
00100 {
00101     return QDesignerFormWindowInterface::findFormWindow(m_containerWidget);
00102 }
00103 
00104 QDesignerContainerExtension *ContainerWidgetTaskMenu::containterExtension() const
00105 {
00106     if (QDesignerFormEditorInterface *ed = core()) {
00107         QExtensionManager *mgr = ed->extensionManager();
00108         return qt_extension<QDesignerContainerExtension*>(mgr, m_containerWidget);
00109     }
00110 
00111     return 0;
00112 }
00113 
00114 void ContainerWidgetTaskMenu::removeCurrentPage()
00115 {
00116     if (QDesignerContainerExtension *c = containterExtension()) {
00117         if (c->currentIndex() == -1)
00118             return;
00119 
00120         QDesignerFormWindowInterface *fw = formWindow();
00121         DeleteContainerWidgetPageCommand *cmd = new DeleteContainerWidgetPageCommand(fw);
00122         cmd->init(m_containerWidget);
00123         fw->commandHistory()->push(cmd);
00124     }
00125 }
00126 
00127 void ContainerWidgetTaskMenu::addPage()
00128 {
00129     if (containterExtension()) {
00130         QDesignerFormWindowInterface *fw = formWindow();
00131         AddContainerWidgetPageCommand *cmd = new AddContainerWidgetPageCommand(fw);
00132         cmd->init(m_containerWidget, AddContainerWidgetPageCommand::InsertBefore);
00133         fw->commandHistory()->push(cmd);
00134     }
00135 }
00136 
00137 void ContainerWidgetTaskMenu::addPageAfter()
00138 {
00139     if (containterExtension()) {
00140         QDesignerFormWindowInterface *fw = formWindow();
00141         AddContainerWidgetPageCommand *cmd = new AddContainerWidgetPageCommand(fw);
00142         cmd->init(m_containerWidget, AddContainerWidgetPageCommand::InsertAfter);
00143         fw->commandHistory()->push(cmd);
00144     }
00145 }
00146 
00147 ContainerWidgetTaskMenuFactory::ContainerWidgetTaskMenuFactory(QExtensionManager *extensionManager)
00148     : QExtensionFactory(extensionManager)
00149 {
00150 }
00151 
00152 QObject *ContainerWidgetTaskMenuFactory::createExtension(QObject *object, const QString &iid, QObject *parent) const
00153 {
00154     if (iid != Q_TYPEID(QDesignerTaskMenuExtension))
00155         return 0;
00156 
00157     QWidget *widget = qobject_cast<QWidget*>(object);
00158     if (!widget)
00159         return 0;
00160 
00161     if (qobject_cast<QDesignerStackedWidget*>(widget)
00162             || qobject_cast<QDesignerToolBox*>(widget)
00163             || qobject_cast<QDesignerTabWidget*>(widget)
00164             || qobject_cast<QDesignerDockWidget*>(widget)
00165             || qobject_cast<QMainWindow*>(widget))
00166         return 0;
00167 
00168     if (qt_extension<QDesignerContainerExtension*>(extensionManager(), object)) {
00169         return new ContainerWidgetTaskMenu(widget, parent);
00170     }
00171 
00172     return 0;
00173 }

Generated on Thu Mar 15 12:01:13 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1