~feng-kylin/youker-assistant/youker-assistant

« back to all changes in this revision

Viewing changes to src/contentfield.cpp

  • Committer: kobe
  • Date: 2015-02-13 07:37:10 UTC
  • Revision ID: xiangli@ubuntukylin.com-20150213073710-0jyp02ilyi5njj10
Qt Version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2013 ~ 2014 National University of Defense Technology(NUDT) & Kylin Ltd.
3
 
 * Author: Kobe Lee
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License as published by
7
 
 * the Free Software Foundation; version 3.
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, see <http://www.gnu.org/licenses/>.
16
 
 */
17
 
 
18
 
#include <QDebug>
19
 
#include "contentfield.h"
20
 
#include "messengerproxy.h"
21
 
 
22
 
ContentField::ContentField(QWidget *parent)
23
 
    :QStackedWidget(parent)
24
 
{
25
 
    this->setStyleSheet("background:transparent;");
26
 
    this->setAutoFillBackground(false);
27
 
    this->view = new QDeclarativeView(this);
28
 
    this->setup();
29
 
//    this->view->rootContext()->setContextProperty("mainwindow", this->view);
30
 
    this->setFixedSize(this->view->size());
31
 
    this->view->move(0, 0);
32
 
 
33
 
    //返回首页信号槽
34
 
    connect(this, SIGNAL(activePushStack(int)), MessengerProxy::get_instance_object(), SLOT(accessCurrentHomeIndex(int)));
35
 
}
36
 
 
37
 
ContentField::~ContentField()
38
 
{
39
 
    delete this->view;
40
 
}
41
 
 
42
 
void ContentField::DoNavigate(int index)
43
 
{
44
 
    if(index >= 0 && index <= 4) {
45
 
        emit activePushStack(index);//返回首页信号
46
 
//        this->setCurrentIndex(index);
47
 
    }
48
 
}
49
 
 
50
 
inline bool isRunningInstalled() {
51
 
    static bool installed = (QCoreApplication::applicationDirPath() ==
52
 
                             QDir(("/usr/bin")).canonicalPath());
53
 
    return installed;
54
 
}
55
 
 
56
 
inline QString getAppDirectory() {
57
 
    if (isRunningInstalled()) {
58
 
//        qDebug() << QCoreApplication::applicationDirPath();
59
 
        return QString("/usr/share/youker-assistant/qml/");
60
 
    } else {
61
 
        return QString(QCoreApplication::applicationDirPath() + "/../qml/");
62
 
    }
63
 
}
64
 
 
65
 
void ContentField::setup() {
66
 
    this->view->engine()->setBaseUrl(QUrl::fromLocalFile(getAppDirectory()));
67
 
    this->view->setSource(QUrl::fromLocalFile("ContentField.qml"));
68
 
}