2 * Copyright (C) 2007 Benjamin C. Meyer
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 History::History(QObject
*parent
) : QObject(parent
), goForwardAction(0), goBackAction(0), currentLocation(-1)
33 QAction
*History::backAction(QObject
*parent
)
35 QAction
*action
= new QAction(tr("Back"), parent
);
36 action
->setShortcuts(QKeySequence::Back
);
37 action
->setIcon(QIcon(":/pics/arrow-left.png"));
38 action
->setEnabled(false);
39 action
->setToolTip(tr("Back"));
43 QAction
*History::forwardAction(QObject
*parent
)
45 QAction
*action
= new QAction(tr("Forward"), parent
);
46 action
->setShortcuts(QKeySequence::Forward
);
47 action
->setIcon(QIcon(":/pics/arrow-right.png"));
48 action
->setEnabled(false);
49 action
->setToolTip(tr("Forward"));
53 void History::currentChanged(const QModelIndex
&index
)
55 if (currentLocation
< 0 || history
.value(currentLocation
) != index
) {
56 while (currentLocation
>= 0 && currentLocation
+ 1 < history
.count()) {
59 history
.append(index
);
63 goForwardAction
->setEnabled(history
.size() - currentLocation
> 1);
65 goBackAction
->setEnabled(currentLocation
> 0);
68 void History::goBack()
70 if (!history
.isEmpty() && currentLocation
> 0) {
72 QModelIndex previousIndex
= history
.at(currentLocation
);
73 emit
goToIndex(previousIndex
);
77 void History::goForward()
79 if (!history
.isEmpty() && currentLocation
< history
.size()) {
81 QModelIndex nextIndex
= history
.at(currentLocation
);
82 emit
goToIndex(nextIndex
);