• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

kapptemplate

  • sources
  • kde-4.12
  • kdesdk
  • kapptemplate
  • templates
  • C++
  • kapp4
  • src
kapp4/src/%{APPNAMELC}.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) %{CURRENT_YEAR} by %{AUTHOR} <%{EMAIL}> *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License *
15  * along with this program; if not, write to the *
16  * Free Software Foundation, Inc., *
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18  ***************************************************************************/
19 
20 #include "%{APPNAMELC}.h"
21 #include "%{APPNAMELC}view.h"
22 #include "settings.h"
23 
24 #include <QtGui/QDropEvent>
25 #include <QtGui/QPainter>
26 #include <QtGui/QPrinter>
27 
28 #include <KConfigDialog>
29 #include <KStatusBar>
30 
31 #include <KAction>
32 #include <KActionCollection>
33 #include <KStandardAction>
34 
35 #include <KLocale>
36 
37 %{APPNAME}::%{APPNAME}()
38  : KXmlGuiWindow(),
39  m_view(new %{APPNAME}View(this)),
40  m_printer(0)
41 {
42  // accept dnd
43  setAcceptDrops(true);
44 
45  // tell the KXmlGuiWindow that this is indeed the main widget
46  setCentralWidget(m_view);
47 
48  // then, setup our actions
49  setupActions();
50 
51  // add a status bar
52  statusBar()->show();
53 
54  // a call to KXmlGuiWindow::setupGUI() populates the GUI
55  // with actions, using KXMLGUI.
56  // It also applies the saved mainwindow settings, if any, and ask the
57  // mainwindow to automatically save settings if changed: window size,
58  // toolbar position, icon size, etc.
59  setupGUI();
60 }
61 
62 %{APPNAME}::~%{APPNAME}()
63 {
64 }
65 
66 void %{APPNAME}::setupActions()
67 {
68  KStandardAction::openNew(this, SLOT(fileNew()), actionCollection());
69  KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollection());
70 
71  KStandardAction::preferences(this, SLOT(optionsPreferences()), actionCollection());
72 
73  // custom menu and menu item - the slot is in the class %{APPNAME}View
74  KAction *custom = new KAction(KIcon("colorize"), i18n("Swi&tch Colors"), this);
75  actionCollection()->addAction( QLatin1String("switch_action"), custom );
76  connect(custom, SIGNAL(triggered(bool)), m_view, SLOT(switchColors()));
77 }
78 
79 void %{APPNAME}::fileNew()
80 {
81  // this slot is called whenever the File->New menu is selected,
82  // the New shortcut is pressed (usually CTRL+N) or the New toolbar
83  // button is clicked
84 
85  // create a new window
86  (new %{APPNAME})->show();
87 }
88 
89 void %{APPNAME}::optionsPreferences()
90 {
91  // The preference dialog is derived from prefs_base.ui
92  //
93  // compare the names of the widgets in the .ui file
94  // to the names of the variables in the .kcfg file
95  //avoid to have 2 dialogs shown
96  if ( KConfigDialog::showDialog( "settings" ) ) {
97  return;
98  }
99  KConfigDialog *dialog = new KConfigDialog(this, "settings", Settings::self());
100  QWidget *generalSettingsDlg = new QWidget;
101  ui_prefs_base.setupUi(generalSettingsDlg);
102  dialog->addPage(generalSettingsDlg, i18n("General"), "package_setting");
103  connect(dialog, SIGNAL(settingsChanged(QString)), m_view, SLOT(settingsChanged()));
104  dialog->setAttribute( Qt::WA_DeleteOnClose );
105  dialog->show();
106 }
107 
108 #include "%{APPNAMELC}.moc"
m_printer
m_printer(0)
Definition: kapp4/src/%{APPNAMELC}.cpp:40
ui_prefs_base
Ui::prefs_base ui_prefs_base
Definition: kapp4/src/%{APPNAMELC}.h:63
QWidget
class @6 QWidget
This is the main view class for %{APPNAME}.
Settings::self
static Settings * self()
Definition: C++/akonadiresource/settings.cpp:19
%{APPNAMELC}.h
%{APPNAMELC}view.h
settings.h
m_view
m_view(new%{APPNAME}View(this))
View
class SettingsHelper View
APPNAME
main APPNAME
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:03:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kapptemplate

Skip menu "kapptemplate"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal