Tests/DemoGUI/ToolBar.cpp
changeset 26 83d6a149c755
equal deleted inserted replaced
25:a180113055cb 26:83d6a149c755
       
     1 #include "ToolBar.h"
       
     2 #include <qmenu.h>
       
     3 #include "ScreenSize.h"
       
     4 #include <qinputdialog.h>
       
     5 #include <qplaintextedit.h>
       
     6 #include <qdir.h>   //Checl lateer
       
     7 #include <qmessagebox.h>
       
     8 #include <qdebug.h>
       
     9 #include <qtooltip.h>
       
    10 //#include <apacmdln.h>
       
    11 //#include <apgcli.h>
       
    12 
       
    13 
       
    14 //MACRO
       
    15 #define KNullUid TUid::Null()
       
    16 
       
    17 //Forward declaration
       
    18 class ScreenSize;
       
    19 
       
    20 ToolBar::ToolBar()
       
    21 {
       
    22 
       
    23 }
       
    24 ToolBar::~ToolBar()
       
    25 {
       
    26 
       
    27 }
       
    28 void ToolBar::GetToolBar(QMainWindow *Mainwindow,QStringList aListOfActions)
       
    29 {
       
    30     //iMainWindow = new QMainWindow;
       
    31     iMainWindow = Mainwindow;
       
    32 
       
    33     QHBoxLayout* layout = new QHBoxLayout;
       
    34     QToolBar* tool = new QToolBar(Mainwindow);
       
    35     QToolButton* button1 = new QToolButton(Mainwindow);
       
    36     QToolButton* button2 = new QToolButton(Mainwindow);
       
    37     QToolButton* button3 = new QToolButton(Mainwindow);
       
    38     QToolButton* button4 = new QToolButton(Mainwindow);
       
    39     
       
    40     tool->setGeometry(0,ScreenSize::GetScreenRect().height() - (ToolbarIconHeight + KWidgetGapFactor),(ScreenSize::GetScreenRect().width()-(KWidgetGapFactor)),ToolbarIconHeight);
       
    41     
       
    42     //ToDo :- Ankit to check on button resizing
       
    43     const int IconWidth = ScreenSize::GetScreenRect().width()/7;
       
    44     button1->setGeometry(0,ScreenSize::GetScreenRect().height() - (ToolbarIconHeight + KWidgetGapFactor),IconWidth,ToolbarIconHeight);
       
    45 
       
    46     button1->setFixedWidth(IconWidth);
       
    47     button2->setFixedWidth(IconWidth);
       
    48     button3->setFixedWidth(IconWidth);
       
    49     button4->setFixedWidth(IconWidth);
       
    50 
       
    51 
       
    52     QIcon icon1("E:/Images/SMF/home.svg");
       
    53 	QIcon icon2("E:/Images/SMF/all_friends.svg"); //next.PNG
       
    54 	QIcon icon3("E:/Images/SMF/mail-message-new.svg");
       
    55 	QIcon icon4("E:/Images/SMF/Phone.svg");
       
    56 	QIcon icon5("E:/Images/SMF/system-log-out.svg");
       
    57 
       
    58     button1->setIcon(icon1);
       
    59     button2->setIcon(icon3);
       
    60     button3->setIcon(icon4);
       
    61     button4->setIcon(icon5);
       
    62 
       
    63    
       
    64     //QToolTip *tTip = new QToolTip();
       
    65     
       
    66     button1->setToolTip("Home");
       
    67     
       
    68     QMenu* menu = new QMenu(Mainwindow);
       
    69     icon2.actualSize(QSize(IconWidth-10,ToolbarIconHeight));
       
    70     //menu->setFixedWidth(IconWidth+10);
       
    71     menu->setIcon(icon2);
       
    72 
       
    73     QMenu *addServ = new QMenu(Mainwindow);
       
    74     addServ->setTitle(aListOfActions.at(2));
       
    75 
       
    76     //For Facebook and Flickr SP
       
    77     QAction *addServ_Facebk = new QAction("FaceBook",Mainwindow);
       
    78     QAction *addServ_Flickr = new QAction("Flickr",Mainwindow);
       
    79 
       
    80 
       
    81     addServ->addAction(addServ_Facebk);
       
    82     addServ->addAction(addServ_Flickr);
       
    83 
       
    84    // }
       
    85     //Create Actions
       
    86     QAction *newAction1 = new QAction(aListOfActions.at(0),Mainwindow);
       
    87     QAction *newAction2 = new QAction(aListOfActions.at(1),Mainwindow);
       
    88 
       
    89     menu->addMenu(addServ);
       
    90     menu->addAction(newAction1);
       
    91     menu->addAction(newAction2);
       
    92     
       
    93     //TODO: button to be disabled
       
    94     //button2->setEnabled(false);
       
    95     //button3->setEnabled(false);
       
    96     
       
    97     tool->addWidget(button1);
       
    98     tool->addAction(menu->menuAction());
       
    99     tool->addWidget(button2);
       
   100     tool->addWidget(button3);
       
   101     tool->addWidget(button4);
       
   102 
       
   103     layout->addWidget(tool);
       
   104     
       
   105     //connect actions
       
   106    connect(button1,SIGNAL(clicked()),this,SLOT(homeView()));
       
   107    connect(button2,SIGNAL(clicked()),this,SLOT(msg()));
       
   108    connect(button3,SIGNAL(clicked()),this,SLOT(call()));
       
   109    connect(button4,SIGNAL(clicked()),this,SLOT(exitApp()));
       
   110    connect(newAction1,SIGNAL(triggered()),this,SLOT(post()));
       
   111    connect(newAction2,SIGNAL(triggered()),this,SLOT(reply()));
       
   112    
       
   113    //connect for authentication
       
   114    connect(addServ_Facebk,SIGNAL(triggered()),this,SLOT(authApp_Fb()));
       
   115    connect(addServ_Flickr,SIGNAL(triggered()),this,SLOT(authApp_Flkr()));
       
   116    
       
   117 }
       
   118 
       
   119 //changing to home view
       
   120 void ToolBar::homeView()
       
   121 {
       
   122     //debug
       
   123     qDebug()<<"Inside View_Change()";
       
   124 }
       
   125 
       
   126 
       
   127 
       
   128 //slot for post comment
       
   129 void ToolBar::post()
       
   130 {
       
   131     //debug purpose
       
   132     qDebug()<<"Inside My Post";
       
   133     bool ok;
       
   134     QInputDialog inptDialg;
       
   135     inptDialg.setStyleSheet("background: black;");//rgb(255,255,255);");
       
   136     QString text = inptDialg.getText(iMainWindow, tr("QInputDialog::getText()"),tr("Post"),
       
   137                                          QLineEdit::Normal,QString::null, &ok,Qt::Window);
       
   138 
       
   139 
       
   140     if ( ok && !text.isEmpty() ) {
       
   141     // user entered something and pressed OK
       
   142     } else {
       
   143     // user entered nothing or pressed Cancel
       
   144     }
       
   145 
       
   146 
       
   147 }
       
   148 
       
   149 //slot for reply comment
       
   150 void ToolBar::reply()
       
   151 {
       
   152     //debug purpose
       
   153     qDebug()<<"Inside Reply";
       
   154 
       
   155     bool ok;
       
   156     QString text = QInputDialog::getText(iMainWindow, tr("QInputDialog::getText()"),tr("Reply To Post"),
       
   157                                          QLineEdit::Normal,QString::null, &ok,Qt::Window);
       
   158 
       
   159 
       
   160     if ( ok && !text.isEmpty() ) {
       
   161     // user entered something and pressed OK
       
   162     } else {
       
   163     // user entered nothing or pressed Cancel
       
   164     }
       
   165 
       
   166 
       
   167 }
       
   168 //calling 
       
   169 //calling 
       
   170 void ToolBar::call()
       
   171 	{
       
   172 		QMessageBox msgbox;
       
   173 		QString msg ("Calling not configured!");
       
   174 		msgbox.setText(msg);
       
   175 		msgbox.exec();
       
   176 	}
       
   177 
       
   178 
       
   179 
       
   180 //msging
       
   181 void ToolBar::msg()
       
   182 	{
       
   183 		QMessageBox msgbox;
       
   184 		QString msg ("Messaging not configured!");
       
   185 		msgbox.setText(msg);
       
   186 		msgbox.exec();
       
   187 	}
       
   188 //exiting application
       
   189 void ToolBar::exitApp()
       
   190 {
       
   191     //qDebug()<<"Inside Exit_App()";
       
   192     QApplication::exit();
       
   193 }
       
   194 
       
   195 
       
   196 //Auth_App for FaceBook
       
   197 void ToolBar::authApp_Fb()
       
   198 {
       
   199     //debug
       
   200     qDebug()<<"Inside Auth app of faceBook";
       
   201     launchFB();
       
   202 }
       
   203 
       
   204 //Auth App for Flickr
       
   205 void ToolBar::authApp_Flkr()
       
   206 {
       
   207     //debug
       
   208     qDebug()<<"Inside Auth App of Flickr";
       
   209     launchFlickr();
       
   210 }
       
   211 
       
   212 
       
   213 //Facebook AuthApp Launch
       
   214 void ToolBar::launchFB()
       
   215 	{
       
   216 	qDebug()<<"Inside Launch FB AuthApp";
       
   217 	TInt result;
       
   218 	_LIT(KExecutableName,"release\\winscw\\udeb\\AuthApp.exe");
       
   219 	
       
   220 	//we can ignore using UID
       
   221 	//const TProcessId FBUid(KFBUid3);
       
   222 	RProcess fbProc;
       
   223 	result = fbProc.Create(KExecutableName,KNullDesC);
       
   224 	if(result != KErrNone)
       
   225 		{
       
   226 		qDebug()<<"FB Can't be opened";
       
   227 		return;
       
   228 		}
       
   229 	qDebug()<<"FB AuthApp Launched";
       
   230 	fbProc.Resume();
       
   231 	fbProc.Close();
       
   232 	return;
       
   233 	
       
   234 	}
       
   235 
       
   236 void ToolBar::launchFlickr()
       
   237 	{
       
   238 	qDebug()<<"Inside Launch FB AuthApp";
       
   239 	TInt result;
       
   240 	_LIT(KExecutableName,"release\\winscw\\udeb\\Flickr.exe");
       
   241 	
       
   242 	//we can ignore using UID
       
   243 	//const TProcessId FBUid(KFBUid3);
       
   244 	RProcess flickrProc;
       
   245 	result = flickrProc.Create(KExecutableName,KNullDesC);
       
   246 	if(result != KErrNone)
       
   247 		{
       
   248 		qDebug()<<"Flickr Can't be opened";
       
   249 		return;
       
   250 		}
       
   251 	qDebug()<<"Flickr AuthApp Launched";
       
   252 	flickrProc.Resume();
       
   253 	flickrProc.Close();
       
   254 	return;
       
   255 	}