Root/
| 1 | /* |
| 2 | * Copyright 2010 Niels Kummerfeldt <niels.kummerfeldt@tu-harburg.de> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 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. |
| 13 | * |
| 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, |
| 17 | * Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include "markerlist.h" |
| 21 | |
| 22 | #include <QtGui/QLayout> |
| 23 | #include <QtGui/QPushButton> |
| 24 | |
| 25 | MarkerList::MarkerList(QWidget *parent) |
| 26 | : QWidget(parent), |
| 27 | m_list(new QListWidget(this)), |
| 28 | m_edit(false) |
| 29 | { |
| 30 | QGridLayout *layout = new QGridLayout(this); |
| 31 | layout->setContentsMargins(0, 0, 0, 0); |
| 32 | layout->addWidget(m_list, 0, 0, 1, 3); |
| 33 | m_list->setSelectionMode(QAbstractItemView::SingleSelection); |
| 34 | connect(m_list, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(center())); |
| 35 | |
| 36 | QPushButton *back = new QPushButton("Show map", this); |
| 37 | back->setShortcut(QKeySequence(Qt::Key_Tab)); |
| 38 | layout->addWidget(back, 1, 0); |
| 39 | connect(back, SIGNAL(clicked()), this, SIGNAL(back())); |
| 40 | |
| 41 | QPushButton *remove = new QPushButton("&Delete", this); |
| 42 | remove->setShortcut(QKeySequence(Qt::ALT + Qt::Key_D)); |
| 43 | layout->addWidget(remove, 1, 1); |
| 44 | connect(remove, SIGNAL(clicked()), this, SLOT(removeMarker())); |
| 45 | |
| 46 | QPushButton *rename = new QPushButton("&Rename", this); |
| 47 | rename->setShortcut(QKeySequence(Qt::ALT + Qt::Key_R)); |
| 48 | layout->addWidget(rename, 1, 2); |
| 49 | connect(rename, SIGNAL(clicked()), this, SLOT(beginRenameMarker())); |
| 50 | |
| 51 | resize(320, 240); |
| 52 | } |
| 53 | |
| 54 | MarkerList::~MarkerList() |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | void MarkerList::addMarker(const QString &name) |
| 59 | { |
| 60 | m_list->addItem(name); |
| 61 | } |
| 62 | |
| 63 | void MarkerList::center() |
| 64 | { |
| 65 | if (m_edit) { |
| 66 | endRenameMarker(); |
| 67 | } else { |
| 68 | emit centerOnMarker(m_list->currentRow()); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | void MarkerList::removeMarker() |
| 73 | { |
| 74 | emit removeMarker(m_list->currentRow()); |
| 75 | m_list->takeItem(m_list->currentRow()); |
| 76 | } |
| 77 | |
| 78 | void MarkerList::beginRenameMarker() |
| 79 | { |
| 80 | m_edit = true; |
| 81 | m_list->openPersistentEditor(m_list->currentItem()); |
| 82 | } |
| 83 | |
| 84 | void MarkerList::endRenameMarker() |
| 85 | { |
| 86 | m_edit = false; |
| 87 | m_list->closePersistentEditor(m_list->currentItem()); |
| 88 | emit markerRenamed(m_list->currentRow(), m_list->currentItem()->text()); |
| 89 | } |
| 90 | |
| 91 |
Branches:
master
