00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kcharselect.h"
00022
00023 #include "kcharselect_p.h"
00024
00025 #include <QtGui/QActionEvent>
00026 #include <QtGui/QDoubleSpinBox>
00027 #include <QtGui/QHeaderView>
00028 #include <QtGui/QBoxLayout>
00029 #include <QtGui/QSplitter>
00030 #include <QtGui/QPushButton>
00031
00032 #include <kcombobox.h>
00033 #include <kdebug.h>
00034 #include <kdialog.h>
00035 #include <klocale.h>
00036 #include <klineedit.h>
00037 #include <ktextbrowser.h>
00038 #include <kfontcombobox.h>
00039
00040 K_GLOBAL_STATIC(KCharSelectData, s_data)
00041
00042 class KCharSelectTablePrivate
00043 {
00044 public:
00045 KCharSelectTablePrivate(KCharSelectTable *q): q(q), model(0) {}
00046 KCharSelectTable *q;
00047
00048 QFont font;
00049 KCharSelectItemModel *model;
00050 QList<QChar> chars;
00051 QChar chr;
00052
00053 void _k_resizeCells();
00054 void _k_doubleClicked(const QModelIndex & index);
00055 void _k_slotCurrentChanged(const QModelIndex & current, const QModelIndex & previous);
00056 };
00057
00058 class KCharSelect::KCharSelectPrivate
00059 {
00060 public:
00061 KLineEdit* searchLine;
00062 KFontComboBox *fontCombo;
00063 QSpinBox *fontSizeSpinBox;
00064 QComboBox *sectionCombo;
00065 QComboBox *blockCombo;
00066 KCharSelectTable *charTable;
00067 KTextBrowser *detailBrowser;
00068
00069 KCharSelect *q;
00070
00071 QString createLinks(QString s);
00072 void _k_fontSelected();
00073 void _k_updateCurrentChar(const QChar &c);
00074 void _k_slotUpdateUnicode(const QChar &c);
00075 void _k_sectionSelected(int index);
00076 void _k_blockSelected(int index);
00077 void _k_searchEditChanged();
00078 void _k_search();
00079 void _k_linkClicked(QUrl url);
00080 };
00081
00082
00083
00084
00085
00086 KCharSelectTable::KCharSelectTable(QWidget *parent, const QFont &_font)
00087 : QTableView(parent), d(new KCharSelectTablePrivate(this))
00088 {
00089 d->font = _font;
00090
00091 setTabKeyNavigation(false);
00092 setSelectionMode(QAbstractItemView::SingleSelection);
00093 QPalette _palette;
00094 _palette.setColor(backgroundRole(), palette().color(QPalette::Base));
00095 setPalette(_palette);
00096 verticalHeader()->setVisible(false);
00097 verticalHeader()->setResizeMode(QHeaderView::Custom);
00098 horizontalHeader()->setVisible(false);
00099 horizontalHeader()->setResizeMode(QHeaderView::Custom);
00100
00101 setFocusPolicy(Qt::StrongFocus);
00102 setDragEnabled(true);
00103 setAcceptDrops(true);
00104 setDropIndicatorShown(false);
00105 setDragDropMode(QAbstractItemView::DragDrop);
00106
00107 connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(_k_doubleClicked(QModelIndex)));
00108
00109 d->_k_resizeCells();
00110 }
00111
00112 KCharSelectTable::~KCharSelectTable()
00113 {
00114 delete d;
00115 }
00116
00117 void KCharSelectTable::setFont(const QFont &_font)
00118 {
00119 QTableView::setFont(_font);
00120 d->font = _font;
00121 if (d->model) d->model->setFont(_font);
00122 d->_k_resizeCells();
00123 }
00124
00125 QChar KCharSelectTable::chr()
00126 {
00127 return d->chr;
00128 }
00129
00130 QFont KCharSelectTable::font() const
00131 {
00132 return d->font;
00133 }
00134
00135 QList<QChar> KCharSelectTable::displayedChars() const
00136 {
00137 return d->chars;
00138 }
00139
00140 void KCharSelectTable::setChar(const QChar &c)
00141 {
00142 int pos = d->chars.indexOf(c);
00143 if (pos != -1) {
00144 setCurrentIndex(model()->index(pos / model()->columnCount(), pos % model()->columnCount()));
00145 }
00146 }
00147
00148 void KCharSelectTable::setContents(QList<QChar> chars)
00149 {
00150 d->chars = chars;
00151
00152 KCharSelectItemModel *m = d->model;
00153 d->model = new KCharSelectItemModel(chars, d->font, this);
00154 setModel(d->model);
00155 d->_k_resizeCells();
00156 QItemSelectionModel *selectionModel = new QItemSelectionModel(d->model);
00157 setSelectionModel(selectionModel);
00158 setSelectionBehavior(QAbstractItemView::SelectItems);
00159 setSelectionMode(QAbstractItemView::SingleSelection);
00160 connect(selectionModel, SIGNAL(currentChanged(const QModelIndex & , const QModelIndex &)), this, SLOT(_k_slotCurrentChanged(const QModelIndex &, const QModelIndex &)));
00161 connect(d->model, SIGNAL(showCharRequested(QChar)), this, SIGNAL(showCharRequested(QChar)));
00162 delete m;
00163 }
00164
00165 void KCharSelectTable::scrollTo(const QModelIndex & index, ScrollHint hint)
00166 {
00167
00168 if (index.isValid() && index.column() != 0) {
00169 QTableView::scrollTo(d->model->index(index.row(), 0), hint);
00170 } else {
00171 QTableView::scrollTo(index, hint);
00172 }
00173 }
00174
00175 void KCharSelectTablePrivate::_k_slotCurrentChanged(const QModelIndex & current, const QModelIndex & previous)
00176 {
00177 Q_UNUSED(previous);
00178 if (!model) return;
00179 QVariant temp = model->data(current, KCharSelectItemModel::CharacterRole);
00180 if (temp.type() != QVariant::Char)
00181 return;
00182 QChar c = temp.toChar();
00183 chr = c;
00184 emit q->focusItemChanged(c);
00185 }
00186
00187 void KCharSelectTable::resizeEvent(QResizeEvent * e)
00188 {
00189 QTableView::resizeEvent(e);
00190 if (e->size().width() != e->oldSize().width()) {
00191 d->_k_resizeCells();
00192 }
00193 }
00194
00195 void KCharSelectTablePrivate::_k_resizeCells()
00196 {
00197 if (!q->model()) return;
00198 static_cast<KCharSelectItemModel*>(q->model())->updateColumnCount(q->viewport()->size().width());
00199
00200 QChar oldChar = q->chr();
00201
00202 const int new_w = q->viewport()->size().width() / q->model()->columnCount(QModelIndex());
00203 const int columns = q->model()->columnCount(QModelIndex());
00204 const int rows = q->model()->rowCount(QModelIndex());
00205 q->setUpdatesEnabled(false);
00206 QHeaderView* hv = q->horizontalHeader();
00207 int spaceLeft = q->viewport()->size().width() % new_w + 1;
00208 for (int i = 0;i <= columns;i++) {
00209 if (i < spaceLeft) {
00210 hv->resizeSection(i, new_w + 1);
00211 } else {
00212 hv->resizeSection(i, new_w);
00213 }
00214 }
00215
00216 hv = q->verticalHeader();
00217 const int new_h = QFontMetrics(font).xHeight() * 3;
00218 for (int i = 0;i < rows;i++) {
00219 hv->resizeSection(i, new_h);
00220 }
00221
00222 q->setUpdatesEnabled(true);
00223 q->setChar(oldChar);
00224 }
00225
00226 void KCharSelectTablePrivate::_k_doubleClicked(const QModelIndex & index)
00227 {
00228 QChar c = model->data(index, KCharSelectItemModel::CharacterRole).toChar();
00229 if (c.isPrint()) {
00230 emit q->activated(c);
00231 }
00232 }
00233
00234 void KCharSelectTable::keyPressEvent(QKeyEvent *e)
00235 {
00236 if (d->model)
00237 switch (e->key()) {
00238 case Qt::Key_Space:
00239 emit activated(' ');
00240 return;
00241 break;
00242 case Qt::Key_Enter: case Qt::Key_Return: {
00243 if (!currentIndex().isValid()) return;
00244 QChar c = d->model->data(currentIndex(), KCharSelectItemModel::CharacterRole).toChar();
00245 if (c.isPrint()) {
00246 emit activated(c);
00247 }
00248 }
00249 return;
00250 break;
00251 }
00252 QTableView::keyPressEvent(e);
00253 }
00254
00255
00256
00257
00258
00259
00260 KCharSelect::KCharSelect(QWidget *parent, const Controls controls)
00261 : QWidget(parent), d(new KCharSelectPrivate)
00262 {
00263 d->q = this;
00264
00265 QVBoxLayout *mainLayout = new QVBoxLayout(this);
00266 mainLayout->setMargin(0);
00267 if (SearchLine & controls) {
00268 QHBoxLayout *searchLayout = new QHBoxLayout();
00269 mainLayout->addLayout(searchLayout);
00270 d->searchLine = new KLineEdit(this);
00271 searchLayout->addWidget(d->searchLine);
00272 d->searchLine->setClickMessage(i18n("Enter a search term or character here"));
00273 d->searchLine->setClearButtonShown(true);
00274 d->searchLine->setToolTip(i18n("Enter a search term or character here"));
00275 connect(d->searchLine, SIGNAL(textChanged(QString)), this, SLOT(_k_searchEditChanged()));
00276
00277 QPushButton* searchButton = new QPushButton(i18n("Search"), this);
00278 searchLayout->addWidget(searchButton);
00279 connect(d->searchLine, SIGNAL(returnPressed(QString)), searchButton, SLOT(animateClick()));
00280 connect(searchButton, SIGNAL(pressed()), this, SLOT(_k_search()));
00281 }
00282
00283 if ((SearchLine & controls) && ((FontCombo & controls) || (FontSize & controls) || (BlockCombos & controls))) {
00284 QFrame* line = new QFrame(this);
00285 line->setFrameShape(QFrame::HLine);
00286 line->setFrameShadow(QFrame::Sunken);
00287 mainLayout->addWidget(line);
00288 }
00289
00290 QHBoxLayout *comboLayout = new QHBoxLayout();
00291
00292
00293 d->fontCombo = new KFontComboBox(this);
00294 comboLayout->addWidget(d->fontCombo);
00295 d->fontCombo->setEditable(true);
00296 d->fontCombo->resize(d->fontCombo->sizeHint());
00297 d->fontCombo->setToolTip(i18n("Set font"));
00298
00299 d->fontSizeSpinBox = new QSpinBox(this);
00300 comboLayout->addWidget(d->fontSizeSpinBox);
00301 d->fontSizeSpinBox->setValue(QWidget::font().pointSize());
00302 d->fontSizeSpinBox->setRange(1, 400);
00303 d->fontSizeSpinBox->setSingleStep(1);
00304 d->fontSizeSpinBox->setToolTip(i18n("Set font size"));
00305
00306 connect(d->fontCombo, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(_k_fontSelected()));
00307 connect(d->fontSizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(_k_fontSelected()));
00308
00309
00310 d->sectionCombo = new KComboBox(this);
00311 d->sectionCombo->setToolTip(i18n("Select a category"));
00312 comboLayout->addWidget(d->sectionCombo);
00313 d->blockCombo = new KComboBox(this);
00314 d->blockCombo->setToolTip(i18n("Select a block to be displayed"));
00315 d->blockCombo->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
00316 comboLayout->addWidget(d->blockCombo, 1);
00317 d->sectionCombo->addItems(s_data->sectionList());
00318 d->blockCombo->setMinimumWidth(QFontMetrics(QWidget::font()).averageCharWidth() * 25);
00319
00320 connect(d->sectionCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(_k_sectionSelected(int)));
00321 connect(d->blockCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(_k_blockSelected(int)));
00322 if ((FontCombo & controls) || (FontSize & controls) || (BlockCombos & controls)) {
00323 mainLayout->addLayout(comboLayout);
00324 }
00325 if (!(FontCombo & controls)) {
00326 d->fontCombo->hide();
00327 }
00328 if (!(FontSize & controls)) {
00329 d->fontSizeSpinBox->hide();
00330 }
00331 if (!(BlockCombos & controls)) {
00332 d->sectionCombo->hide();
00333 d->blockCombo->hide();
00334 }
00335
00336 QSplitter *splitter = new QSplitter(this);
00337 if ((CharacterTable & controls) || (DetailBrowser & controls)) {
00338 mainLayout->addWidget(splitter);
00339 } else {
00340 splitter->hide();
00341 }
00342 d->charTable = new KCharSelectTable(this, QFont());
00343 if (CharacterTable & controls) {
00344 splitter->addWidget(d->charTable);
00345 d->charTable->setFocus(Qt::OtherFocusReason);
00346 } else {
00347 d->charTable->hide();
00348 }
00349
00350 const QSize sz(200, 200);
00351 d->charTable->resize(sz);
00352 d->charTable->setMinimumSize(sz);
00353
00354 d->charTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00355
00356 setCurrentFont(QFont());
00357
00358 connect(d->charTable, SIGNAL(focusItemChanged(const QChar &)), this, SLOT(_k_updateCurrentChar(const QChar &)));
00359 connect(d->charTable, SIGNAL(activated(const QChar &)), this, SIGNAL(charSelected(const QChar &)));
00360 connect(d->charTable, SIGNAL(focusItemChanged(const QChar &)),
00361 this, SIGNAL(currentCharChanged(const QChar &)));
00362
00363 connect(d->charTable, SIGNAL(showCharRequested(QChar)), this, SLOT(setCurrentChar(QChar)));
00364
00365 d->detailBrowser = new KTextBrowser(this);
00366 if (DetailBrowser & controls) {
00367 splitter->addWidget(d->detailBrowser);
00368 } else {
00369 d->detailBrowser->hide();
00370 }
00371 connect(d->detailBrowser, SIGNAL(anchorClicked(QUrl)), this, SLOT(_k_linkClicked(QUrl)));
00372
00373 setFocusPolicy(Qt::StrongFocus);
00374 setFocusProxy(d->charTable);
00375 d->_k_sectionSelected(0);
00376 d->_k_blockSelected(0);
00377 setCurrentChar(0x0);
00378 }
00379
00380 KCharSelect::~KCharSelect()
00381 {
00382 delete d;
00383 }
00384
00385 QSize KCharSelect::sizeHint() const
00386 {
00387 return QWidget::sizeHint();
00388 }
00389
00390 void KCharSelect::setCurrentFont(const QFont &_font)
00391 {
00392 d->fontCombo->setCurrentFont(_font);
00393 d->fontSizeSpinBox->setValue(_font.pointSize());
00394 d->_k_fontSelected();
00395 }
00396
00397 QChar KCharSelect::currentChar() const
00398 {
00399 return d->charTable->chr();
00400 }
00401
00402 QFont KCharSelect::currentFont() const
00403 {
00404 return d->charTable->font();
00405 }
00406
00407 QList<QChar> KCharSelect::displayedChars() const
00408 {
00409 return d->charTable->displayedChars();
00410 }
00411
00412 void KCharSelect::setCurrentChar(const QChar &c)
00413 {
00414 int block = s_data->blockIndex(c);
00415 int section = s_data->sectionIndex(block);
00416 d->sectionCombo->setCurrentIndex(section);
00417 int index = d->blockCombo->findData(block);
00418 if (index != -1) {
00419 d->blockCombo->setCurrentIndex(index);
00420 }
00421 d->charTable->setChar(c);
00422 }
00423
00424 void KCharSelect::KCharSelectPrivate::_k_fontSelected()
00425 {
00426 QFont font = fontCombo->currentFont();
00427 font.setPointSize(fontSizeSpinBox->value());
00428 charTable->setFont(font);
00429 emit q->currentFontChanged(font);
00430 }
00431
00432 void KCharSelect::KCharSelectPrivate::_k_updateCurrentChar(const QChar &c)
00433 {
00434 if(blockCombo->isEnabled() == false) {
00435
00436
00437 int block = s_data->blockIndex(c);
00438 int section = s_data->sectionIndex(block);
00439 sectionCombo->setCurrentIndex(section);
00440 int index = blockCombo->findData(block);
00441 if (index != -1) {
00442 blockCombo->setCurrentIndex(index);
00443 }
00444 }
00445
00446 _k_slotUpdateUnicode(c);
00447 }
00448
00449 void KCharSelect::KCharSelectPrivate::_k_slotUpdateUnicode(const QChar &c)
00450 {
00451 QString html;
00452
00453
00454
00455 if (c.isPrint() && c.unicode() != 0xFDD0 && c.unicode() != 0xFDD1) {
00456 html = QString("<p>" + i18n("Character:") + " <font size=\"+4\" face=\"") + charTable->font().family() + "\">&#" + QString::number(c.unicode()) + ";</font> " + s_data->formatCode(c.unicode()) + "<br>";
00457 } else {
00458 html = QString("<p>" + i18n("Character:") + " <b>" + i18n("Non-printable") + "</b> ") + s_data->formatCode(c.unicode()) + "<br>";
00459 }
00460 QString name = s_data->name(c);
00461 if (!name.isEmpty()) {
00462 html += i18n("Name: ") + Qt::escape(name) + "</p>";
00463 }
00464 QStringList aliases = s_data->aliases(c);
00465 QStringList notes = s_data->notes(c);
00466 QList<QChar> seeAlso = s_data->seeAlso(c);
00467 QStringList equivalents = s_data->equivalents(c);
00468 QStringList approxEquivalents = s_data->approximateEquivalents(c);
00469 if (!(aliases.isEmpty() && notes.isEmpty() && seeAlso.isEmpty() && equivalents.isEmpty() && approxEquivalents.isEmpty())) {
00470 html += "<p><b>" + i18n("Annotations and Cross References") + "</b></p>";
00471 }
00472
00473 if (!aliases.isEmpty()) {
00474 html += "<p style=\"margin-bottom: 0px;\">" + i18n("Alias names:") + "</p><ul style=\"margin-top: 0px;\">";
00475 foreach(const QString &alias, aliases) {
00476 html += "<li>" + Qt::escape(alias) + "</li>";
00477 }
00478 html += "</ul>";
00479 }
00480
00481 if (!notes.isEmpty()) {
00482 html += "<p style=\"margin-bottom: 0px;\">" + i18n("Notes:") + "</p><ul style=\"margin-top: 0px;\">";
00483 foreach(const QString ¬e, notes) {
00484 html += "<li>" + createLinks(Qt::escape(note)) + "</li>";
00485 }
00486 html += "</ul>";
00487 }
00488
00489 if (!seeAlso.isEmpty()) {
00490 html += "<p style=\"margin-bottom: 0px;\">" + i18n("See also:") + "</p><ul style=\"margin-top: 0px;\">";
00491 foreach(const QChar &c2, seeAlso) {
00492 html += "<li><a href=\"" + QString::number(c2.unicode(), 16) + "\">";
00493 if (c2.isPrint()) {
00494 html += "&#" + QString::number(c2.unicode()) + "; ";
00495 }
00496 html += s_data->formatCode(c2.unicode()) + ' ' + Qt::escape(s_data->name(c2)) + "</a></li>";
00497 }
00498 html += "</ul>";
00499 }
00500
00501 if (!equivalents.isEmpty()) {
00502 html += "<p style=\"margin-bottom: 0px;\">" + i18n("Equivalents:") + "</p><ul style=\"margin-top: 0px;\">";
00503 foreach(const QString &equivalent, equivalents) {
00504 html += "<li>" + createLinks(Qt::escape(equivalent)) + "</li>";
00505 }
00506 html += "</ul>";
00507 }
00508
00509 if (!approxEquivalents.isEmpty()) {
00510 html += "<p style=\"margin-bottom: 0px;\">" + i18n("Approximate equivalents:") + "</p><ul style=\"margin-top: 0px;\">";
00511 foreach(const QString &approxEquivalent, approxEquivalents) {
00512 html += "<li>" + createLinks(Qt::escape(approxEquivalent)) + "</li>";
00513 }
00514 html += "</ul>";
00515 }
00516
00517 QStringList unihan = s_data->unihanInfo(c);
00518 if (unihan.count() == 7) {
00519 html += "<p><b>" + i18n("CJK Ideograph Information") + "</b></p><p>";
00520 bool newline = true;
00521 if (!unihan[0].isEmpty()) {
00522 html += i18n("Definition in English: ") + unihan[0];
00523 newline = false;
00524 }
00525 if (!unihan[2].isEmpty()) {
00526 if (!newline) html += "<br>";
00527 html += i18n("Mandarin Pronunciation: ") + unihan[2];
00528 newline = false;
00529 }
00530 if (!unihan[1].isEmpty()) {
00531 if (!newline) html += "<br>";
00532 html += i18n("Cantonese Pronunciation: ") + unihan[1];
00533 newline = false;
00534 }
00535 if (!unihan[6].isEmpty()) {
00536 if (!newline) html += "<br>";
00537 html += i18n("Japanese On Pronunciation: ") + unihan[6];
00538 newline = false;
00539 }
00540 if (!unihan[5].isEmpty()) {
00541 if (!newline) html += "<br>";
00542 html += i18n("Japanese Kun Pronunciation: ") + unihan[5];
00543 newline = false;
00544 }
00545 if (!unihan[3].isEmpty()) {
00546 if (!newline) html += "<br>";
00547 html += i18n("Tang Pronunciation: ") + unihan[3];
00548 newline = false;
00549 }
00550 if (!unihan[4].isEmpty()) {
00551 if (!newline) html += "<br>";
00552 html += i18n("Korean Pronunciation: ") + unihan[4];
00553 newline = false;
00554 }
00555 html += "</p>";
00556 }
00557
00558 html += "<p><b>" + i18n("General Character Properties") + "</b><br>";
00559 html += i18n("Block: ") + s_data->block(c) + "<br>";
00560 html += i18n("Unicode category: ") + s_data->categoryText(c.category()) + "</p>";
00561
00562 QByteArray utf8 = QString(c).toUtf8();
00563
00564 html += "<p><b>" + i18n("Various Useful Representations") + "</b><br>";
00565 html += i18n("UTF-8:");
00566 foreach(unsigned char c, utf8)
00567 html += ' ' + s_data->formatCode(c, 2, "0x");
00568 html += "<br>" + i18n("UTF-16: ") + s_data->formatCode(c.unicode(), 4, "0x") + "<br>";
00569 html += i18n("C octal escaped UTF-8: ");
00570 foreach(unsigned char c, utf8)
00571 html += s_data->formatCode(c, 3, "\\", 8);
00572 html += "<br>" + i18n("XML decimal entity:") + " &#" + QString::number(c.unicode()) + ";</p>";
00573
00574 detailBrowser->setHtml(html);
00575 }
00576
00577 QString KCharSelect::KCharSelectPrivate::createLinks(QString s)
00578 {
00579 QRegExp rx("\\b([\\dABCDEF]{4})\\b");
00580
00581 QStringList chars;
00582 int pos = 0;
00583
00584 while ((pos = rx.indexIn(s, pos)) != -1) {
00585 chars << rx.cap(1);
00586 pos += rx.matchedLength();
00587 }
00588
00589 QSet<QString> chars2 = QSet<QString>::fromList(chars);
00590 foreach(const QString &c, chars2) {
00591 int unicode = c.toInt(0, 16);
00592 QString link = "<a href=\"" + c + "\">";
00593 if (QChar(unicode).isPrint()) {
00594 link += "&#" + QString::number(unicode) + "; ";
00595 }
00596 link += "U+" + c + ' ';
00597 link += Qt::escape(s_data->name(QChar(unicode))) + "</a>";
00598 s.replace(c, link);
00599 }
00600 return s;
00601 }
00602
00603 void KCharSelect::KCharSelectPrivate::_k_sectionSelected(int index)
00604 {
00605 blockCombo->clear();
00606 QList<int> blocks = s_data->sectionContents(index);
00607 foreach(int block, blocks) {
00608 blockCombo->addItem(s_data->blockName(block), QVariant(block));
00609 }
00610 blockCombo->setCurrentIndex(0);
00611 }
00612
00613 void KCharSelect::KCharSelectPrivate::_k_blockSelected(int index)
00614 {
00615 if(blockCombo->isEnabled() == false) {
00616
00617 return;
00618 }
00619
00620 int block = blockCombo->itemData(index).toInt();
00621 const QList<QChar> contents = s_data->blockContents(block);
00622 if(contents.count() <= index) {
00623 return;
00624 }
00625 charTable->setContents(contents);
00626 emit q->displayedCharsChanged();
00627 charTable->setChar(contents[0]);
00628 }
00629
00630 void KCharSelect::KCharSelectPrivate::_k_searchEditChanged()
00631 {
00632 if (searchLine->text().isEmpty()) {
00633 sectionCombo->setEnabled(true);
00634 blockCombo->setEnabled(true);
00635
00636
00637 QChar c = charTable->chr();
00638 _k_blockSelected(blockCombo->currentIndex());
00639 q->setCurrentChar(c);
00640 } else {
00641 sectionCombo->setEnabled(false);
00642 blockCombo->setEnabled(false);
00643 }
00644 }
00645
00646 void KCharSelect::KCharSelectPrivate::_k_search()
00647 {
00648 if (searchLine->text().isEmpty()) {
00649 return;
00650 }
00651 charTable->setContents(s_data->find(searchLine->text()));
00652 emit q->displayedCharsChanged();
00653 }
00654
00655 void KCharSelect::KCharSelectPrivate::_k_linkClicked(QUrl url)
00656 {
00657 QString hex = url.toString();
00658 if (hex.size() > 4) {
00659 return;
00660 }
00661 int unicode = hex.toInt(0, 16);
00662 q->setCurrentChar(QChar(unicode));
00663 }
00664
00666
00667 QVariant KCharSelectItemModel::data(const QModelIndex &index, int role) const
00668 {
00669 int pos = m_columns * (index.row()) + index.column();
00670 if (pos >= m_chars.size() || index.row() < 0 || index.column() < 0) {
00671 if (role == Qt::BackgroundColorRole) {
00672 return QVariant(qApp->palette().color(QPalette::Button));
00673 }
00674 return QVariant();
00675 }
00676
00677 QChar c = m_chars[pos];
00678 if (!index.isValid())
00679 return QVariant();
00680 else if (role == Qt::ToolTipRole) {
00681 QString s;
00682 if (c.isPrint())
00683 s = "&#" + QString::number(c.unicode()) + ';';
00684 else
00685 s = i18n("Non-printable");
00686 QString result = i18nc("Character", "<qt><font size=\"+4\" face=\"%1\">%2</font><br />%3<br />Unicode code point: %4<br />(In decimal: %5)</qt>" , m_font.family() , s , Qt::escape(s_data->name(c)), s_data->formatCode(c.unicode()) , c.unicode());
00687 return QVariant(result);
00688 } else if (role == Qt::TextAlignmentRole)
00689 return QVariant(Qt::AlignHCenter | Qt::AlignVCenter);
00690 else if (role == Qt::DisplayRole) {
00691 if (c.isPrint())
00692 return QVariant(c);
00693 return QVariant();
00694 } else if (role == Qt::BackgroundColorRole) {
00695 QFontMetrics fm = QFontMetrics(m_font);
00696 if (fm.inFont(c) && c.isPrint())
00697 return QVariant(qApp->palette().color(QPalette::Base));
00698 else
00699 return QVariant(qApp->palette().color(QPalette::Button));
00700 } else if (role == Qt::FontRole)
00701 return QVariant(m_font);
00702 else if (role == CharacterRole) {
00703 return QVariant(c);
00704 }
00705 return QVariant();
00706 }
00707
00708 #include "kcharselect.moc"
00709 #include "kcharselect_p.moc"