source: src/gui/tabcontainer.cpp @ 68b2df2

qt5
Last change on this file since 68b2df2 was 68b2df2, checked in by gregor herrmann <gregoa@…>, 10 years ago

Add copyright to source.

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011 Philipp Spitzer, gregor herrmann
4 *
5 * This file is part of ConfClerk.
6 *
7 * ConfClerk is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * ConfClerk is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
19 */
20#include "tabcontainer.h"
21
22#include <QFile>
23#include <QMessageBox>
24#include <QTimer>
25
26#include <treeview.h>
27#include <delegate.h>
28
29#include "eventdialog.h"
30#include "mapwindow.h"
31#include "room.h"
32#include "errormessage.h"
33
34#include "conflictsdialog.h"
35
36TabContainer::TabContainer(QWidget *aParent)
37    : QWidget(aParent)
38{
39    setupUi(this);
40
41    treeView->setHeaderHidden(true);
42    treeView->setRootIsDecorated(false);
43    treeView->setIndentation(0);
44    treeView->setAnimated(true);
45    treeView->setModel(new EventModel());
46    treeView->setItemDelegate(new Delegate(treeView));
47
48    connect(dayNavigator, SIGNAL(dateChanged(const QDate &)), SLOT(updateTreeView(const QDate &)));
49
50    connect(treeView, SIGNAL(eventHasChanged(int,bool)), SIGNAL(eventHasChanged(int,bool)));
51    connect(treeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &)));
52    connect(treeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &)));
53    connect(treeView, SIGNAL(requestForConflicts(const QModelIndex &)), SLOT(displayConflicts(const QModelIndex &)));
54
55    // day navigator is hidden by default
56    dayNavigator->hide();
57}
58
59void TabContainer::updateTreeView(const QDate &aDate)
60{
61    int active_id = Conference::activeConference();
62    dayNavigator->show();
63    if (active_id > 0) {
64        loadEvents(aDate, active_id);
65    } else {
66        static_cast<EventModel*>(treeView->model())->clearModel();
67    }
68}
69
70void TabContainer::itemClicked(const QModelIndex &aIndex)
71{
72    // have to handle only events, not time-groups
73    if(!aIndex.parent().isValid()) // time-group
74        return;
75
76    EventDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
77#ifdef N810
78    dialog.setFixedWidth(static_cast<QWidget*>(parent())->width());
79#endif
80    connect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
81    dialog.exec();
82    disconnect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
83}
84
85void TabContainer::displayMap(const QModelIndex &aIndex)
86{
87    Event *event = static_cast<Event*>(aIndex.internalPointer());
88
89    QVariant mapPathV = event->room()->map();
90    QString mapPath;
91    if (!mapPathV.isValid()) {
92        error_message("No map for this room");
93        return;
94    } else {
95        mapPath = mapPathV.toString();
96        if (!QFile::exists(mapPath)) {
97            error_message("Map for this room not found: " + mapPath);
98            return;
99        }
100    }
101
102    QPixmap map(mapPath);
103    MapWindow window(map, event->room()->name(),this);
104    window.exec();
105}
106
107void TabContainer::displayConflicts(const QModelIndex &aIndex)
108{
109    ConflictsDialog dialog(static_cast<Event*>(aIndex.internalPointer())->id(),this);
110#ifdef N810
111    dialog.setFixedWidth(static_cast<QWidget*>(parent())->width());
112#endif
113    connect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
114    dialog.exec();
115    disconnect(&dialog, SIGNAL(eventHasChanged(int,bool)), this, SIGNAL(eventHasChanged(int,bool)));
116}
117
118void TabContainer::updateTreeViewModel(int aEventId, bool aReloadModel)
119{
120    if(aReloadModel)
121    {
122        // requires special handling
123        // eg. in case of favourities - some favourities may have changed
124        // and so we need to reload them
125        int confId = Conference::activeConference();
126        QDate startDate = Conference::getById(confId).start();
127        QDate endDate = Conference::getById(confId).end();
128        dayNavigator->setDates(startDate, endDate);
129        updateTreeView( Conference::getById(confId).start() );
130    }
131    else
132    {
133        // just update event in the question
134        static_cast<EventModel*>(treeView->model())->updateModel(aEventId);
135    }
136}
137
138void TabContainer::setDates(const QDate &aStart, const QDate &aEnd)
139{
140    dayNavigator->setDates(aStart, aEnd);
141}
142
143void TabContainer::clearModel()
144{
145    static_cast<EventModel*>(treeView->model())->clearModel();
146}
147
Note: See TracBrowser for help on using the repository browser.