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

kanagram

  • sources
  • kde-4.12
  • kdeedu
  • kanagram
  • src
  • plasma-active
  • src
kdeclarativemainwindow.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright 2011 Sebastian Kügler <sebas@kde.org> *
4  * Copyright 2011 Marco Martin <mart@kde.org> *
5  * *
6  * This program is free software; you can redistribute it and/or modify *
7  * it under the terms of the GNU General Public License as published by *
8  * the Free Software Foundation; either version 2 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
20  ***************************************************************************/
21 
22 #include "kdeclarativemainwindow.h"
23 #include "kdeclarativeview.h"
24 
25 #include <QApplication>
26 #include <QDeclarativeContext>
27 
28 #include <KAction>
29 #include <KCmdLineArgs>
30 #include <KStandardAction>
31 
32 #include <Plasma/Theme>
33 
34 
35 
36 class KDeclarativeMainWindowPrivate
37 {
38 public:
39  KDeclarativeMainWindowPrivate(KDeclarativeMainWindow *window)
40  : q(window)
41  {}
42 
43  void statusChanged(QDeclarativeView::Status status);
44 
45  KDeclarativeMainWindow *q;
46  KDeclarativeView *view;
47  KCmdLineArgs *args;
48  QStringList arguments;
49  QString caption;
50 };
51 
52 void KDeclarativeMainWindowPrivate::statusChanged(QDeclarativeView::Status status)
53 {
54  if (status == QDeclarativeView::Ready) {
55  view->rootContext()->setContextProperty("application", q);
56  }
57 }
58 
59 
60 
61 KDeclarativeMainWindow::KDeclarativeMainWindow()
62  : KMainWindow(),
63  d(new KDeclarativeMainWindowPrivate(this))
64 {
65  setAcceptDrops(true);
66  KConfigGroup cg(KSharedConfig::openConfig("plasmarc"), "Theme-plasma-mobile");
67  const QString themeName = cg.readEntry("name", "air-mobile");
68  Plasma::Theme::defaultTheme()->setUseGlobalSettings(false);
69  Plasma::Theme::defaultTheme()->setThemeName(themeName);
70  addAction(KStandardAction::close(this, SLOT(close()), this));
71  addAction(KStandardAction::quit(this, SLOT(close()), this));
72 
73  d->view = new KDeclarativeView(this);
74  connect(d->view, SIGNAL(statusChanged(QDeclarativeView::Status)), this, SLOT(statusChanged(QDeclarativeView::Status)));
75 
76  setCentralWidget(d->view);
77  restoreWindowSize(config("Window"));
78 
79  setWindowIcon(KIcon(KCmdLineArgs::aboutData()->programIconName()));
80 
81  d->args = KCmdLineArgs::parsedArgs();
82  for (int i = 0; i < d->args->count(); i++) {
83  d->arguments << d->args->arg(i);
84  }
85 
86  bool useGL = d->args->isSet("opengl");
87  if (!useGL) {
88  //use plasmarc to share this with plasma-windowed
89  KConfigGroup cg(KSharedConfig::openConfig("plasmarc"), "General");
90  useGL = cg.readEntry("UseOpenGl", true);
91  }
92  d->view->setUseGL(useGL);
93 
94  connect(d->view, SIGNAL(titleChanged(QString)), SLOT(setCaption(QString)));
95 }
96 
97 KDeclarativeMainWindow::~KDeclarativeMainWindow()
98 {
99  saveWindowSize(config("Window"));
100 }
101 
102 
103 KDeclarativeView *KDeclarativeMainWindow::declarativeView() const
104 {
105  return d->view;
106 }
107 
108 KConfigGroup KDeclarativeMainWindow::config(const QString &group)
109 {
110  return KConfigGroup(KSharedConfig::openConfig(qApp->applicationName() + "rc"), group);
111 }
112 
113 QStringList KDeclarativeMainWindow::startupArguments() const
114 {
115  return d->arguments;
116 }
117 
118 QString KDeclarativeMainWindow::startupOption(const QString &option) const
119 {
120  return d->args->getOption(option.toLatin1());
121 }
122 
123 QString KDeclarativeMainWindow::caption() const
124 {
125  return d->caption;
126 }
127 
128 void KDeclarativeMainWindow::setCaption(const QString &caption)
129 {
130  if (d->caption == caption) {
131  return;
132  }
133 
134  d->caption = caption;
135  emit captionChanged();
136  KMainWindow::setCaption(caption);
137 }
138 
139 void KDeclarativeMainWindow::setCaption(const QString &caption, bool modified)
140 {
141  Q_UNUSED(modified)
142 
143  if (d->caption == caption) {
144  return;
145  }
146 
147  d->caption = caption;
148  emit captionChanged();
149  KMainWindow::setCaption(caption, true);
150 }
151 
152 #include "kdeclarativemainwindow.moc"
KDeclarativeView
Definition: kdeclarativeview.h:35
KDeclarativeMainWindow::caption
QString caption() const
kdeclarativemainwindow.h
KDeclarativeMainWindow::captionChanged
void captionChanged()
KDeclarativeMainWindow::~KDeclarativeMainWindow
~KDeclarativeMainWindow()
Definition: kdeclarativemainwindow.cpp:97
KDeclarativeMainWindow::config
KConfigGroup config(const QString &group="Default")
The main kconfiggroup to be used for this application The configuration file name is derived from the...
Definition: kdeclarativemainwindow.cpp:108
KDeclarativeMainWindow::setCaption
void setCaption(const QString &caption)
Definition: kdeclarativemainwindow.cpp:128
KDeclarativeMainWindow::startupOption
Q_INVOKABLE QString startupOption(const QString &option) const
Read out a string option.
Definition: kdeclarativemainwindow.cpp:118
kdeclarativeview.h
KMainWindow
KDeclarativeMainWindow::declarativeView
KDeclarativeView * declarativeView() const
Definition: kdeclarativemainwindow.cpp:103
KDeclarativeMainWindow::startupArguments
QStringList startupArguments() const
KDeclarativeMainWindow
Definition: kdeclarativemainwindow.h:33
KDeclarativeMainWindow::KDeclarativeMainWindow
KDeclarativeMainWindow()
Definition: kdeclarativemainwindow.cpp:61
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:35 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kanagram

Skip menu "kanagram"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

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