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/QPrinter>
25 #include <QtGui/QPrintDialog>
26 #include <QtGui/QPainter>
27 #include <QtGui/QLayout>
28 #include <QtGui/QClipboard>
29 #include <QtGui/QContextMenuEvent>
30 #include <QtGui/QPixmap>
31 #include <QtGui/QDesktopWidget>
33 // include files for KDE
34 #include <kxmlguiclient.h>
36 #include <ktoggleaction.h>
37 #include <kactioncollection.h>
38 #include <kselectaction.h>
39 #include <kdeversion.h>
40 #include <kxmlguifactory.h>
42 #include <kapplication.h>
43 #include <kstandardshortcut.h>
44 #include <kshortcutsdialog.h>
45 #include <kiconloader.h>
46 #include <kmessagebox.h>
47 #include <kfiledialog.h>
52 #include <kstandardaction.h>
53 #include <khelpmenu.h>
56 #include <kio/netaccess.h>
57 #include <ktemporaryfile.h>
59 #include <kedittoolbar.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
<< i18n("&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
120 * Default destructor.
124 m_zoomView
->showSelRect(false);
127 void KmagApp::initActions()
129 fileNewWindow
= actionCollection()->addAction("new_window");
130 fileNewWindow
->setIcon(KIcon("window-new"));
131 fileNewWindow
->setText(i18n("New &Window"));
132 connect(fileNewWindow
, SIGNAL(triggered(bool) ), SLOT(slotFileNewWindow()));
133 fileNewWindow
->setShortcuts(KStandardShortcut::openNew());
134 fileNewWindow
->setToolTip(i18n("Open a new KMagnifier window"));
136 refreshSwitch
= actionCollection()->addAction("start_stop_refresh");
137 refreshSwitch
->setIcon(KIcon("process-stop"));
138 refreshSwitch
->setText(i18n("&Stop"));
139 connect(refreshSwitch
, SIGNAL(triggered(bool) ), SLOT(slotToggleRefresh()));
140 refreshSwitch
->setShortcuts(KStandardShortcut::reload());
141 refreshSwitch
->setToolTip(i18n("Click to stop window refresh"));
142 refreshSwitch
->setWhatsThis(i18n("Clicking on this icon will <b>start</b> / <b>stop</b>\
143 updating of the display. Stopping the update will zero the processing power\
144 required (CPU usage)"));
146 m_pSnapshot
= actionCollection()->addAction("snapshot");
147 m_pSnapshot
->setIcon(KIcon("ksnapshot"));
148 m_pSnapshot
->setText(i18n("&Save Snapshot As..."));
149 connect(m_pSnapshot
, SIGNAL(triggered(bool) ), SLOT(saveZoomPixmap()));
150 m_pSnapshot
->setShortcuts(KStandardShortcut::save());
151 m_pSnapshot
->setWhatsThis(i18n("Saves the zoomed view to an image file."));
152 m_pSnapshot
->setToolTip(i18n("Save image to a file"));
154 m_pPrint
= actionCollection()->addAction(KStandardAction::Print
, this, SLOT(slotFilePrint()));
155 m_pPrint
->setWhatsThis(i18n("Click on this button to print the current zoomed view."));
157 m_pQuit
= actionCollection()->addAction(KStandardAction::Quit
, this, SLOT(slotFileQuit()));
158 m_pQuit
->setToolTip(i18n("Quits the application"));
159 m_pQuit
->setWhatsThis (i18n("Quits the application"));
161 m_pCopy
= actionCollection()->addAction(KStandardAction::Copy
, this, SLOT(copyToClipBoard()));
162 m_pCopy
->setWhatsThis(i18n("Click on this button to copy the current zoomed view to the clipboard which you can paste in other applications."));
163 m_pCopy
->setToolTip(i18n("Copy zoomed image to clipboard"));
165 m_pShowMenu
= new KToggleAction(KIcon("show-menu"), i18n("Show &Menu"), this);
166 actionCollection()->addAction("show_menu", m_pShowMenu
);
167 connect(m_pShowMenu
, SIGNAL(triggered(bool)), SLOT(slotShowMenu()));
168 m_pShowMenu
->setShortcut(Qt::CTRL
+Qt::Key_M
);
169 #ifdef havesetCheckedState
170 m_pShowMenu
->setCheckedState(KGuiItem(i18n("Hide &Menu")));
172 m_pShowMainToolBar
= new KToggleAction(i18n("Show Main &Toolbar"), this);
173 actionCollection()->addAction("show_mainToolBar", m_pShowMainToolBar
);
174 connect(m_pShowMainToolBar
, SIGNAL(triggered(bool)), SLOT(slotShowMainToolBar()));
175 #ifdef havesetCheckedState
176 m_pShowMainToolBar
->setCheckedState(KGuiItem(i18n("Hide Main &Toolbar")));
178 m_pShowViewToolBar
= new KToggleAction(i18n("Show &View Toolbar"), this);
179 actionCollection()->addAction("show_viewToolBar", m_pShowViewToolBar
);
180 connect(m_pShowViewToolBar
, SIGNAL(triggered(bool)), SLOT(slotShowViewToolBar()));
181 #ifdef havesetCheckedState
182 m_pShowViewToolBar
->setCheckedState(KGuiItem(i18n("Hide &View Toolbar")));
184 m_pShowSettingsToolBar
= new KToggleAction(i18n("Show &Settings Toolbar"), this);
185 actionCollection()->addAction("show_settingsToolBar", m_pShowSettingsToolBar
);
186 connect(m_pShowSettingsToolBar
, SIGNAL(triggered(bool)), SLOT(slotShowSettingsToolBar()));
187 #ifdef havesetCheckedState
188 m_pShowSettingsToolBar
->setCheckedState(KGuiItem(i18n("Hide &Settings Toolbar")));
191 m_modeFollowMouse
= new KToggleAction(KIcon("followmouse"), i18n("&Follow Mouse Mode"), this);
192 actionCollection()->addAction("mode_followmouse", m_modeFollowMouse
);
193 connect(m_modeFollowMouse
, SIGNAL(triggered(bool)), SLOT(slotModeFollowMouse()));
194 m_modeFollowMouse
->setShortcut(Qt::Key_F1
);
195 m_modeFollowMouse
->setToolTip(i18n("Magnify around the mouse cursor"));
196 m_modeFollowMouse
->setWhatsThis(i18n("If selected, the area around the mouse cursor is magnified"));
198 m_modeSelWin
= new KToggleAction(KIcon("window"), i18n("Se&lection Window Mode"), this);
199 actionCollection()->addAction("mode_selectionwindow", m_modeSelWin
);
200 connect(m_modeSelWin
, SIGNAL(triggered(bool)), SLOT(slotModeSelWin()));
201 m_modeSelWin
->setShortcut(Qt::Key_F2
);
202 m_modeSelWin
->setToolTip(i18n("Show a window for selecting the magnified area"));
204 m_modeWholeScreen
= new KToggleAction(KIcon("view-fullscreen"), i18n("&Whole Screen Mode"), this);
205 actionCollection()->addAction("mode_wholescreen", m_modeWholeScreen
);
206 connect(m_modeWholeScreen
, SIGNAL(triggered(bool)), SLOT(slotModeWholeScreen()));
207 m_modeWholeScreen
->setShortcut(Qt::Key_F3
);
208 m_modeWholeScreen
->setToolTip(i18n("Magnify the whole screen"));
209 m_modeWholeScreen
->setWhatsThis(i18n("Click on this button to fit the zoom view to the zoom window."));
211 m_hideCursor
= new KToggleAction(KIcon("hidemouse"), i18n("Hide Mouse &Cursor"), this);
212 actionCollection()->addAction("hidecursor", m_hideCursor
);
213 connect(m_hideCursor
, SIGNAL(triggered(bool)), SLOT(slotToggleHideCursor()));
214 m_hideCursor
->setShortcut(Qt::Key_F4
);
215 #ifdef havesetCheckedState
216 m_hideCursor
->setCheckedState(KGuiItem(i18n("Show Mouse &Cursor")));
218 m_hideCursor
->setToolTip(i18n("Hide the mouse cursor"));
220 m_pZoomIn
= actionCollection()->addAction(KStandardAction::ZoomIn
, this, SLOT(zoomIn()));
221 m_pZoomIn
->setWhatsThis(i18n("Click on this button to <b>zoom-in</b> on the selected region."));
223 m_pZoomBox
= new KSelectAction(i18n("&Zoom"), this);
224 actionCollection()->addAction("zoom", m_pZoomBox
);
225 m_pZoomBox
->setItems(zoomArrayString
);
226 m_pZoomBox
->setWhatsThis(i18n("Select the zoom factor."));
227 m_pZoomBox
->setToolTip(i18n("Zoom factor"));
229 m_pZoomOut
= actionCollection()->addAction(KStandardAction::ZoomOut
, this, SLOT(zoomOut()));
230 m_pZoomOut
->setWhatsThis(i18n("Click on this button to <b>zoom-out</b> on the selected region."));
232 m_pRotationBox
= new KSelectAction(i18n("&Rotation"),this);
233 actionCollection()->addAction("rotation", m_pRotationBox
);
234 m_pRotationBox
->setItems(rotationArrayString
);
235 m_pRotationBox
->setWhatsThis(i18n("Select the rotation degree."));
236 m_pRotationBox
->setToolTip(i18n("Rotation degree"));
238 // KHelpMenu *newHelpMenu = new KHelpMenu(this, KGlobal::mainComponent().aboutData());
240 m_keyConf
= actionCollection()->addAction(KStandardAction::KeyBindings
, this, SLOT(slotConfKeys()));
241 m_toolConf
= actionCollection()->addAction(KStandardAction::ConfigureToolbars
, this, SLOT(slotEditToolbars()));
243 m_pFPSBox
= new KSelectAction(i18n("&Refresh"),this);
244 actionCollection()->addAction("fps_selector", m_pFPSBox
);
245 m_pFPSBox
->setItems(fpsArrayString
);
246 m_pFPSBox
->setWhatsThis(i18n("Select the refresh rate. The higher the rate, the more computing power (CPU) will be needed."));
247 m_pFPSBox
->setToolTip(i18n("Refresh rate"));
249 m_pColorBox
= new KSelectAction(i18n("&Color"),this);
250 actionCollection()->addAction("color_mode", m_pColorBox
);
251 m_pColorBox
->setItems(colorArrayString
);
252 m_pColorBox
->setWhatsThis(i18n("Select a mode to simulate various types of color-blindness."));
253 m_pColorBox
->setToolTip(i18n("Color-blindness Simulation Mode"));
258 void KmagApp::initView()
260 m_zoomView
= new KMagZoomView( this, "ZoomView" );
261 m_zoomView
->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType
)7, (QSizePolicy::SizeType
)7, m_zoomView
->sizePolicy().hasHeightForWidth() ) );
262 m_zoomView
->setFrameShape( QFrame::StyledPanel
);
263 m_zoomView
->setFrameShadow( QFrame::Raised
);
265 setCentralWidget(m_zoomView
);
269 void KmagApp::slotChangeZoomBoxIndex(int index
)
271 m_pZoomBox
->setCurrentItem(index
);
274 void KmagApp::slotChangeRotationBoxIndex(int index
)
276 m_pRotationBox
->setCurrentItem(index
);
279 void KmagApp::slotChangeFPSIndex(int index
)
281 m_pFPSBox
->setCurrentItem(index
);
284 void KmagApp::slotChangeColorIndex(int index
)
286 m_pColorBox
->setCurrentItem(index
);
290 * Initialize all connections.
292 void KmagApp::initConnections()
294 // change in zoom value -> update the view
295 connect(this, SIGNAL(updateZoomValue(float)), m_zoomView
, SLOT(setZoom(float)));
296 connect(this, SIGNAL(updateRotationValue(int)), m_zoomView
, SLOT(setRotation(int)));
297 connect(this, SIGNAL(updateFPSValue(float)), m_zoomView
, SLOT(setRefreshRate(float)));
298 connect(this, SIGNAL(updateColorValue(int)), m_zoomView
, SLOT(setColorMode(int)));
300 // change in zoom index -> update the selector
301 connect(this, SIGNAL(updateZoomIndex(int)), this, SLOT(slotChangeZoomBoxIndex(int)));
302 connect(this, SIGNAL(updateRotationIndex(int)), this, SLOT(slotChangeRotationBoxIndex(int)));
303 connect(this, SIGNAL(updateFPSIndex(int)), this, SLOT(slotChangeFPSIndex(int)));
304 connect(this, SIGNAL(updateColorIndex(int)), this, SLOT(slotChangeColorIndex(int)));
306 // selector selects a zoom index -> set the zoom index
307 connect(m_pZoomBox
, SIGNAL(triggered(int)), this, SLOT(setZoomIndex(int)));
308 connect(m_pRotationBox
, SIGNAL(triggered(int)), this, SLOT(setRotationIndex(int)));
309 connect(m_pFPSBox
, SIGNAL(triggered(int)), this, SLOT(setFPSIndex(int)));
310 connect(m_pColorBox
, SIGNAL(triggered(int)), this, SLOT(setColorIndex(int)));
314 * Save options to config file.
316 void KmagApp::saveOptions()
318 KConfigGroup
cg( config
, "General Options");
319 cg
.writeEntry("Geometry", size());
320 cg
.writeEntry("ZoomIndex", m_zoomIndex
);
321 cg
.writeEntry("RotationIndex", m_rotationIndex
);
322 cg
.writeEntry("FPSIndex", m_fpsIndex
);
323 cg
.writeEntry("ColorIndex", m_colorIndex
);
324 cg
.writeEntry("SelRect", m_zoomView
->getSelRectPos());
325 cg
.writeEntry("ShowMouse", m_zoomView
->getShowMouseType());
327 if (m_modeFollowMouse
->isChecked())
328 cg
.writeEntry("Mode", "followmouse");
329 else if (m_modeWholeScreen
->isChecked())
330 cg
.writeEntry("Mode", "wholescreen");
331 else if (m_modeSelWin
->isChecked())
332 cg
.writeEntry("Mode", "selectionwindow");
334 cg
.writeEntry("ShowMenu", m_pShowMenu
->isChecked());
335 cg
.writeEntry("ShowMainToolBar", m_pShowMainToolBar
->isChecked());
336 cg
.writeEntry("ShowViewToolBar", m_pShowViewToolBar
->isChecked());
337 cg
.writeEntry("ShowSettingsToolBar", m_pShowSettingsToolBar
->isChecked());
339 KConfigGroup
mainToolBarGroup(config
,"Main ToolBar");
340 toolBar("mainToolBar")->saveSettings( mainToolBarGroup
);
341 KConfigGroup
viewToolBarGroup(config
,"View ToolBar" );
342 toolBar("viewToolBar")->saveSettings( viewToolBarGroup
);
343 KConfigGroup
settingsToolbarGroup(config
,"Settings ToolBar" );
344 toolBar("settingsToolBar")->saveSettings( settingsToolbarGroup
);
349 * Read settings from config file.
351 void KmagApp::readOptions()
353 QColor
blue (0,0,128);
354 QColor
yellow (255,255,0);
355 QColor
white (255,255,255);
357 KConfigGroup
cgWM( config
, "WM");
359 cgWM
.readEntry("inactiveBackground", blue
),
360 cgWM
.readEntry("inactiveForeground", white
),
361 cgWM
.readEntry("inactiveTitleBtnBg", yellow
));
363 KConfigGroup
cg(config
,"General Options");
365 QSize
defSize(460,390);
366 QSize size
=cg
.readEntry("Geometry", defSize
);
372 // set zoom - defaults to 2x
373 unsigned int zoomIndex
= cg
.readEntry("ZoomIndex", 4);
374 setZoomIndex(zoomIndex
);
375 emit
updateZoomIndex(m_zoomIndex
);
377 unsigned int rotationIndex
= cg
.readEntry("RotationIndex", 0);
378 setRotationIndex(rotationIndex
);
379 emit
updateRotationIndex(m_rotationIndex
);
381 unsigned int fpsIndex
= cg
.readEntry("FPSIndex", 2);
382 setFPSIndex(fpsIndex
);
383 emit
updateFPSIndex(m_fpsIndex
);
385 unsigned int colorIndex
= cg
.readEntry("ColorIndex", 0);
386 setColorIndex(colorIndex
);
387 emit
updateColorIndex(colorIndex
);
389 QString mode
= cg
.readEntry("Mode", "followmouse");
390 if (mode
== "wholescreen")
391 slotModeWholeScreen();
392 else if (mode
== "selectionwindow")
395 slotModeFollowMouse();
397 QRect
defaultRect(0,0,211,164);
398 m_zoomView
->setSelRectPos(cg
.readEntry("SelRect", defaultRect
));
400 m_mouseCursorType
= cg
.readEntry("ShowMouse", m_defaultMouseCursorType
);
401 m_zoomView
->showMouse(m_mouseCursorType
);
402 if(m_mouseCursorType
)
403 m_hideCursor
->setChecked(false);
405 m_hideCursor
->setChecked(true);
407 KConfigGroup
settingsToolbarGroup(config
,"Settings ToolBar");
408 if( settingsToolbarGroup
.exists() )
409 toolBar("settingsToolBar")->applySettings(settingsToolbarGroup
);
411 KConfigGroup
mainToolbarGroup(config
,"Main ToolBar");
412 if( mainToolbarGroup
.exists() )
413 toolBar("mainToolBar")->applySettings( mainToolbarGroup
);
415 KConfigGroup
viewToolbarGroup(config
,"View ToolBar" );
416 if( viewToolbarGroup
.exists() )
417 toolBar("viewToolBar")->applySettings( viewToolbarGroup
);
419 KConfigGroup
generalOptionGroup(config
,"General Options");
420 m_pShowMenu
->setChecked( generalOptionGroup
.readEntry("ShowMenu", true));
423 m_pShowMainToolBar
->setChecked(generalOptionGroup
.readEntry("ShowMainToolBar", false));
424 slotShowMainToolBar();
426 m_pShowViewToolBar
->setChecked(generalOptionGroup
.readEntry("ShowViewToolBar", true));
427 slotShowViewToolBar();
429 m_pShowSettingsToolBar
->setChecked(generalOptionGroup
.readEntry("ShowSettingsToolBar", true));
430 slotShowSettingsToolBar();
433 bool KmagApp::queryClose()
438 bool KmagApp::queryExit()
445 * Called when mouse is clicked inside the window
449 void KmagApp::contextMenuEvent ( QContextMenuEvent
* e
)
452 KXMLGUIFactory
*factory
= this->factory();
453 QMenu
*popup
= (QMenu
*)factory
->container("mainPopUp",this);
455 popup
->popup(e
->globalPos(), 0);
460 /////////////////////////////////////////////////////////////////////
461 // SLOT IMPLEMENTATION
462 /////////////////////////////////////////////////////////////////////
465 * Shows/hides the mouse cursor
467 void KmagApp::showMouseCursor(bool show
)
470 if(m_mouseCursorType
== 0)
471 m_mouseCursorType
= m_defaultMouseCursorType
;
472 m_zoomView
->showMouse(m_mouseCursorType
);
474 m_zoomView
->showMouse(0);
481 void KmagApp::zoomIn()
483 // set the new index .. checking will done inside setZoom
484 setZoomIndex(m_zoomIndex
+1);
485 // signal change in zoom index
486 emit
updateZoomIndex((int)m_zoomIndex
);
492 void KmagApp::zoomOut()
494 // set the new index .. checking will done inside setZoom
495 setZoomIndex(m_zoomIndex
-1);
496 // signal change in zoom index
497 emit
updateZoomIndex((int)m_zoomIndex
);
500 * Sets the zoom index to index
502 void KmagApp::setZoomIndex(int index
)
504 if(index
< 0 || index
>= (int)zoomArray
.size()) {
505 // the index is invalid
506 kWarning() << "Invalid index!" ;
508 } else if((int)m_zoomIndex
== index
) {
515 if(m_zoomIndex
== 0) {
516 // meaning that no more zooming-out is possible
517 // -> disable zoom-out icon
518 m_pZoomOut
->setEnabled(false);
519 } else { // enable the icon
520 m_pZoomOut
->setEnabled(true);
523 if(m_zoomIndex
== zoomArray
.size()-1) {
524 // meaning that no more zooming-in is possible
525 // -> disable zoom-in icon
526 m_pZoomIn
->setEnabled(false);
527 } else { // enable the icon
528 m_pZoomIn
->setEnabled(true);
531 // signal change in zoom value
532 emit
updateZoomValue(zoomArray
[m_zoomIndex
]);
536 * Sets the rotation index to index
538 void KmagApp::setRotationIndex(int index
)
540 if(index
< 0 || index
>= (int)rotationArray
.size()) {
541 // the index is invalid
542 kWarning() << "Invalid index!" ;
544 } else if((int)m_rotationIndex
== index
) {
548 m_rotationIndex
= index
;
551 // signal change in zoom value
552 emit
updateRotationValue(rotationArray
[m_rotationIndex
]);
556 * Sets the fps index to index
558 void KmagApp::setFPSIndex(int index
)
560 if(index
< 0 || index
>= (int)fpsArray
.size()) {
561 // the index is invalid
562 kWarning() << "Invalid index!" ;
564 } else if((int)m_fpsIndex
== index
) {
571 // signal change in fps value
572 emit
updateFPSValue(fpsArray
[m_fpsIndex
]);
576 * Sets the color index to index
578 void KmagApp::setColorIndex(int index
)
580 if(index
< 0 || index
>= (int)colorArray
.size()) {
581 // the index is invalid
582 kWarning() << "Invalid index!" ;
584 } else if((int)m_colorIndex
== index
) {
588 m_colorIndex
= index
;
591 // signal change in fps value
592 emit
updateColorValue(colorArray
[m_colorIndex
]);
596 * Save the zoomed image
598 void KmagApp::saveZoomPixmap()
602 // stop refresh temporarily
603 if (m_zoomView
->getRefreshStatus()) {
608 KUrl url
= KFileDialog::getSaveUrl(QString(),
609 KImageIO::pattern(KImageIO::Writing
),
610 0,i18n("Save Snapshot As"));
612 if(!url
.fileName().isEmpty()) {
613 if(!url
.isLocalFile()) {
614 // create a temp file.. save image to it.. copy over the n/w and then delete the temp file.
615 KTemporaryFile tempFile
;
617 #warning "kde4: port KImageIO::type \n";
619 if(!tempFile
.open() || !m_zoomView
->getPixmap().save(tempFile
.fileName(),"png"/*, KImageIO::type(url.fileName()).latin1()*/)) {
620 KMessageBox::error(0, i18n("Unable to save temporary file (before uploading to the network file you specified)."),
621 i18n("Error Writing File"));
623 if(!KIO::NetAccess::upload(tempFile
.fileName(), url
, this)) {
624 KMessageBox::error(0, i18n("Unable to upload file over the network."),
625 i18n("Error Writing File"));
627 KMessageBox::information(0, i18n("Current zoomed image saved to\n%1", url
.prettyUrl()),
628 i18n("Information"), "save_confirm");
634 #warning "kde4 : port KImageIO::type(...) \n";
636 if(!m_zoomView
->getPixmap().save(url
.path(), "png"/*KImageIO::type(url.fileName()).latin1()*/)) {
637 KMessageBox::error(0, i18n("Unable to save file. Please check if you have permission to write to the directory."),
638 i18n("Error Writing File"));
640 KMessageBox::information(0, i18n("Current zoomed image saved to\n%1", url
.prettyUrl()),
641 i18n("Information"), "save_confirm");
651 void KmagApp::slotToggleRefresh()
653 m_zoomView
->toggleRefresh();
654 if(m_zoomView
->getRefreshStatus()) {
655 refreshSwitch
->setIcon(KIcon("stop.png"));
656 refreshSwitch
->setText(i18n("Stop"));
657 refreshSwitch
->setToolTip(i18n("Click to stop window update"));
659 refreshSwitch
->setIcon(KIcon("reload.png"));
660 refreshSwitch
->setText(i18n("Start"));
661 refreshSwitch
->setToolTip(i18n("Click to start window update"));
666 void KmagApp::slotModeWholeScreen()
668 m_zoomView
->setSelRectPos(QRect (0, 0, QApplication::desktop()->width(), QApplication::desktop()->height()));
669 m_zoomView
->followMouse(false);
670 m_zoomView
->showSelRect(false);
671 m_zoomView
->setFitToWindow (false);
672 m_modeFollowMouse
->setChecked(false);
673 m_modeWholeScreen
->setChecked(true);
674 m_modeSelWin
->setChecked(false);
678 void KmagApp::slotModeSelWin()
680 m_zoomView
->followMouse(false);
681 m_zoomView
->showSelRect(true);
682 m_zoomView
->setFitToWindow (false);
683 m_modeFollowMouse
->setChecked(false);
684 m_modeWholeScreen
->setChecked(false);
685 m_modeSelWin
->setChecked(true);
689 void KmagApp::slotModeFollowMouse()
691 m_zoomView
->followMouse(true);
692 m_zoomView
->showSelRect(false);
693 m_zoomView
->setFitToWindow (true);
694 m_modeFollowMouse
->setChecked(true);
695 m_modeWholeScreen
->setChecked(false);
696 m_modeSelWin
->setChecked(false);
700 void KmagApp::slotToggleHideCursor()
702 showMouseCursor(!m_hideCursor
->isChecked());
706 void KmagApp::slotFileNewWindow()
708 KmagApp
*new_window
= new KmagApp();
713 void KmagApp::slotFilePrint()
715 #ifndef QT_NO_PRINTER
721 // stop refresh temporarily
722 if (m_zoomView
->getRefreshStatus()) {
727 const QPixmap
pixmap(m_zoomView
->getPixmap());
729 // use some AI to get the best orientation
730 if(pixmap
.width() > pixmap
.height()) {
731 printer
.setOrientation(QPrinter::Landscape
);
733 printer
.setOrientation(QPrinter::Portrait
);
736 QPrintDialog
printDialog(&printer
, this);
738 if (printDialog
.exec()) {
741 if(!paint
.begin(&printer
))
744 paint
.drawPixmap(0, 0, pixmap
);
752 #endif // QT_NO_PRINTER
755 void KmagApp::slotFileQuit()
758 // close the first window, the list makes the next one the first again.
759 // This ensures that queryClose() is called on each window to ask for closing
761 if (!memberList().isEmpty())
763 for (int i
= 0; i
< memberList().size(); ++i
)
765 w
= memberList().at(i
);
766 // only close the window if the closeEvent is accepted. If the user presses Cancel on the saveModified() dialog,
767 // the window and the application stay open.
771 #warning "kde4: now memberList() is constant => we can't remove some element!"
773 //memberList()->removeRef(w);
778 void KmagApp::copyToClipBoard()
780 QClipboard
*cb
=KApplication::clipboard();
781 cb
->setPixmap(m_zoomView
->getPixmap());
784 void KmagApp::slotShowMenu()
786 ///////////////////////////////////////////////////////////////////
787 // turn Menu on or off
788 if(!m_pShowMenu
->isChecked())
800 void KmagApp::slotShowMainToolBar()
802 ///////////////////////////////////////////////////////////////////
803 // turn mainToolbar on or off
804 if(!m_pShowMainToolBar
->isChecked())
806 toolBar("mainToolBar")->hide();
810 toolBar("mainToolBar")->show();
814 void KmagApp::slotShowViewToolBar()
816 ///////////////////////////////////////////////////////////////////
817 // turn viewToolbar on or off
818 if(!m_pShowViewToolBar
->isChecked())
820 toolBar("viewToolBar")->hide();
824 toolBar("viewToolBar")->show();
828 void KmagApp::slotShowSettingsToolBar()
830 ///////////////////////////////////////////////////////////////////
831 // turn viewToolbar on or off
832 if(!m_pShowSettingsToolBar
->isChecked())
834 toolBar("settingsToolBar")->hide();
838 toolBar("settingsToolBar")->show();
842 void KmagApp::slotConfKeys()
844 KShortcutsDialog::configure( actionCollection() );
847 void KmagApp::slotEditToolbars()
849 KConfigGroup
cg( KGlobal::config(), "MainWindow" );
850 saveMainWindowSettings( cg
);
851 KEditToolBar
dlg( actionCollection() );
852 connect( &dlg
, SIGNAL( newToolbarConfig() ), this, SLOT( slotNewToolbarConfig() ) );
858 void KmagApp::slotNewToolbarConfig()
860 applyMainWindowSettings( KGlobal::config()->group( "MainWindow" ) );