kmag.cpp 27.6 KB
Newer Older
Sarang Lakare's avatar
Sarang Lakare committed
1
2
3
4
/***************************************************************************
                          kmag.cpp  -  description
                             -------------------
    begin                : Mon Feb 12 23:45:41 EST 2001
5
    copyright            : (C) 2001-2003 by Sarang Lakare
Sarang Lakare's avatar
Sarang Lakare committed
6
    email                : sarang#users.sourceforge.net
7
    copyright            : (C) 2003-2004 by Olaf Schmidt
8
    email                : ojschmidt@kde.org
9
10
    copyright            : (C) 2008 by Matthew Woehlke
    email                : mw_triad@users.sourceforge.net
Sebastian Sauer's avatar
Sebastian Sauer committed
11
12
    copyright              (C) 2010 Sebastian Sauer
    email                  sebsauer@kdab.com
Sarang Lakare's avatar
Sarang Lakare committed
13
14
15
16
17
18
19
20
21
22
23
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

Christoph Feck's avatar
Christoph Feck committed
24
// include files for Qt
25
#include <QApplication>
Christoph Feck's avatar
Christoph Feck committed
26
#include <QClipboard>
Christoph Feck's avatar
Christoph Feck committed
27
#include <QDebug>
Christoph Feck's avatar
Christoph Feck committed
28
#include <QDesktopWidget>
29
#include <QFileDialog>
Christoph Feck's avatar
Christoph Feck committed
30
#include <QImageWriter>
Christoph Feck's avatar
Christoph Feck committed
31
#include <QMenuBar>
Christoph Feck's avatar
Christoph Feck committed
32
#include <QPainter>
Christoph Feck's avatar
Christoph Feck committed
33
#include <QPrintDialog>
34
#include <QTemporaryFile>
Laurent Montel's avatar
Laurent Montel committed
35

36
// include files for KF5
Christoph Feck's avatar
Christoph Feck committed
37
38
39
40
41
42
43
44
45
#include <KActionCollection>
#include <KConfigGroup>
#include <KEditToolBar>
#include <KLocalizedString>
#include <KMessageBox>
#include <KSelectAction>
#include <KShortcutsDialog>
#include <KToggleAction>
#include <KXMLGUIFactory>
46
#include <KIO/FileCopyJob>
Sarang Lakare's avatar
Sarang Lakare committed
47
48

// application specific includes
Christoph Feck's avatar
Christoph Feck committed
49
#include "kmag.h"
Sarang Lakare's avatar
Sarang Lakare committed
50
#include "kmagzoomview.h"
Sarang Lakare's avatar
Sarang Lakare committed
51
52
#include "kmagselrect.h"

53

54
KmagApp::KmagApp(QWidget* , const char* name)
55
56
  : KXmlGuiWindow(0) // Qt::WStyle_MinMax | Qt::WType_TopLevel | Qt::WDestructiveClose | Qt::WStyle_ContextHelp | Qt::WindowCloseButtonHint | Qt::WStyle_StaysOnTop
  , m_defaultMouseCursorType(2)
Sarang Lakare's avatar
Sarang Lakare committed
57
{
58
  setObjectName( QLatin1String( name ) );
59
  setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
60
  config=KSharedConfig::openConfig();
Sarang Lakare's avatar
Sarang Lakare committed
61

62
63
  zoomArrayString << QStringLiteral( "5:1" ) << QStringLiteral( "2:1" ) << QStringLiteral( "1:1" ) << QStringLiteral( "1:1.5" ) << QStringLiteral( "1:2" ) << QStringLiteral( "1:3" ) << QStringLiteral( "1:4" ) << QStringLiteral( "1:5" )
    << QStringLiteral( "1:6" ) << QStringLiteral( "1:7" ) << QStringLiteral( "1:8" ) << QStringLiteral( "1:12" ) << QStringLiteral( "1:16" ) << QStringLiteral( "1:20" );
64

Christoph Feck's avatar
Christoph Feck committed
65
66
67
68
  zoomArray << 0.2 <<0.5 << 1.0;
  zoomArray << 1.5 << 2.0 << 3.0;
  zoomArray << 4.0 << 5.0 << 6.0 << 7.0;
  zoomArray << 8.0 << 12.0 << 16.0 << 20.0;
69

70
  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");
Sarang Lakare's avatar
Sarang Lakare committed
71

Christoph Feck's avatar
Christoph Feck committed
72
73
74
75
76
  fpsArray.append(2); // very low
  fpsArray.append(6); // low
  fpsArray.append(10); // medium
  fpsArray.append(15); // high
  fpsArray.append(25); // very high
Sarang Lakare's avatar
Sarang Lakare committed
77

78
  colorArrayString << i18nc("No color-blindness simulation, i.e. 'normal' vision", "&Normal") << i18n("&Protanopia") << i18n("&Deuteranopia") << i18n("&Tritanopia") << i18n("&Achromatopsia");
79

Christoph Feck's avatar
Christoph Feck committed
80
81
82
83
84
  colorArray.append(0);
  colorArray.append(1);
  colorArray.append(2);
  colorArray.append(3);
  colorArray.append(4);
85

86
  rotationArrayString << i18n("&No Rotation (0 Degrees)") << i18n("&Left (90 Degrees)") << i18n("&Upside Down (180 Degrees)") << i18n("&Right (270 Degrees)");
87

Christoph Feck's avatar
Christoph Feck committed
88
89
90
91
  rotationArray.append(0); // no rotation
  rotationArray.append(90); // left
  rotationArray.append(180); // upside down
  rotationArray.append(270); // right
92

Sarang Lakare's avatar
Sarang Lakare committed
93
94
95
  // call inits to invoke all other construction parts
  initView();
  initActions();
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
96
  initConnections();
Laurent Montel's avatar
Laurent Montel committed
97

98
  // read options from config file
Sarang Lakare's avatar
Sarang Lakare committed
99
100
  readOptions();

101
102
103
  #ifndef QT_NO_PRINTER
  m_printer = 0;
  #endif // QT_NO_PRINTER
Sarang Lakare's avatar
Sarang Lakare committed
104
105
}

Sarang Lakare's avatar
Sarang Lakare committed
106
107
108
/**
 * Default destructor.
 */
Sarang Lakare's avatar
Sarang Lakare committed
109
110
KmagApp::~KmagApp()
{
111
    m_zoomView->showSelRect(false);
112
113
114
115

    #ifndef QT_NO_PRINTER
    delete m_printer;
    #endif // QT_NO_PRINTER
Sarang Lakare's avatar
Sarang Lakare committed
116
117
118
119
}

void KmagApp::initActions()
{
120
121
  fileNewWindow = actionCollection()->addAction(QStringLiteral( "new_window" ));
  fileNewWindow->setIcon(QIcon::fromTheme(QStringLiteral( "window-new" )));
Simon Hausmann's avatar
ported    
Simon Hausmann committed
122
  fileNewWindow->setText(i18n("New &Window"));
123
  connect(fileNewWindow, &QAction::triggered, this, &KmagApp::slotFileNewWindow);
124
  actionCollection()->setDefaultShortcuts(fileNewWindow, KStandardShortcut::openNew());
125
  fileNewWindow->setToolTip(i18n("Open a new KMagnifier window"));
Sarang Lakare's avatar
Sarang Lakare committed
126

127
128
  refreshSwitch = actionCollection()->addAction(QStringLiteral( "start_stop_refresh" ));
  refreshSwitch->setIcon(QIcon::fromTheme(QStringLiteral( "process-stop" )));
Simon Hausmann's avatar
ported    
Simon Hausmann committed
129
  refreshSwitch->setText(i18n("&Stop"));
130
  connect(refreshSwitch, &QAction::triggered, this, &KmagApp::slotToggleRefresh);
131
  actionCollection()->setDefaultShortcuts(refreshSwitch, KStandardShortcut::reload());
Sarang Lakare's avatar
Sarang Lakare committed
132
  refreshSwitch->setToolTip(i18n("Click to stop window refresh"));
133
134
135
  refreshSwitch->setWhatsThis(i18n("Clicking on this icon will <b>start</b> / <b>stop</b> "
                                   "updating of the display. Stopping the update will zero the processing power "
                                   "required (CPU usage)"));
136

137
138
  m_pSnapshot = actionCollection()->addAction(QStringLiteral( "snapshot" ));
  m_pSnapshot->setIcon(QIcon::fromTheme(QStringLiteral( "ksnapshot" )));
Simon Hausmann's avatar
ported    
Simon Hausmann committed
139
  m_pSnapshot->setText(i18n("&Save Snapshot As..."));
140
  connect(m_pSnapshot, &QAction::triggered, this, &KmagApp::saveZoomPixmap);
141
  actionCollection()->setDefaultShortcuts(m_pSnapshot, KStandardShortcut::save());
142
  m_pSnapshot->setWhatsThis(i18n("Saves the zoomed view to an image file."));
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
143
  m_pSnapshot->setToolTip(i18n("Save image to a file"));
Sarang Lakare's avatar
Sarang Lakare committed
144

Simon Hausmann's avatar
ported    
Simon Hausmann committed
145
  m_pPrint = actionCollection()->addAction(KStandardAction::Print, this, SLOT(slotFilePrint()));
Sarang Lakare's avatar
Sarang Lakare committed
146
  m_pPrint->setWhatsThis(i18n("Click on this button to print the current zoomed view."));
147

Simon Hausmann's avatar
ported    
Simon Hausmann committed
148
  m_pQuit = actionCollection()->addAction(KStandardAction::Quit, this, SLOT(slotFileQuit()));
Laurent Montel's avatar
Laurent Montel committed
149
  m_pQuit->setToolTip(i18n("Quits the application"));
150
151
  m_pQuit->setWhatsThis (i18n("Quits the application"));

Simon Hausmann's avatar
ported    
Simon Hausmann committed
152
  m_pCopy = actionCollection()->addAction(KStandardAction::Copy, this, SLOT(copyToClipBoard()));
Sarang Lakare's avatar
Sarang Lakare committed
153
  m_pCopy->setWhatsThis(i18n("Click on this button to copy the current zoomed view to the clipboard which you can paste in other applications."));
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
154
  m_pCopy->setToolTip(i18n("Copy zoomed image to clipboard"));
Sarang Lakare's avatar
Sarang Lakare committed
155

156
157
158
  m_pShowMenu = KStandardAction::showMenubar(this, SLOT(slotShowMenu()), actionCollection());

  setStandardToolBarMenuEnabled(true);
159

160
161
162
  m_modeFollowMouse = new KToggleAction(QIcon::fromTheme(QStringLiteral( "followmouse" )), i18n("&Follow Mouse Mode"), this);
  actionCollection()->addAction(QStringLiteral( "mode_followmouse" ), m_modeFollowMouse);
  connect(m_modeFollowMouse, &QAction::triggered, this, &KmagApp::slotModeChanged);
163
  actionCollection()->setDefaultShortcut(m_modeFollowMouse, Qt::Key_F2);
Sebastian Sauer's avatar
Sebastian Sauer committed
164
  m_modeFollowMouse->setIconText(i18n("Mouse"));
165
166
  m_modeFollowMouse->setToolTip(i18n("Magnify around the mouse cursor"));
  m_modeFollowMouse->setWhatsThis(i18n("If selected, the area around the mouse cursor is magnified"));
167

168
#ifdef QAccessibilityClient_FOUND
169

170
  m_modeFollowFocus = new KToggleAction(QIcon::fromTheme(QLatin1String( "view-restore" )), i18n("&Follow Focus Mode"), this);
171
  actionCollection()->addAction(QLatin1String( "mode_followfocus" ), m_modeFollowFocus);
172
  connect(m_modeFollowFocus, SIGNAL(triggered(bool)), SLOT(slotModeChanged()));
173
  actionCollection()->setDefaultShortcut(m_modeFollowFocus, Qt::Key_F8);
Sebastian Sauer's avatar
Sebastian Sauer committed
174
  m_modeFollowFocus->setIconText(i18n("Focus"));
175
176
  m_modeFollowFocus->setToolTip(i18n("Magnify around the keyboard focus"));
  m_modeFollowFocus->setWhatsThis(i18n("If selected, the area around the keyboard cursor is magnified"));
177

178
#endif
179

180
181
182
  m_modeSelWin = new KToggleAction(QIcon::fromTheme(QStringLiteral( "window" )), i18n("Se&lection Window Mode"), this);
  actionCollection()->addAction(QStringLiteral( "mode_selectionwindow" ), m_modeSelWin);
  connect(m_modeSelWin, &QAction::triggered, this, &KmagApp::slotModeSelWin);
183
  actionCollection()->setDefaultShortcut(m_modeSelWin, Qt::Key_F3);
Sebastian Sauer's avatar
Sebastian Sauer committed
184
  m_modeSelWin->setIconText(i18n("Window"));
185
  m_modeSelWin->setToolTip(i18n("Show a window for selecting the magnified area"));
186

187
188
189
  m_modeWholeScreen = new KToggleAction(QIcon::fromTheme(QStringLiteral( "view-fullscreen" )), i18n("&Whole Screen Mode"), this);
  actionCollection()->addAction(QStringLiteral( "mode_wholescreen" ), m_modeWholeScreen);
  connect(m_modeWholeScreen, &QAction::triggered, this, &KmagApp::slotModeWholeScreen);
190
  actionCollection()->setDefaultShortcut(m_modeWholeScreen, Qt::Key_F4);
Sebastian Sauer's avatar
Sebastian Sauer committed
191
  m_modeWholeScreen->setIconText(i18n("Screen"));
192
193
  m_modeWholeScreen->setToolTip(i18n("Magnify the whole screen"));
  m_modeWholeScreen->setWhatsThis(i18n("Click on this button to fit the zoom view to the zoom window."));
194

195
196
197
  m_hideCursor = new KToggleAction(QIcon::fromTheme(QStringLiteral( "hidemouse" )), i18n("Hide Mouse &Cursor"), this);
  actionCollection()->addAction(QStringLiteral( "hidecursor" ), m_hideCursor);
  connect(m_hideCursor, &QAction::triggered, this, &KmagApp::slotToggleHideCursor);
198
  actionCollection()->setDefaultShortcut(m_hideCursor, Qt::Key_F6);
Sebastian Sauer's avatar
Sebastian Sauer committed
199
  #ifdef havesetCheckedStatef
Laurent Montel's avatar
Laurent Montel committed
200
  m_hideCursor->setCheckedState(KGuiItem(i18n("Show Mouse &Cursor")));
201
  #endif
Sebastian Sauer's avatar
Sebastian Sauer committed
202
  m_hideCursor->setIconText(i18n("Hide"));
203
  m_hideCursor->setToolTip(i18n("Hide the mouse cursor"));
204

205
206
207
  m_staysOnTop = new KToggleAction(QIcon::fromTheme(QStringLiteral( "go-top" )), i18n("Stays On Top"), this);
  actionCollection()->addAction(QStringLiteral( "staysontop" ), m_staysOnTop);
  connect(m_staysOnTop, &QAction::triggered, this, &KmagApp::slotStaysOnTop);
208
  actionCollection()->setDefaultShortcut(m_staysOnTop, Qt::Key_F7);
Sebastian Sauer's avatar
Sebastian Sauer committed
209
  m_staysOnTop->setToolTip(i18n("The KMagnifier Window stays on top of other windows."));
210

Simon Hausmann's avatar
ported    
Simon Hausmann committed
211
  m_pZoomIn = actionCollection()->addAction(KStandardAction::ZoomIn, this, SLOT(zoomIn()));
212
213
  m_pZoomIn->setWhatsThis(i18n("Click on this button to <b>zoom-in</b> on the selected region."));

Simon Hausmann's avatar
ported    
Simon Hausmann committed
214
  m_pZoomBox = new KSelectAction(i18n("&Zoom"), this);
215
  actionCollection()->addAction(QStringLiteral( "zoom" ), m_pZoomBox);
216
  m_pZoomBox->setItems(zoomArrayString);
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
217
218
  m_pZoomBox->setWhatsThis(i18n("Select the zoom factor."));
  m_pZoomBox->setToolTip(i18n("Zoom factor"));
219

Simon Hausmann's avatar
ported    
Simon Hausmann committed
220
  m_pZoomOut = actionCollection()->addAction(KStandardAction::ZoomOut, this, SLOT(zoomOut()));
Sarang Lakare's avatar
Sarang Lakare committed
221
  m_pZoomOut->setWhatsThis(i18n("Click on this button to <b>zoom-out</b> on the selected region."));
222

Simon Hausmann's avatar
ported    
Simon Hausmann committed
223
  m_pRotationBox = new KSelectAction(i18n("&Rotation"),this);
224
  actionCollection()->addAction(QStringLiteral( "rotation" ), m_pRotationBox);
225
  m_pRotationBox->setItems(rotationArrayString);
Gunnar Schmidt's avatar
Gunnar Schmidt committed
226
227
  m_pRotationBox->setWhatsThis(i18n("Select the rotation degree."));
  m_pRotationBox->setToolTip(i18n("Rotation degree"));
228

Simon Hausmann's avatar
ported    
Simon Hausmann committed
229
230
  m_keyConf = actionCollection()->addAction(KStandardAction::KeyBindings, this, SLOT(slotConfKeys()));
  m_toolConf = actionCollection()->addAction(KStandardAction::ConfigureToolbars, this, SLOT(slotEditToolbars()));
231

Simon Hausmann's avatar
ported    
Simon Hausmann committed
232
  m_pFPSBox = new KSelectAction(i18n("&Refresh"),this);
233
  actionCollection()->addAction(QStringLiteral( "fps_selector" ), m_pFPSBox);
Sarang Lakare's avatar
Sarang Lakare committed
234
  m_pFPSBox->setItems(fpsArrayString);
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
235
236
  m_pFPSBox->setWhatsThis(i18n("Select the refresh rate. The higher the rate, the more computing power (CPU) will be needed."));
  m_pFPSBox->setToolTip(i18n("Refresh rate"));
Sarang Lakare's avatar
Sarang Lakare committed
237

238
  m_pColorBox = new KSelectAction(i18nc("Color-blindness simulation mode", "&Color"),this);
239
  actionCollection()->addAction(QStringLiteral( "color_mode" ), m_pColorBox);
240
241
242
243
  m_pColorBox->setItems(colorArrayString);
  m_pColorBox->setWhatsThis(i18n("Select a mode to simulate various types of color-blindness."));
  m_pColorBox->setToolTip(i18n("Color-blindness Simulation Mode"));

244
  setupGUI(ToolBar | Keys | Save | Create);
Sarang Lakare's avatar
Sarang Lakare committed
245
246
}

Sarang Lakare's avatar
Sarang Lakare committed
247
248
void KmagApp::initView()
{
249
  m_zoomView = new KMagZoomView( this, "ZoomView" );
250
//m_zoomView->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, m_zoomView->sizePolicy().hasHeightForWidth() ) );
251
  m_zoomView->setFrameShape( QFrame::NoFrame );
Sarang Lakare's avatar
Sarang Lakare committed
252

253
  setCentralWidget(m_zoomView);
Sarang Lakare's avatar
Sarang Lakare committed
254
255
}

Laurent Montel's avatar
Laurent Montel committed
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271

void KmagApp::slotChangeZoomBoxIndex(int index)
{
   m_pZoomBox->setCurrentItem(index);
}

void KmagApp::slotChangeRotationBoxIndex(int index)
{
  m_pRotationBox->setCurrentItem(index);
}

void KmagApp::slotChangeFPSIndex(int index)
{
  m_pFPSBox->setCurrentItem(index);
}

272
273
274
275
void KmagApp::slotChangeColorIndex(int index)
{
  m_pColorBox->setCurrentItem(index);
}
Laurent Montel's avatar
Laurent Montel committed
276

Sarang Lakare's avatar
Sarang Lakare committed
277
278
279
/**
 * Initialize all connections.
 */
280
281
void KmagApp::initConnections()
{
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
282
  // change in zoom value -> update the view
283
284
285
286
  connect(this, &KmagApp::updateZoomValue, m_zoomView, &KMagZoomView::setZoom);
  connect(this, &KmagApp::updateRotationValue, m_zoomView, &KMagZoomView::setRotation);
  connect(this, &KmagApp::updateFPSValue, m_zoomView, &KMagZoomView::setRefreshRate);
  connect(this, &KmagApp::updateColorValue, m_zoomView, &KMagZoomView::setColorMode);
Sarang Lakare's avatar
Sarang Lakare committed
287

Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
288
  // change in zoom index -> update the selector
289
290
291
292
  connect(this, &KmagApp::updateZoomIndex, this, &KmagApp::slotChangeZoomBoxIndex);
  connect(this, &KmagApp::updateRotationIndex, this, &KmagApp::slotChangeRotationBoxIndex);
  connect(this, &KmagApp::updateFPSIndex, this, &KmagApp::slotChangeFPSIndex);
  connect(this, &KmagApp::updateColorIndex, this, &KmagApp::slotChangeColorIndex);
Sarang Lakare's avatar
Sarang Lakare committed
293

Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
294
  // selector selects a zoom index -> set the zoom index
295
296
297
  connect(m_pZoomBox, SIGNAL(triggered(int)), this, SLOT(setZoomIndex(int)));
  connect(m_pRotationBox, SIGNAL(triggered(int)), this, SLOT(setRotationIndex(int)));
  connect(m_pFPSBox, SIGNAL(triggered(int)), this, SLOT(setFPSIndex(int)));
298
  connect(m_pColorBox, SIGNAL(triggered(int)), this, SLOT(setColorIndex(int)));
299
300
}

301
302
303
/**
 * Save options to config file.
 */
Sarang Lakare's avatar
Sarang Lakare committed
304
void KmagApp::saveOptions()
Laurent Montel's avatar
Laurent Montel committed
305
{
Stephan Kulow's avatar
ported    
Stephan Kulow committed
306
307
308
309
310
  KConfigGroup cg( config, "General Options");
  cg.writeEntry("Geometry", size());
  cg.writeEntry("ZoomIndex", m_zoomIndex);
  cg.writeEntry("RotationIndex", m_rotationIndex);
  cg.writeEntry("FPSIndex", m_fpsIndex);
311
  cg.writeEntry("ColorIndex", m_colorIndex);
Stephan Kulow's avatar
ported    
Stephan Kulow committed
312
313
  cg.writeEntry("SelRect", m_zoomView->getSelRectPos());
  cg.writeEntry("ShowMouse", m_zoomView->getShowMouseType());
Sebastian Sauer's avatar
Sebastian Sauer committed
314
  cg.writeEntry("StaysOnTop", m_staysOnTop->isChecked());
315

316
  if (m_modeFollowMouse->isChecked())
Stephan Kulow's avatar
ported    
Stephan Kulow committed
317
     cg.writeEntry("Mode", "followmouse");
318
#ifdef QAccessibilityClient_FOUND
319
320
  else if (m_modeFollowFocus->isChecked())
     cg.writeEntry("Mode", "followfocus");
321
#endif
322
  else if (m_modeWholeScreen->isChecked())
Stephan Kulow's avatar
ported    
Stephan Kulow committed
323
     cg.writeEntry("Mode", "wholescreen");
324
  else if (m_modeSelWin->isChecked())
Stephan Kulow's avatar
ported    
Stephan Kulow committed
325
     cg.writeEntry("Mode", "selectionwindow");
Sarang Lakare's avatar
Sarang Lakare committed
326
327
328
}


329
330
331
/**
 * Read settings from config file.
 */
Sarang Lakare's avatar
Sarang Lakare committed
332
333
void KmagApp::readOptions()
{
334
335
336
337
  QColor blue (0,0,128);
  QColor yellow (255,255,0);
  QColor white (255,255,255);

Laurent Montel's avatar
Laurent Montel committed
338
  KConfigGroup cgWM( config, "WM");
339
  setTitleColors (
Laurent Montel's avatar
Laurent Montel committed
340
341
342
      cgWM.readEntry("inactiveBackground", blue),
      cgWM.readEntry("inactiveForeground", white),
      cgWM.readEntry("inactiveTitleBtnBg", yellow));
343

Laurent Montel's avatar
Laurent Montel committed
344
  KConfigGroup cg(config,"General Options");
Sarang Lakare's avatar
Sarang Lakare committed
345

346
  QSize defSize(460,390);
Stephan Kulow's avatar
ported    
Stephan Kulow committed
347
  QSize size=cg.readEntry("Geometry", defSize);
Sarang Lakare's avatar
Sarang Lakare committed
348
349
350
351
352
  if(!size.isEmpty())
  {
    resize(size);
  }

Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
353
  // set zoom - defaults to 2x
Stephan Kulow's avatar
ported    
Stephan Kulow committed
354
  unsigned int zoomIndex = cg.readEntry("ZoomIndex", 4);
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
355
356
  setZoomIndex(zoomIndex);
  emit updateZoomIndex(m_zoomIndex);
Sarang Lakare's avatar
Sarang Lakare committed
357

Stephan Kulow's avatar
ported    
Stephan Kulow committed
358
  unsigned int rotationIndex = cg.readEntry("RotationIndex", 0);
359
360
361
  setRotationIndex(rotationIndex);
  emit updateRotationIndex(m_rotationIndex);

Stephan Kulow's avatar
ported    
Stephan Kulow committed
362
  unsigned int fpsIndex = cg.readEntry("FPSIndex", 2);
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
363
364
  setFPSIndex(fpsIndex);
  emit updateFPSIndex(m_fpsIndex);
Sarang Lakare's avatar
Sarang Lakare committed
365

366
367
368
  unsigned int colorIndex = cg.readEntry("ColorIndex", 0);
  setColorIndex(colorIndex);
  emit updateColorIndex(colorIndex);
369

Stephan Kulow's avatar
ported    
Stephan Kulow committed
370
  QString mode = cg.readEntry("Mode", "followmouse");
371
  if (mode == QLatin1String( "wholescreen" )) {
372
    slotModeWholeScreen();
373
  } else if (mode == QLatin1String( "selectionwindow" )) {
374
    slotModeSelWin();
375
376
377
378
379
380
381
  } else if (mode == QLatin1String( "followfocus" )) {
    m_modeFollowFocus->setChecked(true);
    slotModeChanged();
  } else {
    m_modeFollowMouse->setChecked(true);
    slotModeChanged();
  }
382

Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
383
  QRect defaultRect(0,0,211,164);
Stephan Kulow's avatar
ported    
Stephan Kulow committed
384
  m_zoomView->setSelRectPos(cg.readEntry("SelRect", defaultRect));
385

Stephan Kulow's avatar
ported    
Stephan Kulow committed
386
  m_mouseCursorType = cg.readEntry("ShowMouse", m_defaultMouseCursorType);
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
387
  m_zoomView->showMouse(m_mouseCursorType);
Sebastian Sauer's avatar
Sebastian Sauer committed
388
  m_hideCursor->setChecked(!m_mouseCursorType);
389

Sebastian Sauer's avatar
Sebastian Sauer committed
390
391
  m_staysOnTop->setChecked(cg.readEntry("StaysOnTop", true));
  slotStaysOnTop();
Stephan Binner's avatar
Stephan Binner committed
392

393
394
  // XMLGui has already read and set up the menuBar for us
  m_pShowMenu->setChecked(menuBar()->isVisible());
395
}
Sarang Lakare's avatar
Sarang Lakare committed
396
397
398
399

bool KmagApp::queryClose()
{
  saveOptions();
400
  return (true);
Sarang Lakare's avatar
Sarang Lakare committed
401
402
}

403
404
405
406
407
/**
 * Called when mouse is clicked inside the window
 *
 * @param e
 */
408
void KmagApp::contextMenuEvent ( QContextMenuEvent * e )
409
{
410
411
 // show popup
 KXMLGUIFactory *factory = this->factory();
412
 QMenu *popup = (QMenu *)factory->container(QStringLiteral( "mainPopUp" ),this);
413
 if (popup != 0)
414
   popup->popup(e->globalPos());
415
 e->accept();
416
417
418
}


Sarang Lakare's avatar
Sarang Lakare committed
419
420
421
422
/////////////////////////////////////////////////////////////////////
// SLOT IMPLEMENTATION
/////////////////////////////////////////////////////////////////////

Sarang Lakare's avatar
Sarang Lakare committed
423
424
425
426
427
/**
 * Shows/hides the mouse cursor
 */
void KmagApp::showMouseCursor(bool show)
{
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
428
  if(show) {
Sarang Lakare's avatar
Sarang Lakare committed
429
430
    if(m_mouseCursorType == 0)
      m_mouseCursorType = m_defaultMouseCursorType;
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
431
432
433
434
    m_zoomView->showMouse(m_mouseCursorType);
  } else {
    m_zoomView->showMouse(0);
  }
Sarang Lakare's avatar
Sarang Lakare committed
435
436
}

437
438
439
440
/**
 * Zoom in.
 */
void KmagApp::zoomIn()
441
{
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
442
443
444
445
  // set the new index .. checking will done inside setZoom
  setZoomIndex(m_zoomIndex+1);
  // signal change in zoom index
  emit updateZoomIndex((int)m_zoomIndex);
446
447
}

448
449
450
451
/**
 * Zoom out.
 */
void KmagApp::zoomOut()
452
{
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
453
454
455
456
  // set the new index .. checking will done inside setZoom
  setZoomIndex(m_zoomIndex-1);
  // signal change in zoom index
  emit updateZoomIndex((int)m_zoomIndex);
457
}
458
459
460
461
/**
 * Sets the zoom index to index
 */
void KmagApp::setZoomIndex(int index)
462
{
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
463
464
  if(index < 0 || index >= (int)zoomArray.size()) {
    // the index is invalid
Christoph Feck's avatar
Christoph Feck committed
465
    qDebug() << "Invalid index!" ;
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
466
    return;
467
  } else if((int)m_zoomIndex == index) {
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
468
469
470
471
472
    // do nothing!
    return;
  } else {
    m_zoomIndex = index;
  }
473
474
475
476
477
478

  if(m_zoomIndex == 0) {
    // meaning that no more zooming-out is possible
    // -> disable zoom-out icon
    m_pZoomOut->setEnabled(false);
  } else { // enable the icon
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
479
480
    m_pZoomOut->setEnabled(true);
  }
481

482
  if(m_zoomIndex == zoomArray.size()-1) {
483
484
    // meaning that no more zooming-in is possible
    // -> disable zoom-in icon
485
486
    m_pZoomIn->setEnabled(false);
  } else { // enable the icon
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
487
488
    m_pZoomIn->setEnabled(true);
  }
Laurent Montel's avatar
Laurent Montel committed
489

Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
490
  // signal change in zoom value
Christoph Feck's avatar
Christoph Feck committed
491
  emit updateZoomValue(zoomArray.at(m_zoomIndex));
492
493
}

494
495
496
497
498
499
500
/**
 * Sets the rotation index to index
 */
void KmagApp::setRotationIndex(int index)
{
  if(index < 0 || index >= (int)rotationArray.size()) {
    // the index is invalid
Christoph Feck's avatar
Christoph Feck committed
501
    qDebug() << "Invalid index!" ;
502
503
504
505
506
507
508
509
510
    return;
  } else if((int)m_rotationIndex == index) {
    // do nothing!
    return;
  } else {
    m_rotationIndex = index;
  }

  // signal change in zoom value
Christoph Feck's avatar
Christoph Feck committed
511
  emit updateRotationValue(rotationArray.at(m_rotationIndex));
512
513
}

Sarang Lakare's avatar
Sarang Lakare committed
514
515
516
517
518
/**
 * Sets the fps index to index
 */
void KmagApp::setFPSIndex(int index)
{
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
519
520
  if(index < 0 || index >= (int)fpsArray.size()) {
    // the index is invalid
Christoph Feck's avatar
Christoph Feck committed
521
    qDebug() << "Invalid index!" ;
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
522
    return;
Sarang Lakare's avatar
Sarang Lakare committed
523
  } else if((int)m_fpsIndex == index) {
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
524
525
526
527
528
529
    // do nothing!
    return;
  } else {
    m_fpsIndex = index;
  }

530
  // signal change in fps value
Christoph Feck's avatar
Christoph Feck committed
531
  emit updateFPSValue(fpsArray.at(m_fpsIndex));
Sarang Lakare's avatar
Sarang Lakare committed
532
533
}

534
535
536
537
538
539
540
/**
 * Sets the color index to index
 */
void KmagApp::setColorIndex(int index)
{
  if(index < 0 || index >= (int)colorArray.size()) {
    // the index is invalid
Christoph Feck's avatar
Christoph Feck committed
541
    qDebug() << "Invalid index!" ;
542
543
544
545
546
547
548
549
550
    return;
  } else if((int)m_colorIndex == index) {
    // do nothing!
    return;
  } else {
    m_colorIndex = index;
  }

  // signal change in fps value
Christoph Feck's avatar
Christoph Feck committed
551
  emit updateColorValue(colorArray.at(m_colorIndex));
552
}
553

Sarang Lakare's avatar
Sarang Lakare committed
554
555
556
557
558
/**
 * Save the zoomed image
 */
void KmagApp::saveZoomPixmap()
{
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
559
  bool toggled(false);
Sarang Lakare's avatar
Sarang Lakare committed
560

Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
561
  // stop refresh temporarily
Sarang Lakare's avatar
Sarang Lakare committed
562
563
  if (m_zoomView->getRefreshStatus()) {
    slotToggleRefresh();
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
564
    toggled = true;
Sarang Lakare's avatar
Sarang Lakare committed
565
566
  }

567
  QStringList mimeTypes;
Christoph Feck's avatar
Christoph Feck committed
568
  QList<QByteArray> supported = QImageWriter::supportedMimeTypes();
569
570
571
572
573
574
  foreach (QByteArray mimeType, supported) {
    mimeTypes.append(QString::fromLatin1(mimeType));
  }

  QFileDialog fileDialog(this);
  fileDialog.setWindowTitle(i18n("Save Snapshot As"));
Christoph Feck's avatar
Christoph Feck committed
575
  fileDialog.setAcceptMode(QFileDialog::AcceptSave);
576
  fileDialog.setDefaultSuffix(QStringLiteral("png"));
577
578
579
580
581
  fileDialog.setMimeTypeFilters(mimeTypes);
  QUrl url;
  if (fileDialog.exec() && !fileDialog.selectedUrls().isEmpty()) {
      url = fileDialog.selectedUrls().at(0);
  }
Sarang Lakare's avatar
Sarang Lakare committed
582

583
  if(!url.fileName().isEmpty()) {
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
584
585
    if(!url.isLocalFile()) {
      // create a temp file.. save image to it.. copy over the n/w and then delete the temp file.
586
      QTemporaryFile tempFile;
Christoph Feck's avatar
Christoph Feck committed
587
      if(!tempFile.open() || !m_zoomView->getImage().save(tempFile.fileName())) {
588
        KMessageBox::error(0, i18n("Unable to save temporary file (before uploading to the network file you specified)."),
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
589
590
                          i18n("Error Writing File"));
      } else {
591
592
        KIO::FileCopyJob *job = KIO::file_copy(QUrl::fromLocalFile(tempFile.fileName()), url);
        if(!job) {
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
593
594
595
          KMessageBox::error(0, i18n("Unable to upload file over the network."),
                            i18n("Error Writing File"));
        } else {
Christoph Feck's avatar
Christoph Feck committed
596
          KMessageBox::information(0, i18n("Current zoomed image saved to\n%1", url.toDisplayString()),
597
                              i18n("Information"), QStringLiteral( "save_confirm" ));
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
598
599
600
601
        }
      }

    } else {
Christoph Feck's avatar
Christoph Feck committed
602
      if(!m_zoomView->getImage().save(url.path())) {
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
603
604
605
        KMessageBox::error(0, i18n("Unable to save file. Please check if you have permission to write to the directory."),
                            i18n("Error Writing File"));
      } else {
Christoph Feck's avatar
Christoph Feck committed
606
        KMessageBox::information(0, i18n("Current zoomed image saved to\n%1", url.toDisplayString()),
607
                                i18n("Information"), QStringLiteral( "save_confirm" ));
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
608
609
610
611
612
613
      }
    }
  }
  if(toggled) {
    slotToggleRefresh();
  }
Sarang Lakare's avatar
Sarang Lakare committed
614
615
616
}


617
618
void KmagApp::slotToggleRefresh()
{
Sarang Lakare's avatar
Sarang Lakare committed
619
620
  m_zoomView->toggleRefresh();
  if(m_zoomView->getRefreshStatus()) {
621
    refreshSwitch->setIcon(QIcon::fromTheme(QStringLiteral( "process-stop" )));
622
    refreshSwitch->setText(i18n("Stop"));
Sarang Lakare's avatar
Sarang Lakare committed
623
    refreshSwitch->setToolTip(i18n("Click to stop window update"));
624
  } else {
625
    refreshSwitch->setIcon(QIcon::fromTheme(QStringLiteral( "system-run" )));
626
    refreshSwitch->setText(i18nc("Start updating the window", "Start"));
Sarang Lakare's avatar
Sarang Lakare committed
627
    refreshSwitch->setToolTip(i18n("Click to start window update"));
628
629
630
  }
}

631
632

void KmagApp::slotModeWholeScreen()
633
{
634
  m_zoomView->followMouse(false);
635
  m_zoomView->setSelRectPos(QRect (0, 0, QApplication::desktop()->width(), QApplication::desktop()->height()));
636
637
638
  m_zoomView->showSelRect(false);
  m_zoomView->setFitToWindow (false);
  m_modeFollowMouse->setChecked(false);
639
#ifdef QAccessibilityClient_FOUND
640
  m_zoomView->followBoth(false);
641
  m_zoomView->followFocus(false);
642
  m_modeFollowFocus->setChecked(false);
643
#endif
644
645
  m_modeWholeScreen->setChecked(true);
  m_modeSelWin->setChecked(false);
646
647
}

648
649

void KmagApp::slotModeSelWin()
650
{
651
652
653
654
  m_zoomView->followMouse(false);
  m_zoomView->showSelRect(true);
  m_zoomView->setFitToWindow (false);
  m_modeFollowMouse->setChecked(false);
655
#ifdef QAccessibilityClient_FOUND
656
  m_zoomView->followBoth(false);
657
  m_zoomView->followFocus(false);
658
  m_modeFollowFocus->setChecked(false);
659
#endif
660
661
  m_modeWholeScreen->setChecked(false);
  m_modeSelWin->setChecked(true);
662
663
}

664
void KmagApp::slotModeChanged()
665
{
666
#ifdef QAccessibilityClient_FOUND
667
668
669
670
671
672
673
674
675
676
677
678
  if(m_modeFollowMouse->isChecked() && m_modeFollowFocus->isChecked()) {

    //BOTH MODE
    m_zoomView->followMouse(false);
    m_zoomView->followBoth(true);
    m_zoomView->followFocus(false);
    m_zoomView->showSelRect(false);
    m_zoomView->setFitToWindow (true);
    m_modeWholeScreen->setChecked(false);
    m_modeSelWin->setChecked(false);
    return;
  }
679
#endif
680

681
  if (m_modeFollowMouse->isChecked()) {
682

683
684
685
686
687
    //MOUSE MODE
    m_zoomView->followMouse(true);
    m_zoomView->showSelRect(false);
    m_zoomView->setFitToWindow (true);
    m_modeFollowMouse->setChecked(true);
688
#ifdef QAccessibilityClient_FOUND
689
690
691
    m_zoomView->followBoth(false);
    m_zoomView->followFocus(false);
    m_modeFollowFocus->setChecked(false);
692
#endif
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
    m_modeWholeScreen->setChecked(false);
    m_modeSelWin->setChecked(false);

#ifdef QAccessibilityClient_FOUND
  } else if (m_modeFollowFocus->isChecked()) {

    //FOCUS MODE
    m_zoomView->followBoth(false);
    m_zoomView->followMouse(false);
    m_zoomView->followFocus(true);
    m_zoomView->showSelRect(false);
    m_zoomView->setFitToWindow (true);
    m_modeFollowMouse->setChecked(false);
    m_modeFollowFocus->setChecked(true);
    m_modeWholeScreen->setChecked(false);
    m_modeSelWin->setChecked(false);
#endif

  }
}
713
714

void KmagApp::slotToggleHideCursor()
715
{
716
  showMouseCursor(!m_hideCursor->isChecked());
717
718
}

719

Sebastian Sauer's avatar
Sebastian Sauer committed
720
721
722
void KmagApp::slotStaysOnTop()
{
  if (m_staysOnTop->isChecked())
723
      setWindowFlags( windowFlags() | Qt::WindowStaysOnTopHint );
Sebastian Sauer's avatar
Sebastian Sauer committed
724
  else
725
      setWindowFlags( windowFlags() & !Qt::WindowStaysOnTopHint );
Sebastian Sauer's avatar
Sebastian Sauer committed
726
727
728
729
  show();
}


Sarang Lakare's avatar
Sarang Lakare committed
730
void KmagApp::slotFileNewWindow()
Laurent Montel's avatar
Laurent Montel committed
731
{
Sarang Lakare's avatar
Sarang Lakare committed
732
733
734
735
736
737
738
  KmagApp *new_window= new KmagApp();
  new_window->show();
}


void KmagApp::slotFilePrint()
{
739
740
#ifndef QT_NO_PRINTER

Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
741
  bool toggled(false);
742

743
744
745
  if (m_printer == 0) {
    m_printer = new QPrinter();
  }
746

Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
747
  // stop refresh temporarily
748
749
  if (m_zoomView->getRefreshStatus()) {
    slotToggleRefresh();
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
750
    toggled = true;
Sarang Lakare's avatar
Sarang Lakare committed
751
  }
752

753
  const QImage pixmap(m_zoomView->getImage());
Sarang Lakare's avatar
Sarang Lakare committed
754

Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
755
756
  // use some AI to get the best orientation
  if(pixmap.width() > pixmap.height()) {
757
    m_printer->setOrientation(QPrinter::Landscape);
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
758
  } else {
759
    m_printer->setOrientation(QPrinter::Portrait);
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
760
  }
Sarang Lakare's avatar
Sarang Lakare committed
761

762
  QPrintDialog *printDialog = new QPrintDialog(m_printer, this);
John Layt's avatar
John Layt committed
763

764
  if (printDialog->exec()) {
765
    QPainter paint;
Laurent Montel's avatar
Laurent Montel committed
766

767
    if(!paint.begin(m_printer))
Laurent Montel's avatar
Laurent Montel committed
768
769
    {
      delete printDialog;
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
770
      return;
Laurent Montel's avatar
Laurent Montel committed
771
    }
772
    // draw the pixmap
773
    paint.drawImage(0, 0, pixmap);
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
774
775
    // end the painting
    paint.end();
776
777
  }

Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
778
779
780
  if(toggled) {
    slotToggleRefresh();
  }
Laurent Montel's avatar
Laurent Montel committed
781
  delete printDialog;
782
#endif // QT_NO_PRINTER
Sarang Lakare's avatar
Sarang Lakare committed
783
784
}

785
786
787
788
789
790
void KmagApp::slotFileQuit()
{
  saveOptions();
  // close the first window, the list makes the next one the first again.
  // This ensures that queryClose() is called on each window to ask for closing
  KMainWindow* w;
Laurent Montel's avatar
Laurent Montel committed
791
  if (!memberList().isEmpty())
792
  {
Laurent Montel's avatar
Laurent Montel committed
793
	for (int i = 0; i < memberList().size(); ++i)
794
    {
Laurent Montel's avatar
Laurent Montel committed
795
	  w = memberList().at(i);
796
797
798
799
      // only close the window if the closeEvent is accepted. If the user presses Cancel on the saveModified() dialog,
      // the window and the application stay open.
      if(!w->close())
         break;
800
#ifdef __GNUC__
Laurent Montel's avatar
Laurent Montel committed
801
#warning "kde4: now memberList() is constant => we can't remove some element!"
Stephan Kulow's avatar
ported    
Stephan Kulow committed
802
#endif
Laurent Montel's avatar
Laurent Montel committed
803
	//memberList()->removeRef(w);
804
    }
Stephan Binner's avatar
Stephan Binner committed
805
  }
806
807
}

Sarang Lakare's avatar
Sarang Lakare committed
808
void KmagApp::copyToClipBoard()
Sarang Lakare's avatar
Sarang Lakare committed
809
{
810
  QClipboard *cb=QApplication::clipboard();
811
  cb->setPixmap(QPixmap::fromImage(m_zoomView->getImage()));
Sarang Lakare's avatar
Sarang Lakare committed
812
813
}

814
815
816
817
818
819
820
821
822
823
824
825
void KmagApp::slotShowMenu()
{
  ///////////////////////////////////////////////////////////////////
  // turn Menu on or off
  if(!m_pShowMenu->isChecked())
  {
    menuBar()->hide();
  }
  else
  {
    menuBar()->show();
  }
826
827
}

828
829
void KmagApp::slotConfKeys()
{
Laurent Montel's avatar
Laurent Montel committed
830
  KShortcutsDialog::configure( actionCollection() );
831
832
833
834
}

void KmagApp::slotEditToolbars()
{
835
  KConfigGroup cg( KSharedConfig::openConfig(), "MainWindow" );
Stephan Kulow's avatar
ported    
Stephan Kulow committed
836
  saveMainWindowSettings( cg );
837
  QPointer<KEditToolBar> dlg = new KEditToolBar( actionCollection() );
838
  connect(dlg.data(), &KEditToolBar::newToolBarConfig, this, &KmagApp::slotNewToolbarConfig );
839
  if ( dlg->exec() )
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
840
    createGUI();
841
  delete dlg;
842
843
844
845
846
}


void KmagApp::slotNewToolbarConfig()
{
847
  applyMainWindowSettings( KSharedConfig::openConfig()->group( "MainWindow" ) );
Olaf Schmidt-Wischhöfer's avatar
Olaf Schmidt-Wischhöfer committed
848
  createGUI();
Sarang Lakare's avatar
Sarang Lakare committed
849
}