Root/qmain.cpp

1/***************************************************************************
2 * Copyright (C) 2010 by Mirko Lindner *
3 * mirko@sharism.cc *
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; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#include <QtGui>
22#include <QWidget>
23#include <QMessageBox>
24#include "qmain.h"
25
26#include <cxxtools/log.h>
27
28log_define("qvido.qmain");
29
30QMain::QMain(std::string File)
31{
32        
33        this->resize(320, 240);
34        
35        fileLocation = File;
36        
37        centralWidget = new HtmlArea(this);
38    setCentralWidget(centralWidget);
39        
40        centralWidget->getRandom();
41        registerCommands();
42        QObject::connect(centralWidget,SIGNAL(anchorClicked(const QUrl &)),
43                                         centralWidget,SLOT(linking(const QUrl&)));
44        QObject::connect(centralWidget,SIGNAL(sourceChanged(const QUrl &)),
45                                         centralWidget,SLOT(sourceChange(const QUrl&)));
46        
47        QCursor cursor;
48        
49        if (qApp->overrideCursor() == false){
50            qApp->setOverrideCursor(cursor);
51            log_debug("no cursor");
52        }
53
54}
55
56QMain::~QMain(){}
57
58void QMain::searchDialog(){
59        bool ok;
60        QString text = QInputDialog::getText(this, tr("Search Article"),
61                                          tr("Article Title"), QLineEdit::Normal,
62                                          "", &ok);
63        if (ok && !text.isEmpty())
64            this->centralWidget->searchArticle(text);
65            
66}
67
68void QMain::registerCommands()
69{
70        //get random article
71        randomArticleAct = new QAction(tr("Load &Random Article"), this);
72        randomArticleAct->setShortcut(tr("Ctrl+R"));
73        randomArticleAct->setStatusTip(tr("Random Article"));
74        connect(randomArticleAct, SIGNAL(triggered()), this->centralWidget, SLOT(getRandom()));
75        this->addAction(randomArticleAct);
76
77        //get search dialog
78        searchArticleAct = new QAction(tr("&Search Dialog"), this);
79        searchArticleAct->setShortcut(tr("Ctrl+S"));
80        searchArticleAct->setStatusTip(tr("Search for Article"));
81        connect(searchArticleAct, SIGNAL(triggered()), this, SLOT(searchDialog()));
82        this->addAction(searchArticleAct);
83
84        //display help
85        displayHelpAct = new QAction(tr("Display &Help"), this);
86        displayHelpAct->setShortcut(tr("F1"));
87        displayHelpAct->setStatusTip(tr("Display Help"));
88        connect(displayHelpAct, SIGNAL(triggered()), this, SLOT(displayHelp()));
89        this->addAction(displayHelpAct);
90        
91        //go to top
92        goToTopAct = new QAction(tr("Display &Help"), this);
93        goToTopAct->setShortcut(tr("Ctrl+T"));
94        goToTopAct->setStatusTip(tr("Display Help"));
95        connect(goToTopAct, SIGNAL(triggered()), this->centralWidget, SLOT(goToTop()));
96        this->addAction(goToTopAct);
97        
98        // quit qvido
99        quitAct = new QAction(tr("Quit QVido"), this);
100        quitAct->setShortcut(tr("Ctrl+Q"));
101        quitAct->setStatusTip(tr("Quit"));
102        connect(quitAct, SIGNAL(triggered()), qApp, SLOT(quit()));
103        this->addAction(quitAct);
104}
105
106void QMain::displayHelp(){
107    QString txt = "Usage: \n";
108    txt.append("Ctrl + R = Display random article\n");
109    txt.append("Ctrl + S = Search for article\n");
110    txt.append("Ctrl + T = Go to articles top\n");
111    txt.append("Tab = Rotate through links\n");
112    txt.append("Enter = Activate link\n");
113// txt.append("Ctrl + H = Display history\n");
114// txt.append("Ctrl + B = Go back in history\n");
115// txt.append("Ctrl + F = Go forward in history\n");
116    txt.append("Ctrl + Q = Quit Vido\n");
117    txt.append("F1 = Display this help\n");
118
119    QMessageBox::information(this, "Help",
120                                                     txt,
121                           QMessageBox::Close);
122 
123}

Archive Download this file

Branches:
master



interactive