#include <QtGui>
#include "mainwindowimpl.h"
#include "spreadsheet.h" // required for most menu functions
#include "GoToCellDialog.h"
#include "printview.h"
//
MainWindowImpl
::MainWindowImpl(QWidget * parent, Qt
::WFlags f
) {
//setAttribute(Qt::WA_DeleteOnClose); // frees memory from MDI windows
//spreadsheet = new Spreadsheet; commented out for MDI 11/2/10
mdiArea = new QMdiArea;
setCentralWidget(mdiArea);
setupUi(this);
connect(mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)),
this, SLOT(updateActions()));
createActionGroup();
QTimer::singleShot(0,
this,
SLOT(loadFiles
()));
//setCentralWidget(spreadsheet); // centre spreadsheet on form between statusbar, toolbar and
//createContextMenu();
// setup signals and slots for menu actions starting with basic ones
connect(actionC_opy_Ctrl_C, SIGNAL(triggered()), this, SLOT(copy()));
connect(actionSelect_All_Ctrl_A, SIGNAL(triggered()), this, SLOT(selectAll()));
connect(actionSelect_Co_lumn, SIGNAL(triggered()), this, SLOT(selectCurrentColumn()));
connect(actionSelect_Ro_w, SIGNAL(triggered()),this, SLOT(selectCurrentRow()));
connect(action_Paste_Ctrl_V, SIGNAL(triggered()), this, SLOT(paste()));
connect(action_Cut_Ctrl_X, SIGNAL(triggered()), this, SLOT(cut()));
connect(actionFont, SIGNAL(triggered()), this, SLOT(selectFont()));
connect(actionGoto_Cell, SIGNAL(triggered()),this, SLOT(goToCell()));
connect(actionPrint_Pre_view_Alt_P, SIGNAL(triggered()), this, SLOT(printPreview()));
//connect(actionShow_Grid_Alt_G, SIGNAL(toggled(bool)), this, SLOT(setShowGrid(bool)));
//connect(actionPrint_S_elected_Range, SIGNAL(triggered()), this, SLOT(toHtml(const QString &plainText)));
//connect(actionPrint_S_elected_Range, SIGNAL(triggered()), this, SLOT(printHtml(const QString &html)));
connect(action_New_Ctrl_N, SIGNAL(triggered()),this, SLOT(newFile()));
}
//
void MainWindowImpl::newFile()
{
Spreadsheet *spreadsheet = new Spreadsheet;
spreadsheet->newFile();
addSpreadsheet(spreadsheet); // line 51
}
void MainWindowImpl::updateActions()
{
/* bool hasSpreadsheet = (activeSpreadsheet() != 0);
bool hasSelection = activeSpreadsheet()
&& activeSpreadsheet()->textCursor().hasSelection();*/
/* saveAction->setEnabled(hasEditor);
saveAsAction->setEnabled(hasEditor);
cutAction->setEnabled(hasSelection);
copyAction->setEnabled(hasSelection);
pasteAction->setEnabled(hasEditor);
closeAction->setEnabled(hasEditor);
closeAllAction->setEnabled(hasEditor);
tileAction->setEnabled(hasEditor);
cascadeAction->setEnabled(hasEditor);
nextAction->setEnabled(hasEditor);
previousAction->setEnabled(hasEditor);
separatorAction->setVisible(hasEditor); */
if (activeSpreadsheet())
activeSpreadsheet()->windowMenuAction()->setChecked(true);
}
void MainWindowImpl::loadFiles() // added 11/2/09 for MDI
{
args.removeFirst();
if (!args.isEmpty()) {
openFile(arg);
mdiArea->cascadeSubWindows();
} else {
newFile(); //line 85 line 89 is case 4: loadFiles(); break; in moc file
}
mdiArea->activateNextSubWindow();
}
void MainWindowImpl
::openFile(const QString &fileName
) // added 11/2/09 for MDI {
Spreadsheet *spreadsheet = Spreadsheet::openFile(fileName, this);
if (spreadsheet)
addSpreadsheet(spreadsheet);
}
void MainWindowImpl::addSpreadsheet(Spreadsheet *spreadsheet) // added 11/2/09 for MDI
{
QMdiSubWindow *subWindow = mdiArea->addSubWindow(spreadsheet); // line 104
windowMenu->addAction(spreadsheet->windowMenuAction());
windowActionGroup->addAction(spreadsheet->windowMenuAction());
subWindow->show();
}
Spreadsheet *MainWindowImpl::activeSpreadsheet() // added 11/2/09 for MDI
{
QMdiSubWindow *subWindow = mdiArea->activeSubWindow();
if (subWindow)
return qobject_cast<Spreadsheet *>(subWindow->widget());
return 0;
}
void MainWindowImpl::createActionGroup()
{
}
/*
void MainWindowImpl::createContextMenu()
{
activeSpreadsheet()->addAction(action_Cut_Ctrl_X);//changed from spreadsheet() for MDI
activeSpreadsheet()->addAction(actionC_opy_Ctrl_C);//changed from spreadsheet() for MDI
activeSpreadsheet()->addAction(action_Paste_Ctrl_V);//changed from spreadsheet() for MDI
activeSpreadsheet()->setContextMenuPolicy(Qt::ActionsContextMenu);//changed from spreadsheet() for MDI
}
*/
void MainWindowImpl::goToCell()
{
GoToCellDialog dialog(this);
if (dialog.exec())
{
QString str
= dialog.
lineEdit->text
().
toUpper();
activeSpreadsheet()->setCurrentCell(str.mid(1).toInt() - 1, //changed from spreadsheet() for MDI
str[0].unicode() - 'A');
}
}
void MainWindowImpl::printPreview()
{
#ifndef QT_NO_PRINTER
QPrinter printer
(QPrinter::ScreenResolution);
// set printer to screen resolution QPrintPreviewDialog dlg(&printer);
PrintView view;
view.setModel(activeSpreadsheet()->model()); //changed from spreadsheet() for MDI
connect(&dlg,
SIGNAL(paintRequested
(QPrinter *)),
dlg.exec();
#endif
}
void MainWindowImpl::copy()
{
if (activeSpreadsheet())
activeSpreadsheet()->copy();
}
void MainWindowImpl::paste()
{
if (activeSpreadsheet())
activeSpreadsheet()->paste();
}
void MainWindowImpl::cut()
{
if (activeSpreadsheet())
activeSpreadsheet()->cut();
}
void MainWindowImpl::selectAll()
{
if (activeSpreadsheet())
activeSpreadsheet()->selectAll();
}
void MainWindowImpl::selectCurrentColumn()
{
if (activeSpreadsheet())
activeSpreadsheet()->selectCurrentColumn();
}
void MainWindowImpl::selectCurrentRow()
{
if (activeSpreadsheet())
activeSpreadsheet()->selectCurrentRow();
}
#include <QtGui>
#include "mainwindowimpl.h"
#include "spreadsheet.h" // required for most menu functions
#include "GoToCellDialog.h"
#include "printview.h"
//
MainWindowImpl::MainWindowImpl(QWidget * parent, Qt::WFlags f)
: QMainWindow(parent, f)
{
//setAttribute(Qt::WA_DeleteOnClose); // frees memory from MDI windows
//spreadsheet = new Spreadsheet; commented out for MDI 11/2/10
mdiArea = new QMdiArea;
setCentralWidget(mdiArea);
setupUi(this);
connect(mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)),
this, SLOT(updateActions()));
createActionGroup();
QTimer::singleShot(0, this, SLOT(loadFiles()));
//setCentralWidget(spreadsheet); // centre spreadsheet on form between statusbar, toolbar and
//createContextMenu();
// setup signals and slots for menu actions starting with basic ones
connect(actionC_opy_Ctrl_C, SIGNAL(triggered()), this, SLOT(copy()));
connect(actionSelect_All_Ctrl_A, SIGNAL(triggered()), this, SLOT(selectAll()));
connect(actionSelect_Co_lumn, SIGNAL(triggered()), this, SLOT(selectCurrentColumn()));
connect(actionSelect_Ro_w, SIGNAL(triggered()),this, SLOT(selectCurrentRow()));
connect(action_Paste_Ctrl_V, SIGNAL(triggered()), this, SLOT(paste()));
connect(action_Cut_Ctrl_X, SIGNAL(triggered()), this, SLOT(cut()));
connect(actionFont, SIGNAL(triggered()), this, SLOT(selectFont()));
connect(actionGoto_Cell, SIGNAL(triggered()),this, SLOT(goToCell()));
connect(actionPrint_Pre_view_Alt_P, SIGNAL(triggered()), this, SLOT(printPreview()));
//connect(actionShow_Grid_Alt_G, SIGNAL(toggled(bool)), this, SLOT(setShowGrid(bool)));
//connect(actionPrint_S_elected_Range, SIGNAL(triggered()), this, SLOT(toHtml(const QString &plainText)));
//connect(actionPrint_S_elected_Range, SIGNAL(triggered()), this, SLOT(printHtml(const QString &html)));
connect(action_New_Ctrl_N, SIGNAL(triggered()),this, SLOT(newFile()));
}
//
void MainWindowImpl::newFile()
{
Spreadsheet *spreadsheet = new Spreadsheet;
spreadsheet->newFile();
addSpreadsheet(spreadsheet); // line 51
}
void MainWindowImpl::updateActions()
{
/* bool hasSpreadsheet = (activeSpreadsheet() != 0);
bool hasSelection = activeSpreadsheet()
&& activeSpreadsheet()->textCursor().hasSelection();*/
/* saveAction->setEnabled(hasEditor);
saveAsAction->setEnabled(hasEditor);
cutAction->setEnabled(hasSelection);
copyAction->setEnabled(hasSelection);
pasteAction->setEnabled(hasEditor);
closeAction->setEnabled(hasEditor);
closeAllAction->setEnabled(hasEditor);
tileAction->setEnabled(hasEditor);
cascadeAction->setEnabled(hasEditor);
nextAction->setEnabled(hasEditor);
previousAction->setEnabled(hasEditor);
separatorAction->setVisible(hasEditor); */
if (activeSpreadsheet())
activeSpreadsheet()->windowMenuAction()->setChecked(true);
}
void MainWindowImpl::loadFiles() // added 11/2/09 for MDI
{
QStringList args = QApplication::arguments();
args.removeFirst();
if (!args.isEmpty()) {
foreach (QString arg, args)
openFile(arg);
mdiArea->cascadeSubWindows();
} else {
newFile(); //line 85 line 89 is case 4: loadFiles(); break; in moc file
}
mdiArea->activateNextSubWindow();
}
void MainWindowImpl::openFile(const QString &fileName) // added 11/2/09 for MDI
{
Spreadsheet *spreadsheet = Spreadsheet::openFile(fileName, this);
if (spreadsheet)
addSpreadsheet(spreadsheet);
}
void MainWindowImpl::addSpreadsheet(Spreadsheet *spreadsheet) // added 11/2/09 for MDI
{
QMdiSubWindow *subWindow = mdiArea->addSubWindow(spreadsheet); // line 104
windowMenu->addAction(spreadsheet->windowMenuAction());
windowActionGroup->addAction(spreadsheet->windowMenuAction());
subWindow->show();
}
Spreadsheet *MainWindowImpl::activeSpreadsheet() // added 11/2/09 for MDI
{
QMdiSubWindow *subWindow = mdiArea->activeSubWindow();
if (subWindow)
return qobject_cast<Spreadsheet *>(subWindow->widget());
return 0;
}
void MainWindowImpl::createActionGroup()
{
windowActionGroup = new QActionGroup(this);
}
/*
void MainWindowImpl::createContextMenu()
{
activeSpreadsheet()->addAction(action_Cut_Ctrl_X);//changed from spreadsheet() for MDI
activeSpreadsheet()->addAction(actionC_opy_Ctrl_C);//changed from spreadsheet() for MDI
activeSpreadsheet()->addAction(action_Paste_Ctrl_V);//changed from spreadsheet() for MDI
activeSpreadsheet()->setContextMenuPolicy(Qt::ActionsContextMenu);//changed from spreadsheet() for MDI
}
*/
void MainWindowImpl::goToCell()
{
GoToCellDialog dialog(this);
if (dialog.exec())
{
QString str = dialog.lineEdit->text().toUpper();
activeSpreadsheet()->setCurrentCell(str.mid(1).toInt() - 1, //changed from spreadsheet() for MDI
str[0].unicode() - 'A');
}
}
void MainWindowImpl::printPreview()
{
#ifndef QT_NO_PRINTER
QPrinter printer(QPrinter::ScreenResolution); // set printer to screen resolution
QPrintPreviewDialog dlg(&printer);
PrintView view;
view.setModel(activeSpreadsheet()->model()); //changed from spreadsheet() for MDI
connect(&dlg, SIGNAL(paintRequested(QPrinter *)),
&view, SLOT(print(QPrinter *)));
dlg.exec();
#endif
}
void MainWindowImpl::copy()
{
if (activeSpreadsheet())
activeSpreadsheet()->copy();
}
void MainWindowImpl::paste()
{
if (activeSpreadsheet())
activeSpreadsheet()->paste();
}
void MainWindowImpl::cut()
{
if (activeSpreadsheet())
activeSpreadsheet()->cut();
}
void MainWindowImpl::selectAll()
{
if (activeSpreadsheet())
activeSpreadsheet()->selectAll();
}
void MainWindowImpl::selectCurrentColumn()
{
if (activeSpreadsheet())
activeSpreadsheet()->selectCurrentColumn();
}
void MainWindowImpl::selectCurrentRow()
{
if (activeSpreadsheet())
activeSpreadsheet()->selectCurrentRow();
}
To copy to clipboard, switch view to plain text mode
Bookmarks