Release 0.3-1 (Including all changes)
[marketstoday] / src / cpp / marketstodayqmlview.cpp
1 /*
2 @version: 0.2
3 @author: Sudheer K. <scifi1947 at gmail.com>
4 @license: GNU General Public License
5 */
6
7 #include "marketstodayqmlview.h"
8 #include "configqmlview.h"
9 #include "sharedcontext.h"
10 #include <QDeclarativeEngine>
11 #include <QDeclarativeContext>
12 #include <QDeclarativeProperty>
13 #include <QGraphicsObject>
14 #include "logutility.h"
15 #include <QDebug>
16
17 MarketsTodayQMLView::MarketsTodayQMLView(QWidget *parent) : QDeclarativeView(parent), logUtility(new LogUtility(this))
18 {        
19     // Setup QDeclarativeView
20     //setAttribute(Qt::WA_OpaquePaintEvent);
21     //setAttribute(Qt::WA_TranslucentBackground);
22     setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
23     setAlignment(Qt::AlignCenter);
24     this->rootContext()->setContextProperty("logUtility",logUtility);
25 }
26
27 QSize MarketsTodayQMLView::sizeHint() const
28 {
29     return QSize(400, 365);
30 }
31
32 void MarketsTodayQMLView::displayConfigWindow() {
33
34     ConfigQMLView *configView = new ConfigQMLView(this->parentWidget(),this);
35
36 #if defined(Q_WS_MAEMO_5) | defined(Q_WS_MAEMO_6)
37     //For maemo use a common path
38     configView->engine()->setOfflineStoragePath("/home/user/.marketstoday/OfflineStorage");
39 #else
40     configView->engine()->setOfflineStoragePath("qml/OfflineStorage");
41 #endif
42     configView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
43     configView->setSource(QUrl("qrc:/qml/Config.qml"));
44     configView->setWindowTitle("Configuration");
45     QObject::connect((QObject*)configView->engine(), SIGNAL(quit()), configView, SLOT(configClosed()));
46     configView->showFullScreen();
47 }
48
49 void MarketsTodayQMLView::displayStockDetails(QString symbol){
50
51     QDeclarativeView *detailsView = new QDeclarativeView(this->parentWidget());
52     SharedContext *sharedContextObj = new SharedContext(detailsView);
53     sharedContextObj->setComponentToDisplay("StockQuoteDetails");
54     sharedContextObj->setStockSymbol(symbol);
55
56 #if defined(Q_WS_MAEMO_5) | defined(Q_WS_MAEMO_6)
57     //For maemo use a common path
58     detailsView->engine()->setOfflineStoragePath("/home/user/.marketstoday/OfflineStorage");
59 #else
60     detailsView->engine()->setOfflineStoragePath("qml/OfflineStorage");
61 #endif
62
63     detailsView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
64     detailsView->setAlignment(Qt::AlignCenter);
65     detailsView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
66     detailsView->rootContext()->setContextProperty("sharedContext",sharedContextObj);
67     detailsView->rootContext()->setContextProperty("logUtility",logUtility);
68     detailsView->setSource(QUrl("qrc:/qml/MarketsTodayApp.qml"));
69     detailsView->setWindowTitle("Markets Today");
70     QObject::connect((QObject*)detailsView->engine(), SIGNAL(quit()), detailsView, SLOT(close()));
71     detailsView->setFixedSize(800,480);
72     detailsView->showFullScreen();
73
74     logUtility->logMessage("Stock Details window displayed");
75 }
76
77 void MarketsTodayQMLView::initialize(){
78     emit initializeWidget();
79 }
80
81 MarketsTodayQMLView::~MarketsTodayQMLView(){
82     qDebug() << "In destructor for MarketsTodayQMLView object";
83 }
84