void WidgetHandle::paintEvent(QPaintEvent *)
{
    QDesignerFormWindowManagerInterface *m = m_formWindow->core()->formWindowManager();

    QStylePainter p(this);
    if (m_formWindow->currentWidget() == m_widget) {
        p.setPen(m->activeFormWindow() == m_formWindow ? Qt::blue : Qt::red);
        p.drawRect(0, 0, width() - 1, height() - 1);
    }
}
xTupleDesignerActions::xTupleDesignerActions(xTupleDesigner *parent)
  : QObject(parent)
{
  _designer = parent;

  _fileActions = new QActionGroup(parent);
  _fileActions->setObjectName("_fileActions");
  _fileActions->setExclusive(false);

  QAction *closeAct  = new QAction(tr("&Close"),   this);
  QAction *openAct   = new QAction(tr("&Open..."), this);
  QAction *revertAct = new QAction(tr("&Revert"),  this);
  QAction *saveAct   = new QAction(tr("&Save..."), this);

  closeAct->setShortcut(tr("CTRL+W"));
  openAct->setShortcut(tr("CTRL+O"));
  revertAct->setShortcut(tr("CTRL+R"));
  saveAct->setShortcut(tr("CTRL+S"));

  connect(closeAct,  SIGNAL(triggered()), this, SLOT(sClose()));
  connect(openAct,   SIGNAL(triggered()), this, SLOT(sOpen()));
  connect(revertAct, SIGNAL(triggered()), this, SLOT(sRevert()));
  connect(saveAct,   SIGNAL(triggered()), this, SLOT(sSave()));

  _fileActions->addAction(revertAct);
  _fileActions->addAction(separator(this));
  _fileActions->addAction(openAct);
  _fileActions->addAction(saveAct);
  _fileActions->addAction(separator(this));
  _fileActions->addAction(closeAct);

  _editActions = new QActionGroup(parent);
  _editActions->setObjectName("_editActions");
  _editActions->setExclusive(false);

  QDesignerFormWindowManagerInterface *formwm = parent->formeditor()->formWindowManager();

  //QAction *editBuddiesAct    = new QAction(tr("Edit Buddies"),   this);
  //QAction *editSignalSlotAct = new QAction(tr("Edit Signal/Slot Connections"), this);
  //QAction *editTabOrderAct   = new QAction(tr("Edit Tab Order"), this);
  //QAction *editWidgetsAct    = new QAction(tr("Edit Widgets"),   this);
  QAction *redoAct           = formwm->actionRedo();
  QAction *undoAct           = formwm->actionUndo();


  undoAct->setShortcut(tr("CTRL+Z"));
  redoAct->setShortcut(tr("CTRL+SHIFT+Z"));

  _editActions->addAction(undoAct);
  _editActions->addAction(redoAct);
  _editActions->addAction(separator(this));
  _editActions->addAction(formwm->actionCut());
  _editActions->addAction(formwm->actionCopy());
  _editActions->addAction(formwm->actionPaste());
  _editActions->addAction(formwm->actionDelete());
  _editActions->addAction(formwm->actionSelectAll());
  _editActions->addAction(separator(this));
  _editActions->addAction(formwm->actionLower());
  _editActions->addAction(formwm->actionRaise());

  _toolActions = new QActionGroup(parent);
  _toolActions->setObjectName("_toolActions");
  _toolActions->setExclusive(true);

  QAction *m_editWidgetsAction = new QAction(tr("Edit Widgets"),   this);
  m_editWidgetsAction->setCheckable(true);
  QList<QKeySequence> shortcuts;
  shortcuts.append(QKeySequence(Qt::Key_F3));
#if QT_VERSION >= 0x040900 // "ESC" switching to edit mode: Activate once item delegates handle shortcut overrides for ESC.
  shortcuts.append(QKeySequence(Qt::Key_Escape));
#endif
  m_editWidgetsAction->setShortcuts(shortcuts);
  m_editWidgetsAction->setIcon(QIcon(_designer->formeditor()->resourceLocation() + QLatin1String("/widgettool.png")));
  connect(m_editWidgetsAction, SIGNAL(triggered()), this, SLOT(sEditWidgets()));
  m_editWidgetsAction->setChecked(true);
  m_editWidgetsAction->setEnabled(false);
  _toolActions->addAction(m_editWidgetsAction);

  QList<QObject*> builtinPlugins = QPluginLoader::staticInstances();
  builtinPlugins += _designer->formeditor()->pluginManager()->instances();
  foreach (QObject *plugin, builtinPlugins)
  {
    if (QDesignerFormEditorPluginInterface *formEditorPlugin = qobject_cast<QDesignerFormEditorPluginInterface*>(plugin))
    {
      if (QAction *action = formEditorPlugin->action())
      {
        _toolActions->addAction(action);
        action->setCheckable(true);
      }
    }
  }

  _formActions = new QActionGroup(parent);
  _formActions->setObjectName("_formActions");
  _formActions->setExclusive(false);

  _formActions->addAction(formwm->actionHorizontalLayout());
  _formActions->addAction(formwm->actionVerticalLayout());
  _formActions->addAction(formwm->actionSplitHorizontal());
  _formActions->addAction(formwm->actionSplitVertical());
  _formActions->addAction(formwm->actionGridLayout());
  _formActions->addAction(formwm->actionFormLayout());
  _formActions->addAction(formwm->actionBreakLayout());
  _formActions->addAction(formwm->actionAdjustSize());
  _formActions->addAction(formwm->actionSimplifyLayout());

  connect(formwm, SIGNAL(activeFormWindowChanged(QDesignerFormWindowInterface*)),
          this,   SLOT(sActiveFormWindowChanged(QDesignerFormWindowInterface*)));
  sActiveFormWindowChanged(formwm->activeFormWindow());
}