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

kapptemplate

  • sources
  • kde-4.14
  • kdesdk
  • kapptemplate
  • templates
  • C++
  • kapp4-qml
  • src
kapp4-qml/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 #include "ui_prefs_base.h"
24 
25 #include <QtGui/QDropEvent>
26 
27 #include <KConfigDialog>
28 #include <KStatusBar>
29 
30 #include <KAction>
31 #include <KActionCollection>
32 #include <KStandardAction>
33 
34 #include <KLocale>
35 
36 %{APPNAME}::%{APPNAME}()
37  : KXmlGuiWindow(),
38  m_view(new %{APPNAME}View(this))
39 {
40  // accept dnd
41  setAcceptDrops(true);
42 
43  // tell the KXmlGuiWindow that this is indeed the main widget
44  setCentralWidget(m_view);
45 
46  // then, setup our actions
47  setupActions();
48 
49  // add a status bar
50  statusBar()->show();
51 
52  // a call to KXmlGuiWindow::setupGUI() populates the GUI
53  // with actions, using KXMLGUI.
54  // It also applies the saved mainwindow settings, if any, and ask the
55  // mainwindow to automatically save settings if changed: window size,
56  // toolbar position, icon size, etc.
57  setupGUI();
58 }
59 
60 %{APPNAME}::~%{APPNAME}()
61 {
62 }
63 
64 void %{APPNAME}::setupActions()
65 {
66  KStandardAction::openNew(this, SLOT(fileNew()), actionCollection());
67  KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollection());
68 
69  KStandardAction::preferences(this, SLOT(optionsPreferences()), actionCollection());
70 
71  // custom menu and menu item - the slot is in the class %{APPNAME}View
72  KAction *custom = new KAction(KIcon("colorize"), i18n("Swi&tch Colors"), this);
73  actionCollection()->addAction( QLatin1String("switch_action"), custom );
74  connect(custom, SIGNAL(triggered(bool)), m_view, SLOT(switchColors()));
75 }
76 
77 void %{APPNAME}::fileNew()
78 {
79  // this slot is called whenever the File->New menu is selected,
80  // the New shortcut is pressed (usually CTRL+N) or the New toolbar
81  // button is clicked
82 
83  // create a new window
84  (new %{APPNAME})->show();
85 }
86 
87 void %{APPNAME}::optionsPreferences()
88 {
89  // The preference dialog is derived from prefs_base.ui
90  //
91  // compare the names of the widgets in the .ui file
92  // to the names of the variables in the .kcfg file
93  //avoid to have 2 dialogs shown
94  if ( KConfigDialog::showDialog( "settings" ) ) {
95  return;
96  }
97  KConfigDialog *dialog = new KConfigDialog(this, "settings", Settings::self());
98  QWidget *generalSettingsDlg = new QWidget;
99  ui_prefs_base.setupUi(generalSettingsDlg);
100  dialog->addPage(generalSettingsDlg, i18n("General"), "package_setting");
101  connect(dialog, SIGNAL(settingsChanged(QString)), m_view, SLOT(settingsChanged()));
102  dialog->setAttribute( Qt::WA_DeleteOnClose );
103  dialog->show();
104 }
105 
106 #include "%{APPNAMELC}.moc"
QWidget
%{APPNAMELC}view.h
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
QString
settings.h
View
class SettingsHelper View
APPNAME
main APPNAME
QLatin1String
m_view
m_view(new%{APPNAME}View(this))
Definition: kapp4-qml/src/%{APPNAMELC}.cpp:38
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:39:44 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
  • 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