00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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 }