diff options
Diffstat (limited to 'charselectapplet')
-rw-r--r-- | charselectapplet/Makefile.am | 19 | ||||
-rw-r--r-- | charselectapplet/charselectapplet.cpp | 366 | ||||
-rw-r--r-- | charselectapplet/charselectapplet.h | 115 | ||||
-rw-r--r-- | charselectapplet/kcharselectapplet.desktop | 100 |
4 files changed, 600 insertions, 0 deletions
diff --git a/charselectapplet/Makefile.am b/charselectapplet/Makefile.am new file mode 100644 index 0000000..49a70a2 --- /dev/null +++ b/charselectapplet/Makefile.am @@ -0,0 +1,19 @@ +INCLUDES = $(all_includes) + +kde_module_LTLIBRARIES = kcharselect_panelapplet.la + +kcharselect_panelapplet_la_SOURCES = charselectapplet.cpp + +METASOURCES = AUTO +noinst_HEADERS = charselectapplet.h + +lnkdir = $(kde_datadir)/kicker/applets +lnk_DATA = kcharselectapplet.desktop + +EXTRA_DIST = $(lnk_DATA) + +kcharselect_panelapplet_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN) -module +kcharselect_panelapplet_la_LIBADD = $(LIB_KDEUI) + +messages: + $(XGETTEXT) *.cpp *.h -o $(podir)/kcharselectapplet.pot diff --git a/charselectapplet/charselectapplet.cpp b/charselectapplet/charselectapplet.cpp new file mode 100644 index 0000000..f2fccbc --- /dev/null +++ b/charselectapplet/charselectapplet.cpp @@ -0,0 +1,366 @@ +/***************************************************************** + +Copyright (c) 2001 Matthias Elter <elter@kde.org> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +******************************************************************/ + +#include <math.h> + +#include <qlayout.h> +#include <qpainter.h> +#include <qclipboard.h> +#include <qvbox.h> +#include <qspinbox.h> +#include <qlabel.h> + +#include <klocale.h> +#include <kglobal.h> +#include <kconfig.h> +#include <klineedit.h> +#include <kaboutapplication.h> + +#include "charselectapplet.h" +#include "charselectapplet.moc" + +extern "C" +{ + KDE_EXPORT KPanelApplet* init(QWidget *parent, const QString& configFile) + { + KGlobal::locale()->insertCatalogue("kcharselectapplet"); + return new CharSelectApplet(configFile, KPanelApplet::Normal, + KPanelApplet::About | KPanelApplet::Preferences, + parent, "kcharselectapplet"); + } +} + +static int cell_width = 16; +static int cell_height = 16; +static int char_count = 0; + +CharSelectApplet::CharSelectApplet(const QString& configFile, Type type, int actions, + QWidget *parent, const char *name) + : KPanelApplet(configFile, type, actions, parent, name), + _aboutData(0), _configDialog(0) +{ + // read configuration + KConfig *c = config(); + c->setGroup("General"); + cell_width = c->readNumEntry("CellWidth", cell_width); + cell_height = c->readNumEntry("CellHeight", cell_height); + QString characters = c->readEntry("Characters", "ߩ"); + + // setup layout + QHBoxLayout *_layout = new QHBoxLayout(this); + _layout->setAutoAdd(true); + + // setup table view + _table = new CharTable(this); + + // insert chars + _table->setCharacters(characters); +} + +int CharSelectApplet::widthForHeight(int height) const +{ + // number of rows depends on panel size + int rows = (height - (lineWidth() * 2))/ cell_height; + if(rows <= 0) rows = 1; + + // calculate number of columns + float c = (float) char_count / rows; + int columns = (int) ceil(c); + if(columns <= 0) columns = 1; + + _table->setRowsAndColumns(rows, columns); + + // tell kicker how much space we need + return columns * cell_width + lineWidth() * 2; +} + +int CharSelectApplet::heightForWidth(int width) const +{ + // number of columns depends on panel size + int columns = (width - (lineWidth() * 2))/ cell_width; + if(columns <= 0) columns = 1; + + // calculate number of rows we need + float r = (float) char_count / columns; + int rows = (int) ceil(r); + if(rows <= 0) rows = 1; + + _table->setRowsAndColumns(rows, columns); + + return rows * cell_height + lineWidth() *2; +} + +void CharSelectApplet::preferences() +{ + if(!_configDialog) + _configDialog = new ConfigDialog(this); + + _configDialog->setCharacters(_table->characters()); + _configDialog->setCellWidth(cell_width); + _configDialog->setCellHeight(cell_height); + _configDialog->setInitialSize(QSize(300, 100)); + _configDialog->exec(); + + cell_width = _configDialog->cellWidth(); + cell_height = _configDialog->cellHeight(); + _table->setCharacters(_configDialog->characters()); + + emit updateLayout(); + + // write configuration + KConfig *c = config(); + c->setGroup("General"); + c->writeEntry("CellWidth", cell_width); + c->writeEntry("CellHeight", cell_height); + c->writeEntry("Characters", _configDialog->characters()); + c->sync(); +} + +void CharSelectApplet::about() +{ + if(!_aboutData) { + _aboutData = new KAboutData("kcharselectapplet", I18N_NOOP("KCharSelectApplet"), "1.0", + I18N_NOOP("A character picker applet.\n" + "Used to copy single characters to the X11 clipboard.\n" + "You can paste them to an application with the middle mouse button."), + KAboutData::License_BSD, "(c) 2001, Matthias Elter"); + _aboutData->addAuthor("Matthias Elter", 0, "elter@kde.org"); + } + + KAboutApplication dialog(_aboutData); + dialog.exec(); +} + +CharTable::CharTable(QWidget* parent, const char* name) + : QFrame(parent, name), _rows(2), _cols(2), + _activeRow(-1), _activeCol(-1), + _cWidth(cell_width), _cHeight(cell_height) +{ + setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); + setFocusPolicy(QWidget::NoFocus); + setBackgroundMode(QWidget::NoBackground); +} + +void CharTable::setRowsAndColumns(int r, int c) +{ + _rows = r; + _cols = c; +} + +void CharTable::insertChar(QChar c) +{ + _map.insert(char_count++, c); +} + +void CharTable::insertString(QString s) +{ + for (unsigned int i = 0; i < s.length(); i++) + insertChar(s[i]); +} + +void CharTable::setCharacters(const QString& characters) +{ + _map.clear(); + char_count = 0; + insertString(characters); +} + +QString CharTable::characters() +{ + QString characters; + for (int r = 0; r <_rows; r++) + for (int c = 0; c <_cols; c++) + characters += _map[c + r * _cols]; + + return characters; +} + +int CharTable::findRow(int y) +{ + return y / _cHeight; +} + +int CharTable::findCol(int x) +{ + return x / _cWidth; +} + +void CharTable::resizeEvent(QResizeEvent*) +{ + _cWidth = contentsRect().width() / _cols; + _cHeight = contentsRect().height() / _rows; +} + +void CharTable::paintEvent(QPaintEvent* e) +{ + QPainter p(this); + + int xoffset = contentsRect().x(); + int yoffset = contentsRect().y(); + + for (int r = 0; r <_rows; r++) { + for (int c = 0; c <_cols; c++) { + p.setViewport(xoffset + c * _cWidth, yoffset + r * _cHeight, _cWidth, _cHeight); + p.setWindow(0, 0, _cWidth, _cHeight); + paintCell(&p, r, c); + } + } + QFrame::paintEvent(e); +} + +void CharTable::repaintCell(int r, int c) +{ + QPainter p(this); + + int xoffset = contentsRect().x(); + int yoffset = contentsRect().y(); + + p.setViewport(xoffset + c * _cWidth, yoffset + r * _cHeight, _cWidth, _cHeight); + p.setWindow(0, 0, _cWidth, _cHeight); + paintCell(&p, r, c); +} + +void CharTable::paintCell(QPainter* p, int row, int col) +{ + int w = _cWidth; + int h = _cHeight; + int x2 = w - 1; + int y2 = h - 1; + + bool active = (row == _activeRow) && (col == _activeCol); + + // draw background + if (active) { + p->setBrush(QBrush(colorGroup().highlight())); + p->setPen(NoPen); + p->drawRect(0, 0, w, h); + p->setPen(colorGroup().highlightedText()); + } + else { + p->setBrush(QBrush(colorGroup().base())); + p->setPen(NoPen); + p->drawRect(0, 0, w, h); + p->setPen(colorGroup().text()); + } + + // set font + QFont f = font(); + f.setPixelSize(10); + p->setFont(f); + + // draw char + p->drawText(0, 0, x2, y2, AlignHCenter | AlignVCenter, QString(_map[col + row * _cols])); +} + +void CharTable::mousePressEvent(QMouseEvent *e) +{ + int row = findRow(e->y()); + if (row == -1) return; + + int col = findCol(e->x()); + if (col == -1) return; + + selectCell(row, col); +} + +void CharTable::mouseMoveEvent(QMouseEvent *e) +{ + if(!(e->state() & (LeftButton | RightButton | MidButton))) return; + + int row = findRow(e->y()); + if (row == -1) return; + + int col = findCol(e->x()); + if (col == -1) return; + + selectCell(row, col); +} + +void CharTable::selectCell(int row, int col) +{ + if (row >= _rows || row < 0) return; + if (col >= _cols || col < 0) return; + + int oldRow = _activeRow; + int oldCol = _activeCol; + + _activeRow = row; + _activeCol = col; + + repaintCell(oldRow, oldCol); + repaintCell(_activeRow, _activeCol); + + QClipboard *cb = QApplication::clipboard(); + QObject::disconnect( cb, SIGNAL(dataChanged()), this, SLOT(clearCell()) ); + QString text = QString(_map[col + row * _cols]); + bool oldMode = cb->selectionModeEnabled(); + cb->setSelectionMode( true ); + cb->setText( text ); + cb->setSelectionMode( false ); + cb->setText( text ); + cb->setSelectionMode( oldMode ); + QObject::connect( cb, SIGNAL(dataChanged()), this, SLOT(clearCell()) ); +} + +void CharTable::clearCell() +{ + int oldRow = _activeRow; + int oldCol = _activeCol; + + _activeRow = -1; + _activeCol = -1; + + repaintCell(oldRow, oldCol); + + QObject::disconnect( QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clearCell()) ); +} + + +ConfigDialog::ConfigDialog(QWidget* parent, const char* name) + : KDialogBase(parent, name, true, i18n("Configuration"), + Ok | Cancel, Ok, true) +{ + QVBox *page = makeVBoxMainWidget(); + + QHBox *whbox = new QHBox(page); + QHBox *hhbox = new QHBox(page); + QHBox *chbox = new QHBox(page); + + QLabel *wlabel = new QLabel(i18n("Cell width:"), whbox); + QLabel *hlabel = new QLabel(i18n("Cell height:"), hhbox); + (void) new QLabel(i18n("Characters:"), chbox); + + _widthSpinBox = new QSpinBox(whbox); + _widthSpinBox->setMinValue(1); + _heightSpinBox = new QSpinBox(hhbox); + _heightSpinBox->setMinValue(1); + _characterInput = new KLineEdit(chbox); + + whbox->setSpacing(KDialog::spacingHint()); + hhbox->setSpacing(KDialog::spacingHint()); + chbox->setSpacing(KDialog::spacingHint()); + + whbox->setStretchFactor(wlabel, 2); + hhbox->setStretchFactor(hlabel, 2); + chbox->setStretchFactor(_characterInput, 2); +} diff --git a/charselectapplet/charselectapplet.h b/charselectapplet/charselectapplet.h new file mode 100644 index 0000000..b54dc55 --- /dev/null +++ b/charselectapplet/charselectapplet.h @@ -0,0 +1,115 @@ +/***************************************************************** + +Copyright (c) 2001 Matthias Elter <elter@kde.org> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +******************************************************************/ + +#ifndef __charselectapplet_h__ +#define __charselectapplet_h__ + +#include <qmap.h> + +#include <kpanelapplet.h> +#include <kdialogbase.h> + +class QSpinBox; +class KLineEdit; +class KAboutData; + +class ConfigDialog : public KDialogBase +{ + Q_OBJECT + +public: + ConfigDialog(QWidget* parent = 0, const char* name = 0); + + void setCharacters(const QString& s) { _characterInput->setText(s); } + void setCellWidth(int w) { _widthSpinBox->setValue(w); } + void setCellHeight(int h) { _heightSpinBox->setValue(h); } + + QString characters() { return _characterInput->text(); } + int cellWidth() { return _widthSpinBox->value(); } + int cellHeight() { return _heightSpinBox->value(); } + +private: + QSpinBox *_widthSpinBox; + QSpinBox *_heightSpinBox; + KLineEdit *_characterInput; +}; + +class CharTable : public QFrame +{ + Q_OBJECT + +public: + CharTable(QWidget* parent = 0, const char* name = 0); + + void setRowsAndColumns(int, int); + + void setCharacters(const QString&); + QString characters(); + +protected: + void paintEvent(QPaintEvent*); + void resizeEvent(QResizeEvent*); + void mousePressEvent(QMouseEvent*); + void mouseMoveEvent(QMouseEvent*); + + void paintCell(QPainter*, int, int); + void repaintCell(int, int); + void selectCell(int row, int col); + + void insertString(QString s); + void insertChar(QChar c); + + int findRow(int y); + int findCol(int x); + +protected slots: + void clearCell(); +private: + int _rows, _cols; + int _activeRow, _activeCol; + int _cWidth, _cHeight; + int _charcount; + QMap<int, QChar> _map; +}; + +class CharSelectApplet : public KPanelApplet +{ + Q_OBJECT + +public: + CharSelectApplet(const QString& configFile, Type t = Stretch, int actions = 0, + QWidget *parent = 0, const char *name = 0); + + int widthForHeight(int height) const; + int heightForWidth(int width) const; + + void preferences(); + void about(); + +private: + CharTable *_table; + KAboutData *_aboutData; + ConfigDialog *_configDialog; +}; + +#endif diff --git a/charselectapplet/kcharselectapplet.desktop b/charselectapplet/kcharselectapplet.desktop new file mode 100644 index 0000000..029b5be --- /dev/null +++ b/charselectapplet/kcharselectapplet.desktop @@ -0,0 +1,100 @@ +[Desktop Entry] +Name=Character Selector +Name[ar]=أداة اختيار الرموز +Name[az]=Xarakter Seçici +Name[bg]=Избор на знаци +Name[br]=Dibaber arouezenn +Name[bs]=Izbor znakova +Name[ca]=Selector de caràcters +Name[cs]=Vyběr znaků +Name[cy]=Dewisydd Nod +Name[da]=Tegnvælger +Name[de]=Tabelle zur Zeichenauswahl +Name[el]=Επιλογέας χαρακτήρων +Name[eo]=Elektilo por signoj +Name[es]=Selector de caracteres +Name[et]=Sümbolite valija +Name[eu]=Karaktere autatzailea +Name[fa]=گزینندۀ نویسه +Name[fi]=Merkkivalitsin +Name[fr]=Sélecteur de caractères +Name[ga]=Roghnóir Carachtar +Name[gl]=Selector de Caracteres +Name[he]=בוחר תווים +Name[hu]=KCharselectApplet +Name[id]=Pemilih Karakter +Name[is]=Stafaval +Name[it]=Selettore di caratteri +Name[ja]=文字の選択 +Name[ka]=სიმბოლოთა შემრჩეველი +Name[kk]=Таңба тергіш +Name[km]=កម្មវិធីជ្រើសតួអក្សរ +Name[nb]=Tegnvelger +Name[nds]=Tekenutwähler +Name[ne]=क्यारेक्टर चयनकर्ता +Name[nl]=Speciale tekens +Name[nn]=Teiknveljar +Name[pa]=ਅੱਖਰ ਚੋਣਕਾਰ +Name[pl]=Wybór znaku +Name[pt]=Selector de Caracteres +Name[pt_BR]=Seletor de Caracteres +Name[ru]=Выбор символа +Name[sk]=Voľba znakov +Name[sl]=Izbiranje znakov +Name[sr]=Бирач знакова +Name[sr@Latn]=Birač znakova +Name[sv]=Teckenväljare +Name[ta]= எழுத்து தேர்ந்தெடுப்பான் +Name[uk]=Вибір символів +Name[uz]=Harf tanlagich +Name[uz@cyrillic]=Ҳарф танлагич +Name[zh_CN]=字符选择器 +Name[zh_TW]=字元選擇器 +Icon=kcharselect +X-KDE-Library=kcharselect_panelapplet +X-KDE-UniqueApplet=true +Comment=Pick foreign and special characters for clipboard +Comment[ar]=يلتقط الرموز الأجنبية والخاصة من أجل الحافظة +Comment[bg]=Избор на чужди и специални знаци за копиране чрез системния буфер +Comment[bs]=Izaberite posebne i međunarodne znakove sa spiska +Comment[ca]=Selecciona caràcters estranger i especials pel porta-retalls +Comment[cs]=Výběr cizích a speciálních znaků do schránky +Comment[da]=Vælg fremmede tegn og specialtegn for klippebordet +Comment[de]=Fremdsprachige und Sonderzeichen in die Zwischenablage kopieren +Comment[el]=Επιλέξτε ειδικούς χαρακτήρες και χαρακτήρες άλλης γλώσσας για το πρόχειρο +Comment[es]=Seleccionar caracteres extranjeros y especiales para el portapapeles +Comment[et]=Võõr- ja erisümbolite valimine lõikepuhvrisse +Comment[eu]=Hautatu atzerriko karaketereak eta karaketere bereziak arbelarentzat +Comment[fa]=انتخاب نویسههای خارجی و ویژه برای تخته یادداشت +Comment[fi]=Poimi erikoismerkkejä leikepöydälle +Comment[fr]=Sélectionner des caractères étrangers et spéciaux +Comment[ga]=Roghnaigh carachtair iasachta agus speisialta don ghearrthaisce +Comment[he]=בחר תווים זרים ומיוחדים להדבקה +Comment[hu]=Más nyelvi és speciális karakterek másolása a vágólapra +Comment[is]=Velur útlenda og sérstaka stafi fyrir klippispjaldið +Comment[it]=Seleziona caratteri speciali e stranieri per gli appunti +Comment[ja]=クリップボードに外国語文字または特殊文字をピックアップする +Comment[ka]=გაცვლის ბუფერისთვის უცხოური და სპეციალური სიმბოლოების აღება +Comment[kk]=Пернетақтада жоқ таңбаларды алмасу буферіне теріп алу +Comment[km]=ជ្រើសតួអក្សរបរទេស និងពិសេសសម្រាប់ក្តារតម្បៀតខ្ទាស់ +Comment[lt]=Parinkite užsienietiškus ar ypatingus simbolius talpyklei +Comment[nb]=Hent inn fremmede tegn og spesialtegn til utklippstavla +Comment[nds]=Frömdspraak- un Sünnertekens na de Twischenaflaag koperen +Comment[ne]=क्लिबोर्डका लागि विदेशी र विशेष क्यारेक्टर छान्नुहोस् +Comment[nl]=Buitenlandse en speciale tekens van klembord halen +Comment[nn]=Kopier spesialteikn og bokstavar frå framande språk til utklippstavla +Comment[pl]=Wstawia znaki specjalne albo diakrytyczne do schowka +Comment[pt]=Escolher caracteres especiais e estrangeiros para a área de transferência +Comment[pt_BR]=Lista de caracteres especiais para a área de transferência +Comment[ru]=Выбрать и поместить в буфер обмена специальные символы +Comment[sk]=Vložte do schánky cudzie a špeciálne znaky +Comment[sl]=Poberi tuje in posebne znake za na odložišče +Comment[sr]=Бира стране и специјалне знакове за клипборд +Comment[sr@Latn]=Bira strane i specijalne znakove za klipbord +Comment[sv]=Välj främmande tecken och specialtecken för klippbordet +Comment[tr]=Yabancı ve özel karakterleri panoya kopyalar +Comment[uk]=Вибрати і вставити в кишеню іноземні та спеціальні символи +Comment[uz]=Harf va maxsus belgilarni xotiraga olish vositasi +Comment[uz@cyrillic]=Ҳарф ва махсус белгиларни хотирага олиш воситаси +Comment[zh_CN]=将外语和特殊字符拾取到剪贴板 +Comment[zh_TW]=為剪貼簿選擇外國與特殊字元 |