Example #1
0
int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QMainWindow::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: newFile(); break;
        case 1: open(); break;
        case 2: { bool _r = save();
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 3: { bool _r = saveas();
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 4: find(); break;
        case 5: goToCell(); break;
        case 6: sort(); break;
        case 7: about(); break;
        case 8: openRecentFile(); break;
        case 9: updateStatusBar(); break;
        case 10: spreadsheetModified(); break;
        default: ;
        }
        _id -= 11;
    }
    return _id;
}
Example #2
0
void MainWindow::createActions()
{
    newAction = new QAction(tr("&New"), this );
    newAction->setIcon(QIcon(":/images/pics/new.png"));
	newAction->setShortcut(tr("Ctrl+N"));
    newAction->setStatusTip(tr("Create a new spreadsheet."));
	connect(newAction, SIGNAL(triggered()), this , SLOT(newFile()));
	// 其他相关 action
	for ( int i = 0; i < MaxRecentFiles; ++i)
	{
        recentFileActions[i] = new QAction(this);
        recentFileActions[i]->setVisible(false);
		connect(recentFileActions[i], SIGNAL(triggered()), this , SLOT(openRecentFile()));
	}
	
    selectAllAction = new QAction(tr("&Select All"), this );
	selectAllAction->setShortcut(tr("Ctrl+A"));
    selectAllAction->setStatusTip(tr("Select all the data" "spreadsheet"));
    //connect(selectAllAction, SIGNAL(triggered()), spreadsheet, SLOT(selectAll())) ;
	
    aboutQtAction = new QAction(tr("About &Qt"), this );
    aboutQtAction -> setIcon(QIcon(":/images/pics/qt.png"));
    aboutQtAction->setStatusTip(tr("Show the Qt library's About box"));
	connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
	
    saveAction = new QAction(tr("&Save"), this );
    saveAction -> setShortcut(tr("Ctrl+S"));
    saveAction -> setIcon(QIcon(":/images/pics/save.png"));
	connect(saveAction, SIGNAL(triggered()), this, SLOT(save())) ;
	
    saveAsAction = new QAction(tr("Save &As"), this );
	connect(saveAsAction, SIGNAL(triggered()), this, SLOT(saveAs())) ;
	
    openAction = new QAction(tr("&Open"), this);
    openAction -> setShortcut(tr("Ctrl+O"));
    openAction -> setIcon(QIcon(":/images/pics/open.png"));
	connect(openAction, SIGNAL(triggered()), this, SLOT(open()));
	
    cutAction = new QAction(tr("C&ut"), this );
    cutAction -> setShortcut(tr("Ctrl+X"));
    cutAction -> setIcon(QIcon(":/images/pics/cut.png"));
    connect(cutAction, SIGNAL(triggered()), this, SLOT(cut())) ;
	
    copyAction = new QAction(tr("&Copy"), this );
    copyAction -> setShortcut(tr("Ctrl+X"));
    copyAction -> setIcon(QIcon(":/images/pics/copy.png"));
    connect(copyAction, SIGNAL(triggered()), this, SLOT(copy())) ;
	
    pasteAction = new QAction(tr("&Past"), this );
    pasteAction -> setShortcut(tr("Ctrl+P"));
    pasteAction -> setIcon(QIcon(":/images/pics/paste.png"));
    connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste())) ;
	
    deleteAction = new QAction(tr("&Delete"), this );
    deleteAction -> setShortcut(tr("Ctrl+D"));
    deleteAction -> setIcon(QIcon(":/images/pics/delete.png"));
    connect(deleteAction, SIGNAL(triggered()), this, SLOT(del())) ;
	
    findAction = new QAction(tr("&Find"), this );
    findAction -> setShortcut(tr("Ctrl+F"));
    findAction -> setIcon(QIcon(":/images/pics/search.png"));
	connect(findAction, SIGNAL(triggered()), this, SLOT(find())) ;
	
    goToCellAction = new QAction(tr("Go &to Cell"), this );
    goToCellAction -> setShortcut(tr("Ctrl+G"));
    goToCellAction -> setIcon(QIcon(":/images/pics/gotocell.png"));
    connect(goToCellAction, SIGNAL(triggered()), this, SLOT(goToCell()));

    exitAction = new QAction(tr("&Quit"), this );
    exitAction -> setShortcut(tr("Ctrl+Q"));
    exitAction -> setIcon(QIcon(":/images/pics/quit.png"));
	connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
	
    aboutAction = new QAction(tr("&About Spreadsheet"), this );
    aboutAction -> setIcon(QIcon(":/images/pics/about.png"));
	connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
	
    selectRowAction = new QAction(tr("Select &row"), this );
    selectColumnAction = new QAction(tr("Select &column"), this );

    recalculateAction = new QAction(tr("&ReCalculate"), this);
    recalculateAction -> setShortcut(tr("Ctrl+R"));
    recalculateAction -> setIcon(QIcon(":/images/pics/cal.png"));

    sortAction = new QAction(tr("&Sort"), this);
    sortAction -> setShortcut(tr("Ctrl+T"));
    sortAction -> setIcon(QIcon(":/images/pics/sort.png"));
	connect(sortAction, SIGNAL(triggered()), this, SLOT(sort()));
	
    showGridAction = new QAction(tr("Show &Grid"), this );
    showGridAction->setCheckable( true );
    //showGridAction->setChecked(spreadsheet->showGrid());
    showGridAction->setStatusTip(tr("Show or hide the grid"));
    //connect(showGridAction, SIGNAL(toggled( bool )),spreadsheet, SLOT(setShowGrid( bool )));

    autoRecalcAction = new QAction(tr("&Auto RecalcAction"), this);
    autoRecalcAction -> setCheckable(true);
    autoRecalcAction -> setChecked(true);
}
void MainWindow::createActions()
{
    newAction = new QAction(tr("&New"), this);
    newAction->setIcon(QIcon(":/images/new.png"));
    newAction->setShortcut(QKeySequence::New);
    newAction->setStatusTip(tr("Create a new spreadsheet file"));
    connect(newAction, SIGNAL(triggered()), this, SLOT(newFile()));

    openAction = new QAction(tr("&Open..."), this);
    openAction->setIcon(QIcon(":/images/open.png"));
    openAction->setShortcut(QKeySequence::Open);
    openAction->setStatusTip(tr("Open an existing spreadsheet file"));
    connect(openAction, SIGNAL(triggered()), this, SLOT(open()));

    saveAction = new QAction(tr("&Save"), this);
    saveAction->setIcon(QIcon(":/images/save.png"));
    saveAction->setShortcut(QKeySequence::Save);
    saveAction->setStatusTip(tr("Save the spreadsheet to disk"));
    connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));

    saveAsAction = new QAction(tr("Save &As..."), this);
    saveAsAction->setStatusTip(tr("Save the spreadsheet under a new "
                                  "name"));
    connect(saveAsAction, SIGNAL(triggered()), this, SLOT(saveAs()));

    for (int i = 0; i < MaxRecentFiles; ++i) {
        recentFileActions[i] = new QAction(this);
        recentFileActions[i]->setVisible(false);
        connect(recentFileActions[i], SIGNAL(triggered()),
                this, SLOT(openRecentFile()));
    }

    exitAction = new QAction(tr("E&xit"), this);
    exitAction->setShortcut(tr("Ctrl+Q"));
    exitAction->setStatusTip(tr("Exit the application"));
    connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));

    cutAction = new QAction(tr("Cu&t"), this);
    cutAction->setIcon(QIcon(":/images/cut.png"));
    cutAction->setShortcut(QKeySequence::Cut);
    cutAction->setStatusTip(tr("Cut the current selection's contents "
                               "to the clipboard"));
    connect(cutAction, SIGNAL(triggered()), spreadsheet, SLOT(cut()));

    copyAction = new QAction(tr("&Copy"), this);
    copyAction->setIcon(QIcon(":/images/copy.png"));
    copyAction->setShortcut(QKeySequence::Copy);
    copyAction->setStatusTip(tr("Copy the current selection's contents "
                                "to the clipboard"));
    connect(copyAction, SIGNAL(triggered()), spreadsheet, SLOT(copy()));

    pasteAction = new QAction(tr("&Paste"), this);
    pasteAction->setIcon(QIcon(":/images/paste.png"));
    pasteAction->setShortcut(QKeySequence::Paste);
    pasteAction->setStatusTip(tr("Paste the clipboard's contents into "
                                 "the current selection"));
    connect(pasteAction, SIGNAL(triggered()),
            spreadsheet, SLOT(paste()));

    deleteAction = new QAction(tr("&Delete"), this);
    deleteAction->setShortcut(QKeySequence::Delete);
    deleteAction->setStatusTip(tr("Delete the current selection's "
                                  "contents"));
    connect(deleteAction, SIGNAL(triggered()),
            spreadsheet, SLOT(del()));

    selectRowAction = new QAction(tr("&Row"), this);
    selectRowAction->setStatusTip(tr("Select all the cells in the "
                                     "current row"));
    connect(selectRowAction, SIGNAL(triggered()),
            spreadsheet, SLOT(selectCurrentRow()));

    selectColumnAction = new QAction(tr("&Column"), this);
    selectColumnAction->setStatusTip(tr("Select all the cells in the "
                                        "current column"));
    connect(selectColumnAction, SIGNAL(triggered()),
            spreadsheet, SLOT(selectCurrentColumn()));

    selectAllAction = new QAction(tr("&All"), this);
    selectAllAction->setShortcut(QKeySequence::SelectAll);
    selectAllAction->setStatusTip(tr("Select all the cells in the "
                                     "spreadsheet"));
    connect(selectAllAction, SIGNAL(triggered()),
            spreadsheet, SLOT(selectAll()));

    findAction = new QAction(tr("&Find..."), this);
    findAction->setIcon(QIcon(":/images/find.png"));
    findAction->setShortcut(QKeySequence::Find);
    findAction->setStatusTip(tr("Find a matching cell"));
    connect(findAction, SIGNAL(triggered()), this, SLOT(find()));

    goToCellAction = new QAction(tr("&Go to Cell..."), this);
    goToCellAction->setIcon(QIcon(":/images/gotocell.png"));
    goToCellAction->setShortcut(tr("Ctrl+G"));
    goToCellAction->setStatusTip(tr("Go to the specified cell"));
    connect(goToCellAction, SIGNAL(triggered()),
            this, SLOT(goToCell()));

    recalculateAction = new QAction(tr("&Recalculate"), this);
    recalculateAction->setShortcut(tr("F9"));
    recalculateAction->setStatusTip(tr("Recalculate all the "
                                       "spreadsheet's formulas"));
    connect(recalculateAction, SIGNAL(triggered()),
            spreadsheet, SLOT(recalculate()));

    sortAction = new QAction(tr("&Sort..."), this);
    sortAction->setStatusTip(tr("Sort the selected cells or all the "
                                "cells"));
    connect(sortAction, SIGNAL(triggered()), this, SLOT(sort()));

    showGridAction = new QAction(tr("&Show Grid"), this);
    showGridAction->setCheckable(true);
    showGridAction->setChecked(spreadsheet->showGrid());
    showGridAction->setStatusTip(tr("Show or hide the spreadsheet's "
                                    "grid"));
    connect(showGridAction, SIGNAL(toggled(bool)),
            spreadsheet, SLOT(setShowGrid(bool)));
#if QT_VERSION < 0x040102
    // workaround for a QTableWidget bug in Qt 4.1.1
    connect(showGridAction, SIGNAL(toggled(bool)),
            spreadsheet->viewport(), SLOT(update()));
#endif

    autoRecalcAction = new QAction(tr("&Auto-Recalculate"), this);
    autoRecalcAction->setCheckable(true);
    autoRecalcAction->setChecked(spreadsheet->autoRecalculate());
    autoRecalcAction->setStatusTip(tr("Switch auto-recalculation on or "
                                      "off"));
    connect(autoRecalcAction, SIGNAL(toggled(bool)),
            spreadsheet, SLOT(setAutoRecalculate(bool)));

    aboutAction = new QAction(tr("&About"), this);
    aboutAction->setStatusTip(tr("Show the application's About box"));
    connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));

    aboutQtAction = new QAction(tr("About &Qt"), this);
    aboutQtAction->setStatusTip(tr("Show the Qt library's About box"));
    connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
}