Seafood/mainwindow.cpp
author John Kern <johnk@symbian.org>
Thu, 25 Mar 2010 16:49:34 -0700
changeset 7 7ee47a65f1ad
parent 3 e6d1a78b6db9
child 10 79eeacfd15ff
permissions -rw-r--r--
wip
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
     1
#include <QFile>
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
     2
#include <QIcon>
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
     3
#include <QListWidget>
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
     4
#include <QMessageBox>
7
John Kern <johnk@symbian.org>
parents: 3
diff changeset
     5
#include <QStackedWidget>
3
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
     6
#include <QTableWidget>
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
     7
#include <QDesktopServices>
7
John Kern <johnk@symbian.org>
parents: 3
diff changeset
     8
#include <QWebView>
3
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
     9
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    10
#include "Fishes.h"
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    11
#include "mainwindow.h"
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    12
#include "ui_mainwindow.h"
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    13
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    14
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    15
MainWindow::MainWindow(QWidget *parent) :
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    16
    QMainWindow(parent),
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    17
    ui(new Ui::MainWindow)
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    18
{
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    19
    ui->setupUi(this);
7
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    20
    setContextMenuPolicy(Qt::NoContextMenu);
3
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    21
    Fishes *f = new Fishes();
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    22
7
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    23
    this->stackedWidget = new QStackedWidget;
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    24
3
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    25
    this->tabWidget = new QTabWidget;
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    26
    // QIcon icon = new QIcon(":/database/icons/weather-sunny.svg");
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    27
    // this->tabWidget->setTabIcon(1, icon);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    28
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    29
    this->bestList = new QListWidget;
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    30
    this->bestList->addItems(f->GetBest());
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    31
    this->tabWidget->addTab(this->bestList, "best");
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    32
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    33
    this->okList = new QListWidget;
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    34
    this->okList->addItems(f->GetOK());
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    35
    this->tabWidget->addTab(this->okList, "ok");
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    36
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    37
    this->worstList = new QListWidget;
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    38
    this->worstList->addItems(f->GetWorst());
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    39
    this->tabWidget->addTab(this->worstList, "worst");
7
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    40
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    41
    this->stackedWidget->addWidget(tabWidget); // associated with EListPage
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    42
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    43
    this->ecoDetails = new QWebView;
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    44
    this->ecoDetails->setHtml("<html><title>Eco Details</title><ul><li>not yet implemented</li></ul></html>");
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    45
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    46
    this->stackedWidget->addWidget(this->ecoDetails); // associated with EEcoPage
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    47
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    48
    this->stackedWidget->addWidget(ui->centralWidget); // associated with ENutritionPage
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    49
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    50
    setCentralWidget(stackedWidget);
3
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    51
}
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    52
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    53
MainWindow::~MainWindow()
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    54
{
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    55
    delete ui;
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    56
}
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    57
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    58
void MainWindow::createMenus()
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    59
    {
7
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    60
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    61
        ecoAction = new QAction(tr("&eco details"),this);
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    62
        menuBar()->addAction(ecoAction);
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    63
        connect(ecoAction, SIGNAL(triggered()),this, SLOT(displayEcoDetails()));
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    64
3
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    65
        nuAction = new QAction(tr("&Nutrition"),this);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    66
        menuBar()->addAction(nuAction);
7
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    67
        connect(nuAction, SIGNAL(triggered()),this, SLOT(displayNutrition()));
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    68
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    69
        fishesAction = new QAction(tr("&List Fishes"),this);
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    70
        menuBar()->addAction(fishesAction);
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    71
        connect(fishesAction, SIGNAL(triggered()),this, SLOT(displayList()));
3
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    72
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    73
        verAction = new QAction(tr("&Version"),this);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    74
        menuBar()->addAction(verAction);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    75
        connect(verAction, SIGNAL(triggered()),this, SLOT(displayVersion()));
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    76
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    77
        exitAction = new QAction(tr("&Exit"),this);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    78
        menuBar()->addAction(exitAction);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    79
        connect(exitAction, SIGNAL(triggered()),this, SLOT(close()));
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    80
    }
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    81
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    82
void MainWindow::displayVersion()
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    83
{
7
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    84
//    QMessageBox::information(this,"Qt Version", qVersion());
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    85
     QMessageBox::information(this,"selected item", "NYI");
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    86
}
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    87
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    88
void MainWindow::displayNutrition()
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    89
{
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    90
    this->stackedWidget->setCurrentIndex(MainWindow::ENutritionPage);
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    91
}
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    92
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    93
void MainWindow::displayEcoDetails()
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    94
{
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    95
    this->stackedWidget->setCurrentIndex(MainWindow::EEcoPage);
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    96
}
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    97
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    98
void MainWindow::displayList()
John Kern <johnk@symbian.org>
parents: 3
diff changeset
    99
{
John Kern <johnk@symbian.org>
parents: 3
diff changeset
   100
    this->stackedWidget->setCurrentIndex(MainWindow::EListPage);
3
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   101
}
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   102
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   103
void MainWindow::displayPath()
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   104
{
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   105
    QString dbFile = QDesktopServices::storageLocation(QDesktopServices::DataLocation)
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   106
                     + '/'  // Qt Universal file separator
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   107
                     + "seafood.db";
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   108
    QFile f(dbFile);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   109
    if (f.exists()) {
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   110
        QMessageBox::information(this,"db not found ", dbFile);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   111
    } else {
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   112
        QMessageBox::information(this,"found db @ ", dbFile);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   113
    }
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   114
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   115
}
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   116
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   117
void MainWindow::changeEvent(QEvent *e)
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   118
{
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   119
    QMainWindow::changeEvent(e);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   120
    switch (e->type()) {
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   121
    case QEvent::LanguageChange:
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   122
        ui->retranslateUi(this);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   123
        break;
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   124
    default:
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   125
        break;
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   126
    }
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
   127
}