]> ruin.nu Git - hbs.git/blob - bs/bs.cpp
1422dcd3ed48e792b46d2bcfce811d891aa087c0
[hbs.git] / bs / bs.cpp
1 /***************************************************************************
2                           bc.cpp  -  description
3                              -------------------
4     begin                : Sun May 27 22:13:58 CEST 2001
5     copyright            : (C) 2001 by Michael Andreen
6     email                : whale@linux.nu
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #include "../config.h"
19
20 #include <qaccel.h>
21 #include "bc.h"
22 #include "filesave.xpm"
23 #include "fileopen.xpm"
24 #include "filenew.xpm"
25
26 BcApp::BcApp()
27 {
28   setCaption(tr("Bc " VERSION));
29
30   ///////////////////////////////////////////////////////////////////
31   // call inits to invoke all other construction parts
32   initActions();
33   initMenuBar();
34   initToolBar();
35   initStatusBar();
36
37   initDoc();
38   initView();
39
40   viewToolBar->setOn(true);
41   viewStatusBar->setOn(true);
42 }
43
44 BcApp::~BcApp()
45 {
46 }
47
48 /** initializes all QActions of the application */
49 void BcApp::initActions(){
50
51   QPixmap openIcon, saveIcon, newIcon;
52   newIcon = QPixmap(filenew);
53   openIcon = QPixmap(fileopen);
54   saveIcon = QPixmap(filesave);
55
56
57   fileNew = new QAction(tr("New File"), newIcon, tr("&New"), QAccel::stringToKey(tr("Ctrl+N")), this);
58   fileNew->setStatusTip(tr("Creates a new document"));
59   fileNew->setWhatsThis(tr("New File\n\nCreates a new document"));
60   connect(fileNew, SIGNAL(activated()), this, SLOT(slotFileNew()));
61
62   fileOpen = new QAction(tr("Open File"), openIcon, tr("&Open..."), 0, this);
63   fileOpen->setStatusTip(tr("Opens an existing document"));
64   fileOpen->setWhatsThis(tr("Open File\n\nOpens an existing document"));
65   connect(fileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen()));
66
67   fileSave = new QAction(tr("Save File"), saveIcon, tr("&Save"), QAccel::stringToKey(tr("Ctrl+S")), this);
68   fileSave->setStatusTip(tr("Saves the actual document"));
69   fileSave->setWhatsThis(tr("Save File.\n\nSaves the actual document"));
70   connect(fileSave, SIGNAL(activated()), this, SLOT(slotFileSave()));
71
72   fileSaveAs = new QAction(tr("Save File As"), tr("Save &as..."), 0, this);
73   fileSaveAs->setStatusTip(tr("Saves the actual document under a new filename"));
74   fileSaveAs->setWhatsThis(tr("Save As\n\nSaves the actual document under a new filename"));
75   connect(fileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSave()));
76
77   fileClose = new QAction(tr("Close File"), tr("&Close"), QAccel::stringToKey(tr("Ctrl+W")), this);
78   fileClose->setStatusTip(tr("Closes the actual document"));
79   fileClose->setWhatsThis(tr("Close File\n\nCloses the actual document"));
80   connect(fileClose, SIGNAL(activated()), this, SLOT(slotFileClose()));
81
82   filePrint = new QAction(tr("Print File"), tr("&Print"), QAccel::stringToKey(tr("Ctrl+P")), this);
83   filePrint->setStatusTip(tr("Prints out the actual document"));
84   filePrint->setWhatsThis(tr("Print File\n\nPrints out the actual document"));
85   connect(filePrint, SIGNAL(activated()), this, SLOT(slotFilePrint()));
86
87   fileQuit = new QAction(tr("Exit"), tr("E&xit"), QAccel::stringToKey(tr("Ctrl+Q")), this);
88   fileQuit->setStatusTip(tr("Quits the application"));
89   fileQuit->setWhatsThis(tr("Exit\n\nQuits the application"));
90   connect(fileQuit, SIGNAL(activated()), this, SLOT(slotFileQuit()));
91
92   editCut = new QAction(tr("Cut"), tr("Cu&t"), QAccel::stringToKey(tr("Ctrl+X")), this);
93   editCut->setStatusTip(tr("Cuts the selected section and puts it to the clipboard"));
94   editCut->setWhatsThis(tr("Cut\n\nCuts the selected section and puts it to the clipboard"));
95   connect(editCut, SIGNAL(activated()), this, SLOT(slotEditCut()));
96
97   editCopy = new QAction(tr("Copy"), tr("&Copy"), QAccel::stringToKey(tr("Ctrl+C")), this);
98   editCopy->setStatusTip(tr("Copies the selected section to the clipboard"));
99   editCopy->setWhatsThis(tr("Copy\n\nCopies the selected section to the clipboard"));
100   connect(editCopy, SIGNAL(activated()), this, SLOT(slotEditCopy()));
101
102   editPaste = new QAction(tr("Paste"), tr("&Paste"), QAccel::stringToKey(tr("Ctrl+V")), this);
103   editPaste->setStatusTip(tr("Pastes the clipboard contents to actual position"));
104   editPaste->setWhatsThis(tr("Paste\n\nPastes the clipboard contents to actual position"));
105   connect(editPaste, SIGNAL(activated()), this, SLOT(slotEditPaste()));
106
107   viewToolBar = new QAction(tr("Toolbar"), tr("Tool&bar"), 0, this, 0, true);
108   viewToolBar->setStatusTip(tr("Enables/disables the toolbar"));
109   viewToolBar->setWhatsThis(tr("Toolbar\n\nEnables/disables the toolbar"));
110   connect(viewToolBar, SIGNAL(toggled(bool)), this, SLOT(slotViewToolBar(bool)));
111
112   viewStatusBar = new QAction(tr("Statusbar"), tr("&Statusbar"), 0, this, 0, true);
113   viewStatusBar->setStatusTip(tr("Enables/disables the statusbar"));
114   viewStatusBar->setWhatsThis(tr("Statusbar\n\nEnables/disables the statusbar"));
115   connect(viewStatusBar, SIGNAL(toggled(bool)), this, SLOT(slotViewStatusBar(bool)));
116
117   helpAboutApp = new QAction(tr("About"), tr("&About..."), 0, this);
118   helpAboutApp->setStatusTip(tr("About the application"));
119   helpAboutApp->setWhatsThis(tr("About\n\nAbout the application"));
120   connect(helpAboutApp, SIGNAL(activated()), this, SLOT(slotHelpAbout()));
121
122 }
123
124 void BcApp::initMenuBar()
125 {
126   ///////////////////////////////////////////////////////////////////
127   // MENUBAR
128
129   ///////////////////////////////////////////////////////////////////
130   // menuBar entry fileMenu
131   fileMenu=new QPopupMenu();
132   fileNew->addTo(fileMenu);
133   fileOpen->addTo(fileMenu);
134   fileClose->addTo(fileMenu);
135   fileMenu->insertSeparator();
136   fileSave->addTo(fileMenu);
137   fileSaveAs->addTo(fileMenu);
138   fileMenu->insertSeparator();
139   filePrint->addTo(fileMenu);
140   fileMenu->insertSeparator();
141   fileQuit->addTo(fileMenu);
142
143   ///////////////////////////////////////////////////////////////////
144   // menuBar entry editMenu
145   editMenu=new QPopupMenu();
146   editCut->addTo(editMenu);
147   editCopy->addTo(editMenu);
148   editPaste->addTo(editMenu);
149
150   ///////////////////////////////////////////////////////////////////
151   // menuBar entry viewMenu
152   viewMenu=new QPopupMenu();
153   viewMenu->setCheckable(true);
154   viewToolBar->addTo(viewMenu);
155   viewStatusBar->addTo(viewMenu);
156   ///////////////////////////////////////////////////////////////////
157   // EDIT YOUR APPLICATION SPECIFIC MENUENTRIES HERE
158
159   ///////////////////////////////////////////////////////////////////
160   // menuBar entry helpMenu
161   helpMenu=new QPopupMenu();
162   helpAboutApp->addTo(helpMenu);
163
164   ///////////////////////////////////////////////////////////////////
165   // MENUBAR CONFIGURATION
166   menuBar()->insertItem(tr("&File"), fileMenu);
167   menuBar()->insertItem(tr("&Edit"), editMenu);
168   menuBar()->insertItem(tr("&View"), viewMenu);
169   menuBar()->insertSeparator();
170   menuBar()->insertItem(tr("&Help"), helpMenu);
171
172 }
173
174 void BcApp::initToolBar()
175 {
176   ///////////////////////////////////////////////////////////////////
177   // TOOLBAR
178   fileToolbar = new QToolBar(this, "file operations");
179   fileNew->addTo(fileToolbar);
180   fileOpen->addTo(fileToolbar);
181   fileSave->addTo(fileToolbar);
182   fileToolbar->addSeparator();
183   QWhatsThis::whatsThisButton(fileToolbar);
184
185 }
186
187 void BcApp::initStatusBar()
188 {
189   ///////////////////////////////////////////////////////////////////
190   //STATUSBAR
191   statusBar()->message(tr("Ready."), 2000);
192 }
193
194 void BcApp::initDoc()
195 {
196    doc=new BcDoc();
197 }
198
199 void BcApp::initView()
200 {
201   ////////////////////////////////////////////////////////////////////
202   // set the main widget here
203   view=new BcView(this, doc);
204   setCentralWidget(view);
205 }
206
207 bool BcApp::queryExit()
208 {
209   int exit=QMessageBox::information(this, tr("Quit..."),
210                                     tr("Do your really want to quit?"),
211                                     QMessageBox::Ok, QMessageBox::Cancel);
212
213   if (exit==1)
214   {
215
216   }
217   else
218   {
219
220   };
221
222   return (exit==1);
223 }
224
225 /////////////////////////////////////////////////////////////////////
226 // SLOT IMPLEMENTATION
227 /////////////////////////////////////////////////////////////////////
228
229
230 void BcApp::slotFileNew()
231 {
232   statusBar()->message(tr("Creating new file..."));
233   doc->newDoc();
234   statusBar()->message(tr("Ready."));
235 }
236
237 void BcApp::slotFileOpen()
238 {
239   statusBar()->message(tr("Opening file..."));
240
241   QString fileName = QFileDialog::getOpenFileName(0,0,this);
242   if (!fileName.isEmpty())
243   {
244     doc->load(fileName);
245     setCaption(fileName);
246     QString message=tr("Loaded document: ")+fileName;
247     statusBar()->message(message, 2000);
248   }
249   else
250   {
251     statusBar()->message(tr("Opening aborted"), 2000);
252   }
253 }
254
255
256 void BcApp::slotFileSave()
257 {
258   statusBar()->message(tr("Saving file..."));
259   doc->save();
260   statusBar()->message(tr("Ready."));
261 }
262
263 void BcApp::slotFileSaveAs()
264 {
265   statusBar()->message(tr("Saving file under new filename..."));
266   QString fn = QFileDialog::getSaveFileName(0, 0, this);
267   if (!fn.isEmpty())
268   {
269     doc->saveAs(fn);
270   }
271   else
272   {
273     statusBar()->message(tr("Saving aborted"), 2000);
274   }
275
276   statusBar()->message(tr("Ready."));
277 }
278
279 void BcApp::slotFileClose()
280 {
281   statusBar()->message(tr("Closing file..."));
282
283   statusBar()->message(tr("Ready."));
284 }
285
286 void BcApp::slotFilePrint()
287 {
288   statusBar()->message(tr("Printing..."));
289   QPrinter printer;
290   if (printer.setup(this))
291   {
292     QPainter painter;
293     painter.begin(&printer);
294
295     ///////////////////////////////////////////////////////////////////
296     // TODO: Define printing by using the QPainter methods here
297
298     painter.end();
299   };
300
301   statusBar()->message(tr("Ready."));
302 }
303
304 void BcApp::slotFileQuit()
305 {
306   statusBar()->message(tr("Exiting application..."));
307   ///////////////////////////////////////////////////////////////////
308   // exits the Application
309   if(doc->isModified())
310   {
311     if(queryExit())
312     {
313       qApp->quit();
314     }
315     else
316     {
317
318     };
319   }
320   else
321   {
322     qApp->quit();
323   };
324
325   statusBar()->message(tr("Ready."));
326 }
327
328 void BcApp::slotEditCut()
329 {
330   statusBar()->message(tr("Cutting selection..."));
331
332   statusBar()->message(tr("Ready."));
333 }
334
335 void BcApp::slotEditCopy()
336 {
337   statusBar()->message(tr("Copying selection to clipboard..."));
338
339   statusBar()->message(tr("Ready."));
340 }
341
342 void BcApp::slotEditPaste()
343 {
344   statusBar()->message(tr("Inserting clipboard contents..."));
345
346   statusBar()->message(tr("Ready."));
347 }
348
349
350 void BcApp::slotViewToolBar(bool toggle)
351 {
352   statusBar()->message(tr("Toggle toolbar..."));
353   ///////////////////////////////////////////////////////////////////
354   // turn Toolbar on or off
355
356   if (toggle== false)
357   {
358     fileToolbar->hide();
359   }
360   else
361   {
362     fileToolbar->show();
363   };
364
365   statusBar()->message(tr("Ready."));
366 }
367
368 void BcApp::slotViewStatusBar(bool toggle)
369 {
370   statusBar()->message(tr("Toggle statusbar..."));
371   ///////////////////////////////////////////////////////////////////
372   //turn Statusbar on or off
373
374   if (toggle == false)
375   {
376     statusBar()->hide();
377   }
378   else
379   {
380     statusBar()->show();
381   }
382
383   statusBar()->message(tr("Ready."));
384 }
385
386 void BcApp::slotHelpAbout()
387 {
388   QMessageBox::about(this,tr("About..."),
389                       tr("Bc\nVersion " VERSION "\n(c) 2001 by Michael Andreen") );
390 }
391