• 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
qml/src/%{APPNAMELC}view.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}view.h"
21 #include "settings.h"
22 
23 #include <KLocale>
24 #include <KStandardDirs>
25 
26 #include <QApplication>
27 #include <QtGui/QLabel>
28 #include <QGraphicsObject>
29 #include <QtDeclarative/QDeclarativeView>
30 #include <QtDeclarative/QDeclarativeProperty>
31 #include <QtDeclarative/QDeclarativeItem>
32 
33 %{APPNAME}View::%{APPNAME}View(QWidget *)
34 {
35  view = new QDeclarativeView(this);
36  view->setSource(QUrl::fromLocalFile(KStandardDirs::locate("data", "%{APPNAMELC}/qml/main.qml")));
37  kcfg_sillyLabel = view->rootObject();
38  kcfg_sillyLabel->setProperty("width", width());
39  QDeclarativeProperty(kcfg_sillyLabel, "width").write(width());
40  kcfg_sillyLabel->setProperty("height", height());
41  QDeclarativeProperty(kcfg_sillyLabel, "height").write(height());
42  QObject::connect(kcfg_sillyLabel, SIGNAL(clicked()),
43  qApp, SLOT(quit()));
44  view->show();
45  settingsChanged();
46 }
47 
48 %{APPNAME}View::~%{APPNAME}View()
49 {
50 }
51 
52 void %{APPNAME}View::settingsChanged()
53 {
54  QPalette pal;
55  pal.setColor( QPalette::Window, Settings::col_background());
56  pal.setColor( QPalette::WindowText, Settings::col_foreground());
57  // Set the color from the Settings dialog to the foreground
58  QDeclarativeProperty(kcfg_sillyLabel, "color").write(Settings::col_background());
59  // Access the Text element from the QML file with its objectName
60  QObject *kcfg_col_foreground = kcfg_sillyLabel->findChild<QObject*>("kcfg_col_foreground");
61  // Set the Text color
62  if (kcfg_col_foreground) {
63  QDeclarativeProperty(kcfg_col_foreground, "color").write(Settings::col_foreground());
64  }
65 
66  emit signalChangeStatusbar( i18n("Settings changed") );
67 }
68 
69 void %{APPNAME}View::switchColors()
70 {
71  // switch the foreground/background colors of the label
72  QColor color = Settings::col_background();
73  Settings::setCol_background( Settings::col_foreground() );
74  Settings::setCol_foreground( color );
75 
76  settingsChanged();
77 }
78 
79 #include "%{APPNAMELC}view.moc"
QDeclarativeView::setSource
void setSource(const QUrl &url)
QDeclarativeView::rootObject
QGraphicsObject * rootObject() const
QDeclarativeProperty::write
bool write(const QVariant &value) const
Settings::setCol_foreground
static void setCol_foreground(const QColor &v)
Set color of the foreground.
Definition: C++/kapp4/src/settings.h:39
QWidget
%{APPNAMELC}view.h
QPalette::setColor
void setColor(ColorGroup group, ColorRole role, const QColor &color)
kcfg_sillyLabel
QObject * kcfg_sillyLabel
Definition: kapp4-qml/src/%{APPNAMELC}view.h:54
QDeclarativeProperty
QDeclarativeView
Settings::col_background
static QColor col_background()
Get color of the background.
Definition: C++/kapp4/src/settings.h:30
QObject
clicked
void clicked()
settings.h
QColor
View
class SettingsHelper View
view
virtual QDeclarativeView * view
Destructor.
Definition: kapp4-qml/src/%{APPNAMELC}view.h:51
signalChangeStatusbar
void signalChangeStatusbar(const QString &text)
Use this signal to change the content of the statusbar.
APPNAME
main APPNAME
Settings::col_foreground
static QColor col_foreground()
Get color of the foreground.
Definition: C++/kapp4/src/settings.h:49
QObject::setProperty
bool setProperty(const char *name, const QVariant &value)
QWidget::show
void show()
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Settings::setCol_background
static void setCol_background(const QColor &v)
Set color of the background.
Definition: C++/kapp4/src/settings.h:20
QPalette
QUrl::fromLocalFile
QUrl fromLocalFile(const QString &localFile)
QObject::findChild
T findChild(const QString &name) const
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