Port to new api
[kdeaccessibility.git] / kmag / kmag.cpp
blobbc56b5b597d5a2e2a4918f3cbf7bac2553841389
1 /***************************************************************************
2 kmag.cpp - description
3 -------------------
4 begin : Mon Feb 12 23:45:41 EST 2001
5 copyright : (C) 2001-2003 by Sarang Lakare
6 email : sarang#users.sourceforge.net
7 copyright : (C) 2003-2004 by Olaf Schmidt
8 email : ojschmidt@kde.org
9 ***************************************************************************/
11 /***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
20 // include files for QT
21 #include <QDir>
22 #include <QPrinter>
23 #include <QPainter>
24 #include <QLayout>
25 #include <QClipboard>
26 #include <q3dragobject.h>
27 #include <QToolTip>
28 #include <q3popupmenu.h>
29 #include <kxmlguiclient.h>
30 #include <ktoolbar.h>
31 #include <ktoggleaction.h>
32 #include <kactioncollection.h>
33 #include <kselectaction.h>
34 //Added by qt3to4:
35 #include <QContextMenuEvent>
36 #include <QPixmap>
37 #include <QDesktopWidget>
38 #include <kdeversion.h>
39 #include <kxmlguifactory.h>
40 #include <kicon.h>
41 // include files for KDE
42 #include <kapplication.h>
43 #include <kstandardshortcut.h>
44 #include <kshortcutsdialog.h>
45 #include <kiconloader.h>
46 #include <kmessagebox.h>
47 #include <kfiledialog.h>
48 #include <kmenubar.h>
49 #include <klocale.h>
50 #include <kconfig.h>
51 #include <kdebug.h>
52 #include <kstandardaction.h>
53 #include <khelpmenu.h>
54 #include <kimageio.h>
55 #include <kio/job.h>
56 #include <kio/netaccess.h>
57 #include <ktemporaryfile.h>
58 #include <kmenu.h>
59 #include <kedittoolbar.h>
61 #include <kprinter.h>
62 #include <kglobal.h>
64 // application specific includes
65 #include "kmag.moc"
66 #include "kmagzoomview.h"
67 #include "kmagselrect.h"
70 #define havesetCheckedState
72 KmagApp::KmagApp(QWidget* , const char* name)
73 : KXmlGuiWindow(0, Qt::WStyle_MinMax | Qt::WType_TopLevel | Qt::WDestructiveClose | Qt::WStyle_ContextHelp | Qt::WStyle_StaysOnTop),
74 m_defaultMouseCursorType(2)
76 setObjectName(name);
77 config=KGlobal::config();
79 zoomArrayString << "5:1" << "2:1" << "1:1" << "1:1.5" << "1:2" << "1:3" << "1:4" << "1:5"
80 << "1:6" << "1:7" << "1:8" << "1:12" << "1:16" << "1:20";
82 // Is there a better way to initialize a vector array?
83 zoomArray.push_back(0.2); zoomArray.push_back(0.5); zoomArray.push_back(1.0);
84 zoomArray.push_back(1.5); zoomArray.push_back(2.0); zoomArray.push_back(3.0);
85 zoomArray.push_back(4.0); zoomArray.push_back(5.0); zoomArray.push_back(6.0); zoomArray.push_back(7.0);
86 zoomArray.push_back(8.0); zoomArray.push_back(12.0); zoomArray.push_back(16.0); zoomArray.push_back(20.0);
88 fpsArrayString << i18n("&Very Low") << i18n("&Low") << i18n("&Medium") << i18n("&High") << i18n("V&ery High");
90 fpsArray.push_back(2); // very low
91 fpsArray.push_back(6); // low
92 fpsArray.push_back(10); // medium
93 fpsArray.push_back(15); // high
94 fpsArray.push_back(25); // very high
96 rotationArrayString << i18n("&No Rotation (0 Degrees)") << i18n("&Left (90 Degrees)") << i18n("&Upside Down (180 Degrees)") << i18n("&Right (270 Degrees)");
98 rotationArray.push_back(0); // no rotation
99 rotationArray.push_back(90); // left
100 rotationArray.push_back(180); // upside down
101 rotationArray.push_back(270); // right
103 // call inits to invoke all other construction parts
104 initView();
105 initActions();
106 initConnections();
108 // read options from config file
109 readOptions();
114 * Default destructor.
116 KmagApp::~KmagApp()
118 m_zoomView->showSelRect(false);
121 void KmagApp::initActions()
123 fileNewWindow = actionCollection()->addAction("new_window");
124 fileNewWindow->setIcon(KIcon("window-new"));
125 fileNewWindow->setText(i18n("New &Window"));
126 connect(fileNewWindow, SIGNAL(triggered(bool) ), SLOT(slotFileNewWindow()));
127 fileNewWindow->setShortcuts(KStandardShortcut::openNew());
128 fileNewWindow->setToolTip(i18n("Open a new KMagnifier window"));
130 refreshSwitch = actionCollection()->addAction("start_stop_refresh");
131 refreshSwitch->setIcon(KIcon("process-stop"));
132 refreshSwitch->setText(i18n("&Stop"));
133 connect(refreshSwitch, SIGNAL(triggered(bool) ), SLOT(slotToggleRefresh()));
134 refreshSwitch->setShortcuts(KStandardShortcut::reload());
135 refreshSwitch->setToolTip(i18n("Click to stop window refresh"));
136 refreshSwitch->setWhatsThis(i18n("Clicking on this icon will <b>start</b> / <b>stop</b>\
137 updating of the display. Stopping the update will zero the processing power\
138 required (CPU usage)"));
140 m_pSnapshot = actionCollection()->addAction("snapshot");
141 m_pSnapshot->setIcon(KIcon("ksnapshot"));
142 m_pSnapshot->setText(i18n("&Save Snapshot As..."));
143 connect(m_pSnapshot, SIGNAL(triggered(bool) ), SLOT(saveZoomPixmap()));
144 m_pSnapshot->setShortcuts(KStandardShortcut::save());
145 m_pSnapshot->setWhatsThis(i18n("Saves the zoomed view to an image file."));
146 m_pSnapshot->setToolTip(i18n("Save image to a file"));
148 m_pPrint = actionCollection()->addAction(KStandardAction::Print, this, SLOT(slotFilePrint()));
149 m_pPrint->setWhatsThis(i18n("Click on this button to print the current zoomed view."));
151 m_pQuit = actionCollection()->addAction(KStandardAction::Quit, this, SLOT(slotFileQuit()));
152 m_pQuit->setToolTip(i18n("Quits the application"));
153 m_pQuit->setWhatsThis (i18n("Quits the application"));
155 m_pCopy = actionCollection()->addAction(KStandardAction::Copy, this, SLOT(copyToClipBoard()));
156 m_pCopy->setWhatsThis(i18n("Click on this button to copy the current zoomed view to the clipboard which you can paste in other applications."));
157 m_pCopy->setToolTip(i18n("Copy zoomed image to clipboard"));
159 m_pShowMenu = new KToggleAction(KIcon("show-menu"), i18n("Show &Menu"), this);
160 actionCollection()->addAction("show_menu", m_pShowMenu);
161 connect(m_pShowMenu, SIGNAL(triggered(bool)), SLOT(slotShowMenu()));
162 m_pShowMenu->setShortcut(Qt::CTRL+Qt::Key_M);
163 #ifdef havesetCheckedState
164 m_pShowMenu->setCheckedState(KGuiItem(i18n("Hide &Menu")));
165 #endif
166 m_pShowMainToolBar = new KToggleAction(i18n("Show Main &Toolbar"), this);
167 actionCollection()->addAction("show_mainToolBar", m_pShowMainToolBar);
168 connect(m_pShowMainToolBar, SIGNAL(triggered(bool)), SLOT(slotShowMainToolBar()));
169 #ifdef havesetCheckedState
170 m_pShowMainToolBar->setCheckedState(KGuiItem(i18n("Hide Main &Toolbar")));
171 #endif
172 m_pShowViewToolBar = new KToggleAction(i18n("Show &View Toolbar"), this);
173 actionCollection()->addAction("show_viewToolBar", m_pShowViewToolBar);
174 connect(m_pShowViewToolBar, SIGNAL(triggered(bool)), SLOT(slotShowViewToolBar()));
175 #ifdef havesetCheckedState
176 m_pShowViewToolBar->setCheckedState(KGuiItem(i18n("Hide &View Toolbar")));
177 #endif
178 m_pShowSettingsToolBar = new KToggleAction(i18n("Show &Settings Toolbar"), this);
179 actionCollection()->addAction("show_settingsToolBar", m_pShowSettingsToolBar);
180 connect(m_pShowSettingsToolBar, SIGNAL(triggered(bool)), SLOT(slotShowSettingsToolBar()));
181 #ifdef havesetCheckedState
182 m_pShowSettingsToolBar->setCheckedState(KGuiItem(i18n("Hide &Settings Toolbar")));
183 #endif
185 m_modeFollowMouse = new KToggleAction(KIcon("followmouse"), i18n("&Follow Mouse Mode"), this);
186 actionCollection()->addAction("mode_followmouse", m_modeFollowMouse);
187 connect(m_modeFollowMouse, SIGNAL(triggered(bool)), SLOT(slotModeFollowMouse()));
188 m_modeFollowMouse->setShortcut(Qt::Key_F1);
189 m_modeFollowMouse->setToolTip(i18n("Magnify around the mouse cursor"));
190 m_modeFollowMouse->setWhatsThis(i18n("If selected, the area around the mouse cursor is magnified"));
192 m_modeSelWin = new KToggleAction(KIcon("window"), i18n("Se&lection Window Mode"), this);
193 actionCollection()->addAction("mode_selectionwindow", m_modeSelWin);
194 connect(m_modeSelWin, SIGNAL(triggered(bool)), SLOT(slotModeSelWin()));
195 m_modeSelWin->setShortcut(Qt::Key_F2);
196 m_modeSelWin->setToolTip(i18n("Show a window for selecting the magnified area"));
198 m_modeWholeScreen = new KToggleAction(KIcon("view-fullscreen"), i18n("&Whole Screen Mode"), this);
199 actionCollection()->addAction("mode_wholescreen", m_modeWholeScreen);
200 connect(m_modeWholeScreen, SIGNAL(triggered(bool)), SLOT(slotModeWholeScreen()));
201 m_modeWholeScreen->setShortcut(Qt::Key_F3);
202 m_modeWholeScreen->setToolTip(i18n("Magnify the whole screen"));
203 m_modeWholeScreen->setWhatsThis(i18n("Click on this button to fit the zoom view to the zoom window."));
205 m_hideCursor = new KToggleAction(KIcon("hidemouse"), i18n("Hide Mouse &Cursor"), this);
206 actionCollection()->addAction("hidecursor", m_hideCursor);
207 connect(m_hideCursor, SIGNAL(triggered(bool)), SLOT(slotToggleHideCursor()));
208 m_hideCursor->setShortcut(Qt::Key_F4);
209 #ifdef havesetCheckedState
210 m_hideCursor->setCheckedState(KGuiItem(i18n("Show Mouse &Cursor")));
211 #endif
212 m_hideCursor->setToolTip(i18n("Hide the mouse cursor"));
214 m_pZoomIn = actionCollection()->addAction(KStandardAction::ZoomIn, this, SLOT(zoomIn()));
215 m_pZoomIn->setWhatsThis(i18n("Click on this button to <b>zoom-in</b> on the selected region."));
217 m_pZoomBox = new KSelectAction(i18n("&Zoom"), this);
218 actionCollection()->addAction("zoom", m_pZoomBox);
219 m_pZoomBox->setItems(zoomArrayString);
220 m_pZoomBox->setWhatsThis(i18n("Select the zoom factor."));
221 m_pZoomBox->setToolTip(i18n("Zoom factor"));
223 m_pZoomOut = actionCollection()->addAction(KStandardAction::ZoomOut, this, SLOT(zoomOut()));
224 m_pZoomOut->setWhatsThis(i18n("Click on this button to <b>zoom-out</b> on the selected region."));
226 m_pRotationBox = new KSelectAction(i18n("&Rotation"),this);
227 actionCollection()->addAction("rotation", m_pRotationBox);
228 m_pRotationBox->setItems(rotationArrayString);
229 m_pRotationBox->setWhatsThis(i18n("Select the rotation degree."));
230 m_pRotationBox->setToolTip(i18n("Rotation degree"));
232 // KHelpMenu *newHelpMenu = new KHelpMenu(this, KGlobal::mainComponent().aboutData());
234 m_keyConf = actionCollection()->addAction(KStandardAction::KeyBindings, this, SLOT(slotConfKeys()));
235 m_toolConf = actionCollection()->addAction(KStandardAction::ConfigureToolbars, this, SLOT(slotEditToolbars()));
237 m_pFPSBox = new KSelectAction(i18n("&Refresh"),this);
238 actionCollection()->addAction("fps_selector", m_pFPSBox);
239 m_pFPSBox->setItems(fpsArrayString);
240 m_pFPSBox->setWhatsThis(i18n("Select the refresh rate. The higher the rate, the more computing power (CPU) will be needed."));
241 m_pFPSBox->setToolTip(i18n("Refresh rate"));
243 createGUI();
246 void KmagApp::initView()
248 m_zoomView = new KMagZoomView( this, "ZoomView" );
249 m_zoomView->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, m_zoomView->sizePolicy().hasHeightForWidth() ) );
250 m_zoomView->setFrameShape( QFrame::StyledPanel );
251 m_zoomView->setFrameShadow( QFrame::Raised );
253 setCentralWidget(m_zoomView);
257 void KmagApp::slotChangeZoomBoxIndex(int index)
259 m_pZoomBox->setCurrentItem(index);
262 void KmagApp::slotChangeRotationBoxIndex(int index)
264 m_pRotationBox->setCurrentItem(index);
267 void KmagApp::slotChangeFPSIndex(int index)
269 m_pFPSBox->setCurrentItem(index);
274 * Initialize all connections.
276 void KmagApp::initConnections()
278 // change in zoom value -> update the view
279 connect(this, SIGNAL(updateZoomValue(float)), m_zoomView, SLOT(setZoom(float)));
280 connect(this, SIGNAL(updateRotationValue(int)), m_zoomView, SLOT(setRotation(int)));
281 connect(this, SIGNAL(updateFPSValue(float)), m_zoomView, SLOT(setRefreshRate(float)));
283 // change in zoom index -> update the selector
284 connect(this, SIGNAL(updateZoomIndex(int)), this, SLOT(slotChangeZoomBoxIndex(int)));
285 connect(this, SIGNAL(updateRotationIndex(int)), this, SLOT(slotChangeRotationBoxIndex(int)));
286 connect(this, SIGNAL(updateFPSIndex(int)), this, SLOT(slotChangeFPSIndex(int)));
288 // selector selects a zoom index -> set the zoom index
289 connect(m_pZoomBox, SIGNAL(activated(int)), this, SLOT(setZoomIndex(int)));
290 connect(m_pRotationBox, SIGNAL(activated(int)), this, SLOT(setRotationIndex(int)));
291 connect(m_pFPSBox, SIGNAL(activated(int)), this, SLOT(setFPSIndex(int)));
295 * Save options to config file.
297 void KmagApp::saveOptions()
299 KConfigGroup cg( config, "General Options");
300 cg.writeEntry("Geometry", size());
301 cg.writeEntry("ZoomIndex", m_zoomIndex);
302 cg.writeEntry("RotationIndex", m_rotationIndex);
303 cg.writeEntry("FPSIndex", m_fpsIndex);
304 cg.writeEntry("SelRect", m_zoomView->getSelRectPos());
305 cg.writeEntry("ShowMouse", m_zoomView->getShowMouseType());
307 if (m_modeFollowMouse->isChecked())
308 cg.writeEntry("Mode", "followmouse");
309 else if (m_modeWholeScreen->isChecked())
310 cg.writeEntry("Mode", "wholescreen");
311 else if (m_modeSelWin->isChecked())
312 cg.writeEntry("Mode", "selectionwindow");
314 cg.writeEntry("ShowMenu", m_pShowMenu->isChecked());
315 cg.writeEntry("ShowMainToolBar", m_pShowMainToolBar->isChecked());
316 cg.writeEntry("ShowViewToolBar", m_pShowViewToolBar->isChecked());
317 cg.writeEntry("ShowSettingsToolBar", m_pShowSettingsToolBar->isChecked());
319 cg.changeGroup( "Main ToolBar" );
320 toolBar("mainToolBar")->saveSettings( cg );
321 cg.changeGroup( "View ToolBar" );
322 toolBar("viewToolBar")->saveSettings( cg );
323 cg.changeGroup( "Settings ToolBar" );
324 toolBar("settingsToolBar")->saveSettings( cg );
329 * Read settings from config file.
331 void KmagApp::readOptions()
333 QColor blue (0,0,128);
334 QColor yellow (255,255,0);
335 QColor white (255,255,255);
337 KConfigGroup cg( config, "WM");
338 setTitleColors (
339 cg.readEntry("inactiveBackground", blue),
340 cg.readEntry("inactiveForeground", white),
341 cg.readEntry("inactiveTitleBtnBg", yellow));
343 cg.changeGroup("General Options");
345 QSize defSize(460,390);
346 QSize size=cg.readEntry("Geometry", defSize);
347 if(!size.isEmpty())
349 resize(size);
352 // set zoom - defaults to 2x
353 unsigned int zoomIndex = cg.readEntry("ZoomIndex", 4);
354 setZoomIndex(zoomIndex);
355 emit updateZoomIndex(m_zoomIndex);
357 unsigned int rotationIndex = cg.readEntry("RotationIndex", 0);
358 setRotationIndex(rotationIndex);
359 emit updateRotationIndex(m_rotationIndex);
361 unsigned int fpsIndex = cg.readEntry("FPSIndex", 2);
362 setFPSIndex(fpsIndex);
363 emit updateFPSIndex(m_fpsIndex);
365 QString mode = cg.readEntry("Mode", "followmouse");
366 if (mode == "wholescreen")
367 slotModeWholeScreen();
368 else if (mode == "selectionwindow")
369 slotModeSelWin();
370 else
371 slotModeFollowMouse();
373 QRect defaultRect(0,0,211,164);
374 m_zoomView->setSelRectPos(cg.readEntry("SelRect", defaultRect));
376 m_mouseCursorType = cg.readEntry("ShowMouse", m_defaultMouseCursorType);
377 m_zoomView->showMouse(m_mouseCursorType);
378 if(m_mouseCursorType)
379 m_hideCursor->setChecked(false);
380 else
381 m_hideCursor->setChecked(true);
383 cg.changeGroup("Settings ToolBar");
384 if( cg.exists() )
385 toolBar("settingsToolBar")->applySettings(cg );
387 cg.changeGroup("Main ToolBar");
388 if( cg.exists() )
389 toolBar("mainToolBar")->applySettings( cg );
391 cg.changeGroup("View ToolBar" );
392 if( cg.exists() )
393 toolBar("viewToolBar")->applySettings( cg );
395 cg.changeGroup("General Options");
396 m_pShowMenu->setChecked( cg.readEntry("ShowMenu", true));
397 slotShowMenu();
399 m_pShowMainToolBar->setChecked(cg.readEntry("ShowMainToolBar", false));
400 slotShowMainToolBar();
402 m_pShowViewToolBar->setChecked(cg.readEntry("ShowViewToolBar", true));
403 slotShowViewToolBar();
405 m_pShowSettingsToolBar->setChecked(cg.readEntry("ShowSettingsToolBar", true));
406 slotShowSettingsToolBar();
409 bool KmagApp::queryClose()
411 return (true);
414 bool KmagApp::queryExit()
416 saveOptions();
417 return true;
421 * Called when mouse is clicked inside the window
423 * @param e
425 void KmagApp::contextMenuEvent ( QContextMenuEvent * e )
427 // show popup
428 KXMLGUIFactory *factory = this->factory();
429 QMenu *popup = (QMenu *)factory->container("mainPopUp",this);
430 if (popup != 0)
431 popup->popup(e->globalPos(), 0);
432 e->accept();
436 /////////////////////////////////////////////////////////////////////
437 // SLOT IMPLEMENTATION
438 /////////////////////////////////////////////////////////////////////
441 * Shows/hides the mouse cursor
443 void KmagApp::showMouseCursor(bool show)
445 if(show) {
446 if(m_mouseCursorType == 0)
447 m_mouseCursorType = m_defaultMouseCursorType;
448 m_zoomView->showMouse(m_mouseCursorType);
449 } else {
450 m_zoomView->showMouse(0);
455 * Zoom in.
457 void KmagApp::zoomIn()
459 // set the new index .. checking will done inside setZoom
460 setZoomIndex(m_zoomIndex+1);
461 // signal change in zoom index
462 emit updateZoomIndex((int)m_zoomIndex);
466 * Zoom out.
468 void KmagApp::zoomOut()
470 // set the new index .. checking will done inside setZoom
471 setZoomIndex(m_zoomIndex-1);
472 // signal change in zoom index
473 emit updateZoomIndex((int)m_zoomIndex);
476 * Sets the zoom index to index
478 void KmagApp::setZoomIndex(int index)
480 if(index < 0 || index >= (int)zoomArray.size()) {
481 // the index is invalid
482 kWarning() << "Invalid index!" << endl;
483 return;
484 } else if((int)m_zoomIndex == index) {
485 // do nothing!
486 return;
487 } else {
488 m_zoomIndex = index;
491 if(m_zoomIndex == 0) {
492 // meaning that no more zooming-out is possible
493 // -> disable zoom-out icon
494 m_pZoomOut->setEnabled(false);
495 } else { // enable the icon
496 m_pZoomOut->setEnabled(true);
499 if(m_zoomIndex == zoomArray.size()-1) {
500 // meaning that no more zooming-in is possible
501 // -> disable zoom-in icon
502 m_pZoomIn->setEnabled(false);
503 } else { // enable the icon
504 m_pZoomIn->setEnabled(true);
507 // signal change in zoom value
508 emit updateZoomValue(zoomArray[m_zoomIndex]);
512 * Sets the rotation index to index
514 void KmagApp::setRotationIndex(int index)
516 if(index < 0 || index >= (int)rotationArray.size()) {
517 // the index is invalid
518 kWarning() << "Invalid index!" << endl;
519 return;
520 } else if((int)m_rotationIndex == index) {
521 // do nothing!
522 return;
523 } else {
524 m_rotationIndex = index;
527 // signal change in zoom value
528 emit updateRotationValue(rotationArray[m_rotationIndex]);
532 * Sets the fps index to index
534 void KmagApp::setFPSIndex(int index)
536 if(index < 0 || index >= (int)fpsArray.size()) {
537 // the index is invalid
538 kWarning() << "Invalid index!" << endl;
539 return;
540 } else if((int)m_fpsIndex == index) {
541 // do nothing!
542 return;
543 } else {
544 m_fpsIndex = index;
547 // signal change in fps value
548 emit updateFPSValue(fpsArray[m_fpsIndex]);
553 * Save the zoomed image
555 void KmagApp::saveZoomPixmap()
557 bool toggled(false);
559 // stop refresh temporarily
560 if (m_zoomView->getRefreshStatus()) {
561 slotToggleRefresh();
562 toggled = true;
565 KUrl url = KFileDialog::getSaveUrl(QString(),
566 KImageIO::pattern(KImageIO::Writing),
567 0,i18n("Save Snapshot As"));
569 if(!url.fileName().isEmpty()) {
570 if(!url.isLocalFile()) {
571 // create a temp file.. save image to it.. copy over the n/w and then delete the temp file.
572 KTemporaryFile tempFile;
573 #ifdef __GNUC__
574 #warning "kde4: port KImageIO::type \n";
575 #endif
576 if(!tempFile.open() || !m_zoomView->getPixmap().save(tempFile.fileName(),"png"/*, KImageIO::type(url.fileName()).latin1()*/)) {
577 KMessageBox::error(0, i18n("Unable to save temporary file (before uploading to the network file you specified)."),
578 i18n("Error Writing File"));
579 } else {
580 if(!KIO::NetAccess::upload(tempFile.fileName(), url, this)) {
581 KMessageBox::error(0, i18n("Unable to upload file over the network."),
582 i18n("Error Writing File"));
583 } else {
584 KMessageBox::information(0, i18n("Current zoomed image saved to\n%1", url.prettyUrl()),
585 i18n("Information"), "save_confirm");
589 } else {
590 #ifdef __GNUC__
591 #warning "kde4 : port KImageIO::type(...) \n";
592 #endif
593 if(!m_zoomView->getPixmap().save(url.path(), "png"/*KImageIO::type(url.fileName()).latin1()*/)) {
594 KMessageBox::error(0, i18n("Unable to save file. Please check if you have permission to write to the directory."),
595 i18n("Error Writing File"));
596 } else {
597 KMessageBox::information(0, i18n("Current zoomed image saved to\n%1", url.prettyUrl()),
598 i18n("Information"), "save_confirm");
602 if(toggled) {
603 slotToggleRefresh();
608 void KmagApp::slotToggleRefresh()
610 m_zoomView->toggleRefresh();
611 if(m_zoomView->getRefreshStatus()) {
612 refreshSwitch->setIcon(KIcon("stop.png"));
613 refreshSwitch->setText(i18n("Stop"));
614 refreshSwitch->setToolTip(i18n("Click to stop window update"));
615 } else {
616 refreshSwitch->setIcon(KIcon("reload.png"));
617 refreshSwitch->setText(i18n("Start"));
618 refreshSwitch->setToolTip(i18n("Click to start window update"));
623 void KmagApp::slotModeWholeScreen()
625 m_zoomView->setSelRectPos(QRect (0, 0, QApplication::desktop()->width(), QApplication::desktop()->height()));
626 m_zoomView->followMouse(false);
627 m_zoomView->showSelRect(false);
628 m_zoomView->setFitToWindow (false);
629 m_modeFollowMouse->setChecked(false);
630 m_modeWholeScreen->setChecked(true);
631 m_modeSelWin->setChecked(false);
635 void KmagApp::slotModeSelWin()
637 m_zoomView->followMouse(false);
638 m_zoomView->showSelRect(true);
639 m_zoomView->setFitToWindow (false);
640 m_modeFollowMouse->setChecked(false);
641 m_modeWholeScreen->setChecked(false);
642 m_modeSelWin->setChecked(true);
646 void KmagApp::slotModeFollowMouse()
648 m_zoomView->followMouse(true);
649 m_zoomView->showSelRect(false);
650 m_zoomView->setFitToWindow (true);
651 m_modeFollowMouse->setChecked(true);
652 m_modeWholeScreen->setChecked(false);
653 m_modeSelWin->setChecked(false);
657 void KmagApp::slotToggleHideCursor()
659 showMouseCursor(!m_hideCursor->isChecked());
663 void KmagApp::slotFileNewWindow()
665 KmagApp *new_window= new KmagApp();
666 new_window->show();
670 void KmagApp::slotFilePrint()
672 #ifndef QT_NO_PRINTER
674 bool toggled(false);
676 KPrinter printer;
678 // stop refresh temporarily
679 if (m_zoomView->getRefreshStatus()) {
680 slotToggleRefresh();
681 toggled = true;
684 const QPixmap pixmap(m_zoomView->getPixmap());
686 // use some AI to get the best orientation
687 if(pixmap.width() > pixmap.height()) {
688 printer.setOrientation(KPrinter::Landscape);
689 } else {
690 printer.setOrientation(KPrinter::Portrait);
693 if (printer.setup(this)) {
694 QPainter paint;
696 if(!paint.begin(&printer))
697 return;
698 // draw the pixmap
699 paint.drawPixmap(0, 0, pixmap);
700 // end the painting
701 paint.end();
704 if(toggled) {
705 slotToggleRefresh();
707 #endif // QT_NO_PRINTER
710 void KmagApp::slotFileQuit()
712 saveOptions();
713 // close the first window, the list makes the next one the first again.
714 // This ensures that queryClose() is called on each window to ask for closing
715 KMainWindow* w;
716 if (!memberList().isEmpty())
718 for (int i = 0; i < memberList().size(); ++i)
720 w = memberList().at(i);
721 // only close the window if the closeEvent is accepted. If the user presses Cancel on the saveModified() dialog,
722 // the window and the application stay open.
723 if(!w->close())
724 break;
725 #ifdef __GNUC__
726 #warning "kde4: now memberList() is constant => we can't remove some element!"
727 #endif
728 //memberList()->removeRef(w);
733 void KmagApp::copyToClipBoard()
735 QClipboard *cb=KApplication::clipboard();
736 cb->setPixmap(m_zoomView->getPixmap());
739 void KmagApp::slotShowMenu()
741 ///////////////////////////////////////////////////////////////////
742 // turn Menu on or off
743 if(!m_pShowMenu->isChecked())
745 menuBar()->hide();
747 else
749 menuBar()->show();
755 void KmagApp::slotShowMainToolBar()
757 ///////////////////////////////////////////////////////////////////
758 // turn mainToolbar on or off
759 if(!m_pShowMainToolBar->isChecked())
761 toolBar("mainToolBar")->hide();
763 else
765 toolBar("mainToolBar")->show();
769 void KmagApp::slotShowViewToolBar()
771 ///////////////////////////////////////////////////////////////////
772 // turn viewToolbar on or off
773 if(!m_pShowViewToolBar->isChecked())
775 toolBar("viewToolBar")->hide();
777 else
779 toolBar("viewToolBar")->show();
783 void KmagApp::slotShowSettingsToolBar()
785 ///////////////////////////////////////////////////////////////////
786 // turn viewToolbar on or off
787 if(!m_pShowSettingsToolBar->isChecked())
789 toolBar("settingsToolBar")->hide();
791 else
793 toolBar("settingsToolBar")->show();
797 void KmagApp::slotConfKeys()
799 KShortcutsDialog::configure( actionCollection() );
802 void KmagApp::slotEditToolbars()
804 KConfigGroup cg( KGlobal::config(), "MainWindow" );
805 saveMainWindowSettings( cg );
806 KEditToolBar dlg( actionCollection() );
807 connect( &dlg, SIGNAL( newToolbarConfig() ), this, SLOT( slotNewToolbarConfig() ) );
808 if ( dlg.exec() )
809 createGUI();
813 void KmagApp::slotNewToolbarConfig()
815 applyMainWindowSettings( KGlobal::config()->group( "MainWindow" ) );
816 createGUI();