Seafood/mainwindow.cpp
changeset 3 e6d1a78b6db9
child 7 7ee47a65f1ad
equal deleted inserted replaced
2:6894bf2709c0 3:e6d1a78b6db9
       
     1 #include <QFile>
       
     2 #include <QIcon>
       
     3 #include <QListWidget>
       
     4 #include <QMessageBox>
       
     5 #include <QTableWidget>
       
     6 #include <QDesktopServices>
       
     7 
       
     8 #include "Fishes.h"
       
     9 #include "mainwindow.h"
       
    10 #include "ui_mainwindow.h"
       
    11 
       
    12 
       
    13 MainWindow::MainWindow(QWidget *parent) :
       
    14     QMainWindow(parent),
       
    15     ui(new Ui::MainWindow)
       
    16 {
       
    17     ui->setupUi(this);
       
    18     Fishes *f = new Fishes();
       
    19 
       
    20     this->tabWidget = new QTabWidget;
       
    21     // QIcon icon = new QIcon(":/database/icons/weather-sunny.svg");
       
    22     // this->tabWidget->setTabIcon(1, icon);
       
    23 
       
    24     this->bestList = new QListWidget;
       
    25     this->bestList->addItems(f->GetBest());
       
    26     this->tabWidget->addTab(this->bestList, "best");
       
    27 
       
    28     this->okList = new QListWidget;
       
    29     this->okList->addItems(f->GetOK());
       
    30     this->tabWidget->addTab(this->okList, "ok");
       
    31 
       
    32     this->worstList = new QListWidget;
       
    33     this->worstList->addItems(f->GetWorst());
       
    34     this->tabWidget->addTab(this->worstList, "worst");
       
    35     setCentralWidget(tabWidget);
       
    36 }
       
    37 
       
    38 MainWindow::~MainWindow()
       
    39 {
       
    40     delete ui;
       
    41 }
       
    42 
       
    43 void MainWindow::createMenus()
       
    44     {
       
    45         nuAction = new QAction(tr("&Nutrition"),this);
       
    46         menuBar()->addAction(nuAction);
       
    47         connect(nuAction, SIGNAL(triggered()),this, SLOT(displayVersion()));
       
    48 
       
    49         verAction = new QAction(tr("&Version"),this);
       
    50         menuBar()->addAction(verAction);
       
    51         connect(verAction, SIGNAL(triggered()),this, SLOT(displayVersion()));
       
    52 
       
    53         exitAction = new QAction(tr("&Exit"),this);
       
    54         menuBar()->addAction(exitAction);
       
    55         connect(exitAction, SIGNAL(triggered()),this, SLOT(close()));
       
    56     }
       
    57 
       
    58 void MainWindow::displayVersion()
       
    59 {
       
    60     QMessageBox::information(this,"Qt Version", qVersion());
       
    61 }
       
    62 
       
    63 void MainWindow::displayPath()
       
    64 {
       
    65     QString dbFile = QDesktopServices::storageLocation(QDesktopServices::DataLocation)
       
    66                      + '/'  // Qt Universal file separator
       
    67                      + "seafood.db";
       
    68     QFile f(dbFile);
       
    69     if (f.exists()) {
       
    70         QMessageBox::information(this,"db not found ", dbFile);
       
    71     } else {
       
    72         QMessageBox::information(this,"found db @ ", dbFile);
       
    73     }
       
    74 
       
    75 }
       
    76 
       
    77 void MainWindow::changeEvent(QEvent *e)
       
    78 {
       
    79     QMainWindow::changeEvent(e);
       
    80     switch (e->type()) {
       
    81     case QEvent::LanguageChange:
       
    82         ui->retranslateUi(this);
       
    83         break;
       
    84     default:
       
    85         break;
       
    86     }
       
    87 }