2 * This file is part of the vng project
3 * Copyright (C) 2008 Thomas Zander <tzander@trolltech.com>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "GenericCursor.h"
23 GenericCursor::GenericCursor(AcceptanceMode mode
)
31 m_allowedOptions
= QLatin1String("ynqjk");
34 m_allowedOptions
= QLatin1String("ynqadjk");
39 GenericCursor::~GenericCursor()
44 int GenericCursor::forward(Scope scope
, bool skipAnswered
)
48 if (m_items
.count() <= m_curentIndex
+ 1) {
49 if (m_mode
== ExitWhenDone
)
51 return m_items
.count();
54 if (m_items
[m_curentIndex
]->m_acceptance
== Vng::Undecided
)
56 } while (skipAnswered
);
57 return m_curentIndex
+1;
60 int GenericCursor::back(Scope scope
)
63 while (m_curentIndex
> 0) {
65 if (m_items
[m_curentIndex
]->m_acceptance
== Vng::Undecided
)
68 return m_curentIndex
+1;
71 void GenericCursor::setResponse(bool response
, Scope scope
)
74 if (m_curentIndex
>= 0 && m_curentIndex
< m_items
.count()) {
75 m_items
[m_curentIndex
]->m_acceptance
= response
? Vng::Accepted
: Vng::Rejected
;
81 void GenericCursor::setAllowedOptions(QString
&options
)
83 m_allowedOptions
= options
;
86 QString
GenericCursor::allowedOptions() const
88 return m_allowedOptions
;
91 int GenericCursor::count()
93 return m_items
.count();
96 void GenericCursor::forceCount()
100 QString
GenericCursor::currentText() const
102 return m_items
[m_curentIndex
]->text();
105 void GenericCursor::setHelpMessage(const QString
&message
)
107 m_helpMessage
= message
;
110 QString
GenericCursor::helpMessage() const
112 return m_helpMessage
;
115 bool GenericCursor::isValid() const
117 if (m_mode
== ExitOnAccept
)
118 return !m_oneAccepted
;
119 return m_curentIndex
>= 0 && m_curentIndex
< m_items
.count();
122 int GenericCursor::addDataItem(const QString
&text
)
124 Item
*item
= new Item(text
);
126 return m_items
.count();
129 QList
<int> GenericCursor::selectedItems() const
133 foreach (Item
*item
, m_items
) {
134 if (item
->m_acceptance
== Vng::Accepted
)
142 GenericCursor::Item::Item(const QString
&text
)
143 : m_acceptance(Vng::Undecided
),
148 QString
GenericCursor::Item::text() const