generic: remove unused KCharSelect class

Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
Ivailo Monev 2019-12-20 00:28:21 +00:00
parent 5d6db58b4d
commit eda7c9685f
17 changed files with 0 additions and 2543 deletions

View file

@ -49,7 +49,6 @@ install(
KIdleTime
KCalendarSystem
KCharMacroExpander
KCharSelect
KCharsets
KCheckableProxyModel
KCmdLineArgs

View file

@ -1 +0,0 @@
#include "../kcharselect.h"

View file

@ -211,8 +211,6 @@ set(kdeui_LIB_SRCS
widgets/kdialogbuttonbox.cpp
widgets/kbuttongroup.cpp
widgets/kcapacitybar.cpp
widgets/kcharselect.cpp
widgets/kcharselectdata.cpp
widgets/kcmodule.cpp
widgets/kcombobox.cpp
widgets/kcompletionbox.cpp
@ -420,11 +418,6 @@ install(
DESTINATION ${DATA_INSTALL_DIR}/kdeui/pics
)
install(
FILES widgets/kcharselect-data
DESTINATION ${DATA_INSTALL_DIR}/kcharselect
)
install(
FILES
xmlgui/ui_standards.rc
@ -576,7 +569,6 @@ install(
widgets/kcombobox.h
widgets/kcompletionbox.h
widgets/kbuttongroup.h
widgets/kcharselect.h
widgets/kdatetable.h
widgets/kdatetimeedit.h
widgets/kdatetimewidget.h

View file

@ -78,7 +78,6 @@ KDEUI_EXECUTABLE_TESTS(
kaccelgentest
kactionselectortest
kanimatedbuttontest
kcharselecttest
kapptest
kassistantdialogtest
kcategorizedviewtest

View file

@ -1,20 +0,0 @@
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <kapplication.h>
#include <klocale.h>
#include "kcharselect.h"
int main (int argc,char **argv)
{
KAboutData about("kcharselecttest", 0, ki18n("kcharselecttest"), "version");
KCmdLineArgs::init(argc, argv, &about);
KApplication app;
KCharSelect selector( 0, 0 );
selector.resize( selector.sizeHint() );
selector.show();
selector.setWindowTitle( "KCharSelect Test" );
return app.exec();
}

Binary file not shown.

View file

@ -1,189 +0,0 @@
/* This file is part of the KDE libraries
Copyright (C) 2007 Daniel Laidig <d.laidig@gmx.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
This file is autogenerated by kdeutils/kcharselect/kcharselect-generate-datafile.py
*/
I18N_NOOP2("KCharSelect section name", "European Alphabets");
I18N_NOOP2("KCharSelect section name", "African Scripts");
I18N_NOOP2("KCharSelect section name", "Middle Eastern Scripts");
I18N_NOOP2("KCharSelect section name", "South Asian Scripts");
I18N_NOOP2("KCharSelect section name", "Philippine Scripts");
I18N_NOOP2("KCharSelect section name", "South East Asian Scripts");
I18N_NOOP2("KCharSelect section name", "East Asian Scripts");
I18N_NOOP2("KCharSelect section name", "Central Asian Scripts");
I18N_NOOP2("KCharSelect section name", "Other Scripts");
I18N_NOOP2("KCharSelect section name", "Symbols");
I18N_NOOP2("KCharSelect section name", "Mathematical Symbols");
I18N_NOOP2("KCharSelect section name", "Phonetic Symbols");
I18N_NOOP2("KCharSelect section name", "Combining Diacritical Marks");
I18N_NOOP2("KCharSelect section name", "Other");
I18N_NOOP2("KCharselect unicode block name", "Basic Latin");
I18N_NOOP2("KCharselect unicode block name", "Latin-1 Supplement");
I18N_NOOP2("KCharselect unicode block name", "Latin Extended-A");
I18N_NOOP2("KCharselect unicode block name", "Latin Extended-B");
I18N_NOOP2("KCharselect unicode block name", "IPA Extensions");
I18N_NOOP2("KCharselect unicode block name", "Spacing Modifier Letters");
I18N_NOOP2("KCharselect unicode block name", "Combining Diacritical Marks");
I18N_NOOP2("KCharselect unicode block name", "Greek and Coptic");
I18N_NOOP2("KCharselect unicode block name", "Cyrillic");
I18N_NOOP2("KCharselect unicode block name", "Cyrillic Supplement");
I18N_NOOP2("KCharselect unicode block name", "Armenian");
I18N_NOOP2("KCharselect unicode block name", "Hebrew");
I18N_NOOP2("KCharselect unicode block name", "Arabic");
I18N_NOOP2("KCharselect unicode block name", "Syriac");
I18N_NOOP2("KCharselect unicode block name", "Arabic Supplement");
I18N_NOOP2("KCharselect unicode block name", "Thaana");
I18N_NOOP2("KCharselect unicode block name", "NKo");
I18N_NOOP2("KCharselect unicode block name", "Samaritan");
I18N_NOOP2("KCharselect unicode block name", "Mandaic");
I18N_NOOP2("KCharselect unicode block name", "Devanagari");
I18N_NOOP2("KCharselect unicode block name", "Bengali");
I18N_NOOP2("KCharselect unicode block name", "Gurmukhi");
I18N_NOOP2("KCharselect unicode block name", "Gujarati");
I18N_NOOP2("KCharselect unicode block name", "Oriya");
I18N_NOOP2("KCharselect unicode block name", "Tamil");
I18N_NOOP2("KCharselect unicode block name", "Telugu");
I18N_NOOP2("KCharselect unicode block name", "Kannada");
I18N_NOOP2("KCharselect unicode block name", "Malayalam");
I18N_NOOP2("KCharselect unicode block name", "Sinhala");
I18N_NOOP2("KCharselect unicode block name", "Thai");
I18N_NOOP2("KCharselect unicode block name", "Lao");
I18N_NOOP2("KCharselect unicode block name", "Tibetan");
I18N_NOOP2("KCharselect unicode block name", "Myanmar");
I18N_NOOP2("KCharselect unicode block name", "Georgian");
I18N_NOOP2("KCharselect unicode block name", "Hangul Jamo");
I18N_NOOP2("KCharselect unicode block name", "Ethiopic");
I18N_NOOP2("KCharselect unicode block name", "Ethiopic Supplement");
I18N_NOOP2("KCharselect unicode block name", "Cherokee");
I18N_NOOP2("KCharselect unicode block name", "Unified Canadian Aboriginal Syllabics");
I18N_NOOP2("KCharselect unicode block name", "Ogham");
I18N_NOOP2("KCharselect unicode block name", "Runic");
I18N_NOOP2("KCharselect unicode block name", "Tagalog");
I18N_NOOP2("KCharselect unicode block name", "Hanunoo");
I18N_NOOP2("KCharselect unicode block name", "Buhid");
I18N_NOOP2("KCharselect unicode block name", "Tagbanwa");
I18N_NOOP2("KCharselect unicode block name", "Khmer");
I18N_NOOP2("KCharselect unicode block name", "Mongolian");
I18N_NOOP2("KCharselect unicode block name", "Unified Canadian Aboriginal Syllabics Extended");
I18N_NOOP2("KCharselect unicode block name", "Limbu");
I18N_NOOP2("KCharselect unicode block name", "Tai Le");
I18N_NOOP2("KCharselect unicode block name", "New Tai Lue");
I18N_NOOP2("KCharselect unicode block name", "Khmer Symbols");
I18N_NOOP2("KCharselect unicode block name", "Buginese");
I18N_NOOP2("KCharselect unicode block name", "Tai Tham");
I18N_NOOP2("KCharselect unicode block name", "Balinese");
I18N_NOOP2("KCharselect unicode block name", "Sundanese");
I18N_NOOP2("KCharselect unicode block name", "Batak");
I18N_NOOP2("KCharselect unicode block name", "Lepcha");
I18N_NOOP2("KCharselect unicode block name", "Ol Chiki");
I18N_NOOP2("KCharselect unicode block name", "Vedic Extensions");
I18N_NOOP2("KCharselect unicode block name", "Phonetic Extensions");
I18N_NOOP2("KCharselect unicode block name", "Phonetic Extensions Supplement");
I18N_NOOP2("KCharselect unicode block name", "Combining Diacritical Marks Supplement");
I18N_NOOP2("KCharselect unicode block name", "Latin Extended Additional");
I18N_NOOP2("KCharselect unicode block name", "Greek Extended");
I18N_NOOP2("KCharselect unicode block name", "General Punctuation");
I18N_NOOP2("KCharselect unicode block name", "Superscripts and Subscripts");
I18N_NOOP2("KCharselect unicode block name", "Currency Symbols");
I18N_NOOP2("KCharselect unicode block name", "Combining Diacritical Marks for Symbols");
I18N_NOOP2("KCharselect unicode block name", "Letterlike Symbols");
I18N_NOOP2("KCharselect unicode block name", "Number Forms");
I18N_NOOP2("KCharselect unicode block name", "Arrows");
I18N_NOOP2("KCharselect unicode block name", "Mathematical Operators");
I18N_NOOP2("KCharselect unicode block name", "Miscellaneous Technical");
I18N_NOOP2("KCharselect unicode block name", "Control Pictures");
I18N_NOOP2("KCharselect unicode block name", "Optical Character Recognition");
I18N_NOOP2("KCharselect unicode block name", "Enclosed Alphanumerics");
I18N_NOOP2("KCharselect unicode block name", "Box Drawing");
I18N_NOOP2("KCharselect unicode block name", "Block Elements");
I18N_NOOP2("KCharselect unicode block name", "Geometric Shapes");
I18N_NOOP2("KCharselect unicode block name", "Miscellaneous Symbols");
I18N_NOOP2("KCharselect unicode block name", "Dingbats");
I18N_NOOP2("KCharselect unicode block name", "Miscellaneous Mathematical Symbols-A");
I18N_NOOP2("KCharselect unicode block name", "Supplemental Arrows-A");
I18N_NOOP2("KCharselect unicode block name", "Braille Patterns");
I18N_NOOP2("KCharselect unicode block name", "Supplemental Arrows-B");
I18N_NOOP2("KCharselect unicode block name", "Miscellaneous Mathematical Symbols-B");
I18N_NOOP2("KCharselect unicode block name", "Supplemental Mathematical Operators");
I18N_NOOP2("KCharselect unicode block name", "Miscellaneous Symbols and Arrows");
I18N_NOOP2("KCharselect unicode block name", "Glagolitic");
I18N_NOOP2("KCharselect unicode block name", "Latin Extended-C");
I18N_NOOP2("KCharselect unicode block name", "Coptic");
I18N_NOOP2("KCharselect unicode block name", "Georgian Supplement");
I18N_NOOP2("KCharselect unicode block name", "Tifinagh");
I18N_NOOP2("KCharselect unicode block name", "Ethiopic Extended");
I18N_NOOP2("KCharselect unicode block name", "Cyrillic Extended-A");
I18N_NOOP2("KCharselect unicode block name", "Supplemental Punctuation");
I18N_NOOP2("KCharselect unicode block name", "CJK Radicals Supplement");
I18N_NOOP2("KCharselect unicode block name", "Kangxi Radicals");
I18N_NOOP2("KCharselect unicode block name", "Ideographic Description Characters");
I18N_NOOP2("KCharselect unicode block name", "CJK Symbols and Punctuation");
I18N_NOOP2("KCharselect unicode block name", "Hiragana");
I18N_NOOP2("KCharselect unicode block name", "Katakana");
I18N_NOOP2("KCharselect unicode block name", "Bopomofo");
I18N_NOOP2("KCharselect unicode block name", "Hangul Compatibility Jamo");
I18N_NOOP2("KCharselect unicode block name", "Kanbun");
I18N_NOOP2("KCharselect unicode block name", "Bopomofo Extended");
I18N_NOOP2("KCharselect unicode block name", "CJK Strokes");
I18N_NOOP2("KCharselect unicode block name", "Katakana Phonetic Extensions");
I18N_NOOP2("KCharselect unicode block name", "Enclosed CJK Letters and Months");
I18N_NOOP2("KCharselect unicode block name", "CJK Compatibility");
I18N_NOOP2("KCharselect unicode block name", "CJK Unified Ideographs Extension A");
I18N_NOOP2("KCharselect unicode block name", "Yijing Hexagram Symbols");
I18N_NOOP2("KCharselect unicode block name", "CJK Unified Ideographs");
I18N_NOOP2("KCharselect unicode block name", "Yi Syllables");
I18N_NOOP2("KCharselect unicode block name", "Yi Radicals");
I18N_NOOP2("KCharselect unicode block name", "Lisu");
I18N_NOOP2("KCharselect unicode block name", "Vai");
I18N_NOOP2("KCharselect unicode block name", "Cyrillic Extended-B");
I18N_NOOP2("KCharselect unicode block name", "Bamum");
I18N_NOOP2("KCharselect unicode block name", "Modifier Tone Letters");
I18N_NOOP2("KCharselect unicode block name", "Latin Extended-D");
I18N_NOOP2("KCharselect unicode block name", "Syloti Nagri");
I18N_NOOP2("KCharselect unicode block name", "Common Indic Number Forms");
I18N_NOOP2("KCharselect unicode block name", "Phags-pa");
I18N_NOOP2("KCharselect unicode block name", "Saurashtra");
I18N_NOOP2("KCharselect unicode block name", "Devanagari Extended");
I18N_NOOP2("KCharselect unicode block name", "Kayah Li");
I18N_NOOP2("KCharselect unicode block name", "Rejang");
I18N_NOOP2("KCharselect unicode block name", "Hangul Jamo Extended-A");
I18N_NOOP2("KCharselect unicode block name", "Javanese");
I18N_NOOP2("KCharselect unicode block name", "Cham");
I18N_NOOP2("KCharselect unicode block name", "Myanmar Extended-A");
I18N_NOOP2("KCharselect unicode block name", "Tai Viet");
I18N_NOOP2("KCharselect unicode block name", "Ethiopic Extended-A");
I18N_NOOP2("KCharselect unicode block name", "Meetei Mayek");
I18N_NOOP2("KCharselect unicode block name", "Hangul Syllables");
I18N_NOOP2("KCharselect unicode block name", "Hangul Jamo Extended-B");
I18N_NOOP2("KCharselect unicode block name", "High Surrogates");
I18N_NOOP2("KCharselect unicode block name", "High Private Use Surrogates");
I18N_NOOP2("KCharselect unicode block name", "Low Surrogates");
I18N_NOOP2("KCharselect unicode block name", "Private Use Area");
I18N_NOOP2("KCharselect unicode block name", "CJK Compatibility Ideographs");
I18N_NOOP2("KCharselect unicode block name", "Alphabetic Presentation Forms");
I18N_NOOP2("KCharselect unicode block name", "Arabic Presentation Forms-A");
I18N_NOOP2("KCharselect unicode block name", "Variation Selectors");
I18N_NOOP2("KCharselect unicode block name", "Vertical Forms");
I18N_NOOP2("KCharselect unicode block name", "Combining Half Marks");
I18N_NOOP2("KCharselect unicode block name", "CJK Compatibility Forms");
I18N_NOOP2("KCharselect unicode block name", "Small Form Variants");
I18N_NOOP2("KCharselect unicode block name", "Arabic Presentation Forms-B");
I18N_NOOP2("KCharselect unicode block name", "Halfwidth and Fullwidth Forms");
I18N_NOOP2("KCharselect unicode block name", "Specials");

View file

@ -1,889 +0,0 @@
/* This file is part of the KDE libraries
Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kcharselect.h"
#include "kcharselect_p.h"
#include <QtGui/qevent.h>
#include <QtGui/QDoubleSpinBox>
#include <QtGui/QHeaderView>
#include <QtGui/QBoxLayout>
#include <QtGui/QShortcut>
#include <QtGui/QSplitter>
#include <QtGui/QPushButton>
#include <QtGui/QToolButton>
#include <QtGui/QTextBrowser>
#include <kcombobox.h>
#include <kdebug.h>
#include <kdialog.h>
#include <klocale.h>
#include <klineedit.h>
#include <kfontcombobox.h>
#include <kactioncollection.h>
#include <kstandardaction.h>
K_GLOBAL_STATIC(KCharSelectData, s_data)
class KCharSelectTablePrivate
{
public:
KCharSelectTablePrivate(KCharSelectTable *q): q(q), model(0)
{}
KCharSelectTable *q;
QFont font;
KCharSelectItemModel *model;
QList<QChar> chars;
QChar chr;
void _k_resizeCells();
void _k_doubleClicked(const QModelIndex & index);
void _k_slotSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected);
};
class KCharSelect::KCharSelectPrivate
{
public:
struct HistoryItem
{
QChar c;
bool fromSearch;
QString searchString;
};
enum { MaxHistoryItems = 100 };
KCharSelectPrivate(KCharSelect *q)
: q(q)
,searchLine(0)
,searchMode(false)
,historyEnabled(false)
,inHistory(0)
,actions(NULL)
{
}
KCharSelect *q;
QToolButton *backButton;
QToolButton *forwardButton;
KLineEdit* searchLine;
KFontComboBox *fontCombo;
QSpinBox *fontSizeSpinBox;
QComboBox *sectionCombo;
QComboBox *blockCombo;
KCharSelectTable *charTable;
QTextBrowser *detailBrowser;
bool searchMode; //a search is active
bool historyEnabled;
int inHistory; //index of current char in history
QList<HistoryItem> history;
KActionCollection* actions;
QString createLinks(QString s);
void historyAdd(const QChar &c, bool fromSearch, const QString &searchString);
void showFromHistory(int index);
void updateBackForwardButtons();
void _k_activateSearchLine();
void _k_back();
void _k_forward();
void _k_fontSelected();
void _k_updateCurrentChar(const QChar &c);
void _k_slotUpdateUnicode(const QChar &c);
void _k_sectionSelected(int index);
void _k_blockSelected(int index);
void _k_searchEditChanged();
void _k_search();
void _k_linkClicked(QUrl url);
};
/******************************************************************/
/* Class: KCharSelectTable */
/******************************************************************/
KCharSelectTable::KCharSelectTable(QWidget *parent, const QFont &_font)
: QTableView(parent), d(new KCharSelectTablePrivate(this))
{
d->font = _font;
setTabKeyNavigation(false);
setSelectionMode(QAbstractItemView::SingleSelection);
QPalette _palette;
_palette.setColor(backgroundRole(), palette().color(QPalette::Base));
setPalette(_palette);
verticalHeader()->setVisible(false);
verticalHeader()->setResizeMode(QHeaderView::Custom);
horizontalHeader()->setVisible(false);
horizontalHeader()->setResizeMode(QHeaderView::Custom);
setFocusPolicy(Qt::StrongFocus);
setDragEnabled(true);
setAcceptDrops(true);
setDropIndicatorShown(false);
setDragDropMode(QAbstractItemView::DragDrop);
connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(_k_doubleClicked(QModelIndex)));
d->_k_resizeCells();
}
KCharSelectTable::~KCharSelectTable()
{
delete d;
}
void KCharSelectTable::setFont(const QFont &_font)
{
QTableView::setFont(_font);
d->font = _font;
if (d->model) d->model->setFont(_font);
d->_k_resizeCells();
}
QChar KCharSelectTable::chr()
{
return d->chr;
}
QFont KCharSelectTable::font() const
{
return d->font;
}
QList<QChar> KCharSelectTable::displayedChars() const
{
return d->chars;
}
void KCharSelectTable::setChar(const QChar &c)
{
int pos = d->chars.indexOf(c);
if (pos != -1) {
setCurrentIndex(model()->index(pos / model()->columnCount(), pos % model()->columnCount()));
}
}
void KCharSelectTable::setContents(QList<QChar> chars)
{
d->chars = chars;
KCharSelectItemModel *m = d->model;
d->model = new KCharSelectItemModel(chars, d->font, this);
setModel(d->model);
d->_k_resizeCells();
QItemSelectionModel *selectionModel = new QItemSelectionModel(d->model);
setSelectionModel(selectionModel);
setSelectionBehavior(QAbstractItemView::SelectItems);
setSelectionMode(QAbstractItemView::SingleSelection);
connect(selectionModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(_k_slotSelectionChanged(QItemSelection,QItemSelection)));
connect(d->model, SIGNAL(showCharRequested(QChar)), this, SIGNAL(showCharRequested(QChar)));
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)
}
void KCharSelectTable::scrollTo(const QModelIndex & index, ScrollHint hint)
{
// this prevents horizontal scrolling when selecting a character in the last column
if (index.isValid() && index.column() != 0) {
QTableView::scrollTo(d->model->index(index.row(), 0), hint);
} else {
QTableView::scrollTo(index, hint);
}
}
void KCharSelectTablePrivate::_k_slotSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
{
Q_UNUSED(deselected);
if (!model || selected.indexes().isEmpty())
return;
QVariant temp = model->data(selected.indexes().at(0), KCharSelectItemModel::CharacterRole);
if (temp.type() != QVariant::Char)
return;
QChar c = temp.toChar();
chr = c;
emit q->focusItemChanged(c);
}
void KCharSelectTable::resizeEvent(QResizeEvent * e)
{
QTableView::resizeEvent(e);
if (e->size().width() != e->oldSize().width()) {
d->_k_resizeCells();
}
}
void KCharSelectTablePrivate::_k_resizeCells()
{
if (!q->model()) return;
static_cast<KCharSelectItemModel*>(q->model())->updateColumnCount(q->viewport()->size().width());
QChar oldChar = q->chr();
const int new_w = q->viewport()->size().width() / q->model()->columnCount(QModelIndex());
const int columns = q->model()->columnCount(QModelIndex());
const int rows = q->model()->rowCount(QModelIndex());
q->setUpdatesEnabled(false);
QHeaderView* hv = q->horizontalHeader();
int spaceLeft = q->viewport()->size().width() % new_w + 1;
for (int i = 0;i <= columns;i++) {
if (i < spaceLeft) {
hv->resizeSection(i, new_w + 1);
} else {
hv->resizeSection(i, new_w);
}
}
hv = q->verticalHeader();
int new_h = QFontMetrics(font).xHeight() * 3;
if (new_h < 5 || new_h < 4 + QFontMetrics(font).height()) {
new_h = qMax(5, 4 + QFontMetrics(font).height());
}
for (int i = 0;i < rows;i++) {
hv->resizeSection(i, new_h);
}
q->setUpdatesEnabled(true);
q->setChar(oldChar);
}
void KCharSelectTablePrivate::_k_doubleClicked(const QModelIndex & index)
{
QChar c = model->data(index, KCharSelectItemModel::CharacterRole).toChar();
if (s_data->isPrint(c)) {
emit q->activated(c);
}
}
void KCharSelectTable::keyPressEvent(QKeyEvent *e)
{
if (d->model)
switch (e->key()) {
case Qt::Key_Space:
emit activated(' ');
return;
break;
case Qt::Key_Enter: case Qt::Key_Return: {
if (!currentIndex().isValid()) return;
QChar c = d->model->data(currentIndex(), KCharSelectItemModel::CharacterRole).toChar();
if (s_data->isPrint(c)) {
emit activated(c);
}
}
return;
break;
}
QTableView::keyPressEvent(e);
}
/******************************************************************/
/* Class: KCharSelect */
/******************************************************************/
KCharSelect::KCharSelect(
QWidget *parent
,KActionCollection *collection
,const Controls controls)
: QWidget(parent), d(new KCharSelectPrivate(this))
{
qRegisterMetaType<QList<QChar> >();
init(controls, collection);
}
void KCharSelect::init(const Controls controls, KActionCollection *collection)
{
if (collection==NULL) {
d->actions = new KActionCollection(this);
d->actions->addAssociatedWidget(this);
} else {
d->actions = collection;
}
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->setMargin(0);
if (SearchLine & controls) {
QHBoxLayout *searchLayout = new QHBoxLayout();
mainLayout->addLayout(searchLayout);
d->searchLine = new KLineEdit(this);
searchLayout->addWidget(d->searchLine);
d->searchLine->setClickMessage(i18n("Enter a search term or character here"));
d->searchLine->setClearButtonShown(true);
d->searchLine->setToolTip(i18n("Enter a search term or character here"));
KStandardAction::find(this, SLOT(_k_activateSearchLine()), d->actions);
connect(d->searchLine, SIGNAL(textChanged(QString)), this, SLOT(_k_searchEditChanged()));
connect(d->searchLine, SIGNAL(returnPressed()), this, SLOT(_k_search()));
}
if ((SearchLine & controls) && ((FontCombo & controls) || (FontSize & controls) || (BlockCombos & controls))) {
QFrame* line = new QFrame(this);
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
mainLayout->addWidget(line);
}
QHBoxLayout *comboLayout = new QHBoxLayout();
d->backButton = new QToolButton(this);
comboLayout->addWidget(d->backButton);
d->backButton->setEnabled(false);
d->backButton->setText(i18nc("Goes to previous character", "Previous in History"));
d->backButton->setIcon(KIcon("go-previous"));
d->backButton->setToolTip(i18n("Previous Character in History"));
d->forwardButton = new QToolButton(this);
comboLayout->addWidget(d->forwardButton);
d->forwardButton->setEnabled(false);
d->forwardButton->setText(i18nc("Goes to next character", "Next in History"));
d->forwardButton->setIcon(KIcon("go-next"));
d->forwardButton->setToolTip(i18n("Next Character in History"));
KStandardAction::back(d->backButton, SLOT(animateClick()), d->actions);
KStandardAction::forward(d->forwardButton, SLOT(animateClick()), d->actions);
connect(d->backButton, SIGNAL(clicked()), this, SLOT(_k_back()));
connect(d->forwardButton, SIGNAL(clicked()), this, SLOT(_k_forward()));
d->sectionCombo = new KComboBox(this);
d->sectionCombo->setToolTip(i18n("Select a category"));
comboLayout->addWidget(d->sectionCombo);
d->blockCombo = new KComboBox(this);
d->blockCombo->setToolTip(i18n("Select a block to be displayed"));
d->blockCombo->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
comboLayout->addWidget(d->blockCombo, 1);
d->sectionCombo->addItems(s_data->sectionList());
d->blockCombo->setMinimumWidth(QFontMetrics(QWidget::font()).averageCharWidth() * 25);
connect(d->sectionCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(_k_sectionSelected(int)));
connect(d->blockCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(_k_blockSelected(int)));
d->fontCombo = new KFontComboBox(this);
comboLayout->addWidget(d->fontCombo);
d->fontCombo->setEditable(true);
d->fontCombo->resize(d->fontCombo->sizeHint());
d->fontCombo->setToolTip(i18n("Set font"));
d->fontSizeSpinBox = new QSpinBox(this);
comboLayout->addWidget(d->fontSizeSpinBox);
d->fontSizeSpinBox->setValue(QWidget::font().pointSize());
d->fontSizeSpinBox->setRange(1, 400);
d->fontSizeSpinBox->setSingleStep(1);
d->fontSizeSpinBox->setToolTip(i18n("Set font size"));
connect(d->fontCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(_k_fontSelected()));
connect(d->fontSizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(_k_fontSelected()));
if ((HistoryButtons & controls) || (FontCombo & controls) || (FontSize & controls) || (BlockCombos & controls)) {
mainLayout->addLayout(comboLayout);
}
if (!(HistoryButtons & controls)) {
d->backButton->hide();
d->forwardButton->hide();
}
if (!(FontCombo & controls)) {
d->fontCombo->hide();
}
if (!(FontSize & controls)) {
d->fontSizeSpinBox->hide();
}
if (!(BlockCombos & controls)) {
d->sectionCombo->hide();
d->blockCombo->hide();
}
QSplitter *splitter = new QSplitter(this);
if ((CharacterTable & controls) || (DetailBrowser & controls)) {
mainLayout->addWidget(splitter);
} else {
splitter->hide();
}
d->charTable = new KCharSelectTable(this, QFont());
if (CharacterTable & controls) {
splitter->addWidget(d->charTable);
d->charTable->setFocus(Qt::OtherFocusReason);
} else {
d->charTable->hide();
}
const QSize sz(200, 200);
d->charTable->resize(sz);
d->charTable->setMinimumSize(sz);
d->charTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setCurrentFont(QFont());
connect(d->charTable, SIGNAL(focusItemChanged(QChar)), this, SLOT(_k_updateCurrentChar(QChar)));
connect(d->charTable, SIGNAL(activated(QChar)), this, SIGNAL(charSelected(QChar)));
connect(d->charTable, SIGNAL(focusItemChanged(QChar)),
this, SIGNAL(currentCharChanged(QChar)));
connect(d->charTable, SIGNAL(showCharRequested(QChar)), this, SLOT(setCurrentChar(QChar)));
d->detailBrowser = new QTextBrowser(this);
if (DetailBrowser & controls) {
splitter->addWidget(d->detailBrowser);
} else {
d->detailBrowser->hide();
}
d->detailBrowser->setOpenLinks(false);
connect(d->detailBrowser, SIGNAL(anchorClicked(QUrl)), this, SLOT(_k_linkClicked(QUrl)));
setFocusPolicy(Qt::StrongFocus);
setFocusProxy(d->charTable);
d->_k_sectionSelected(0);
d->_k_blockSelected(0);
setCurrentChar(0x0);
d->historyEnabled = true;
}
KCharSelect::~KCharSelect()
{
delete d;
}
QSize KCharSelect::sizeHint() const
{
return QWidget::sizeHint();
}
void KCharSelect::setCurrentFont(const QFont &_font)
{
d->fontCombo->setCurrentFont(_font);
d->fontSizeSpinBox->setValue(_font.pointSize());
d->_k_fontSelected();
}
QChar KCharSelect::currentChar() const
{
return d->charTable->chr();
}
QFont KCharSelect::currentFont() const
{
return d->charTable->font();
}
QList<QChar> KCharSelect::displayedChars() const
{
return d->charTable->displayedChars();
}
void KCharSelect::setCurrentChar(const QChar &c)
{
bool oldHistoryEnabled = d->historyEnabled;
d->historyEnabled = false;
int block = s_data->blockIndex(c);
int section = s_data->sectionIndex(block);
d->sectionCombo->setCurrentIndex(section);
int index = d->blockCombo->findData(block);
if (index != -1) {
d->blockCombo->setCurrentIndex(index);
}
d->historyEnabled = oldHistoryEnabled;
d->charTable->setChar(c);
}
void KCharSelect::KCharSelectPrivate::historyAdd(const QChar &c, bool fromSearch, const QString &searchString)
{
//kDebug() << "about to add char" << c << "fromSearch" << fromSearch << "searchString" << searchString;
if (!historyEnabled) {
return;
}
if (!history.isEmpty() && c == history.last().c) {
//avoid duplicates
return;
}
//behave like a web browser, i.e. if user goes back from B to A then clicks C, B is forgotten
while (!history.isEmpty() && inHistory != history.count() - 1) {
history.removeLast();
}
while (history.size() >= MaxHistoryItems) {
history.removeFirst();
}
HistoryItem item;
item.c = c;
item.fromSearch = fromSearch;
item.searchString = searchString;
history.append(item);
inHistory = history.count() - 1;
updateBackForwardButtons();
}
void KCharSelect::KCharSelectPrivate::showFromHistory(int index)
{
Q_ASSERT(index >= 0 && index < history.count());
Q_ASSERT(index != inHistory);
inHistory = index;
updateBackForwardButtons();
const HistoryItem &item = history[index];
//kDebug() << "index" << index << "char" << item.c << "fromSearch" << item.fromSearch
// << "searchString" << item.searchString;
//avoid adding an item from history into history again
bool oldHistoryEnabled = historyEnabled;
historyEnabled = false;
if (item.fromSearch) {
if (searchLine->text() != item.searchString) {
searchLine->setText(item.searchString);
_k_search();
}
charTable->setChar(item.c);
} else {
searchLine->clear();
q->setCurrentChar(item.c);
}
historyEnabled = oldHistoryEnabled;
}
void KCharSelect::KCharSelectPrivate::updateBackForwardButtons()
{
backButton->setEnabled(inHistory > 0);
forwardButton->setEnabled(inHistory < history.count() - 1);
}
void KCharSelect::KCharSelectPrivate::_k_activateSearchLine()
{
searchLine->setFocus();
searchLine->selectAll();
}
void KCharSelect::KCharSelectPrivate::_k_back()
{
Q_ASSERT(inHistory > 0);
showFromHistory(inHistory - 1);
}
void KCharSelect::KCharSelectPrivate::_k_forward()
{
Q_ASSERT(inHistory + 1 < history.count());
showFromHistory(inHistory + 1);
}
void KCharSelect::KCharSelectPrivate::_k_fontSelected()
{
QFont font = fontCombo->currentFont();
font.setPointSize(fontSizeSpinBox->value());
charTable->setFont(font);
emit q->currentFontChanged(font);
}
void KCharSelect::KCharSelectPrivate::_k_updateCurrentChar(const QChar &c)
{
if (searchMode) {
//we are in search mode. make the two comboboxes show the section & block for this character.
//(when we are not in search mode the current character always belongs to the current section & block.)
int block = s_data->blockIndex(c);
int section = s_data->sectionIndex(block);
sectionCombo->setCurrentIndex(section);
int index = blockCombo->findData(block);
if (index != -1) {
blockCombo->setCurrentIndex(index);
}
}
if( searchLine)
historyAdd(c, searchMode, searchLine->text());
_k_slotUpdateUnicode(c);
}
void KCharSelect::KCharSelectPrivate::_k_slotUpdateUnicode(const QChar &c)
{
QString html = "<p>" + i18n("Character:") + ' ' + s_data->display(c, charTable->font()) + ' ' +
s_data->formatCode(c.unicode()) + "<br />";
QString name = s_data->name(c);
if (!name.isEmpty()) {
//is name ever empty? </p> should always be there...
html += i18n("Name: ") + Qt::escape(name) + "</p>";
}
QStringList aliases = s_data->aliases(c);
QStringList notes = s_data->notes(c);
QList<QChar> seeAlso = s_data->seeAlso(c);
QStringList equivalents = s_data->equivalents(c);
QStringList approxEquivalents = s_data->approximateEquivalents(c);
if (!(aliases.isEmpty() && notes.isEmpty() && seeAlso.isEmpty() && equivalents.isEmpty() && approxEquivalents.isEmpty())) {
html += "<p><b>" + i18n("Annotations and Cross References") + "</b></p>";
}
if (!aliases.isEmpty()) {
html += "<p style=\"margin-bottom: 0px;\">" + i18n("Alias names:") + "</p><ul style=\"margin-top: 0px;\">";
foreach(const QString &alias, aliases) {
html += "<li>" + Qt::escape(alias) + "</li>";
}
html += "</ul>";
}
if (!notes.isEmpty()) {
html += "<p style=\"margin-bottom: 0px;\">" + i18n("Notes:") + "</p><ul style=\"margin-top: 0px;\">";
foreach(const QString &note, notes) {
html += "<li>" + createLinks(Qt::escape(note)) + "</li>";
}
html += "</ul>";
}
if (!seeAlso.isEmpty()) {
html += "<p style=\"margin-bottom: 0px;\">" + i18n("See also:") + "</p><ul style=\"margin-top: 0px;\">";
foreach(const QChar &c2, seeAlso) {
html += "<li><a href=\"" + QString::number(c2.unicode(), 16) + "\">";
if (s_data->isPrint(c2)) {
html += "&#" + QString::number(c2.unicode()) + "; ";
}
html += s_data->formatCode(c2.unicode()) + ' ' + Qt::escape(s_data->name(c2)) + "</a></li>";
}
html += "</ul>";
}
if (!equivalents.isEmpty()) {
html += "<p style=\"margin-bottom: 0px;\">" + i18n("Equivalents:") + "</p><ul style=\"margin-top: 0px;\">";
foreach(const QString &equivalent, equivalents) {
html += "<li>" + createLinks(Qt::escape(equivalent)) + "</li>";
}
html += "</ul>";
}
if (!approxEquivalents.isEmpty()) {
html += "<p style=\"margin-bottom: 0px;\">" + i18n("Approximate equivalents:") + "</p><ul style=\"margin-top: 0px;\">";
foreach(const QString &approxEquivalent, approxEquivalents) {
html += "<li>" + createLinks(Qt::escape(approxEquivalent)) + "</li>";
}
html += "</ul>";
}
QStringList unihan = s_data->unihanInfo(c);
if (unihan.count() == 7) {
html += "<p><b>" + i18n("CJK Ideograph Information") + "</b></p><p>";
bool newline = true;
if (!unihan[0].isEmpty()) {
html += i18n("Definition in English: ") + unihan[0];
newline = false;
}
if (!unihan[2].isEmpty()) {
if (!newline) html += "<br>";
html += i18n("Mandarin Pronunciation: ") + unihan[2];
newline = false;
}
if (!unihan[1].isEmpty()) {
if (!newline) html += "<br>";
html += i18n("Cantonese Pronunciation: ") + unihan[1];
newline = false;
}
if (!unihan[6].isEmpty()) {
if (!newline) html += "<br>";
html += i18n("Japanese On Pronunciation: ") + unihan[6];
newline = false;
}
if (!unihan[5].isEmpty()) {
if (!newline) html += "<br>";
html += i18n("Japanese Kun Pronunciation: ") + unihan[5];
newline = false;
}
if (!unihan[3].isEmpty()) {
if (!newline) html += "<br>";
html += i18n("Tang Pronunciation: ") + unihan[3];
newline = false;
}
if (!unihan[4].isEmpty()) {
if (!newline) html += "<br>";
html += i18n("Korean Pronunciation: ") + unihan[4];
newline = false;
}
html += "</p>";
}
html += "<p><b>" + i18n("General Character Properties") + "</b><br>";
html += i18n("Block: ") + s_data->block(c) + "<br>";
html += i18n("Unicode category: ") + s_data->categoryText(s_data->category(c)) + "</p>";
QByteArray utf8 = QString(c).toUtf8();
html += "<p><b>" + i18n("Various Useful Representations") + "</b><br>";
html += i18n("UTF-8:");
foreach(unsigned char c, utf8)
html += ' ' + s_data->formatCode(c, 2, "0x");
html += "<br>" + i18n("UTF-16: ") + s_data->formatCode(c.unicode(), 4, "0x") + "<br>";
html += i18n("C octal escaped UTF-8: ");
foreach(unsigned char c, utf8)
html += s_data->formatCode(c, 3, "\\", 8);
html += "<br>" + i18n("XML decimal entity:") + " &amp;#" + QString::number(c.unicode()) + ";</p>";
detailBrowser->setHtml(html);
}
QString KCharSelect::KCharSelectPrivate::createLinks(QString s)
{
QRegExp rx("\\b([\\dABCDEF]{4})\\b");
QStringList chars;
int pos = 0;
while ((pos = rx.indexIn(s, pos)) != -1) {
chars << rx.cap(1);
pos += rx.matchedLength();
}
QSet<QString> chars2 = QSet<QString>::fromList(chars);
foreach(const QString &c, chars2) {
int unicode = c.toInt(0, 16);
QString link = "<a href=\"" + c + "\">";
if (s_data->isPrint(QChar(unicode))) {
link += "&#" + QString::number(unicode) + ";&nbsp;";
}
link += "U+" + c + ' ';
link += Qt::escape(s_data->name(QChar(unicode))) + "</a>";
s.replace(c, link);
}
return s;
}
void KCharSelect::KCharSelectPrivate::_k_sectionSelected(int index)
{
blockCombo->clear();
QList<int> blocks = s_data->sectionContents(index);
foreach(int block, blocks) {
blockCombo->addItem(s_data->blockName(block), QVariant(block));
}
blockCombo->setCurrentIndex(0);
}
void KCharSelect::KCharSelectPrivate::_k_blockSelected(int index)
{
if (index == -1) {
//the combo box has been cleared and is about to be filled again (because the section has changed)
return;
}
if (searchMode) {
//we are in search mode, so don't fill the table with this block.
return;
}
int block = blockCombo->itemData(index).toInt();
const QList<QChar> contents = s_data->blockContents(block);
if(contents.count() <= index) {
return;
}
charTable->setContents(contents);
emit q->displayedCharsChanged();
charTable->setChar(contents[0]);
}
void KCharSelect::KCharSelectPrivate::_k_searchEditChanged()
{
if (searchLine->text().isEmpty()) {
sectionCombo->setEnabled(true);
blockCombo->setEnabled(true);
//upon leaving search mode, keep the same character selected
searchMode = false;
QChar c = charTable->chr();
bool oldHistoryEnabled = historyEnabled;
historyEnabled = false;
_k_blockSelected(blockCombo->currentIndex());
historyEnabled = oldHistoryEnabled;
q->setCurrentChar(c);
} else {
sectionCombo->setEnabled(false);
blockCombo->setEnabled(false);
int length = searchLine->text().length();
if (length >= 3) {
_k_search();
}
}
}
void KCharSelect::KCharSelectPrivate::_k_search()
{
if (searchLine->text().isEmpty()) {
return;
}
searchMode = true;
const QList<QChar> contents = s_data->find(searchLine->text());
charTable->setContents(contents);
emit q->displayedCharsChanged();
if (!contents.isEmpty()) {
charTable->setChar(contents[0]);
}
}
void KCharSelect::KCharSelectPrivate::_k_linkClicked(QUrl url)
{
QString hex = url.toString();
if (hex.size() > 4) {
return;
}
int unicode = hex.toInt(0, 16);
searchLine->clear();
q->setCurrentChar(QChar(unicode));
}
////
QVariant KCharSelectItemModel::data(const QModelIndex &index, int role) const
{
int pos = m_columns * (index.row()) + index.column();
if (!index.isValid() || pos < 0 || pos >= m_chars.size()
|| index.row() < 0 || index.column() < 0) {
if (role == Qt::BackgroundRole) {
return QVariant(qApp->palette().color(QPalette::Button));
}
return QVariant();
}
QChar c = m_chars[pos];
if (role == Qt::ToolTipRole) {
QString result = s_data->display(c, m_font) + "<br />" + Qt::escape(s_data->name(c)) + "<br />" +
i18n("Unicode code point:") + ' ' + s_data->formatCode(c.unicode()) + "<br />" +
i18nc("Character", "In decimal:") + ' ' + QString::number(c.unicode());
return QVariant(result);
} else if (role == Qt::TextAlignmentRole)
return QVariant(Qt::AlignHCenter | Qt::AlignVCenter);
else if (role == Qt::DisplayRole) {
if (s_data->isPrint(c))
return QVariant(c);
return QVariant();
} else if (role == Qt::BackgroundRole) {
QFontMetrics fm = QFontMetrics(m_font);
if (fm.inFont(c) && s_data->isPrint(c))
return QVariant(qApp->palette().color(QPalette::Base));
else
return QVariant(qApp->palette().color(QPalette::Button));
} else if (role == Qt::FontRole)
return QVariant(m_font);
else if (role == CharacterRole) {
return QVariant(c);
}
return QVariant();
}
#include "moc_kcharselect.cpp"
#include "moc_kcharselect_p.cpp"

View file

@ -1,218 +0,0 @@
/* This file is part of the KDE libraries
Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCHARSELECT_H
#define KCHARSELECT_H
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QMetaType>
#include <QtGui/QWidget>
#include <kglobal.h>
#include <kdeui_export.h>
class KActionCollection;
#include <QFont>
#include <QUrl>
/**
* @short Character selection widget
*
* This widget allows the user to select a character of a
* specified font and to browse Unicode information
*
* \image html kcharselect.png "Character Selection Widget"
*
* You can specify the font whose characters should be displayed via
* setCurrentFont(). Using the Controls argument in the contructor
* you can create a compact version of KCharSelect if there is not enough
* space and if you don't need all features.
*
* KCharSelect displays one Unicode block at a time and provides
* categorized access to them. Unicode character names and further details,
* including cross references, are displayed. Additionally, there is a search
* to find characters.
*
* To get the current selected character, use the currentChar()
* method. You can set the character which should be displayed with
* setCurrentChar().
*
* @author Reginald Stadlbauer <reggie@kde.org>
* @author Daniel Laidig <d.laidig@gmx.de>
*/
class KDEUI_EXPORT KCharSelect : public QWidget
{
Q_OBJECT
Q_PROPERTY(QFont currentFont READ currentFont WRITE setCurrentFont)
Q_PROPERTY(QChar currentChar READ currentChar WRITE setCurrentChar)
Q_PROPERTY(QList<QChar> displayedChars READ displayedChars)
public:
/**
* Flags to set the shown widgets
*/
enum Control {
/**
* Shows the search widgets
*/
SearchLine = 0x01,
/**
* Shows the font combo box
*/
FontCombo = 0x02,
/**
* Shows the font size spin box
*/
FontSize = 0x04,
/**
* Shows the category/block selection combo boxes
*/
BlockCombos = 0x08,
/**
* Shows the actual table
*/
CharacterTable = 0x10,
/**
* Shows the detail browser
*/
DetailBrowser = 0x20,
/**
* Shows the Back/Forward buttons
*/
HistoryButtons = 0x40,
/**
* Shows everything
*/
AllGuiElements = 65535
};
Q_DECLARE_FLAGS(Controls,
Control)
/** @deprecated */
/**
* Constructor. @p controls can be used to show a custom set of widgets.
*
* The widget uses the following actions:
* - KStandardActions::find() (edit_find)
* - KStandardActions::back() (go_back)
* - KStandardActions::forward() (go_forward)
*
* If you provide a KActionCollection, this will be populated with the above actions,
* which you can then manually trigger or place in menus and toolbars.
*
* @param parent the parent widget for this KCharSelect (see QWidget documentation)
* @param collection if this is not @c null, KCharSelect will place its actions into this
* collection
* @param controls selects the visible controls on the KCharSelect widget
*
* @since 4.2
*/
explicit KCharSelect(
QWidget *parent,
KActionCollection *collection,
const Controls controls = AllGuiElements);
~KCharSelect();
/**
* Reimplemented.
*/
virtual QSize sizeHint() const;
/**
* Returns the currently selected character.
*/
QChar currentChar() const;
/**
* Returns the currently displayed font.
*/
QFont currentFont() const;
/**
* Returns a list of currently displayed characters.
*/
QList<QChar> displayedChars() const;
public Q_SLOTS:
/**
* Highlights the character @p c. If the character is not displayed, the block is changed.
*
* @param c the character to highlight
*/
void setCurrentChar(const QChar &c);
/**
* Sets the font which is displayed to @p font
*
* @param font the display font for the widget
*/
void setCurrentFont(const QFont &font);
Q_SIGNALS:
/**
* A new font is selected or the font size changed.
*
* @param font the new font
*/
void currentFontChanged(const QFont &font);
/**
* The current character is changed.
*
* @param c the new character
*/
void currentCharChanged(const QChar &c);
/**
* The currently displayed characters are changed (search results or block).
*/
void displayedCharsChanged();
/**
* A character is selected to be inserted somewhere.
*
* @param c the selected character
*/
void charSelected(const QChar &c);
private:
Q_PRIVATE_SLOT(d, void _k_activateSearchLine())
Q_PRIVATE_SLOT(d, void _k_back())
Q_PRIVATE_SLOT(d, void _k_forward())
Q_PRIVATE_SLOT(d, void _k_fontSelected())
Q_PRIVATE_SLOT(d, void _k_updateCurrentChar(const QChar &c))
Q_PRIVATE_SLOT(d, void _k_slotUpdateUnicode(const QChar &c))
Q_PRIVATE_SLOT(d, void _k_sectionSelected(int index))
Q_PRIVATE_SLOT(d, void _k_blockSelected(int index))
Q_PRIVATE_SLOT(d, void _k_searchEditChanged())
Q_PRIVATE_SLOT(d, void _k_search())
Q_PRIVATE_SLOT(d, void _k_linkClicked(QUrl))
class KCharSelectPrivate;
KCharSelectPrivate* const d;
void init(const Controls, KActionCollection *);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(KCharSelect::Controls)
Q_DECLARE_METATYPE(QList<QChar>)
#endif

View file

@ -1,226 +0,0 @@
/* This file is part of the KDE libraries
Copyright (C) 2005 Joseph Wenninger <jowenn@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCHARSELECT_P_H
#define KCHARSELECT_P_H
#include <QtCore/qabstractitemmodel.h>
#include <QAbstractItemView>
#include <QTextDocument>
#include <QFont>
#include <QApplication>
#include <QMimeData>
#include <QtGui/QTableView>
#include <klocale.h>
#include "kcharselectdata_p.h"
class KCharSelectTablePrivate;
/**
* @short Character selection table
*
* A table widget which displays the characters of a font. Internally
* used by KCharSelect. See the KCharSelect documentation for further
* details.
*
* @author Reginald Stadlbauer <reggie@kde.org>
* @author Daniel Laidig <d.laidig@gmx.de>
*/
class KCharSelectTable : public QTableView
{
Q_OBJECT
public:
/**
* Constructor. Using @p _font, draw a table of chars.
* @sa setContents
*/
KCharSelectTable(QWidget *parent, const QFont &_font);
~KCharSelectTable();
/**
* Reimplemented.
*/
virtual void resizeEvent(QResizeEvent *);
/** Set the font to be displayed to @p _font . */
virtual void setFont(const QFont &_font);
/** Set the highlighted character to @p c . */
virtual void setChar(const QChar &c);
/** Set the contents of the table to @p chars . */
void setContents(QList<QChar> chars);
/** @return Currently highlighted character. */
virtual QChar chr();
/**
* Returns the currently displayed font.
*/
QFont font() const;
/**
* Returns a list of currently displayed characters.
*/
QList<QChar> displayedChars() const;
/**
* Reimplemented.
*/
virtual void scrollTo(const QModelIndex & index, ScrollHint hint = EnsureVisible);
protected:
/**
* Reimplemented.
*/
virtual void keyPressEvent(QKeyEvent *e);
Q_SIGNALS:
/** Emitted to indicate that character @p c is activated (such as by double-clicking it). */
void activated(const QChar &c);
void focusItemChanged(const QChar &c);
void showCharRequested(const QChar& c);
private:
Q_PRIVATE_SLOT(d, void _k_slotSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected))
Q_PRIVATE_SLOT(d, void _k_resizeCells())
Q_PRIVATE_SLOT(d, void _k_doubleClicked(const QModelIndex & index))
private:
friend class KCharSelectTablePrivate;
KCharSelectTablePrivate* const d;
Q_DISABLE_COPY(KCharSelectTable)
};
// NO D-Pointer needed, private internal class, no public API
class KCharSelectItemModel: public QAbstractTableModel
{
Q_OBJECT
public:
KCharSelectItemModel(QList<QChar> chars, const QFont& font, QObject *parent): QAbstractTableModel(parent), m_chars(chars), m_font(font)
{
if(chars.count()) {
m_columns = chars.count();
} else {
m_columns = 1;
}
}
enum internalRoles {CharacterRole = Qt::UserRole};
int rowCount(const QModelIndex&) const
{
if (m_chars.count() % m_columns == 0)
return m_chars.count() / m_columns;
else
return m_chars.count() / m_columns + 1;
}
int columnCount(const QModelIndex&) const
{
return m_columns;
}
void setFont(const QFont& font)
{
m_font = font; reset();
}
Qt::ItemFlags flags(const QModelIndex &index) const
{
int pos = m_columns * (index.row()) + index.column();
if (pos >= m_chars.size() || index.row() < 0 || index.column() < 0) {
return Qt::ItemIsDropEnabled;
}
return (Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsSelectable | Qt::ItemIsEnabled);
}
QVariant data(const QModelIndex &index, int role) const;
QMimeData *mimeData(const QModelIndexList & indexes) const
{
if (indexes.size() != 1) {
return 0;
}
QMimeData *mimeData = new QMimeData();
mimeData->setText(data(indexes[0], CharacterRole).toString());
return mimeData;
}
Qt::DropActions supportedDropActions() const
{
return Qt::CopyAction;
}
QStringList mimeTypes() const
{
QStringList types;
types << "text/plain";
return types;
}
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
Q_UNUSED(row)
Q_UNUSED(parent)
if (action == Qt::IgnoreAction) {
return true;
}
if (!data->hasText()) {
return false;
}
if (column > 0) {
return false;
}
QString text = data->text();
if (text.isEmpty()) {
return false;
}
emit showCharRequested(text[0]);
return true;
}
void updateColumnCount(int maxWidth)
{
emit layoutAboutToBeChanged();
QFontMetrics fm(m_font);
int maxChar = fm.maxWidth();
if (maxChar < 2*fm.xHeight()) {
maxChar = 2 * fm.xHeight();
}
if (maxChar < 5) {
maxChar = qMax(5, fm.height());
}
m_columns = maxWidth / maxChar;
if (m_columns <= 0) {
m_columns = 1;
}
emit layoutChanged();
}
private:
QList<QChar> m_chars;
QFont m_font;
int m_columns;
Q_SIGNALS:
void showCharRequested(const QChar& c);
};
#endif // KCHARSELECT_P_H

View file

@ -1,889 +0,0 @@
/* This file is part of the KDE libraries
Copyright (C) 2007 Daniel Laidig <d.laidig@gmx.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kcharselectdata_p.h"
#include <QStringList>
#include <QFile>
#include <QSet>
#include <qendian.h>
#include <QtConcurrentRun>
#include <string.h>
#include <klocalizedstring.h>
#include <kstandarddirs.h>
/* constants for hangul (de)composition, see UAX #15 */
#define SBase 0xAC00
#define LBase 0x1100
#define VBase 0x1161
#define TBase 0x11A7
#define LCount 19
#define VCount 21
#define TCount 28
#define NCount (VCount * TCount)
#define SCount (LCount * NCount)
static const char JAMO_L_TABLE[][4] =
{
"G", "GG", "N", "D", "DD", "R", "M", "B", "BB",
"S", "SS", "", "J", "JJ", "C", "K", "T", "P", "H"
};
static const char JAMO_V_TABLE[][4] =
{
"A", "AE", "YA", "YAE", "EO", "E", "YEO", "YE", "O",
"WA", "WAE", "OE", "YO", "U", "WEO", "WE", "WI",
"YU", "EU", "YI", "I"
};
static const char JAMO_T_TABLE[][4] =
{
"", "G", "GG", "GS", "N", "NJ", "NH", "D", "L", "LG", "LM",
"LB", "LS", "LT", "LP", "LH", "M", "B", "BS",
"S", "SS", "NG", "J", "C", "K", "T", "P", "H"
};
bool KCharSelectData::openDataFile()
{
if(!dataFile.isEmpty()) {
return true;
} else {
QFile file(KStandardDirs::locate("data", "kcharselect/kcharselect-data"));
if (!file.open(QIODevice::ReadOnly)) {
return false;
}
dataFile = file.readAll();
file.close();
futureIndex = QtConcurrent::run(this, &KCharSelectData::createIndex, dataFile);
return true;
}
}
quint32 KCharSelectData::getDetailIndex(const QChar& c) const
{
const uchar* data = reinterpret_cast<const uchar*>(dataFile.constData());
// Convert from little-endian, so that this code works on PPC too.
// http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=482286
const quint32 offsetBegin = qFromLittleEndian<quint32>(data+12);
const quint32 offsetEnd = qFromLittleEndian<quint32>(data+16);
int min = 0;
int mid;
int max = ((offsetEnd - offsetBegin) / 27) - 1;
quint16 unicode = c.unicode();
static quint16 most_recent_searched;
static quint32 most_recent_result;
if (unicode == most_recent_searched)
return most_recent_result;
most_recent_searched = unicode;
while (max >= min) {
mid = (min + max) / 2;
const quint16 midUnicode = qFromLittleEndian<quint16>(data + offsetBegin + mid*27);
if (unicode > midUnicode)
min = mid + 1;
else if (unicode < midUnicode)
max = mid - 1;
else {
most_recent_result = offsetBegin + mid*27;
return most_recent_result;
}
}
most_recent_result = 0;
return 0;
}
QString KCharSelectData::formatCode(ushort code, int length, const QString& prefix, int base)
{
QString s = QString::number(code, base).toUpper();
while (s.size() < length)
s.prepend('0');
s.prepend(prefix);
return s;
}
QList<QChar> KCharSelectData::blockContents(int block)
{
if(!openDataFile()) {
return QList<QChar>();
}
const uchar* data = reinterpret_cast<const uchar*>(dataFile.constData());
const quint32 offsetBegin = qFromLittleEndian<quint32>(data+20);
const quint32 offsetEnd = qFromLittleEndian<quint32>(data+24);
int max = ((offsetEnd - offsetBegin) / 4) - 1;
QList<QChar> res;
if(block > max)
return res;
quint16 unicodeBegin = qFromLittleEndian<quint16>(data + offsetBegin + block*4);
quint16 unicodeEnd = qFromLittleEndian<quint16>(data + offsetBegin + block*4 + 2);
while(unicodeBegin < unicodeEnd) {
res.append(unicodeBegin);
unicodeBegin++;
}
res.append(unicodeBegin); // Be carefull when unicodeEnd==0xffff
return res;
}
QList<int> KCharSelectData::sectionContents(int section)
{
if(!openDataFile()) {
return QList<int>();
}
const uchar* data = reinterpret_cast<const uchar*>(dataFile.constData());
const quint32 offsetBegin = qFromLittleEndian<quint32>(data+28);
const quint32 offsetEnd = qFromLittleEndian<quint32>(data+32);
int max = ((offsetEnd - offsetBegin) / 4) - 1;
QList<int> res;
if(section > max)
return res;
for(int i = 0; i <= max; i++) {
const quint16 currSection = qFromLittleEndian<quint16>(data + offsetBegin + i*4);
if(currSection == section) {
res.append( qFromLittleEndian<quint16>(data + offsetBegin + i*4 + 2) );
}
}
return res;
}
QStringList KCharSelectData::sectionList()
{
if(!openDataFile()) {
return QStringList();
}
const uchar* udata = reinterpret_cast<const uchar*>(dataFile.constData());
const quint32 stringBegin = qFromLittleEndian<quint32>(udata+24);
const quint32 stringEnd = qFromLittleEndian<quint32>(udata+28);
const char* data = dataFile.constData();
QStringList list;
quint32 i = stringBegin;
while(i < stringEnd) {
list.append(i18nc("KCharSelect section name", data + i));
i += strlen(data + i) + 1;
}
return list;
}
QString KCharSelectData::block(const QChar& c)
{
return blockName(blockIndex(c));
}
QString KCharSelectData::section(const QChar& c)
{
return sectionName(sectionIndex(blockIndex(c)));
}
QString KCharSelectData::name(const QChar& c)
{
if(!openDataFile()) {
return QString();
}
ushort unicode = c.unicode();
if ((unicode >= 0x3400 && unicode <= 0x4DB5)
|| (unicode >= 0x4e00 && unicode <= 0x9fa5)) {
// || (unicode >= 0x20000 && unicode <= 0x2A6D6) // useless, since limited to 16 bit
return "CJK UNIFIED IDEOGRAPH-" + QString::number(unicode, 16);
} else if (c >= 0xac00 && c <= 0xd7af) {
/* compute hangul syllable name as per UAX #15 */
int SIndex = c.unicode() - SBase;
int LIndex, VIndex, TIndex;
if (SIndex < 0 || SIndex >= SCount)
return QString();
LIndex = SIndex / NCount;
VIndex = (SIndex % NCount) / TCount;
TIndex = SIndex % TCount;
return QLatin1String("HANGUL SYLLABLE ") + QLatin1String(JAMO_L_TABLE[LIndex])
+ QLatin1String(JAMO_V_TABLE[VIndex]) + QLatin1String(JAMO_T_TABLE[TIndex]);
} else if (unicode >= 0xD800 && unicode <= 0xDB7F)
return i18n("<Non Private Use High Surrogate>");
else if (unicode >= 0xDB80 && unicode <= 0xDBFF)
return i18n("<Private Use High Surrogate>");
else if (unicode >= 0xDC00 && unicode <= 0xDFFF)
return i18n("<Low Surrogate>");
else if (unicode >= 0xE000 && unicode <= 0xF8FF)
return i18n("<Private Use>");
// else if (unicode >= 0xF0000 && unicode <= 0xFFFFD) // 16 bit!
// return i18n("<Plane 15 Private Use>");
// else if (unicode >= 0x100000 && unicode <= 0x10FFFD)
// return i18n("<Plane 16 Private Use>");
else {
const uchar* data = reinterpret_cast<const uchar*>(dataFile.constData());
const quint32 offsetBegin = qFromLittleEndian<quint32>(data+4);
const quint32 offsetEnd = qFromLittleEndian<quint32>(data+8);
int min = 0;
int mid;
int max = ((offsetEnd - offsetBegin) / 6) - 1;
QString s;
while (max >= min) {
mid = (min + max) / 2;
const quint16 midUnicode = qFromLittleEndian<quint16>(data + offsetBegin + mid*6);
if (unicode > midUnicode)
min = mid + 1;
else if (unicode < midUnicode)
max = mid - 1;
else {
quint32 offset = qFromLittleEndian<quint32>(data + offsetBegin + mid*6 + 2);
s = QString(dataFile.constData() + offset + 1);
break;
}
}
if (s.isNull()) {
return i18n("<not assigned>");
} else {
return s;
}
}
}
int KCharSelectData::blockIndex(const QChar& c)
{
if(!openDataFile()) {
return 0;
}
const uchar* data = reinterpret_cast<const uchar*>(dataFile.constData());
const quint32 offsetBegin = qFromLittleEndian<quint32>(data+20);
const quint32 offsetEnd = qFromLittleEndian<quint32>(data+24);
const quint16 unicode = c.unicode();
int max = ((offsetEnd - offsetBegin) / 4) - 1;
int i = 0;
while (unicode > qFromLittleEndian<quint16>(data + offsetBegin + i*4 + 2) && i < max) {
i++;
}
return i;
}
int KCharSelectData::sectionIndex(int block)
{
if(!openDataFile()) {
return 0;
}
const uchar* data = reinterpret_cast<const uchar*>(dataFile.constData());
const quint32 offsetBegin = qFromLittleEndian<quint32>(data+28);
const quint32 offsetEnd = qFromLittleEndian<quint32>(data+32);
int max = ((offsetEnd - offsetBegin) / 4) - 1;
for(int i = 0; i <= max; i++) {
if( qFromLittleEndian<quint16>(data + offsetBegin + i*4 + 2) == block) {
return qFromLittleEndian<quint16>(data + offsetBegin + i*4);
}
}
return 0;
}
QString KCharSelectData::blockName(int index)
{
if(!openDataFile()) {
return QString();
}
const uchar* udata = reinterpret_cast<const uchar*>(dataFile.constData());
const quint32 stringBegin = qFromLittleEndian<quint32>(udata+16);
const quint32 stringEnd = qFromLittleEndian<quint32>(udata+20);
quint32 i = stringBegin;
int currIndex = 0;
const char* data = dataFile.constData();
while(i < stringEnd && currIndex < index) {
i += strlen(data + i) + 1;
currIndex++;
}
return i18nc("KCharselect unicode block name", data + i);
}
QString KCharSelectData::sectionName(int index)
{
if(!openDataFile()) {
return QString();
}
const uchar* udata = reinterpret_cast<const uchar*>(dataFile.constData());
const quint32 stringBegin = qFromLittleEndian<quint32>(udata+24);
const quint32 stringEnd = qFromLittleEndian<quint32>(udata+28);
quint32 i = stringBegin;
int currIndex = 0;
const char* data = dataFile.constData();
while(i < stringEnd && currIndex < index) {
i += strlen(data + i) + 1;
currIndex++;
}
return i18nc("KCharselect unicode section name", data + i);
}
QStringList KCharSelectData::aliases(const QChar& c)
{
if(!openDataFile()) {
return QStringList();
}
const uchar* udata = reinterpret_cast<const uchar*>(dataFile.constData());
const int detailIndex = getDetailIndex(c);
if(detailIndex == 0) {
return QStringList();
}
const quint8 count = * (quint8 *)(udata + detailIndex + 6);
quint32 offset = qFromLittleEndian<quint32>(udata + detailIndex + 2);
QStringList aliases;
const char* data = dataFile.constData();
for (int i = 0; i < count; i++) {
aliases.append(QString::fromLatin1(data + offset));
offset += strlen(data + offset) + 1;
}
return aliases;
}
QStringList KCharSelectData::notes(const QChar& c)
{
if(!openDataFile()) {
return QStringList();
}
const int detailIndex = getDetailIndex(c);
if(detailIndex == 0) {
return QStringList();
}
const uchar* udata = reinterpret_cast<const uchar*>(dataFile.constData());
const quint8 count = * (quint8 *)(udata + detailIndex + 11);
quint32 offset = qFromLittleEndian<quint32>(udata + detailIndex + 7);
QStringList notes;
const char* data = dataFile.constData();
for (int i = 0; i < count; i++) {
notes.append(QString::fromLatin1(data + offset));
offset += strlen(data + offset) + 1;
}
return notes;
}
QList<QChar> KCharSelectData::seeAlso(const QChar& c)
{
if(!openDataFile()) {
return QList<QChar>();
}
const int detailIndex = getDetailIndex(c);
if(detailIndex == 0) {
return QList<QChar>();
}
const uchar* udata = reinterpret_cast<const uchar*>(dataFile.constData());
const quint8 count = * (quint8 *)(udata + detailIndex + 26);
quint32 offset = qFromLittleEndian<quint32>(udata + detailIndex + 22);
QList<QChar> seeAlso;
for (int i = 0; i < count; i++) {
seeAlso.append(qFromLittleEndian<quint16> (udata + offset));
offset += 2;
}
return seeAlso;
}
QStringList KCharSelectData::equivalents(const QChar& c)
{
if(!openDataFile()) {
return QStringList();
}
const int detailIndex = getDetailIndex(c);
if(detailIndex == 0) {
return QStringList();
}
const uchar* udata = reinterpret_cast<const uchar*>(dataFile.constData());
const quint8 count = * (quint8 *)(udata + detailIndex + 21);
quint32 offset = qFromLittleEndian<quint32>(udata + detailIndex + 17);
QStringList equivalents;
const char* data = dataFile.constData();
for (int i = 0; i < count; i++) {
equivalents.append(QString::fromLatin1(data + offset));
offset += strlen(data + offset) + 1;
}
return equivalents;
}
QStringList KCharSelectData::approximateEquivalents(const QChar& c)
{
if(!openDataFile()) {
return QStringList();
}
const int detailIndex = getDetailIndex(c);
if(detailIndex == 0) {
return QStringList();
}
const uchar* udata = reinterpret_cast<const uchar*>(dataFile.constData());
const quint8 count = * (quint8 *)(udata + detailIndex + 16);
quint32 offset = qFromLittleEndian<quint32>(udata + detailIndex + 12);
QStringList approxEquivalents;
const char* data = dataFile.constData();
for (int i = 0; i < count; i++) {
approxEquivalents.append(QString::fromLatin1(data + offset));
offset += strlen(data + offset) + 1;
}
return approxEquivalents;
}
QStringList KCharSelectData::unihanInfo(const QChar& c)
{
if(!openDataFile()) {
return QStringList();
}
const char* data = dataFile.constData();
const uchar* udata = reinterpret_cast<const uchar*>(data);
const quint32 offsetBegin = qFromLittleEndian<quint32>(udata+36);
const quint32 offsetEnd = dataFile.size();
int min = 0;
int mid;
int max = ((offsetEnd - offsetBegin) / 30) - 1;
quint16 unicode = c.unicode();
while (max >= min) {
mid = (min + max) / 2;
const quint16 midUnicode = qFromLittleEndian<quint16>(udata + offsetBegin + mid*30);
if (unicode > midUnicode)
min = mid + 1;
else if (unicode < midUnicode)
max = mid - 1;
else {
QStringList res;
for(int i = 0; i < 7; i++) {
quint32 offset = qFromLittleEndian<quint32>(udata + offsetBegin + mid*30 + 2 + i*4);
if(offset != 0) {
res.append(QString::fromLatin1(data + offset));
} else {
res.append(QString());
}
}
return res;
}
}
return QStringList();
}
QChar::Category KCharSelectData::category(const QChar& c)
{
if(!openDataFile()) {
return c.category();
}
ushort unicode = c.unicode();
const uchar* data = reinterpret_cast<const uchar*>(dataFile.constData());
const quint32 offsetBegin = qFromLittleEndian<quint32>(data+4);
const quint32 offsetEnd = qFromLittleEndian<quint32>(data+8);
int min = 0;
int mid;
int max = ((offsetEnd - offsetBegin) / 6) - 1;
QString s;
while (max >= min) {
mid = (min + max) / 2;
const quint16 midUnicode = qFromLittleEndian<quint16>(data + offsetBegin + mid*6);
if (unicode > midUnicode)
min = mid + 1;
else if (unicode < midUnicode)
max = mid - 1;
else {
quint32 offset = qFromLittleEndian<quint32>(data + offsetBegin + mid*6 + 2);
const quint8 categoryCode = * (quint8 *)(data + offset);
return QChar::Category(categoryCode);
}
}
return c.category();
}
bool KCharSelectData::isPrint(const QChar& c)
{
QChar::Category cat = category(c);
return !(cat == QChar::Other_Control || cat == QChar::Other_NotAssigned);
}
bool KCharSelectData::isDisplayable(const QChar& c)
{
// Qt internally uses U+FDD0 and U+FDD1 to mark the beginning and the end of frames.
// They should be seen as non-printable characters, as trying to display them leads
// to a crash caused by a Qt "noBlockInString" assertion.
if(c == 0xFDD0 || c == 0xFDD1)
return false;
return !isIgnorable(c) && isPrint(c);
}
bool KCharSelectData::isIgnorable(const QChar& c)
{
/*
* According to the Unicode standard, Default Ignorable Code Points
* should be ignored unless explicitly supported. For example, U+202E
* RIGHT-TO-LEFT-OVERRIDE ir printable according to Qt, but displaying
* it gives the undesired effect of all text being turned RTL. We do not
* have a way to "explicitly" support it, so we will treat it as
* non-printable.
*
* There is a list of these on
* http://unicode.org/Public/UNIDATA/DerivedCoreProperties.txt under the
* property Default_Ignorable_Code_Point.
*/
//NOTE: not very nice to hardcode these here; is it worth it to modify
// the binary data file to hold them?
return c == 0x00AD || c == 0x034F || c == 0x115F || c == 0x1160 ||
c == 0x17B4 || c == 0x17B5 || (c >= 0x180B && c <= 0x180D) ||
(c >= 0x200B && c <= 0x200F) || (c >= 0x202A && c <= 0x202E) ||
(c >= 0x2060 && c <= 0x206F) || c == 0x3164 ||
(c >= 0xFE00 && c <= 0xFE0F) || c == 0xFEFF || c == 0xFFA0 ||
(c >= 0xFFF0 && c <= 0xFFF8);
}
bool KCharSelectData::isCombining(const QChar &c)
{
return section(c) == i18nc("KCharSelect section name", "Combining Diacritical Marks");
//FIXME: this is an imperfect test. There are many combining characters
// that are outside of this section. See Grapheme_Extend in
// http://www.unicode.org/Public/UNIDATA/DerivedCoreProperties.txt
}
QString KCharSelectData::display(const QChar &c, const QFont &font)
{
if (!isDisplayable(c)) {
return QString("<b>") + i18n("Non-printable") + "</b>";
} else {
QString s = QString("<font size=\"+4\" face=\"") + font.family() + "\">";
if (isCombining(c)) {
s += displayCombining(c);
} else {
s += "&#" + QString::number(c.unicode()) + ';';
}
s += "</font>";
return s;
}
}
QString KCharSelectData::displayCombining(const QChar &c)
{
/*
* The purpose of this is to make it easier to see how a combining
* character affects the text around it.
* The initial plan was to use U+25CC DOTTED CIRCLE for this purpose,
* as seen in pdfs from Unicode, but there seem to be a lot of alignment
* problems with that.
*
* Eventually, it would be nice to determine whether the character
* combines to the left or to the right, etc.
*/
QString s = "&nbsp;&#" + QString::number(c.unicode()) + ";&nbsp;" +
" (ab&#" + QString::number(c.unicode()) + ";c)";
return s;
}
QString KCharSelectData::categoryText(QChar::Category category)
{
switch (category) {
case QChar::Other_Control: return i18n("Other, Control");
case QChar::Other_Format: return i18n("Other, Format");
case QChar::Other_NotAssigned: return i18n("Other, Not Assigned");
case QChar::Other_PrivateUse: return i18n("Other, Private Use");
case QChar::Other_Surrogate: return i18n("Other, Surrogate");
case QChar::Letter_Lowercase: return i18n("Letter, Lowercase");
case QChar::Letter_Modifier: return i18n("Letter, Modifier");
case QChar::Letter_Other: return i18n("Letter, Other");
case QChar::Letter_Titlecase: return i18n("Letter, Titlecase");
case QChar::Letter_Uppercase: return i18n("Letter, Uppercase");
case QChar::Mark_SpacingCombining: return i18n("Mark, Spacing Combining");
case QChar::Mark_Enclosing: return i18n("Mark, Enclosing");
case QChar::Mark_NonSpacing: return i18n("Mark, Non-Spacing");
case QChar::Number_DecimalDigit: return i18n("Number, Decimal Digit");
case QChar::Number_Letter: return i18n("Number, Letter");
case QChar::Number_Other: return i18n("Number, Other");
case QChar::Punctuation_Connector: return i18n("Punctuation, Connector");
case QChar::Punctuation_Dash: return i18n("Punctuation, Dash");
case QChar::Punctuation_Close: return i18n("Punctuation, Close");
case QChar::Punctuation_FinalQuote: return i18n("Punctuation, Final Quote");
case QChar::Punctuation_InitialQuote: return i18n("Punctuation, Initial Quote");
case QChar::Punctuation_Other: return i18n("Punctuation, Other");
case QChar::Punctuation_Open: return i18n("Punctuation, Open");
case QChar::Symbol_Currency: return i18n("Symbol, Currency");
case QChar::Symbol_Modifier: return i18n("Symbol, Modifier");
case QChar::Symbol_Math: return i18n("Symbol, Math");
case QChar::Symbol_Other: return i18n("Symbol, Other");
case QChar::Separator_Line: return i18n("Separator, Line");
case QChar::Separator_Paragraph: return i18n("Separator, Paragraph");
case QChar::Separator_Space: return i18n("Separator, Space");
default: return i18n("Unknown");
}
}
QList<QChar> KCharSelectData::find(const QString& needle)
{
QSet<quint16> result;
QList<QChar> returnRes;
QString simplified = needle.simplified();
QStringList searchStrings = splitString(needle.simplified());
if(simplified.length() == 1) {
// search for hex representation of the character
searchStrings = QStringList(formatCode(simplified.at(0).unicode()));
}
if (searchStrings.count() == 0) {
return returnRes;
}
QRegExp regExp("^(|u\\+|U\\+|0x|0X)([A-Fa-f0-9]{4})$");
foreach(const QString &s, searchStrings) {
if(regExp.exactMatch(s)) {
returnRes.append(regExp.cap(2).toInt(0, 16));
// search for "1234" instead of "0x1234"
if (s.length() == 6) {
searchStrings[searchStrings.indexOf(s)] = regExp.cap(2);
}
}
// try to parse string as decimal number
bool ok;
int unicode = s.toInt(&ok);
if (ok && unicode >= 0 && unicode <= 0xFFFF) {
returnRes.append(unicode);
}
}
bool firstSubString = true;
foreach(const QString &s, searchStrings) {
QSet<quint16> partResult = getMatchingChars(s.toLower());
if (firstSubString) {
result = partResult;
firstSubString = false;
} else {
result = result.intersect(partResult);
}
}
// remove results found by matching the code point to prevent duplicate results
// while letting these characters stay at the beginning
foreach(const QChar &c, returnRes) {
result.remove(c.unicode());
}
QList<quint16> sortedResult = result.toList();
qSort(sortedResult);
foreach(const quint16 &c, sortedResult) {
returnRes.append(c);
}
return returnRes;
}
QSet<quint16> KCharSelectData::getMatchingChars(const QString& s)
{
futureIndex.waitForFinished();
const Index index = futureIndex;
Index::const_iterator pos = index.lowerBound(s);
QSet<quint16> result;
while (pos != index.constEnd() && pos.key().startsWith(s)) {
foreach (const quint16 &c, pos.value()) {
result.insert(c);
}
++pos;
}
return result;
}
QStringList KCharSelectData::splitString(const QString& s)
{
QStringList result;
int start = 0;
int end = 0;
int length = s.length();
while (end < length) {
while (end < length && (s[end].isLetterOrNumber() || s[end] == '+')) {
end++;
}
if (start != end) {
result.append(s.mid(start, end - start));
}
start = end;
while (end < length && !(s[end].isLetterOrNumber() || s[end] == '+')) {
end++;
start++;
}
}
return result;
}
void KCharSelectData::appendToIndex(Index *index, quint16 unicode, const QString& s)
{
const QStringList strings = splitString(s);
foreach(const QString &s, strings) {
(*index)[s.toLower()].append(unicode);
}
}
Index KCharSelectData::createIndex(const QByteArray& dataFile)
{
Index i;
// character names
const uchar* udata = reinterpret_cast<const uchar*>(dataFile.constData());
const char* data = dataFile.constData();
const quint32 nameOffsetBegin = qFromLittleEndian<quint32>(udata+4);
const quint32 nameOffsetEnd = qFromLittleEndian<quint32>(udata+8);
int max = ((nameOffsetEnd - nameOffsetBegin) / 6) - 1;
for (int pos = 0; pos <= max; pos++) {
const quint16 unicode = qFromLittleEndian<quint16>(udata + nameOffsetBegin + pos*6);
quint32 offset = qFromLittleEndian<quint32>(udata + nameOffsetBegin + pos*6 + 2);
appendToIndex(&i, unicode, QString(data + offset + 1));
}
// details
const quint32 detailsOffsetBegin = qFromLittleEndian<quint32>(udata+12);
const quint32 detailsOffsetEnd = qFromLittleEndian<quint32>(udata+16);
max = ((detailsOffsetEnd - detailsOffsetBegin) / 27) - 1;
for (int pos = 0; pos <= max; pos++) {
const quint16 unicode = qFromLittleEndian<quint16>(udata + detailsOffsetBegin + pos*27);
// aliases
const quint8 aliasCount = * (quint8 *)(udata + detailsOffsetBegin + pos*27 + 6);
quint32 aliasOffset = qFromLittleEndian<quint32>(udata + detailsOffsetBegin + pos*27 + 2);
for (int j = 0; j < aliasCount; j++) {
appendToIndex(&i, unicode, QString::fromLatin1(data + aliasOffset));
aliasOffset += strlen(data + aliasOffset) + 1;
}
// notes
const quint8 notesCount = * (quint8 *)(udata + detailsOffsetBegin + pos*27 + 11);
quint32 notesOffset = qFromLittleEndian<quint32>(udata + detailsOffsetBegin + pos*27 + 7);
for (int j = 0; j < notesCount; j++) {
appendToIndex(&i, unicode, QString::fromLatin1(data + notesOffset));
notesOffset += strlen(data + notesOffset) + 1;
}
// approximate equivalents
const quint8 apprCount = * (quint8 *)(udata + detailsOffsetBegin + pos*27 + 16);
quint32 apprOffset = qFromLittleEndian<quint32>(udata + detailsOffsetBegin + pos*27 + 12);
for (int j = 0; j < apprCount; j++) {
appendToIndex(&i, unicode, QString::fromLatin1(data + apprOffset));
apprOffset += strlen(data + apprOffset) + 1;
}
// equivalents
const quint8 equivCount = * (quint8 *)(udata + detailsOffsetBegin + pos*27 + 21);
quint32 equivOffset = qFromLittleEndian<quint32>(udata + detailsOffsetBegin + pos*27 + 17);
for (int j = 0; j < equivCount; j++) {
appendToIndex(&i, unicode, QString::fromLatin1(data + equivOffset));
equivOffset += strlen(data + equivOffset) + 1;
}
// see also - convert to string (hex)
const quint8 seeAlsoCount = * (quint8 *)(udata + detailsOffsetBegin + pos*27 + 26);
quint32 seeAlsoOffset = qFromLittleEndian<quint32>(udata + detailsOffsetBegin + pos*27 + 22);
for (int j = 0; j < seeAlsoCount; j++) {
quint16 seeAlso = qFromLittleEndian<quint16> (udata + seeAlsoOffset);
appendToIndex(&i, unicode, formatCode(seeAlso, 4, QString()));
equivOffset += strlen(data + equivOffset) + 1;
}
}
// unihan data
// temporary disabled due to the huge amount of data
// const quint32 unihanOffsetBegin = qFromLittleEndian<quint32>(udata+36);
// const quint32 unihanOffsetEnd = dataFile.size();
// max = ((unihanOffsetEnd - unihanOffsetBegin) / 30) - 1;
//
// for (int pos = 0; pos <= max; pos++) {
// const quint16 unicode = qFromLittleEndian<quint16>(udata + unihanOffsetBegin + pos*30);
// for(int j = 0; j < 7; j++) {
// quint32 offset = qFromLittleEndian<quint32>(udata + unihanOffsetBegin + pos*30 + 2 + j*4);
// if(offset != 0) {
// appendToIndex(&i, unicode, QString::fromUtf8(data + offset));
// }
// }
// }
return i;
}

View file

@ -1,88 +0,0 @@
/* This file is part of the KDE libraries
Copyright (C) 2007 Daniel Laidig <d.laidig@gmx.de>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCHARSELECTDATA_H
#define KCHARSELECTDATA_H
#include <QtCore/QChar>
#include <QtCore/QList>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QFuture>
#include <QtGui/QFont>
// Internal class used by KCharSelect
typedef QMap<QString, QVector<quint16> > Index;
class KCharSelectData
{
public:
QString formatCode(ushort code, int length = 4, const QString& prefix = "U+", int base = 16);
QList<QChar> blockContents(int block);
QList<int> sectionContents(int section);
QStringList sectionList();
QString block(const QChar& c);
QString section(const QChar& c);
QString name(const QChar& c);
int blockIndex(const QChar& c);
int sectionIndex(int block);
QString blockName(int index);
QString sectionName(int index);
QStringList aliases(const QChar& c);
QStringList notes(const QChar& c);
QList<QChar> seeAlso(const QChar& c);
QStringList equivalents(const QChar& c);
QStringList approximateEquivalents(const QChar& c);
QStringList unihanInfo(const QChar& c);
QChar::Category category(const QChar& c);
bool isPrint(const QChar& c);
bool isDisplayable(const QChar& c);
bool isIgnorable(const QChar& c);
bool isCombining(const QChar& c);
QString display(const QChar& c, const QFont& font);
QString displayCombining(const QChar& c);
QString categoryText(QChar::Category category);
QList<QChar> find(const QString& s);
private:
bool openDataFile();
quint32 getDetailIndex(const QChar& c) const;
QSet<quint16> getMatchingChars(const QString& s);
QStringList splitString(const QString& s);
void appendToIndex(Index *index, quint16 unicode, const QString& s);
Index createIndex(const QByteArray& dataFile);
QByteArray dataFile;
QFuture<Index> futureIndex;
};
#endif /* #ifndef KCHARSELECTDATA_H */

View file

@ -31,12 +31,6 @@ ToolTip=Categorized Item View (KDE)
WhatsThis=Item view for listing items in a categorized fashion optionally.
Group=Views (KDE)
[KCharSelect]
ToolTip=Character Selection Widget (KDE)
WhatsThis=A widget that allows selection a character out ot a table
Group=Graphics (KDE)
ConstructorArgs=(parent, 0)
[KColorButton]
ToolTip=Color Chooser Button (KDE)
WhatsThis=A button that allows selecting a color

View file

@ -2,7 +2,6 @@
<qresource>
<file>pics/kactionselector.png</file>
<file>pics/kactivelabel.png</file>
<file>pics/kcharselect.png</file>
<file>pics/kcmodule.png</file>
<file>pics/kcolorbutton.png</file>
<file>pics/kcolorcombo.png</file>

View file

@ -25,7 +25,6 @@ install(
kgradientselector.png
kdualcolorbutton.png
kpushbutton.png
kcharselect.png
kdatepicker.png
kdialog.png
keditlistbox.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -8,11 +8,6 @@ ToolTip=Active Label (KDE)
WhatsThis=A label with support for selection and clickable links
Group=Display (KDE)
[KCharSelect]
ToolTip=Character Selection Widget (KDE)
WhatsThis=A widget that allows selection a character out ot a table
Group=Graphics (KDE)
[KColorButton]
ToolTip=Color Chooser Button (KDE)
WhatsThis=A button that allows selecting a color