1 /***************************************************************************
4 begin : Sun May 27 22:13:58 CEST 2001
5 copyright : (C) 2001 by Michael Andreen
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
18 #include "../config.h"
22 #include "filesave.xpm"
23 #include "fileopen.xpm"
24 #include "filenew.xpm"
28 setCaption(tr("Bc " VERSION));
30 ///////////////////////////////////////////////////////////////////
31 // call inits to invoke all other construction parts
40 viewToolBar->setOn(true);
41 viewStatusBar->setOn(true);
48 /** initializes all QActions of the application */
49 void BcApp::initActions(){
51 QPixmap openIcon, saveIcon, newIcon;
52 newIcon = QPixmap(filenew);
53 openIcon = QPixmap(fileopen);
54 saveIcon = QPixmap(filesave);
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()));
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()));
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()));
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()));
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()));
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()));
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()));
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()));
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()));
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()));
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)));
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)));
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()));
124 void BcApp::initMenuBar()
126 ///////////////////////////////////////////////////////////////////
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);
143 ///////////////////////////////////////////////////////////////////
144 // menuBar entry editMenu
145 editMenu=new QPopupMenu();
146 editCut->addTo(editMenu);
147 editCopy->addTo(editMenu);
148 editPaste->addTo(editMenu);
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
159 ///////////////////////////////////////////////////////////////////
160 // menuBar entry helpMenu
161 helpMenu=new QPopupMenu();
162 helpAboutApp->addTo(helpMenu);
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);
174 void BcApp::initToolBar()
176 ///////////////////////////////////////////////////////////////////
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);
187 void BcApp::initStatusBar()
189 ///////////////////////////////////////////////////////////////////
191 statusBar()->message(tr("Ready."), 2000);
194 void BcApp::initDoc()
199 void BcApp::initView()
201 ////////////////////////////////////////////////////////////////////
202 // set the main widget here
203 view=new BcView(this, doc);
204 setCentralWidget(view);
207 bool BcApp::queryExit()
209 int exit=QMessageBox::information(this, tr("Quit..."),
210 tr("Do your really want to quit?"),
211 QMessageBox::Ok, QMessageBox::Cancel);
225 /////////////////////////////////////////////////////////////////////
226 // SLOT IMPLEMENTATION
227 /////////////////////////////////////////////////////////////////////
230 void BcApp::slotFileNew()
232 statusBar()->message(tr("Creating new file..."));
234 statusBar()->message(tr("Ready."));
237 void BcApp::slotFileOpen()
239 statusBar()->message(tr("Opening file..."));
241 QString fileName = QFileDialog::getOpenFileName(0,0,this);
242 if (!fileName.isEmpty())
245 setCaption(fileName);
246 QString message=tr("Loaded document: ")+fileName;
247 statusBar()->message(message, 2000);
251 statusBar()->message(tr("Opening aborted"), 2000);
256 void BcApp::slotFileSave()
258 statusBar()->message(tr("Saving file..."));
260 statusBar()->message(tr("Ready."));
263 void BcApp::slotFileSaveAs()
265 statusBar()->message(tr("Saving file under new filename..."));
266 QString fn = QFileDialog::getSaveFileName(0, 0, this);
273 statusBar()->message(tr("Saving aborted"), 2000);
276 statusBar()->message(tr("Ready."));
279 void BcApp::slotFileClose()
281 statusBar()->message(tr("Closing file..."));
283 statusBar()->message(tr("Ready."));
286 void BcApp::slotFilePrint()
288 statusBar()->message(tr("Printing..."));
290 if (printer.setup(this))
293 painter.begin(&printer);
295 ///////////////////////////////////////////////////////////////////
296 // TODO: Define printing by using the QPainter methods here
301 statusBar()->message(tr("Ready."));
304 void BcApp::slotFileQuit()
306 statusBar()->message(tr("Exiting application..."));
307 ///////////////////////////////////////////////////////////////////
308 // exits the Application
309 if(doc->isModified())
325 statusBar()->message(tr("Ready."));
328 void BcApp::slotEditCut()
330 statusBar()->message(tr("Cutting selection..."));
332 statusBar()->message(tr("Ready."));
335 void BcApp::slotEditCopy()
337 statusBar()->message(tr("Copying selection to clipboard..."));
339 statusBar()->message(tr("Ready."));
342 void BcApp::slotEditPaste()
344 statusBar()->message(tr("Inserting clipboard contents..."));
346 statusBar()->message(tr("Ready."));
350 void BcApp::slotViewToolBar(bool toggle)
352 statusBar()->message(tr("Toggle toolbar..."));
353 ///////////////////////////////////////////////////////////////////
354 // turn Toolbar on or off
365 statusBar()->message(tr("Ready."));
368 void BcApp::slotViewStatusBar(bool toggle)
370 statusBar()->message(tr("Toggle statusbar..."));
371 ///////////////////////////////////////////////////////////////////
372 //turn Statusbar on or off
383 statusBar()->message(tr("Ready."));
386 void BcApp::slotHelpAbout()
388 QMessageBox::about(this,tr("About..."),
389 tr("Bc\nVersion " VERSION "\n(c) 2001 by Michael Andreen") );