Skip to content

Commit

Permalink
mainwindow: prepared for multiple edit boxes
Browse files Browse the repository at this point in the history
the edit box context menu actions are now saved in a member variable so
that the action list can be reused in another edit box instance and the
separators were given the main window instance as parent instead of the
edit box instance

the connection of the signals from the edit box instance and the setting
of edit box context menu were moved to a new set active function, which
can be called for any edit box instance, with preliminary code to
disconnect the signals and remove the context menu actions of a previous
edit box (commented since only one edit box is currently supported)
  • Loading branch information
thunder422 committed Jan 4, 2014
1 parent f06fa7c commit 5b87417
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 34 deletions.
86 changes: 52 additions & 34 deletions mainwindow.cpp
Expand Up @@ -61,6 +61,19 @@ MainWindow::MainWindow(QWidget *parent) :

statusBarCreate();

// create actions for edit box context menu
m_contextActions.append(ui->actionUndo);
m_contextActions.append(ui->actionRedo);
m_contextActions.append(new QAction(this));
m_contextActions.last()->setSeparator(true);
m_contextActions.append(ui->actionCut);
m_contextActions.append(ui->actionCopy);
m_contextActions.append(ui->actionPaste);
m_contextActions.append(ui->actionDelete);
m_contextActions.append(new QAction(this));
m_contextActions.last()->setSeparator(true);
m_contextActions.append(ui->actionSelectAll);

// TODO settings will eventually have info about edit boxes that were open
// TODO that will need to be restored, for now there is a single edit box

Expand All @@ -77,40 +90,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(m_editBox->document(), SIGNAL(modificationChanged(bool)),
ui->actionSave, SLOT(setEnabled(bool)));

// connect available signals to the appropriate edit actions
connect(m_editBox, SIGNAL(undoAvailable(bool)),
ui->actionUndo, SLOT(setEnabled(bool)));
connect(m_editBox, SIGNAL(redoAvailable(bool)),
ui->actionRedo, SLOT(setEnabled(bool)));
connect(m_editBox, SIGNAL(copyAvailable(bool)),
ui->actionCut, SLOT(setEnabled(bool)));
connect(m_editBox, SIGNAL(copyAvailable(bool)),
ui->actionCopy, SLOT(setEnabled(bool)));
connect(m_editBox, SIGNAL(copyAvailable(bool)),
ui->actionDelete, SLOT(setEnabled(bool)));
connect(m_editBox, SIGNAL(errorsAvailable(bool)),
ui->actionGoNextError, SLOT(setEnabled(bool)));
connect(m_editBox, SIGNAL(errorsAvailable(bool)),
ui->actionGoPrevError, SLOT(setEnabled(bool)));

connect(m_editBox, SIGNAL(cursorChanged(QString)),
this, SLOT(statusBarUpdate(QString)));

// create actions for edit box context menu
QList<QAction *> actions;
actions.append(ui->actionUndo);
actions.append(ui->actionRedo);
actions.append(new QAction(m_editBox));
actions.last()->setSeparator(true);
actions.append(ui->actionCut);
actions.append(ui->actionCopy);
actions.append(ui->actionPaste);
actions.append(ui->actionDelete);
actions.append(new QAction(m_editBox));
actions.last()->setSeparator(true);
actions.append(ui->actionSelectAll);
m_editBox->addActions(actions);
m_editBox->setContextMenuPolicy(Qt::ActionsContextMenu);
editBoxSetActive(m_editBox);

//========================================
// SETUP PROGRAM LINE DELEGATE AND VIEW
Expand Down Expand Up @@ -206,6 +186,44 @@ void MainWindow::statusBarUpdate(const QString &message)
}


// function to set an edit box active
void MainWindow::editBoxSetActive(EditBox *editBox)
{
// TODO first disconnect signals and remove actions from current edit box
#if 0
m_editBox->disconnect();
QList<QAction *>actions = m_editBox->actions();
foreach(QAction *action, actions)
{
m_editBox->removeAction(action);
}
#endif

// connect available signals to the appropriate edit actions
connect(editBox, SIGNAL(undoAvailable(bool)),
ui->actionUndo, SLOT(setEnabled(bool)));
connect(editBox, SIGNAL(redoAvailable(bool)),
ui->actionRedo, SLOT(setEnabled(bool)));
connect(editBox, SIGNAL(copyAvailable(bool)),
ui->actionCut, SLOT(setEnabled(bool)));
connect(editBox, SIGNAL(copyAvailable(bool)),
ui->actionCopy, SLOT(setEnabled(bool)));
connect(editBox, SIGNAL(copyAvailable(bool)),
ui->actionDelete, SLOT(setEnabled(bool)));
connect(editBox, SIGNAL(errorsAvailable(bool)),
ui->actionGoNextError, SLOT(setEnabled(bool)));
connect(editBox, SIGNAL(errorsAvailable(bool)),
ui->actionGoPrevError, SLOT(setEnabled(bool)));

connect(editBox, SIGNAL(cursorChanged(QString)),
this, SLOT(statusBarUpdate(QString)));

// set context actions for edit box context menu
editBox->addActions(m_contextActions);
editBox->setContextMenuPolicy(Qt::ActionsContextMenu);
}


// function called when new program has been requested
//
// - if it is ok to continue, the current program is cleared
Expand Down
3 changes: 3 additions & 0 deletions mainwindow.h
Expand Up @@ -81,6 +81,7 @@ private slots:

private:
void statusBarCreate(void);
void editBoxSetActive(EditBox *editBox);

bool isOkToContinue(void);
void setCurProgram(const QString &programPath);
Expand All @@ -105,6 +106,8 @@ private slots:
ProgramLineDelegate *m_programLineDelegate;
QLabel *m_statusPositionLabel;
QLabel *m_statusMessageLabel;
QList<QAction *> m_contextActions;
};


#endif // MAINWINDOW_H

0 comments on commit 5b87417

Please sign in to comment.