00001 #include <qfiledialog.h>
00002 #include <qlabel.h>
00003 #include "spreadsheet.h"
00004 #include "iis.h"
00005 #include "version.h"
00006 #ifdef GELSIGNAL
00007 #include "about-gelsignal.h"
00008 #endif
00009
00010 class ApplicationWindow;
00011 QApplication *mainapp;
00012 ApplicationWindow * mainwindow;
00013
00014 ApplicationWindow::ApplicationWindow()
00015 {
00016 workspace = new QWorkspace(this);
00017 setCentralWidget(workspace);
00018 QPopupMenu * files = new QPopupMenu(this);
00019 QAction * action = new QAction( "New File", QIconSet(), "&New", CTRL+Key_N, this, "new" );
00020 action->addTo(files);
00021 connect(action,SIGNAL(activated()),this,SLOT(newWindow()));
00022
00023 action = new QAction( "Save", QIconSet(), "&Save", CTRL+Key_S, this, "save" );
00024 action->addTo(files);
00025 connect(action,SIGNAL(activated()),this,SLOT(saveFile()));
00026
00027 action = new QAction( "Open", QIconSet(), "&Open...", CTRL+Key_O, this, "open" );
00028 action->addTo(files);
00029 connect(action,SIGNAL(activated()),this,SLOT(openFile()));
00030
00031 action = new QAction( "Save as...", QIconSet(), "&Save as...", CTRL+Key_N, this, "saveas" );
00032 action->addTo(files);
00033 connect(action,SIGNAL(activated()),this,SLOT(saveFileAs()));
00034
00035
00036 QPopupMenu * spreadsheet = new QPopupMenu(this);
00037 action = new QAction( "User input", QIconSet(), "&Start user input", QKeySequence(), this, "userinput");
00038 action->addTo(spreadsheet);
00039 connect(action,SIGNAL(activated()),this,SLOT(allowUserInput()));
00040
00041 action = new QAction( "Insert Rows", QIconSet(), "&Insert Rows", QKeySequence(), this, "insertrows");
00042 action->addTo(spreadsheet);
00043 connect(action,SIGNAL(activated()),this,SLOT(insertRows()));
00044
00045 action = new QAction( "Insert Cols", QIconSet(), "&Insert Cols", QKeySequence(), this, "insertcols");
00046 action->addTo(spreadsheet);
00047 connect(action,SIGNAL(activated()),this,SLOT(insertCols()));
00048
00049 action = new QAction( "Copy Right", QIconSet(), "&Copy Right", QKeySequence(), this, "copyright");
00050 action->addTo(spreadsheet);
00051 connect(action,SIGNAL(activated()),this,SLOT(copyRight()));
00052
00053 action = new QAction( "Copy Down", QIconSet(), "&Copy Down", QKeySequence(), this, "copyright");
00054 action->addTo(spreadsheet);
00055 connect(action,SIGNAL(activated()),this,SLOT(copyDown()));
00056
00057 QPopupMenu * help = new QPopupMenu(this);
00058 action = new QAction("About", QIconSet(), "&About", QKeySequence(), this, "about");
00059 action->addTo(help);
00060 connect(action,SIGNAL(activated()),this,SLOT(doAbout()));
00061
00062 menuBar() -> insertItem("&Files",files);
00063 menuBar() -> insertItem("&Spreadsheet",spreadsheet);
00064 menuBar() -> insertItem("&Help",help);
00065 }
00066
00067 void ApplicationWindow::newWindow()
00068 {
00069 SpreadSheet * w = new SpreadSheet( workspace, 0, WDestructiveClose );
00070 if ( workspace->windowList().isEmpty() )
00071 w->showMaximized();
00072 else
00073 w->show();
00074 }
00075
00076 void ApplicationWindow::recalcNow()
00077 {
00078 SpreadSheet * w = (SpreadSheet*)workspace->activeWindow();
00079 if (!w) return;
00080 w->recalcSelection();
00081 }
00082
00083 void ApplicationWindow::allowUserInput()
00084 {
00085 SpreadSheet * w = (SpreadSheet*)workspace->activeWindow();
00086 if (!w) return;
00087 w->allowUserInput();
00088 }
00089
00090 void ApplicationWindow::insertRows()
00091 {
00092 SpreadSheet * w = (SpreadSheet*)workspace->activeWindow();
00093 if (!w) return;
00094 w->insertRows();
00095 }
00096
00097 void ApplicationWindow::insertCols()
00098 {
00099 SpreadSheet * w = (SpreadSheet*)workspace->activeWindow();
00100 if (!w) return;
00101 w->insertCols();
00102 }
00103
00104 void ApplicationWindow::copyRight()
00105 {
00106 SpreadSheet * w = (SpreadSheet*)workspace->activeWindow();
00107 if (!w) return;
00108 w->copyRight();
00109 }
00110
00111 void ApplicationWindow::copyDown()
00112 {
00113 SpreadSheet * w = (SpreadSheet*)workspace->activeWindow();
00114 if (!w) return;
00115 w->copyDown();
00116 }
00117
00118 void ApplicationWindow::saveFile()
00119 {
00120 SpreadSheet * w = (SpreadSheet*)workspace->activeWindow();
00121 if (!w) return;
00122 if (w->hasFilename())
00123 w->saveFile();
00124 else
00125 saveFileAs();
00126 }
00127
00128 void ApplicationWindow::saveFileAs()
00129 {
00130 SpreadSheet * w = (SpreadSheet*)workspace->activeWindow();
00131 if (!w) return;
00132 QString s = QFileDialog::getSaveFileName(".",
00133 "Images (*"IIS_EXTENSION")",
00134 NULL,
00135 "Select filename",
00136 "Choose a file");
00137 if(s.isEmpty()) return;
00138 w->setFilename(s);
00139 w->saveFile();
00140 }
00141
00142 void ApplicationWindow::openFile()
00143 {
00144 QString s = QFileDialog::getOpenFileName(".",
00145 "Images (*"IIS_EXTENSION")",
00146 NULL,
00147 "Select filename",
00148 "Choose a file");
00149 if(s.isEmpty()) return;
00150
00151 SpreadSheet * w = new SpreadSheet( s, workspace, 0, WDestructiveClose );
00152 if ( workspace->windowList().isEmpty() )
00153 w->showMaximized();
00154 else
00155 w->show();
00156 }
00157
00158 void ApplicationWindow::doAbout()
00159 {
00160 #ifdef GELSIGNAL
00161 AboutGelSignal about(this);
00162 about.versionlabel->setText(QString("v" IIS_VERSION));
00163 about.exec();
00164 #endif
00165 }
00166
00167 int main(int argc, char* argv[])
00168 {
00169 mainapp=new QApplication(argc,argv);
00170 mainwindow = new ApplicationWindow();
00171 mainapp->setMainWidget(mainwindow);
00172 mainwindow->show();
00173 return mainapp->exec();
00174 }
00175