1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| #include<QtGui> #include "symbolpicker.h" #include "ui_symbolpicker.h" SymbolPicker::SymbolPicker(const QMap<int,QString> &symbolMap,QWidget *parent) : QDialog(parent), ui(new Ui::SymbolPicker) { ui->setupUi(this); id = -1; listWidget = new QListWidget; listWidget->setIconSize(QSize(60,60)); QMapIterator<int,QString> i(symbolMap); while(i.hasNext()) { i.next(); QListWidgetItem *item = new QListWidgetItem(i.value(),listWidget); item->setIcon(iconForSymbol(i.value())); item->setData(Qt::UserRole,i.key()); } buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok| QDialogButtonBox::Cancel); connect(buttonBox,SIGNAL(accepted()),this,SLOT(accept())); connect(buttonBox,SIGNAL(rejected()),this,SLOT(reject())); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(listWidget); layout->addWidget(buttonBox); setLayout(layout); setWindowTitle(tr("Symbol Picker")); } SymbolPicker::~SymbolPicker() { delete ui; } void SymbolPicker::done(int result) { id = -1; if (result == QDialog::Accepted) { QListWidgetItem *item = listWidget->currentItem(); if (item) id = item->data(Qt::UserRole).toInt(); } QDialog::done(result); } QIcon SymbolPicker::iconForSymbol(const QString &symbolName) { QString fileName = ":/images/" + symbolName.toLower(); fileName.replace(' ','-'); return QIcon(fileName); }
|