Seafood/mainwindow.cpp
author John Kern <johnk@symbian.org>
Wed, 24 Mar 2010 14:05:38 -0700
changeset 3 e6d1a78b6db9
child 7 7ee47a65f1ad
permissions -rw-r--r--
wip - start of an example for my forthcoming presentation
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>
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
     5
#include <QTableWidget>
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
     6
#include <QDesktopServices>
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
     7
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
     8
#include "Fishes.h"
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
     9
#include "mainwindow.h"
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    10
#include "ui_mainwindow.h"
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    11
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    12
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    13
MainWindow::MainWindow(QWidget *parent) :
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    14
    QMainWindow(parent),
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    15
    ui(new Ui::MainWindow)
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    16
{
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    17
    ui->setupUi(this);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    18
    Fishes *f = new Fishes();
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    19
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    20
    this->tabWidget = new QTabWidget;
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    21
    // 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
    22
    // this->tabWidget->setTabIcon(1, icon);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    23
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    24
    this->bestList = new QListWidget;
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    25
    this->bestList->addItems(f->GetBest());
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    26
    this->tabWidget->addTab(this->bestList, "best");
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    27
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    28
    this->okList = new QListWidget;
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    29
    this->okList->addItems(f->GetOK());
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    30
    this->tabWidget->addTab(this->okList, "ok");
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    31
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    32
    this->worstList = new QListWidget;
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    33
    this->worstList->addItems(f->GetWorst());
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    34
    this->tabWidget->addTab(this->worstList, "worst");
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    35
    setCentralWidget(tabWidget);
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
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    38
MainWindow::~MainWindow()
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    39
{
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    40
    delete ui;
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    41
}
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    42
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    43
void MainWindow::createMenus()
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    44
    {
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    45
        nuAction = new QAction(tr("&Nutrition"),this);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    46
        menuBar()->addAction(nuAction);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    47
        connect(nuAction, SIGNAL(triggered()),this, SLOT(displayVersion()));
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    48
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    49
        verAction = new QAction(tr("&Version"),this);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    50
        menuBar()->addAction(verAction);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    51
        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
    52
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    53
        exitAction = new QAction(tr("&Exit"),this);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    54
        menuBar()->addAction(exitAction);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    55
        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
    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::displayVersion()
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    59
{
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    60
    QMessageBox::information(this,"Qt Version", qVersion());
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    61
}
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    62
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    63
void MainWindow::displayPath()
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    64
{
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    65
    QString dbFile = QDesktopServices::storageLocation(QDesktopServices::DataLocation)
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    66
                     + '/'  // Qt Universal file separator
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    67
                     + "seafood.db";
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    68
    QFile f(dbFile);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    69
    if (f.exists()) {
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    70
        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
    71
    } else {
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    72
        QMessageBox::information(this,"found db @ ", dbFile);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    73
    }
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    74
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    75
}
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
void MainWindow::changeEvent(QEvent *e)
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    78
{
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    79
    QMainWindow::changeEvent(e);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    80
    switch (e->type()) {
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    81
    case QEvent::LanguageChange:
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    82
        ui->retranslateUi(this);
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    83
        break;
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    84
    default:
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    85
        break;
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    86
    }
e6d1a78b6db9 wip - start of an example for my forthcoming presentation
John Kern <johnk@symbian.org>
parents:
diff changeset
    87
}