1 /***************************************************************************
2 eonsl.cpp - description
4 begin : mån okt 23 17:11:28 CEST 2000
5 copyright : (C) 2000 by Michael Andreen
8 ***************************************************************************/
10 /***************************************************************************
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. *
17 ***************************************************************************/
20 #include "filesave.xpm"
21 #include "fileopen.xpm"
22 #include "filenew.xpm"
26 setCaption("EonSL " VERSION);
28 ///////////////////////////////////////////////////////////////////
29 // call inits to invoke all other construction parts
42 void EonSL::initMenuBar()
44 ///////////////////////////////////////////////////////////////////
47 ///////////////////////////////////////////////////////////////////
48 // menuBar entry fileMenu
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);
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);
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);
77 viewMenu->setItemChecked(ID_VIEW_TOOLBAR, true);
78 viewMenu->setItemChecked(ID_VIEW_STATUSBAR, true);
80 ///////////////////////////////////////////////////////////////////
81 // EDIT YOUR APPLICATION SPECIFIC MENUENTRIES HERE
83 ///////////////////////////////////////////////////////////////////
84 // menuBar entry helpMenu
85 helpMenu=new QPopupMenu();
86 helpMenu->insertItem("About...", this, SLOT(slotHelpAbout()), 0, ID_HELP_ABOUT);
89 ///////////////////////////////////////////////////////////////////
90 // MENUBAR CONFIGURATION
91 // set menuBar() the current menuBar
93 menuBar()->insertItem("&File", fileMenu);
94 menuBar()->insertItem("&Edit", editMenu);
95 menuBar()->insertItem("&View", viewMenu);
96 menuBar()->insertSeparator();
97 menuBar()->insertItem("&Help", helpMenu);
99 ///////////////////////////////////////////////////////////////////
100 // CONNECT THE SUBMENU SLOTS WITH SIGNALS
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)));
109 void EonSL::initToolBar()
111 ///////////////////////////////////////////////////////////////////
113 QPixmap openIcon, saveIcon, newIcon;
115 fileToolbar = new QToolBar(this, "file operations");
117 newIcon = QPixmap(filenew);
118 QToolButton *fileNew = new QToolButton(newIcon, "New File", 0, this,
119 SLOT(slotFileNew()), fileToolbar);
121 openIcon = QPixmap(fileopen);
122 QToolButton *fileOpen = new QToolButton(openIcon, "Open File", 0, this,
123 SLOT(slotFileOpen()), fileToolbar);
125 saveIcon = QPixmap(filesave);
126 QToolButton *fileSave = new QToolButton(saveIcon, "Save File", 0, this,
127 SLOT(slotFileSave()), fileToolbar);
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.");
142 void EonSL::initStatusBar()
144 ///////////////////////////////////////////////////////////////////
146 statusBar()->message(IDS_STATUS_DEFAULT, 2000);
149 void EonSL::initDoc()
154 void EonSL::initView()
156 ////////////////////////////////////////////////////////////////////
157 // set the main widget here
158 view=new EonSLView(this, doc);
159 setCentralWidget(view);
162 bool EonSL::queryExit()
164 int exit=QMessageBox::information(this, "Quit...",
165 "Do your really want to quit?",
166 QMessageBox::Ok, QMessageBox::Cancel);
180 /////////////////////////////////////////////////////////////////////
181 // SLOT IMPLEMENTATION
182 /////////////////////////////////////////////////////////////////////
185 void EonSL::slotFileNew()
187 statusBar()->message("Creating new file...");
189 statusBar()->message(IDS_STATUS_DEFAULT);
192 void EonSL::slotFileOpen()
194 statusBar()->message("Opening file...");
196 QString fileName = QFileDialog::getOpenFileName(0,0,this);
197 if (!fileName.isEmpty())
200 setCaption(fileName);
201 QString message="Loaded document: "+fileName;
202 statusBar()->message(message, 2000);
206 statusBar()->message("Opening aborted", 2000);
211 void EonSL::slotFileSave()
213 statusBar()->message("Saving file...");
215 statusBar()->message(IDS_STATUS_DEFAULT);
218 void EonSL::slotFileSaveAs()
220 statusBar()->message("Saving file under new filename...");
221 QString fn = QFileDialog::getSaveFileName(0, 0, this);
228 statusBar()->message("Saving aborted", 2000);
231 statusBar()->message(IDS_STATUS_DEFAULT);
234 void EonSL::slotFileClose()
236 statusBar()->message("Closing file...");
238 statusBar()->message(IDS_STATUS_DEFAULT);
241 void EonSL::slotFilePrint()
243 statusBar()->message("Printing...");
245 if (printer.setup(this))
248 painter.begin(&printer);
250 ///////////////////////////////////////////////////////////////////
251 // TODO: Define printing by using the QPainter methods here
256 statusBar()->message(IDS_STATUS_DEFAULT);
259 void EonSL::slotFileQuit()
261 statusBar()->message("Exiting application...");
262 ///////////////////////////////////////////////////////////////////
263 // exits the Application
264 if(doc->isModified())
280 statusBar()->message(IDS_STATUS_DEFAULT);
283 void EonSL::slotEditCut()
285 statusBar()->message("Cutting selection...");
287 statusBar()->message(IDS_STATUS_DEFAULT);
290 void EonSL::slotEditCopy()
292 statusBar()->message("Copying selection to clipboard...");
294 statusBar()->message(IDS_STATUS_DEFAULT);
297 void EonSL::slotEditPaste()
299 statusBar()->message("Inserting clipboard contents...");
301 statusBar()->message(IDS_STATUS_DEFAULT);
305 void EonSL::slotViewToolBar()
307 statusBar()->message("Toggle toolbar...");
308 ///////////////////////////////////////////////////////////////////
309 // turn Toolbar on or off
311 if (fileToolbar->isVisible())
314 viewMenu->setItemChecked(ID_VIEW_TOOLBAR, false);
319 viewMenu->setItemChecked(ID_VIEW_TOOLBAR, true);
322 statusBar()->message(IDS_STATUS_DEFAULT);
325 void EonSL::slotViewStatusBar()
327 statusBar()->message("Toggle statusbar...");
328 ///////////////////////////////////////////////////////////////////
329 //turn Statusbar on or off
331 if (statusBar()->isVisible())
334 viewMenu->setItemChecked(ID_VIEW_STATUSBAR, false);
339 viewMenu->setItemChecked(ID_VIEW_STATUSBAR, true);
342 statusBar()->message(IDS_STATUS_DEFAULT);
345 void EonSL::slotHelpAbout()
347 QMessageBox::about(this,"About...",
351 void EonSL::slotStatusHelpMsg(const QString &text)
353 ///////////////////////////////////////////////////////////////////
354 // change status message of whole statusbar temporary (text, msec)
355 statusBar()->message(text, 2000);
358 void EonSL::statusCallback(int id_)
363 slotStatusHelpMsg("Creates a new document");
367 slotStatusHelpMsg("Opens an existing document");
371 slotStatusHelpMsg("Saves the actual document");
374 case ID_FILE_SAVE_AS:
375 slotStatusHelpMsg("Saves the actual document as...");
379 slotStatusHelpMsg("Closes the actual document");
383 slotStatusHelpMsg("Prints out the actual document");
387 slotStatusHelpMsg("Quits the application");
391 slotStatusHelpMsg("Cuts the selected section and puts it to the clipboard");
395 slotStatusHelpMsg("Copies the selected section to the clipboard");
399 slotStatusHelpMsg("Pastes the clipboard contents to actual position");
402 case ID_EDIT_SELECT_ALL:
403 slotStatusHelpMsg("Selects the whole document contents");
406 case ID_VIEW_TOOLBAR:
407 slotStatusHelpMsg("Enables/disables the toolbar");
410 case ID_VIEW_STATUSBAR:
411 slotStatusHelpMsg("Enables/disables the statusbar");
415 slotStatusHelpMsg("Shows an aboutbox");