]> ruin.nu Git - eonsl.git/blob - eonsl/eonsl.cpp
The makefile linked wrong, just some cleanup..
[eonsl.git] / eonsl / eonsl.cpp
1 /***************************************************************************
2                           eonsl.cpp  -  description
3                              -------------------
4     begin     : mån okt 23 17:11:28 CEST 2000
5     copyright : (C) 2000 by Michael Andreen
6     email     : whale@linux.nu
7     changes   :
8  ***************************************************************************/
9
10 /***************************************************************************
11  *                                                                         *
12  *   This program is free software; you can redistribute it and/or modify  *
13  *   it under the terms of the GNU General Public License as published by  *
14  *   the Free Software Foundation; either version 2 of the License, or     *
15  *   (at your option) any later version.                                   *
16  *                                                                         *
17  ***************************************************************************/
18
19 #include "eonsl.h"
20 #include "filesave.xpm"
21 #include "fileopen.xpm"
22 #include "filenew.xpm"
23
24 EonSL::EonSL()
25 {
26   setCaption("EonSL " VERSION);
27   
28   ///////////////////////////////////////////////////////////////////
29   // call inits to invoke all other construction parts
30   initMenuBar();
31   initToolBar();
32   initStatusBar();
33
34   initDoc();
35   initView();  
36 }
37
38 EonSL::~EonSL()
39 {
40 }
41
42 void EonSL::initMenuBar()
43 {
44   ///////////////////////////////////////////////////////////////////
45   // MENUBAR
46
47   ///////////////////////////////////////////////////////////////////
48   // menuBar entry fileMenu
49
50   fileMenu=new QPopupMenu();
51   fileMenu->insertItem("&New", this, SLOT(slotFileNew()), CTRL+Key_N, ID_FILE_NEW);
52   fileMenu->insertItem("&Open...", this, SLOT(slotFileOpen()), CTRL+Key_O, ID_FILE_OPEN);
53   fileMenu->insertSeparator();
54   fileMenu->insertItem("&Save", this, SLOT(slotFileSave()), CTRL+Key_S, ID_FILE_SAVE);
55   fileMenu->insertItem("Save &as...", this, SLOT(slotFileSaveAs()), 0, ID_FILE_SAVE_AS);
56   fileMenu->insertItem("&Close", this, SLOT(slotFileClose()), CTRL+Key_W, ID_FILE_CLOSE);
57   fileMenu->insertSeparator();
58   fileMenu->insertItem("&Print", this, SLOT(slotFilePrint()), CTRL+Key_P, ID_FILE_PRINT);
59   fileMenu->insertSeparator();
60   fileMenu->insertItem("E&xit", this, SLOT(slotFileQuit()), CTRL+Key_Q, ID_FILE_QUIT);
61
62   ///////////////////////////////////////////////////////////////////
63   // menuBar entry editMenu
64   editMenu=new QPopupMenu();
65   editMenu->insertItem("Cu&t", this, SLOT(slotEditCut()), CTRL+Key_X, ID_EDIT_CUT);
66   editMenu->insertItem("&Copy", this, SLOT(slotEditCopy()), CTRL+Key_C, ID_EDIT_COPY);
67   editMenu->insertItem("&Paste", this, SLOT(slotEditPaste()), CTRL+Key_V, ID_EDIT_PASTE);
68  
69   
70   ///////////////////////////////////////////////////////////////////
71   // menuBar entry viewMenu
72   viewMenu=new QPopupMenu();
73   viewMenu->setCheckable(true);
74   viewMenu->insertItem("Tool&bar", this, SLOT(slotViewToolBar()), 0, ID_VIEW_TOOLBAR);
75   viewMenu->insertItem("&Statusbar", this, SLOT(slotViewStatusBar()), 0, ID_VIEW_STATUSBAR);
76
77   viewMenu->setItemChecked(ID_VIEW_TOOLBAR, true);
78   viewMenu->setItemChecked(ID_VIEW_STATUSBAR, true);
79
80   ///////////////////////////////////////////////////////////////////
81   // EDIT YOUR APPLICATION SPECIFIC MENUENTRIES HERE
82   
83   ///////////////////////////////////////////////////////////////////
84   // menuBar entry helpMenu
85   helpMenu=new QPopupMenu();
86   helpMenu->insertItem("About...", this, SLOT(slotHelpAbout()), 0, ID_HELP_ABOUT);
87
88
89   ///////////////////////////////////////////////////////////////////
90   // MENUBAR CONFIGURATION
91   // set menuBar() the current menuBar 
92
93   menuBar()->insertItem("&File", fileMenu);
94   menuBar()->insertItem("&Edit", editMenu);
95   menuBar()->insertItem("&View", viewMenu);
96   menuBar()->insertSeparator();
97   menuBar()->insertItem("&Help", helpMenu);
98   
99   ///////////////////////////////////////////////////////////////////
100   // CONNECT THE SUBMENU SLOTS WITH SIGNALS
101
102   connect(fileMenu, SIGNAL(highlighted(int)), SLOT(statusCallback(int)));
103   connect(editMenu, SIGNAL(highlighted(int)), SLOT(statusCallback(int)));
104   connect(viewMenu, SIGNAL(highlighted(int)), SLOT(statusCallback(int)));
105   connect(helpMenu, SIGNAL(highlighted(int)), SLOT(statusCallback(int)));
106   
107 }
108
109 void EonSL::initToolBar()
110 {
111   ///////////////////////////////////////////////////////////////////
112   // TOOLBAR
113   QPixmap openIcon, saveIcon, newIcon;
114
115   fileToolbar = new QToolBar(this, "file operations");
116  
117   newIcon = QPixmap(filenew);
118   QToolButton *fileNew = new QToolButton(newIcon, "New File", 0, this,
119                                          SLOT(slotFileNew()), fileToolbar);
120
121   openIcon = QPixmap(fileopen);
122   QToolButton *fileOpen = new QToolButton(openIcon, "Open File", 0, this,
123                                           SLOT(slotFileOpen()), fileToolbar);
124
125   saveIcon = QPixmap(filesave);
126   QToolButton *fileSave = new QToolButton(saveIcon, "Save File", 0, this,
127                                           SLOT(slotFileSave()), fileToolbar);
128   
129   
130   fileToolbar->addSeparator();
131   QWhatsThis::whatsThisButton(fileToolbar);
132   QWhatsThis::add(fileNew,"Click this button to create a new file.\n\n"
133                   "You can also select the New command from the File menu.");
134   QWhatsThis::add(fileOpen,"Click this button to open a new file.\n\n"
135                   "You can also select the Open command from the File menu.");
136   QWhatsThis::add(fileSave,"Click this button to save the file you are "
137                   "editing. You will be prompted for a file name.\n\n"
138                   "You can also select the Save command from the File menu.");
139   
140 }
141
142 void EonSL::initStatusBar()
143 {
144   ///////////////////////////////////////////////////////////////////
145   //STATUSBAR
146   statusBar()->message(IDS_STATUS_DEFAULT, 2000);
147 }
148
149 void EonSL::initDoc()
150 {
151    doc=new EonSLDoc();
152 }
153
154 void EonSL::initView()
155
156   ////////////////////////////////////////////////////////////////////
157   // set the main widget here
158   view=new EonSLView(this, doc);
159   setCentralWidget(view);
160 }
161
162 bool EonSL::queryExit()
163 {
164   int exit=QMessageBox::information(this, "Quit...",
165                                     "Do your really want to quit?",
166                                     QMessageBox::Ok, QMessageBox::Cancel);
167
168   if (exit==1)
169   {
170
171   }
172   else
173   {
174
175   };
176
177   return (exit==1);
178 }
179
180 /////////////////////////////////////////////////////////////////////
181 // SLOT IMPLEMENTATION
182 /////////////////////////////////////////////////////////////////////
183
184
185 void EonSL::slotFileNew()
186 {
187   statusBar()->message("Creating new file...");
188   doc->newDoc();
189   statusBar()->message(IDS_STATUS_DEFAULT);
190 }
191
192 void EonSL::slotFileOpen()
193 {
194   statusBar()->message("Opening file...");
195
196   QString fileName = QFileDialog::getOpenFileName(0,0,this);
197   if (!fileName.isEmpty())
198   {
199     doc->load(fileName);
200     setCaption(fileName);
201     QString message="Loaded document: "+fileName;
202     statusBar()->message(message, 2000);
203   }
204   else
205   {
206     statusBar()->message("Opening aborted", 2000);
207   }
208 }
209
210
211 void EonSL::slotFileSave()
212 {
213   statusBar()->message("Saving file...");
214   doc->save();
215   statusBar()->message(IDS_STATUS_DEFAULT);
216 }
217
218 void EonSL::slotFileSaveAs()
219 {
220   statusBar()->message("Saving file under new filename...");
221   QString fn = QFileDialog::getSaveFileName(0, 0, this);
222   if (!fn.isEmpty())
223   {
224     doc->saveAs(fn);
225   }
226   else
227   {
228     statusBar()->message("Saving aborted", 2000);
229   }
230
231   statusBar()->message(IDS_STATUS_DEFAULT);
232 }
233
234 void EonSL::slotFileClose()
235 {
236   statusBar()->message("Closing file...");
237
238   statusBar()->message(IDS_STATUS_DEFAULT);
239 }
240
241 void EonSL::slotFilePrint()
242 {
243   statusBar()->message("Printing...");
244   QPrinter printer;
245   if (printer.setup(this))
246   {
247     QPainter painter;
248     painter.begin(&printer);
249
250     ///////////////////////////////////////////////////////////////////
251     // TODO: Define printing by using the QPainter methods here
252
253     painter.end();
254   };
255
256   statusBar()->message(IDS_STATUS_DEFAULT);
257 }
258
259 void EonSL::slotFileQuit()
260
261   statusBar()->message("Exiting application...");
262   ///////////////////////////////////////////////////////////////////
263   // exits the Application
264   if(doc->isModified())
265   {
266     if(queryExit())
267     {
268       qApp->quit();
269     }
270     else
271     {
272
273     };
274   }
275   else
276   {
277     qApp->quit();
278   };
279
280   statusBar()->message(IDS_STATUS_DEFAULT);
281 }
282
283 void EonSL::slotEditCut()
284 {
285   statusBar()->message("Cutting selection...");
286
287   statusBar()->message(IDS_STATUS_DEFAULT);
288 }
289
290 void EonSL::slotEditCopy()
291 {
292   statusBar()->message("Copying selection to clipboard...");
293   
294   statusBar()->message(IDS_STATUS_DEFAULT);
295 }
296
297 void EonSL::slotEditPaste()
298 {
299   statusBar()->message("Inserting clipboard contents...");
300   
301   statusBar()->message(IDS_STATUS_DEFAULT);
302 }
303
304
305 void EonSL::slotViewToolBar()
306 {
307   statusBar()->message("Toggle toolbar...");
308   ///////////////////////////////////////////////////////////////////
309   // turn Toolbar on or off
310   
311   if (fileToolbar->isVisible())
312   {
313     fileToolbar->hide();
314     viewMenu->setItemChecked(ID_VIEW_TOOLBAR, false);
315   } 
316   else
317   {
318     fileToolbar->show();
319     viewMenu->setItemChecked(ID_VIEW_TOOLBAR, true);
320   };
321
322   statusBar()->message(IDS_STATUS_DEFAULT);
323 }
324
325 void EonSL::slotViewStatusBar()
326 {
327   statusBar()->message("Toggle statusbar...");
328   ///////////////////////////////////////////////////////////////////
329   //turn Statusbar on or off
330   
331   if (statusBar()->isVisible())
332   {
333     statusBar()->hide();
334     viewMenu->setItemChecked(ID_VIEW_STATUSBAR, false);
335   }
336   else
337   {
338     statusBar()->show();
339     viewMenu->setItemChecked(ID_VIEW_STATUSBAR, true);
340   }
341   
342   statusBar()->message(IDS_STATUS_DEFAULT);
343 }
344
345 void EonSL::slotHelpAbout()
346 {
347   QMessageBox::about(this,"About...", IDS_APP_ABOUT );
348 }
349
350 void EonSL::slotStatusHelpMsg(const QString &text)
351 {
352   ///////////////////////////////////////////////////////////////////
353   // change status message of whole statusbar temporary (text, msec)
354   statusBar()->message(text, 2000);
355 }
356
357 void EonSL::statusCallback(int id_)
358 {
359   switch (id_)
360   {
361     case ID_FILE_NEW:
362          slotStatusHelpMsg("Creates a new document");
363          break;
364
365     case ID_FILE_OPEN:
366          slotStatusHelpMsg("Opens an existing document");
367          break;
368
369     case ID_FILE_SAVE:
370          slotStatusHelpMsg("Saves the actual document");
371          break;
372
373     case ID_FILE_SAVE_AS:
374          slotStatusHelpMsg("Saves the actual document as...");
375          break;
376
377     case ID_FILE_CLOSE:
378          slotStatusHelpMsg("Closes the actual document");
379          break;
380
381     case ID_FILE_PRINT:
382          slotStatusHelpMsg("Prints out the actual document");
383          break;
384
385     case ID_FILE_QUIT:
386          slotStatusHelpMsg("Quits the application");
387          break;
388
389     case ID_EDIT_CUT:
390          slotStatusHelpMsg("Cuts the selected section and puts it to the clipboard");
391          break;
392
393     case ID_EDIT_COPY:
394          slotStatusHelpMsg("Copies the selected section to the clipboard");
395          break;
396
397     case ID_EDIT_PASTE:
398          slotStatusHelpMsg("Pastes the clipboard contents to actual position");
399          break;
400
401     case ID_EDIT_SELECT_ALL:
402          slotStatusHelpMsg("Selects the whole document contents");
403          break;
404
405     case ID_VIEW_TOOLBAR:
406          slotStatusHelpMsg("Enables/disables the toolbar");
407          break;
408
409     case ID_VIEW_STATUSBAR:
410          slotStatusHelpMsg("Enables/disables the statusbar");
411          break;
412
413     case ID_HELP_ABOUT:
414          slotStatusHelpMsg("Shows an aboutbox");
415          break;
416   }
417 }
418