only include Applications by default on OS X
[ambit.git] / src / history.cpp
blobd76a42ccc0ecf9b16815fb58081642637676e298
1 /**
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.
19 #include "history.h"
21 #include <qaction.h>
22 #include <qstyle.h>
23 #include <qdebug.h>
25 History::History(QObject *parent) : QObject(parent), goForwardAction(0), goBackAction(0), currentLocation(-1)
29 History::~History()
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"));
40 return action;
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"));
50 return action;
53 void History::currentChanged(const QModelIndex &index)
55 if (currentLocation < 0 || history.value(currentLocation) != index) {
56 while (currentLocation >= 0 && currentLocation + 1 < history.count()) {
57 history.removeLast();
59 history.append(index);
60 ++currentLocation;
62 if (goForwardAction)
63 goForwardAction->setEnabled(history.size() - currentLocation > 1);
64 if (goBackAction)
65 goBackAction->setEnabled(currentLocation > 0);
68 void History::goBack()
70 if (!history.isEmpty() && currentLocation > 0) {
71 --currentLocation;
72 QModelIndex previousIndex = history.at(currentLocation);
73 emit goToIndex(previousIndex);
77 void History::goForward()
79 if (!history.isEmpty() && currentLocation < history.size()) {
80 ++currentLocation;
81 QModelIndex nextIndex = history.at(currentLocation);
82 emit goToIndex(nextIndex);