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

kanagram

  • sources
  • kde-4.14
  • kdeedu
  • kanagram
  • 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 
48  KCmdLineArgs *args;
49  QStringList arguments;
50  QString caption;
51 };
52 
53 void KDeclarativeMainWindowPrivate::statusChanged(QDeclarativeView::Status status)
54 {
55  if (status == QDeclarativeView::Ready) {
56  view->rootContext()->setContextProperty("application", q);
57  }
58 }
59 
60 KDeclarativeMainWindow::KDeclarativeMainWindow()
61  : KMainWindow(),
62  d(new KDeclarativeMainWindowPrivate(this))
63 {
64  setAcceptDrops(true);
65  KConfigGroup cg(KSharedConfig::openConfig("plasmarc"), "Theme-plasma-mobile");
66  const QString themeName = cg.readEntry("name", "air-mobile");
67  Plasma::Theme::defaultTheme()->setUseGlobalSettings(false);
68  Plasma::Theme::defaultTheme()->setThemeName(themeName);
69  addAction(KStandardAction::close(this, SLOT(close()), this));
70  addAction(KStandardAction::quit(this, SLOT(close()), this));
71 
72  d->view = new KDeclarativeView(this);
73  connect(d->view, SIGNAL(statusChanged(QDeclarativeView::Status)), this, SLOT(statusChanged(QDeclarativeView::Status)));
74 
75  setCentralWidget(d->view);
76  restoreWindowSize(config("Window"));
77 
78  setWindowIcon(KIcon(KCmdLineArgs::aboutData()->programIconName()));
79 
80  d->args = KCmdLineArgs::parsedArgs();
81  for (int i = 0; i < d->args->count(); i++) {
82  d->arguments << d->args->arg(i);
83  }
84 
85  bool useGL = d->args->isSet("opengl");
86  if (!useGL) {
87  //use plasmarc to share this with plasma-windowed
88  KConfigGroup cg(KSharedConfig::openConfig("plasmarc"), "General");
89  useGL = cg.readEntry("UseOpenGl", true);
90  }
91  d->view->setUseGL(useGL);
92 
93  connect(d->view, SIGNAL(titleChanged(QString)), SLOT(setCaption(QString)));
94 }
95 
96 KDeclarativeMainWindow::~KDeclarativeMainWindow()
97 {
98  saveWindowSize(config("Window"));
99 }
100 
101 
102 KDeclarativeView *KDeclarativeMainWindow::declarativeView() const
103 {
104  return d->view;
105 }
106 
107 KConfigGroup KDeclarativeMainWindow::config(const QString &group)
108 {
109  return KConfigGroup(KSharedConfig::openConfig(qApp->applicationName() + "rc"), group);
110 }
111 
112 QStringList KDeclarativeMainWindow::startupArguments() const
113 {
114  return d->arguments;
115 }
116 
117 QString KDeclarativeMainWindow::startupOption(const QString &option) const
118 {
119  return d->args->getOption(option.toLatin1());
120 }
121 
122 QString KDeclarativeMainWindow::caption() const
123 {
124  return d->caption;
125 }
126 
127 void KDeclarativeMainWindow::setCaption(const QString &caption)
128 {
129  if (d->caption == caption) {
130  return;
131  }
132 
133  d->caption = caption;
134  emit captionChanged();
135  KMainWindow::setCaption(caption);
136 }
137 
138 void KDeclarativeMainWindow::setCaption(const QString &caption, bool modified)
139 {
140  Q_UNUSED(modified)
141 
142  if (d->caption == caption) {
143  return;
144  }
145 
146  d->caption = caption;
147  emit captionChanged();
148  KMainWindow::setCaption(caption, true);
149 }
150 
151 #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:96
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:107
KDeclarativeMainWindow::setCaption
void setCaption(const QString &caption)
Definition: kdeclarativemainwindow.cpp:127
KDeclarativeMainWindow::startupOption
Q_INVOKABLE QString startupOption(const QString &option) const
Read out a string option.
Definition: kdeclarativemainwindow.cpp:117
kdeclarativeview.h
KMainWindow
QString
QStringList
KDeclarativeMainWindow::declarativeView
KDeclarativeView * declarativeView() const
Definition: kdeclarativemainwindow.cpp:102
QString::toLatin1
QByteArray toLatin1() const
KDeclarativeMainWindow::startupArguments
QStringList startupArguments() const
KDeclarativeMainWindow
Definition: kdeclarativemainwindow.h:33
KDeclarativeMainWindow::KDeclarativeMainWindow
KDeclarativeMainWindow()
Definition: kdeclarativemainwindow.cpp:60
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:12:00 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
  • 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