diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 19:17:32 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 19:17:32 +0000 |
commit | e38d2351b83fa65c66ccde443777647ef5cb6cff (patch) | |
tree | 1897fc20e9f73a81c520a5b9f76f8ed042124883 /src/gui/stringmapdialog.cpp | |
download | tellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.tar.gz tellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.zip |
Added KDE3 version of Tellico
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/tellico@1097620 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/gui/stringmapdialog.cpp')
-rw-r--r-- | src/gui/stringmapdialog.cpp | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/src/gui/stringmapdialog.cpp b/src/gui/stringmapdialog.cpp new file mode 100644 index 0000000..4a5374f --- /dev/null +++ b/src/gui/stringmapdialog.cpp @@ -0,0 +1,125 @@ +/*************************************************************************** + copyright : (C) 2003-2006 by Robby Stephenson + email : robby@periapsis.org + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of version 2 of the GNU General Public License as * + * published by the Free Software Foundation; * + * * + ***************************************************************************/ + +#include "stringmapdialog.h" + +#include <klistview.h> +#include <klocale.h> +#include <klineedit.h> +#include <kbuttonbox.h> +#include <kiconloader.h> + +#include <qlayout.h> +#include <qheader.h> +#include <qhbox.h> +#include <qwhatsthis.h> +#include <qpushbutton.h> + +using Tellico::StringMapDialog; + +StringMapDialog::StringMapDialog(const QMap<QString, QString>& map_, QWidget* parent_, const char* name_/*=0*/, bool modal_/*=false*/) + : KDialogBase(parent_, name_, modal_, QString::null, Ok|Cancel) { + QWidget* page = new QWidget(this); + QVBoxLayout* l = new QVBoxLayout(page, 0, KDialog::spacingHint()); + + m_listView = new KListView(page); + m_listView->setAllColumnsShowFocus(true); + m_listView->setShowSortIndicator(true); + m_listView->addColumn(QString::null); + m_listView->addColumn(QString::null); + m_listView->header()->hide(); // hide header since neither column has a label initially + m_listView->setColumnWidthMode(0, QListView::Maximum); + m_listView->setColumnWidthMode(1, QListView::Maximum); + m_listView->setResizeMode(QListView::AllColumns); + connect(m_listView, SIGNAL(currentChanged(QListViewItem*)), SLOT(slotUpdate(QListViewItem*))); + connect(m_listView, SIGNAL(clicked(QListViewItem*)), SLOT(slotUpdate(QListViewItem*))); + l->addWidget(m_listView); + + QHBox* box = new QHBox(page); + box->setMargin(4); + box->setSpacing(KDialog::spacingHint()); + + m_edit1 = new KLineEdit(box); + m_edit1->setFocus(); + m_edit2 = new KLineEdit(box); + KButtonBox* bb = new KButtonBox(box); + bb->addStretch(); + QPushButton* btn = bb->addButton(i18n("&Set"), this, SLOT(slotAdd())); + btn->setIconSet(BarIcon(QString::fromLatin1("filenew"), KIcon::SizeSmall)); + btn = bb->addButton(i18n("&Delete"), this, SLOT(slotDelete())); + btn->setIconSet(BarIcon(QString::fromLatin1("editdelete"), KIcon::SizeSmall)); + + l->addWidget(box); + l->addStretch(1); + setMainWidget(page); + + for(QMap<QString, QString>::ConstIterator it = map_.begin(); it != map_.end(); ++it) { + if(!it.data().isEmpty()) { + (void) new KListViewItem(m_listView, it.key(), it.data()); + } + } + + setMinimumWidth(400); + enableButtonSeparator(true); +} + +void StringMapDialog::slotAdd() { + QString s1 = m_edit1->text(); + QString s2 = m_edit2->text(); + if(s1.isEmpty() && s2.isEmpty()) { + return; + } + QListViewItem* item = m_listView->currentItem(); + if(item && s1 == item->text(0)) { // only update values if same key + item->setText(1, s2); + } else { + item = new KListViewItem(m_listView, s1, s2); + } + m_listView->ensureItemVisible(item); + m_listView->setSelected(item, true); + m_listView->setCurrentItem(item); +} + +void StringMapDialog::slotDelete() { + delete m_listView->currentItem(); + m_edit1->clear(); + m_edit2->clear(); + m_listView->setSelected(m_listView->currentItem(), true); +} + +void StringMapDialog::slotUpdate(QListViewItem* item_) { + if(item_) { + m_edit1->setText(item_->text(0)); + m_edit2->setText(item_->text(1)); + m_listView->header()->adjustHeaderSize(); + } else { + m_edit1->clear(); + m_edit2->clear(); + } +} + +void StringMapDialog::setLabels(const QString& label1_, const QString& label2_) { + m_listView->header()->setLabel(0, label1_); + m_listView->header()->setLabel(1, label2_); + m_listView->header()->show(); +} + +QMap<QString, QString> StringMapDialog::stringMap() { + QMap<QString, QString> map; + for(QListViewItem* item = m_listView->firstChild(); item; item = item->nextSibling()) { + map.insert(item->text(0), item->text(1)); + } + return map; +} + +#include "stringmapdialog.moc" |