diff options
Diffstat (limited to 'kdict/applet')
-rw-r--r-- | kdict/applet/Makefile.am | 19 | ||||
-rw-r--r-- | kdict/applet/kdictapplet.cpp | 405 | ||||
-rw-r--r-- | kdict/applet/kdictapplet.desktop | 147 | ||||
-rw-r--r-- | kdict/applet/kdictapplet.h | 101 |
4 files changed, 672 insertions, 0 deletions
diff --git a/kdict/applet/Makefile.am b/kdict/applet/Makefile.am new file mode 100644 index 00000000..db1f4bc2 --- /dev/null +++ b/kdict/applet/Makefile.am @@ -0,0 +1,19 @@ +INCLUDES = $(all_includes) + +kde_module_LTLIBRARIES = kdict_panelapplet.la + +kdict_panelapplet_la_SOURCES = kdictapplet.cpp + +METASOURCES = AUTO +noinst_HEADERS = kdictapplet.h + +lnkdir = $(kde_datadir)/kicker/applets +lnk_DATA = kdictapplet.desktop + +EXTRA_DIST = $(lnk_DATA) + +kdict_panelapplet_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN) -module +kdict_panelapplet_la_LIBADD = $(LIB_KSYCOCA) $(LIB_KDEUI) + +messages: rc.cpp + $(XGETTEXT) *.cpp *.h -o $(podir)/kdictapplet.pot diff --git a/kdict/applet/kdictapplet.cpp b/kdict/applet/kdictapplet.cpp new file mode 100644 index 00000000..ad907864 --- /dev/null +++ b/kdict/applet/kdictapplet.cpp @@ -0,0 +1,405 @@ +/* ------------------------------------------------------------- + + kdictapplet.h (part of The KDE Dictionary Client) + + Copyright (C) 2001 Christian Gebauer <gebauer@kde.org> + + The applet is loosely based on the "Run" applet included in KDE. + Copyright (c) 2000 Matthias Elter <elter@kde.org> (Artistic License) + + This file is distributed under the Artistic License. + See LICENSE for details. + + ------------------------------------------------------------- + + PopupBox helper class + DictApplet a small kicker-applet + + ------------------------------------------------------------- */ + +#include <qlabel.h> +#include <qpushbutton.h> +#include <qtimer.h> +#include <qlayout.h> +#include <qtooltip.h> + +#include <kconfig.h> +#include <kcombobox.h> +#include <kiconloader.h> +#include <klocale.h> +#include <dcopclient.h> +#include <kapplication.h> +#include <kprocess.h> + +#include "kdictapplet.h" + +//********* PopupBox ******************************************** + +PopupBox::PopupBox() + : QHBox(0, 0, WStyle_Customize | WType_Popup ), popupEnabled(true) +{ +} + + +PopupBox::~PopupBox() +{} + + +bool PopupBox::showBox() +{ + if (!popupEnabled) // prevents that the popup is shown again immediatly + return false; + else { + show(); + return true; + } +} + + +void PopupBox::hideEvent(QHideEvent *) +{ + emit(hidden()); + popupEnabled = false; + QTimer::singleShot(100, this, SLOT(enablePopup())); +} + + +void PopupBox::enablePopup() +{ + popupEnabled = true; +} + + +//********* DictApplet ******************************************** + +extern "C" +{ + KDE_EXPORT KPanelApplet* init(QWidget *parent, const QString& configFile) + { + KGlobal::locale()->insertCatalogue("kdictapplet"); + return new DictApplet(configFile, KPanelApplet::Stretch, 0, parent, "kdictapplet"); + } +} + + +DictApplet::DictApplet(const QString& configFile, Type type, int actions, QWidget *parent, const char *name) + : KPanelApplet(configFile, type, actions, parent, name), waiting(0) +{ + // first the widgets for a horizontal panel + baseWidget = new QWidget(this); + QGridLayout *baseLay = new QGridLayout(baseWidget,2,6,0,1); + + textLabel = new QLabel(i18n("Dictionary:"), baseWidget); + textLabel->setBackgroundOrigin(AncestorOrigin); + QFont f(textLabel->font()); + f.setPixelSize(12); + textLabel->setFont(f); + baseLay->addWidget(textLabel,0,1); + QToolTip::add(textLabel,i18n("Look up a word or phrase with Kdict")); + + iconLabel = new QLabel(baseWidget); + iconLabel->setBackgroundOrigin(AncestorOrigin); + QPixmap pm = KGlobal::iconLoader()->loadIcon("kdict", KIcon::Panel, KIcon::SizeSmall, KIcon::DefaultState, 0L, true); + iconLabel->setPixmap(pm); + baseLay->addWidget(iconLabel,1,0); + iconLabel->setAlignment(Qt::AlignCenter | Qt::AlignVCenter); + iconLabel->setFixedWidth(pm.width()+4); + QToolTip::add(iconLabel,i18n("Look up a word or phrase with Kdict")); + + f.setPixelSize(10); + clipboardBtn = new QPushButton(i18n("C"),baseWidget); + clipboardBtn->setBackgroundOrigin(AncestorOrigin); + clipboardBtn->setFont(f); + clipboardBtn->setFixedSize(16,16); + connect(clipboardBtn, SIGNAL(clicked()), SLOT(queryClipboard())); + baseLay->addWidget(clipboardBtn,0,3); + QToolTip::add(clipboardBtn,i18n("Define selected text")); + + defineBtn = new QPushButton(i18n("D"),baseWidget); + defineBtn->setBackgroundOrigin(AncestorOrigin); + defineBtn->setFont(f); + defineBtn->setFixedSize(16,16); + defineBtn->setEnabled(false); + connect(defineBtn, SIGNAL(clicked()), SLOT(startDefine())); + baseLay->addWidget(defineBtn,0,4); + QToolTip::add(defineBtn,i18n("Define word/phrase")); + + matchBtn = new QPushButton(i18n("M"),baseWidget); + matchBtn->setBackgroundOrigin(AncestorOrigin); + matchBtn->setFont(f); + matchBtn->setFixedSize(16,16); + matchBtn->setEnabled(false); + connect(matchBtn, SIGNAL(clicked()), SLOT(startMatch())); + baseLay->addWidget(matchBtn,0,5); + QToolTip::add(matchBtn,i18n("Find matching definitions")); + + completionObject = new KCompletion(); + + internalCombo = new KHistoryCombo(baseWidget); + internalCombo->setBackgroundOrigin(AncestorOrigin); + internalCombo->setCompletionObject(completionObject); + internalCombo->setFocus(); + internalCombo->clearEdit(); + internalCombo->lineEdit()->installEventFilter( this ); + connect(internalCombo, SIGNAL(returnPressed(const QString&)), SLOT(startQuery(const QString&))); + connect(internalCombo, SIGNAL(textChanged(const QString&)), SLOT(comboTextChanged(const QString&))); + QToolTip::add(internalCombo,i18n("Look up a word or phrase with Kdict")); + + baseLay->addMultiCellWidget(internalCombo,1,1,1,5); + + baseLay->setColStretch(2,1); + + // widgets for a vertical panel + verticalBtn = new QPushButton(this); + connect(verticalBtn, SIGNAL(pressed()), SLOT(showExternalCombo())); + QToolTip::add(verticalBtn,i18n("Look up a word or phrase with Kdict")); + + popupBox = new PopupBox(); + popupBox->setFixedSize(160, 22); + connect(popupBox, SIGNAL(hidden()), SLOT(externalComboHidden())); + externalCombo = new KHistoryCombo(popupBox); + externalCombo->setCompletionObject(completionObject); + connect(externalCombo, SIGNAL(returnPressed(const QString&)), SLOT(startQuery(const QString&))); + externalCombo->setFixedSize(160, externalCombo->sizeHint().height()); + + connect(internalCombo, SIGNAL(completionModeChanged(KGlobalSettings::Completion)), + this, SLOT(updateCompletionMode(KGlobalSettings::Completion))); + connect(externalCombo, SIGNAL(completionModeChanged(KGlobalSettings::Completion)), + this, SLOT(updateCompletionMode(KGlobalSettings::Completion))); + + // restore history and completion list + KConfig *c = config(); + c->setGroup("General"); + + QStringList list = c->readListEntry("Completion list"); + completionObject->setItems(list); + int mode = c->readNumEntry("Completion mode", + KGlobalSettings::completionMode()); + internalCombo->setCompletionMode((KGlobalSettings::Completion)mode); + externalCombo->setCompletionMode((KGlobalSettings::Completion)mode); + + list = c->readListEntry("History list"); + internalCombo->setHistoryItems(list); + externalCombo->setHistoryItems(list); +} + + +DictApplet::~DictApplet() +{ + // save history and completion list + KConfig *c = config(); + c->setGroup("General"); + + QStringList list = completionObject->items(); + c->writeEntry("Completion list", list); + c->writeEntry("Completion mode", (int) internalCombo->completionMode()); + + list = internalCombo->historyItems(); + c->writeEntry("History list", list); + c->sync(); + + delete completionObject; +} + + +int DictApplet::widthForHeight(int height) const +{ + if (height >= 38) + return textLabel->sizeHint().width()+55; + else + return textLabel->sizeHint().width()+25; +} + + +int DictApplet::heightForWidth(int width) const +{ + return width; +} + + +void DictApplet::resizeEvent(QResizeEvent*) +{ + if (orientation() == Horizontal) { + verticalBtn->hide(); + baseWidget->show(); + baseWidget->setFixedSize(width(),height()); + + if (height() < internalCombo->sizeHint().height()) + internalCombo->setFixedHeight(height()); + else + internalCombo->setFixedHeight(internalCombo->sizeHint().height()); + + if (height() >= 38) { + textLabel->show(); + clipboardBtn->show(); + defineBtn->show(); + matchBtn->show(); + iconLabel->hide(); + internalCombo->setFixedWidth(width()); + } else { + textLabel->hide(); + clipboardBtn->hide(); + defineBtn->hide(); + matchBtn->hide(); + iconLabel->show(); + internalCombo->setFixedWidth(width()-iconLabel->width()-1); + } + + baseWidget->updateGeometry(); + } else { // orientation() == Vertical + verticalBtn->show(); + baseWidget->hide(); + verticalBtn->setFixedSize(width(),width()); + + KIcon::StdSizes sz = width() < 32 ? KIcon::SizeSmall : (width() < 48 ? KIcon::SizeMedium : KIcon::SizeLarge); + QPixmap pm = KGlobal::iconLoader()->loadIcon("kdict", KIcon::Panel, sz, KIcon::DefaultState, 0L, true); + verticalBtn->setPixmap(pm); + } +} + + +bool DictApplet::eventFilter( QObject *o, QEvent * e) +{ + if (e->type() == QEvent::MouseButtonRelease) + emit requestFocus(); + + return KPanelApplet::eventFilter(o, e); +} + + +void DictApplet::sendCommand(const QCString &fun, const QString &data) +{ + if (waiting > 0) { + waiting = 1; + delayedFunc = fun.copy(); + delayedData = data; + return; + } + + DCOPClient *client = kapp->dcopClient(); + if (!client->isApplicationRegistered("kdict")) { + KApplication::startServiceByDesktopName("kdict"); + waiting = 1; + delayedFunc = fun.copy(); + delayedData = data; + QTimer::singleShot(100, this, SLOT(sendDelayedCommand())); + return; + } else { + QCStringList list = client->remoteObjects("kdict"); + if (list.findIndex("KDictIface")==-1) { + waiting = 1; + delayedFunc = fun.copy(); + delayedData = data; + QTimer::singleShot(100, this, SLOT(sendDelayedCommand())); + return; + } + } + + client->send("kdict","default",fun,data); +} + + +void DictApplet::sendDelayedCommand() +{ + if (waiting > 100) { // timeout after ten seconds + waiting = 0; + return; + } + + DCOPClient *client = kapp->dcopClient(); + if (!client->isApplicationRegistered("kdict")) { + waiting++; + QTimer::singleShot(100, this, SLOT(sendDelayedCommand())); + return; + } else { + QCStringList list = client->remoteObjects("kdict"); + if (list.findIndex("KDictIface")==-1) { + waiting++; + QTimer::singleShot(100, this, SLOT(sendDelayedCommand())); + return; + } + } + + client->send("kdict","default",delayedFunc,delayedData); + waiting = 0; +} + + +void DictApplet::startQuery(const QString &s) +{ + QString query = s.stripWhiteSpace(); + if (query.isEmpty()) + return; + + internalCombo->addToHistory(query); + externalCombo->addToHistory(query); + internalCombo->clearEdit(); + externalCombo->clearEdit(); + + sendCommand("definePhrase(QString)",query); + + if (orientation() == Vertical) + popupBox->hide(); +} + + +void DictApplet::comboTextChanged(const QString &s) +{ + defineBtn->setEnabled(!s.isEmpty()); + matchBtn->setEnabled(!s.isEmpty()); +} + + +void DictApplet::queryClipboard() +{ + sendCommand("defineClipboardContent()",QString::null); +} + + +void DictApplet::startDefine() +{ + startQuery(internalCombo->currentText()); +} + + +void DictApplet::startMatch() +{ + QString query = internalCombo->currentText().stripWhiteSpace(); + internalCombo->addToHistory(query); + externalCombo->addToHistory(query); + internalCombo->clearEdit(); + externalCombo->clearEdit(); + + sendCommand("matchPhrase(QString)",query); +} + + +void DictApplet::showExternalCombo() +{ + QPoint p; + if (position() == pLeft) + p = mapToGlobal(QPoint(-popupBox->width()-1, 0)); + else + p = mapToGlobal(QPoint(width()+1, 0)); + popupBox->move(p); + if (popupBox->showBox()) + externalCombo->setFocus(); + else + verticalBtn->setDown(false); +} + + +void DictApplet::externalComboHidden() +{ + verticalBtn->setDown(false); +} + +void DictApplet::updateCompletionMode(KGlobalSettings::Completion mode) +{ + internalCombo->setCompletionMode(mode); + externalCombo->setCompletionMode(mode); +} + +//-------------------------------- + +#include "kdictapplet.moc" diff --git a/kdict/applet/kdictapplet.desktop b/kdict/applet/kdictapplet.desktop new file mode 100644 index 00000000..23d26f3f --- /dev/null +++ b/kdict/applet/kdictapplet.desktop @@ -0,0 +1,147 @@ +[Desktop Entry] +Comment=Lookup phrases in a dictionary +Comment[af]=Opkyk frases in 'n woordeboek +Comment[ar]=ابحث عن الكلمات في القاموس +Comment[az]=Lüğətdən kəlimələrə baxın +Comment[be]=Пошук выразаў у слоўніку +Comment[bg]=Търсене на фрази в речника +Comment[bn]=একটি অভিধানে শব্দসমষ্টির খোঁজ করো +Comment[bs]=Potražite fraze u rječniku +Comment[ca]=Cerca expressions en un diccionari +Comment[cs]=Vyhledávač pojmů ve slovníku +Comment[cy]=Edrych am ddywediadau mewn geiriadur +Comment[da]=Slå sætninger op i en ordbog +Comment[de]=Ausdrücke in einem Lexikon nachschlagen +Comment[el]=Αναζήτηση φράσεων σε λεξικό +Comment[eo]=Serĉi kapvortojn en vortaroj +Comment[es]=Busca expresiones en un diccionario +Comment[et]=Fraaside otsimine sõnaraamatust +Comment[eu]=Bilatu esaldiak hiztegi batean +Comment[fa]=مراجعه به واژهنامه برای عبارتها +Comment[fi]=Hae lauseita sanakirjasta +Comment[fr]=Recherche de phrases dans un dictionnaire +Comment[ga]=Cuardaigh frásaí i bhfoclóir +Comment[gl]=Buscar expresións no diccionario +Comment[he]=חיפוש ביטויים במילון +Comment[hi]=शब्दकोश में वाक्यांशों को देखे +Comment[hr]=Potraži fraze u rječniku +Comment[hu]=Szótárkezelő alkalmazás +Comment[is]=Fletta upp í orðabók +Comment[it]=Cerca frasi in un dizionario +Comment[ja]=辞書で語句を検索 +Comment[ka]=ფრაზების ლექსიკონში ძებნა +Comment[kk]=Сөздікте іздеу +Comment[km]=រកមើលប្រយោគនៅក្នុងវចនានុក្រមមួយ +Comment[ko]=사전에서 글귀를 찾아줍니다 +Comment[lt]=Ieškoti frazių žodyne +Comment[lv]=Skatīt frāzes vārdnīcā +Comment[mk]=Барајте за изрази во речник +Comment[mn]=Толь бичигээс үг харах +Comment[ms]=Mencari frasa di dalam kamus +Comment[mt]=Fittex frażijiet fid-dizzjunarju +Comment[nb]=Finn fraser i en ordbok +Comment[nds]=Begrepen in en Wöörbook nakieken +Comment[ne]=शब्दकोशमा वाक्यांश खोजी गर्नुहोस् +Comment[nl]=Zoek bepaalde uitdrukkingen op in een woordenboek +Comment[nn]=Slå opp ord i ei ordboka +Comment[nso]=Nyaka mantsu ka gare ga pukuntsu +Comment[pl]=Szukanie zwrotów w słowniku +Comment[pt]=Procura por frases num dicionário +Comment[pt_BR]=Busca frases em um dicionário +Comment[ro]=Caută fraze într-un dicţionar +Comment[ru]=Поиск слов в словаре +Comment[se]=Oza sániid sátnegirjjis +Comment[sk]=Hľadanie fráz v slovníku +Comment[sl]=Iskanje Izrazov v slovarju +Comment[sr]=Потражите фразе у речнику +Comment[sr@Latn]=Potražite fraze u rečniku +Comment[sv]=Leta upp fraser i en ordlista +Comment[ta]=ஒரு அகராதியிலுள்ள தேடற்சொற்தொடர்கள் +Comment[tg]=Ҷустуҷӯи ибораҳо дар луғат +Comment[th]=ค้นหาวลีในพจนานุกรม +Comment[tr]=Sözlükten kelimelere bakın +Comment[uk]=Пошук фраз у словнику +Comment[ven]=Todani fhungo kha bugu talutshedza maipfi +Comment[wa]=Cweri des fråzes dins on diccionaire +Comment[xh]=Jonga amabinzana kwincwadi enekcazelo zamagama +Comment[zh_CN]=在字典中查找短语 +Comment[zh_HK]=在字典中尋找片語 +Comment[zh_TW]=在字典中尋找片語 +Comment[zu]=Bheka amagama kwisichazamagama +Icon= +Name=Dictionary +Name[af]=Woordeboek +Name[ar]=القاموس +Name[az]=Lüğət +Name[be]=Слоўнік +Name[bg]=Речник +Name[bn]=অভিধান +Name[br]=Geriadur +Name[bs]=Rječnik +Name[ca]=Diccionari +Name[cs]=Slovník +Name[cy]=Geiriadur +Name[da]=Ordbog +Name[de]=Lexikon +Name[el]=Λεξικό +Name[eo]=Vortaro +Name[es]=Diccionario +Name[et]=Sõnaraamat +Name[eu]=Hiztegia +Name[fa]=واژهنامه +Name[fi]=Sanakirja +Name[fr]=Dictionnaire +Name[ga]=Foclóir +Name[gl]=Diccionario +Name[he]=מילון +Name[hi]=शब्दकोश +Name[hr]=Rječnik +Name[hu]=Szótár +Name[is]=Orðabók +Name[it]=Dizionario +Name[ja]=辞書 +Name[ka]=ლექსიკონი +Name[kk]=Сөздік +Name[km]=វចនានុក្រម +Name[ko]=사전 +Name[lt]=Žodynas +Name[lv]=Vārdnīca +Name[mk]=Речник +Name[mn]=Толь бичиг +Name[ms]=Kamus +Name[mt]=Dizzjunarju +Name[nb]=Ordbok +Name[nds]=Wöörbook +Name[ne]=शब्दकोश +Name[nl]=Woordenboek +Name[nn]=Ordbok +Name[nso]=Pukuntsu +Name[pa]=ਸ਼ਬਦ-ਕੋਸ਼ +Name[pl]=Słownik +Name[pt]=Dicionário +Name[pt_BR]=Dicionário +Name[ro]=Dicţionar +Name[ru]=Словарь +Name[se]=Sátnegirji +Name[sk]=Slovník +Name[sl]=Slovar +Name[sr]=Речник +Name[sr@Latn]=Rečnik +Name[sv]=Ordlista +Name[ta]=அகராதி +Name[tg]=Луғат +Name[th]=พจนานุกรม +Name[tr]=Sözlük +Name[uk]=Словник +Name[uz]=Lugʻat +Name[uz@cyrillic]=Луғат +Name[ven]=Bugu yau talutshedza maipfi +Name[wa]=Motî +Name[xh]=Incwadi eneenkcazelo zamagama +Name[zh_CN]=字典 +Name[zh_HK]=字典 +Name[zh_TW]=字典 +Name[zu]=Isichazamagama +Icon=kdict +X-KDE-Library=kdict_panelapplet +X-KDE-UniqueApplet=true diff --git a/kdict/applet/kdictapplet.h b/kdict/applet/kdictapplet.h new file mode 100644 index 00000000..a9738148 --- /dev/null +++ b/kdict/applet/kdictapplet.h @@ -0,0 +1,101 @@ +/* ------------------------------------------------------------- + + kdictapplet.h (part of The KDE Dictionary Client) + + Copyright (C) 2001 Christian Gebauer <gebauer@kde.org> + + The applet is loosely based on the "Run" applet included in KDE. + Copyright (c) 2000 Matthias Elter <elter@kde.org> (Artistic License) + + This file is distributed under the Artistic License. + See LICENSE for details. + + ------------------------------------------------------------- + + PopupBox helper class + DictApplet a small kicker-applet + + ------------------------------------------------------------- */ + +#ifndef _DICTAPPLET_H_ +#define _DICTAPPLET_H_ + +#include <qhbox.h> +#include <kpanelapplet.h> + +class QLabel; +class QPushButton; +class KHistoryCombo; + + +//********* PopupBox ******************************************** + +class PopupBox : public QHBox +{ + Q_OBJECT + +public: + PopupBox(); + ~PopupBox(); + + bool showBox(); + +signals: + void hidden(); + +public slots: + void enablePopup(); + +protected: + void hideEvent(QHideEvent *); + +private: + bool popupEnabled; + +}; + +//********* DictApplet ******************************************** + +class DictApplet : public KPanelApplet +{ + Q_OBJECT + +public: + DictApplet(const QString& configFile, Type t = Stretch, int actions = 0, QWidget *parent = 0, const char *name = 0); + virtual ~DictApplet(); + + int widthForHeight(int height) const; + int heightForWidth(int width) const; + +protected: + void resizeEvent(QResizeEvent*); + bool eventFilter( QObject *, QEvent * ); + + void sendCommand(const QCString &fun, const QString &data); + +protected slots: + void sendDelayedCommand(); + void startQuery(const QString&); + void comboTextChanged(const QString&); + void queryClipboard(); + void startDefine(); + void startMatch(); + void showExternalCombo(); + void externalComboHidden(); + void updateCompletionMode(KGlobalSettings::Completion mode); + +private: + KHistoryCombo *internalCombo, *externalCombo; + KCompletion *completionObject; + QLabel *textLabel, *iconLabel; + QPushButton *verticalBtn, *clipboardBtn, *defineBtn, *matchBtn; + QWidget *baseWidget; + PopupBox *popupBox; + + int waiting; + QCString delayedFunc; + QString delayedData; + +}; + +#endif |