~ubuntu-branches/ubuntu/quantal/fet/quantal

« back to all changes in this revision

Viewing changes to src/interface/constraintstudentsmaxhourscontinuouslyform.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2008-05-05 22:28:46 UTC
  • mfrom: (1.1.6 upstream) (3.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080505222846-l34al11t2vivuh3h
Tags: 5.5.5-1ubuntu1
* Merge from debian unstable (LP: #227080), remaining changes:
  - Include .desktop file and logo

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          constraintstudentsmaxhourscontinuouslyform.cpp  -  description
 
3
                             -------------------
 
4
    begin                : July 19, 2007
 
5
    copyright            : (C) 2007 by Lalescu Liviu
 
6
    email                : Please see http://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address)
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
 
 
18
#include "constraintstudentsmaxhourscontinuouslyform.h"
 
19
#include "addconstraintstudentsmaxhourscontinuouslyform.h"
 
20
#include "modifyconstraintstudentsmaxhourscontinuouslyform.h"
 
21
 
 
22
#include <QDesktopWidget>
 
23
 
 
24
ConstraintStudentsMaxHoursContinuouslyForm::ConstraintStudentsMaxHoursContinuouslyForm()
 
25
{
 
26
        //setWindowFlags(Qt::Window);
 
27
        setWindowFlags(windowFlags() | Qt::WindowMinMaxButtonsHint);
 
28
        QDesktopWidget* desktop=QApplication::desktop();
 
29
        int xx=desktop->width()/2 - frameGeometry().width()/2;
 
30
        int yy=desktop->height()/2 - frameGeometry().height()/2;
 
31
        move(xx, yy);
 
32
 
 
33
        this->filterChanged();
 
34
}
 
35
 
 
36
ConstraintStudentsMaxHoursContinuouslyForm::~ConstraintStudentsMaxHoursContinuouslyForm()
 
37
{
 
38
}
 
39
 
 
40
bool ConstraintStudentsMaxHoursContinuouslyForm::filterOk(TimeConstraint* ctr)
 
41
{
 
42
        if(ctr->type==CONSTRAINT_STUDENTS_MAX_HOURS_CONTINUOUSLY)
 
43
                return true;
 
44
        else
 
45
                return false;
 
46
}
 
47
 
 
48
void ConstraintStudentsMaxHoursContinuouslyForm::filterChanged()
 
49
{
 
50
        this->visibleConstraintsList.clear();
 
51
        constraintsListBox->clear();
 
52
        for(int i=0; i<gt.rules.timeConstraintsList.size(); i++){
 
53
                TimeConstraint* ctr=gt.rules.timeConstraintsList[i];
 
54
                if(filterOk(ctr)){
 
55
                        visibleConstraintsList.append(ctr);
 
56
                        constraintsListBox->insertItem(ctr->getDescription(gt.rules));
 
57
                }
 
58
        }
 
59
}
 
60
 
 
61
void ConstraintStudentsMaxHoursContinuouslyForm::constraintChanged(int index)
 
62
{
 
63
        if(index<0)
 
64
                return;
 
65
        assert(index<this->visibleConstraintsList.size());
 
66
        TimeConstraint* ctr=this->visibleConstraintsList.at(index);
 
67
        assert(ctr!=NULL);
 
68
        currentConstraintTextEdit->setText(ctr->getDetailedDescription(gt.rules));
 
69
}
 
70
 
 
71
void ConstraintStudentsMaxHoursContinuouslyForm::addConstraint()
 
72
{
 
73
        AddConstraintStudentsMaxHoursContinuouslyForm *form=new AddConstraintStudentsMaxHoursContinuouslyForm();
 
74
        form->exec();
 
75
 
 
76
        filterChanged();
 
77
        
 
78
        constraintsListBox->setCurrentItem(constraintsListBox->count()-1);
 
79
}
 
80
 
 
81
void ConstraintStudentsMaxHoursContinuouslyForm::modifyConstraint()
 
82
{
 
83
        int i=constraintsListBox->currentItem();
 
84
        if(i<0){
 
85
                QMessageBox::information(this, QObject::tr("FET information"), QObject::tr("Invalid selected constraint"));
 
86
                return;
 
87
        }
 
88
        TimeConstraint* ctr=this->visibleConstraintsList.at(i);
 
89
 
 
90
        ModifyConstraintStudentsMaxHoursContinuouslyForm *form
 
91
         = new ModifyConstraintStudentsMaxHoursContinuouslyForm((ConstraintStudentsMaxHoursContinuously*)ctr);
 
92
        form->exec();
 
93
 
 
94
        filterChanged();
 
95
        constraintsListBox->setCurrentItem(i);
 
96
}
 
97
 
 
98
void ConstraintStudentsMaxHoursContinuouslyForm::removeConstraint()
 
99
{
 
100
        int i=constraintsListBox->currentItem();
 
101
        if(i<0){
 
102
                QMessageBox::information(this, QObject::tr("FET information"), QObject::tr("Invalid selected constraint"));
 
103
                return;
 
104
        }
 
105
        TimeConstraint* ctr=this->visibleConstraintsList.at(i);
 
106
        QString s;
 
107
        s=QObject::tr("Removing constraint:\n");
 
108
        s+=ctr->getDetailedDescription(gt.rules);
 
109
        s+=QObject::tr("\nAre you sure?");
 
110
 
 
111
        switch( QMessageBox::warning( this, QObject::tr("FET warning"),
 
112
                s, QObject::tr("OK"), QObject::tr("Cancel"), 0, 0, 1 ) ){
 
113
        case 0: // The user clicked the OK again button or pressed Enter
 
114
                gt.rules.removeTimeConstraint(ctr);
 
115
                filterChanged();
 
116
                break;
 
117
        case 1: // The user clicked the Cancel or pressed Escape
 
118
                break;
 
119
        }
 
120
        
 
121
        if((uint)(i) >= constraintsListBox->count())
 
122
                i=constraintsListBox->count()-1;
 
123
        constraintsListBox->setCurrentItem(i);
 
124
}