Ignore:
Timestamp:
01/26/10 20:17:47 (12 years ago)
Author:
pavelpa <pavelpa@…>
Branches:
master, qt5
Children:
3a8dc71
Parents:
61ff1b8
Message:

implemented 'tab container' widget, which groups daynavigator with treeview

  • moved functionality from mainwindow to tabcontainer
  • TODO: 'search' tab not done yet
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/gui/mainwindow.cpp

    r61ff1b8 r05afe5f  
    33
    44#include <QTreeView>
    5 #include <QDirModel>
     5#include <QFile>
    66
    77#include <sqlengine.h>
     
    1515#include <QDialog>
    1616#include <QMessageBox>
    17 #include <QTimer>
    1817#include "ui_about.h"
    19 #include "eventdialog.h"
     18#include <eventdialog.h>
    2019#include "daynavigatorwidget.h"
    2120#include "importschedulewidget.h"
    2221#include "mapwindow.h"
    2322
     23#include <tabcontainer.h>
     24
    2425MainWindow::MainWindow(int aEventId, QWidget *aParent)
    2526    : QMainWindow(aParent)
     
    3031    // opens DB connection (needed for EventModel)
    3132    mSqlEngine = new SqlEngine(this);
    32     mSqlEngine->initialize();
     33    //mSqlEngine->initialize();
    3334    importScheduleWidget->setSqlEngine(mSqlEngine);
    3435
     
    4950    }
    5051
     52    dayTabContainer->setType(TabContainer::EContainerTypeDay);
     53    favsTabContainer->setType(TabContainer::EContainerTypeFavs);
     54    tracksTabContainer->setType(TabContainer::EContainerTypeTracks);
     55    nowTabContainer->setType(TabContainer::EContainerTypeNow);
     56    roomsTabContainer->setType(TabContainer::EContainerTypeRooms);
     57
    5158    connect(importScheduleWidget, SIGNAL(scheduleImported(int)), SLOT(scheduleImported(int)));
    5259
    53     connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateDayView(const QDate &)));
    54     connect(trackDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTracksView(const QDate &)));
    55     connect(favouriteDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateFavouritesView(const QDate &)));
    5660    connect(searchDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateSearchView(const QDate &)));
    57     connect(roomDayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateRoomView(const QDate &)));
    58 
    59     // DAY EVENTS View
    60     dayTreeView->setHeaderHidden(true);
    61     dayTreeView->setRootIsDecorated(false);
    62     dayTreeView->setIndentation(0);
    63     dayTreeView->setAnimated(true);
    64     dayTreeView->setModel(new EventModel());
    65     dayTreeView->setItemDelegate(new Delegate(dayTreeView));
    66 
    67     // FAVOURITIES View
    68     favTreeView->setHeaderHidden(true);
    69     favTreeView->setRootIsDecorated(false);
    70     favTreeView->setIndentation(0);
    71     favTreeView->setAnimated(true);
    72     favTreeView->setModel(new EventModel());
    73     favTreeView->setItemDelegate(new Delegate(favTreeView));
    74 
    75     // TRACKS View
    76     trackTreeView->setHeaderHidden(true);
    77     trackTreeView->setRootIsDecorated(false);
    78     trackTreeView->setIndentation(0);
    79     trackTreeView->setAnimated(true);
    80     trackTreeView->setModel(new EventModel());
    81     trackTreeView->setItemDelegate(new Delegate(trackTreeView));
    8261
    8362    // SEARCH EVENTS View
     
    8968        searchTreeView->setItemDelegate(new Delegate(searchTreeView));
    9069
    91     // NOW View
    92         nowTreeView->setHeaderHidden(true);
    93         nowTreeView->setRootIsDecorated(false);
    94         nowTreeView->setIndentation(0);
    95         nowTreeView->setAnimated(true);
    96         nowTreeView->setModel(new EventModel());
    97         nowTreeView->setItemDelegate(new Delegate(nowTreeView));
    98 
    99         // NOW View refresh timer
    100     QTimer *timer = new QTimer( this );
    101     connect( timer, SIGNAL(timeout()), SLOT(timerUpdateNowView()) );
    102     timer->start( 30000); // 30 seconds timer
    103 
    104     // ROOMS View
    105     roomTreeView->setHeaderHidden(true);
    106     roomTreeView->setRootIsDecorated(false);
    107     roomTreeView->setIndentation(0);
    108     roomTreeView->setAnimated(true);
    109     roomTreeView->setModel(new EventModel());
    110     roomTreeView->setItemDelegate(new Delegate(roomTreeView));
    111 
    11270    // event details have changed
    113     connect(dayTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
    114     connect(favTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
    115     connect(trackTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
     71    connect(dayTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
     72    connect(favsTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
     73    connect(favsTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
     74    connect(roomsTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
     75    connect(nowTabContainer, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
     76
    11677    connect(searchTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
    117     connect(nowTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
    118     connect(roomTreeView, SIGNAL(eventHasChanged(int)), SLOT(eventHasChanged(int)));
    11978
    12079    // event clicked
    121     connect(dayTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
    122     connect(favTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
    123     connect(trackTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
    12480    connect(searchTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
    125     connect(nowTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
    126     connect(roomTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
    127     // request for map to be displayed
    128     connect(dayTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
    129     connect(favTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
    130     connect(trackTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
    131     connect(searchTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
    132     connect(nowTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
    133     connect(roomTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
    134     // request for warning to be displayed
    135     connect(dayTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
    136     connect(favTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
    137     connect(trackTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
    138     connect(searchTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
    139     connect(nowTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
    140     connect(roomTreeView, SIGNAL(requestForWarning(const QModelIndex &)), SLOT(displayWarning(const QModelIndex &)));
     81
    14182    // event search button clicked
    14283    connect(searchButton, SIGNAL(clicked()), SLOT(searchClicked()));
    14384    connect(searchAgainButton, SIGNAL(clicked()), SLOT(searchAgainClicked()));
     85
    14486    // event conference map button clicked
    14587    connect(showMapButton, SIGNAL(clicked()), SLOT(conferenceMapClicked()));
    14688    //
    147     connect(tabWidget, SIGNAL(currentChanged(int)), SLOT(tabHasChanged(int)));
    14889    connect(tabWidget, SIGNAL(infoIconClicked()), SLOT(aboutApp()));
    14990
    150     if(!Conference::getAll().count()) // no conference(s) in the DB
    151     {
    152         dayNavigator->hide(); // hide DayNavigatorWidget
    153         trackDayNavigator->hide();
    154         roomDayNavigator->hide();
    155     }
    156     else
     91    if(Conference::getAll().count()) // no conference(s) in the DB
    15792    {
    15893        QDate aStartDate = Conference::getById(AppSettings::confId()).start();
    15994        QDate aEndDate = Conference::getById(AppSettings::confId()).end();
    160         dayNavigator->setDates(aStartDate, aEndDate);
    161         trackDayNavigator->setDates(aStartDate, aEndDate);
    162         favouriteDayNavigator->setDates(aStartDate, aEndDate);
    16395        searchDayNavigator->setDates(aStartDate, aEndDate);
    164         roomDayNavigator->setDates(aStartDate, aEndDate);
     96        //
     97        dayTabContainer->setDates(aStartDate, aEndDate);
     98        tracksTabContainer->setDates(aStartDate, aEndDate);
     99        roomsTabContainer->setDates(aStartDate, aEndDate);
     100        favsTabContainer->setDates(aStartDate, aEndDate);
    165101        //
    166102        conferenceTitle->setText(Conference::getById(AppSettings::confId()).title());
     
    215151
    216152        // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates
    217         QDate aStartDate = Conference::getById(AppSettings::confId()).start();
    218         QDate aEndDate = Conference::getById(AppSettings::confId()).end();
    219         dayNavigator->setDates(aStartDate, aEndDate);
    220         trackDayNavigator->setDates(aStartDate, aEndDate);
    221         roomDayNavigator->setDates(aStartDate, aEndDate);
     153        QDate startDate = Conference::getById(AppSettings::confId()).start();
     154        QDate endDate = Conference::getById(AppSettings::confId()).end();
     155        dayTabContainer->setDates(startDate, endDate);
     156        tracksTabContainer->setDates(startDate, endDate);
     157        roomsTabContainer->setDates(startDate, endDate);
     158        favsTabContainer->setDates(startDate, endDate);
    222159    }
    223160}
     
    229166    ui.setupUi(&dialog);
    230167    dialog.exec();
    231 }
    232 
    233 void MainWindow::updateDayView(const QDate &aDate)
    234 {
    235     static_cast<EventModel*>(dayTreeView->model())->loadEvents(aDate,AppSettings::confId());
    236     dayTreeView->reset();
    237     dayNavigator->show();
    238 }
    239 
    240 void MainWindow::updateTracksView(const QDate &aDate)
    241 {
    242     static_cast<EventModel*>(trackTreeView->model())->loadEventsByTrack(aDate, AppSettings::confId());
    243     trackTreeView->reset();
    244     trackDayNavigator->show();
    245 }
    246 
    247 void MainWindow::updateFavouritesView(const QDate &aDate)
    248 {
    249     static_cast<EventModel*>(favTreeView->model())->loadFavEvents(aDate,AppSettings::confId());
    250     favTreeView->reset();
    251     favouriteDayNavigator->show();
    252168}
    253169
     
    269185        searchHead->show();
    270186    }
    271 }
    272 
    273 void MainWindow::updateNowView()
    274 {
    275     EventModel *model = static_cast<EventModel*>(nowTreeView->model());
    276     model->loadNowEvents(AppSettings::confId());
    277     nowTreeView->reset();
    278     nowTreeView->setAllExpanded(true);
    279 }
    280 
    281 void MainWindow::updateRoomView(const QDate &aDate)
    282 {
    283     static_cast<EventModel*>(roomTreeView->model())->loadEventsByRoom(aDate, AppSettings::confId());
    284     roomTreeView->reset();
    285     roomDayNavigator->show();
    286 }
    287 
    288 void MainWindow::itemClicked(const QModelIndex &aIndex)
    289 {
    290     // have to handle only events, not time-groups
    291     if(!aIndex.parent().isValid()) // time-group
    292         return;
    293 
    294     EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
    295     dialog.exec();
    296 }
    297 
    298 void MainWindow::displayMap(const QModelIndex &aIndex)
    299 {
    300     Event *event = static_cast<Event*>(aIndex.internalPointer());
    301 
    302     // room names are stored in lower-case format
    303     // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
    304     QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
    305     if(!QFile::exists(mapPath))
    306         mapPath = QString(":/maps/rooms/not-available.png");
    307 
    308     QString roomName;
    309     if(mapPath.contains("not-available", Qt::CaseInsensitive))
    310         roomName = QString("Map is not available: %1").arg(event->room());
    311     else
    312         roomName = event->room();
    313 
    314     QPixmap map(mapPath);
    315     MapWindow window(map,roomName,this);
    316     window.exec();
    317187}
    318188
     
    348218    searchVerticalWidget->hide();
    349219    searchTreeView->hide();
    350 
    351220}
    352221
    353222void MainWindow::conferenceMapClicked()
    354223{
    355 
    356224    QString mapPath = QString(":/maps/campus.png");
    357225    if(!QFile::exists(mapPath))
     
    365233}
    366234
    367 void MainWindow::displayWarning(const QModelIndex &aIndex)
    368 {
    369     Q_UNUSED(aIndex);
    370 
    371     QMessageBox::warning(
    372     this,
    373     tr("Time Conflict Warning"),
    374     tr("This event happens at the same time than another one of your favourites.") );
    375 }
    376 
    377235void MainWindow::eventHasChanged(int aEventId)
    378236{
    379     static_cast<EventModel*>(dayTreeView->model())->updateModel(aEventId);
    380 
    381     // we need to reload favourites, because some favourite could be deleted
    382     //static_cast<EventModel*>(favTreeView->model())->updateModel(aEventId);
    383     QDate aStartDate = Conference::getById(AppSettings::confId()).start();
    384     QDate aEndDate = Conference::getById(AppSettings::confId()).end();
    385     favouriteDayNavigator->setDates(aStartDate, aEndDate);
    386     updateFavouritesView( Conference::getById(AppSettings::confId()).start() );
    387 
    388     static_cast<EventModel*>(trackTreeView->model())->updateModel(aEventId);
     237    dayTabContainer->updateTreeViewModel(aEventId);
     238    favsTabContainer->updateTreeViewModel(aEventId);
     239    tracksTabContainer->updateTreeViewModel(aEventId);
     240    nowTabContainer->updateTreeViewModel(aEventId);
     241    roomsTabContainer->updateTreeViewModel(aEventId);
     242
    389243    static_cast<EventModel*>(searchTreeView->model())->updateModel(aEventId);
    390     static_cast<EventModel*>(nowTreeView->model())->updateModel(aEventId);
    391     static_cast<EventModel*>(roomTreeView->model())->updateModel(aEventId);
    392 }
    393 
    394 void MainWindow::tabHasChanged(int aIndex)
    395 {
    396     Q_UNUSED(aIndex);
    397 
    398     // TODO: only if it changed to favourities tab
    399     updateFavouritesView(favouriteDayNavigator->getCurrentDate());
    400     // TODO: only if it changed to now tab
    401     updateNowView();
    402 }
    403 
    404 void MainWindow::timerUpdateNowView()
    405 {
    406         QWidget * pCurrentWidget = tabWidget->widget(tabWidget->currentIndex());
    407 
    408         if( pCurrentWidget != NULL )
    409         {
    410                 if( pCurrentWidget == tab )
    411                     updateNowView();
    412         }
    413 }
     244}
     245
Note: See TracChangeset for help on using the changeset viewer.