1 /***************************************************************************
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 copyright : (C) 2008 by Matthew Woehlke
10 email : mw_triad@users.sourceforge.net
11 ***************************************************************************/
13 /***************************************************************************
15 * This program is free software; you can redistribute it and/or modify *
16 * it under the terms of the GNU General Public License as published by *
17 * the Free Software Foundation; either version 2 of the License, or *
18 * (at your option) any later version. *
20 ***************************************************************************/
22 // include files for QT
23 #include <QtCore/QDir>
24 #include <QtGui/QPrintDialog>
25 #include <QtGui/QPainter>
26 #include <QtGui/QLayout>
27 #include <QtGui/QClipboard>
28 #include <QtGui/QContextMenuEvent>
29 #include <QtGui/QPixmap>
30 #include <QtGui/QDesktopWidget>
32 // include files for KDE
33 #include <kxmlguiclient.h>
35 #include <ktoggleaction.h>
36 #include <kactioncollection.h>
37 #include <kselectaction.h>
38 #include <kdeversion.h>
39 #include <kxmlguifactory.h>
41 #include <kapplication.h>
42 #include <kstandardshortcut.h>
43 #include <kshortcutsdialog.h>
44 #include <kiconloader.h>
45 #include <kmessagebox.h>
46 #include <kfiledialog.h>
51 #include <kstandardaction.h>
52 #include <khelpmenu.h>
55 #include <kio/netaccess.h>
56 #include <ktemporaryfile.h>
58 #include <kedittoolbar.h>
60 #include <kdeprintdialog.h>
62 // application specific includes
64 #include "kmagzoomview.h"
65 #include "kmagselrect.h"
68 #define havesetCheckedState
70 KmagApp::KmagApp(QWidget
* , const char* name
)
71 : KXmlGuiWindow(0, Qt::WStyle_MinMax
| Qt::WType_TopLevel
| Qt::WDestructiveClose
| Qt::WStyle_ContextHelp
| Qt::WStyle_StaysOnTop
),
72 m_defaultMouseCursorType(2)
75 config
=KGlobal::config();
77 zoomArrayString
<< "5:1" << "2:1" << "1:1" << "1:1.5" << "1:2" << "1:3" << "1:4" << "1:5"
78 << "1:6" << "1:7" << "1:8" << "1:12" << "1:16" << "1:20";
80 // Is there a better way to initialize a vector array?
81 zoomArray
.push_back(0.2); zoomArray
.push_back(0.5); zoomArray
.push_back(1.0);
82 zoomArray
.push_back(1.5); zoomArray
.push_back(2.0); zoomArray
.push_back(3.0);
83 zoomArray
.push_back(4.0); zoomArray
.push_back(5.0); zoomArray
.push_back(6.0); zoomArray
.push_back(7.0);
84 zoomArray
.push_back(8.0); zoomArray
.push_back(12.0); zoomArray
.push_back(16.0); zoomArray
.push_back(20.0);
86 fpsArrayString
<< i18nc("Zoom at very low", "&Very Low") << i18nc("Zoom at low", "&Low") << i18nc("Zoom at medium", "&Medium") << i18nc("Zoom at high", "&High") << i18nc("Zoom at very high", "V&ery High");
88 fpsArray
.push_back(2); // very low
89 fpsArray
.push_back(6); // low
90 fpsArray
.push_back(10); // medium
91 fpsArray
.push_back(15); // high
92 fpsArray
.push_back(25); // very high
94 colorArrayString
<< i18nc("No color-blindness simulation, i.e.'normal' vision'", "&Normal") << i18n("&Protanopia") << i18n("&Deuteranopia") << i18n("&Tritanopia") << i18n("&Achromatopsia");
96 colorArray
.push_back(0);
97 colorArray
.push_back(1);
98 colorArray
.push_back(2);
99 colorArray
.push_back(3);
100 colorArray
.push_back(4);
102 rotationArrayString
<< i18n("&No Rotation (0 Degrees)") << i18n("&Left (90 Degrees)") << i18n("&Upside Down (180 Degrees)") << i18n("&Right (270 Degrees)");
104 rotationArray
.push_back(0); // no rotation
105 rotationArray
.push_back(90); // left
106 rotationArray
.push_back(180); // upside down
107 rotationArray
.push_back(270); // right
109 // call inits to invoke all other construction parts
114 // read options from config file
117 #ifndef QT_NO_PRINTER
119 #endif // QT_NO_PRINTER
123 * Default destructor.
127 m_zoomView
->showSelRect(false);
129 #ifndef QT_NO_PRINTER
131 #endif // QT_NO_PRINTER
134 void KmagApp::initActions()
136 fileNewWindow
= actionCollection()->addAction("new_window");
137 fileNewWindow
->setIcon(KIcon("window-new"));
138 fileNewWindow
->setText(i18n("New &Window"));
139 connect(fileNewWindow
, SIGNAL(triggered(bool) ), SLOT(slotFileNewWindow()));
140 fileNewWindow
->setShortcuts(KStandardShortcut::openNew());
141 fileNewWindow
->setToolTip(i18n("Open a new KMagnifier window"));
143 refreshSwitch
= actionCollection()->addAction("start_stop_refresh");
144 refreshSwitch
->setIcon(KIcon("process-stop"));
145 refreshSwitch
->setText(i18n("&Stop"));
146 connect(refreshSwitch
, SIGNAL(triggered(bool) ), SLOT(slotToggleRefresh()));
147 refreshSwitch
->setShortcuts(KStandardShortcut::reload());
148 refreshSwitch
->setToolTip(i18n("Click to stop window refresh"));
149 refreshSwitch
->setWhatsThis(i18n("Clicking on this icon will <b>start</b> / <b>stop</b>\
150 updating of the display. Stopping the update will zero the processing power\
151 required (CPU usage)"));
153 m_pSnapshot
= actionCollection()->addAction("snapshot");
154 m_pSnapshot
->setIcon(KIcon("ksnapshot"));
155 m_pSnapshot
->setText(i18n("&Save Snapshot As..."));
156 connect(m_pSnapshot
, SIGNAL(triggered(bool) ), SLOT(saveZoomPixmap()));
157 m_pSnapshot
->setShortcuts(KStandardShortcut::save());
158 m_pSnapshot
->setWhatsThis(i18n("Saves the zoomed view to an image file."));
159 m_pSnapshot
->setToolTip(i18n("Save image to a file"));
161 m_pPrint
= actionCollection()->addAction(KStandardAction::Print
, this, SLOT(slotFilePrint()));
162 m_pPrint
->setWhatsThis(i18n("Click on this button to print the current zoomed view."));
164 m_pQuit
= actionCollection()->addAction(KStandardAction::Quit
, this, SLOT(slotFileQuit()));
165 m_pQuit
->setToolTip(i18n("Quits the application"));
166 m_pQuit
->setWhatsThis (i18n("Quits the application"));
168 m_pCopy
= actionCollection()->addAction(KStandardAction::Copy
, this, SLOT(copyToClipBoard()));
169 m_pCopy
->setWhatsThis(i18n("Click on this button to copy the current zoomed view to the clipboard which you can paste in other applications."));
170 m_pCopy
->setToolTip(i18n("Copy zoomed image to clipboard"));
172 m_pShowMenu
= new KToggleAction(KIcon("show-menu"), i18n("Show &Menu"), this);
173 actionCollection()->addAction("show_menu", m_pShowMenu
);
174 connect(m_pShowMenu
, SIGNAL(triggered(bool)), SLOT(slotShowMenu()));
175 m_pShowMenu
->setShortcut(Qt::CTRL
+Qt::Key_M
);
176 #ifdef havesetCheckedState
177 m_pShowMenu
->setCheckedState(KGuiItem(i18n("Hide &Menu")));
179 m_pShowMainToolBar
= new KToggleAction(i18n("Show Main &Toolbar"), this);
180 actionCollection()->addAction("show_mainToolBar", m_pShowMainToolBar
);
181 connect(m_pShowMainToolBar
, SIGNAL(triggered(bool)), SLOT(slotShowMainToolBar()));
182 #ifdef havesetCheckedState
183 m_pShowMainToolBar
->setCheckedState(KGuiItem(i18n("Hide Main &Toolbar")));
185 m_pShowViewToolBar
= new KToggleAction(i18n("Show &View Toolbar"), this);
186 actionCollection()->addAction("show_viewToolBar", m_pShowViewToolBar
);
187 connect(m_pShowViewToolBar
, SIGNAL(triggered(bool)), SLOT(slotShowViewToolBar()));
188 #ifdef havesetCheckedState
189 m_pShowViewToolBar
->setCheckedState(KGuiItem(i18n("Hide &View Toolbar")));
191 m_pShowSettingsToolBar
= new KToggleAction(i18n("Show &Settings Toolbar"), this);
192 actionCollection()->addAction("show_settingsToolBar", m_pShowSettingsToolBar
);
193 connect(m_pShowSettingsToolBar
, SIGNAL(triggered(bool)), SLOT(slotShowSettingsToolBar()));
194 #ifdef havesetCheckedState
195 m_pShowSettingsToolBar
->setCheckedState(KGuiItem(i18n("Hide &Settings Toolbar")));
198 m_modeFollowMouse
= new KToggleAction(KIcon("followmouse"), i18n("&Follow Mouse Mode"), this);
199 actionCollection()->addAction("mode_followmouse", m_modeFollowMouse
);
200 connect(m_modeFollowMouse
, SIGNAL(triggered(bool)), SLOT(slotModeFollowMouse()));
201 m_modeFollowMouse
->setShortcut(Qt::Key_F1
);
202 m_modeFollowMouse
->setToolTip(i18n("Magnify around the mouse cursor"));
203 m_modeFollowMouse
->setWhatsThis(i18n("If selected, the area around the mouse cursor is magnified"));
205 m_modeSelWin
= new KToggleAction(KIcon("window"), i18n("Se&lection Window Mode"), this);
206 actionCollection()->addAction("mode_selectionwindow", m_modeSelWin
);
207 connect(m_modeSelWin
, SIGNAL(triggered(bool)), SLOT(slotModeSelWin()));
208 m_modeSelWin
->setShortcut(Qt::Key_F2
);
209 m_modeSelWin
->setToolTip(i18n("Show a window for selecting the magnified area"));
211 m_modeWholeScreen
= new KToggleAction(KIcon("view-fullscreen"), i18n("&Whole Screen Mode"), this);
212 actionCollection()->addAction("mode_wholescreen", m_modeWholeScreen
);
213 connect(m_modeWholeScreen
, SIGNAL(triggered(bool)), SLOT(slotModeWholeScreen()));
214 m_modeWholeScreen
->setShortcut(Qt::Key_F3
);
215 m_modeWholeScreen
->setToolTip(i18n("Magnify the whole screen"));
216 m_modeWholeScreen
->setWhatsThis(i18n("Click on this button to fit the zoom view to the zoom window."));
218 m_hideCursor
= new KToggleAction(KIcon("hidemouse"), i18n("Hide Mouse &Cursor"), this);
219 actionCollection()->addAction("hidecursor", m_hideCursor
);
220 connect(m_hideCursor
, SIGNAL(triggered(bool)), SLOT(slotToggleHideCursor()));
221 m_hideCursor
->setShortcut(Qt::Key_F4
);
222 #ifdef havesetCheckedState
223 m_hideCursor
->setCheckedState(KGuiItem(i18n("Show Mouse &Cursor")));
225 m_hideCursor
->setToolTip(i18n("Hide the mouse cursor"));
227 m_pZoomIn
= actionCollection()->addAction(KStandardAction::ZoomIn
, this, SLOT(zoomIn()));
228 m_pZoomIn
->setWhatsThis(i18n("Click on this button to <b>zoom-in</b> on the selected region."));
230 m_pZoomBox
= new KSelectAction(i18n("&Zoom"), this);
231 actionCollection()->addAction("zoom", m_pZoomBox
);
232 m_pZoomBox
->setItems(zoomArrayString
);
233 m_pZoomBox
->setWhatsThis(i18n("Select the zoom factor."));
234 m_pZoomBox
->setToolTip(i18n("Zoom factor"));
236 m_pZoomOut
= actionCollection()->addAction(KStandardAction::ZoomOut
, this, SLOT(zoomOut()));
237 m_pZoomOut
->setWhatsThis(i18n("Click on this button to <b>zoom-out</b> on the selected region."));
239 m_pRotationBox
= new KSelectAction(i18n("&Rotation"),this);
240 actionCollection()->addAction("rotation", m_pRotationBox
);
241 m_pRotationBox
->setItems(rotationArrayString
);
242 m_pRotationBox
->setWhatsThis(i18n("Select the rotation degree."));
243 m_pRotationBox
->setToolTip(i18n("Rotation degree"));
245 // KHelpMenu *newHelpMenu = new KHelpMenu(this, KGlobal::mainComponent().aboutData());
247 m_keyConf
= actionCollection()->addAction(KStandardAction::KeyBindings
, this, SLOT(slotConfKeys()));
248 m_toolConf
= actionCollection()->addAction(KStandardAction::ConfigureToolbars
, this, SLOT(slotEditToolbars()));
250 m_pFPSBox
= new KSelectAction(i18n("&Refresh"),this);
251 actionCollection()->addAction("fps_selector", m_pFPSBox
);
252 m_pFPSBox
->setItems(fpsArrayString
);
253 m_pFPSBox
->setWhatsThis(i18n("Select the refresh rate. The higher the rate, the more computing power (CPU) will be needed."));
254 m_pFPSBox
->setToolTip(i18n("Refresh rate"));
256 m_pColorBox
= new KSelectAction(i18nc("Color-blindness simulation mode", "&Color"),this);
257 actionCollection()->addAction("color_mode", m_pColorBox
);
258 m_pColorBox
->setItems(colorArrayString
);
259 m_pColorBox
->setWhatsThis(i18n("Select a mode to simulate various types of color-blindness."));
260 m_pColorBox
->setToolTip(i18n("Color-blindness Simulation Mode"));
265 void KmagApp::initView()
267 m_zoomView
= new KMagZoomView( this, "ZoomView" );
268 m_zoomView
->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType
)7, (QSizePolicy::SizeType
)7, m_zoomView
->sizePolicy().hasHeightForWidth() ) );
269 m_zoomView
->setFrameShape( QFrame::StyledPanel
);
270 m_zoomView
->setFrameShadow( QFrame::Raised
);
272 setCentralWidget(m_zoomView
);
276 void KmagApp::slotChangeZoomBoxIndex(int index
)
278 m_pZoomBox
->setCurrentItem(index
);
281 void KmagApp::slotChangeRotationBoxIndex(int index
)
283 m_pRotationBox
->setCurrentItem(index
);
286 void KmagApp::slotChangeFPSIndex(int index
)
288 m_pFPSBox
->setCurrentItem(index
);
291 void KmagApp::slotChangeColorIndex(int index
)
293 m_pColorBox
->setCurrentItem(index
);
297 * Initialize all connections.
299 void KmagApp::initConnections()
301 // change in zoom value -> update the view
302 connect(this, SIGNAL(updateZoomValue(float)), m_zoomView
, SLOT(setZoom(float)));
303 connect(this, SIGNAL(updateRotationValue(int)), m_zoomView
, SLOT(setRotation(int)));
304 connect(this, SIGNAL(updateFPSValue(float)), m_zoomView
, SLOT(setRefreshRate(float)));
305 connect(this, SIGNAL(updateColorValue(int)), m_zoomView
, SLOT(setColorMode(int)));
307 // change in zoom index -> update the selector
308 connect(this, SIGNAL(updateZoomIndex(int)), this, SLOT(slotChangeZoomBoxIndex(int)));
309 connect(this, SIGNAL(updateRotationIndex(int)), this, SLOT(slotChangeRotationBoxIndex(int)));
310 connect(this, SIGNAL(updateFPSIndex(int)), this, SLOT(slotChangeFPSIndex(int)));
311 connect(this, SIGNAL(updateColorIndex(int)), this, SLOT(slotChangeColorIndex(int)));
313 // selector selects a zoom index -> set the zoom index
314 connect(m_pZoomBox
, SIGNAL(triggered(int)), this, SLOT(setZoomIndex(int)));
315 connect(m_pRotationBox
, SIGNAL(triggered(int)), this, SLOT(setRotationIndex(int)));
316 connect(m_pFPSBox
, SIGNAL(triggered(int)), this, SLOT(setFPSIndex(int)));
317 connect(m_pColorBox
, SIGNAL(triggered(int)), this, SLOT(setColorIndex(int)));
321 * Save options to config file.
323 void KmagApp::saveOptions()
325 KConfigGroup
cg( config
, "General Options");
326 cg
.writeEntry("Geometry", size());
327 cg
.writeEntry("ZoomIndex", m_zoomIndex
);
328 cg
.writeEntry("RotationIndex", m_rotationIndex
);
329 cg
.writeEntry("FPSIndex", m_fpsIndex
);
330 cg
.writeEntry("ColorIndex", m_colorIndex
);
331 cg
.writeEntry("SelRect", m_zoomView
->getSelRectPos());
332 cg
.writeEntry("ShowMouse", m_zoomView
->getShowMouseType());
334 if (m_modeFollowMouse
->isChecked())
335 cg
.writeEntry("Mode", "followmouse");
336 else if (m_modeWholeScreen
->isChecked())
337 cg
.writeEntry("Mode", "wholescreen");
338 else if (m_modeSelWin
->isChecked())
339 cg
.writeEntry("Mode", "selectionwindow");
341 cg
.writeEntry("ShowMenu", m_pShowMenu
->isChecked());
342 cg
.writeEntry("ShowMainToolBar", m_pShowMainToolBar
->isChecked());
343 cg
.writeEntry("ShowViewToolBar", m_pShowViewToolBar
->isChecked());
344 cg
.writeEntry("ShowSettingsToolBar", m_pShowSettingsToolBar
->isChecked());
346 KConfigGroup
mainToolBarGroup(config
,"Main ToolBar");
347 toolBar("mainToolBar")->saveSettings( mainToolBarGroup
);
348 KConfigGroup
viewToolBarGroup(config
,"View ToolBar" );
349 toolBar("viewToolBar")->saveSettings( viewToolBarGroup
);
350 KConfigGroup
settingsToolbarGroup(config
,"Settings ToolBar" );
351 toolBar("settingsToolBar")->saveSettings( settingsToolbarGroup
);
356 * Read settings from config file.
358 void KmagApp::readOptions()
360 QColor
blue (0,0,128);
361 QColor
yellow (255,255,0);
362 QColor
white (255,255,255);
364 KConfigGroup
cgWM( config
, "WM");
366 cgWM
.readEntry("inactiveBackground", blue
),
367 cgWM
.readEntry("inactiveForeground", white
),
368 cgWM
.readEntry("inactiveTitleBtnBg", yellow
));
370 KConfigGroup
cg(config
,"General Options");
372 QSize
defSize(460,390);
373 QSize size
=cg
.readEntry("Geometry", defSize
);
379 // set zoom - defaults to 2x
380 unsigned int zoomIndex
= cg
.readEntry("ZoomIndex", 4);
381 setZoomIndex(zoomIndex
);
382 emit
updateZoomIndex(m_zoomIndex
);
384 unsigned int rotationIndex
= cg
.readEntry("RotationIndex", 0);
385 setRotationIndex(rotationIndex
);
386 emit
updateRotationIndex(m_rotationIndex
);
388 unsigned int fpsIndex
= cg
.readEntry("FPSIndex", 2);
389 setFPSIndex(fpsIndex
);
390 emit
updateFPSIndex(m_fpsIndex
);
392 unsigned int colorIndex
= cg
.readEntry("ColorIndex", 0);
393 setColorIndex(colorIndex
);
394 emit
updateColorIndex(colorIndex
);
396 QString mode
= cg
.readEntry("Mode", "followmouse");
397 if (mode
== "wholescreen")
398 slotModeWholeScreen();
399 else if (mode
== "selectionwindow")
402 slotModeFollowMouse();
404 QRect
defaultRect(0,0,211,164);
405 m_zoomView
->setSelRectPos(cg
.readEntry("SelRect", defaultRect
));
407 m_mouseCursorType
= cg
.readEntry("ShowMouse", m_defaultMouseCursorType
);
408 m_zoomView
->showMouse(m_mouseCursorType
);
409 if(m_mouseCursorType
)
410 m_hideCursor
->setChecked(false);
412 m_hideCursor
->setChecked(true);
414 KConfigGroup
settingsToolbarGroup(config
,"Settings ToolBar");
415 if( settingsToolbarGroup
.exists() )
416 toolBar("settingsToolBar")->applySettings(settingsToolbarGroup
);
418 KConfigGroup
mainToolbarGroup(config
,"Main ToolBar");
419 if( mainToolbarGroup
.exists() )
420 toolBar("mainToolBar")->applySettings( mainToolbarGroup
);
422 KConfigGroup
viewToolbarGroup(config
,"View ToolBar" );
423 if( viewToolbarGroup
.exists() )
424 toolBar("viewToolBar")->applySettings( viewToolbarGroup
);
426 KConfigGroup
generalOptionGroup(config
,"General Options");
427 m_pShowMenu
->setChecked( generalOptionGroup
.readEntry("ShowMenu", true));
430 m_pShowMainToolBar
->setChecked(generalOptionGroup
.readEntry("ShowMainToolBar", false));
431 slotShowMainToolBar();
433 m_pShowViewToolBar
->setChecked(generalOptionGroup
.readEntry("ShowViewToolBar", true));
434 slotShowViewToolBar();
436 m_pShowSettingsToolBar
->setChecked(generalOptionGroup
.readEntry("ShowSettingsToolBar", true));
437 slotShowSettingsToolBar();
440 bool KmagApp::queryClose()
445 bool KmagApp::queryExit()
452 * Called when mouse is clicked inside the window
456 void KmagApp::contextMenuEvent ( QContextMenuEvent
* e
)
459 KXMLGUIFactory
*factory
= this->factory();
460 QMenu
*popup
= (QMenu
*)factory
->container("mainPopUp",this);
462 popup
->popup(e
->globalPos(), 0);
467 /////////////////////////////////////////////////////////////////////
468 // SLOT IMPLEMENTATION
469 /////////////////////////////////////////////////////////////////////
472 * Shows/hides the mouse cursor
474 void KmagApp::showMouseCursor(bool show
)
477 if(m_mouseCursorType
== 0)
478 m_mouseCursorType
= m_defaultMouseCursorType
;
479 m_zoomView
->showMouse(m_mouseCursorType
);
481 m_zoomView
->showMouse(0);
488 void KmagApp::zoomIn()
490 // set the new index .. checking will done inside setZoom
491 setZoomIndex(m_zoomIndex
+1);
492 // signal change in zoom index
493 emit
updateZoomIndex((int)m_zoomIndex
);
499 void KmagApp::zoomOut()
501 // set the new index .. checking will done inside setZoom
502 setZoomIndex(m_zoomIndex
-1);
503 // signal change in zoom index
504 emit
updateZoomIndex((int)m_zoomIndex
);
507 * Sets the zoom index to index
509 void KmagApp::setZoomIndex(int index
)
511 if(index
< 0 || index
>= (int)zoomArray
.size()) {
512 // the index is invalid
513 kWarning() << "Invalid index!" ;
515 } else if((int)m_zoomIndex
== index
) {
522 if(m_zoomIndex
== 0) {
523 // meaning that no more zooming-out is possible
524 // -> disable zoom-out icon
525 m_pZoomOut
->setEnabled(false);
526 } else { // enable the icon
527 m_pZoomOut
->setEnabled(true);
530 if(m_zoomIndex
== zoomArray
.size()-1) {
531 // meaning that no more zooming-in is possible
532 // -> disable zoom-in icon
533 m_pZoomIn
->setEnabled(false);
534 } else { // enable the icon
535 m_pZoomIn
->setEnabled(true);
538 // signal change in zoom value
539 emit
updateZoomValue(zoomArray
[m_zoomIndex
]);
543 * Sets the rotation index to index
545 void KmagApp::setRotationIndex(int index
)
547 if(index
< 0 || index
>= (int)rotationArray
.size()) {
548 // the index is invalid
549 kWarning() << "Invalid index!" ;
551 } else if((int)m_rotationIndex
== index
) {
555 m_rotationIndex
= index
;
558 // signal change in zoom value
559 emit
updateRotationValue(rotationArray
[m_rotationIndex
]);
563 * Sets the fps index to index
565 void KmagApp::setFPSIndex(int index
)
567 if(index
< 0 || index
>= (int)fpsArray
.size()) {
568 // the index is invalid
569 kWarning() << "Invalid index!" ;
571 } else if((int)m_fpsIndex
== index
) {
578 // signal change in fps value
579 emit
updateFPSValue(fpsArray
[m_fpsIndex
]);
583 * Sets the color index to index
585 void KmagApp::setColorIndex(int index
)
587 if(index
< 0 || index
>= (int)colorArray
.size()) {
588 // the index is invalid
589 kWarning() << "Invalid index!" ;
591 } else if((int)m_colorIndex
== index
) {
595 m_colorIndex
= index
;
598 // signal change in fps value
599 emit
updateColorValue(colorArray
[m_colorIndex
]);
603 * Save the zoomed image
605 void KmagApp::saveZoomPixmap()
609 // stop refresh temporarily
610 if (m_zoomView
->getRefreshStatus()) {
615 KUrl url
= KFileDialog::getSaveUrl(QString(),
616 KImageIO::pattern(KImageIO::Writing
),
617 0,i18n("Save Snapshot As"));
619 if(!url
.fileName().isEmpty()) {
620 if(!url
.isLocalFile()) {
621 // create a temp file.. save image to it.. copy over the n/w and then delete the temp file.
622 KTemporaryFile tempFile
;
624 #warning "kde4: port KImageIO::type \n";
626 if(!tempFile
.open() || !m_zoomView
->getPixmap().save(tempFile
.fileName(),"png"/*, KImageIO::type(url.fileName()).latin1()*/)) {
627 KMessageBox::error(0, i18n("Unable to save temporary file (before uploading to the network file you specified)."),
628 i18n("Error Writing File"));
630 if(!KIO::NetAccess::upload(tempFile
.fileName(), url
, this)) {
631 KMessageBox::error(0, i18n("Unable to upload file over the network."),
632 i18n("Error Writing File"));
634 KMessageBox::information(0, i18n("Current zoomed image saved to\n%1", url
.prettyUrl()),
635 i18n("Information"), "save_confirm");
641 #warning "kde4 : port KImageIO::type(...) \n";
643 if(!m_zoomView
->getPixmap().save(url
.path(), "png"/*KImageIO::type(url.fileName()).latin1()*/)) {
644 KMessageBox::error(0, i18n("Unable to save file. Please check if you have permission to write to the directory."),
645 i18n("Error Writing File"));
647 KMessageBox::information(0, i18n("Current zoomed image saved to\n%1", url
.prettyUrl()),
648 i18n("Information"), "save_confirm");
658 void KmagApp::slotToggleRefresh()
660 m_zoomView
->toggleRefresh();
661 if(m_zoomView
->getRefreshStatus()) {
662 refreshSwitch
->setIcon(KIcon("stop.png"));
663 refreshSwitch
->setText(i18n("Stop"));
664 refreshSwitch
->setToolTip(i18n("Click to stop window update"));
666 refreshSwitch
->setIcon(KIcon("reload.png"));
667 refreshSwitch
->setText(i18nc("Start updating the window", "Start"));
668 refreshSwitch
->setToolTip(i18n("Click to start window update"));
673 void KmagApp::slotModeWholeScreen()
675 m_zoomView
->setSelRectPos(QRect (0, 0, QApplication::desktop()->width(), QApplication::desktop()->height()));
676 m_zoomView
->followMouse(false);
677 m_zoomView
->showSelRect(false);
678 m_zoomView
->setFitToWindow (false);
679 m_modeFollowMouse
->setChecked(false);
680 m_modeWholeScreen
->setChecked(true);
681 m_modeSelWin
->setChecked(false);
685 void KmagApp::slotModeSelWin()
687 m_zoomView
->followMouse(false);
688 m_zoomView
->showSelRect(true);
689 m_zoomView
->setFitToWindow (false);
690 m_modeFollowMouse
->setChecked(false);
691 m_modeWholeScreen
->setChecked(false);
692 m_modeSelWin
->setChecked(true);
696 void KmagApp::slotModeFollowMouse()
698 m_zoomView
->followMouse(true);
699 m_zoomView
->showSelRect(false);
700 m_zoomView
->setFitToWindow (true);
701 m_modeFollowMouse
->setChecked(true);
702 m_modeWholeScreen
->setChecked(false);
703 m_modeSelWin
->setChecked(false);
707 void KmagApp::slotToggleHideCursor()
709 showMouseCursor(!m_hideCursor
->isChecked());
713 void KmagApp::slotFileNewWindow()
715 KmagApp
*new_window
= new KmagApp();
720 void KmagApp::slotFilePrint()
722 #ifndef QT_NO_PRINTER
726 if (m_printer
== 0) {
727 m_printer
= new QPrinter();
730 // stop refresh temporarily
731 if (m_zoomView
->getRefreshStatus()) {
736 const QPixmap
pixmap(m_zoomView
->getPixmap());
738 // use some AI to get the best orientation
739 if(pixmap
.width() > pixmap
.height()) {
740 m_printer
->setOrientation(QPrinter::Landscape
);
742 m_printer
->setOrientation(QPrinter::Portrait
);
745 QPrintDialog
*printDialog
= KdePrint::createPrintDialog(m_printer
, this);
747 if (printDialog
->exec()) {
750 if(!paint
.begin(m_printer
))
756 paint
.drawPixmap(0, 0, pixmap
);
765 #endif // QT_NO_PRINTER
768 void KmagApp::slotFileQuit()
771 // close the first window, the list makes the next one the first again.
772 // This ensures that queryClose() is called on each window to ask for closing
774 if (!memberList().isEmpty())
776 for (int i
= 0; i
< memberList().size(); ++i
)
778 w
= memberList().at(i
);
779 // only close the window if the closeEvent is accepted. If the user presses Cancel on the saveModified() dialog,
780 // the window and the application stay open.
784 #warning "kde4: now memberList() is constant => we can't remove some element!"
786 //memberList()->removeRef(w);
791 void KmagApp::copyToClipBoard()
793 QClipboard
*cb
=KApplication::clipboard();
794 cb
->setPixmap(m_zoomView
->getPixmap());
797 void KmagApp::slotShowMenu()
799 ///////////////////////////////////////////////////////////////////
800 // turn Menu on or off
801 if(!m_pShowMenu
->isChecked())
813 void KmagApp::slotShowMainToolBar()
815 ///////////////////////////////////////////////////////////////////
816 // turn mainToolbar on or off
817 if(!m_pShowMainToolBar
->isChecked())
819 toolBar("mainToolBar")->hide();
823 toolBar("mainToolBar")->show();
827 void KmagApp::slotShowViewToolBar()
829 ///////////////////////////////////////////////////////////////////
830 // turn viewToolbar on or off
831 if(!m_pShowViewToolBar
->isChecked())
833 toolBar("viewToolBar")->hide();
837 toolBar("viewToolBar")->show();
841 void KmagApp::slotShowSettingsToolBar()
843 ///////////////////////////////////////////////////////////////////
844 // turn viewToolbar on or off
845 if(!m_pShowSettingsToolBar
->isChecked())
847 toolBar("settingsToolBar")->hide();
851 toolBar("settingsToolBar")->show();
855 void KmagApp::slotConfKeys()
857 KShortcutsDialog::configure( actionCollection() );
860 void KmagApp::slotEditToolbars()
862 KConfigGroup
cg( KGlobal::config(), "MainWindow" );
863 saveMainWindowSettings( cg
);
864 KEditToolBar
dlg( actionCollection() );
865 connect( &dlg
, SIGNAL( newToolbarConfig() ), this, SLOT( slotNewToolbarConfig() ) );
871 void KmagApp::slotNewToolbarConfig()
873 applyMainWindowSettings( KGlobal::config()->group( "MainWindow" ) );