• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • sources
  • kde-4.12
  • kdelibs
  • kdeui
  • widgets
kcharselect.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2 
3  Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "kcharselect.h"
22 
23 #include "kcharselect_p.h"
24 
25 #include <QtGui/QActionEvent>
26 #include <QtGui/QDoubleSpinBox>
27 #include <QtGui/QHeaderView>
28 #include <QtGui/QBoxLayout>
29 #include <QtGui/QShortcut>
30 #include <QtGui/QSplitter>
31 #include <QtGui/QPushButton>
32 #include <QtGui/QToolButton>
33 
34 #include <kcombobox.h>
35 #include <kdebug.h>
36 #include <kdialog.h>
37 #include <klocale.h>
38 #include <klineedit.h>
39 #include <ktextbrowser.h>
40 #include <kfontcombobox.h>
41 #include <kactioncollection.h>
42 #include <kstandardaction.h>
43 
44 K_GLOBAL_STATIC(KCharSelectData, s_data)
45 
46 class KCharSelectTablePrivate
47 {
48 public:
49  KCharSelectTablePrivate(KCharSelectTable *q): q(q), model(0)
50  {}
51 
52  KCharSelectTable *q;
53 
54  QFont font;
55  KCharSelectItemModel *model;
56  QList<QChar> chars;
57  QChar chr;
58 
59  void _k_resizeCells();
60  void _k_doubleClicked(const QModelIndex & index);
61  void _k_slotSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
62 };
63 
64 class KCharSelect::KCharSelectPrivate
65 {
66 public:
67  struct HistoryItem
68  {
69  QChar c;
70  bool fromSearch;
71  QString searchString;
72  };
73 
74  enum { MaxHistoryItems = 100 };
75 
76  KCharSelectPrivate(KCharSelect *q)
77  : q(q)
78  ,searchLine(0)
79  ,searchMode(false)
80  ,historyEnabled(false)
81  ,inHistory(0)
82  ,actions(NULL)
83  {
84  }
85 
86  KCharSelect *q;
87 
88  QToolButton *backButton;
89  QToolButton *forwardButton;
90  KLineEdit* searchLine;
91  KFontComboBox *fontCombo;
92  QSpinBox *fontSizeSpinBox;
93  QComboBox *sectionCombo;
94  QComboBox *blockCombo;
95  KCharSelectTable *charTable;
96  KTextBrowser *detailBrowser;
97 
98  bool searchMode; //a search is active
99  bool historyEnabled;
100  int inHistory; //index of current char in history
101  QList<HistoryItem> history;
102  KActionCollection* actions;
103 
104  QString createLinks(QString s);
105  void historyAdd(const QChar &c, bool fromSearch, const QString &searchString);
106  void showFromHistory(int index);
107  void updateBackForwardButtons();
108  void _k_activateSearchLine();
109  void _k_back();
110  void _k_forward();
111  void _k_fontSelected();
112  void _k_updateCurrentChar(const QChar &c);
113  void _k_slotUpdateUnicode(const QChar &c);
114  void _k_sectionSelected(int index);
115  void _k_blockSelected(int index);
116  void _k_searchEditChanged();
117  void _k_search();
118  void _k_linkClicked(QUrl url);
119 };
120 
121 /******************************************************************/
122 /* Class: KCharSelectTable */
123 /******************************************************************/
124 
125 KCharSelectTable::KCharSelectTable(QWidget *parent, const QFont &_font)
126  : QTableView(parent), d(new KCharSelectTablePrivate(this))
127 {
128  d->font = _font;
129 
130  setTabKeyNavigation(false);
131  setSelectionMode(QAbstractItemView::SingleSelection);
132  QPalette _palette;
133  _palette.setColor(backgroundRole(), palette().color(QPalette::Base));
134  setPalette(_palette);
135  verticalHeader()->setVisible(false);
136  verticalHeader()->setResizeMode(QHeaderView::Custom);
137  horizontalHeader()->setVisible(false);
138  horizontalHeader()->setResizeMode(QHeaderView::Custom);
139 
140  setFocusPolicy(Qt::StrongFocus);
141  setDragEnabled(true);
142  setAcceptDrops(true);
143  setDropIndicatorShown(false);
144  setDragDropMode(QAbstractItemView::DragDrop);
145 
146  connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(_k_doubleClicked(QModelIndex)));
147 
148  d->_k_resizeCells();
149 }
150 
151 KCharSelectTable::~KCharSelectTable()
152 {
153  delete d;
154 }
155 
156 void KCharSelectTable::setFont(const QFont &_font)
157 {
158  QTableView::setFont(_font);
159  d->font = _font;
160  if (d->model) d->model->setFont(_font);
161  d->_k_resizeCells();
162 }
163 
164 QChar KCharSelectTable::chr()
165 {
166  return d->chr;
167 }
168 
169 QFont KCharSelectTable::font() const
170 {
171  return d->font;
172 }
173 
174 QList<QChar> KCharSelectTable::displayedChars() const
175 {
176  return d->chars;
177 }
178 
179 void KCharSelectTable::setChar(const QChar &c)
180 {
181  int pos = d->chars.indexOf(c);
182  if (pos != -1) {
183  setCurrentIndex(model()->index(pos / model()->columnCount(), pos % model()->columnCount()));
184  }
185 }
186 
187 void KCharSelectTable::setContents(QList<QChar> chars)
188 {
189  d->chars = chars;
190 
191  KCharSelectItemModel *m = d->model;
192  d->model = new KCharSelectItemModel(chars, d->font, this);
193  setModel(d->model);
194  d->_k_resizeCells();
195  QItemSelectionModel *selectionModel = new QItemSelectionModel(d->model);
196  setSelectionModel(selectionModel);
197  setSelectionBehavior(QAbstractItemView::SelectItems);
198  setSelectionMode(QAbstractItemView::SingleSelection);
199  connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(_k_slotSelectionChanged(QItemSelection,QItemSelection)));
200  connect(d->model, SIGNAL(showCharRequested(QChar)), this, SIGNAL(showCharRequested(QChar)));
201  delete m; // this should hopefully delete aold selection models too, since it is the parent of them (didn't track, if there are setParent calls somewhere. Check that (jowenn)
202 }
203 
204 void KCharSelectTable::scrollTo(const QModelIndex & index, ScrollHint hint)
205 {
206  // this prevents horizontal scrolling when selecting a character in the last column
207  if (index.isValid() && index.column() != 0) {
208  QTableView::scrollTo(d->model->index(index.row(), 0), hint);
209  } else {
210  QTableView::scrollTo(index, hint);
211  }
212 }
213 
214 void KCharSelectTablePrivate::_k_slotSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
215 {
216  Q_UNUSED(deselected);
217  if (!model || selected.indexes().isEmpty())
218  return;
219  QVariant temp = model->data(selected.indexes().at(0), KCharSelectItemModel::CharacterRole);
220  if (temp.type() != QVariant::Char)
221  return;
222  QChar c = temp.toChar();
223  chr = c;
224  emit q->focusItemChanged(c);
225 }
226 
227 void KCharSelectTable::resizeEvent(QResizeEvent * e)
228 {
229  QTableView::resizeEvent(e);
230  if (e->size().width() != e->oldSize().width()) {
231  d->_k_resizeCells();
232  }
233 }
234 
235 void KCharSelectTablePrivate::_k_resizeCells()
236 {
237  if (!q->model()) return;
238  static_cast<KCharSelectItemModel*>(q->model())->updateColumnCount(q->viewport()->size().width());
239 
240  QChar oldChar = q->chr();
241 
242  const int new_w = q->viewport()->size().width() / q->model()->columnCount(QModelIndex());
243  const int columns = q->model()->columnCount(QModelIndex());
244  const int rows = q->model()->rowCount(QModelIndex());
245  q->setUpdatesEnabled(false);
246  QHeaderView* hv = q->horizontalHeader();
247  int spaceLeft = q->viewport()->size().width() % new_w + 1;
248  for (int i = 0;i <= columns;i++) {
249  if (i < spaceLeft) {
250  hv->resizeSection(i, new_w + 1);
251  } else {
252  hv->resizeSection(i, new_w);
253  }
254  }
255 
256  hv = q->verticalHeader();
257 #ifdef Q_WS_WIN
258  int new_h = QFontMetrics(font).lineSpacing() + 1;
259 #else
260  int new_h = QFontMetrics(font).xHeight() * 3;
261 #endif
262  if (new_h < 5 || new_h < 4 + QFontMetrics(font).height()) {
263  new_h = qMax(5, 4 + QFontMetrics(font).height());
264  }
265  for (int i = 0;i < rows;i++) {
266  hv->resizeSection(i, new_h);
267  }
268 
269  q->setUpdatesEnabled(true);
270  q->setChar(oldChar);
271 }
272 
273 void KCharSelectTablePrivate::_k_doubleClicked(const QModelIndex & index)
274 {
275  QChar c = model->data(index, KCharSelectItemModel::CharacterRole).toChar();
276  if (s_data->isPrint(c)) {
277  emit q->activated(c);
278  }
279 }
280 
281 void KCharSelectTable::keyPressEvent(QKeyEvent *e)
282 {
283  if (d->model)
284  switch (e->key()) {
285  case Qt::Key_Space:
286  emit activated(' ');
287  return;
288  break;
289  case Qt::Key_Enter: case Qt::Key_Return: {
290  if (!currentIndex().isValid()) return;
291  QChar c = d->model->data(currentIndex(), KCharSelectItemModel::CharacterRole).toChar();
292  if (s_data->isPrint(c)) {
293  emit activated(c);
294  }
295  }
296  return;
297  break;
298  }
299  QTableView::keyPressEvent(e);
300 }
301 
302 
303 /******************************************************************/
304 /* Class: KCharSelect */
305 /******************************************************************/
306 
307 #ifndef KDE_NO_DEPRECATED
308 KCharSelect::KCharSelect(QWidget *parent, const Controls controls)
309  : QWidget(parent), d(new KCharSelectPrivate(this))
310 {
311  init(controls, NULL);
312 }
313 #endif
314 
315 KCharSelect::KCharSelect(
316  QWidget *parent
317  ,KActionCollection *collection
318  ,const Controls controls)
319  : QWidget(parent), d(new KCharSelectPrivate(this))
320 {
321  init(controls, collection);
322 }
323 
324 void KCharSelect::init(const Controls controls, KActionCollection *collection)
325 {
326  if (collection==NULL) {
327  d->actions = new KActionCollection(this);
328  d->actions->addAssociatedWidget(this);
329  } else {
330  d->actions = collection;
331  }
332 
333  QVBoxLayout *mainLayout = new QVBoxLayout(this);
334  mainLayout->setMargin(0);
335  if (SearchLine & controls) {
336  QHBoxLayout *searchLayout = new QHBoxLayout();
337  mainLayout->addLayout(searchLayout);
338  d->searchLine = new KLineEdit(this);
339  searchLayout->addWidget(d->searchLine);
340  d->searchLine->setClickMessage(i18n("Enter a search term or character here"));
341  d->searchLine->setClearButtonShown(true);
342  d->searchLine->setToolTip(i18n("Enter a search term or character here"));
343  KStandardAction::find(this, SLOT(_k_activateSearchLine()), d->actions);
344  connect(d->searchLine, SIGNAL(textChanged(QString)), this, SLOT(_k_searchEditChanged()));
345  connect(d->searchLine, SIGNAL(returnPressed()), this, SLOT(_k_search()));
346  }
347 
348  if ((SearchLine & controls) && ((FontCombo & controls) || (FontSize & controls) || (BlockCombos & controls))) {
349  QFrame* line = new QFrame(this);
350  line->setFrameShape(QFrame::HLine);
351  line->setFrameShadow(QFrame::Sunken);
352  mainLayout->addWidget(line);
353  }
354 
355  QHBoxLayout *comboLayout = new QHBoxLayout();
356 
357  d->backButton = new QToolButton(this);
358  comboLayout->addWidget(d->backButton);
359  d->backButton->setEnabled(false);
360  d->backButton->setText(i18nc("Goes to previous character", "Previous in History"));
361  d->backButton->setIcon(KIcon("go-previous"));
362  d->backButton->setToolTip(i18n("Previous Character in History"));
363 
364  d->forwardButton = new QToolButton(this);
365  comboLayout->addWidget(d->forwardButton);
366  d->forwardButton->setEnabled(false);
367  d->forwardButton->setText(i18nc("Goes to next character", "Next in History"));
368  d->forwardButton->setIcon(KIcon("go-next"));
369  d->forwardButton->setToolTip(i18n("Next Character in History"));
370 
371  KStandardAction::back(d->backButton, SLOT(animateClick()), d->actions);
372  KStandardAction::forward(d->forwardButton, SLOT(animateClick()), d->actions);
373  connect(d->backButton, SIGNAL(clicked()), this, SLOT(_k_back()));
374  connect(d->forwardButton, SIGNAL(clicked()), this, SLOT(_k_forward()));
375 
376  d->sectionCombo = new KComboBox(this);
377  d->sectionCombo->setToolTip(i18n("Select a category"));
378  comboLayout->addWidget(d->sectionCombo);
379  d->blockCombo = new KComboBox(this);
380  d->blockCombo->setToolTip(i18n("Select a block to be displayed"));
381  d->blockCombo->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
382  comboLayout->addWidget(d->blockCombo, 1);
383  d->sectionCombo->addItems(s_data->sectionList());
384  d->blockCombo->setMinimumWidth(QFontMetrics(QWidget::font()).averageCharWidth() * 25);
385 
386  connect(d->sectionCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(_k_sectionSelected(int)));
387  connect(d->blockCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(_k_blockSelected(int)));
388 
389  d->fontCombo = new KFontComboBox(this);
390  comboLayout->addWidget(d->fontCombo);
391  d->fontCombo->setEditable(true);
392  d->fontCombo->resize(d->fontCombo->sizeHint());
393  d->fontCombo->setToolTip(i18n("Set font"));
394 
395  d->fontSizeSpinBox = new QSpinBox(this);
396  comboLayout->addWidget(d->fontSizeSpinBox);
397  d->fontSizeSpinBox->setValue(QWidget::font().pointSize());
398  d->fontSizeSpinBox->setRange(1, 400);
399  d->fontSizeSpinBox->setSingleStep(1);
400  d->fontSizeSpinBox->setToolTip(i18n("Set font size"));
401 
402  connect(d->fontCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(_k_fontSelected()));
403  connect(d->fontSizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(_k_fontSelected()));
404 
405  if ((HistoryButtons & controls) || (FontCombo & controls) || (FontSize & controls) || (BlockCombos & controls)) {
406  mainLayout->addLayout(comboLayout);
407  }
408  if (!(HistoryButtons & controls)) {
409  d->backButton->hide();
410  d->forwardButton->hide();
411  }
412  if (!(FontCombo & controls)) {
413  d->fontCombo->hide();
414  }
415  if (!(FontSize & controls)) {
416  d->fontSizeSpinBox->hide();
417  }
418  if (!(BlockCombos & controls)) {
419  d->sectionCombo->hide();
420  d->blockCombo->hide();
421  }
422 
423  QSplitter *splitter = new QSplitter(this);
424  if ((CharacterTable & controls) || (DetailBrowser & controls)) {
425  mainLayout->addWidget(splitter);
426  } else {
427  splitter->hide();
428  }
429  d->charTable = new KCharSelectTable(this, QFont());
430  if (CharacterTable & controls) {
431  splitter->addWidget(d->charTable);
432  d->charTable->setFocus(Qt::OtherFocusReason);
433  } else {
434  d->charTable->hide();
435  }
436 
437  const QSize sz(200, 200);
438  d->charTable->resize(sz);
439  d->charTable->setMinimumSize(sz);
440 
441  d->charTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
442 
443  setCurrentFont(QFont());
444 
445  connect(d->charTable, SIGNAL(focusItemChanged(QChar)), this, SLOT(_k_updateCurrentChar(QChar)));
446  connect(d->charTable, SIGNAL(activated(QChar)), this, SIGNAL(charSelected(QChar)));
447  connect(d->charTable, SIGNAL(focusItemChanged(QChar)),
448  this, SIGNAL(currentCharChanged(QChar)));
449 
450  connect(d->charTable, SIGNAL(showCharRequested(QChar)), this, SLOT(setCurrentChar(QChar)));
451 
452  d->detailBrowser = new KTextBrowser(this);
453  if (DetailBrowser & controls) {
454  splitter->addWidget(d->detailBrowser);
455  } else {
456  d->detailBrowser->hide();
457  }
458  d->detailBrowser->setOpenLinks(false);
459  connect(d->detailBrowser, SIGNAL(anchorClicked(QUrl)), this, SLOT(_k_linkClicked(QUrl)));
460 
461  setFocusPolicy(Qt::StrongFocus);
462  setFocusProxy(d->charTable);
463  d->_k_sectionSelected(0);
464  d->_k_blockSelected(0);
465  setCurrentChar(0x0);
466 
467  d->historyEnabled = true;
468 }
469 
470 KCharSelect::~KCharSelect()
471 {
472  delete d;
473 }
474 
475 QSize KCharSelect::sizeHint() const
476 {
477  return QWidget::sizeHint();
478 }
479 
480 void KCharSelect::setCurrentFont(const QFont &_font)
481 {
482  d->fontCombo->setCurrentFont(_font);
483  d->fontSizeSpinBox->setValue(_font.pointSize());
484  d->_k_fontSelected();
485 }
486 
487 QChar KCharSelect::currentChar() const
488 {
489  return d->charTable->chr();
490 }
491 
492 QFont KCharSelect::currentFont() const
493 {
494  return d->charTable->font();
495 }
496 
497 QList<QChar> KCharSelect::displayedChars() const
498 {
499  return d->charTable->displayedChars();
500 }
501 
502 void KCharSelect::setCurrentChar(const QChar &c)
503 {
504  bool oldHistoryEnabled = d->historyEnabled;
505  d->historyEnabled = false;
506  int block = s_data->blockIndex(c);
507  int section = s_data->sectionIndex(block);
508  d->sectionCombo->setCurrentIndex(section);
509  int index = d->blockCombo->findData(block);
510  if (index != -1) {
511  d->blockCombo->setCurrentIndex(index);
512  }
513  d->historyEnabled = oldHistoryEnabled;
514  d->charTable->setChar(c);
515 }
516 
517 void KCharSelect::KCharSelectPrivate::historyAdd(const QChar &c, bool fromSearch, const QString &searchString)
518 {
519  //kDebug() << "about to add char" << c << "fromSearch" << fromSearch << "searchString" << searchString;
520 
521  if (!historyEnabled) {
522  return;
523  }
524 
525  if (!history.isEmpty() && c == history.last().c) {
526  //avoid duplicates
527  return;
528  }
529 
530  //behave like a web browser, i.e. if user goes back from B to A then clicks C, B is forgotten
531  while (!history.isEmpty() && inHistory != history.count() - 1) {
532  history.removeLast();
533  }
534 
535  while (history.size() >= MaxHistoryItems) {
536  history.removeFirst();
537  }
538 
539  HistoryItem item;
540  item.c = c;
541  item.fromSearch = fromSearch;
542  item.searchString = searchString;
543  history.append(item);
544 
545  inHistory = history.count() - 1;
546  updateBackForwardButtons();
547 }
548 
549 void KCharSelect::KCharSelectPrivate::showFromHistory(int index)
550 {
551  Q_ASSERT(index >= 0 && index < history.count());
552  Q_ASSERT(index != inHistory);
553 
554  inHistory = index;
555  updateBackForwardButtons();
556 
557  const HistoryItem &item = history[index];
558  //kDebug() << "index" << index << "char" << item.c << "fromSearch" << item.fromSearch
559  // << "searchString" << item.searchString;
560 
561  //avoid adding an item from history into history again
562  bool oldHistoryEnabled = historyEnabled;
563  historyEnabled = false;
564  if (item.fromSearch) {
565  if (searchLine->text() != item.searchString) {
566  searchLine->setText(item.searchString);
567  _k_search();
568  }
569  charTable->setChar(item.c);
570  } else {
571  searchLine->clear();
572  q->setCurrentChar(item.c);
573  }
574  historyEnabled = oldHistoryEnabled;
575 }
576 
577 void KCharSelect::KCharSelectPrivate::updateBackForwardButtons()
578 {
579  backButton->setEnabled(inHistory > 0);
580  forwardButton->setEnabled(inHistory < history.count() - 1);
581 }
582 
583 void KCharSelect::KCharSelectPrivate::_k_activateSearchLine()
584 {
585  searchLine->setFocus();
586  searchLine->selectAll();
587 }
588 
589 void KCharSelect::KCharSelectPrivate::_k_back()
590 {
591  Q_ASSERT(inHistory > 0);
592  showFromHistory(inHistory - 1);
593 }
594 
595 void KCharSelect::KCharSelectPrivate::_k_forward()
596 {
597  Q_ASSERT(inHistory + 1 < history.count());
598  showFromHistory(inHistory + 1);
599 }
600 
601 void KCharSelect::KCharSelectPrivate::_k_fontSelected()
602 {
603  QFont font = fontCombo->currentFont();
604  font.setPointSize(fontSizeSpinBox->value());
605  charTable->setFont(font);
606  emit q->currentFontChanged(font);
607 }
608 
609 void KCharSelect::KCharSelectPrivate::_k_updateCurrentChar(const QChar &c)
610 {
611  if (searchMode) {
612  //we are in search mode. make the two comboboxes show the section & block for this character.
613  //(when we are not in search mode the current character always belongs to the current section & block.)
614  int block = s_data->blockIndex(c);
615  int section = s_data->sectionIndex(block);
616  sectionCombo->setCurrentIndex(section);
617  int index = blockCombo->findData(block);
618  if (index != -1) {
619  blockCombo->setCurrentIndex(index);
620  }
621  }
622 
623  if( searchLine)
624  historyAdd(c, searchMode, searchLine->text());
625 
626  _k_slotUpdateUnicode(c);
627 }
628 
629 void KCharSelect::KCharSelectPrivate::_k_slotUpdateUnicode(const QChar &c)
630 {
631  QString html = "<p>" + i18n("Character:") + ' ' + s_data->display(c, charTable->font()) + ' ' +
632  s_data->formatCode(c.unicode()) + "<br />";
633 
634  QString name = s_data->name(c);
635  if (!name.isEmpty()) {
636  //is name ever empty? </p> should always be there...
637  html += i18n("Name: ") + Qt::escape(name) + "</p>";
638  }
639  QStringList aliases = s_data->aliases(c);
640  QStringList notes = s_data->notes(c);
641  QList<QChar> seeAlso = s_data->seeAlso(c);
642  QStringList equivalents = s_data->equivalents(c);
643  QStringList approxEquivalents = s_data->approximateEquivalents(c);
644  if (!(aliases.isEmpty() && notes.isEmpty() && seeAlso.isEmpty() && equivalents.isEmpty() && approxEquivalents.isEmpty())) {
645  html += "<p><b>" + i18n("Annotations and Cross References") + "</b></p>";
646  }
647 
648  if (!aliases.isEmpty()) {
649  html += "<p style=\"margin-bottom: 0px;\">" + i18n("Alias names:") + "</p><ul style=\"margin-top: 0px;\">";
650  foreach(const QString &alias, aliases) {
651  html += "<li>" + Qt::escape(alias) + "</li>";
652  }
653  html += "</ul>";
654  }
655 
656  if (!notes.isEmpty()) {
657  html += "<p style=\"margin-bottom: 0px;\">" + i18n("Notes:") + "</p><ul style=\"margin-top: 0px;\">";
658  foreach(const QString &note, notes) {
659  html += "<li>" + createLinks(Qt::escape(note)) + "</li>";
660  }
661  html += "</ul>";
662  }
663 
664  if (!seeAlso.isEmpty()) {
665  html += "<p style=\"margin-bottom: 0px;\">" + i18n("See also:") + "</p><ul style=\"margin-top: 0px;\">";
666  foreach(const QChar &c2, seeAlso) {
667  html += "<li><a href=\"" + QString::number(c2.unicode(), 16) + "\">";
668  if (s_data->isPrint(c2)) {
669  html += "&#" + QString::number(c2.unicode()) + "; ";
670  }
671  html += s_data->formatCode(c2.unicode()) + ' ' + Qt::escape(s_data->name(c2)) + "</a></li>";
672  }
673  html += "</ul>";
674  }
675 
676  if (!equivalents.isEmpty()) {
677  html += "<p style=\"margin-bottom: 0px;\">" + i18n("Equivalents:") + "</p><ul style=\"margin-top: 0px;\">";
678  foreach(const QString &equivalent, equivalents) {
679  html += "<li>" + createLinks(Qt::escape(equivalent)) + "</li>";
680  }
681  html += "</ul>";
682  }
683 
684  if (!approxEquivalents.isEmpty()) {
685  html += "<p style=\"margin-bottom: 0px;\">" + i18n("Approximate equivalents:") + "</p><ul style=\"margin-top: 0px;\">";
686  foreach(const QString &approxEquivalent, approxEquivalents) {
687  html += "<li>" + createLinks(Qt::escape(approxEquivalent)) + "</li>";
688  }
689  html += "</ul>";
690  }
691 
692  QStringList unihan = s_data->unihanInfo(c);
693  if (unihan.count() == 7) {
694  html += "<p><b>" + i18n("CJK Ideograph Information") + "</b></p><p>";
695  bool newline = true;
696  if (!unihan[0].isEmpty()) {
697  html += i18n("Definition in English: ") + unihan[0];
698  newline = false;
699  }
700  if (!unihan[2].isEmpty()) {
701  if (!newline) html += "<br>";
702  html += i18n("Mandarin Pronunciation: ") + unihan[2];
703  newline = false;
704  }
705  if (!unihan[1].isEmpty()) {
706  if (!newline) html += "<br>";
707  html += i18n("Cantonese Pronunciation: ") + unihan[1];
708  newline = false;
709  }
710  if (!unihan[6].isEmpty()) {
711  if (!newline) html += "<br>";
712  html += i18n("Japanese On Pronunciation: ") + unihan[6];
713  newline = false;
714  }
715  if (!unihan[5].isEmpty()) {
716  if (!newline) html += "<br>";
717  html += i18n("Japanese Kun Pronunciation: ") + unihan[5];
718  newline = false;
719  }
720  if (!unihan[3].isEmpty()) {
721  if (!newline) html += "<br>";
722  html += i18n("Tang Pronunciation: ") + unihan[3];
723  newline = false;
724  }
725  if (!unihan[4].isEmpty()) {
726  if (!newline) html += "<br>";
727  html += i18n("Korean Pronunciation: ") + unihan[4];
728  newline = false;
729  }
730  html += "</p>";
731  }
732 
733  html += "<p><b>" + i18n("General Character Properties") + "</b><br>";
734  html += i18n("Block: ") + s_data->block(c) + "<br>";
735  html += i18n("Unicode category: ") + s_data->categoryText(s_data->category(c)) + "</p>";
736 
737  QByteArray utf8 = QString(c).toUtf8();
738 
739  html += "<p><b>" + i18n("Various Useful Representations") + "</b><br>";
740  html += i18n("UTF-8:");
741  foreach(unsigned char c, utf8)
742  html += ' ' + s_data->formatCode(c, 2, "0x");
743  html += "<br>" + i18n("UTF-16: ") + s_data->formatCode(c.unicode(), 4, "0x") + "<br>";
744  html += i18n("C octal escaped UTF-8: ");
745  foreach(unsigned char c, utf8)
746  html += s_data->formatCode(c, 3, "\\", 8);
747  html += "<br>" + i18n("XML decimal entity:") + " &amp;#" + QString::number(c.unicode()) + ";</p>";
748 
749  detailBrowser->setHtml(html);
750 }
751 
752 QString KCharSelect::KCharSelectPrivate::createLinks(QString s)
753 {
754  QRegExp rx("\\b([\\dABCDEF]{4})\\b");
755 
756  QStringList chars;
757  int pos = 0;
758 
759  while ((pos = rx.indexIn(s, pos)) != -1) {
760  chars << rx.cap(1);
761  pos += rx.matchedLength();
762  }
763 
764  QSet<QString> chars2 = QSet<QString>::fromList(chars);
765  foreach(const QString &c, chars2) {
766  int unicode = c.toInt(0, 16);
767  QString link = "<a href=\"" + c + "\">";
768  if (s_data->isPrint(QChar(unicode))) {
769  link += "&#" + QString::number(unicode) + ";&nbsp;";
770  }
771  link += "U+" + c + ' ';
772  link += Qt::escape(s_data->name(QChar(unicode))) + "</a>";
773  s.replace(c, link);
774  }
775  return s;
776 }
777 
778 void KCharSelect::KCharSelectPrivate::_k_sectionSelected(int index)
779 {
780  blockCombo->clear();
781  QList<int> blocks = s_data->sectionContents(index);
782  foreach(int block, blocks) {
783  blockCombo->addItem(s_data->blockName(block), QVariant(block));
784  }
785  blockCombo->setCurrentIndex(0);
786 }
787 
788 void KCharSelect::KCharSelectPrivate::_k_blockSelected(int index)
789 {
790  if (index == -1) {
791  //the combo box has been cleared and is about to be filled again (because the section has changed)
792  return;
793  }
794  if (searchMode) {
795  //we are in search mode, so don't fill the table with this block.
796  return;
797  }
798 
799  int block = blockCombo->itemData(index).toInt();
800  const QList<QChar> contents = s_data->blockContents(block);
801  if(contents.count() <= index) {
802  return;
803  }
804  charTable->setContents(contents);
805  emit q->displayedCharsChanged();
806  charTable->setChar(contents[0]);
807 }
808 
809 void KCharSelect::KCharSelectPrivate::_k_searchEditChanged()
810 {
811  if (searchLine->text().isEmpty()) {
812  sectionCombo->setEnabled(true);
813  blockCombo->setEnabled(true);
814 
815  //upon leaving search mode, keep the same character selected
816  searchMode = false;
817  QChar c = charTable->chr();
818  bool oldHistoryEnabled = historyEnabled;
819  historyEnabled = false;
820  _k_blockSelected(blockCombo->currentIndex());
821  historyEnabled = oldHistoryEnabled;
822  q->setCurrentChar(c);
823  } else {
824  sectionCombo->setEnabled(false);
825  blockCombo->setEnabled(false);
826 
827  int length = searchLine->text().length();
828  if (length >= 3) {
829  _k_search();
830  }
831  }
832 }
833 
834 void KCharSelect::KCharSelectPrivate::_k_search()
835 {
836  if (searchLine->text().isEmpty()) {
837  return;
838  }
839  searchMode = true;
840  const QList<QChar> contents = s_data->find(searchLine->text());
841  charTable->setContents(contents);
842  emit q->displayedCharsChanged();
843  if (!contents.isEmpty()) {
844  charTable->setChar(contents[0]);
845  }
846 }
847 
848 void KCharSelect::KCharSelectPrivate::_k_linkClicked(QUrl url)
849 {
850  QString hex = url.toString();
851  if (hex.size() > 4) {
852  return;
853  }
854  int unicode = hex.toInt(0, 16);
855  searchLine->clear();
856  q->setCurrentChar(QChar(unicode));
857 }
858 
860 
861 QVariant KCharSelectItemModel::data(const QModelIndex &index, int role) const
862 {
863  int pos = m_columns * (index.row()) + index.column();
864  if (!index.isValid() || pos < 0 || pos >= m_chars.size()
865  || index.row() < 0 || index.column() < 0) {
866  if (role == Qt::BackgroundColorRole) {
867  return QVariant(qApp->palette().color(QPalette::Button));
868  }
869  return QVariant();
870  }
871 
872  QChar c = m_chars[pos];
873  if (role == Qt::ToolTipRole) {
874  QString result = s_data->display(c, m_font) + "<br />" + Qt::escape(s_data->name(c)) + "<br />" +
875  i18n("Unicode code point:") + ' ' + s_data->formatCode(c.unicode()) + "<br />" +
876  i18nc("Character", "In decimal:") + ' ' + QString::number(c.unicode());
877  return QVariant(result);
878  } else if (role == Qt::TextAlignmentRole)
879  return QVariant(Qt::AlignHCenter | Qt::AlignVCenter);
880  else if (role == Qt::DisplayRole) {
881  if (s_data->isPrint(c))
882  return QVariant(c);
883  return QVariant();
884  } else if (role == Qt::BackgroundColorRole) {
885  QFontMetrics fm = QFontMetrics(m_font);
886  if (fm.inFont(c) && s_data->isPrint(c))
887  return QVariant(qApp->palette().color(QPalette::Base));
888  else
889  return QVariant(qApp->palette().color(QPalette::Button));
890  } else if (role == Qt::FontRole)
891  return QVariant(m_font);
892  else if (role == CharacterRole) {
893  return QVariant(c);
894  }
895  return QVariant();
896 }
897 
898 #include "kcharselect.moc"
899 #include "kcharselect_p.moc"
QVariant
kdialog.h
i18n
QString i18n(const char *text)
ktextbrowser.h
kcombobox.h
KActionCollection
A container for a set of QAction objects.
Definition: kactioncollection.h:56
QItemSelectionModel
kdebug.h
KStandardAction::back
KAction * back(const QObject *recvr, const char *slot, QObject *parent)
Move back (web style menu).
Definition: kstandardaction.cpp:394
KFontComboBox
A lightweight font selection widget.
Definition: kfontcombobox.h:49
kactioncollection.h
K_GLOBAL_STATIC
#define K_GLOBAL_STATIC(TYPE, NAME)
KCharSelect::FontSize
Shows the font size spin box.
Definition: kcharselect.h:84
QWidget
KStandardAction::name
const char * name(StandardAction id)
This will return the internal name of a given standard action.
Definition: kstandardaction.cpp:223
KCharSelect::SearchLine
Shows the search widgets.
Definition: kcharselect.h:76
KStandardAction::find
KAction * find(const QObject *recvr, const char *slot, QObject *parent)
Initiate a 'find' request in the current document.
Definition: kstandardaction.cpp:329
QUrl
QString
KCharSelect::DetailBrowser
Shows the detail browser.
Definition: kcharselect.h:96
klocale.h
i18nc
QString i18nc(const char *ctxt, const char *text)
KCharSelect::BlockCombos
Shows the category/block selection combo boxes.
Definition: kcharselect.h:88
KCharSelect::currentChar
QChar currentChar() const
Returns the currently selected character.
kfontcombobox.h
KCharSelect::charSelected
void charSelected(const QChar &c)
A character is selected to be inserted somewhere.
KCharSelect::HistoryButtons
Shows the Back/Forward buttons.
Definition: kcharselect.h:100
KCharSelect::CharacterTable
Shows the actual table.
Definition: kcharselect.h:92
QStringList
QComboBox
KCharSelect::displayedChars
QList< QChar > displayedChars() const
Returns a list of currently displayed characters.
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:40
KCharSelect::setCurrentChar
void setCurrentChar(const QChar &c)
Highlights the character c.
Definition: kcharselect.cpp:502
kstandardaction.h
KCharSelect::FontCombo
Shows the font combo box.
Definition: kcharselect.h:80
KCharSelect::currentCharChanged
void currentCharChanged(const QChar &c)
The current character is changed.
KCharSelect::setCurrentFont
void setCurrentFont(const QFont &font)
Sets the font which is displayed to font.
Definition: kcharselect.cpp:480
QSet< QString >
KStandardAction::forward
KAction * forward(const QObject *recvr, const char *slot, QObject *parent)
Move forward (web style menu).
Definition: kstandardaction.cpp:399
KTextBrowser
Extended QTextBrowser.
Definition: ktextbrowser.h:51
KCharSelect::~KCharSelect
~KCharSelect()
Definition: kcharselect.cpp:470
KCharSelect
Character selection widget.
Definition: kcharselect.h:61
QFont
KLineEdit
An enhanced QLineEdit widget for inputting text.
Definition: klineedit.h:149
QSpinBox
KCharSelect::KCharSelect
KCharSelect(QWidget *parent, KActionCollection *collection, const Controls controls=AllGuiElements)
Constructor.
Definition: kcharselect.cpp:308
KComboBox
An enhanced combo box.
Definition: kcombobox.h:148
QSize
klineedit.h
QToolButton
kcharselect.h
QFrame
KCharSelect::currentFont
QFont currentFont() const
Returns the currently displayed font.
QList< QChar >
KCharSelect::sizeHint
virtual QSize sizeHint() const
Reimplemented.
Definition: kcharselect.cpp:475
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:49:14 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal