-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlglearnassistant.cpp
117 lines (100 loc) · 3.92 KB
/
dlglearnassistant.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/***************************************************************************
* Copyright (C) 2003-2007 by Oliver Saal *
* osaal@gmx.de *
* http://www.oliver-saal.de/software/afutrainer/ *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "dlglearnassistant.h"
#include <qheaderview.h>
#include <qmessagebox.h>
#include "catalog.h"
CDlgLearnAssistant::CDlgLearnAssistant (QWidget *pParent) : QDialog(pParent)
{
m_pCatalog=0;
setupUi(this);
tvChapters->setModel (&m_modelChapter);
tvChapters->header()->setStretchLastSection(false);
tvChapters->header()->setResizeMode (0, QHeaderView::Stretch);
tvChapters->header()->setResizeMode (1, QHeaderView::Interactive);
tvChapters->header()->setResizeMode (3, QHeaderView::Interactive);
tvChapters->header()->resizeSection(1, 50);
tvChapters->header()->resizeSection(2, 140);
tvChapters->header()->resizeSection(3, 20);
}
bool CDlgLearnAssistant::setup(CCatalog *pCatalog)
{
bool bEnableRepeat;
QList<CChapter*> listAll, listNow, listToday, listSelected;
CChapter *c;
m_pCatalog = pCatalog;
if (pCatalog->recommendationCount (CChapter::RecommendationRepeatToday) > 0)
{
bEnableRepeat = true;
labRepeat->setText(tr("Es sind %1 Fragen vorhanden").arg(pCatalog->recommendedQuestions().count()));
rbRepeat->setChecked(true);
}
else
{
bEnableRepeat = false;
labRepeat->setText(tr("Keine Fragen vorhanden."));
rbList->setChecked(true);
}
rbRepeat->setEnabled(bEnableRepeat);
labRepeat->setEnabled(bEnableRepeat);
// update list
listAll = pCatalog->chapters();
for (int i=0; i<listAll.size(); i++)
{
c = listAll.at(i);
if (c->isRecommendedNow(pCatalog))
listNow << c;
else if (c->recommendation() == CChapter::RecommendationLearnNew)
listToday << c;
}
listSelected << listNow << listToday;
m_modelChapter.setModelData (pCatalog, listSelected);
if (!bEnableRepeat && listSelected.isEmpty()) return false;
updateEnable();
return true;
}
void CDlgLearnAssistant::updateEnable()
{
labRepeat->setEnabled(rbRepeat->isChecked());
tvChapters->setEnabled(rbList->isChecked());
}
void CDlgLearnAssistant::on_buttonBox_accepted()
{
QModelIndexList list = tvChapters->selectionModel()->selectedIndexes();
if (rbList->isChecked() && list.isEmpty())
{
QMessageBox::information(this, tr("Information"), tr("Bitte markieren Sie in der Liste ein Kapitel, das Sie lernen möchten!"));
return;
}
accept();
}
CChapter* CDlgLearnAssistant::selectedChapter()
{
QModelIndexList list = tvChapters->selectionModel()->selectedIndexes();
if (rbRepeat->isChecked())
return m_pCatalog;
if (rbList->isChecked())
{
if (list.isEmpty()) return 0;
return (CChapter*)list.first().internalPointer();
}
return 0;
}